Просмотр исходного кода

Fix conductor server failing tests

Fixed by testing the `delete_replica_disks` function without its
decorator, since we don’t need it for the test. Using the removed
decorator, it will give an `oslo_config` required value error for option
`lock_path`.

Moved the `get_wrapped_function` function from `test_api.py` to
`testutils.py` since it is generic and can be used by all test modules.

Renamed test from `test_update_endpoint_not_found` to
`test_delete_replica_disks_invalid_state`. Most likely, the previous
name was a copying error.

Removed unused data input from the test.
Sergiu Miclea 4 лет назад
Родитель
Сommit
8448bcd6ec

+ 8 - 7
coriolis/tests/conductor/rpc/test_server.py

@@ -6,7 +6,7 @@ from unittest import mock
 
 from coriolis.conductor.rpc import server
 from coriolis import exception
-from coriolis.tests import test_base
+from coriolis.tests import test_base, testutils
 
 
 @ddt.ddt
@@ -17,21 +17,22 @@ class ConductorServerEndpointTestCase(test_base.CoriolisBaseTestCase):
         super(ConductorServerEndpointTestCase, self).setUp()
         self.server = server.ConductorServerEndpoint()
 
-    @ddt.data({}, {mock.sentinel.instance: {}})
     @mock.patch.object(server.ConductorServerEndpoint, '_create_task')
     @mock.patch.object(server.ConductorServerEndpoint,
                        '_check_replica_running_executions')
     @mock.patch.object(server.ConductorServerEndpoint, '_get_replica')
-    def test_update_endpoint_not_found(self, replica_info, mock_get_replica,
-                                       mock_check_replica_running,
-                                       mock_create_task):
+    def test_delete_replica_disks_invalid_state(self, mock_get_replica,
+                                                mock_check_replica_running,
+                                                mock_create_task):
         mock_replica = mock_get_replica.return_value
         mock_replica.instances = [mock.sentinel.instance]
         mock_replica.info = {}
+        delete_replica_disks = testutils.get_wrapped_function(
+            self.server.delete_replica_disks)
 
         self.assertRaises(exception.InvalidReplicaState,
-                          self.server.delete_replica_disks,
-                          mock.sentinel.context, mock.sentinel.replica_id)
+                          delete_replica_disks,
+                          self.server, mock.sentinel.context, mock.sentinel.replica_id)
 
         mock_get_replica.assert_called_once_with(mock.sentinel.context,
                                                  mock.sentinel.replica_id)

+ 2 - 25
coriolis/tests/db/test_api.py

@@ -5,30 +5,7 @@ from unittest import mock
 
 from coriolis.db import api
 from coriolis import exception
-from coriolis.tests import test_base
-
-
-def get_wrapped_function(function):
-    """Get the method at the bottom of a stack of decorators."""
-    if not hasattr(function, '__closure__') or not function.__closure__:
-        return function
-
-    def _get_wrapped_function(function):
-        if not hasattr(function, '__closure__') or not function.__closure__:
-            return None
-
-        for closure in function.__closure__:
-            func = closure.cell_contents
-
-            deeper_func = _get_wrapped_function(func)
-            if deeper_func:
-                return deeper_func
-            elif hasattr(closure.cell_contents, '__call__'):
-                return closure.cell_contents
-
-        return function
-
-    return _get_wrapped_function(function)
+from coriolis.tests import test_base, testutils
 
 
 class DBAPITestCase(test_base.CoriolisBaseTestCase):
@@ -41,7 +18,7 @@ class DBAPITestCase(test_base.CoriolisBaseTestCase):
         # We only need to test the unwrapped functions. Without this,
         # when calling a coriolis.db.api function, it will try to
         # establish an SQL connection.
-        update_endpoint = get_wrapped_function(api.update_endpoint)
+        update_endpoint = testutils.get_wrapped_function(api.update_endpoint)
 
         self.assertRaises(exception.NotFound, update_endpoint,
                           mock.sentinel.context, mock.sentinel.endpoint_id,

+ 23 - 0
coriolis/tests/testutils.py

@@ -11,3 +11,26 @@ def identity_dec(item, *args, **kwargs):
 def make_identity_decorator_mock():
     """Returns a MagicMock with identity_dec as a side-effect."""
     return mock.MagicMock(side_effect=identity_dec)
+
+
+def get_wrapped_function(function):
+    """Get the method at the bottom of a stack of decorators."""
+    if not hasattr(function, '__closure__') or not function.__closure__:
+        return function
+
+    def _get_wrapped_function(function):
+        if not hasattr(function, '__closure__') or not function.__closure__:
+            return None
+
+        for closure in function.__closure__:
+            func = closure.cell_contents
+
+            deeper_func = _get_wrapped_function(func)
+            if deeper_func:
+                return deeper_func
+            elif hasattr(closure.cell_contents, '__call__'):
+                return closure.cell_contents
+
+        return function
+
+    return _get_wrapped_function(function)