Browse Source

Use self.flags everywhere

Switching to use self.flags over cfg.CONF.set_overrride when setting
confi options for test.

Change-Id: I90dca96ebfaaba0fad2e576b520b96241c835155
Andreas Scheuring 2 years ago
parent
commit
a0d4216e7f
1 changed files with 38 additions and 41 deletions
  1. 38
    41
      networking_dpm/tests/unit/ml2/test_dpm_neutron_agent.py

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

@@ -17,7 +17,6 @@
17 17
 import sys
18 18
 
19 19
 import mock
20
-from oslo_config import cfg
21 20
 from zhmcclient import ConnectionError
22 21
 from zhmcclient import HTTPError
23 22
 
@@ -29,34 +28,36 @@ from networking_dpm.tests.unit import fake_zhmcclient
29 28
 
30 29
 from neutron.common import topics
31 30
 
31
+OID_A = "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
32
+OID_B = "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb"
33
+OID_C = "cccccccc-cccc-cccc-cccc-cccccccccccc"
34
+
32 35
 
33 36
 class TestPhysnetMapping(base.BaseTestCase):
34 37
 
35 38
     def test_create_mapping(self):
36
-        conf_mapping = [("physnet1", "uuid-1", "0"),
37
-                        ("physnet2", "uuid-2", "1"),
38
-                        ("physnet3", "uuid-3", "0")
39
-                        ]
40
-        cfg.CONF.set_override('physical_network_adapter_mappings',
41
-                              conf_mapping, group='dpm')
39
+        conf_mapping = ["physnet1:" + OID_A + ":0",
40
+                        "physnet2:" + OID_B + ":1",
41
+                        "physnet3:" + OID_C + ":0"]
42
+        self.flags(group="dpm", physical_network_adapter_mappings=conf_mapping)
42 43
         expected = {'physnet1': ['vswitch-uuid-1'],
43 44
                     'physnet2': ['vswitch-uuid-2'],
44 45
                     'physnet3': ['vswitch-uuid-3']}
45 46
 
46
-        adapters = [{'object-id': 'uuid-1', 'type': 'osd',
47
-                     'ports': [{'element-id': '0'}]},
48
-                    {'object-id': 'uuid-2', 'type': 'osd',
49
-                     'ports': [{'element-id': '1'}]},
50
-                    {'object-id': 'uuid-3', 'type': 'hipersockets',
51
-                     'ports': [{'element-id': '0'}]}]
47
+        adapters = [{'object-id': OID_A,
48
+                     'type': 'osd', 'ports': [{'element-id': '0'}]},
49
+                    {'object-id': OID_B,
50
+                     'type': 'osd', 'ports': [{'element-id': '1'}]},
51
+                    {'object-id': OID_C,
52
+                     'type': 'hipersockets', 'ports': [{'element-id': '0'}]}]
52 53
         vswitches = [
53
-            {"backing-adapter-uri": "/api/adapters/uuid-1",
54
+            {"backing-adapter-uri": "/api/adapters/" + OID_A,
54 55
              "object-id": "vswitch-uuid-1",
55 56
              "port": 0},
56
-            {"backing-adapter-uri": "/api/adapters/uuid-2",
57
+            {"backing-adapter-uri": "/api/adapters/" + OID_B,
57 58
              "object-id": "vswitch-uuid-2",
58 59
              "port": 1},
59
-            {"backing-adapter-uri": "/api/adapters/uuid-3",
60
+            {"backing-adapter-uri": "/api/adapters/" + OID_C,
60 61
              "object-id": "vswitch-uuid-3",
61 62
              "port": 0}]
62 63
         hmc = {"cpcs": [{"object-id": "cpcpid", "vswitches": vswitches,
@@ -76,9 +77,8 @@ class TestPhysnetMapping(base.BaseTestCase):
76 77
         self.assertIn("vswitch-uuid-3", vswitch_ids)
77 78
 
78 79
     def test_create_mapping_invalid_adapter_type(self):
79
-        cfg.CONF.set_override('physical_network_adapter_mappings',
80
-                              [('physnet1', 'uuid-1', '0')],
81
-                              group='dpm')
80
+        conf_mapping = ["physnet1:" + OID_A + ":0"]
81
+        self.flags(group="dpm", physical_network_adapter_mappings=conf_mapping)
82 82
         hmc = {"cpcs": [{
83 83
             "object-id": "cpcpid",
84 84
             "adapters": [{'object-id': 'uuid-1', 'type': 'bad_type'}]}]}
@@ -88,9 +88,8 @@ class TestPhysnetMapping(base.BaseTestCase):
88 88
                           dpm_map.create_mapping, cpc)
89 89
 
90 90
     def test_create_mapping_adapter_not_exists(self):
91
-        conf_mapping = [('physnet1', 'not_exists', '0')]
92
-        cfg.CONF.set_override('physical_network_adapter_mappings',
93
-                              conf_mapping, group='dpm')
91
+        conf_mapping = ["physnet1:" + OID_A + ":0"]
92
+        self.flags(group="dpm", physical_network_adapter_mappings=conf_mapping)
94 93
         hmc = {"cpcs": [{
95 94
             "object-id": "cpcpid",
96 95
             "adapters": [{'object-id': 'other_adapter', 'type': 'osd'}]}]}
@@ -100,12 +99,11 @@ class TestPhysnetMapping(base.BaseTestCase):
100 99
                           dpm_map.create_mapping, cpc)
101 100
 
102 101
     def test_create_mapping_adapter_port_not_exists(self):
103
-        conf_mapping = [('physnet1', 'uuid-1', '1')]
104
-        cfg.CONF.set_override('physical_network_adapter_mappings',
105
-                              conf_mapping, group='dpm')
102
+        conf_mapping = ["physnet1:" + OID_A + ":1"]
103
+        self.flags(group="dpm", physical_network_adapter_mappings=conf_mapping)
106 104
         hmc = {"cpcs": [{
107 105
             "object-id": "cpcpid",
108
-            "adapters": [{'object-id': 'uuid-1', 'type': 'osd',
106
+            "adapters": [{'object-id': OID_A, 'type': 'osd',
109 107
                           'ports': []}]}]}
110 108
 
111 109
         cpc = fake_zhmcclient.get_cpc(hmc)
@@ -113,29 +111,28 @@ class TestPhysnetMapping(base.BaseTestCase):
113 111
                           dpm_map.create_mapping, cpc)
114 112
 
115 113
     def test_create_mapping_vswitch_not_exists(self):
116
-        conf_mapping = [('physnet1', 'uuid-1', '0')]
117
-        cfg.CONF.set_override('physical_network_adapter_mappings',
118
-                              conf_mapping, group='dpm')
114
+        conf_mapping = ["physnet1:" + OID_A + ":0"]
115
+        self.flags(group="dpm", physical_network_adapter_mappings=conf_mapping)
119 116
         hmc = {"cpcs": [{
120 117
             "object-id": "cpcpid",
121
-            "adapters": [{'object-id': 'uuid-1', 'type': 'osd'}]}]}
118
+            "adapters": [{'object-id': OID_A, 'type': 'osd'}]}]}
122 119
 
123 120
         cpc = fake_zhmcclient.get_cpc(hmc)
124 121
         self.assertRaises(SystemExit,
125 122
                           dpm_map.create_mapping, cpc)
126 123
 
127 124
     def test_create_mapping_multiple_adapters_per_physnet(self):
128
-        mapping = [('physnet1', 'uuid-1', '0'), ('physnet1', 'uuid-3', '0')]
129
-        cfg.CONF.set_override('physical_network_adapter_mappings', mapping,
130
-                              group='dpm')
125
+        conf_mapping = ["physnet1:" + OID_A + ":0",
126
+                        "physnet1:" + OID_B + ":0"]
127
+        self.flags(group="dpm", physical_network_adapter_mappings=conf_mapping)
131 128
 
132
-        adapters = [{'object-id': 'uuid-1', 'type': 'osd'},
133
-                    {'object-id': 'uuid-3', 'type': 'osd'}]
129
+        adapters = [{'object-id': OID_A, 'type': 'osd'},
130
+                    {'object-id': OID_B, 'type': 'osd'}]
134 131
         hmc = {"cpcs": [{"object-id": "cpcpid", "vswitches": [
135
-            {"backing-adapter-uri": "/api/adapters/uuid-1",
132
+            {"backing-adapter-uri": "/api/adapters/" + OID_A,
136 133
              "object-id": "vswitch-uuid-1",
137 134
              "port": 0},
138
-            {"backing-adapter-uri": "/api/adapters/uuid-3",
135
+            {"backing-adapter-uri": "/api/adapters/" + OID_B,
139 136
              "object-id": "vswitch-uuid-3",
140 137
              "port": 0}], "adapters": adapters}]}
141 138
         cpc = fake_zhmcclient.get_cpc(hmc)
@@ -165,7 +162,7 @@ class TestDPMManager(base.BaseTestCase):
165 162
         self.mgr = dpm_agt.DPMManager({}, mock.Mock(), [])
166 163
 
167 164
     def test__managed_by_agent(self):
168
-        cfg.CONF.set_override('host', 'foo-host')
165
+        self.flags(host='foo-host')
169 166
         valid_mac_str = "mac=00:11:22:33:44:55:66"
170 167
         # Host and mac part of description
171 168
         self.assertTrue(self.mgr._managed_by_agent(fake_zhmcclient._NIC(
@@ -293,7 +290,7 @@ class TestDPMManager(base.BaseTestCase):
293 290
         self.assertEqual(expected, self.mgr.get_agent_configurations())
294 291
 
295 292
     def test_get_agent_id(self):
296
-        cfg.CONF.set_override('host', 'foo')
293
+        self.flags(host='foo')
297 294
         self.assertEqual("dpm-foo", self.mgr.get_agent_id())
298 295
 
299 296
     def test_get_extension_driver_type(self):
@@ -328,12 +325,12 @@ class TestDPMMain(base.BaseTestCase):
328 325
         valid_drivers = ['neutron.agent.firewall.NoopFirewallDriver',
329 326
                          'noop']
330 327
         for driver in valid_drivers:
331
-            cfg.CONF.set_override('firewall_driver', driver, 'SECURITYGROUP')
328
+            self.flags(group='SECURITYGROUP', firewall_driver=driver)
332 329
             dpm_agt._validate_firewall_driver()
333 330
 
334 331
     @mock.patch.object(sys, 'exit')
335 332
     def test__validate_firewall_driver_invalid(self, mock_exit):
336
-        cfg.CONF.set_override('firewall_driver', 'foo', 'SECURITYGROUP')
333
+        self.flags(group='SECURITYGROUP', firewall_driver='foo')
337 334
         dpm_agt._validate_firewall_driver()
338 335
         mock_exit.assert_called_with(1)
339 336
 

Loading…
Cancel
Save