Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ideas about smoke tests #10

Draft
wants to merge 24 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions .github/workflows/integration_test.yaml

This file was deleted.

34 changes: 34 additions & 0 deletions .github/workflows/spread_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: e2e smoke tests with spread

on:
push:
branches:
- master
pull_request:
workflow_dispatch:

jobs:
run-spread-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- uses: actions/setup-go@v5
with:
check-latest: true
go-version: 'stable'

- name: Install spread
run: |
go install github.com/snapcore/spread/cmd/spread@latest

- name: Run tests
run: |
sudo adduser --gecos "" --disabled-password ubuntu
echo "ubuntu:ubuntu" | sudo chpasswd
spread github-ci:

- name: Tmate debugging session
if: ${{ failure() }}
uses: mxschmitt/action-tmate@v3
timeout-minutes: 15
168 changes: 168 additions & 0 deletions spread.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
project: paas-charm

environment:
PROVIDER: microk8s
CHARMCRAFT_CHANNEL: latest/edge
ROCKCRAFT_CHANNEL: latest/edge
JUJU_CHANNEL: 3/stable
LXD_CHANNEL: latest/stable
MICROK8S_CHANNEL: 1.28-strict/stable
MICROK8S_ADDONS: hostpath-storage registry

JUJU_BOOTSTRAP_OPTIONS: --model-default test-mode=true --model-default automatically-retry-hooks=false --model-default
JUJU_EXTRA_BOOTSTRAP_OPTIONS: ""
JUJU_BOOTSTRAP_CONSTRAINTS: ""

# important to ensure adhoc and linode/qemu behave the same
SUDO_USER: ""
SUDO_UID: ""

LANG: "C.UTF-8"
LANGUAGE: "en"

PROJECT_PATH: /home/spread/proj
CRAFT_TEST_LIB_PATH: /home/spread/proj/tests/spread/lib

PATH: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:$CRAFT_TEST_LIB_PATH/tools

backends:
multipass:
type: adhoc
allocate: |
# Mitigate issues found when launching multiple mutipass instances
# concurrently. See https://github.com/canonical/multipass/issues/3336
sleep 0.$RANDOM
sleep 0.$RANDOM
sleep 0.$RANDOM

mkdir -p "$HOME/.spread"
export counter_file="$HOME/.spread/multipass-count"

# Sequential variable for unique instance names
instance_num=$(flock -x $counter_file bash -c '
[ -s $counter_file ] || echo 0 > $counter_file
num=$(< $counter_file)
echo $num
echo $(( $num + 1 )) > $counter_file')

multipass_image=$(echo "${SPREAD_SYSTEM}" | sed -e s/ubuntu-// -e s/-64//)

system=$(echo "${SPREAD_SYSTEM}" | tr . -)
instance_name="spread-${SPREAD_BACKEND}-${instance_num}-${system}"

multipass launch -vv --cpus 2 --disk 20G --memory 4G --name "${instance_name}" \
--cloud-init tests/spread/lib/cloud-config.yaml "${multipass_image}"

# Get the IP from the instance
ip=$(multipass info --format csv "$instance_name" | tail -1 | cut -d\, -f3)
ADDRESS "$ip"

discard: |
instance_name=$(multipass list --format csv | grep $SPREAD_SYSTEM_ADDRESS | cut -f1 -d\,)
multipass delete --purge "${instance_name}"

systems:
- ubuntu-22.04:
username: spread
password: spread
workers: 1

- ubuntu-20.04:
username: spread
password: spread
workers: 1

github-ci:
type: adhoc

allocate: |
echo "Allocating ad-hoc $SPREAD_SYSTEM"
if [ -z "${GITHUB_RUN_ID:-}" ]; then
FATAL "this back-end only works inside GitHub CI"
exit 1
fi
# echo 'ubuntu ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/99-spread-users
whoami
echo 'ubuntu ALL=(ALL) NOPASSWD:ALL' | sudo tee /etc/sudoers.d/99-spread-users
ADDRESS localhost:22

discard: |
echo "Discarding ad-hoc $SPREAD_SYSTEM"

systems:
- ubuntu-22.04-amd64:
username: ubuntu
password: ubuntu
workers: 1

lxd:
systems:
- ubuntu-22.04-64:
image: ubuntu:22.04
profiles:
- default
# With this profile, it works: https://microk8s.io/docs/install-lxd
- microk8s

suites:
tests/spread/general/:
summary: Charm functionality tests

systems:
- ubuntu-22.04*

environment:
# CHARMCRAFT_CHANNEL/charmcraft_current: latest/stable
# CHARMCRAFT_CHANNEL/charmcraft_next: latest/candidate
CHARMCRAFT_CHANNEL/charmcraft_edge: latest/edge

prepare: |
set -e
. "$CRAFT_TEST_LIB_PATH"/test-helpers.sh
DEBIAN_FRONTEND=noninteractive apt-get update -y
DEBIAN_FRONTEND=noninteractive apt-get install -y python3-pip jq
pip3 install tox

install_lxd
install_charmcraft
install_rockcraft
install_juju
install_microk8s

bootstrap_juju

juju add-model testing

restore: |
set -e
. "$CRAFT_TEST_LIB_PATH"/test-helpers.sh
# rm -f "$PROJECT_PATH"/*.charm
# charmcraft clean -p "$PROJECT_PATH"

restore_juju
restore_charmcraft
restore_rockcraft
restore_microk8s
restore_lxd

exclude:
- .git
- .tox

path: /home/spread/proj

prepare: |
snap refresh --hold

if systemctl is-enabled unattended-upgrades.service; then
systemctl stop unattended-upgrades.service
systemctl mask unattended-upgrades.service
fi

restore: |
apt autoremove -y --purge
rm -Rf "$PROJECT_PATH"
mkdir -p "$PROJECT_PATH"


kill-timeout: 1h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
ASGI config for django_hello_world project.

It exposes the ASGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/5.1/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_hello_world.settings')

application = get_asgi_application()
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
"""
Django settings for django_hello_world project.

Generated by 'django-admin startproject' using Django 5.1.2.

For more information on this file, see
https://docs.djangoproject.com/en/5.1/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/5.1/ref/settings/
"""

from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-#!kmjy@xy-q85-qbsheq1f)2je_)48uc+yodn=e0n*ku_22%4)'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'django_hello_world.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

WSGI_APPLICATION = 'django_hello_world.wsgi.application'


# Database
# https://docs.djangoproject.com/en/5.1/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}


# Password validation
# https://docs.djangoproject.com/en/5.1/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]


# Internationalization
# https://docs.djangoproject.com/en/5.1/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.1/howto/static-files/

STATIC_URL = 'static/'

# Default primary key field type
# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""
URL configuration for django_hello_world project.

The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/5.1/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path

urlpatterns = [
path('admin/', admin.site.urls),
]
Loading
Loading