Browse Source

support vlan network

Change-Id: I7e9b01f4f8177f971754a4464894e47136fddf28
tags/1.0.0
Itsuro Oda 1 year ago
parent
commit
ec2499d5f4

+ 52
- 18
networking_spp/agent/spp_agent.py View File

@@ -184,51 +184,84 @@ class SppAgent(object):
184 184
     def _init_vhost_mac_address(self, info):
185 185
         table = info.get("classifier_table", [])
186 186
         for entry in table:
187
-            if entry["type"] == "mac" and entry["port"].startswith("ring:"):
187
+            if (entry["type"] in ["mac", "vlan"] and
188
+                    entry["port"].startswith("ring:")):
188 189
                 ring_id = int(entry["port"][len("ring:"):])
189 190
                 vhost_id = ring_id // 2
191
+                mac_string = entry["value"]
192
+                if entry["type"] == "vlan":
193
+                    _vlan_id, mac_string = mac_string.split('/')
190 194
                 # match format of neutron standard
191
-                mac = str(netaddr.EUI(entry["value"],
195
+                mac = str(netaddr.EUI(mac_string,
192 196
                                       dialect=netaddr.mac_unix_expanded))
193 197
                 self.vhostusers[vhost_id].mac_address = mac
194 198
 
195
-    def set_classifier_table(self, vhost_id, mac_address):
199
+    def set_classifier_table(self, vhost_id, mac_address, vlan_id):
196 200
         vhost = self.vhostusers[vhost_id]
197 201
         if vhost.mac_address == mac_address:
198 202
             LOG.debug("classifier table already set: %d: %s",
199 203
                       vhost_id, mac_address)
200 204
             return
201 205
 
202
-        port = _rx_ring_port(vhost_id)
203
-        self.spp_vf_api.set_classifier_table(vhost.sec_id, mac_address, port)
206
+        rx_port = _rx_ring_port(vhost_id)
207
+        if vlan_id is None:
208
+            self.spp_vf_api.set_classifier_table(vhost.sec_id, mac_address,
209
+                                                 rx_port)
210
+        else:
211
+            forwarder = "forward_%d_rx" % vhost_id
212
+            self.spp_vf_api.port_del(vhost.sec_id, _vhost_port(vhost_id), "rx",
213
+                                     forwarder)
214
+            self.spp_vf_api.port_add(vhost.sec_id, _vhost_port(vhost_id), "rx",
215
+                                     forwarder, "add_vlantag", vlan_id)
216
+            self.spp_vf_api.port_del(vhost.sec_id, rx_port, "tx", "classifier")
217
+            self.spp_vf_api.port_add(vhost.sec_id, rx_port, "tx", "classifier",
218
+                                     "del_vlantag")
219
+            self.spp_vf_api.set_classifier_table_with_vlan(vhost.sec_id,
220
+                                                           mac_address,
221
+                                                           rx_port, vlan_id)
222
+        self.spp_vf_api.flush(vhost.sec_id)
204 223
 
205 224
         vhost.mac_address = mac_address
206 225
 
207
-    def clear_classifier_table(self, vhost_id, mac_address):
226
+    def clear_classifier_table(self, vhost_id, mac_address, vlan_id):
208 227
         vhost = self.vhostusers[vhost_id]
209 228
         if vhost.mac_address == "unuse":
210 229
             LOG.debug("classifier table already clear: %d", vhost_id)
211 230
             return
212 231
 
213
-        port = _rx_ring_port(vhost_id)
214
-        self.spp_vf_api.clear_classifier_table(vhost.sec_id, mac_address, port)
232
+        rx_port = _rx_ring_port(vhost_id)
233
+        if vlan_id is None:
234
+            self.spp_vf_api.clear_classifier_table(vhost.sec_id, mac_address,
235
+                                                   rx_port)
236
+        else:
237
+            forwarder = "forward_%d_rx" % vhost_id
238
+            self.spp_vf_api.port_del(vhost.sec_id, _vhost_port(vhost_id), "rx",
239
+                                     forwarder)
240
+            self.spp_vf_api.port_add(vhost.sec_id, _vhost_port(vhost_id), "rx",
241
+                                     forwarder)
242
+            self.spp_vf_api.port_del(vhost.sec_id, rx_port, "tx", "classifier")
243
+            self.spp_vf_api.port_add(vhost.sec_id, rx_port, "tx", "classifier")
244
+            self.spp_vf_api.clear_classifier_table_with_vlan(vhost.sec_id,
245
+                                                             mac_address,
246
+                                                             rx_port, vlan_id)
247
+        self.spp_vf_api.flush(vhost.sec_id)
215 248
 
216 249
         vhost.mac_address = "unuse"
217 250
 
218
-    def _plug_port(self, port_id, vhost_id, mac_address):
219
-        LOG.info("plug port %s: mac: %s, vhost: %d", port_id,
220
-                 mac_address, vhost_id)
251
+    def _plug_port(self, port_id, vhost_id, mac_address, vlan_id):
252
+        LOG.info("plug port %s: mac: %s, vhost: %d, vlan_id: %s", port_id,
253
+                 mac_address, vhost_id, vlan_id)
221 254
 
222
-        self.set_classifier_table(vhost_id, mac_address)
255
+        self.set_classifier_table(vhost_id, mac_address, vlan_id)
223 256
 
224 257
         key = etcd_key.port_status_key(self.host, port_id)
225 258
         self.etcd.put(key, "up")
226 259
 
227
-    def _unplug_port(self, port_id, vhost_id, mac_address):
228
-        LOG.info("unplug port %s: mac: %s, vhost: %d", port_id,
229
-                 mac_address, vhost_id)
260
+    def _unplug_port(self, port_id, vhost_id, mac_address, vlan_id):
261
+        LOG.info("unplug port %s: mac: %s, vhost: %d, vlan_id: %s", port_id,
262
+                 mac_address, vhost_id, vlan_id)
230 263
 
231
-        self.clear_classifier_table(vhost_id, mac_address)
264
+        self.clear_classifier_table(vhost_id, mac_address, vlan_id)
232 265
 
233 266
         phys = self.vhostusers[vhost_id].physical_network
234 267
         key = etcd_key.vhost_key(self.host, phys, vhost_id)
@@ -250,12 +283,13 @@ class SppAgent(object):
250 283
             data = json.loads(value)
251 284
             vhost_id = data['vhost_id']
252 285
             mac_address = data['mac_address']
286
+            vlan_id = data.get('vlan_id')
253 287
             # get action again to get the newest value
254 288
             op = self.etcd.get(etcd_key.action_key(self.host, port_id))
255 289
             if op == "plug":
256
-                self._plug_port(port_id, vhost_id, mac_address)
290
+                self._plug_port(port_id, vhost_id, mac_address, vlan_id)
257 291
             else:
258
-                self._unplug_port(port_id, vhost_id, mac_address)
292
+                self._unplug_port(port_id, vhost_id, mac_address, vlan_id)
259 293
 
260 294
     def port_plug_watch(self):
261 295
         LOG.info("SPP port_plug_watch stated")

+ 23
- 3
networking_spp/agent/spp_api.py View File

@@ -45,9 +45,19 @@ class SppVfApi(object):
45 45
                    .format(**locals()))
46 46
         self._exec_command(sec_id, command)
47 47
 
48
-    def port_add(self, sec_id, port, direction, comp_name):
48
+    def port_add(self, sec_id, port, direction, comp_name,
49
+                 op=None, vlan_id=None):
49 50
         command = ("port add {port} {direction} {comp_name}"
50 51
                    .format(**locals()))
52
+        if op:
53
+            command += " %s" % op
54
+            if op == "add_vlantag":
55
+                command += " %d 0" % vlan_id
56
+        self._exec_command(sec_id, command)
57
+
58
+    def port_del(self, sec_id, port, direction, comp_name):
59
+        command = ("port del {port} {direction} {comp_name}"
60
+                   .format(**locals()))
51 61
         self._exec_command(sec_id, command)
52 62
 
53 63
     def flush(self, sec_id):
@@ -60,10 +70,20 @@ class SppVfApi(object):
60 70
         command = ("classifier_table add mac {mac_address} {port}"
61 71
                    .format(**locals()))
62 72
         self._exec_command(sec_id, command)
63
-        self.flush(sec_id)
64 73
 
65 74
     def clear_classifier_table(self, sec_id, mac_address, port):
66 75
         command = ("classifier_table del mac {mac_address} {port}"
67 76
                    .format(**locals()))
68 77
         self._exec_command(sec_id, command)
69
-        self.flush(sec_id)
78
+
79
+    def set_classifier_table_with_vlan(self, sec_id, mac_address, port,
80
+                                       vlan_id):
81
+        command = ("classifier_table add vlan {vlan_id} {mac_address} {port}"
82
+                   .format(**locals()))
83
+        self._exec_command(sec_id, command)
84
+
85
+    def clear_classifier_table_with_vlan(self, sec_id, mac_address, port,
86
+                                         vlan_id):
87
+        command = ("classifier_table del vlan {vlan_id} {mac_address} {port}"
88
+                   .format(**locals()))
89
+        self._exec_command(sec_id, command)

+ 10
- 4
networking_spp/mech_driver/mech_spp.py View File

@@ -42,6 +42,9 @@ class SppMechanismDriver(api.MechanismDriver):
42 42
 
43 43
     def _try_to_bind(self, context, segment):
44 44
         port_id = context.current['id']
45
+        if self.etcd.get(etcd_key.bind_port_key(context.host, port_id)):
46
+            # check already tried to bind at first.
47
+            return
45 48
         phys = segment[api.PHYSICAL_NETWORK]
46 49
         prefix = etcd_key.vhost_phys_prefix(context.host, phys)
47 50
         vhost_id = None
@@ -56,7 +59,7 @@ class SppMechanismDriver(api.MechanismDriver):
56 59
             LOG.warn("no vhost available for port %s", port_id)
57 60
             return
58 61
 
59
-        self._add_bind_port(context, vhost_id)
62
+        self._add_bind_port(context, vhost_id, segment[api.SEGMENTATION_ID])
60 63
         if not self._wait_plug_port(context.host, port_id):
61 64
             return
62 65
 
@@ -87,14 +90,17 @@ class SppMechanismDriver(api.MechanismDriver):
87 90
             return
88 91
 
89 92
         for segment in context.segments_to_bind:
90
-            if (segment[api.NETWORK_TYPE] in [constants.TYPE_FLAT] and
91
-                    segment[api.PHYSICAL_NETWORK] in phys_nets):
93
+            if (segment[api.NETWORK_TYPE] in [constants.TYPE_FLAT,
94
+                                              constants.TYPE_VLAN]
95
+                    and segment[api.PHYSICAL_NETWORK] in phys_nets):
92 96
                 self._try_to_bind(context, segment)
93 97
                 return
94 98
 
95
-    def _add_bind_port(self, context, vhost_id):
99
+    def _add_bind_port(self, context, vhost_id, vlan_id):
96 100
         port = context.current
97 101
         value = {'mac_address': port['mac_address'], 'vhost_id': int(vhost_id)}
102
+        if vlan_id is not None:
103
+            value['vlan_id'] = vlan_id
98 104
         value = json.dumps(value)
99 105
         key = etcd_key.bind_port_key(context.host, port['id'])
100 106
         self.etcd.put(key, value)

+ 20
- 1
networking_spp/tests/unit/test_mech_spp.py View File

@@ -63,6 +63,22 @@ class SppMechanismTestCase(base.BaseTestCase):
63 63
         self.driver.bind_port(self.context)
64 64
         mocked_try_to_bind.aseert_called()
65 65
 
66
+    @mock.patch('networking_spp.mech_driver.mech_spp.'
67
+                'SppMechanismDriver._spp_agent_alive')
68
+    @mock.patch('networking_spp.mech_driver.mech_spp.'
69
+                'SppMechanismDriver._try_to_bind')
70
+    def test_bind_port_call_try_to_bind_vlan(self, mocked_try_to_bind,
71
+                                             mocked_spp_agent_alive):
72
+        # conditions to call _try_to_bind
73
+        agent_conf = [{'physical_network': 'phy_net'}]
74
+        self.driver.etcd.get.return_value = json.dumps(agent_conf)
75
+        mocked_spp_agent_alive.return_value = True
76
+        segment = {api.NETWORK_TYPE: constants.TYPE_VLAN,
77
+                   api.PHYSICAL_NETWORK: 'phy_net'}
78
+        self.context.segments_to_bind = [segment]
79
+        self.driver.bind_port(self.context)
80
+        mocked_try_to_bind.aseert_called()
81
+
66 82
     @mock.patch('networking_spp.mech_driver.mech_spp.'
67 83
                 'SppMechanismDriver._spp_agent_alive')
68 84
     @mock.patch('networking_spp.mech_driver.mech_spp.'
@@ -207,7 +223,7 @@ class SppMechanismTestCase(base.BaseTestCase):
207 223
         mocked_action_key.side_effect = lambda host, port: host + port
208 224
         mocked_bind_port_key.side_effect = lambda host, port: host + port
209 225
         self.driver.etcd.put.side_effect = self._put
210
-        self.driver._add_bind_port(self.context, '1')
226
+        self.driver._add_bind_port(self.context, '1', None)
211 227
         args, w = self.driver.etcd.put.call_args
212 228
         self.assertEqual(args[0], 'host1AAAABBBB')
213 229
         self.assertEqual(self.driver.etcd.put.call_count, 2)
@@ -227,12 +243,14 @@ class SppMechanismTestCase(base.BaseTestCase):
227 243
         self.context.host = 'host1'
228 244
         segment = {api.NETWORK_TYPE: constants.TYPE_FLAT,
229 245
                    api.PHYSICAL_NETWORK: 'phy1',
246
+                   api.SEGMENTATION_ID: None,
230 247
                    api.ID: 'id'}
231 248
         mocked_vhost_phys_prefix.side_effect = \
232 249
             lambda a, b: '/x/y/%s/%s/' % (a, b)
233 250
         value = [('/x/y/host1/phy1/1', '1234AAAA'),
234 251
                  ('/x/y/host1/phy1/2', 'EEEE4444'),
235 252
                  ('/x/y/host1/phy1/3', 'None')]
253
+        self.driver.etcd.get.return_value = None
236 254
         self.driver.etcd.get_prefix.return_value = value
237 255
         self.driver.etcd.replace.return_value = True
238 256
         mocked_wait_plug_port.return_value = True
@@ -269,6 +287,7 @@ class SppMechanismTestCase(base.BaseTestCase):
269 287
         value = [('/x/y/host1/phy1/1', '1234AAAA'),
270 288
                  ('/x/y/host1/phy1/2', 'EEEE4444'),
271 289
                  ('/x/y/host1/phy1/3', '99999999')]
290
+        self.driver.etcd.get.return_value = None
272 291
         self.driver.etcd.get_prefix.return_value = value
273 292
         self.driver.etcd.replace.return_value = True
274 293
 

+ 42
- 13
networking_spp/tests/unit/test_spp_agent.py View File

@@ -207,7 +207,7 @@ class SppAgentTestCase(base.BaseTestCase):
207 207
         self.agent.vhostusers[1] = mock.Mock()
208 208
         self.agent.vhostusers[1].mac_address = mac
209 209
 
210
-        ret = self.agent.set_classifier_table(1, mac)
210
+        ret = self.agent.set_classifier_table(1, mac, None)
211 211
         self.assertEqual(ret, None)
212 212
         self.assertEqual(self.agent.spp_vf_api.set_classifier_table.call_count,
213 213
                          0)
@@ -216,11 +216,25 @@ class SppAgentTestCase(base.BaseTestCase):
216 216
         # conditions to exec correctly
217 217
         mac = '12:ab:34:cd:56:ef'
218 218
         self.agent.vhostusers[1] = mock.Mock()
219
-        self.agent.vhostusers[1].mac_address = '32:ab:34:cd:56:ef'
219
+        self.agent.vhostusers[1].mac_address = 'unuse'
220 220
 
221
-        self.agent.set_classifier_table(1, mac)
221
+        self.agent.set_classifier_table(1, mac, None)
222 222
         self.assertEqual(self.agent.spp_vf_api.set_classifier_table.call_count,
223 223
                          1)
224
+        self.assertEqual(self.agent.spp_vf_api.flush.call_count, 1)
225
+        self.assertEqual(self.agent.vhostusers[1].mac_address, mac)
226
+
227
+    def test_set_classifier_table_with_vlan(self):
228
+        mac = '12:ab:34:cd:56:ef'
229
+        self.agent.vhostusers[1] = mock.Mock()
230
+        self.agent.vhostusers[1].mac_address = 'unuse'
231
+
232
+        self.agent.set_classifier_table(1, mac, 10)
233
+        self.assertEqual(self.agent.spp_vf_api.port_add.call_count, 2)
234
+        self.assertEqual(self.agent.spp_vf_api.port_del.call_count, 2)
235
+        self.assertEqual(
236
+            self.agent.spp_vf_api.set_classifier_table_with_vlan.call_count, 1)
237
+        self.assertEqual(self.agent.spp_vf_api.flush.call_count, 1)
224 238
         self.assertEqual(self.agent.vhostusers[1].mac_address, mac)
225 239
 
226 240
     def test_clear_classifier_table_con1(self):
@@ -229,7 +243,7 @@ class SppAgentTestCase(base.BaseTestCase):
229 243
         self.agent.vhostusers[1] = mock.Mock()
230 244
         self.agent.vhostusers[1].mac_address = mac
231 245
 
232
-        ret = self.agent.clear_classifier_table(1, mac)
246
+        ret = self.agent.clear_classifier_table(1, mac, None)
233 247
         self.assertEqual(ret, None)
234 248
         count = self.agent.spp_vf_api.clear_classifier_table.call_count
235 249
         self.assertEqual(count, 0)
@@ -240,9 +254,23 @@ class SppAgentTestCase(base.BaseTestCase):
240 254
         self.agent.vhostusers[1] = mock.Mock()
241 255
         self.agent.vhostusers[1].mac_address = mac
242 256
 
243
-        self.agent.clear_classifier_table(1, mac)
257
+        self.agent.clear_classifier_table(1, mac, None)
244 258
         count = self.agent.spp_vf_api.clear_classifier_table.call_count
245 259
         self.assertEqual(count, 1)
260
+        self.assertEqual(self.agent.spp_vf_api.flush.call_count, 1)
261
+        self.assertEqual(self.agent.vhostusers[1].mac_address, 'unuse')
262
+
263
+    def test_clear_classifier_table_with_vlan(self):
264
+        mac = '12:ab:34:cd:56:ef'
265
+        self.agent.vhostusers[1] = mock.Mock()
266
+        self.agent.vhostusers[1].mac_address = mac
267
+
268
+        self.agent.clear_classifier_table(1, mac, 10)
269
+        self.assertEqual(self.agent.spp_vf_api.port_add.call_count, 2)
270
+        self.assertEqual(self.agent.spp_vf_api.port_del.call_count, 2)
271
+        cnt = self.agent.spp_vf_api.clear_classifier_table_with_vlan.call_count
272
+        self.assertEqual(cnt, 1)
273
+        self.assertEqual(self.agent.spp_vf_api.flush.call_count, 1)
246 274
         self.assertEqual(self.agent.vhostusers[1].mac_address, 'unuse')
247 275
 
248 276
     @mock.patch('networking_spp.agent.spp_agent.SppAgent.set_classifier_table')
@@ -254,8 +282,8 @@ class SppAgentTestCase(base.BaseTestCase):
254 282
         self.agent.host = 'host1'
255 283
         key = '/spp/openstack/port_status/host1/111'
256 284
 
257
-        self.agent._plug_port(port_id, vhost_id, mac)
258
-        m_set.assert_called_with(vhost_id, mac)
285
+        self.agent._plug_port(port_id, vhost_id, mac, None)
286
+        m_set.assert_called_with(vhost_id, mac, None)
259 287
         self.agent.etcd.put.assert_called_with(key, "up")
260 288
 
261 289
     @mock.patch('networking_spp.common.etcd_key.bind_port_key')
@@ -281,8 +309,8 @@ class SppAgentTestCase(base.BaseTestCase):
281 309
         self.agent.vhostusers = {1: vhostuser}
282 310
         m_vhost_key.return_value = 'key'
283 311
 
284
-        self.agent._unplug_port(port_id, vhost_id, mac)
285
-        m_clear.assert_called_with(vhost_id, mac)
312
+        self.agent._unplug_port(port_id, vhost_id, mac, None)
313
+        m_clear.assert_called_with(vhost_id, mac, None)
286 314
         m_vhost_key.assert_called_with('host', 'phy_net', vhost_id)
287 315
         self.agent.etcd.replace.assert_called_once()
288 316
         m_bind_port_key.assert_called_with('host', port_id)
@@ -308,18 +336,19 @@ class SppAgentTestCase(base.BaseTestCase):
308 336
         self.agent.etcd.get.side_effect = [value, 'plug']
309 337
 
310 338
         self.agent._do_plug_unplug(port_id)
311
-        m_plug_port.assert_called_with(port_id, 1, '12:34:56:78:90:ab')
339
+        m_plug_port.assert_called_with(port_id, 1, '12:34:56:78:90:ab', None)
312 340
 
313 341
     @mock.patch('networking_spp.agent.spp_agent.SppAgent._unplug_port')
314 342
     def test_do_plug_unplug_con3(self, m_unplug_port):
315 343
         # conditions to exec the else statement
316 344
         port_id = 111
317
-        data = {"vhost_id": 1, 'mac_address': '12:34:56:78:90:ab'}
345
+        data = {"vhost_id": 1, 'mac_address': '12:34:56:78:90:ab',
346
+                'vlan_id': 10}
318 347
         value = json.dumps(data)
319
-        self.agent.etcd.get.side_effect = [value, '']
348
+        self.agent.etcd.get.side_effect = [value, 'unplug']
320 349
 
321 350
         self.agent._do_plug_unplug(port_id)
322
-        m_unplug_port.assert_called_with(port_id, 1, '12:34:56:78:90:ab')
351
+        m_unplug_port.assert_called_with(port_id, 1, '12:34:56:78:90:ab', 10)
323 352
 
324 353
     @mock.patch('networking_spp.common.etcd_key.action_host_prefix')
325 354
     @mock.patch('networking_spp.agent.spp_agent.SppAgent._do_plug_unplug')

+ 59
- 8
networking_spp/tests/unit/test_spp_api.py View File

@@ -75,6 +75,41 @@ class SppVfApiTestCase(base.BaseTestCase):
75 75
         self.spp_api.port_add(self.sec_id, port, direction, comp_name)
76 76
         m_exec_command.assert_called_with(self.sec_id, command)
77 77
 
78
+    @mock.patch('networking_spp.agent.spp_api.SppVfApi'
79
+                '._exec_command')
80
+    def test_port_add_add_vlantag(self, m_exec_command):
81
+        port = 'port'
82
+        direction = 'd'
83
+        comp_name = 'cn'
84
+        op = 'add_vlantag'
85
+        vlan_id = 10
86
+        command = "port add %s %s %s %s %s 0" % (port, direction, comp_name,
87
+                                                 op, vlan_id)
88
+        self.spp_api.port_add(self.sec_id, port, direction, comp_name,
89
+                              op, vlan_id)
90
+        m_exec_command.assert_called_with(self.sec_id, command)
91
+
92
+    @mock.patch('networking_spp.agent.spp_api.SppVfApi'
93
+                '._exec_command')
94
+    def test_port_add_del_vlantag(self, m_exec_command):
95
+        port = 'port'
96
+        direction = 'd'
97
+        comp_name = 'cn'
98
+        op = 'del_vlantag'
99
+        command = "port add %s %s %s %s" % (port, direction, comp_name, op)
100
+        self.spp_api.port_add(self.sec_id, port, direction, comp_name, op)
101
+        m_exec_command.assert_called_with(self.sec_id, command)
102
+
103
+    @mock.patch('networking_spp.agent.spp_api.SppVfApi'
104
+                '._exec_command')
105
+    def test_port_del(self, m_exec_command):
106
+        port = 'port'
107
+        direction = 'd'
108
+        comp_name = 'cn'
109
+        command = "port del %s %s %s" % (port, direction, comp_name)
110
+        self.spp_api.port_del(self.sec_id, port, direction, comp_name)
111
+        m_exec_command.assert_called_with(self.sec_id, command)
112
+
78 113
     @mock.patch('networking_spp.agent.spp_api.SppVfApi'
79 114
                 '._exec_command')
80 115
     def test_flush(self, m_exec_command):
@@ -89,24 +124,40 @@ class SppVfApiTestCase(base.BaseTestCase):
89 124
 
90 125
     @mock.patch('networking_spp.agent.spp_api.SppVfApi'
91 126
                 '._exec_command')
92
-    @mock.patch('networking_spp.agent.spp_api.SppVfApi'
93
-                '.flush')
94
-    def test_set_classifier_table(self, m_flush, m_exec_command):
127
+    def test_set_classifier_table(self, m_exec_command):
95 128
         mac = 'mac'
96 129
         port = 'port'
97 130
         command = "classifier_table add mac %s %s" % (mac, port)
98 131
         self.spp_api.set_classifier_table(self.sec_id, mac, port)
99 132
         m_exec_command.assert_called_with(self.sec_id, command)
100
-        m_flush.assert_called_with(self.sec_id)
101 133
 
102 134
     @mock.patch('networking_spp.agent.spp_api.SppVfApi'
103 135
                 '._exec_command')
104
-    @mock.patch('networking_spp.agent.spp_api.SppVfApi'
105
-                '.flush')
106
-    def test_clear_classifier_table(self, m_flush, m_exec_command):
136
+    def test_clear_classifier_table(self, m_exec_command):
107 137
         mac = 'mac'
108 138
         port = 'port'
109 139
         command = "classifier_table del mac %s %s" % (mac, port)
110 140
         self.spp_api.clear_classifier_table(self.sec_id, mac, port)
111 141
         m_exec_command.assert_called_with(self.sec_id, command)
112
-        m_flush.assert_called_with(self.sec_id)
142
+
143
+    @mock.patch('networking_spp.agent.spp_api.SppVfApi'
144
+                '._exec_command')
145
+    def test_set_classifier_table_with_vlan(self, m_exec_command):
146
+        mac = 'mac'
147
+        port = 'port'
148
+        vlan_id = 10
149
+        command = "classifier_table add vlan %s %s %s" % (vlan_id, mac, port)
150
+        self.spp_api.set_classifier_table_with_vlan(self.sec_id, mac, port,
151
+                                                    vlan_id)
152
+        m_exec_command.assert_called_with(self.sec_id, command)
153
+
154
+    @mock.patch('networking_spp.agent.spp_api.SppVfApi'
155
+                '._exec_command')
156
+    def test_clear_classifier_table_with_vlan(self, m_exec_command):
157
+        mac = 'mac'
158
+        port = 'port'
159
+        vlan_id = 10
160
+        command = "classifier_table del vlan %s %s %s" % (vlan_id, mac, port)
161
+        self.spp_api.clear_classifier_table_with_vlan(self.sec_id, mac, port,
162
+                                                      vlan_id)
163
+        m_exec_command.assert_called_with(self.sec_id, command)

+ 4
- 2
networking_spp/tests/unit/test_spp_manager.py View File

@@ -15,7 +15,6 @@
15 15
 
16 16
 import json
17 17
 import mock
18
-from time import sleep
19 18
 
20 19
 from networking_spp.agent import spp_manager
21 20
 from networking_spp.agent.spp_manager import SPP_PRIMATY_SERVICE
@@ -296,5 +295,8 @@ class SppManagerTestCase(base.BaseTestCase):
296 295
         self.assertEqual(m_wait_service.call_count, 0)
297 296
 
298 297
     def test_wait_service_initialized(self):
298
+        def dummy(sec):
299
+            pass
300
+
299 301
         # exec try statement
300
-        self.assertEqual(None, spp_manager._wait_service_initialized(sleep, 2))
302
+        self.assertEqual(None, spp_manager._wait_service_initialized(dummy, 2))

Loading…
Cancel
Save