Skip to content

Commit

Permalink
fix: apt related background service related errors (#246)
Browse files Browse the repository at this point in the history
* fix: apt background services

* chore: remove unused funcs

* fix: lint

* move test up
  • Loading branch information
yanksyoon authored Mar 25, 2024
1 parent edef10c commit 7aa4e5c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 45 deletions.
7 changes: 7 additions & 0 deletions scripts/build-lxd-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions scripts/build-openstack-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
45 changes: 0 additions & 45 deletions tests/integration/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
22 changes: 22 additions & 0 deletions tests/integration/test_charm_one_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 7aa4e5c

Please sign in to comment.