Conditionally make neutron-plugin relations required
When charm is not managing the plugin the neutron-plugin-* relations should be required. Change-Id: I8c061f272e68b05b6d415e0686564bd7f617aa12changes/70/706670/2
parent
38117ba022
commit
4ac5e3f71c
|
@ -696,7 +696,7 @@ class EtcdContext(context.OSContextGenerator):
|
|||
|
||||
|
||||
class NeutronApiSDNContext(context.SubordinateConfigContext):
|
||||
interfaces = 'neutron-plugin-api-subordinate'
|
||||
interfaces = ['neutron-plugin-api-subordinate']
|
||||
|
||||
def __init__(self, config_file='/etc/neutron/neutron.conf'):
|
||||
"""Initialize context for plugin subordinates.
|
||||
|
@ -807,7 +807,10 @@ class NeutronApiSDNContext(context.SubordinateConfigContext):
|
|||
# Do not set empty values
|
||||
pass
|
||||
return ctxt
|
||||
return ctxt
|
||||
# Return empty dict when there are no related units, this will flag the
|
||||
# context as incomplete and will allow end user messaging of missing
|
||||
# relations
|
||||
return {}
|
||||
|
||||
|
||||
class NeutronApiSDNConfigFileContext(context.OSContextGenerator):
|
||||
|
@ -820,7 +823,12 @@ class NeutronApiSDNConfigFileContext(context.OSContextGenerator):
|
|||
neutron_server_plugin_conf = rdata.get('neutron-plugin-config')
|
||||
if neutron_server_plugin_conf:
|
||||
return {'config': neutron_server_plugin_conf}
|
||||
return {'config': '/etc/neutron/plugins/ml2/ml2_conf.ini'}
|
||||
else:
|
||||
return {'config': '/etc/neutron/plugins/ml2/ml2_conf.ini'}
|
||||
# Return empty dict when there are no related units, this will flag the
|
||||
# context as incomplete and will allow end user messaging of missing
|
||||
# relations
|
||||
return {}
|
||||
|
||||
|
||||
class NeutronApiApiPasteContext(context.OSContextGenerator):
|
||||
|
|
|
@ -896,6 +896,11 @@ def get_optional_interfaces():
|
|||
optional_interfaces = {}
|
||||
if relation_ids('ha'):
|
||||
optional_interfaces['ha'] = ['cluster']
|
||||
if not manage_plugin():
|
||||
optional_interfaces['neutron-plugin'] = [
|
||||
'neutron-plugin-api',
|
||||
'neutron-plugin-api-subordinate',
|
||||
]
|
||||
return optional_interfaces
|
||||
|
||||
|
||||
|
|
|
@ -1204,7 +1204,7 @@ class NeutronApiSDNContextTest(CharmTestCase):
|
|||
def test_empty(self):
|
||||
self.ctxt_check(
|
||||
{},
|
||||
{'sections': {}},
|
||||
{},
|
||||
)
|
||||
|
||||
def test_is_allowed(self):
|
||||
|
@ -1235,12 +1235,18 @@ class NeutronApiSDNConfigFileContextTest(CharmTestCase):
|
|||
})
|
||||
|
||||
def test_default(self):
|
||||
self.relation_ids.return_value = []
|
||||
self.relation_ids.return_value = ['rid3']
|
||||
self.related_units.return_value = ['unit2']
|
||||
napisdn_ctxt = context.NeutronApiSDNConfigFileContext()()
|
||||
self.assertEqual(napisdn_ctxt, {
|
||||
'config': '/etc/neutron/plugins/ml2/ml2_conf.ini'
|
||||
})
|
||||
|
||||
def test_no_related_unites(self):
|
||||
self.relation_ids.return_value = ['rid4']
|
||||
napisdn_ctxt = context.NeutronApiSDNConfigFileContext()()
|
||||
self.assertEqual(napisdn_ctxt, {})
|
||||
|
||||
|
||||
class NeutronApiApiPasteContextTest(CharmTestCase):
|
||||
|
||||
|
|
|
@ -979,6 +979,25 @@ class TestNeutronAPIUtils(CharmTestCase):
|
|||
"?ssl_ca=foo&ssl_cert=bar&ssl_key=baz"
|
||||
)
|
||||
|
||||
@patch.object(nutils, 'manage_plugin')
|
||||
@patch.object(nutils, 'relation_ids')
|
||||
def test_get_optional_interfaces(self, mock_relation_ids,
|
||||
mock_manage_plugin):
|
||||
mock_relation_ids.return_value = False
|
||||
mock_manage_plugin.return_value = True
|
||||
self.assertDictEqual(nutils.get_optional_interfaces(), {})
|
||||
mock_relation_ids.assert_called_once_with('ha')
|
||||
mock_manage_plugin.assert_called_once_with()
|
||||
mock_relation_ids.return_value = True
|
||||
mock_manage_plugin.return_value = False
|
||||
self.assertDictEqual(nutils.get_optional_interfaces(), {
|
||||
'ha': ['cluster'],
|
||||
'neutron-plugin': [
|
||||
'neutron-plugin-api',
|
||||
'neutron-plugin-api-subordinate',
|
||||
],
|
||||
})
|
||||
|
||||
@patch.object(nutils, 'config')
|
||||
@patch.object(nutils, 'relation_ids')
|
||||
@patch.object(nutils, 'log')
|
||||
|
|
Loading…
Reference in New Issue