From f71afd9178954c80c98c02ed0fde29b1720b67eb Mon Sep 17 00:00:00 2001 From: Liam Young Date: Mon, 14 Jan 2019 11:37:00 +0000 Subject: [PATCH] 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 --- charms_openstack/charm/classes.py | 10 ++++ .../charms_openstack/charm/test_classes.py | 46 +++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/charms_openstack/charm/classes.py b/charms_openstack/charm/classes.py index 79e5c55..7671071 100644 --- a/charms_openstack/charm/classes.py +++ b/charms_openstack/charm/classes.py @@ -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() diff --git a/unit_tests/charms_openstack/charm/test_classes.py b/unit_tests/charms_openstack/charm/test_classes.py index 9de8e22..65a8de6 100644 --- a/unit_tests/charms_openstack/charm/test_classes.py +++ b/unit_tests/charms_openstack/charm/test_classes.py @@ -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