diff --git a/scripts/build-lxd-image.sh b/scripts/build-lxd-image.sh index f4f8e1e02..96caed895 100644 --- a/scripts/build-lxd-image.sh +++ b/scripts/build-lxd-image.sh @@ -99,6 +99,13 @@ retry '/snap/bin/lxc exec builder -- /usr/bin/nslookup github.com' 'Wait for net /snap/bin/lxc exec builder --env DEBIAN_FRONTEND=noninteractive -- /usr/bin/apt-get install docker.io npm python3-pip shellcheck jq wget unzip gh -yq # Uninstall unattended-upgrades, to avoid lock errors when unattended-upgrades is active in the runner +/snap/bin/lxc exec builder --env DEBIAN_FRONTEND=noninteractive -- /usr/bin/systemctl stop apt-daily.timer +/snap/bin/lxc exec builder --env DEBIAN_FRONTEND=noninteractive -- /usr/bin/systemctl disable apt-daily.timer +/snap/bin/lxc exec builder --env DEBIAN_FRONTEND=noninteractive -- /usr/bin/systemctl mask apt-daily.service +/snap/bin/lxc exec builder --env DEBIAN_FRONTEND=noninteractive -- /usr/bin/systemctl stop apt-daily-upgrade.timer +/snap/bin/lxc exec builder --env DEBIAN_FRONTEND=noninteractive -- /usr/bin/systemctl disable apt-daily-upgrade.timer +/snap/bin/lxc exec builder --env DEBIAN_FRONTEND=noninteractive -- /usr/bin/systemctl mask apt-daily-upgrade.service +/snap/bin/lxc exec builder --env DEBIAN_FRONTEND=noninteractive -- /usr/bin/systemctl daemon-reload /snap/bin/lxc exec builder --env DEBIAN_FRONTEND=noninteractive -- /usr/bin/apt-get purge unattended-upgrades -yq if [[ -n "$HTTP_PROXY" ]]; then diff --git a/scripts/build-openstack-image.sh b/scripts/build-openstack-image.sh index 8b97486ca..d3e41b615 100755 --- a/scripts/build-openstack-image.sh +++ b/scripts/build-openstack-image.sh @@ -146,6 +146,13 @@ DEBIAN_FRONTEND=noninteractive /usr/bin/apt-get install docker.io npm python3-pi ln -s /usr/bin/python3 /usr/bin/python # Uninstall unattended-upgrades, to avoid lock errors when unattended-upgrades is active in the runner +DEBIAN_FRONTEND=noninteractive /usr/bin/systemctl stop apt-daily.timer +DEBIAN_FRONTEND=noninteractive /usr/bin/systemctl disable apt-daily.timer +DEBIAN_FRONTEND=noninteractive /usr/bin/systemctl mask apt-daily.service +DEBIAN_FRONTEND=noninteractive /usr/bin/systemctl stop apt-daily-upgrade.timer +DEBIAN_FRONTEND=noninteractive /usr/bin/systemctl disable apt-daily-upgrade.timer +DEBIAN_FRONTEND=noninteractive /usr/bin/systemctl mask apt-daily-upgrade.service +DEBIAN_FRONTEND=noninteractive /usr/bin/systemctl daemon-reload DEBIAN_FRONTEND=noninteractive /usr/bin/apt-get purge unattended-upgrades -yq /usr/sbin/useradd -m ubuntu diff --git a/tests/integration/helpers.py b/tests/integration/helpers.py index b8dd5b93f..aca334a72 100644 --- a/tests/integration/helpers.py +++ b/tests/integration/helpers.py @@ -424,51 +424,6 @@ def get_workflow_runs( yield run -async def _wait_until_runner_is_used_up(runner_name: str, unit: Unit): - """Wait until the runner is used up. - - Args: - runner_name: The runner name to wait for. - unit: The unit which contains the runner. - """ - for _ in range(30): - runners = await get_runner_names(unit) - if runner_name not in runners: - break - await sleep(30) - else: - assert False, "Timeout while waiting for the runner to be used up" - - -async def _assert_workflow_run_conclusion( - runner_name: str, conclusion: str, workflow: Workflow, start_time: datetime -): - """Assert that the workflow run has the expected conclusion. - - Args: - runner_name: The runner name to assert the workflow run conclusion for. - conclusion: The expected workflow run conclusion. - workflow: The workflow to assert the workflow run conclusion for. - start_time: The start time of the workflow. - """ - log_found = False - for run in workflow.get_runs(created=f">={start_time.isoformat()}"): - latest_job: WorkflowJob = run.jobs()[0] - logs = get_job_logs(job=latest_job) - - if runner_name in logs: - log_found = True - assert latest_job.conclusion == conclusion, ( - f"Job {latest_job.name} for {runner_name} expected {conclusion}, " - f"got {latest_job.conclusion}" - ) - - assert log_found, ( - f"No run with runner({runner_name}) log found for workflow({workflow.name}) " - f"starting from {start_time} with conclusion {conclusion}" - ) - - def _get_latest_run( workflow: Workflow, start_time: datetime, branch: Branch | None = None ) -> WorkflowRun | None: diff --git a/tests/integration/test_charm_one_runner.py b/tests/integration/test_charm_one_runner.py index 5f1dab570..eb305b25d 100644 --- a/tests/integration/test_charm_one_runner.py +++ b/tests/integration/test_charm_one_runner.py @@ -255,6 +255,28 @@ async def test_runner_labels( assert found, "Runner with testing label not found." +async def test_disabled_apt_daily_upgrades(model: Model, app: Application) -> None: + """ + arrange: Given a github runner running on lxd image. + act: When the runner is spawned. + assert: No apt related background services are running. + """ + await model.wait_for_idle() + unit = app.units[0] + await wait_till_num_of_runners(unit, num=1) + names = await get_runner_names(unit) + assert names, "LXD runners not ready" + + ret_code, stdout = await run_in_lxd_instance( + unit, names[0], "sudo systemctl list-units --no-pager" + ) + assert ret_code == 0, "Failed to list systemd units" + assert stdout, "No units listed in stdout" + + assert "apt-daily" not in stdout # this also checks for apt-daily-upgrade service + assert "unattended-upgrades" not in stdout + + async def test_token_config_changed_insufficient_perms( model: Model, app: Application, token: str ) -> None: