Browse Source

Fix updating Ucast_Macs_Remote entry in removing port

In case of VM/router/DHCP ports, Ucast_Macs_Remote entory should be
removed on deleting these ports. In addition, this commit includes
some refactor.

Change-Id: Ief913c7605657e03f9d297cf5839e73d3c0fff42
tags/7.0.0^0
Yushiro FURUKAWA 1 year ago
parent
commit
25c19efb5d

+ 2
- 1
networking_fujitsu/ml2/cfab/mech_cfab.py View File

@@ -1,4 +1,4 @@
1
-# Copyright 2015-2017 FUJITSU LIMITED
1
+# Copyright 2015-2018 FUJITSU LIMITED
2 2
 #
3 3
 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
4 4
 #    not use this file except in compliance with the License. You may obtain
@@ -127,6 +127,7 @@ class CFABMechanismDriver(api.MechanismDriver):
127 127
         Case2: Otherwise
128 128
                    Associate the assigned MAC address to the portprofile.
129 129
         """
130
+
130 131
         port = mech_context.current
131 132
         network = mech_context.network
132 133
         if utils.is_baremetal(port):

+ 2
- 16
networking_fujitsu/ml2/common/ovsdb/ovsdb_writer.py View File

@@ -1,4 +1,4 @@
1
-# Copyright 2017 FUJITSU LIMITED
1
+# Copyright 2017-2018 FUJITSU LIMITED
2 2
 #
3 3
 #   Licensed under the Apache License, Version 2.0 (the "License"); you may
4 4
 #   not use this file except in compliance with the License. You may obtain
@@ -28,6 +28,7 @@ LOG = logging.getLogger(__name__)
28 28
 
29 29
 class OVSDBWriter(base_connection.BaseConnection):
30 30
     """Performs transactions to OVSDB server tables."""
31
+
31 32
     def __init__(self, ovsdb_ip, ovsdb_port):
32 33
         super(OVSDBWriter, self).__init__(ovsdb_ip, ovsdb_port)
33 34
 
@@ -160,7 +161,6 @@ class OVSDBWriter(base_connection.BaseConnection):
160 161
         :param logical_switch_name: Neutron network uuid, but delete all '-'
161 162
                                     to make sure the length is within 32.
162 163
         :type logical_switch_name: string
163
-
164 164
         :returns: None
165 165
         """
166 166
 
@@ -182,7 +182,6 @@ class OVSDBWriter(base_connection.BaseConnection):
182 182
         :param logical_switch_name: Neutron network uuid, but delete all '-'
183 183
                                     to make sure the length is within 32.
184 184
         :type logical_switch_name: string
185
-
186 185
         :returns: UUID of ROW in Logical_Switch table.
187 186
         :rtype: uuid
188 187
         """
@@ -212,7 +211,6 @@ class OVSDBWriter(base_connection.BaseConnection):
212 211
 
213 212
         :param logical_switch_uuid: UUID of ROW in Logical_Switch table.
214 213
         :type logical_switch_uuid: uuid
215
-
216 214
         :returns: None
217 215
         """
218 216
 
@@ -240,7 +238,6 @@ class OVSDBWriter(base_connection.BaseConnection):
240 238
         :param logical_switch_uuid: UUID of logical_switch in the binding-pair
241 239
                                     mapping.
242 240
         :type logical_switch_uuid: uuid
243
-
244 241
         :returns: vlanid in the binding-pair mapping.
245 242
         :rtype: integer
246 243
         """
@@ -290,7 +287,6 @@ class OVSDBWriter(base_connection.BaseConnection):
290 287
         :param logical_switch_uuid: UUID of logical_switch in the binding-pair
291 288
                                     mapping.
292 289
         :type logical_switch_uuid: uuid
293
-
294 290
         :returns: None
295 291
         """
296 292
 
@@ -315,7 +311,6 @@ class OVSDBWriter(base_connection.BaseConnection):
315 311
 
316 312
         :param port_mac: MAC address of physical port.
317 313
         :type port_mac: string
318
-
319 314
         :returns: list of ROWs information of the given port_mac in
320 315
                   Ucast_Macs_Local table.
321 316
         :rtype: list
@@ -345,7 +340,6 @@ class OVSDBWriter(base_connection.BaseConnection):
345 340
 
346 341
         :param port_mac: MAC address of physical port.
347 342
         :type port_mac: string
348
-
349 343
         :returns: None
350 344
         """
351 345
 
@@ -365,7 +359,6 @@ class OVSDBWriter(base_connection.BaseConnection):
365 359
 
366 360
         :param dst_ip: IP address of physical locator.
367 361
         :type dst_ip: string
368
-
369 362
         :returns: uuid of ROW of the given dst_ip in Physical_Locator table.
370 363
         :rtype: uuid
371 364
         """
@@ -399,7 +392,6 @@ class OVSDBWriter(base_connection.BaseConnection):
399 392
         :type locator_uuid: uuid
400 393
         :param MAC_value: MAC address of NIC of baremetal server.
401 394
         :type MAC_value: string
402
-
403 395
         :returns: None
404 396
         """
405 397
 
@@ -429,7 +421,6 @@ class OVSDBWriter(base_connection.BaseConnection):
429 421
         :type locator_ip: string
430 422
         :param MAC_value: MAC address of NIC of baremetal server.
431 423
         :type MAC_value: string
432
-
433 424
         :returns: None
434 425
         """
435 426
 
@@ -457,7 +448,6 @@ class OVSDBWriter(base_connection.BaseConnection):
457 448
 
458 449
         :param port_mac: MAC address of VM port.
459 450
         :type port_mac: string
460
-
461 451
         :returns: list of ROWs information of the given port_mac in
462 452
                   Ucast_Macs_Remote table.
463 453
         :rtype: list
@@ -487,7 +477,6 @@ class OVSDBWriter(base_connection.BaseConnection):
487 477
 
488 478
         :param port_mac: MAC address of VM port.
489 479
         :type port_mac: string
490
-
491 480
         :returns: None
492 481
         """
493 482
 
@@ -521,7 +510,6 @@ class OVSDBWriter(base_connection.BaseConnection):
521 510
         :param locator_uuid: uuid of physical locator (remote VTEP) where
522 511
                              the port is binding to.
523 512
         :type locator_uuid: uuid
524
-
525 513
         :returns: None
526 514
         """
527 515
 
@@ -563,7 +551,6 @@ class OVSDBWriter(base_connection.BaseConnection):
563 551
         :param locator_IP: IP address of physical locator (remote VTEP) where
564 552
                            the port is binding to.
565 553
         :type locator_uuid: string
566
-
567 554
         :returns: None
568 555
         """
569 556
 
@@ -596,7 +583,6 @@ class OVSDBWriter(base_connection.BaseConnection):
596 583
                           format: <slot/port>
597 584
                           example: 0/2
598 585
         :type port_name: string
599
-
600 586
         :returns: None
601 587
         """
602 588
 

+ 1
- 2
networking_fujitsu/ml2/common/tunnel_caller.py View File

@@ -1,4 +1,4 @@
1
-# Copyright 2017 FUJITSU LIMITED
1
+# Copyright 2017-2018 FUJITSU LIMITED
2 2
 #
3 3
 #   Licensed under the Apache License, Version 2.0 (the "License"); you may
4 4
 #   not use this file except in compliance with the License. You may obtain
@@ -34,7 +34,6 @@ class TunnelCaller(object):
34 34
         :type context: A Neutron context object.
35 35
         :param tunnel_ip: An endpoint IP address of vxlan.
36 36
         :type tunnel_ip: string
37
-
38 37
         :returns: None
39 38
         """
40 39
 

+ 6
- 11
networking_fujitsu/ml2/common/utils.py View File

@@ -1,4 +1,4 @@
1
-# Copyright 2015-2017 FUJITSU LIMITED
1
+# Copyright 2015-2018 FUJITSU LIMITED
2 2
 #
3 3
 # Licensed under the Apache License, Version 2.0 (the "License");
4 4
 # you may not use this file except in compliance with the License.
@@ -32,7 +32,6 @@ def eliminate_val(source, reject):
32 32
     :type source: string
33 33
     :param reject: a list of integer to reject. ex. [1, 2]
34 34
     :type reject: list of integer
35
-
36 35
     :returns: a string separated with "," like an example
37 36
     :rtype: string
38 37
     """
@@ -120,10 +119,10 @@ def get_network_type(network):
120 119
 
121 120
     :param network: NetworkContext or network dict
122 121
     :type network: NetworkContext or dict
123
-
124 122
     :returns network_type: 'vlan', 'vxlan', 'local', 'flat' and 'geneve'
125 123
     :rtype: string
126 124
     """
125
+
127 126
     return _get_provider_attribute(network, 'NETWORK_TYPE')
128 127
 
129 128
 
@@ -132,10 +131,10 @@ def get_segmentation_id(network):
132 131
 
133 132
     :param network: NetworkContext or network dict
134 133
     :type network: NetworkContext or dict
135
-
136 134
     :returns segmentation_id: VLANID('vlan') or VNI('vxlan')
137 135
     :rtype: integer
138 136
     """
137
+
139 138
     return _get_provider_attribute(network, 'SEGMENTATION_ID')
140 139
 
141 140
 
@@ -144,10 +143,10 @@ def get_physical_network(network):
144 143
 
145 144
     :param network: NetworkContext or network dict
146 145
     :type network: NetworkContext or dict
147
-
148 146
     :returns physical_network: physical network name for the network
149 147
     :rtype: string
150 148
     """
149
+
151 150
     return _get_provider_attribute(network, 'PHYSICAL_NETWORK')
152 151
 
153 152
 
@@ -156,7 +155,6 @@ def get_physical_connectivity(port):
156 155
 
157 156
     :param port: a dictionary of neutron port
158 157
     :type port: dictionary
159
-
160 158
     :returns lli: "local_link_information" as follows
161 159
                  [{"switch_id": "MAC_of_switch", "port_id": "1/1/0/1",
162 160
                   "switch_info": "switch_name"}]
@@ -180,7 +178,6 @@ def has_lli(port):
180 178
 
181 179
     :param port: a port dictionary
182 180
     :type port: dictionary
183
-
184 181
     :returns True(a port has 'local_link_information') or False(otherwise)
185 182
     :rtype: boolean
186 183
     """
@@ -193,7 +190,6 @@ def is_baremetal(port):
193 190
 
194 191
     :param port: a dictionary of neutron port
195 192
     :type port: dictionary
196
-
197 193
     :returns: True(vnic_type is baremetal) or False(otherwise)
198 194
     :rtype: boolean
199 195
     """
@@ -207,7 +203,6 @@ def is_lag(local_link_information):
207 203
 
208 204
     :param local_link_information: physical connectivity information
209 205
     :type local_link_information: list of dict
210
-
211 206
     :returns: True(mode is LAG) or False(otherwise)
212 207
     :rtype: boolean
213 208
     """
@@ -216,13 +211,13 @@ def is_lag(local_link_information):
216 211
 
217 212
 
218 213
 def is_unbound(context):
219
-    """Judge current port object is unbound or not.
214
+    """Judge current port object is changed into 'unbound' status or not.
220 215
 
221 216
     :param context: port context
222 217
     :type context: PortContext object
223
-
224 218
     :returns: True(port is unbound) or False(otherwise)
225 219
     :rtype: boolean
226 220
     """
221
+
227 222
     return (context.current[pb_def.VIF_TYPE] == pb_def.VIF_TYPE_UNBOUND and
228 223
             context.original[pb_def.VIF_TYPE] == pb_def.VIF_TYPE_OTHER)

+ 19
- 31
networking_fujitsu/ml2/fossw/client.py View File

@@ -1,4 +1,4 @@
1
-# Copyright 2017 FUJITSU LIMITED
1
+# Copyright 2017-2018 FUJITSU LIMITED
2 2
 #
3 3
 #   Licensed under the Apache License, Version 2.0 (the "License"); you may
4 4
 #   not use this file except in compliance with the License. You may obtain
@@ -50,13 +50,13 @@ class FOSSWClient(object):
50 50
         If exists session for specified target, reuse it otherwise reconnect.
51 51
         In order to get command result correctly, execute 'terminal length 0'
52 52
         at the beginning of the session.
53
+
53 54
         :param ip: a ip address of FOS switch
54 55
         :type ip: string
55 56
         :returns: None
56 57
         :rtype: None
57
-
58 58
         """
59
-        if not self.lookup(ip):
59
+        if not self._lookup(ip):
60 60
             self._reconnect(ip)
61 61
             self._exec_command(TERMINAL_LENGTH_0)
62 62
 
@@ -67,8 +67,8 @@ class FOSSWClient(object):
67 67
         :type ip: string
68 68
         :returns: None
69 69
         :rtypes: None
70
-
71 70
         """
71
+
72 72
         self.disconnect()
73 73
         method = "connect"
74 74
         retry_count = 0
@@ -112,8 +112,8 @@ class FOSSWClient(object):
112 112
 
113 113
         :returns: None
114 114
         :rtypes: None
115
-
116 115
         """
116
+
117 117
         if self.ssh:
118 118
             self.ssh.close()
119 119
             self.ssh = None
@@ -159,15 +159,13 @@ class FOSSWClient(object):
159 159
             raise FOSSWClientException(method)
160 160
         return formatted
161 161
 
162
-    def lookup(self, target):
162
+    def _lookup(self, target):
163 163
         """Check exist session for specified IP.
164 164
 
165 165
         :param target: IP address of a target host
166 166
         :type target: string
167
-
168 167
         :returns: exist(True) or not exist(False)
169 168
         :rtype: bool
170
-
171 169
         """
172 170
         if self.ssh:
173 171
             if self.ssh._host_keys:
@@ -181,10 +179,8 @@ class FOSSWClient(object):
181 179
 
182 180
         :param segmentation_id: id of VLAN to be created.
183 181
         :type segmentation_id: string
184
-
185 182
         :returns: received message from FOS switch
186 183
         :rtype: string
187
-
188 184
         """
189 185
         self.change_mode(MODE_VLAN)
190 186
         cmd = self._format_command("vlan {vlanid}", vlanid=segmentation_id)
@@ -195,11 +191,10 @@ class FOSSWClient(object):
195 191
 
196 192
         :param segmentation_id: id of VLAN to be deleted.
197 193
         :type segmentation_id: string
198
-
199 194
         :returns: None
200 195
         :rtype: None
201
-
202 196
         """
197
+
203 198
         self.change_mode(MODE_VLAN)
204 199
         cmd = self._format_command("no vlan {vlanid}", vlanid=segmentation_id)
205 200
         if "Failed to delete" in self._exec_command(cmd):
@@ -212,11 +207,10 @@ class FOSSWClient(object):
212 207
         :type segmentation_id: string
213 208
         :param port_id: the number of physical port on FOS switch
214 209
         :type port_id: string
215
-
216 210
         :returns: None
217 211
         :rtype: None
218
-
219 212
         """
213
+
220 214
         method = "set_vlan"
221 215
         self.change_mode(MODE_INTERFACE, port_id)
222 216
         self._exec_command("switchport mode access")
@@ -232,11 +226,10 @@ class FOSSWClient(object):
232 226
 
233 227
         :param port_id: the number of physical port on FOS switch
234 228
         :type port_id: string
235
-
236 229
         :returns: None
237 230
         :rtype: None
238
-
239 231
         """
232
+
240 233
         self.change_mode(MODE_INTERFACE, port_id)
241 234
         self._exec_command("no switchport access vlan")
242 235
         self._exec_command("no switchport mode")
@@ -248,11 +241,10 @@ class FOSSWClient(object):
248 241
         :type port: string
249 242
         :param logicalport: the number of logical port on FOS switch
250 243
         :type logicalport: string
251
-
252 244
         :returns: None
253 245
         :rtype: None
254
-
255 246
         """
247
+
256 248
         self.change_mode(MODE_INTERFACE, ifname=logicalport)
257 249
         self._exec_command("no port-channel static")
258 250
 
@@ -268,10 +260,10 @@ class FOSSWClient(object):
268 260
         :param logicalport: the number of logicalport
269 261
             (optional, default: "none")
270 262
         :type logicalport: string
271
-
272 263
         :returns: the ID of VPC or None.
273 264
         :rtype: string
274 265
         """
266
+
275 267
         # TODO(yushiro): Replace regexp
276 268
         for i in iter(range(1, MAX_VPC_ID + 1)):
277 269
             cmd = 'show vpc {vid} | include "Port channel"'.format(vid=str(i))
@@ -297,11 +289,10 @@ class FOSSWClient(object):
297 289
         :type logicalport: string
298 290
         :param vpcid: id of VPC
299 291
         :type vpcid: string
300
-
301 292
         :returns: None
302 293
         :rtype: None
303
-
304 294
         """
295
+
305 296
         self.change_mode(MODE_INTERFACE, ifname=logicalport)
306 297
         self._exec_command("vpc {vpcid}".format(vpcid=vpcid))
307 298
 
@@ -310,8 +301,8 @@ class FOSSWClient(object):
310 301
 
311 302
         :returns: IP address of peerlink partner
312 303
         :rtype: string
313
-
314 304
         """
305
+
315 306
         # TODO(yushiro): Replace regexp
316 307
         ret = self._exec_command('show vpc peer-keepalive | include "Peer '
317 308
                                  'IP address"')
@@ -331,8 +322,8 @@ class FOSSWClient(object):
331 322
         :returns: the number of logical port which associated with specified
332 323
                   physical port
333 324
         :rtype: string
334
-
335 325
         """
326
+
336 327
         # Find related lag_port with specified portname
337 328
         if portname:
338 329
             cmd = "show running-config interface %s" % portname
@@ -349,8 +340,8 @@ class FOSSWClient(object):
349 340
 
350 341
         :returns: MAC address of FOS switch
351 342
         :rtype: string
352
-
353 343
         """
344
+
354 345
         cmd = 'show hardware eeprom | include "Base MAC Address"'
355 346
         res = self._exec_command(cmd)
356 347
         if res:
@@ -364,11 +355,10 @@ class FOSSWClient(object):
364 355
         :type port: string
365 356
         :param logicalport: the number of logical port on FOS switch
366 357
         :type logicalport: string
367
-
368 358
         :returns: None
369 359
         :rtype: None
370
-
371 360
         """
361
+
372 362
         self.change_mode(MODE_INTERFACE, ifname=port)
373 363
         res = self._exec_command(
374 364
             "deleteport {lo_port}".format(lo_port=logicalport))
@@ -386,11 +376,10 @@ class FOSSWClient(object):
386 376
         :type logicalport: string
387 377
         :param vpcid: id of VPC
388 378
         :type vpcid: string
389
-
390 379
         :returns: None
391 380
         :rtype: None
392
-
393 381
         """
382
+
394 383
         self.change_mode(MODE_INTERFACE, ifname=logicalport)
395 384
         res = self._exec_command("no vpc {vpcid}".format(vpcid=vpcid))
396 385
         if "Failed to remove" in res:
@@ -403,8 +392,8 @@ class FOSSWClient(object):
403 392
 
404 393
         :returns: None
405 394
         :rtypes: None
406
-
407 395
         """
396
+
408 397
         self._exec_command("copy system:running-config nvram:startup-config")
409 398
         self._exec_command("y")
410 399
         self._exec_command("")
@@ -417,11 +406,10 @@ class FOSSWClient(object):
417 406
         :param ifname: the number of physical port on FOS switch
418 407
             (optional, default: None)
419 408
         :type ifname: string
420
-
421 409
         :returns: None
422 410
         :rtype: None
423
-
424 411
         """
412
+
425 413
         # Move to Privileged EXEC mode.
426 414
         prompt = self._exec_command(END)
427 415
         if ") >" in prompt:

+ 14
- 20
networking_fujitsu/ml2/fossw/fossw_vlandriver.py View File

@@ -1,4 +1,4 @@
1
-# Copyright 2017 FUJITSU LIMITED
1
+# Copyright 2017-2018 FUJITSU LIMITED
2 2
 #
3 3
 #   Licensed under the Apache License, Version 2.0 (the "License"); you may
4 4
 #   not use this file except in compliance with the License. You may obtain
@@ -46,14 +46,13 @@ class FOSSWVlanDriver(object):
46 46
     def get_switch_mac_ip_pair(self, ips):
47 47
         """Get and create pair of switch's MAC address and IP address.
48 48
 
49
-        :param ips: list of IP address of FOS switch
50
-        :type ips: list of IP address strings
51
-
52
-        :returns: the dictionary which stores pair of  MAC address and IP
53
-                  address
54
-        :rtype: dictionary of MAC address and IP address
55
-
49
+        :param ips: List of IP address of FOS switch
50
+        :type ips: List of IP address strings
51
+        :returns: A dictionary which stores pair of MAC address and IP
52
+                  address like {'fe:54:00:23:33:9a': '192.168.50.1'}
53
+        :rtype: A dictionary of MAC address and IP address
56 54
         """
55
+
57 56
         switches_mac_ip_pair = {}
58 57
         for ip in ips:
59 58
             self.client.connect(ip)
@@ -73,11 +72,10 @@ class FOSSWVlanDriver(object):
73 72
         :type ip: string
74 73
         :param vlanid: ID of VLAN to be created
75 74
         :type vlanid: string
76
-
77 75
         :returns: None
78 76
         :rtype: None
79
-
80 77
         """
78
+
81 79
         method = 'create_vlan'
82 80
         try:
83 81
             self.client.connect(ip)
@@ -96,11 +94,10 @@ class FOSSWVlanDriver(object):
96 94
         :type ip: string
97 95
         :param vlanid: ID of VLAN to be deleted
98 96
         :type vlanid: string
99
-
100 97
         :returns: None
101 98
         :rtype: None
102
-
103 99
         """
100
+
104 101
         method = 'delete_vlan'
105 102
         try:
106 103
             self.client.connect(ip)
@@ -122,11 +119,10 @@ class FOSSWVlanDriver(object):
122 119
         :param ip_mac_pairs: the pair of MAC address and IP address of FOS
123 120
                              switch
124 121
         :type ip_mac_pairs: dictionary
125
-
126 122
         :returns: None
127 123
         :rtype: None
128
-
129 124
         """
125
+
130 126
         method = "setup_vlan"
131 127
         sw_mac = lli[0]['switch_id']
132 128
         port_id = lli[0]['port_id']
@@ -158,11 +154,10 @@ class FOSSWVlanDriver(object):
158 154
         :param vlanid: the VLANID to configure. If it is not set, it will skip
159 155
                        VLAN configuration.
160 156
         :type vlanid: Integer
161
-
162 157
         :returns: mac_lag_map MAC address and LAG port ID pair
163 158
         :rtype: dictionary
164
-
165 159
         """
160
+
166 161
         method = "setup_lag"
167 162
         mlag = False
168 163
         unique_mac_list = sorted(list(set([lli['switch_id'] for lli in llis])))
@@ -238,11 +233,10 @@ class FOSSWVlanDriver(object):
238 233
         :param ip_mac_pairs: the pair of MAC address and IP address of FOS
239 234
                              switches
240 235
         :type ip_mac_pairs: dictionary
241
-
242 236
         :returns: Result of validation
243 237
         :rtype: Boolean
244
-
245 238
         """
239
+
246 240
         try:
247 241
             ips = self._validate_lli_macs_with_config(macs, ip_mac_pairs)
248 242
             self.client.connect(ips[0])
@@ -264,6 +258,7 @@ class FOSSWVlanDriver(object):
264 258
                              switches
265 259
         :type ip_mac_pairs: dictionary
266 260
         """
261
+
267 262
         method = "clear_vlan"
268 263
         sw_mac = lli[0]['switch_id']
269 264
         port_id = lli[0]['port_id']
@@ -292,11 +287,10 @@ class FOSSWVlanDriver(object):
292 287
         :param ip_mac_pairs: the pair of MAC address and IP address of FOS
293 288
                              switches
294 289
         :type ip_mac_pairs: dictionary
295
-
296 290
         :returns: None
297 291
         :rtype: None
298
-
299 292
         """
293
+
300 294
         method = "clear_lag"
301 295
         mlag = None
302 296
         unique_mac_list = sorted(list(set([lli['switch_id'] for lli in llis])))

+ 12
- 12
networking_fujitsu/ml2/fossw/fossw_vxlandriver.py View File

@@ -1,4 +1,4 @@
1
-# Copyright 2017 FUJITSU LIMITED
1
+# Copyright 2017-2018 FUJITSU LIMITED
2 2
 #
3 3
 #   Licensed under the Apache License, Version 2.0 (the "License"); you may
4 4
 #   not use this file except in compliance with the License. You may obtain
@@ -66,6 +66,7 @@ class FOSSWVxlanDriver(object):
66 66
 
67 67
     def save_all_fossw(self):
68 68
         """Save running-config to startup-config in all FOS switches."""
69
+
69 70
         for fossw_ip in self.fossw_ips:
70 71
             self.client.connect(fossw_ip)
71 72
             self.client.save_running_config()
@@ -75,6 +76,7 @@ class FOSSWVxlanDriver(object):
75 76
         """Update Neutron DB ml2_vxlan_endpoints table
76 77
 
77 78
         Update with VTEPs of all FOS switches.
79
+
78 80
         :returns: None
79 81
         """
80 82
 
@@ -125,11 +127,11 @@ class FOSSWVxlanDriver(object):
125 127
 
126 128
         We consider net_uuid is always unique, and both vni and net_uuid
127 129
         must be immutable. So there is not a update case.
130
+
128 131
         :param net_uuid: The uuid of Neutron network.
129 132
         :type net_uuid: string
130 133
         :param vni: The segment ID of Neutron network.
131 134
         :type vni: integer
132
-
133 135
         :returns: None
134 136
         """
135 137
 
@@ -145,9 +147,9 @@ class FOSSWVxlanDriver(object):
145 147
 
146 148
         We only consider deleting the existing Logical_Switch ROW.
147 149
         Also note that even it does not exit, the jsonrpc returns no error.
150
+
148 151
         :param net_uuid: The uuid of Neutron network.
149 152
         :type: string
150
-
151 153
         :returns: None
152 154
         """
153 155
 
@@ -182,14 +184,13 @@ class FOSSWVxlanDriver(object):
182 184
                      to.
183 185
         :type vni: integer
184 186
         :param lli: The local_link_information of the port.
185
-                    If it is a VM port, then [{}] should be given.
187
+                    If it is a VM port, then [] should be given.
186 188
         :type lli: list
187 189
         :param port: Dictionary of a port
188 190
         :type port: dictionary
189 191
         :param ip_mac_pairs: List of MAC(key) - IP(value) pairs of all FOS
190 192
                              switches.
191 193
         :type ip_mac_pairs: dictionary
192
-
193 194
         :returns: None
194 195
         """
195 196
 
@@ -247,6 +248,7 @@ class FOSSWVxlanDriver(object):
247 248
     def _update_ucast_macs_remote(self, logical_switch_name, mac, tunnel_ip,
248 249
                                   port_ips, ignore=None):
249 250
         """Update Ucast_Macs_Remote table in all FOS switches OVSDB."""
251
+
250 252
         for fossw_ip in self.fossw_ips:
251 253
             if ignore == fossw_ip:
252 254
                 continue
@@ -263,7 +265,7 @@ class FOSSWVxlanDriver(object):
263 265
                     ls_uuid, mac, port_ips, tunnel_ip)
264 266
 
265 267
     def reset_physical_port(self, lli, port, ip_mac_pairs, save=True):
266
-        """Remove setting of raw of Physical_Port table in FOS switch OVSDB.
268
+        """Remove setting of row of Physical_Port table in FOS switch OVSDB.
267 269
 
268 270
         ROWs with the same MAC address in Ucast_Macs_Local table and
269 271
         Ucast_Macs_Remote table are the target to extinct.
@@ -275,16 +277,16 @@ class FOSSWVxlanDriver(object):
275 277
         :param ip_mac_pairs: List of MAC(key) - IP(value) pairs of all FOS
276 278
                              switches.
277 279
         :type ip_mac_pairs: dictionary
278
-
279 280
         :returns: None
280 281
         """
281 282
 
282 283
         if lli:
283 284
             target = ip_mac_pairs[lli[0]['switch_id']]
284
-            port_id = lli[0]['port_id']
285
+            # If this method is callef from reset_physical_port_with_lag,
286
+            # sw_port_id should be logical port(for LAG)
287
+            sw_port_id = lli[0]['port_id']
285 288
             ovsdb_cli = ovsdb_writer.OVSDBWriter(target, self.ovsdb_port)
286
-            # TODO(yushiro): Need to send lag port in case of LAG
287
-            ovsdb_cli.reset_physical_port(port_id)
289
+            ovsdb_cli.reset_physical_port(sw_port_id)
288 290
 
289 291
         mac = port["mac_address"]
290 292
 
@@ -316,7 +318,6 @@ class FOSSWVxlanDriver(object):
316 318
         :param req_id: A request ID of network context which use for generate
317 319
                        new context.
318 320
         :type req_id: string
319
-
320 321
         :returns: None
321 322
         """
322 323
 
@@ -338,7 +339,6 @@ class FOSSWVxlanDriver(object):
338 339
         :param ip_mac_pairs: List of MAC(key) - IP(value) pairs of all FOS
339 340
                              switches.
340 341
         :type ip_mac_pairs: dictionary
341
-
342 342
         :returns: None
343 343
         """
344 344
 

+ 31
- 59
networking_fujitsu/ml2/fossw/mech_fossw.py View File

@@ -1,4 +1,4 @@
1
-# Copyright 2017 FUJITSU LIMITED
1
+# Copyright 2017-2018 FUJITSU LIMITED
2 2
 #
3 3
 #   Licensed under the Apache License, Version 2.0 (the "License"); you may
4 4
 #   not use this file except in compliance with the License. You may obtain
@@ -115,10 +115,8 @@ class FOSSWMechanismDriver(api.MechanismDriver):
115 115
 
116 116
         :param mech_context: context of network
117 117
         :type mech_context: NetworkContext
118
-
119 118
         :returns: None
120 119
         :rtype: None
121
-
122 120
         """
123 121
 
124 122
         network = net_context.current
@@ -143,11 +141,10 @@ class FOSSWMechanismDriver(api.MechanismDriver):
143 141
 
144 142
         :param vlanid: the ID of VLAN to be created
145 143
         :type vlanid: string
146
-
147 144
         :returns: None
148 145
         :rtype: None
149
-
150 146
         """
147
+
151 148
         method = 'create_network_postcommit'
152 149
         for ip in self.ips:
153 150
             try:
@@ -159,6 +156,7 @@ class FOSSWMechanismDriver(api.MechanismDriver):
159 156
 
160 157
     @log_helpers.log_method_call
161 158
     def create_network_postcommit_vxlan(self, net_uuid, seg_id):
159
+
162 160
         method = 'create_network_postcommit'
163 161
         try:
164 162
             self._vxlan_driver.create_logical_switch(net_uuid, seg_id)
@@ -181,7 +179,6 @@ class FOSSWMechanismDriver(api.MechanismDriver):
181 179
 
182 180
         :param net_context: context of network
183 181
         :type net_context: NetworkContext
184
-
185 182
         :returns: None
186 183
         :rtype: None
187 184
         """
@@ -206,11 +203,10 @@ class FOSSWMechanismDriver(api.MechanismDriver):
206 203
 
207 204
         :param vlanid: the ID of VLAN to be deleted
208 205
         :type vlanid: string
209
-
210 206
         :returns: None
211 207
         :rtypes: None
212
-
213 208
         """
209
+
214 210
         method = 'delete_network_postcommit'
215 211
         for ip in self.ips:
216 212
             try:
@@ -234,16 +230,17 @@ class FOSSWMechanismDriver(api.MechanismDriver):
234 230
     def delete_port_postcommit(self, mech_context):
235 231
         """Calls cleanup process for FOS switch.
236 232
 
237
-        Case1: Baremetal deploy with VLAN
238
-                   Clear VLAN/LAG for specified physical port.
239
-        Case2:
240
-                   Clear VXLAN/LAG for specified physical port.
241
-        Case3: Otherwise
242
-                   Do nothing.
233
+        Case1: 'network_type' is 'vlan' and the port is for baremetal
234
+                   Call clear VLAN/LAG for specified physical port.
235
+        Case2: 'network_type' is 'vxlan' and the port is for baremetal
236
+                   Call clear VXLAN/LAG for specified physical port.
237
+        Case3: 'network_type' is 'vxlan' and the port is for VM/DHCP/router
238
+                   Call clear VXLAN/LAG for specified physical port.
239
+        Case4: Otherwise
240
+                   Ignore
243 241
 
244 242
         :param mech_context: context of port
245 243
         :type mech_context: PortContext
246
-
247 244
         :returns: None
248 245
         :rtype: None
249 246
         """
@@ -266,6 +263,7 @@ class FOSSWMechanismDriver(api.MechanismDriver):
266 263
     @log_helpers.log_method_call
267 264
     def update_port_postcommit(self, context):
268 265
         """Update specified physical port on switch."""
266
+
269 267
         method = 'update_port_postcommit'
270 268
         port = context.current
271 269
         network = context.network
@@ -291,7 +289,7 @@ class FOSSWMechanismDriver(api.MechanismDriver):
291 289
             if (network_type != nl_const.TYPE_VXLAN or
292 290
                     vif_type == pb_def.VIF_TYPE_UNBOUND):
293 291
                 return
294
-            # currently supports only one segment per network
292
+            # Currently this driver supports only one segment per network.
295 293
             # Setup VXLAN for port which bound with DHCP, router, and vms.
296 294
             try:
297 295
                 self._vxlan_driver.update_physical_port(
@@ -313,7 +311,6 @@ class FOSSWMechanismDriver(api.MechanismDriver):
313 311
         :param params: a dictionary of the return value for
314 312
                         get_physical_net_params
315 313
         :type params: dictionary
316
-
317 314
         :returns: None
318 315
         :rtype: None
319 316
         """
@@ -363,8 +360,6 @@ class FOSSWMechanismDriver(api.MechanismDriver):
363 360
         try:
364 361
             call_target = target if params['lag'] else 'clear_vlan'
365 362
             clear_method = getattr(self._vlan_driver, call_target)
366
-            LOG.info("call %(target)s. params: %(params)s",
367
-                     {'target': call_target, 'params': params})
368 363
             clear_method(params['local_link_info'], self.switches_mac_ip_pair)
369 364
         except Exception:
370 365
             LOG.exception("Failed to clear vlan(%s)", params['vlanid'])
@@ -378,18 +373,20 @@ class FOSSWMechanismDriver(api.MechanismDriver):
378 373
         network = context.network
379 374
         if port[pb_def.VIF_TYPE] == pb_def.VIF_TYPE_UNBOUND:
380 375
             return
381
-        if not utils.has_lli(port):
382
-            LOG.warning('local_link_information not found in port %s', port)
383
-            return
376
+        # Returns empty list if port doesn't include 'local_link_information'
384 377
         lli = utils.get_physical_connectivity(port)
385 378
         try:
386 379
             if utils.is_lag(lli):
387
-                mac_lag_map = self._vlan_driver.clear_lag(
380
+                ret = self._vlan_driver.clear_lag(
388 381
                     lli, self.switches_mac_ip_pair)
389 382
                 self._vxlan_driver.reset_physical_port_with_lag(
390
-                    lli, port, self.switches_mac_ip_pair,
391
-                    mac_lag_map=mac_lag_map)
383
+                    lli, port, self.switches_mac_ip_pair, mac_lag_map=ret)
392 384
             else:
385
+                # In case of baremetal port
386
+                #   - 'lli' exists and 'vnic_type' is 'baremetal'
387
+                # In case of router/DHCP/VM port
388
+                #   - 'lli' is [](empty list)
389
+                #   - This method only removes Ucast_macs_Remote entry
393 390
                 self._vxlan_driver.reset_physical_port(
394 391
                     lli, port, self.switches_mac_ip_pair)
395 392
         except Exception:
@@ -415,10 +412,10 @@ class FOSSWMechanismDriver(api.MechanismDriver):
415 412
         :type port: dictionary
416 413
         :param network: a network object
417 414
         :type network: NetworkContext
418
-
419 415
         :returns: A dictionary parameters for baremetal deploy
420 416
         :rtype: dictionary
421 417
         """
418
+
422 419
         port = context.original if use_original else context.current
423 420
         network = context.network
424 421
         vlanid = utils.get_segmentation_id(network)
@@ -437,31 +434,22 @@ class FOSSWMechanismDriver(api.MechanismDriver):
437 434
         network = context.network
438 435
         if not is_supported(network):
439 436
             return
440
-        LOG.debug("Attempting to bind port %(port)s with vnic_type "
441
-                  "%(vnic_type)s on network %(network)s",
442
-                  {'port': port['id'], 'vnic_type': port[pb_def.VNIC_TYPE],
443
-                   'network': port['network_id']})
444 437
 
445 438
         network_type = utils.get_network_type(network)
446
-        to_bind = False
447
-
448 439
         if network_type == nl_const.TYPE_VXLAN:
449
-            # vxlan driver handles not only baremetal port, but vm, dhcp,
450
-            # router ports.
440
+            # VXLAN driver handles not only baremetal port, but VM/DHCP/router
451 441
             self.setup_vxlan(context)
452
-            to_bind = True
453
-        if utils.is_baremetal(port) and network_type == nl_const.TYPE_VLAN:
442
+        if network_type == nl_const.TYPE_VLAN and utils.is_baremetal(port):
454 443
             self.setup_vlan(self.get_physical_net_params(context))
455
-            to_bind = True
456
-        if to_bind:
457
-            context.set_binding(context.segments_to_bind[0][api.ID],
458
-                                pb_def.VIF_TYPE_OTHER, {},
459
-                                status=nl_const.PORT_STATUS_ACTIVE)
444
+
445
+        context.set_binding(context.segments_to_bind[0][api.ID],
446
+                            pb_def.VIF_TYPE_OTHER, {},
447
+                            status=nl_const.PORT_STATUS_ACTIVE)
460 448
 
461 449
     @log_helpers.log_method_call
462 450
     def setup_vxlan(self, context):
463 451
         """Update VXLAN from specified physical port on switch."""
464
-        # currently supports only one segment per network
452
+
465 453
         port = context.current
466 454
         seg_id = utils.get_segmentation_id(context.network)
467 455
         lli = utils.get_physical_connectivity(port)
@@ -486,8 +474,7 @@ def is_supported(network):
486 474
 
487 475
     :param network: a network object
488 476
     :type network: NetworkContext
489
-
490
-    :returns: True if network_type is supported and segmentation_id is included
477
+    :returns: True if network_type is supported and segmentation_id exists
491 478
               otherwise False
492 479
     :rtype: boolean
493 480
     """
@@ -497,18 +484,3 @@ def is_supported(network):
497 484
         LOG.warning("Network type(%s) is not supported. Skip it.", net_type)
498 485
         return False
499 486
     return True if utils.get_segmentation_id(network) else False
500
-
501
-
502
-def validate_baremetal_deploy(port_context, use_original=False):
503
-    """Validate baremetal deploy.
504
-
505
-    :param port_context: a PortContext object
506
-    :type port_context: PortContext
507
-
508
-    :returns: True if enable to baremetal deploy otherwise False
509
-    :rtype: boolean
510
-    """
511
-
512
-    port = port_context.original if use_original else port_context.current
513
-    network = port_context.network
514
-    return utils.is_baremetal(port) and is_supported(network)

+ 31
- 1
networking_fujitsu/tests/unit/ml2/fossw/test_mech_fossw.py View File

@@ -1,4 +1,4 @@
1
-# Copyright 2017 FUJITSU LIMITED
1
+# Copyright 2017-2018 FUJITSU LIMITED
2 2
 #
3 3
 # Licensed under the Apache License, Version 2.0 (the "License");
4 4
 # you may not use this file except in compliance with the License.
@@ -507,6 +507,26 @@ class TestFOSSWBaremetalPortsVxlan(TestFujitsuMechDriverV2):
507 507
             ml2_exc.MechanismDriverError,
508 508
             self.mech.update_port_postcommit, ctx)
509 509
 
510
+    def test_update_port_raises_setup_vlan(self):
511
+        ctx = self.prepare_dummy_context(net_type='vxlan',
512
+                                         vif_type='unbound',
513
+                                         set_original=True)
514
+        # Raise in setup_vlan method
515
+        self.mech._vxlan_driver.reset_physical_port.side_effect = Exception
516
+        self.assertRaises(
517
+            ml2_exc.MechanismDriverError,
518
+            self.mech.update_port_postcommit, ctx)
519
+
520
+    def test_update_port_raises_setup_vxlan(self):
521
+        ctx = self.prepare_dummy_context(net_type='vxlan',
522
+                                         vif_type='unbound',
523
+                                         set_original=True)
524
+        # Raise in setup_vxlan method
525
+        self.mech._vxlan_driver.reset_physical_port.side_effect = Exception
526
+        self.assertRaises(
527
+            ml2_exc.MechanismDriverError,
528
+            self.mech.update_port_postcommit, ctx)
529
+
510 530
     def test_delete_port(self):
511 531
         ctx = self.prepare_dummy_context(net_type='vxlan')
512 532
         self.mech.delete_port_postcommit(ctx)
@@ -528,6 +548,16 @@ class TestFOSSWBaremetalPortsVxlan(TestFujitsuMechDriverV2):
528 548
             self.mech.switches_mac_ip_pair
529 549
         )
530 550
 
551
+    def test_delete_port_with_bound_not_baremetal(self):
552
+        ctx = self.prepare_dummy_context(net_type='vxlan', vif_type='ovs')
553
+        ctx.current['binding:profile'] = {}
554
+        self.mech.delete_port_postcommit(ctx)
555
+        self.mech._vxlan_driver.reset_physical_port.assert_called_once_with(
556
+            [],
557
+            ctx.current,
558
+            self.mech.switches_mac_ip_pair
559
+        )
560
+
531 561
     def test_delete_port_raises_reset_physical_port(self):
532 562
         ctx = self.prepare_dummy_context(net_type='vxlan', vif_type='normal')
533 563
         self.mech._vxlan_driver.reset_physical_port.side_effect = Exception

Loading…
Cancel
Save