Skip to content

Commit

Permalink
Use sudo rather than sg on ubuntu-24.04 runners (#140)
Browse files Browse the repository at this point in the history
* Use sudo rather than sg on ubuntu-24.04 runners
* Test on focal, jammy, and noble
* Improve mocked websocket failure
  • Loading branch information
addyess committed Sep 24, 2024
1 parent f8ab499 commit 2ea3e38
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
name: Lint Unit
uses: charmed-kubernetes/workflows/.github/workflows/lint-unit.yaml@main
with:
python: "['3.8', '3.9', '3.10', '3.11']"
python: "['3.8', '3.9', '3.10', '3.11', '3.12']"
needs:
- call-inclusive-naming-check

Expand Down Expand Up @@ -60,10 +60,11 @@ jobs:

integration-test:
name: Integration test with juju
runs-on: ubuntu-22.04
runs-on: ubuntu-${{ matrix.ubuntu }}
timeout-minutes: 40
strategy:
matrix:
ubuntu: ['20.04', '22.04', '24.04']
juju: ['3.1', '3']
steps:
- name: Check out code
Expand Down
7 changes: 4 additions & 3 deletions pytest_operator/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,6 @@ async def build_charm(
cmd = ["charm", "build", "--charm-file"]
else:
# Handle newer, operator framework charms.
all_groups = {g.gr_name for g in grp.getgrall()}
users_groups = {grp.getgrgid(g).gr_name for g in os.getgroups()}
cmd = ["charmcraft", "pack"]
if bases_index is not None:
Expand All @@ -1117,12 +1116,14 @@ async def build_charm(
cmd.append("--destructive-mode")
elif "lxd" not in users_groups:
# building with lxd builder and user does't already have lxd group;
# make sure it's available and if so, try using `sg` to acquire it
# try to build with sudo -u <user> -E charmcraft pack

all_groups = {g.gr_name for g in grp.getgrall()}
assert "lxd" in all_groups, (
"Group 'lxd' required but not available; "
"ensure that lxd is available or use --destructive-mode"
)
cmd = ["sg", "lxd", "-c", " ".join(cmd)]
cmd = ["sudo", "-g", "lxd", "-E", *cmd]

log.info(f"Building charm {charm_name}")
start = timer()
Expand Down
5 changes: 3 additions & 2 deletions tests/unit/test_pytest_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ async def test_destructive_mode(monkeypatch, tmp_path_factory):
# We didn't actually build it
assert str(e).startswith("Failed to build charm")
assert mock_run.called
assert mock_run.call_args[0] == ("sg", "lxd", "-c", "charmcraft pack")
assert mock_run.call_args[0] == ("sudo", "-g", "lxd", "-E", "charmcraft", "pack")

mock_getgroups.return_value = [ANY]
try:
Expand Down Expand Up @@ -644,7 +644,8 @@ async def test_fixture_set_up_automatic_model(
@pytest.mark.parametrize("model_name", [None, "alt-model"])
@pytest.mark.parametrize("cloud_name", [None, "alt-cloud"])
@pytest.mark.parametrize(
"block_exception", [None, asyncio.TimeoutError(), ConnectionClosed(1, "test")]
"block_exception",
[None, asyncio.TimeoutError(), ConnectionClosed(1, "test", False)],
)
@patch("pytest_operator.plugin.OpsTest.juju", autospec=True)
async def test_fixture_create_remove_model(
Expand Down

0 comments on commit 2ea3e38

Please sign in to comment.