From e9dc9be0049a3439282e0a8252f8a294b25cbce3 Mon Sep 17 00:00:00 2001 From: Tony Meyer Date: Mon, 26 Aug 2024 17:58:12 +1200 Subject: [PATCH 01/25] ci: run the smoke tests on a schedule. --- .github/workflows/smoke.yaml | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .github/workflows/smoke.yaml diff --git a/.github/workflows/smoke.yaml b/.github/workflows/smoke.yaml new file mode 100644 index 000000000..9b1cd7657 --- /dev/null +++ b/.github/workflows/smoke.yaml @@ -0,0 +1,36 @@ +name: ops Smoke Tests + +on: + workflow_dispatch: + schedule: + - cron: '0 7 25 * *' + +jobs: + test: + runs-on: ubuntu-latest + + strategy: + matrix: + juju-version: ['2.9', '3', '4.0'] + charmcraft-version: ['2.x', '3.x'] + + steps: + - name: Set up Juju + run: sudo snap install juju --channel=${{ matrix.juju-version }} + + - name: Set up LXD + uses: canonical/setup-lxd@ce8decb3609c0a03c5abd5034d02a6c145e2076f + with: + channel: 5.0/stable + + - name: Bootstrap Juju controller + run: juju bootstrap localhost + + - name: Install charmcraft + run: sudo snap install charmcraft --channel=${{ matrix.charmcraft-version }} + + - name: Install tox + run: pip install tox~=4.2 + + - name: Run smoke tests + run: tox -e smoke From 2244f830a0802cf5e125564abad07b111a476369 Mon Sep 17 00:00:00 2001 From: Tony Meyer Date: Mon, 26 Aug 2024 18:02:19 +1200 Subject: [PATCH 02/25] 2.9 needs to install with --classic. --- .github/workflows/smoke.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/smoke.yaml b/.github/workflows/smoke.yaml index 9b1cd7657..77ef7f4f1 100644 --- a/.github/workflows/smoke.yaml +++ b/.github/workflows/smoke.yaml @@ -11,7 +11,7 @@ jobs: strategy: matrix: - juju-version: ['2.9', '3', '4.0'] + juju-version: ['2.9 --classic', '3', '4.0'] charmcraft-version: ['2.x', '3.x'] steps: From 885c9da01b552b01d7bde9b98bd69fd6390876e2 Mon Sep 17 00:00:00 2001 From: Tony Meyer Date: Mon, 26 Aug 2024 18:05:27 +1200 Subject: [PATCH 03/25] 4.0 needs the beta label. --- .github/workflows/smoke.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/smoke.yaml b/.github/workflows/smoke.yaml index 77ef7f4f1..3b6145800 100644 --- a/.github/workflows/smoke.yaml +++ b/.github/workflows/smoke.yaml @@ -11,7 +11,7 @@ jobs: strategy: matrix: - juju-version: ['2.9 --classic', '3', '4.0'] + juju-version: ['2.9 --classic', '3', '4.0/beta'] charmcraft-version: ['2.x', '3.x'] steps: From ce9912f39d8fde379d2ec310c98a6ac577e1c1ae Mon Sep 17 00:00:00 2001 From: Tony Meyer Date: Mon, 26 Aug 2024 18:10:07 +1200 Subject: [PATCH 04/25] charmcraft needs --classic. --- .github/workflows/smoke.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/smoke.yaml b/.github/workflows/smoke.yaml index 3b6145800..b61f9ede2 100644 --- a/.github/workflows/smoke.yaml +++ b/.github/workflows/smoke.yaml @@ -27,7 +27,7 @@ jobs: run: juju bootstrap localhost - name: Install charmcraft - run: sudo snap install charmcraft --channel=${{ matrix.charmcraft-version }} + run: sudo snap install charmcraft --channel=${{ matrix.charmcraft-version }} --classic - name: Install tox run: pip install tox~=4.2 From 8fca48ea5c0c0f38aa62c299e0cbbdd84c8850fa Mon Sep 17 00:00:00 2001 From: Tony Meyer Date: Mon, 26 Aug 2024 18:14:13 +1200 Subject: [PATCH 05/25] Need the actual repo to run the tests :) --- .github/workflows/smoke.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/smoke.yaml b/.github/workflows/smoke.yaml index b61f9ede2..d861b58ba 100644 --- a/.github/workflows/smoke.yaml +++ b/.github/workflows/smoke.yaml @@ -29,6 +29,12 @@ jobs: - name: Install charmcraft run: sudo snap install charmcraft --channel=${{ matrix.charmcraft-version }} --classic + - name: Checkout the repository + uses: actions/checkout@v4 + + - name: Set up Python 3 + uses: actions/setup-python@v5 + - name: Install tox run: pip install tox~=4.2 From 05af3ffc3d1e9137b6d4989a31e82efe5b5f30d3 Mon Sep 17 00:00:00 2001 From: Tony Meyer Date: Mon, 26 Aug 2024 18:20:28 +1200 Subject: [PATCH 06/25] Test on lxd and microk8s. --- .github/workflows/smoke.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/smoke.yaml b/.github/workflows/smoke.yaml index d861b58ba..b7391f75d 100644 --- a/.github/workflows/smoke.yaml +++ b/.github/workflows/smoke.yaml @@ -13,16 +13,22 @@ jobs: matrix: juju-version: ['2.9 --classic', '3', '4.0/beta'] charmcraft-version: ['2.x', '3.x'] + cloud: ['lxd', 'microk8s'] steps: - name: Set up Juju run: sudo snap install juju --channel=${{ matrix.juju-version }} - name: Set up LXD + if: ${{ matrix.cloud }} == 'lxd' uses: canonical/setup-lxd@ce8decb3609c0a03c5abd5034d02a6c145e2076f with: channel: 5.0/stable + - name: Set up Microk8s + if: ${{ matrix.cloud }} == 'microk8s' + run: snap install microk8s + - name: Bootstrap Juju controller run: juju bootstrap localhost From 2f0d7565d02063e88f964bcc695ec1b073e38ac9 Mon Sep 17 00:00:00 2001 From: Tony Meyer Date: Mon, 26 Aug 2024 18:26:29 +1200 Subject: [PATCH 07/25] pylibjuju on 2.x and 4.x is complex, so just stick with Juju 3 for now. --- .github/workflows/smoke.yaml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/smoke.yaml b/.github/workflows/smoke.yaml index b7391f75d..c202b559d 100644 --- a/.github/workflows/smoke.yaml +++ b/.github/workflows/smoke.yaml @@ -11,7 +11,13 @@ jobs: strategy: matrix: - juju-version: ['2.9 --classic', '3', '4.0/beta'] + # pylibjuju does not currently support Juju 4.x + # TODO: we should run against 2.9, but that means installing pylibjuju + # "<3", and we need to do that inside the tox environment, so that's a + # bit more complex than having everything inside this workflow. + # Note that Juju 2.9 needs to be '2.9 --classic' because the snap is + # only available with classic confinement. + juju-version: ['3'] charmcraft-version: ['2.x', '3.x'] cloud: ['lxd', 'microk8s'] From c379ea43e8734da0e0025cab5971f9f09badde52 Mon Sep 17 00:00:00 2001 From: Tony Meyer Date: Mon, 26 Aug 2024 18:32:13 +1200 Subject: [PATCH 08/25] Use the tutorial instructions for setting up microk8s. --- .github/workflows/smoke.yaml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/smoke.yaml b/.github/workflows/smoke.yaml index c202b559d..2c1b7ac79 100644 --- a/.github/workflows/smoke.yaml +++ b/.github/workflows/smoke.yaml @@ -33,7 +33,13 @@ jobs: - name: Set up Microk8s if: ${{ matrix.cloud }} == 'microk8s' - run: snap install microk8s + run: | + sudo snap install microk8s + sudo adduser $USER snap_microk8s + sudo chown -f -R $USER ~/.kube + sudo microk8s status --wait-ready + sudo microk8s enable hostpath-storage dns + newgrp snap_microk8s - name: Bootstrap Juju controller run: juju bootstrap localhost From 7c686b7ecdbf299cd55a185c23d66c1d4f5664cd Mon Sep 17 00:00:00 2001 From: Tony Meyer Date: Mon, 26 Aug 2024 18:33:23 +1200 Subject: [PATCH 09/25] Set up the cloud before Juju. --- .github/workflows/smoke.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/smoke.yaml b/.github/workflows/smoke.yaml index 2c1b7ac79..d95634857 100644 --- a/.github/workflows/smoke.yaml +++ b/.github/workflows/smoke.yaml @@ -22,9 +22,6 @@ jobs: cloud: ['lxd', 'microk8s'] steps: - - name: Set up Juju - run: sudo snap install juju --channel=${{ matrix.juju-version }} - - name: Set up LXD if: ${{ matrix.cloud }} == 'lxd' uses: canonical/setup-lxd@ce8decb3609c0a03c5abd5034d02a6c145e2076f @@ -41,6 +38,9 @@ jobs: sudo microk8s enable hostpath-storage dns newgrp snap_microk8s + - name: Set up Juju + run: sudo snap install juju --channel=${{ matrix.juju-version }} + - name: Bootstrap Juju controller run: juju bootstrap localhost From 30640463fde2b6aae6f5b2691c56aef48b60318b Mon Sep 17 00:00:00 2001 From: Tony Meyer Date: Mon, 26 Aug 2024 18:34:44 +1200 Subject: [PATCH 10/25] microk8s needs --classic. --- .github/workflows/smoke.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/smoke.yaml b/.github/workflows/smoke.yaml index d95634857..be3449aee 100644 --- a/.github/workflows/smoke.yaml +++ b/.github/workflows/smoke.yaml @@ -31,7 +31,7 @@ jobs: - name: Set up Microk8s if: ${{ matrix.cloud }} == 'microk8s' run: | - sudo snap install microk8s + sudo snap install microk8s --classic sudo adduser $USER snap_microk8s sudo chown -f -R $USER ~/.kube sudo microk8s status --wait-ready From cced4e68d6edc673712c816c6d33848d67b64de3 Mon Sep 17 00:00:00 2001 From: Tony Meyer Date: Mon, 26 Aug 2024 18:37:37 +1200 Subject: [PATCH 11/25] Fix if statements. --- .github/workflows/smoke.yaml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/smoke.yaml b/.github/workflows/smoke.yaml index be3449aee..e710c0c9c 100644 --- a/.github/workflows/smoke.yaml +++ b/.github/workflows/smoke.yaml @@ -23,13 +23,13 @@ jobs: steps: - name: Set up LXD - if: ${{ matrix.cloud }} == 'lxd' + if: matrix.cloud == 'lxd' uses: canonical/setup-lxd@ce8decb3609c0a03c5abd5034d02a6c145e2076f with: channel: 5.0/stable - name: Set up Microk8s - if: ${{ matrix.cloud }} == 'microk8s' + if: matrix.cloud == 'microk8s' run: | sudo snap install microk8s --classic sudo adduser $USER snap_microk8s @@ -41,7 +41,12 @@ jobs: - name: Set up Juju run: sudo snap install juju --channel=${{ matrix.juju-version }} - - name: Bootstrap Juju controller + - name: Bootstrap Juju controller (k8s) + if: matrix.cloud == 'microk8s' + run: juju bootstrap localhost + + - name: Bootstrap Juju controller (lxd) + if: matrix.cloud == 'lxd' run: juju bootstrap localhost - name: Install charmcraft From 7573ca5af6e59aa0b9688b1e0fadac099e03f090 Mon Sep 17 00:00:00 2001 From: Tony Meyer Date: Mon, 26 Aug 2024 18:39:15 +1200 Subject: [PATCH 12/25] Maybe the group instructions are out of date? --- .github/workflows/smoke.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/smoke.yaml b/.github/workflows/smoke.yaml index e710c0c9c..bb8b06126 100644 --- a/.github/workflows/smoke.yaml +++ b/.github/workflows/smoke.yaml @@ -32,11 +32,9 @@ jobs: if: matrix.cloud == 'microk8s' run: | sudo snap install microk8s --classic - sudo adduser $USER snap_microk8s sudo chown -f -R $USER ~/.kube sudo microk8s status --wait-ready sudo microk8s enable hostpath-storage dns - newgrp snap_microk8s - name: Set up Juju run: sudo snap install juju --channel=${{ matrix.juju-version }} From 530553c6a8cb06dac4044405e7aa319b35ea833c Mon Sep 17 00:00:00 2001 From: Tony Meyer Date: Mon, 26 Aug 2024 18:42:59 +1200 Subject: [PATCH 13/25] Simplify the microk8s install. --- .github/workflows/smoke.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/smoke.yaml b/.github/workflows/smoke.yaml index bb8b06126..8cc5b8af7 100644 --- a/.github/workflows/smoke.yaml +++ b/.github/workflows/smoke.yaml @@ -32,7 +32,6 @@ jobs: if: matrix.cloud == 'microk8s' run: | sudo snap install microk8s --classic - sudo chown -f -R $USER ~/.kube sudo microk8s status --wait-ready sudo microk8s enable hostpath-storage dns From 78aea0d4bab60cb2fc3cabe94b5e6c9be188cbd5 Mon Sep 17 00:00:00 2001 From: Tony Meyer Date: Mon, 26 Aug 2024 18:45:30 +1200 Subject: [PATCH 14/25] Use a pre-packaged action to get microk8s. --- .github/workflows/smoke.yaml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/smoke.yaml b/.github/workflows/smoke.yaml index 8cc5b8af7..0b87ba144 100644 --- a/.github/workflows/smoke.yaml +++ b/.github/workflows/smoke.yaml @@ -30,10 +30,11 @@ jobs: - name: Set up Microk8s if: matrix.cloud == 'microk8s' - run: | - sudo snap install microk8s --classic - sudo microk8s status --wait-ready - sudo microk8s enable hostpath-storage dns + uses: balchua/microk8s-actions@v0.3.2 + with: + channel: '1.26-strict/stable' + devMode: 'true' + addons: '["dns", "hostpath-storage"]' - name: Set up Juju run: sudo snap install juju --channel=${{ matrix.juju-version }} From c4113ba43568f3d2f02e4f3737a1a45f2ad095d6 Mon Sep 17 00:00:00 2001 From: Tony Meyer Date: Mon, 26 Aug 2024 18:50:06 +1200 Subject: [PATCH 15/25] Fix the cloud name for k8s. --- .github/workflows/smoke.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/smoke.yaml b/.github/workflows/smoke.yaml index 0b87ba144..053da2c46 100644 --- a/.github/workflows/smoke.yaml +++ b/.github/workflows/smoke.yaml @@ -41,7 +41,7 @@ jobs: - name: Bootstrap Juju controller (k8s) if: matrix.cloud == 'microk8s' - run: juju bootstrap localhost + run: juju bootstrap microk8s - name: Bootstrap Juju controller (lxd) if: matrix.cloud == 'lxd' From aa1e0f6c484e1f3bcbf9f2932944f8a8634b09b2 Mon Sep 17 00:00:00 2001 From: Tony Meyer Date: Mon, 26 Aug 2024 21:07:54 +1200 Subject: [PATCH 16/25] Run tests as root (ugh). --- .github/workflows/smoke.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/smoke.yaml b/.github/workflows/smoke.yaml index 053da2c46..a53e98e87 100644 --- a/.github/workflows/smoke.yaml +++ b/.github/workflows/smoke.yaml @@ -60,4 +60,6 @@ jobs: run: pip install tox~=4.2 - name: Run smoke tests - run: tox -e smoke + # pytest-operator runs charmcraft pack with `sg lxd`, which seems to + # prompt for a password, so bypass that. + run: sudo tox -e smoke From 728789c5a5dae98c28eea90d3351a52267cfb0dc Mon Sep 17 00:00:00 2001 From: Tony Meyer Date: Mon, 26 Aug 2024 21:11:46 +1200 Subject: [PATCH 17/25] Install tox for root. --- .github/workflows/smoke.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/smoke.yaml b/.github/workflows/smoke.yaml index a53e98e87..7c5bb5ab7 100644 --- a/.github/workflows/smoke.yaml +++ b/.github/workflows/smoke.yaml @@ -57,7 +57,7 @@ jobs: uses: actions/setup-python@v5 - name: Install tox - run: pip install tox~=4.2 + run: sudo pip install tox~=4.2 - name: Run smoke tests # pytest-operator runs charmcraft pack with `sg lxd`, which seems to From ad6c711ce4f1996d7aa18886e0928196b1312ead Mon Sep 17 00:00:00 2001 From: Tony Meyer Date: Mon, 26 Aug 2024 21:15:58 +1200 Subject: [PATCH 18/25] Use sudo for bootstrapping k8s. --- .github/workflows/smoke.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/smoke.yaml b/.github/workflows/smoke.yaml index 7c5bb5ab7..60f30e9df 100644 --- a/.github/workflows/smoke.yaml +++ b/.github/workflows/smoke.yaml @@ -41,7 +41,7 @@ jobs: - name: Bootstrap Juju controller (k8s) if: matrix.cloud == 'microk8s' - run: juju bootstrap microk8s + run: sudo juju bootstrap microk8s - name: Bootstrap Juju controller (lxd) if: matrix.cloud == 'lxd' From ec417cac96f937b68ea849b93e4c484c0febf0eb Mon Sep 17 00:00:00 2001 From: Tony Meyer Date: Mon, 26 Aug 2024 21:16:13 +1200 Subject: [PATCH 19/25] Use sudo for bootstrapping k8s. --- .github/workflows/smoke.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/smoke.yaml b/.github/workflows/smoke.yaml index 60f30e9df..87ab6e582 100644 --- a/.github/workflows/smoke.yaml +++ b/.github/workflows/smoke.yaml @@ -41,6 +41,7 @@ jobs: - name: Bootstrap Juju controller (k8s) if: matrix.cloud == 'microk8s' + # TODO: instead of sudo, use `sg` to do this? `sudo usermod -a -G snap_microk8s runner` run: sudo juju bootstrap microk8s - name: Bootstrap Juju controller (lxd) From 5533145b5efa38989b182cd5153f81456e73e74e Mon Sep 17 00:00:00 2001 From: Tony Meyer Date: Mon, 26 Aug 2024 21:18:05 +1200 Subject: [PATCH 20/25] Try to get just k8s working. --- .github/workflows/smoke.yaml | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/.github/workflows/smoke.yaml b/.github/workflows/smoke.yaml index 87ab6e582..b2c0a64fa 100644 --- a/.github/workflows/smoke.yaml +++ b/.github/workflows/smoke.yaml @@ -19,7 +19,8 @@ jobs: # only available with classic confinement. juju-version: ['3'] charmcraft-version: ['2.x', '3.x'] - cloud: ['lxd', 'microk8s'] +# cloud: ['lxd', 'microk8s'] + cloud: ['microk8s'] steps: - name: Set up LXD @@ -41,8 +42,7 @@ jobs: - name: Bootstrap Juju controller (k8s) if: matrix.cloud == 'microk8s' - # TODO: instead of sudo, use `sg` to do this? `sudo usermod -a -G snap_microk8s runner` - run: sudo juju bootstrap microk8s + run: sg snap_microk8s -c 'juju bootstrap microk8s' - name: Bootstrap Juju controller (lxd) if: matrix.cloud == 'lxd' @@ -58,9 +58,7 @@ jobs: uses: actions/setup-python@v5 - name: Install tox - run: sudo pip install tox~=4.2 + run: pip install tox~=4.2 - name: Run smoke tests - # pytest-operator runs charmcraft pack with `sg lxd`, which seems to - # prompt for a password, so bypass that. - run: sudo tox -e smoke + run: tox -e smoke From e7291064a4ecd5b9710af8758267997f59c3b6e7 Mon Sep 17 00:00:00 2001 From: Tony Meyer Date: Mon, 26 Aug 2024 21:24:58 +1200 Subject: [PATCH 21/25] LXD is required for packing. --- .github/workflows/smoke.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/smoke.yaml b/.github/workflows/smoke.yaml index b2c0a64fa..e7f971030 100644 --- a/.github/workflows/smoke.yaml +++ b/.github/workflows/smoke.yaml @@ -23,8 +23,9 @@ jobs: cloud: ['microk8s'] steps: + # LXD is required for charmcraft to pack, even if it's not used as the + # Juju cloud. - name: Set up LXD - if: matrix.cloud == 'lxd' uses: canonical/setup-lxd@ce8decb3609c0a03c5abd5034d02a6c145e2076f with: channel: 5.0/stable From b57a376fd4d4b3ebf0e9e3853c7a0685b1d77fff Mon Sep 17 00:00:00 2001 From: Tony Meyer Date: Wed, 4 Sep 2024 20:22:25 +1200 Subject: [PATCH 22/25] Pack ourselves, to work around the permission issue (and does packing really belong in pytest-operator?). --- test/smoke/test_smoke.py | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/test/smoke/test_smoke.py b/test/smoke/test_smoke.py index acf049722..859d0f0fe 100644 --- a/test/smoke/test_smoke.py +++ b/test/smoke/test_smoke.py @@ -14,7 +14,11 @@ # # Learn more about testing at: https://juju.is/docs/sdk/testing +import grp import logging +import os +import pathlib +import subprocess import pytest from pytest_operator.plugin import OpsTest @@ -45,6 +49,33 @@ """ +def pack(charm_dir: pathlib.Path): + """Pack the charm. + + The pytest-operator plugin has a pack method, but it doesn't work out of the + box in GitHub actions, and there isn't really any reason that it should be + part of the plugin, so we just have a simple subprocess here. + """ + cmd = ['charmcraft', 'pack'] + # We need to use `sudo` in the GitHub actions environment, just as in + # the pack test. `sg lxd -c` should work, but does not - perhaps because of + # the way we are installing LXD? + if 'lxd' not in {grp.getgrgid(g).gr_name for g in os.getgroups()}: + cmd.insert(0, 'sudo') + + logger.info('Building charm with %r', cmd) + subprocess.run(cmd, cwd=charm_dir, check=True) + logger.info('Built charm') + + # Move the packed charm to the charm directory. + dest_name = None + for charm in charm_dir.glob('*.charm'): + dest_name = charm_dir / charm.name + charm.rename(dest_name) + # With the way we use charmcraft, we know that there will only be one. + return dest_name + + @pytest.mark.parametrize( 'base,charmcraft_version,name', ( @@ -61,7 +92,7 @@ async def test_smoke(ops_test: OpsTest, base: str, charmcraft_version: int, name }[charmcraft_version].format(base=base) with open('./test/charms/test_smoke/charmcraft.yaml', 'w') as outf: outf.write(charmcraft_yaml) - charm = await ops_test.build_charm('./test/charms/test_smoke/') + charm = pack(pathlib.Path('./test/charms/test_smoke/')) app = await ops_test.model.deploy( charm, base=f'ubuntu@{base}', application_name=f'{name}-smoke' From 7653ed46c5fe768272ce6afcc2bd90d3ea17aece Mon Sep 17 00:00:00 2001 From: Tony Meyer Date: Wed, 4 Sep 2024 20:42:49 +1200 Subject: [PATCH 23/25] The charm path needs to be absolute or Juju looks in the store. --- test/smoke/test_smoke.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/smoke/test_smoke.py b/test/smoke/test_smoke.py index 859d0f0fe..cfdd36226 100644 --- a/test/smoke/test_smoke.py +++ b/test/smoke/test_smoke.py @@ -73,7 +73,7 @@ def pack(charm_dir: pathlib.Path): dest_name = charm_dir / charm.name charm.rename(dest_name) # With the way we use charmcraft, we know that there will only be one. - return dest_name + return dest_name.absolute() @pytest.mark.parametrize( From 4b57fe7fadaf5a8d82e12302f3c3aa4297cad8e4 Mon Sep 17 00:00:00 2001 From: Tony Meyer Date: Wed, 4 Sep 2024 20:43:00 +1200 Subject: [PATCH 24/25] Try running against Juju 2 and 3. --- .github/workflows/smoke.yaml | 18 ++++++++++-------- tox.ini | 3 +++ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/.github/workflows/smoke.yaml b/.github/workflows/smoke.yaml index e7f971030..97bc7e3c7 100644 --- a/.github/workflows/smoke.yaml +++ b/.github/workflows/smoke.yaml @@ -12,15 +12,12 @@ jobs: strategy: matrix: # pylibjuju does not currently support Juju 4.x - # TODO: we should run against 2.9, but that means installing pylibjuju - # "<3", and we need to do that inside the tox environment, so that's a - # bit more complex than having everything inside this workflow. - # Note that Juju 2.9 needs to be '2.9 --classic' because the snap is - # only available with classic confinement. - juju-version: ['3'] + juju-version: ['2.9', '3.5'] charmcraft-version: ['2.x', '3.x'] -# cloud: ['lxd', 'microk8s'] - cloud: ['microk8s'] + cloud: ['lxd', 'microk8s'] + + env: + JUJU_VERSION: "${{ matrix.juju-version }}" steps: # LXD is required for charmcraft to pack, even if it's not used as the @@ -38,7 +35,12 @@ jobs: devMode: 'true' addons: '["dns", "hostpath-storage"]' + - name: Set up Juju (classic) + if: matrix.juju-version == '2.9' + run: sudo snap install juju --classic --channel=${{ matrix.juju-version }} + - name: Set up Juju + if: matrix.juju-version != '2.9' run: sudo snap install juju --channel=${{ matrix.juju-version }} - name: Bootstrap Juju controller (k8s) diff --git a/tox.ini b/tox.ini index cf097a12f..0e462abfb 100644 --- a/tox.ini +++ b/tox.ini @@ -136,6 +136,7 @@ description = Run a smoke test against a Juju controller. allowlist_externals = juju charmcraft bash +passenv = JUJU_VERSION deps = build coverage[toml]~=7.0 @@ -147,6 +148,8 @@ commands = python -m build --sdist --outdir={toxinidir}/test/charms/test_smoke/ # Inject the tarball into the smoke test charm's requirements. bash -c 'echo "./$(ls -1 ./test/charms/test_smoke/ | grep tar.gz)" > ./test/charms/test_smoke/requirements.txt' + # If a specific Juju version is set, then make sure we are using that version of pylibjuju. + bash -c 'if [ -n "$JUJU_VERSION" ]; then pip install "juju ~= $JUJU_VERSION"; fi' # Run our smoke tests (this will build the charm, then run the tests). pytest -v --tb native --log-cli-level=INFO -s {posargs} {toxinidir}/test/smoke/ From 49dccfd189c1d1429f667fe3c153bc1b853dbc6e Mon Sep 17 00:00:00 2001 From: Tony Meyer Date: Wed, 4 Sep 2024 21:04:28 +1200 Subject: [PATCH 25/25] Stick with Juju 3.5 for now. --- .github/workflows/smoke.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/smoke.yaml b/.github/workflows/smoke.yaml index 97bc7e3c7..c50fdd64b 100644 --- a/.github/workflows/smoke.yaml +++ b/.github/workflows/smoke.yaml @@ -12,7 +12,8 @@ jobs: strategy: matrix: # pylibjuju does not currently support Juju 4.x - juju-version: ['2.9', '3.5'] + # The smoke tests do not yet work on Juju 2.9. + juju-version: ['3.5'] charmcraft-version: ['2.x', '3.x'] cloud: ['lxd', 'microk8s']