Skip to content

Commit

Permalink
Use sudo rather than sg on ubuntu-24.04 runners
Browse files Browse the repository at this point in the history
  • Loading branch information
addyess committed Sep 24, 2024
1 parent f8ab499 commit 422e220
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
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
2 changes: 1 addition & 1 deletion 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

0 comments on commit 422e220

Please sign in to comment.