|
|
|
@ -1,7 +1,7 @@
|
|
|
|
|
from test_utils import CharmTestCase |
|
|
|
|
from mock import patch |
|
|
|
|
import neutron_api_context as context |
|
|
|
|
|
|
|
|
|
import charmhelpers |
|
|
|
|
TO_PATCH = [ |
|
|
|
|
'relation_get', |
|
|
|
|
'relation_ids', |
|
|
|
@ -10,6 +10,42 @@ TO_PATCH = [
|
|
|
|
|
] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class IdentityServiceContext(CharmTestCase): |
|
|
|
|
def setUp(self): |
|
|
|
|
super(IdentityServiceContext, self).setUp(context, TO_PATCH) |
|
|
|
|
self.relation_get.side_effect = self.test_relation.get |
|
|
|
|
self.config.side_effect = self.test_config.get |
|
|
|
|
self.test_config.set('region', 'region457') |
|
|
|
|
|
|
|
|
|
@patch.object(charmhelpers.contrib.openstack.context, 'context_complete') |
|
|
|
|
@patch.object(charmhelpers.contrib.openstack.context, 'relation_get') |
|
|
|
|
@patch.object(charmhelpers.contrib.openstack.context, 'related_units') |
|
|
|
|
@patch.object(charmhelpers.contrib.openstack.context, 'relation_ids') |
|
|
|
|
@patch.object(charmhelpers.contrib.openstack.context, 'log') |
|
|
|
|
def test_ids_ctxt(self, _log, _rids, _runits, _rget, _ctxt_comp): |
|
|
|
|
_rids.return_value = 'rid1' |
|
|
|
|
_runits.return_value = 'runit' |
|
|
|
|
_ctxt_comp.return_value = True |
|
|
|
|
id_data = { |
|
|
|
|
'service_port': 9876, |
|
|
|
|
'service_host': '127.0.0.4', |
|
|
|
|
'auth_host': '127.0.0.5', |
|
|
|
|
'auth_port': 5432, |
|
|
|
|
'service_tenant': 'ten', |
|
|
|
|
'service_username': 'admin', |
|
|
|
|
'service_password': 'adminpass', |
|
|
|
|
} |
|
|
|
|
_rget.return_value = id_data |
|
|
|
|
ids_ctxt = context.IdentityServiceContext() |
|
|
|
|
self.assertEquals(ids_ctxt()['region'], 'region457') |
|
|
|
|
|
|
|
|
|
@patch.object(charmhelpers.contrib.openstack.context, 'relation_ids') |
|
|
|
|
@patch.object(charmhelpers.contrib.openstack.context, 'log') |
|
|
|
|
def test_ids_ctxt_no_rels(self, _log, _rids): |
|
|
|
|
_rids.return_value = [] |
|
|
|
|
ids_ctxt = context.IdentityServiceContext() |
|
|
|
|
self.assertEquals(ids_ctxt(), None) |
|
|
|
|
|
|
|
|
|
class NeutronAPIContextsTest(CharmTestCase): |
|
|
|
|
|
|
|
|
|
def setUp(self): |
|
|
|
@ -27,7 +63,7 @@ class NeutronAPIContextsTest(CharmTestCase):
|
|
|
|
|
|
|
|
|
|
@patch.object(context.NeutronCCContext, 'network_manager') |
|
|
|
|
@patch.object(context.NeutronCCContext, 'plugin') |
|
|
|
|
def test_quantum_plugin_context_no_setting(self, plugin, nm): |
|
|
|
|
def test_neutroncc_context_no_setting(self, plugin, nm): |
|
|
|
|
plugin.return_value = None |
|
|
|
|
napi_ctxt = context.NeutronCCContext() |
|
|
|
|
ctxt_data = { |
|
|
|
@ -38,13 +74,24 @@ class NeutronAPIContextsTest(CharmTestCase):
|
|
|
|
|
with patch.object(napi_ctxt, '_ensure_packages'): |
|
|
|
|
self.assertEquals(ctxt_data, napi_ctxt()) |
|
|
|
|
|
|
|
|
|
def test_quantum_plugin_context_manager(self): |
|
|
|
|
@patch.object(context.NeutronCCContext, 'network_manager') |
|
|
|
|
@patch.object(context.NeutronCCContext, 'plugin') |
|
|
|
|
def test_neutroncc_context_api_rel(self, plugin, nm): |
|
|
|
|
nova_url = 'http://127.0.0.10' |
|
|
|
|
plugin.return_value = None |
|
|
|
|
self.related_units.return_value = ['unit1'] |
|
|
|
|
self.relation_ids.return_value = ['rid2'] |
|
|
|
|
self.test_relation.set({'nova_url': nova_url}) |
|
|
|
|
napi_ctxt = context.NeutronCCContext() |
|
|
|
|
self.assertEquals(nova_url, napi_ctxt()['nova_url']) |
|
|
|
|
|
|
|
|
|
def test_neutroncc_context_manager(self): |
|
|
|
|
napi_ctxt = context.NeutronCCContext() |
|
|
|
|
self.assertEquals(napi_ctxt.network_manager, 'neutron') |
|
|
|
|
self.assertEquals(napi_ctxt.plugin, 'ovs') |
|
|
|
|
self.assertEquals(napi_ctxt.neutron_security_groups, True) |
|
|
|
|
|
|
|
|
|
def test_quantum_plugin_context_manager_pkgs(self): |
|
|
|
|
def test_neutroncc_context_manager_pkgs(self): |
|
|
|
|
napi_ctxt = context.NeutronCCContext() |
|
|
|
|
with patch.object(napi_ctxt, '_ensure_packages') as ep: |
|
|
|
|
napi_ctxt._ensure_packages() |
|
|
|
|