Add fall back for retrofit series
Default is to use most recent LTS. If no value is configured and the charm is not able to find the most recent LTS image in Glance it will attempt to find a image matching the series of the unit the charm is run on. Change-Id: I5143372712d2cd6c37bfffae8aac519a88732659 Closes-Bug: #1878144
This commit is contained in:
parent
fb3c4593fc
commit
4dfbf7fdea
|
@ -6,7 +6,10 @@ options:
|
|||
Ubuntu series (eg. 'bionic') to look for in Glance to use as base
|
||||
for the retrofitting process.
|
||||
.
|
||||
Default is to use most recent LTS.
|
||||
Default is to use most recent LTS. If no value is configured and the
|
||||
charm is not able to find the most recent LTS image in Glance it will
|
||||
attempt to find a image matching the series of the unit the charm is run
|
||||
on.
|
||||
retrofit-uca-pocket:
|
||||
type: string
|
||||
default:
|
||||
|
|
|
@ -96,11 +96,27 @@ class OctaviaDiskimageRetrofitCharm(charms_openstack.charm.OpenStackCharm):
|
|||
if image_id:
|
||||
source_image = next(glance.images.list(filters={'id': image_id}))
|
||||
else:
|
||||
source_image = glance_retrofitter.find_source_image(
|
||||
glance,
|
||||
release=ubuntu_release)
|
||||
if not source_image:
|
||||
raise SourceImageNotFound('unable to find suitable source image')
|
||||
source_image = None
|
||||
if not self.config['retrofit-series']:
|
||||
# When no specifc series is configured we fall back to looking
|
||||
# for an image with series matching the series of the unit the
|
||||
# charm runs on if most recent LTS image is not available
|
||||
candidate_releases = (
|
||||
ubuntu_release,
|
||||
self.get_ubuntu_release(
|
||||
series=ch_core.host.get_distrib_codename()))
|
||||
else:
|
||||
candidate_releases = (ubuntu_release,)
|
||||
for release in candidate_releases:
|
||||
source_image = glance_retrofitter.find_source_image(
|
||||
glance,
|
||||
release=release)
|
||||
if source_image:
|
||||
ubuntu_release = release
|
||||
break
|
||||
else:
|
||||
raise SourceImageNotFound(
|
||||
'unable to find suitable source image')
|
||||
|
||||
if not image_id:
|
||||
for image in glance_retrofitter.find_destination_image(
|
||||
|
|
|
@ -34,6 +34,8 @@ applications:
|
|||
num_units: 1
|
||||
options:
|
||||
openstack-origin: cloud:bionic-ussuri/proposed
|
||||
# NOTE(fnordahl): We deliberately do not include Focal here to confirm that
|
||||
# the charm defaults work.
|
||||
glance-simplestreams-sync:
|
||||
charm: cs:~openstack-charmers-next/glance-simplestreams-sync
|
||||
num_units: 1
|
||||
|
@ -60,9 +62,8 @@ applications:
|
|||
'ftype~(disk1.img|disk.img)'
|
||||
]
|
||||
}]"
|
||||
# NOTE(fnordahl): We deliberately do not include retrofit-series and uca
|
||||
# pocket configuration options here to confirm that the charm defaults work.
|
||||
octavia-diskimage-retrofit:
|
||||
series: bionic
|
||||
charm: ../../../octavia-diskimage-retrofit
|
||||
options:
|
||||
retrofit-series: bionic
|
||||
retrofit-uca-pocket: ussuri-proposed
|
||||
|
|
|
@ -116,6 +116,9 @@ class TestOctaviaDiskimageRetrofitCharm(test_utils.PatchHelper):
|
|||
self.patch_target('get_ubuntu_release')
|
||||
self.get_ubuntu_release.side_effect = lambda series: (
|
||||
'20.04' if series == 'focal' else '18.04')
|
||||
self.patch_object(octavia_diskimage_retrofit.ch_core.host,
|
||||
'get_distrib_codename')
|
||||
self.get_distrib_codename.return_value = 'charm-unit-distro'
|
||||
with mock.patch('charm.openstack.octavia_diskimage_retrofit.open',
|
||||
create=True) as mocked_open:
|
||||
self.glance_retrofitter.find_destination_image.return_value = \
|
||||
|
@ -126,6 +129,11 @@ class TestOctaviaDiskimageRetrofitCharm(test_utils.PatchHelper):
|
|||
_fsi_mock = self.glance_retrofitter.find_source_image
|
||||
_fsi_mock.assert_called_once_with(
|
||||
mock.ANY, release='20.04')
|
||||
self.get_ubuntu_release.assert_has_calls([
|
||||
mock.call(series=''),
|
||||
mock.call(series='charm-unit-distro'),
|
||||
])
|
||||
self.get_ubuntu_release.reset_mock()
|
||||
self.config.__getitem__ = lambda _, key: {
|
||||
'debug': True,
|
||||
'retrofit-series': 'bionic',
|
||||
|
@ -137,11 +145,12 @@ class TestOctaviaDiskimageRetrofitCharm(test_utils.PatchHelper):
|
|||
assert_called_once_with('aKeystone')
|
||||
self.glance_retrofitter.get_glance_client.assert_called_once_with(
|
||||
self.glance_retrofitter.session_from_identity_credentials())
|
||||
|
||||
self.glance_retrofitter.find_destination_image.return_value = \
|
||||
[]
|
||||
self.hookenv.env_proxy_settings.return_value = proxy_envvars
|
||||
self.target.retrofit('aKeystone')
|
||||
self.get_ubuntu_release.assert_called_once_with(series='bionic')
|
||||
|
||||
self.glance_retrofitter.find_source_image.assert_called_once_with(
|
||||
mock.ANY, release='18.04')
|
||||
self.NamedTemporaryFile.assert_has_calls([
|
||||
|
|
Loading…
Reference in New Issue