Browse Source

Convert port to int for vswitch object

Patch [1] changed the behavior of 'port' to be always of type str.
Till then it was read as str from the config file, converted to int
and converted back to str for some cases.

But this patch did not consider that 2 flavors of port exists in
the DPM API:

* the 'port' attribute of a vswitch is of type int
* the 'element-id' of an adapter port is of type str

With [1], also for the vswitch case the int string was used, which
resulted in a zhmcclient.NotFound exception.

This patch fixes this by converting the value for this special
case to int.

Closes-Bug: #1673185

[1] f59ff63da4

Change-Id: I6fbfbb8d81b5078ac336aab33da4295a9b835d9c
Andreas Scheuring 2 years ago
parent
commit
948171e71d

+ 3
- 1
networking_dpm/ml2/dpm_neutron_agent.py View File

@@ -70,7 +70,9 @@ class PhysicalNetworkMapping(object):
70 70
             # whole list of items is retrieved
71 71
             return self._cpc.vswitches.find(**{
72 72
                 'backing-adapter-uri': ADAPTER_URI + adapter_id,
73
-                'port': port
73
+                # 'port' attribute of vswitch is of type int. But 'element-id'
74
+                # attribute of an adapter port is still of type str.
75
+                'port': int(port)
74 76
             })
75 77
         except zhmcclient.NotFound:
76 78
             LOG.error(

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

@@ -58,6 +58,16 @@ class TestPhysnetMapping(base.BaseTestCase):
58 58
         mapping = dpm_map(mock.Mock())
59 59
         self.assertEqual(test_mapping, mapping._get_interface_mapping_conf())
60 60
 
61
+    def test__get_vswitch_port_converted_to_int(self):
62
+        vswitches = [
63
+            {"backing-adapter-uri": "/api/adapters/uuid-1",
64
+             "port": 0}]
65
+        hmc = {"cpcs": [{"vswitches": vswitches}]}
66
+        cpc = fake_zhmcclient.get_cpc(hmc)
67
+        mapping = dpm_map(cpc)
68
+        vswitch = mapping._get_vswitch("uuid-1", "0")
69
+        self.assertEqual(0, vswitch.get_property("port"))
70
+
61 71
     def test_create_mapping(self):
62 72
         conf_mapping = ["physnet1:uuid-1:",
63 73
                         "physnet2:uuid-2:1",
@@ -78,13 +88,13 @@ class TestPhysnetMapping(base.BaseTestCase):
78 88
         vswitches = [
79 89
             {"backing-adapter-uri": "/api/adapters/uuid-1",
80 90
              "object-id": "vswitch-uuid-1",
81
-             "port": "0"},
91
+             "port": 0},
82 92
             {"backing-adapter-uri": "/api/adapters/uuid-2",
83 93
              "object-id": "vswitch-uuid-2",
84
-             "port": "1"},
94
+             "port": 1},
85 95
             {"backing-adapter-uri": "/api/adapters/uuid-3",
86 96
              "object-id": "vswitch-uuid-3",
87
-             "port": "0"}]
97
+             "port": 0}]
88 98
         hmc = {"cpcs": [{"object-id": "cpcpid", "vswitches": vswitches,
89 99
                          "adapters": adapters}]}
90 100
         cpc = fake_zhmcclient.get_cpc(hmc)

Loading…
Cancel
Save