Browse Source

Use oslo config for physical_network_adapter_map

Use the newly added oslo config opt [1] for the
'physical_network_adapter_mappings' configuration option.

The new config option does all the validation. It also ensures that
the port-element-id defaults to 0 if none is given. The corresponding
code is getting removed.

[1] https://review.openstack.org/443615

Change-Id: I5a1bd27fdb10579ac4e85bc502a364f2521bd162
Closes-Bug: #1659315
Closes-Bug: #1663369
Andreas Scheuring 2 years ago
parent
commit
bac784f902

+ 6
- 3
networking_dpm/conf/config.py View File

@@ -17,6 +17,8 @@
17 17
 from os_dpm.config import config as os_dpm_conf
18 18
 from oslo_config import cfg
19 19
 
20
+from networking_dpm.conf.cfg import MultiNetworkAdapterMappingOpt
21
+
20 22
 # Update help text of DPM group with networking-dpm specifics
21 23
 os_dpm_conf.DPM_GROUP.help += """
22 24
 
@@ -34,9 +36,10 @@ mapping_example = ["physnet1:12345678-1234-1234-1234-123456789a",
34 36
 # TODO(andreas_s): Neutron does not make use of required=True, therefore
35 37
 # the Neutron test base class tests fail when enabled
36 38
 dpm_opts = [
37
-    cfg.MultiStrOpt('physical_network_adapter_mappings',
38
-                    sample_default=mapping_example,
39
-                    help="""
39
+    MultiNetworkAdapterMappingOpt(
40
+        'physical_network_adapter_mappings',
41
+        sample_default=mapping_example,
42
+        help="""
40 43
 The OpenStack physical networks that can be used by this OpenStack hypervisor
41 44
 host, and their backing network adapters and ports in the target CPC.
42 45
 

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

@@ -131,37 +131,13 @@ class PhysicalNetworkMapping(object):
131 131
                                            'port': port})
132 132
             sys.exit(1)
133 133
 
134
-    @staticmethod
135
-    def _parse_config_line(line):
136
-        result = line.split(":")
137
-        # TODO(andreas_s): Validate line
138
-        net = result[0]
139
-        adapter_id = result[1]
140
-        # If no port-element-id was defined, default to 0
141
-        # result[2] can also be '' - handled by 'and result[2]'
142
-        port = result[2] if len(result) == 3 and result[2] else "0"
143
-        return net, adapter_id, port
144
-
145
-    @staticmethod
146
-    def _get_interface_mapping_conf():
147
-        interface_mappings = CONF.dpm.physical_network_adapter_mappings
148
-
149
-        if not interface_mappings:
150
-            LOG.error(_LE("physical_adapter_mappings dpm configuration not "
151
-                          "specified or empty value provided. Agent "
152
-                          "terminated!"))
153
-            sys.exit(1)
154
-
155
-        return interface_mappings
156
-
157 134
     @staticmethod
158 135
     def create_mapping(cpc):
159 136
         mapping = PhysicalNetworkMapping(cpc)
160
-        interface_mappings = mapping._get_interface_mapping_conf()
161 137
 
162
-        for entry in interface_mappings:
163
-            net, adapter_uuid, port = \
164
-                PhysicalNetworkMapping._parse_config_line(entry)
138
+        for entry in CONF.dpm.physical_network_adapter_mappings:
139
+            # Safe as config option ensures validity of the tuple
140
+            net, adapter_uuid, port = entry
165 141
 
166 142
             adapter = mapping._get_adapter(adapter_uuid)
167 143
             mapping._validate_adapter_type(adapter)

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

@@ -32,46 +32,10 @@ from neutron.common import topics
32 32
 
33 33
 class TestPhysnetMapping(base.BaseTestCase):
34 34
 
35
-    def _test__parse_config_line(self, line, ex_net, ex_adapt, ex_port):
36
-        net, adapt, port = dpm_map._parse_config_line(line)
37
-        self.assertEqual(ex_net, net)
38
-        self.assertEqual(ex_adapt, adapt)
39
-        self.assertEqual(ex_port, port)
40
-
41
-    def test__parse_config_line_default_to_zero(self):
42
-        line = "foo:uuid:"
43
-        self._test__parse_config_line(line, 'foo', 'uuid', '0')
44
-        line = "foo:uuid"
45
-        self._test__parse_config_line(line, 'foo', 'uuid', '0')
46
-
47
-    def test__parse_config_line(self):
48
-        line = "foo:uuid:1"
49
-        self._test__parse_config_line(line, 'foo', 'uuid', '1')
50
-
51
-    def test__get_interface_mapping_conf(self):
52
-        test_mapping = ["physnet1:uuid1:1",
53
-                        "physnet1:uuid2:1",
54
-                        "physnet2:uuid3:1"
55
-                        ]
56
-        cfg.CONF.set_override('physical_network_adapter_mappings',
57
-                              test_mapping, group='dpm')
58
-        mapping = dpm_map(mock.Mock())
59
-        self.assertEqual(test_mapping, mapping._get_interface_mapping_conf())
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
-
71 35
     def test_create_mapping(self):
72
-        conf_mapping = ["physnet1:uuid-1:",
73
-                        "physnet2:uuid-2:1",
74
-                        "physnet3:uuid-3:0"
36
+        conf_mapping = [("physnet1", "uuid-1", "0"),
37
+                        ("physnet2", "uuid-2", "1"),
38
+                        ("physnet3", "uuid-3", "0")
75 39
                         ]
76 40
         cfg.CONF.set_override('physical_network_adapter_mappings',
77 41
                               conf_mapping, group='dpm')
@@ -113,7 +77,7 @@ class TestPhysnetMapping(base.BaseTestCase):
113 77
 
114 78
     def test_create_mapping_invalid_adapter_type(self):
115 79
         cfg.CONF.set_override('physical_network_adapter_mappings',
116
-                              ["physnet1:uuid-1:"],
80
+                              [('physnet1', 'uuid-1', '0')],
117 81
                               group='dpm')
118 82
         hmc = {"cpcs": [{
119 83
             "object-id": "cpcpid",
@@ -124,7 +88,7 @@ class TestPhysnetMapping(base.BaseTestCase):
124 88
                           dpm_map.create_mapping, cpc)
125 89
 
126 90
     def test_create_mapping_adapter_not_exists(self):
127
-        conf_mapping = ['physnet1:not_exists:']
91
+        conf_mapping = [('physnet1', 'not_exists', '0')]
128 92
         cfg.CONF.set_override('physical_network_adapter_mappings',
129 93
                               conf_mapping, group='dpm')
130 94
         hmc = {"cpcs": [{
@@ -136,7 +100,7 @@ class TestPhysnetMapping(base.BaseTestCase):
136 100
                           dpm_map.create_mapping, cpc)
137 101
 
138 102
     def test_create_mapping_adapter_port_not_exists(self):
139
-        conf_mapping = ['physnet1:uuid-1:1']
103
+        conf_mapping = [('physnet1', 'uuid-1', '1')]
140 104
         cfg.CONF.set_override('physical_network_adapter_mappings',
141 105
                               conf_mapping, group='dpm')
142 106
         hmc = {"cpcs": [{
@@ -149,7 +113,7 @@ class TestPhysnetMapping(base.BaseTestCase):
149 113
                           dpm_map.create_mapping, cpc)
150 114
 
151 115
     def test_create_mapping_vswitch_not_exists(self):
152
-        conf_mapping = ['physnet1:uuid-1:']
116
+        conf_mapping = [('physnet1', 'uuid-1', '0')]
153 117
         cfg.CONF.set_override('physical_network_adapter_mappings',
154 118
                               conf_mapping, group='dpm')
155 119
         hmc = {"cpcs": [{
@@ -160,15 +124,8 @@ class TestPhysnetMapping(base.BaseTestCase):
160 124
         self.assertRaises(SystemExit,
161 125
                           dpm_map.create_mapping, cpc)
162 126
 
163
-    def test_create_mapping_no_config(self):
164
-        cfg.CONF.set_override('physical_network_adapter_mappings', [],
165
-                              group='dpm')
166
-        self.assertRaises(SystemExit,
167
-                          dpm_map.create_mapping,
168
-                          mock.Mock())
169
-
170 127
     def test_create_mapping_multiple_adapters_per_physnet(self):
171
-        mapping = ['physnet1:uuid-1:', 'physnet1:uuid-3:0']
128
+        mapping = [('physnet1', 'uuid-1', '0'), ('physnet1', 'uuid-3', '0')]
172 129
         cfg.CONF.set_override('physical_network_adapter_mappings', mapping,
173 130
                               group='dpm')
174 131
 

Loading…
Cancel
Save