Skip to content

Commit

Permalink
feat(test): move spread test setup from task to suite
Browse files Browse the repository at this point in the history
Signed-off-by: Claudio Matsuoka <claudio.matsuoka@canonical.com>
  • Loading branch information
cmatsuoka committed Mar 22, 2024
1 parent 6f84191 commit 568ee53
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 61 deletions.
44 changes: 36 additions & 8 deletions charmcraft/templates/init-machine/spread.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ project: {{ name }}-tests

environment:
CHARMCRAFT_CHANNEL: latest/stable
JUJU_CHANNEL: latest/stable
JUJU_CHANNEL: 3/stable
LXD_CHANNEL: latest/stable

JUJU_BOOTSTRAP_OPTIONS: --model-default test-mode=true --model-default automatically-retry-hooks=false --model-default
Expand All @@ -17,7 +17,7 @@ environment:
LANGUAGE: "en"

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

backends:
multipass:
Expand Down Expand Up @@ -85,9 +85,40 @@ backends:


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

systems:
- ubuntu-22.04
- ubuntu-20.04

environment:
CHARMCRAFT_CHANNEL/charmcraft_current: latest/stable
CHARMCRAFT_CHANNEL/charmcraft_next: latest/candidate

prepare: |
set -e
. "$CRAFT_TEST_LIB_PATH"/funcs.sh
apt update -y
apt install -y python3-pip
pip3 install tox

install_lxd
install_charmcraft
install_juju
bootstrap_juju

juju add-model testing

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

restore_juju
restore_charmcraft
restore_lxd

exclude:
- .git
Expand All @@ -109,7 +140,4 @@ restore: |
mkdir -p "$PROJECT_PATH"


kill-timeout: 15m

workers: 1

kill-timeout: 1h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
summary: Run the charm integration test

execute: |
tox -e integration
32 changes: 30 additions & 2 deletions charmcraft/templates/init-machine/tests/spread/lib/funcs.sh.j2
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,43 @@ install_lxd() {
}


install_charmcraft() {
snap install charmcraft --classic --channel "$CHARMCRAFT_CHANNEL"
snap refresh charmcraft --classic --channel "$CHARMCRAFT_CHANNEL"
}


install_juju() {
snap install juju --classic --channel "$JUJU_CHANNEL"
snap refresh juju --classic --channel "$JUJU_CHANNEL"
mkdir -p "$HOME"/.local/share/juju
snap install juju-crashdump --classic
}


bootstrap_juju() {
juju bootstrap --verbose "$PROVIDER" "$CONTROLLER_NAME" \
$JUJU_BOOTSTRAP_OPTIONS $JUJU_EXTRA_BOOTSTRAP_OPTIONS \
--bootstrap-constraints=$JUJU_BOOTSTRAP_CONSTRAINTS
}


restore_charmcraft() {
snap remove --purge charmcraft
}


restore_lxd() {
snap stop lxd
snap remove --purge lxd
}


restore_juju() {
juju controllers --refresh ||:
juju destroy-controller -v --no-prompt --show-log \
juju controllers --refresh ||:
juju destroy-controller -v --no-prompt --show-log \
--destroy-storage --destroy-all-models "$CONTROLLER_NAME"
snap stop juju
snap remove --purge juju
snap remove --purge juju-crashdump
}

This file was deleted.

0 comments on commit 568ee53

Please sign in to comment.