Allow specifying config key in call to configure_source
A charm may be in need of adding multiple sources (for example vendor specific PPAs), and it would be useful if the ``configure_source`` method would allow to do this. In such a use case overriding the ``source_config_key`` class variable would not be practical, so we allow to optionally specify it as a argument to the method. Change-Id: Ia5a8f05e863251520771a1c01a5f7dddf4be34d0 Closes-Bug: #1876720
This commit is contained in:
parent
f9bd43ff5d
commit
21da52526c
|
@ -657,16 +657,19 @@ class BaseOpenStackCharmActions(object):
|
|||
hookenv.status_set('maintenance',
|
||||
'Installation complete - awaiting next status')
|
||||
|
||||
def configure_source(self):
|
||||
"""Configure installation source using the config item
|
||||
indicated in the source_config_key class variable
|
||||
(default: 'openstack-origin')
|
||||
def configure_source(self, config_key=None):
|
||||
"""Configure installation source.
|
||||
|
||||
This configures the installation source for deb packages and then
|
||||
updates the packages list on the unit.
|
||||
:param config_key: Config item (default: value indicated in the
|
||||
source_config_key class variable)
|
||||
:type config_key: Optional[str]
|
||||
|
||||
This adds an installation source for deb packages and then updates the
|
||||
packages list on the unit.
|
||||
"""
|
||||
config_key = config_key or self.source_config_key
|
||||
source, key = os_utils.get_source_and_pgp_key(
|
||||
self.config[self.source_config_key])
|
||||
self.config[config_key])
|
||||
fetch.add_source(source, key)
|
||||
fetch.apt_update(fatal=True)
|
||||
|
||||
|
|
|
@ -101,11 +101,18 @@ class TestOpenStackCharm(BaseOpenStackCharmTest):
|
|||
self.patch_object(chm_core.charmhelpers.fetch, 'add_source')
|
||||
self.patch_object(chm_core.charmhelpers.fetch, 'apt_update')
|
||||
self.patch_object(chm_core.os_utils, 'get_source_and_pgp_key')
|
||||
self.patch_target('config', new={'openstack-origin': 'an-origin'})
|
||||
self.patch_target('config', new={
|
||||
'openstack-origin': 'an-origin',
|
||||
'some-other-key': 'another-origin',
|
||||
})
|
||||
self.get_source_and_pgp_key.return_value = ("an-origin", None)
|
||||
self.target.configure_source()
|
||||
self.add_source.assert_called_once_with('an-origin', None)
|
||||
self.apt_update.assert_called_once_with(fatal=True)
|
||||
self.get_source_and_pgp_key.reset_mock()
|
||||
self.get_source_and_pgp_key.return_value = ('another-origin', None)
|
||||
self.target.configure_source('some-other-key')
|
||||
self.get_source_and_pgp_key.assert_called_once_with('another-origin')
|
||||
|
||||
def test_region(self):
|
||||
self.patch_target('config', new={'region': 'a-region'})
|
||||
|
|
Loading…
Reference in New Issue