diff --git a/charmcraft/application/commands/init.py b/charmcraft/application/commands/init.py index c6c39650c..dcce13e21 100644 --- a/charmcraft/application/commands/init.py +++ b/charmcraft/application/commands/init.py @@ -83,15 +83,8 @@ ├── tests │ ├── integration │ │ └── test_charm.py - Integration tests - │ ├── spread - │ │ ├── lib - │ │ │ └── test-helpers.sh - │ │ └── general - │ │ └── integration - │ │ └── task.yaml - Run integration tests in spread back-end │ └── unit │ └── test_charm.py - Unit tests - ├── spread.yaml - Spread testing configuration file └── tox.ini - Configuration for tox, the tool to run all tests You will need to edit at least charmcraft.yaml and README.md. diff --git a/charmcraft/templates/init-kubernetes/spread.yaml.j2 b/charmcraft/templates/init-kubernetes/spread.yaml.j2 deleted file mode 100644 index a92e0e55b..000000000 --- a/charmcraft/templates/init-kubernetes/spread.yaml.j2 +++ /dev/null @@ -1,158 +0,0 @@ -project: {{ name }}-k8s-tests - -environment: - PROVIDER: microk8s - CHARMCRAFT_CHANNEL: latest/stable - JUJU_CHANNEL: 3/stable - LXD_CHANNEL: latest/stable - MICROK8S_CHANNEL: 1.28-strict/stable - MICROK8S_ADDONS: hostpath-storage - - 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 - -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-24.04: - username: spread - password: spread - workers: 1 - - - 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 - ADDRESS localhost:22 - - discard: | - echo "Discarding ad-hoc $SPREAD_SYSTEM" - - systems: - - ubuntu-22.04-amd64: - username: ubuntu - password: ubuntu - workers: 1 - - -suites: - tests/spread/general/: - summary: Charm functionality tests - - systems: - - ubuntu-22.04* - - ubuntu-24.04* - - environment: - CHARMCRAFT_CHANNEL/charmcraft_current: latest/stable - # CHARMCRAFT_CHANNEL/charmcraft_next: latest/candidate - - prepare: | - set -e - . "$CRAFT_TEST_LIB_PATH"/test-helpers.sh - apt update -y - apt install -y python3-pip - pip3 install tox - - install_lxd - install_charmcraft - 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_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 diff --git a/charmcraft/templates/init-kubernetes/tests/spread/general/integration/task.yaml.j2 b/charmcraft/templates/init-kubernetes/tests/spread/general/integration/task.yaml.j2 deleted file mode 100644 index 8440186b5..000000000 --- a/charmcraft/templates/init-kubernetes/tests/spread/general/integration/task.yaml.j2 +++ /dev/null @@ -1,4 +0,0 @@ -summary: Run the charm integration test - -execute: | - tox -e integration diff --git a/charmcraft/templates/init-kubernetes/tests/spread/lib/cloud-config.yaml.j2 b/charmcraft/templates/init-kubernetes/tests/spread/lib/cloud-config.yaml.j2 deleted file mode 100644 index 29618c66b..000000000 --- a/charmcraft/templates/init-kubernetes/tests/spread/lib/cloud-config.yaml.j2 +++ /dev/null @@ -1,10 +0,0 @@ -#cloud-config - -ssh_pwauth: true - -users: - - default - - name: spread - plain_text_passwd: spread - lock_passwd: false - sudo: ALL=(ALL) NOPASSWD:ALL diff --git a/charmcraft/templates/init-kubernetes/tests/spread/lib/test-helpers.sh.j2 b/charmcraft/templates/init-kubernetes/tests/spread/lib/test-helpers.sh.j2 deleted file mode 100644 index 544ac30c7..000000000 --- a/charmcraft/templates/init-kubernetes/tests/spread/lib/test-helpers.sh.j2 +++ /dev/null @@ -1,86 +0,0 @@ - -export PATH=/snap/bin:$PROJECT_PATH/tests/spread/lib/tools:$PATH -export CONTROLLER_NAME="craft-test-$PROVIDER" - - -install_lxd() { - snap install lxd --channel "$LXD_CHANNEL" - snap refresh lxd --channel "$LXD_CHANNEL" - lxd waitready - lxd init --auto - chmod a+wr /var/snap/lxd/common/lxd/unix.socket - lxc network set lxdbr0 ipv6.address none - usermod -a -G lxd "$USER" - - # Work-around clash between docker and lxd on jammy - # https://github.com/docker/for-linux/issues/1034 - iptables -F FORWARD - iptables -P FORWARD ACCEPT -} - - -install_microk8s() { - snap install microk8s --channel "$MICROK8S_CHANNEL" - snap refresh microk8s --channel "$MICROK8S_CHANNEL" - microk8s status --wait-ready - - if [ ! -z "$MICROK8S_ADDONS" ]; then - microk8s enable $MICROK8S_ADDONS - fi - - local version=$(snap list microk8s | grep microk8s | awk '{ print $2 }') - - # workarounds for https://bugs.launchpad.net/juju/+bug/1937282 - retry microk8s kubectl -n kube-system rollout status deployment/coredns - retry microk8s kubectl -n kube-system rollout status deployment/hostpath-provisioner - - retry microk8s kubectl auth can-i create pods -} - - -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_microk8s() { - snap stop microk8s - snap remove --purge microk8s -} - - -restore_juju() { - 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 -} diff --git a/charmcraft/templates/init-kubernetes/tests/spread/lib/tools/retry.j2 b/charmcraft/templates/init-kubernetes/tests/spread/lib/tools/retry.j2 deleted file mode 100755 index 233ad372a..000000000 --- a/charmcraft/templates/init-kubernetes/tests/spread/lib/tools/retry.j2 +++ /dev/null @@ -1,158 +0,0 @@ -#!/usr/bin/env python3 - -from __future__ import annotations - -import argparse -import itertools -import os -import subprocess -import sys -import time - - -def envpair(s: str) -> str: - if not "=" in s: - raise argparse.ArgumentTypeError( - "environment variables expected format is 'KEY=VAL' got '{}'".format(s) - ) - return s - - -def _make_parser() -> argparse.ArgumentParser: - parser = argparse.ArgumentParser( - description=""" -Retry executes COMMAND at most N times, waiting for SECONDS between each -attempt. On failure the exit code from the final attempt is returned. -""" - ) - parser.add_argument( - "-n", - "--attempts", - metavar="N", - type=int, - default=10, - help="number of attempts (default %(default)s)", - ) - parser.add_argument( - "--wait", - metavar="SECONDS", - type=float, - default=5, - help="grace period between attempts (default %(default)ss)", - ) - parser.add_argument( - "--env", - type=envpair, - metavar="KEY=VAL", - action="append", - default=[], - help="environment variable to use with format KEY=VALUE (no default)", - ) - parser.add_argument( - "--maxmins", - metavar="MINUTES", - type=float, - default=0, - help="number of minutes after which to give up (no default, if set attempts is ignored)", - ) - parser.add_argument( - "--expect-rc", - metavar="RETCODE", - type=int, - default=0, - help="the expected return code to consider the command execution successful (default 0)", - ) - parser.add_argument( - "--quiet", - dest="verbose", - action="store_false", - default=True, - help="refrain from printing any output", - ) - parser.add_argument("cmd", metavar="COMMAND", nargs="...", help="command to execute") - return parser - - -def get_env(env: list[str]) -> dict[str, str]: - new_env = os.environ.copy() - maxsplit = 1 # no keyword support for str.split() in py2 - for key, val in [s.split("=", maxsplit) for s in env]: - new_env[key] = val - return new_env - - -def run_cmd( - cmd: list[str], - n: int, - wait: float, - maxmins: float, - verbose: bool, - env: list[str], - expect_rc: bool, -) -> int: - if maxmins != 0: - attempts = itertools.count(1) - t0 = time.time() - after = "{} minutes".format(maxmins) - of_attempts_suffix = "" - else: - attempts = range(1, n + 1) - after = "{} attempts".format(n) - of_attempts_suffix = " of {}".format(n) - retcode = 0 - i = 0 - new_env = get_env(env) - for i in attempts: - retcode = subprocess.call(cmd, env=new_env) - if retcode == expect_rc: - return 0 - if verbose: - print( - f"retry: command {' '.join(cmd)} unexpected code {retcode}", - file=sys.stderr, - ) - if maxmins != 0: - elapsed = (time.time() - t0) / 60 - if elapsed > maxmins: - break - if i < n or maxmins != 0: - if verbose: - print( - f"retry: next attempt in {wait} second(s) (attempt {i}{of_attempts_suffix})", - file=sys.stderr, - ) - time.sleep(wait) - - if verbose and i > 1: - print( - f"retry: command {' '.join(cmd)} keeps failing after {after}", - file=sys.stderr, - ) - return retcode - - -def main() -> None: - parser = _make_parser() - ns = parser.parse_args() - # The command cannot be empty but it is difficult to express in argparse itself. - if len(ns.cmd) == 0: - parser.print_usage() - parser.exit(0) - # Return the last exit code as the exit code of this process. - try: - retcode = run_cmd( - ns.cmd, ns.attempts, ns.wait, ns.maxmins, ns.verbose, ns.env, ns.expect_rc - ) - except OSError as exc: - if ns.verbose: - print( - "retry: cannot execute command {}: {}".format(" ".join(ns.cmd), exc), - file=sys.stderr, - ) - raise SystemExit(1) - else: - raise SystemExit(retcode) - - -if __name__ == "__main__": - main() diff --git a/charmcraft/templates/init-machine/spread.yaml.j2 b/charmcraft/templates/init-machine/spread.yaml.j2 deleted file mode 100644 index 0f6f91651..000000000 --- a/charmcraft/templates/init-machine/spread.yaml.j2 +++ /dev/null @@ -1,153 +0,0 @@ -project: {{ name }}-tests - -environment: - PROVIDER: lxd - CHARMCRAFT_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 - 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 - -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-24.04: - username: spread - password: spread - workers: 1 - - - 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 - ADDRESS localhost:22 - - discard: | - echo "Discarding ad-hoc $SPREAD_SYSTEM" - - systems: - - ubuntu-22.04-amd64: - username: ubuntu - password: ubuntu - workers: 1 - - -suites: - tests/spread/general/: - summary: Charm functionality tests - - systems: - - ubuntu-22.04* - - ubuntu-24.04* - - environment: - CHARMCRAFT_CHANNEL/charmcraft_current: latest/stable - # CHARMCRAFT_CHANNEL/charmcraft_next: latest/candidate - - prepare: | - set -e - . "$CRAFT_TEST_LIB_PATH"/test-helpers.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"/test-helpers.sh - rm -f "$PROJECT_PATH"/*.charm - charmcraft clean -p "$PROJECT_PATH" - - restore_juju - restore_charmcraft - 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 diff --git a/charmcraft/templates/init-machine/tests/spread/general/integration/task.yaml.j2 b/charmcraft/templates/init-machine/tests/spread/general/integration/task.yaml.j2 deleted file mode 100644 index 8440186b5..000000000 --- a/charmcraft/templates/init-machine/tests/spread/general/integration/task.yaml.j2 +++ /dev/null @@ -1,4 +0,0 @@ -summary: Run the charm integration test - -execute: | - tox -e integration diff --git a/charmcraft/templates/init-machine/tests/spread/lib/cloud-config.yaml.j2 b/charmcraft/templates/init-machine/tests/spread/lib/cloud-config.yaml.j2 deleted file mode 100644 index 29618c66b..000000000 --- a/charmcraft/templates/init-machine/tests/spread/lib/cloud-config.yaml.j2 +++ /dev/null @@ -1,10 +0,0 @@ -#cloud-config - -ssh_pwauth: true - -users: - - default - - name: spread - plain_text_passwd: spread - lock_passwd: false - sudo: ALL=(ALL) NOPASSWD:ALL diff --git a/charmcraft/templates/init-machine/tests/spread/lib/test-helpers.sh.j2 b/charmcraft/templates/init-machine/tests/spread/lib/test-helpers.sh.j2 deleted file mode 100644 index 7999346cd..000000000 --- a/charmcraft/templates/init-machine/tests/spread/lib/test-helpers.sh.j2 +++ /dev/null @@ -1,61 +0,0 @@ - -export PATH=/snap/bin:$PROJECT_PATH/tests/spread/lib/tools:$PATH -export CONTROLLER_NAME="craft-test-$PROVIDER" - - -install_lxd() { - snap install lxd --channel "$LXD_CHANNEL" - snap refresh lxd --channel "$LXD_CHANNEL" - lxd waitready - lxd init --auto - chmod a+wr /var/snap/lxd/common/lxd/unix.socket - lxc network set lxdbr0 ipv6.address none - usermod -a -G lxd "$USER" - - # Work-around clash between docker and lxd on jammy - # https://github.com/docker/for-linux/issues/1034 - iptables -F FORWARD - iptables -P FORWARD ACCEPT -} - - -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 \ - --destroy-storage --destroy-all-models "$CONTROLLER_NAME" - snap stop juju - snap remove --purge juju - snap remove --purge juju-crashdump -} diff --git a/charmcraft/templates/init-simple/spread.yaml.j2 b/charmcraft/templates/init-simple/spread.yaml.j2 deleted file mode 100644 index 4e94625b8..000000000 --- a/charmcraft/templates/init-simple/spread.yaml.j2 +++ /dev/null @@ -1,158 +0,0 @@ -project: {{ name }}-k8s-tests - -environment: - PROVIDER: microk8s - CHARMCRAFT_CHANNEL: latest/stable - JUJU_CHANNEL: 3/stable - LXD_CHANNEL: latest/stable - MICROK8S_CHANNEL: 1.28-strict/stable - MICROK8S_ADDONS: hostpath-storage - - 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 - -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-24.04: - username: spread - password: spread - workers: 1 - - - 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 - ADDRESS localhost:22 - - discard: | - echo "Discarding ad-hoc $SPREAD_SYSTEM" - - systems: - - ubuntu-22.04-amd64: - username: ubuntu - password: ubuntu - workers: 1 - - -suites: - tests/spread/general/: - summary: Charm functionality tests - - systems: - - ubuntu-24.04* - - ubuntu-22.04* - - environment: - CHARMCRAFT_CHANNEL/charmcraft_current: latest/stable - # CHARMCRAFT_CHANNEL/charmcraft_next: latest/candidate - - prepare: | - set -e - . "$CRAFT_TEST_LIB_PATH"/test-helpers.sh - apt update -y - apt install -y python3-pip - pip3 install tox - - install_lxd - install_charmcraft - 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_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 diff --git a/charmcraft/templates/init-simple/tests/spread/general/integration/task.yaml.j2 b/charmcraft/templates/init-simple/tests/spread/general/integration/task.yaml.j2 deleted file mode 100644 index 8440186b5..000000000 --- a/charmcraft/templates/init-simple/tests/spread/general/integration/task.yaml.j2 +++ /dev/null @@ -1,4 +0,0 @@ -summary: Run the charm integration test - -execute: | - tox -e integration diff --git a/charmcraft/templates/init-simple/tests/spread/lib/cloud-config.yaml.j2 b/charmcraft/templates/init-simple/tests/spread/lib/cloud-config.yaml.j2 deleted file mode 100644 index 29618c66b..000000000 --- a/charmcraft/templates/init-simple/tests/spread/lib/cloud-config.yaml.j2 +++ /dev/null @@ -1,10 +0,0 @@ -#cloud-config - -ssh_pwauth: true - -users: - - default - - name: spread - plain_text_passwd: spread - lock_passwd: false - sudo: ALL=(ALL) NOPASSWD:ALL diff --git a/charmcraft/templates/init-simple/tests/spread/lib/test-helpers.sh.j2 b/charmcraft/templates/init-simple/tests/spread/lib/test-helpers.sh.j2 deleted file mode 100644 index 544ac30c7..000000000 --- a/charmcraft/templates/init-simple/tests/spread/lib/test-helpers.sh.j2 +++ /dev/null @@ -1,86 +0,0 @@ - -export PATH=/snap/bin:$PROJECT_PATH/tests/spread/lib/tools:$PATH -export CONTROLLER_NAME="craft-test-$PROVIDER" - - -install_lxd() { - snap install lxd --channel "$LXD_CHANNEL" - snap refresh lxd --channel "$LXD_CHANNEL" - lxd waitready - lxd init --auto - chmod a+wr /var/snap/lxd/common/lxd/unix.socket - lxc network set lxdbr0 ipv6.address none - usermod -a -G lxd "$USER" - - # Work-around clash between docker and lxd on jammy - # https://github.com/docker/for-linux/issues/1034 - iptables -F FORWARD - iptables -P FORWARD ACCEPT -} - - -install_microk8s() { - snap install microk8s --channel "$MICROK8S_CHANNEL" - snap refresh microk8s --channel "$MICROK8S_CHANNEL" - microk8s status --wait-ready - - if [ ! -z "$MICROK8S_ADDONS" ]; then - microk8s enable $MICROK8S_ADDONS - fi - - local version=$(snap list microk8s | grep microk8s | awk '{ print $2 }') - - # workarounds for https://bugs.launchpad.net/juju/+bug/1937282 - retry microk8s kubectl -n kube-system rollout status deployment/coredns - retry microk8s kubectl -n kube-system rollout status deployment/hostpath-provisioner - - retry microk8s kubectl auth can-i create pods -} - - -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_microk8s() { - snap stop microk8s - snap remove --purge microk8s -} - - -restore_juju() { - 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 -} diff --git a/charmcraft/templates/init-simple/tests/spread/lib/tools/retry.j2 b/charmcraft/templates/init-simple/tests/spread/lib/tools/retry.j2 deleted file mode 120000 index 7777b7ab7..000000000 --- a/charmcraft/templates/init-simple/tests/spread/lib/tools/retry.j2 +++ /dev/null @@ -1 +0,0 @@ -../../../../../init-kubernetes/tests/spread/lib/tools/retry.j2 \ No newline at end of file diff --git a/docs/reference/changelog.rst b/docs/reference/changelog.rst index 6089bbcce..a5cb79654 100644 --- a/docs/reference/changelog.rst +++ b/docs/reference/changelog.rst @@ -77,6 +77,17 @@ Changelog For a complete list of commits, see the `X.Y.Z`_ release on GitHub. +3.3.2 (2025-01027) +------------------ + +This release contains some bug fixes for the 3.3 branch. + +Command line +============ + +This release removes experimental test templates added to the project when +running ``charmcraft init``. Existing projects will not be affected. + 3.3.1 (2025-01-23) ------------------ diff --git a/tests/integration/commands/test_init.py b/tests/integration/commands/test_init.py index 3248e5358..776dcb03a 100644 --- a/tests/integration/commands/test_init.py +++ b/tests/integration/commands/test_init.py @@ -56,33 +56,6 @@ "tox.ini", ) ) -BASIC_INIT_FILES_WITH_SPREAD = frozenset( - list(BASIC_INIT_FILES) - + [ - pathlib.Path(p) - for p in ( - "spread.yaml", - "tests/spread", - "tests/spread/lib", - "tests/spread/lib/cloud-config.yaml", - "tests/spread/lib/test-helpers.sh", - "tests/spread/general", - "tests/spread/general/integration", - "tests/spread/general/integration/task.yaml", - ) - ] -) -BASIC_INIT_FILES_WITH_TOOLS = frozenset( - list(BASIC_INIT_FILES_WITH_SPREAD) - + [ - pathlib.Path(p) - for p in ( - "tests/spread/lib", - "tests/spread/lib/tools", - "tests/spread/lib/tools/retry", - ) - ] -) UNKNOWN_AUTHOR_REGEX = re.compile( r"^Unable to automatically determine author's name, specify it with --author$" ) @@ -125,9 +98,9 @@ def create_namespace( @pytest.mark.parametrize( ("profile", "expected_files"), [ - pytest.param("simple", BASIC_INIT_FILES_WITH_TOOLS, id="simple"), - pytest.param("machine", BASIC_INIT_FILES_WITH_SPREAD, id="machine"), - pytest.param("kubernetes", BASIC_INIT_FILES_WITH_TOOLS, id="kubernetes"), + pytest.param("simple", BASIC_INIT_FILES, id="simple"), + pytest.param("machine", BASIC_INIT_FILES, id="machine"), + pytest.param("kubernetes", BASIC_INIT_FILES, id="kubernetes"), ], ) @pytest.mark.parametrize("charm_name", ["my-charm", "charm123"]) @@ -240,7 +213,7 @@ def test_gecos_user_has_no_name(monkeypatch, new_path, init_command): ), ], ) -@pytest.mark.parametrize("expected_files", [BASIC_INIT_FILES_WITH_TOOLS]) +@pytest.mark.parametrize("expected_files", [BASIC_INIT_FILES]) def test_create_directory(new_path, init_command, subdir, expected_files): init_dir = new_path / subdir