Browse Source

Treat port-element id as String

The HMC and requires port-element-id to be a string!

The port-element-id taken from the config file got converted from
string to int. The code internally used the int value. But for
communication to the HMC it was converted to string again.

This patch removes the transiation from string - int - string. Now
always the string value is used.

Change-Id: I51361f6abd2b0b447ecbf0844a3a38459999678f
Andreas Scheuring 2 years ago
parent
commit
f59ff63da4

+ 2
- 5
networking_dpm/ml2/dpm_neutron_agent.py View File

@@ -120,10 +120,7 @@ class PhysicalNetworkMapping(object):
120 120
         try:
121 121
             # TODO(andreas_s): Optimize in zhmcclient - For 'find' the
122 122
             # whole list of items is retrieved
123
-            # TODO(andreas_s): zhmcclient requires the port-element-id as
124
-            # string. Int results in an NotFound Error.
125
-            # See https://github.com/zhmcclient/python-zhmcclient/issues/125
126
-            adapter.ports.find(**{'element-id': str(port)})
123
+            adapter.ports.find(**{'element-id': port})
127 124
         except zhmcclient.NotFound:
128 125
             LOG.error(_LE("Configured port %(port)s for adapter "
129 126
                           "%(adapt)s does not exist. Please update "
@@ -140,7 +137,7 @@ class PhysicalNetworkMapping(object):
140 137
         adapter_id = result[1]
141 138
         # If no port-element-id was defined, default to 0
142 139
         # result[2] can also be '' - handled by 'and result[2]'
143
-        port = int(result[2] if len(result) == 3 and result[2] else 0)
140
+        port = result[2] if len(result) == 3 and result[2] else "0"
144 141
         return net, adapter_id, port
145 142
 
146 143
     @staticmethod

+ 17
- 17
networking_dpm/tests/unit/ml2/test_dpm_neutron_agent.py View File

@@ -40,13 +40,13 @@ class TestPhysnetMapping(base.BaseTestCase):
40 40
 
41 41
     def test__parse_config_line_default_to_zero(self):
42 42
         line = "foo:uuid:"
43
-        self._test__parse_config_line(line, 'foo', 'uuid', 0)
43
+        self._test__parse_config_line(line, 'foo', 'uuid', '0')
44 44
         line = "foo:uuid"
45
-        self._test__parse_config_line(line, 'foo', 'uuid', 0)
45
+        self._test__parse_config_line(line, 'foo', 'uuid', '0')
46 46
 
47 47
     def test__parse_config_line(self):
48 48
         line = "foo:uuid:1"
49
-        self._test__parse_config_line(line, 'foo', 'uuid', 1)
49
+        self._test__parse_config_line(line, 'foo', 'uuid', '1')
50 50
 
51 51
     def test__get_interface_mapping_conf(self):
52 52
         test_mapping = ["physnet1:uuid1:1",
@@ -70,21 +70,21 @@ class TestPhysnetMapping(base.BaseTestCase):
70 70
                     'physnet3': ['vswitch-uuid-3']}
71 71
 
72 72
         adapters = [{'object-id': 'uuid-1', 'type': 'osd',
73
-                     'ports': [{'element-id': 0}]},
73
+                     'ports': [{'element-id': '0'}]},
74 74
                     {'object-id': 'uuid-2', 'type': 'osd',
75
-                     'ports': [{'element-id': 1}]},
75
+                     'ports': [{'element-id': '1'}]},
76 76
                     {'object-id': 'uuid-3', 'type': 'hipersockets',
77
-                     'ports': [{'element-id': 0}]}]
77
+                     'ports': [{'element-id': '0'}]}]
78 78
         vswitches = [
79 79
             {"backing-adapter-uri": "/api/adapters/uuid-1",
80 80
              "object-id": "vswitch-uuid-1",
81
-             "port": 0},
81
+             "port": "0"},
82 82
             {"backing-adapter-uri": "/api/adapters/uuid-2",
83 83
              "object-id": "vswitch-uuid-2",
84
-             "port": 1},
84
+             "port": "1"},
85 85
             {"backing-adapter-uri": "/api/adapters/uuid-3",
86 86
              "object-id": "vswitch-uuid-3",
87
-             "port": 0}]
87
+             "port": "0"}]
88 88
         hmc = {"cpcs": [{"object-id": "cpcpid", "vswitches": vswitches,
89 89
                          "adapters": adapters}]}
90 90
         cpc = fake_zhmcclient.get_cpc(hmc)
@@ -167,10 +167,10 @@ class TestPhysnetMapping(base.BaseTestCase):
167 167
         hmc = {"cpcs": [{"object-id": "cpcpid", "vswitches": [
168 168
             {"backing-adapter-uri": "/api/adapters/uuid-1",
169 169
              "object-id": "vswitch-uuid-1",
170
-             "port": 0},
170
+             "port": "0"},
171 171
             {"backing-adapter-uri": "/api/adapters/uuid-3",
172 172
              "object-id": "vswitch-uuid-3",
173
-             "port": 0}], "adapters": adapters}]}
173
+             "port": "0"}], "adapters": adapters}]}
174 174
         cpc = fake_zhmcclient.get_cpc(hmc)
175 175
         self.assertRaises(SystemExit,
176 176
                           dpm_map.create_mapping,
@@ -233,19 +233,19 @@ class TestDPMManager(base.BaseTestCase):
233 233
         hmc = {"cpcs": [{"object-id": "cpcpid", "vswitches": [
234 234
             {"backing-adapter-uri": "/api/adapters/uuid-1",
235 235
              "object-id": "vswitch-uuid-1",
236
-             "port": 0,
236
+             "port": "0",
237 237
              "nics": [{"description": "foomac=00:00:00:00:00:11bar"},
238 238
                       {"description": "foomac=00:00:00:00:00:33bar"}]},
239 239
             {"backing-adapter-uri": "/api/adapters/uuid-2",
240 240
              "object-id": "vswitch-uuid-2",
241
-             "port": 1,
241
+             "port": "1",
242 242
              "nics": [{"description": "foomac=00:00:00:00:00:22bar"}]},
243 243
             {"backing-adapter-uri": "/api/adapters/uuid-3",
244 244
              "object-id": "vswitch-uuid-3",
245
-             "port": 0},
245
+             "port": "0"},
246 246
             {"backing-adapter-uri": "/api/adapters/not-configured",
247 247
              "object-id": "not-configured",
248
-             "port": 1,
248
+             "port": "1",
249 249
              "nics": [{"description": "not-configured"}]},
250 250
         ]}]}
251 251
 
@@ -266,7 +266,7 @@ class TestDPMManager(base.BaseTestCase):
266 266
         hmc = {"cpcs": [{"object-id": "cpcpid", "vswitches": [
267 267
             {"backing-adapter-uri": "/api/adapters/uuid-1",
268 268
              "object-id": "vswitch-uuid-1",
269
-             "port": 0,
269
+             "port": "0",
270 270
              "nics": [{"description": "OpenStack foo"}]},
271 271
         ]}]}
272 272
 
@@ -281,7 +281,7 @@ class TestDPMManager(base.BaseTestCase):
281 281
         hmc = {"cpcs": [{"object-id": "cpcpid", "vswitches": [
282 282
             {"backing-adapter-uri": "/api/adapters/uuid-1",
283 283
              "object-id": "vswitch-uuid-1",
284
-             "port": 0,
284
+             "port": "0",
285 285
              "nics": [{"name": "port-id-1"}]},
286 286
         ]}]}
287 287
         cpc = self.mgr.cpc = fake_zhmcclient.get_cpc(hmc)

Loading…
Cancel
Save