Skip to content

Commit

Permalink
Merge pull request #806 from mkalcok/xena-backport-ovn-uca-pocket
Browse files Browse the repository at this point in the history
[stable/xena] Add support for OVN UCA pocket
  • Loading branch information
fnordahl authored Jun 29, 2023
2 parents 905164c + 860f26b commit 04767dd
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
15 changes: 13 additions & 2 deletions charmhelpers/fetch/ubuntu.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@
'yoga/proposed': 'focal-proposed/yoga',
'focal-yoga/proposed': 'focal-proposed/yoga',
'focal-proposed/yoga': 'focal-proposed/yoga',

# OVN
'focal-ovn-22.03': 'focal-updates/ovn-22.03',
'focal-ovn-22.03/proposed': 'focal-proposed/ovn-22.03',
}


Expand Down Expand Up @@ -683,6 +687,7 @@ def add_source(source, key=None, fail_invalid=False):
(r"^cloud-archive:(.*)$", _add_apt_repository),
(r"^((?:deb |http:|https:|ppa:).*)$", _add_apt_repository),
(r"^cloud:(.*)-(.*)\/staging$", _add_cloud_staging),
(r"^cloud:(.*)-(ovn-.*)$", _add_cloud_distro_check),
(r"^cloud:(.*)-(.*)$", _add_cloud_distro_check),
(r"^cloud:(.*)$", _add_cloud_pocket),
(r"^snap:.*-(.*)-(.*)$", _add_cloud_distro_check),
Expand Down Expand Up @@ -746,6 +751,11 @@ def _add_apt_repository(spec):
)


def __write_sources_list_d_actual_pocket(file, actual_pocket):
with open('/etc/apt/sources.list.d/{}'.format(file), 'w') as apt:
apt.write(CLOUD_ARCHIVE.format(actual_pocket))


def _add_cloud_pocket(pocket):
"""Add a cloud pocket as /etc/apt/sources.d/cloud-archive.list
Expand All @@ -765,8 +775,9 @@ def _add_cloud_pocket(pocket):
'Unsupported cloud: source option %s' %
pocket)
actual_pocket = CLOUD_ARCHIVE_POCKETS[pocket]
with open('/etc/apt/sources.list.d/cloud-archive.list', 'w') as apt:
apt.write(CLOUD_ARCHIVE.format(actual_pocket))
__write_sources_list_d_actual_pocket(
'cloud-archive{}.list'.format('' if 'ovn' not in pocket else '-ovn'),
actual_pocket)


def _add_cloud_staging(cloud_archive_release, openstack_release):
Expand Down
34 changes: 34 additions & 0 deletions tests/fetch/test_fetch_ubuntu.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,8 @@ def test_add_source_cloud_pocket_style(self, get_distrib_codename,
with patch_open() as (mock_open, mock_file):
fetch.add_source(source=source)
mock_file.write.assert_called_with(result)
mock_open.assert_called_once_with(
'/etc/apt/sources.list.d/cloud-archive.list', 'w')
filter_pkg.assert_called_with(['ubuntu-cloud-keyring'])

@patch('charmhelpers.fetch.ubuntu.log')
Expand All @@ -547,6 +549,8 @@ def test_add_source_cloud_os_style(self, get_distrib_codename, apt_install,
with patch_open() as (mock_open, mock_file):
fetch.add_source(source=source)
mock_file.write.assert_called_with(result)
mock_open.assert_called_once_with(
'/etc/apt/sources.list.d/cloud-archive.list', 'w')
filter_pkg.assert_called_with(['ubuntu-cloud-keyring'])

@patch('charmhelpers.fetch.ubuntu.log')
Expand All @@ -561,6 +565,8 @@ def test_add_source_cloud_distroless_style(self, apt_install,
with patch_open() as (mock_open, mock_file):
fetch.add_source(source=source)
mock_file.write.assert_called_with(result)
mock_open.assert_called_once_with(
'/etc/apt/sources.list.d/cloud-archive.list', 'w')
filter_pkg.assert_called_with(['ubuntu-cloud-keyring'])

@patch('charmhelpers.fetch.ubuntu.log')
Expand Down Expand Up @@ -666,6 +672,34 @@ def check_output_side_effect(command, env):
env=None),
])

@patch('charmhelpers.fetch.ubuntu.log')
@patch.object(fetch, 'filter_installed_packages')
@patch.object(fetch, 'apt_install')
@patch.object(fetch, 'get_distrib_codename')
def test_add_source_cloud_ovn(self, get_distrib_codename, apt_install,
filter_pkg, log):
source = "cloud:focal-ovn-22.03"
get_distrib_codename.return_value = 'focal'
result = ('# Ubuntu Cloud Archive\n'
'deb http://ubuntu-cloud.archive.canonical.com/ubuntu'
' focal-updates/ovn-22.03 main\n')
with patch_open() as (mock_open, mock_file):
fetch.add_source(source=source)
mock_file.write.assert_called_with(result)
mock_open.assert_called_once_with(
'/etc/apt/sources.list.d/cloud-archive-ovn.list', 'w')
filter_pkg.assert_called_with(['ubuntu-cloud-keyring'])

source = "cloud:focal-ovn-22.03/proposed"
result = ('# Ubuntu Cloud Archive\n'
'deb http://ubuntu-cloud.archive.canonical.com/ubuntu'
' focal-proposed/ovn-22.03 main\n')
with patch_open() as (mock_open, mock_file):
fetch.add_source(source=source)
mock_file.write.assert_called_with(result)
mock_open.assert_called_once_with(
'/etc/apt/sources.list.d/cloud-archive-ovn.list', 'w')

@patch('charmhelpers.fetch.ubuntu.log')
def test_configure_bad_install_source(self, log):
try:
Expand Down

0 comments on commit 04767dd

Please sign in to comment.