Browse Source

Merge "Make Neutron gate great again"

tags/15.0.0.0b1
Zuul 1 week ago
parent
commit
0d511025eb

+ 23
- 19
neutron/tests/functional/privileged/agent/linux/test_ip_lib.py View File

@@ -13,6 +13,7 @@
13 13
 #    under the License.
14 14
 
15 15
 import functools
16
+import random
16 17
 
17 18
 import eventlet
18 19
 import netaddr
@@ -191,42 +192,45 @@ class GetDevicesInfoTestCase(functional_base.BaseSudoTestCase):
191 192
         self.assertEqual(sorted(interfaces_tested),
192 193
                          sorted(self.interfaces + vxlan_interfaces))
193 194
 
195
+    def _retrieve_interface(self, interface_name, namespace):
196
+        for device in priv_ip_lib.get_link_devices(namespace):
197
+            if interface_name == ip_lib.get_attr(device, 'IFLA_IFNAME'):
198
+                return device
199
+        else:
200
+            self.fail('Interface "%s" not found' % interface_name)
201
+
194 202
     def test_get_devices_info_veth_different_namespaces(self):
195 203
         namespace2 = 'ns_test-' + uuidutils.generate_uuid()
196 204
         priv_ip_lib.create_netns(namespace2)
197 205
         self.addCleanup(self._remove_ns, namespace2)
206
+        # Create a random number of dummy interfaces in namespace2, in order
207
+        # to increase the 'veth1_2' interface index in its namespace.
208
+        for idx in range(5, random.randint(15, 20)):
209
+            priv_ip_lib.create_interface('int_%s' % idx, namespace2, 'dummy')
210
+
198 211
         ip_wrapper = ip_lib.IPWrapper(self.namespace)
199 212
         ip_wrapper.add_veth('veth1_1', 'veth1_2', namespace2)
200 213
 
201
-        devices = priv_ip_lib.get_link_devices(self.namespace)
202
-        for device in devices:
203
-            name = ip_lib.get_attr(device, 'IFLA_IFNAME')
204
-            if name == 'veth1_1':
205
-                veth1_1 = device
206
-                break
207
-        else:
208
-            self.fail('Interface "veth1_1" not found')
214
+        veth1_1 = self._retrieve_interface('veth1_1', self.namespace)
215
+        veth1_2 = self._retrieve_interface('veth1_2', namespace2)
209 216
 
210 217
         ifla_linkinfo = ip_lib.get_attr(veth1_1, 'IFLA_LINKINFO')
211 218
         self.assertEqual(ip_lib.get_attr(ifla_linkinfo, 'IFLA_INFO_KIND'),
212 219
                          'veth')
213
-        self.assertIsNone(ip_lib.get_attr(veth1_1, 'IFLA_LINK'))
220
+        # NOTE(ralonsoh): since kernel_version=4.15.0-60-generic, iproute2
221
+        # provides the veth pair index, even if the pair interface is in other
222
+        # namespace. In previous versions, the parameter 'IFLA_LINK' was not
223
+        # present. We need to handle both cases.
224
+        self.assertIn(ip_lib.get_attr(veth1_1, 'IFLA_LINK'),
225
+                      [None, veth1_2['index']])
214 226
 
215 227
     def test_get_devices_info_veth_same_namespaces(self):
216 228
         ip_wrapper = ip_lib.IPWrapper(self.namespace)
217 229
         ip_wrapper.add_veth('veth1_1', 'veth1_2')
218 230
 
219
-        devices = priv_ip_lib.get_link_devices(self.namespace)
220
-        veth1_1 = veth1_2 = None
221
-        for device in devices:
222
-            name = ip_lib.get_attr(device, 'IFLA_IFNAME')
223
-            if name == 'veth1_1':
224
-                veth1_1 = device
225
-            elif name == 'veth1_2':
226
-                veth1_2 = device
231
+        veth1_1 = self._retrieve_interface('veth1_1', self.namespace)
232
+        veth1_2 = self._retrieve_interface('veth1_2', self.namespace)
227 233
 
228
-        self.assertIsNotNone(veth1_1)
229
-        self.assertIsNotNone(veth1_2)
230 234
         veth1_1_link = ip_lib.get_attr(veth1_1, 'IFLA_LINK')
231 235
         veth1_2_link = ip_lib.get_attr(veth1_2, 'IFLA_LINK')
232 236
         self.assertEqual(veth1_1['index'], veth1_2_link)

+ 29
- 15
neutron/tests/functional/test_server.py View File

@@ -34,9 +34,10 @@ from neutron import wsgi
34 34
 
35 35
 CONF = cfg.CONF
36 36
 
37
-# This message will be written to temporary file each time
38
-# start method is called.
37
+# Those messages will be written to temporary file each time
38
+# start/reset methods are called.
39 39
 FAKE_START_MSG = b"start"
40
+FAKE_RESET_MSG = b"reset"
40 41
 
41 42
 TARGET_PLUGIN = 'neutron.plugins.ml2.plugin.Ml2Plugin'
42 43
 
@@ -130,6 +131,10 @@ class TestNeutronServer(base.BaseLoggingTestCase):
130 131
         with open(self.temp_file, 'ab') as f:
131 132
             f.write(FAKE_START_MSG)
132 133
 
134
+    def _fake_reset(self):
135
+        with open(self.temp_file, 'ab') as f:
136
+            f.write(FAKE_RESET_MSG)
137
+
133 138
     def _test_restart_service_on_sighup(self, service, workers=1):
134 139
         """Test that a service correctly (re)starts on receiving SIGHUP.
135 140
 
@@ -141,7 +146,11 @@ class TestNeutronServer(base.BaseLoggingTestCase):
141 146
         self._start_server(callback=service, workers=workers)
142 147
         os.kill(self.service_pid, signal.SIGHUP)
143 148
 
144
-        expected_msg = FAKE_START_MSG * workers * 2
149
+        # After sending SIGHUP it is expected that there will be as many
150
+        # FAKE_RESET_MSG as number of workers + one additional for main
151
+        # process
152
+        expected_msg = (
153
+            FAKE_START_MSG * workers + FAKE_RESET_MSG * (workers + 1))
145 154
 
146 155
         # Wait for temp file to be created and its size reaching the expected
147 156
         # value
@@ -208,8 +217,10 @@ class TestWsgiServer(TestNeutronServer):
208 217
 
209 218
         # Mock start method to check that children are started again on
210 219
         # receiving SIGHUP.
211
-        with mock.patch("neutron.wsgi.WorkerService.start") as start_method:
220
+        with mock.patch("neutron.wsgi.WorkerService.start") as start_method,\
221
+                mock.patch("neutron.wsgi.WorkerService.reset") as reset_method:
212 222
             start_method.side_effect = self._fake_start
223
+            reset_method.side_effect = self._fake_reset
213 224
 
214 225
             server = wsgi.Server("Test")
215 226
             server.start(self.application, 0, "0.0.0.0",
@@ -241,19 +252,21 @@ class TestRPCServer(TestNeutronServer):
241 252
 
242 253
         # Mock start method to check that children are started again on
243 254
         # receiving SIGHUP.
244
-        with mock.patch("neutron.service.RpcWorker.start") as start_method:
245
-            with mock.patch(
246
-                    "neutron_lib.plugins.directory.get_plugin"
247
-            ) as get_plugin:
248
-                start_method.side_effect = self._fake_start
249
-                get_plugin.return_value = self.plugin
255
+        with mock.patch("neutron.service.RpcWorker.start") as start_method,\
256
+                mock.patch(
257
+                    "neutron.service.RpcWorker.reset") as reset_method,\
258
+                mock.patch(
259
+                    "neutron_lib.plugins.directory.get_plugin") as get_plugin:
260
+            start_method.side_effect = self._fake_start
261
+            reset_method.side_effect = self._fake_reset
262
+            get_plugin.return_value = self.plugin
250 263
 
251
-                CONF.set_override("rpc_workers", workers)
252
-                # not interested in state report workers specifically
253
-                CONF.set_override("rpc_state_report_workers", 0)
264
+            CONF.set_override("rpc_workers", workers)
265
+            # not interested in state report workers specifically
266
+            CONF.set_override("rpc_state_report_workers", 0)
254 267
 
255
-                rpc_workers_launcher = service.start_rpc_workers()
256
-                rpc_workers_launcher.wait()
268
+            rpc_workers_launcher = service.start_rpc_workers()
269
+            rpc_workers_launcher.wait()
257 270
 
258 271
     def test_restart_rpc_on_sighup_multiple_workers(self):
259 272
         self._test_restart_service_on_sighup(service=self._serve_rpc,
@@ -292,6 +305,7 @@ class TestPluginWorker(TestNeutronServer):
292 305
 
293 306
         # Make both ABC happy and ensure 'self' is correct
294 307
         FakeWorker.start = self._fake_start
308
+        FakeWorker.reset = self._fake_reset
295 309
         workers = [FakeWorker()]
296 310
         self.plugin.return_value.get_workers.return_value = workers
297 311
         self._test_restart_service_on_sighup(service=self._start_plugin,

Loading…
Cancel
Save