Fixes and context unit tests

This commit is contained in:
Liam Young 2014-06-18 16:34:56 +01:00
parent 592ae155f0
commit d8ab9cf359
3 changed files with 69 additions and 1 deletions

View File

@ -0,0 +1,51 @@
from test_utils import CharmTestCase
from mock import patch
import neutron_api_context as context
TO_PATCH = [
'relation_get',
'relation_ids',
'related_units',
'config',
]
class NeutronAPIContextsTest(CharmTestCase):
def setUp(self):
super(NeutronAPIContextsTest, 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('neutron-plugin', 'ovs')
self.test_config.set('neutron-security-groups', True)
self.test_config.set('debug', True)
self.test_config.set('verbose', True)
self.test_config.set('neutron-external-network', 'bob')
def tearDown(self):
super(NeutronAPIContextsTest, self).tearDown()
@patch.object(context.NeutronCCContext, 'network_manager')
@patch.object(context.NeutronCCContext, 'plugin')
def test_quantum_plugin_context_no_setting(self, plugin, nm):
plugin.return_value = None
napi_ctxt = context.NeutronCCContext()
ctxt_data = {
'debug': True,
'external_network': 'bob',
'verbose': True
}
with patch.object(napi_ctxt, '_ensure_packages'):
self.assertEquals(ctxt_data, napi_ctxt())
def test_quantum_plugin_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):
napi_ctxt = context.NeutronCCContext()
with patch.object(napi_ctxt, '_ensure_packages') as ep:
napi_ctxt._ensure_packages()
ep.assert_has_calls([])

View File

@ -34,6 +34,7 @@ TO_PATCH = [
'is_relation_made',
'log',
'network_manager',
'neutron_plugin_attribute',
'open_port',
'relation_get',
'relation_ids',

View File

@ -18,16 +18,32 @@ import charmhelpers.core.hookenv as hookenv
TO_PATCH = [
'b64encode',
'config',
# 'neutron_plugin_attribute',
'neutron_plugin_attribute',
]
def _mock_npa(plugin, attr, net_manager=None):
plugins = {
'ovs': {
'config': '/etc/neutron/plugins/ml2/ml2_conf.ini',
'driver': 'neutron.plugins.ml2.plugin.Ml2Plugin',
'contexts': [],
'services': ['neutron-plugin-openvswitch-agent'],
'packages': [['neutron-plugin-openvswitch-agent']],
'server_packages': ['neutron-server',
'neutron-plugin-ml2'],
'server_services': ['neutron-server']
},
}
return plugins[plugin][attr]
class TestNeutronAPIUtils(CharmTestCase):
def setUp(self):
super(TestNeutronAPIUtils, self).setUp(nutils, TO_PATCH)
self.config.side_effect = self.test_config.get
self.test_config.set('region', 'region101')
self.neutron_plugin_attribute.side_effect = _mock_npa
def tearDown(self):
# Reset cached cache