Skip to content

Commit

Permalink
Merge branch 'main' into snapshot/using-hard-link
Browse files Browse the repository at this point in the history
  • Loading branch information
rgildein committed Jan 10, 2024
2 parents 61a8acf + ba80a6e commit ce760f8
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ jobs:
python-version-func: "3.10"
tox-version: "<4"
juju-channel: "3.1/stable"
commands: "['FUNC_ARGS=\"--series bionic\" make functional', 'FUNC_ARGS=\"--series focal\" make functional', 'FUNC_ARGS=\"--series jammy\" make functional']"
commands: "['FUNC_ARGS=\"--series focal\" make functional', 'FUNC_ARGS=\"--series jammy\" make functional']"
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ The charm can be deployed using `Juju`:
juju deploy apt-mirror
```

The charm can handle arbitrary set of upstream DEB sources via setting `mirror-list`. Example below shows a bundle with this charm configured to mirror multiple Ubuntu series (Bionic and Focal) in a single repository and expose this repository via NGINX. Additionally PPAs and external repositories can be mirrored.
The charm can handle arbitrary set of upstream DEB sources via setting `mirror-list`. Example below shows a bundle with this charm configured to mirror multiple Ubuntu series (Focal and Jammy) in a single repository and expose this repository via NGINX. Additionally PPAs and external repositories can be mirrored.
```
series: bionic
series: jammy
machines:
'0':
series: bionic
series: jammy
services:
nginx:
charm: nginx
Expand All @@ -34,14 +34,14 @@ services:
num_units: 1
options:
mirror-list: |-
deb http://archive.ubuntu.com/ubuntu bionic main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu bionic-updates main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu bionic-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu bionic-security main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu focal main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu focal-updates main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu focal-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu focal-security main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu jammy main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu jammy-updates main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu jammy-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu jammy-security main restricted universe multiverse
to:
- '0'
relations:
Expand Down
4 changes: 0 additions & 4 deletions charmcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,3 @@ bases:
channel: "20.04"
architectures:
- amd64
- name: ubuntu
channel: "18.04"
architectures:
- amd64
2 changes: 1 addition & 1 deletion config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
options:
mirror-list:
default: |-
deb http://archive.ubuntu.com/ubuntu bionic main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu jammy main restricted universe multiverse
description: A list of repositories to mirror.
type: string
base-path:
Expand Down
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
# remain compatible with bionic
ops < 2.0
ops
jinja2
74 changes: 54 additions & 20 deletions tests/functional/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,16 +290,16 @@ async def test_unreferenced_packages_config_changed(

# Start with 2 mirror lists.
mirror_list = """\
deb https://ppa.launchpadcontent.net/canonical-bootstack/public/ubuntu focal main
deb http://ppa.launchpad.net/landscape/19.10/ubuntu bionic main\
deb https://ppa.launchpadcontent.net/canonical-bootstack/public/ubuntu jammy main
deb http://ppa.launchpad.net/landscape/self-hosted-23.10/ubuntu jammy main\
"""
await apt_mirror_app.set_config({"mirror-list": mirror_list})
await ops_test.model.wait_for_idle(apps=["apt-mirror"])
await apt_mirror_unit.run_action("synchronize")

# End up with 1 mirror lists.
mirror_list = """\
deb https://ppa.launchpadcontent.net/canonical-bootstack/public/ubuntu focal main
deb https://ppa.launchpadcontent.net/canonical-bootstack/public/ubuntu jammy main
"""
await apt_mirror_app.set_config({"mirror-list": mirror_list})
await ops_test.model.wait_for_idle(apps=["apt-mirror"])
Expand Down Expand Up @@ -328,7 +328,7 @@ async def test_unreferenced_packages_config_changed_snapshoted(
# Start with 2 mirror lists.
mirror_list = """\
deb https://ppa.launchpadcontent.net/canonical-bootstack/public/ubuntu focal main
deb http://ppa.launchpad.net/landscape/19.10/ubuntu bionic main\
deb http://ppa.launchpad.net/landscape/self-hosted-23.10/ubuntu jammy main\
"""
await apt_mirror_app.set_config({"mirror-list": mirror_list})
await ops_test.model.wait_for_idle(apps=["apt-mirror"])
Expand All @@ -343,9 +343,22 @@ async def test_unreferenced_packages_config_changed_snapshoted(
"""
await apt_mirror_app.set_config({"mirror-list": mirror_list})
await ops_test.model.wait_for_idle(apps=["apt-mirror"])
results = await helper.run_action_wait(apt_mirror_unit, "synchronize")
_, changed_packages = re.findall(r"-?\d+\.?\d*", results.get("message"))
assert int(changed_packages) > 0
await apt_mirror_unit.run_action("synchronize")

# Even though we end up with only 1 mirror list, but since we created
# a snapshot before changing mirror list, we should still have
# references to the packages in the snapshot, thus there should be no
# packages to be removed.
results = await helper.run_action_wait(apt_mirror_unit, "check-packages")
count = int(results.get("count"))
assert count == 0

# Let's try to delete the snapshot and check if there are
# still some unreferenced packages remain.
await apt_mirror_unit.run("rm -rf {}/snapshot-*".format(base_path))
results = await helper.run_action_wait(apt_mirror_unit, "check-packages")
count = int(results.get("count"))
assert count > 0

async def test_outdated_packages_version_changed(
self, ops_test, apt_mirror_app, apt_mirror_unit, base_path, helper
Expand Down Expand Up @@ -394,10 +407,8 @@ async def test_outdated_packages_distro_changed(
"""Test removing outdated packages.
Test outdated packages are removed when a distro is upgraded, when no
indices are not requiring them.
The `synchronized` action will automatically cleaned up all outdated packages,
so the check-packages action should return empty list always.
indices are not requiring them. Also, test the outdated packages are
not removed when the index of the old distro is kept in the snapshot.
"""
# Clean up
await apt_mirror_unit.run("rm -rf {}/mirror/*".format(base_path))
Expand All @@ -410,23 +421,46 @@ async def test_outdated_packages_distro_changed(
"""
await apt_mirror_app.set_config({"mirror-list": mirror_list})
await ops_test.model.wait_for_idle(apps=["apt-mirror"])
results = await helper.run_action_wait(apt_mirror_unit, "synchronize")
assert results.get("message") == "Freed up 0.0 bytes by cleaning 0 packages"
await apt_mirror_unit.run_action("synchronize")

await helper.run_action_wait(apt_mirror_unit, "create-snapshot")
# Upgrade the distro to Jammy
mirror_list = """\
deb https://ppa.launchpadcontent.net/canonical-bootstack/public/ubuntu jammy main
"""
await apt_mirror_app.set_config({"mirror-list": mirror_list})
await ops_test.model.wait_for_idle(apps=["apt-mirror"])
await apt_mirror_unit.run_action("synchronize")

# Upgrade the distro to jammy
# Make sure we don't find outdated packages because they should be
# removed during synchronization.
results = await helper.run_action_wait(apt_mirror_unit, "check-packages")
count = int(results.get("count"))
assert count == 0

# Let's switch back to Focal and create a snapshot before switching to
# Jammy.
mirror_list = """\
deb https://ppa.launchpadcontent.net/canonical-bootstack/public/ubuntu focal main
"""
await apt_mirror_app.set_config({"mirror-list": mirror_list})
await ops_test.model.wait_for_idle(apps=["apt-mirror"])
await apt_mirror_unit.run_action("synchronize")
await helper.run_action_wait(apt_mirror_unit, "create-snapshot")
mirror_list = """\
deb https://ppa.launchpadcontent.net/canonical-bootstack/public/ubuntu jammy main
"""
await apt_mirror_app.set_config({"mirror-list": mirror_list})
await ops_test.model.wait_for_idle(apps=["apt-mirror"])
results = await helper.run_action_wait(apt_mirror_unit, "synchronize")
_, changed_packages = re.findall(r"-?\d+\.?\d*", results.get("message"))
assert int(changed_packages) > 0
await apt_mirror_unit.run_action("synchronize")

# The `synchronize` action should clean up also the mirror, so the
# `check-packages` action should not find any package to clean up.
# This time we should not find any "outdated" packages because they are
# still required in the snapshot.
results = await helper.run_action_wait(apt_mirror_unit, "check-packages")
count = int(results.get("count"))
assert count == 0

# Remove the snapshot, and we should find the "outdated" packages
await apt_mirror_unit.run("rm -rf {}/snapshot-*".format(base_path))
results = await helper.run_action_wait(apt_mirror_unit, "check-packages")
count = int(results.get("count"))
assert count > 0
2 changes: 1 addition & 1 deletion tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def test_cron_schedule_remove(self, mock_open_call, os_path_exists, os_unlink):
@patch("charm.open", new_callable=mock_open)
def test_apt_mirror_list(self, mocked_open):
url = "http://archive.ubuntu.com/ubuntu"
opts = "bionic main restricted universe multiverse"
opts = "jammy main restricted universe multiverse"
self.harness.update_config({"mirror-list": "deb {} {}".format(url, opts)})
mocked_open.assert_called_with(Path("/etc/apt/mirror.list"), "wb")
mocked_open().write.assert_called_once_with(
Expand Down

0 comments on commit ce760f8

Please sign in to comment.