]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Correct _test_delete_ports_by_device_id_second_call_failure
authorCedric Brandily <zzelle@gmail.com>
Mon, 12 Jan 2015 13:10:03 +0000 (13:10 +0000)
committerCedric Brandily <zzelle@gmail.com>
Thu, 15 Jan 2015 10:48:13 +0000 (10:48 +0000)
Currently the test assumes delete_ports_by_device_id deletes ports in
the order they were created but nothing ensures it. This change
updates _test_delete_ports_by_device_id_second_call_failure to avoid
such (incorrect) assumption. The assumption is in general broken in
daughter change which adds a unique constraint on Port table.

Change-Id: I387354eb8c02b614321ace5a105253d7504d5119

neutron/tests/unit/test_db_plugin.py

index 3bce709d593cd08255730104e95e635b7f476bd1..576926f99c40caa0e8d7a0ba8a472b1050228aff 100644 (file)
@@ -451,15 +451,19 @@ class NeutronDbPluginV2TestCase(testlib_api.WebTestCase,
         res = req.get_response(self._api_for_resource(collection))
         self.assertEqual(res.status_int, expected_code)
 
-    def _show(self, resource, id,
-              expected_code=webob.exc.HTTPOk.code,
-              neutron_context=None):
+    def _show_response(self, resource, id, neutron_context=None):
         req = self.new_show_request(resource, id)
         if neutron_context:
             # create a specific auth context for this request
             req.environ['neutron.context'] = neutron_context
-        res = req.get_response(self._api_for_resource(resource))
-        self.assertEqual(res.status_int, expected_code)
+        return req.get_response(self._api_for_resource(resource))
+
+    def _show(self, resource, id,
+              expected_code=webob.exc.HTTPOk.code,
+              neutron_context=None):
+        res = self._show_response(resource, id,
+                                  neutron_context=neutron_context)
+        self.assertEqual(expected_code, res.status_int)
         return self.deserialize(self.fmt, res)
 
     def _update(self, resource, id, new_data,
@@ -1781,10 +1785,11 @@ fixed_ips=ip_address%%3D%s&fixed_ips=ip_address%%3D%s&fixed_ips=subnet_id%%3D%s
                     self.assertRaises(n_exc.NeutronException,
                                       plugin.delete_ports_by_device_id,
                                       ctx, 'owner1', network_id)
-                self._show('ports', p1['port']['id'],
-                           expected_code=webob.exc.HTTPNotFound.code)
-                self._show('ports', p2['port']['id'],
-                           expected_code=webob.exc.HTTPOk.code)
+                statuses = {
+                    self._show_response('ports', p['port']['id']).status_int
+                    for p in [p1, p2]}
+                expected = {webob.exc.HTTPNotFound.code, webob.exc.HTTPOk.code}
+                self.assertEqual(expected, statuses)
                 self._show('ports', p3['port']['id'],
                            expected_code=webob.exc.HTTPOk.code)