Support for an additional PPA for Cinder plugins

Cinder storage plugins may involve vendor drivers which live
outside of the cinder tree. To support these add a default
install handler that checks for an additional source and adds it
if found.

Change-Id: Ic3ddf5542fbb9c5f4246f478a8b80d1927d16966
This commit is contained in:
Liam Young 2019-01-14 11:37:00 +00:00
parent d658c0974c
commit f71afd9178
2 changed files with 56 additions and 0 deletions

View File

@ -876,6 +876,16 @@ class CinderStoragePluginCharm(OpenStackCharm):
# first_release = this is the first release in which this charm works
release = ''
def install(self):
"""Install PPA if one has been defined."""
if self.config.get('driver-source'):
fetch.add_source(
self.config.get('driver-source'),
key=self.config.get('driver-key'))
fetch.apt_update()
super().install()
self.assess_status()
@property
def stateless(self):
raise NotImplementedError()

View File

@ -1029,6 +1029,52 @@ class TestCinderStoragePluginCharm(BaseOpenStackCharmTest):
chm.CinderStoragePluginCharm,
TEST_CONFIG)
def test_install(self):
self.patch_object(chm.subprocess, 'check_output', return_value=b'\n')
self.patch_object(chm_core.charmhelpers.fetch, 'add_source')
self.patch_object(chm_core.charmhelpers.fetch, 'apt_update')
self.patch_target('config', new={'driver-source': 'ppa:user/ppa'})
self.target.install()
self.add_source.assert_called_once_with('ppa:user/ppa', key=None)
self.apt_update.assert_called_once_with()
def test_install_with_key(self):
self.patch_object(chm.subprocess, 'check_output', return_value=b'\n')
self.patch_object(chm_core.charmhelpers.fetch, 'add_source')
self.patch_object(chm_core.charmhelpers.fetch, 'apt_update')
self.patch_target(
'config',
new={
'driver-source': 'ppa:user/ppa',
'driver-key': 'mykey'})
self.target.install()
self.add_source.assert_called_once_with('ppa:user/ppa', key='mykey')
self.apt_update.assert_called_once_with()
def test_install_no_additional_source(self):
self.patch_object(chm.subprocess, 'check_output', return_value=b'\n')
self.patch_object(chm_core.charmhelpers.fetch, 'add_source')
self.patch_object(chm_core.charmhelpers.fetch, 'apt_update')
self.patch_target(
'config',
new={
'driver-source': '',
'driver-key': ''})
self.target.install()
self.assertFalse(self.add_source.called)
self.assertFalse(self.apt_update.called)
def test_install_source_undefined(self):
# A charm may be based from this class but not implement the
# additonal ppa option.
self.patch_object(chm.subprocess, 'check_output', return_value=b'\n')
self.patch_object(chm_core.charmhelpers.fetch, 'add_source')
self.patch_object(chm_core.charmhelpers.fetch, 'apt_update')
self.patch_target('config', new={})
self.target.install()
self.assertFalse(self.add_source.called)
self.assertFalse(self.apt_update.called)
def test_stateless(self):
with self.assertRaises(NotImplementedError):
self.target.stateless