[gnuoy, r=james-page]

Allow a subordinate to request a metadata proxy without setting a shared secret
This commit is contained in:
Liam Young 2016-01-15 14:13:25 +00:00
commit 7747f7f997
2 changed files with 37 additions and 4 deletions

View File

@ -19,7 +19,9 @@ from charmhelpers.core.host import (
restart_on_change,
service_restart,
)
from charmhelpers.core.strutils import (
bool_from_string,
)
from charmhelpers.fetch import (
apt_install,
apt_purge,
@ -391,9 +393,14 @@ def neutron_plugin_joined(relid=None):
@restart_on_change(restart_map())
def neutron_plugin_changed():
settings = relation_get()
if 'metadata-shared-secret' in settings:
if settings.get('enable-metadata'):
enable_metadata = bool_from_string(settings['enable-metadata'])
else:
enable_metadata = False
if 'metadata-shared-secret' in settings or enable_metadata:
apt_update()
apt_install('nova-api-metadata', fatal=True)
apt_install(filter_installed_packages(['nova-api-metadata']),
fatal=True)
else:
apt_purge('nova-api-metadata', fatal=True)
CONFIGS.write(NOVA_CONF)

View File

@ -25,6 +25,7 @@ TO_PATCH = [
'unit_get',
# charmhelpers.core.host
'apt_install',
'apt_purge',
'apt_update',
'filter_installed_packages',
'restart_on_change',
@ -490,5 +491,30 @@ class NovaComputeRelationsTests(CharmTestCase):
'sharedsecret'}
hooks.neutron_plugin_changed()
self.assertTrue(self.apt_update.called)
self.apt_install.assert_called_with('nova-api-metadata', fatal=True)
self.apt_install.assert_called_with(['nova-api-metadata'],
fatal=True)
configs.write.assert_called_with('/etc/nova/nova.conf')
@patch.object(hooks, 'CONFIGS')
def test_neutron_plugin_changed_nometa_implicit(self, configs):
self.relation_get.return_value = {}
hooks.neutron_plugin_changed()
self.apt_purge.assert_called_with('nova-api-metadata',
fatal=True)
configs.write.assert_called_with('/etc/nova/nova.conf')
@patch.object(hooks, 'CONFIGS')
def test_neutron_plugin_changed_meta(self, configs):
self.relation_get.return_value = {'enable-metadata': 'True'}
hooks.neutron_plugin_changed()
self.apt_install.assert_called_with(['nova-api-metadata'],
fatal=True)
configs.write.assert_called_with('/etc/nova/nova.conf')
@patch.object(hooks, 'CONFIGS')
def test_neutron_plugin_changed_nometa_explicit(self, configs):
self.relation_get.return_value = {'enable-metadata': 'false'}
hooks.neutron_plugin_changed()
self.apt_purge.assert_called_with('nova-api-metadata',
fatal=True)
configs.write.assert_called_with('/etc/nova/nova.conf')