summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPradeep Sathasivam <psathasi@brocade.com>2015-04-10 15:12:03 +0530
committerPradeep Sathasivam <psathasi@brocade.com>2015-04-13 11:54:23 +0530
commit20aea72cfcd266986ba7f2849937d08bb30ffd3e (patch)
tree478930a843bf63c8f13fa1444e4db97572d316f7
parentcead1a3507d5b7febecff8c35399b99995f480bd (diff)
Removed built-in transaction support
The below statement has some issues due to which router interface was not added for the first time. with context.session.begin(subtransactions=True): The above statement is removed and transaction is handled like we do it in ML2 plugin code. We call super.remove_router_interface in case of an exception Also added negative unit test cases and enabled L3 tests in test_discover module Renamed the following modules: l3_router_fi_ni_plugin.py to l3_router_plugin.py test_brocade_l3_router_fi_ni_plugin.py to test_l3_router_plugin.py Change-Id: Id0de71c758c3c271cc54ed00a5014e7e2fc6609d Closes-Bug: #1439095
Notes
Notes (review): Verified+2: Jenkins Code-Review+1: Angela Smith <aallen@brocade.com> Code-Review+2: Karthik Natarajan <natarajk@brocade.com> Workflow+1: Karthik Natarajan <natarajk@brocade.com> Submitted-by: Jenkins Submitted-at: Tue, 14 Apr 2015 18:46:20 +0000 Reviewed-on: https://review.openstack.org/172358 Project: stackforge/networking-brocade Branch: refs/heads/master
-rw-r--r--networking_brocade/mlx/services/l3_router/brocade/l3_router_plugin.py (renamed from networking_brocade/mlx/services/l3_router/brocade/l3_router_fi_ni_plugin.py)142
-rw-r--r--networking_brocade/mlx/tests/unit/services/l3_router/brocade/test_l3_router_plugin.py (renamed from networking_brocade/mlx/tests/unit/services/l3_router/brocade/test_brocade_l3_router_fi_ni_plugin.py)221
-rw-r--r--networking_brocade/test_discover/test_discover.py3
3 files changed, 180 insertions, 186 deletions
diff --git a/networking_brocade/mlx/services/l3_router/brocade/l3_router_fi_ni_plugin.py b/networking_brocade/mlx/services/l3_router/brocade/l3_router_plugin.py
index 778dc65..0d3b7ed 100644
--- a/networking_brocade/mlx/services/l3_router/brocade/l3_router_fi_ni_plugin.py
+++ b/networking_brocade/mlx/services/l3_router/brocade/l3_router_plugin.py
@@ -19,16 +19,16 @@
19 19
20from neutron.i18n import _LE 20from neutron.i18n import _LE
21from neutron.i18n import _LI 21from neutron.i18n import _LI
22from neutron.plugins.ml2.drivers.brocade.db import models as brocade_db 22from neutron.plugins.ml2.driver_context import NetworkContext
23from neutron.services.l3_router import l3_router_plugin as router 23from neutron.services.l3_router import l3_router_plugin as router
24from oslo_log import log as logging 24from oslo_log import log as logging
25from oslo_utils import importutils 25from oslo_utils import importutils
26 26
27LOG = logging.getLogger(__name__) 27LOG = logging.getLogger(__name__)
28NI = "neutron.plugins.ml2.drivers.brocade.fi_ni.ni_driver.NetIronDriver" 28NI = "networking_brocade.mlx.ml2.fi_ni.ni_driver.NetIronDriver"
29BROCADE_CONFIG = ("neutron.plugins.ml2.drivers.brocade.fi_ni.brcd_config." 29BROCADE_CONFIG = ("networking_brocade.mlx.ml2.fi_ni.brcd_config."
30 "ML2BrocadeConfig") 30 "ML2BrocadeConfig")
31DRIVER_FACTORY = ("neutron.plugins.ml2.drivers.brocade.fi_ni." 31DRIVER_FACTORY = ("networking_brocade.mlx.ml2.fi_ni."
32 "driver_factory.BrocadeDriverFactory") 32 "driver_factory.BrocadeDriverFactory")
33# Property to identify which device type to use 33# Property to identify which device type to use
34# Currently supports only NI devices. If FI devices needs to be 34# Currently supports only NI devices. If FI devices needs to be
@@ -37,7 +37,7 @@ DRIVER_FACTORY = ("neutron.plugins.ml2.drivers.brocade.fi_ni."
37ROUTER_DEVICE_TYPE = ['NI'] 37ROUTER_DEVICE_TYPE = ['NI']
38 38
39 39
40class BrocadeFiNiL3RouterPlugin(router.L3RouterPlugin): 40class BrocadeRouterPlugin(router.L3RouterPlugin):
41 41
42 """ 42 """
43 SVI Mechanism driver for Brocade ICX and MLX devices. This will take care 43 SVI Mechanism driver for Brocade ICX and MLX devices. This will take care
@@ -49,9 +49,10 @@ class BrocadeFiNiL3RouterPlugin(router.L3RouterPlugin):
49 49
50 Specify switch address and db configuration. 50 Specify switch address and db configuration.
51 """ 51 """
52 self._devices = {}
53 self._physical_networks = {}
52 self._driver_map = {} 54 self._driver_map = {}
53 self._router_devices_map = {} 55 super(BrocadeRouterPlugin, self).__init__()
54 super(BrocadeFiNiL3RouterPlugin, self).__init__()
55 self.brocade_init() 56 self.brocade_init()
56 57
57 def brocade_init(self): 58 def brocade_init(self):
@@ -59,18 +60,17 @@ class BrocadeFiNiL3RouterPlugin(router.L3RouterPlugin):
59 and stores all the device information in a dictionary. Then it filters 60 and stores all the device information in a dictionary. Then it filters
60 the router devices from it. 61 the router devices from it.
61 """ 62 """
62 LOG.debug("BrocadeFiNiL3RouterPlugin::brocade_init()") 63 LOG.debug("BrocadeRouterPlugin::brocade_init()")
63 64
64 self._devices, self._physical_networks = importutils.import_object( 65 self._devices, self._physical_networks = importutils.import_object(
65 BROCADE_CONFIG).create_ml2_brocade_dictionary() 66 BROCADE_CONFIG).create_brocade_dictionary(isL2=False)
66 self._filter_router_devices(self._devices)
67 67
68 def add_router_interface(self, context, router_id, interface_info): 68 def add_router_interface(self, context, router_id, interface_info):
69 """Adds router interface to a vlan on NI device and assigns ip 69 """Adds router interface to a vlan on NI device and assigns ip
70 address to configure l3 router interface. 70 address to configure l3 router interface.
71 """ 71 """
72 72
73 self.add_remove_router_interface(context, router_id, 73 return self.add_remove_router_interface(context, router_id,
74 interface_info, 74 interface_info,
75 True) 75 True)
76 76
@@ -100,79 +100,77 @@ class BrocadeFiNiL3RouterPlugin(router.L3RouterPlugin):
100 else: 100 else:
101 method = "remove_router_interface" 101 method = "remove_router_interface"
102 operation = "Remove" 102 operation = "Remove"
103 103 info = getattr(super(BrocadeRouterPlugin, self),
104 with context.session.begin(subtransactions=True): 104 method)(context, router_id, interface_info)
105 info = getattr(super(BrocadeFiNiL3RouterPlugin, self), 105 interface_info = info
106 method)(context, router_id, interface_info) 106 subnet = self._core_plugin._get_subnet(context.elevated(),
107 interface_info = info 107 interface_info["subnet_id"])
108 subnet = self._core_plugin._get_subnet(context, 108 vlan_id, gateway_ip_cidr = self._get_network_info(context, subnet)
109 interface_info["subnet_id"]) 109 for device in self._devices:
110 vlan_id, gateway_ip_cidr = self._get_network_info(context, subnet) 110 device_info = self._devices.get(device)
111 for device in self._router_devices_map: 111 address = device_info.get('address')
112 device_info = self._router_devices_map.get(device) 112 driver = self._get_driver(device)
113 driver = self._driver_map.get(device) 113 LOG.info(_LI("BrocadeRouterPlugin:Before %(op)s l3 "
114 address = device_info.get('address') 114 "router to vlan %(vlan_id)s with ip %(gatewayip)s"
115 LOG.info(_LI("BrocadeFiNiL3RouterPlugin:Before %(op)s l3 " 115 "on device "
116 "router to vlan %(vlan_id)s with ip %(gatewayip)s" 116 "%(host)s"), {'op': operation,
117 "on device " 117 'vlan_id': vlan_id,
118 "%(host)s"), {'op': operation, 118 'gatewayip': gateway_ip_cidr,
119 'vlan_id': vlan_id, 119 'host': address})
120 'gatewayip': gateway_ip_cidr, 120 try:
121 'host': address}) 121 if is_add is True:
122 try: 122 getattr(driver, method)(vlan_id, gateway_ip_cidr)
123 if is_add is True: 123 else:
124 getattr(driver, method)(vlan_id, gateway_ip_cidr) 124 getattr(driver, method)(vlan_id)
125 else: 125 except Exception as e:
126 getattr(driver, method)(vlan_id) 126 if is_add:
127 except Exception as e: 127 method = "remove_router_interface"
128 LOG.exception(_LE("BrocadeFiNiL3RouterPlugin: failed to" 128 info = getattr(super(BrocadeRouterPlugin, self),
129 " %(op)s l3 router interface for " 129 method)(context, router_id, interface_info)
130 "device= %(device)s exception : " 130 LOG.exception(_LE("BrocadeRouterPlugin: failed to"
131 "%(error)s"), {'op': operation, 131 " %(op)s l3 router interface for "
132 'device': address, 132 "device= %(device)s exception : "
133 'error': e.args}) 133 "%(error)s"), {'op': operation,
134 raise Exception( 134 'device': address,
135 _("BrocadeFiNiL3RouterPlugin: %(op)s router " 135 'error': e.args})
136 "interface failed"), {'op': operation}) 136 raise Exception(
137 LOG.info(_LI("BrocadeFiNiL3RouterPlugin:%(op)sed router " 137 _("BrocadeRouterPlugin: %(op)s router "
138 "interface in vlan = %(vlan_id)s with ip address" 138 "interface failed"), {'op': operation})
139 " %(gatewayip)s on device %(host)s " 139 LOG.info(_LI("BrocadeRouterPlugin:%(op)sed router "
140 "successful"), {'op': operation, 140 "interface in vlan = %(vlan_id)s with ip address"
141 'vlan_id': vlan_id, 141 " %(gatewayip)s on device %(host)s "
142 'gatewayip': gateway_ip_cidr, 142 "successful"), {'op': operation,
143 'host': address}) 143 'vlan_id': vlan_id,
144 return True 144 'gatewayip': gateway_ip_cidr,
145 145 'host': address})
146 def _filter_router_devices(self, devices): 146 return info
147
148 def _get_driver(self, device):
147 """ 149 """
148 Filters devices using the firmware types in the ROUTER_DEVICE_TYPE from 150 Gets the driver based on the firmware version of the device.
149 devices. It stores the filtered devices in another dictionary 151
150 _router_devices_map. This method also identifies the driver for the 152 :param:device: Contains device name
151 filtered devices and stores them in the map _driver_map with device
152 name as key and the driver as value.
153
154 :param:devices: Contains device name as key and device information
155 in a map with key-value pairs as value.
156 :raises: Exception 153 :raises: Exception
157 """ 154 """
158 driver_factory = importutils.import_object(DRIVER_FACTORY) 155 driver = self._driver_map.get(device)
159 for device in devices: 156 if driver is None:
160 device_info = devices.get(device) 157 driver_factory = importutils.import_object(DRIVER_FACTORY)
158 device_info = self._devices.get(device)
161 address = device_info.get('address') 159 address = device_info.get('address')
160 os_type = device_info.get('ostype')
162 try: 161 try:
163 driver = driver_factory.get_driver(device_info) 162 driver = driver_factory.get_driver(device_info)
164 os_type = device_info.get('ostype')
165 if driver is not None and os_type in ROUTER_DEVICE_TYPE: 163 if driver is not None and os_type in ROUTER_DEVICE_TYPE:
166 self._router_devices_map.update({device: device_info})
167 self._driver_map.update({device: driver}) 164 self._driver_map.update({device: driver})
168 except Exception as e: 165 except Exception as e:
169 LOG.exception(_LE("BrocadeFiNiL3RouterPlugin:" 166 LOG.exception(_LE("BrocadeRouterPlugin:"
170 "_filter_router_devices: Error while getting" 167 "_filter_router_devices: Error while getting"
171 " driver : device - %(host)s: %(error)s"), 168 " driver : device - %(host)s: %(error)s"),
172 {'host': address, 'error': e.args}) 169 {'host': address, 'error': e.args})
173 raise Exception(_("BrocadeFiNiL3RouterPlugin:" 170 raise Exception(_("BrocadeRouterPlugin:"
174 "_filter_router_devices failed for " 171 "_filter_router_devices failed for "
175 "device %(host)s"), {'host': address}) 172 "device %(host)s"), {'host': address})
173 return driver
176 174
177 def _get_network_info(self, context, subnet): 175 def _get_network_info(self, context, subnet):
178 """ 176 """
@@ -188,8 +186,8 @@ class BrocadeFiNiL3RouterPlugin(router.L3RouterPlugin):
188 net_addr, net_len = self.net_addr(cidr) 186 net_addr, net_len = self.net_addr(cidr)
189 gateway_ip = subnet["gateway_ip"] 187 gateway_ip = subnet["gateway_ip"]
190 network_id = subnet['network_id'] 188 network_id = subnet['network_id']
191 bnet = brocade_db.get_network(context, network_id) 189 ml2_db = NetworkContext(self, context, {'id': network_id})
192 vlan_id = bnet['vlan'] 190 vlan_id = ml2_db.network_segments[0]['segmentation_id']
193 gateway_ip_cidr = gateway_ip + '/' + str(net_len) 191 gateway_ip_cidr = gateway_ip + '/' + str(net_len)
194 192
195 return vlan_id, gateway_ip_cidr 193 return vlan_id, gateway_ip_cidr
diff --git a/networking_brocade/mlx/tests/unit/services/l3_router/brocade/test_brocade_l3_router_fi_ni_plugin.py b/networking_brocade/mlx/tests/unit/services/l3_router/brocade/test_l3_router_plugin.py
index 8ed2692..fa2f290 100644
--- a/networking_brocade/mlx/tests/unit/services/l3_router/brocade/test_brocade_l3_router_fi_ni_plugin.py
+++ b/networking_brocade/mlx/tests/unit/services/l3_router/brocade/test_l3_router_plugin.py
@@ -16,7 +16,7 @@
16 16
17import mock 17import mock
18from networking_brocade.mlx.services.l3_router.brocade import ( 18from networking_brocade.mlx.services.l3_router.brocade import (
19 l3_router_fi_ni_plugin as brocadel3routerfiniplugin) 19 l3_router_plugin as brocadel3routerplugin)
20from neutron import context 20from neutron import context
21from neutron.db import l3_db 21from neutron.db import l3_db
22from neutron.i18n import _LE 22from neutron.i18n import _LE
@@ -26,9 +26,12 @@ from oslo_utils import importutils
26 26
27 27
28MECHANISM_NAME = ('networking_brocade.mlx.services.l3_router.brocade.' 28MECHANISM_NAME = ('networking_brocade.mlx.services.l3_router.brocade.'
29 'l3_router_fi_ni_plugin.BrocadeFiNiL3RouterPlugin') 29 'l3_router_plugin.BrocadeRouterPlugin')
30VE = 've ' 30VE = 've '
31config_map = {} 31config_map = {}
32vlan_map = {}
33interface_map = {}
34
32device_map = { 35device_map = {
33 'mlx': { 36 'mlx': {
34 'address': '2.2.2.2', 37 'address': '2.2.2.2',
@@ -52,6 +55,10 @@ delete_config_map = {
52 } 55 }
53} 56}
54 57
58interface_info = {
59 'subnet_id': 'subnet1',
60 'port_id': 'port1'}
61
55vlan_id = '402' 62vlan_id = '402'
56gateway_ip_cidr = '12.0.0.1/24' 63gateway_ip_cidr = '12.0.0.1/24'
57ROUTER = 'router1' 64ROUTER = 'router1'
@@ -62,8 +69,7 @@ INVALID_INPUT = "Invalid input"
62RANGE_ERROR = "outside of allowed max" 69RANGE_ERROR = "outside of allowed max"
63 70
64 71
65class TestBrocadeL3RouterFiNiPlugin(base.BaseTestCase, 72class TestBrocadeL3RouterPlugin(base.BaseTestCase, router.L3RouterPlugin):
66 router.L3RouterPlugin):
67 73
68 """ 74 """
69 Test Brocade L3 Router FI/NI plugin. 75 Test Brocade L3 Router FI/NI plugin.
@@ -73,131 +79,126 @@ class TestBrocadeL3RouterFiNiPlugin(base.BaseTestCase,
73 _mechanism_name = MECHANISM_NAME 79 _mechanism_name = MECHANISM_NAME
74 80
75 def mocked_initialize(self): 81 def mocked_initialize(self):
76 self._router_devices_map = device_map 82 self._devices = device_map
77 self._driver_map = {'mlx': FakeDriver(device_map.get('mlx'))}
78 83
79 with mock.patch.object(brocadel3routerfiniplugin 84 with mock.patch.object(brocadel3routerplugin
80 .BrocadeFiNiL3RouterPlugin, 85 .BrocadeRouterPlugin,
81 'brocade_init', new=mocked_initialize): 86 'brocade_init', new=mocked_initialize):
82 super(TestBrocadeL3RouterFiNiPlugin, self).setUp() 87 super(TestBrocadeL3RouterPlugin, self).setUp()
83 self.interface_info = {'subnet_id': SUBNET,
84 'port_id': PORT}
85 self.driver = importutils.import_object(_mechanism_name) 88 self.driver = importutils.import_object(_mechanism_name)
86 89
87 @mock.patch.object( 90 @mock.patch.object(brocadel3routerplugin.BrocadeRouterPlugin,
88 brocadel3routerfiniplugin.BrocadeFiNiL3RouterPlugin, 91 '_get_driver')
89 '_get_network_info') 92 @mock.patch.object(brocadel3routerplugin.BrocadeRouterPlugin,
93 '_get_network_info')
90 @mock.patch.object(l3_db.L3_NAT_dbonly_mixin, '_core_plugin') 94 @mock.patch.object(l3_db.L3_NAT_dbonly_mixin, '_core_plugin')
91 @mock.patch.object(router.L3RouterPlugin, 95 @mock.patch.object(router.L3RouterPlugin, 'add_router_interface')
92 'add_router_interface')
93 def test_add_router_interface( 96 def test_add_router_interface(
94 self, mock_super, mock_core_plugin, mock_network_info): 97 self, mock_super, mock_core_plugin, mock_network_info,
98 mock_driver):
95 99
96 mech_ctx = _get_network_context('physnet1', 'vlan') 100 mock_driver.side_effect = self.side_effect
101 mech_ctx = self._get_network_context('physnet1', 'vlan')
97 ctx = mech_ctx._plugin_context 102 ctx = mech_ctx._plugin_context
98 ctx.session.begin = mock.MagicMock() 103 ctx.session.begin = mock.MagicMock()
99 mock_super.returnValue = self.interface_info 104 mock_super.returnValue = interface_info
100 mock_core_plugin.side_effect = mock.MagicMock() 105 mock_core_plugin.side_effect = mock.MagicMock()
101 mock_network_info.side_effect = side_effect_network_info 106 mock_network_info.side_effect = self.side_effect_network_info
102 self.driver.add_router_interface(ctx, ROUTER, 107 self.driver.add_router_interface(ctx, ROUTER,
103 self.interface_info) 108 interface_info)
104 global config_map
105 self.assertDictSupersetOf(config_map, add_config_map) 109 self.assertDictSupersetOf(config_map, add_config_map)
106 110
107 @mock.patch.object(
108 brocadel3routerfiniplugin.BrocadeFiNiL3RouterPlugin,
109 '_get_network_info')
110 @mock.patch.object(l3_db.L3_NAT_dbonly_mixin, '_core_plugin')
111 @mock.patch.object(router.L3RouterPlugin, 'remove_router_interface') 111 @mock.patch.object(router.L3RouterPlugin, 'remove_router_interface')
112 def test_remove_router_interface( 112 @mock.patch.object(brocadel3routerplugin.BrocadeRouterPlugin,
113 self, mock_super, mock_core_plugin, mock_network_info): 113 '_get_driver')
114 mech_ctx = _get_network_context('physnet1', 'vlan') 114 @mock.patch.object(brocadel3routerplugin.BrocadeRouterPlugin,
115 ctx = mech_ctx._plugin_context 115 '_get_network_info')
116 ctx.session.begin = mock.MagicMock()
117 mock_super.returnValue = self.interface_info
118 mock_core_plugin.side_effect = mock.MagicMock()
119 mock_network_info.side_effect = side_effect_network_info
120 self.driver.remove_router_interface(ctx, ROUTER,
121 self.interface_info)
122 global config_map
123 self.assertDictSupersetOf(config_map, delete_config_map)
124
125
126class TestBrocadeL3RouterFiNiPluginException(base.BaseTestCase,
127 router.L3RouterPlugin):
128
129 """
130 Test Brocade L3 Router FI/NI plugin for negative scenario
131 """
132
133 def setUp(self):
134 _mechanism_name = MECHANISM_NAME
135
136 def mocked_initialize(self):
137 self._router_devices_map = device_map
138 self._driver_map = {
139 'mlx': FakeDriver(
140 device_map.get('mlx'),
141 error=True)}
142
143 with mock.patch.object(brocadel3routerfiniplugin
144 .BrocadeFiNiL3RouterPlugin,
145 'brocade_init', new=mocked_initialize):
146 super(TestBrocadeL3RouterFiNiPluginException, self).setUp()
147 self.interface_info = {'subnet_id': SUBNET,
148 'port_id': PORT}
149 self.driver = importutils.import_object(_mechanism_name)
150
151 @mock.patch.object(
152 brocadel3routerfiniplugin.BrocadeFiNiL3RouterPlugin,
153 '_get_network_info')
154 @mock.patch.object(l3_db.L3_NAT_dbonly_mixin, '_core_plugin') 116 @mock.patch.object(l3_db.L3_NAT_dbonly_mixin, '_core_plugin')
155 @mock.patch.object(router.L3RouterPlugin, 'add_router_interface') 117 @mock.patch.object(router.L3RouterPlugin, 'add_router_interface')
156 def test_add_router_interface_exception( 118 def test_add_router_interface_exception(
157 self, mock_super, mock_core_plugin, mock_network_info): 119 self, mock_super, mock_core_plugin, mock_network_info,
120 mock_driver, mock_super_remove):
158 121
159 mech_ctx = _get_network_context('physnet1', 'vlan') 122 mock_driver.side_effect = self.side_effect_error
123 mech_ctx = self._get_network_context('physnet1', 'vlan')
160 ctx = mech_ctx._plugin_context 124 ctx = mech_ctx._plugin_context
161 ctx.session.begin = mock.MagicMock() 125 ctx.session.begin = mock.MagicMock()
162 mock_super.returnValue = self.interface_info 126 mock_super.returnValue = interface_info
163 mock_core_plugin.side_effect = mock.MagicMock() 127 mock_core_plugin.side_effect = mock.MagicMock()
164 mock_network_info.side_effect = side_effect_network_info 128 mock_network_info.side_effect = self.side_effect_network_info
129 mock_super_remove.returnValue = interface_info
165 self.assertRaisesRegexp( 130 self.assertRaisesRegexp(
166 Exception, (_LE("BrocadeFiNiL3RouterPlugin")), 131 Exception, (_LE("BrocadeRouterPlugin")),
167 self.driver.add_router_interface, 132 self.driver.add_router_interface,
168 ctx, ROUTER, self.interface_info) 133 ctx, ROUTER, interface_info)
169
170
171def _get_network_context(physnet, network_type):
172 """
173 Create mock network context
174 """
175 network = {
176 'id': 1,
177 'name': 'private',
178 'tenant_id': 1,
179 'vlan': 200,
180 'network_type': network_type,
181 'provider:segmentation_id': 200
182 }
183
184 network_segments = [{
185 'id': 1,
186 'segmentation_id': 200,
187 'network_type': network_type,
188 'physical_network': physnet
189 }]
190
191 _plugin_context = context.get_admin_context()
192 return FakeNetworkContext(network, network_segments, _plugin_context)
193 134
135 @mock.patch.object(brocadel3routerplugin.BrocadeRouterPlugin,
136 '_get_driver')
137 @mock.patch.object(brocadel3routerplugin.BrocadeRouterPlugin,
138 '_get_network_info')
139 @mock.patch.object(l3_db.L3_NAT_dbonly_mixin, '_core_plugin')
140 @mock.patch.object(router.L3RouterPlugin, 'remove_router_interface')
141 def test_remove_router_interface(
142 self, mock_super, mock_core_plugin, mock_network_info,
143 mock_driver):
194 144
195def side_effect_network_info(vlan, ip): 145 mock_driver.side_effect = self.side_effect
196 """ 146 mech_ctx = self._get_network_context('physnet1', 'vlan')
197 Mock _get_driver method and return FakeDriver 147 ctx = mech_ctx._plugin_context
198 """ 148 ctx.session.begin = mock.MagicMock()
149 mock_super.returnValue = interface_info
150 mock_core_plugin.side_effect = mock.MagicMock()
151 mock_network_info.side_effect = self.side_effect_network_info
152 ve_map = {'ve 402': '12.0.0.1/24'}
153 vlan_map.update({'402': ve_map})
154 config_map.update({'2.2.2.2': vlan_map})
155 self.driver.remove_router_interface(ctx, ROUTER,
156 interface_info)
157 self.assertDictSupersetOf(config_map, delete_config_map)
199 158
200 return vlan_id, gateway_ip_cidr 159 def side_effect(self, dev_name):
160 """
161 Mock _get_driver method and return FakeDriver
162 """
163 device = device_map.get(dev_name)
164 return FakeDriver(device)
165
166 def side_effect_error(self, dev_name):
167 """
168 Mock _get_driver method and return FakeDriver
169 """
170 device = device_map.get(dev_name)
171 return FakeDriver(device, error=True)
172
173 def _get_network_context(self, physnet, network_type):
174 """
175 Create mock network context
176 """
177 network = {
178 'id': 1,
179 'name': 'private',
180 'tenant_id': 1,
181 'vlan': 200,
182 'network_type': network_type,
183 'provider:segmentation_id': 200
184 }
185
186 network_segments = [{
187 'id': 1,
188 'segmentation_id': 200,
189 'network_type': network_type,
190 'physical_network': physnet
191 }]
192
193 _plugin_context = context.get_admin_context()
194 return FakeNetworkContext(network, network_segments, _plugin_context)
195
196 def side_effect_network_info(self, vlan, ip):
197 """
198 Mock _get_driver method and return FakeDriver
199 """
200
201 return vlan_id, gateway_ip_cidr
201 202
202 203
203class FakeNetworkContext(object): 204class FakeNetworkContext(object):
@@ -247,19 +248,13 @@ class FakeDriver(object):
247 "ve out of range error") 248 "ve out of range error")
248 elif self.error: 249 elif self.error:
249 raise Exception("Add Router Interface failed") 250 raise Exception("Add Router Interface failed")
250 vlan_map = {} 251
251 interface_map = {}
252 interface_map.update({VE + vlan_id: gateway_ip_cidr}) 252 interface_map.update({VE + vlan_id: gateway_ip_cidr})
253 vlan_map.update({vlan_id: interface_map}) 253 vlan_map.update({vlan_id: interface_map})
254 global config_map
255 config_map.update({self.address: vlan_map}) 254 config_map.update({self.address: vlan_map})
256 255
257 def remove_router_interface(self, vlan_id): 256 def remove_router_interface(self, vlan_id):
258 vlan_map = delete_config_map.pop(self.address, None) 257 if vlan_id in config_map[self.address]:
259 interface_map = vlan_map.pop(vlan_id, None) 258 config_map[self.address].update({vlan_id: {}})
260 if vlan_map is None:
261 raise Exception("No Address")
262 elif interface_map is None:
263 raise Exception("No Router Interface")
264 else: 259 else:
265 interface_map.pop(VE + vlan_id, None) 260 raise Exception("vlan is not there")
diff --git a/networking_brocade/test_discover/test_discover.py b/networking_brocade/test_discover/test_discover.py
index e8eb666..ec40611 100644
--- a/networking_brocade/test_discover/test_discover.py
+++ b/networking_brocade/test_discover/test_discover.py
@@ -29,7 +29,8 @@ def load_tests(loader, tests, pattern):
29 base_path = os.path.split(base_path)[0] 29 base_path = os.path.split(base_path)[0]
30 test_dirs = {'./networking_brocade/tests', 30 test_dirs = {'./networking_brocade/tests',
31 './networking_brocade/vdx/tests/unit/ml2/drivers/brocade', 31 './networking_brocade/vdx/tests/unit/ml2/drivers/brocade',
32 MLX_TEST_BASE_PATH + '/unit/ml2/drivers/brocade' 32 MLX_TEST_BASE_PATH + '/unit/ml2/drivers/brocade',
33 MLX_TEST_BASE_PATH + '/unit/services/l3_router/brocade'
33 } 34 }
34 for test_dir in test_dirs: 35 for test_dir in test_dirs:
35 if not pattern: 36 if not pattern: