]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/orchestrator: remove tox and move test to parent dir 31561/head
authorSebastian Wagner <sebastian.wagner@suse.com>
Tue, 12 Nov 2019 10:48:54 +0000 (11:48 +0100)
committerSebastian Wagner <sebastian.wagner@suse.com>
Thu, 14 Nov 2019 11:37:50 +0000 (12:37 +0100)
Signed-off-by: Sebastian Wagner <sebastian.wagner@suse.com>
src/pybind/mgr/CMakeLists.txt
src/pybind/mgr/ansible/__init__.py
src/pybind/mgr/dashboard/__init__.py
src/pybind/mgr/orchestrator_cli/CMakeLists.txt [deleted file]
src/pybind/mgr/orchestrator_cli/requirements.txt [deleted file]
src/pybind/mgr/orchestrator_cli/test_orchestrator.py [deleted file]
src/pybind/mgr/requirements.txt
src/pybind/mgr/tests/__init__.py [new file with mode: 0644]
src/pybind/mgr/tests/test_orchestrator.py [new file with mode: 0644]
src/pybind/mgr/tox.ini

index ead8453b3ecae48fb6624bd7f47bfbb16c5afe82..f46a00a06d81fce57c80572140990b0ce4c42cba 100644 (file)
@@ -3,7 +3,6 @@ if(WITH_MGR_DASHBOARD_FRONTEND)
 endif()
 add_subdirectory(insights)
 add_subdirectory(ansible)
-add_subdirectory(orchestrator_cli)
 
 if(WITH_TESTS)
   include(AddCephTest)
index ea61a12fd7eaf800f2feaa9fef155cfe9a0aa770..6dab577a502b52cdb8cb62d9a9e1941413e5f24d 100644 (file)
@@ -1,9 +1,7 @@
 from __future__ import absolute_import
+
 import os
+if 'UNITTEST' in os.environ:
+    import tests
 
-if 'UNITTEST' not in os.environ:
-    from .module import Module
-else:
-    import sys
-    import mock
-    sys.modules['ceph_module'] = mock.Mock()
+from .module import Module
index a1affa2ef5888b835d4c35ac9151b1844741ea11..eae1c27cde7607d2aa20efbf966fe9a052ad1ddb 100644 (file)
@@ -45,15 +45,7 @@ else:
     os.environ['PATH'] = '{}:{}'.format(os.path.abspath('../../../../build/bin'),
                                         os.environ['PATH'])
 
-    # Mock ceph module otherwise every module that is involved in a testcase and imports it will
-    # raise an ImportError
-    import sys
-    try:
-        import mock
-    except ImportError:
-        import unittest.mock as mock
-
-    sys.modules['ceph_module'] = mock.Mock()
+    from tests import mock
 
     mgr = mock.Mock()
     mgr.get_frontend_path.side_effect = lambda: os.path.abspath("./frontend/dist")
diff --git a/src/pybind/mgr/orchestrator_cli/CMakeLists.txt b/src/pybind/mgr/orchestrator_cli/CMakeLists.txt
deleted file mode 100644 (file)
index 68c3346..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-if(WITH_TESTS)
-  include(AddCephTest)
-  add_tox_test(mgr-orchestrator_cli)
-endif()
diff --git a/src/pybind/mgr/orchestrator_cli/requirements.txt b/src/pybind/mgr/orchestrator_cli/requirements.txt
deleted file mode 100644 (file)
index 2585d05..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-tox==2.9.1
-../../../python-common
-pytest
-mock
-requests-mock
diff --git a/src/pybind/mgr/orchestrator_cli/test_orchestrator.py b/src/pybind/mgr/orchestrator_cli/test_orchestrator.py
deleted file mode 100644 (file)
index de50acb..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-from __future__ import absolute_import
-import json
-
-import pytest
-
-from ceph.deployment import inventory
-from orchestrator import ReadCompletion, raise_if_exception, RGWSpec
-from orchestrator import InventoryNode, ServiceDescription
-from orchestrator import OrchestratorValidationError
-
-
-def _test_resource(data, resource_class, extra=None):
-    # ensure we can deserialize and serialize
-    rsc = resource_class.from_json(data)
-    rsc.to_json()
-
-    if extra:
-        # if there is an unexpected data provided
-        data.update(extra)
-        with pytest.raises(OrchestratorValidationError):
-            resource_class.from_json(data)
-
-
-def test_inventory():
-    json_data = {
-        'name': 'host0',
-        'devices': [
-            {
-                'sys_api': {
-                    'rotational': '1',
-                    'size': 1024,
-                },
-                'path': '/dev/sda',
-                'available': False,
-                'rejected_reasons': [],
-                'lvs': []
-            }
-        ]
-    }
-    _test_resource(json_data, InventoryNode, {'abc': False})
-    for devices in json_data['devices']:
-        _test_resource(devices, inventory.Device)
-
-    json_data = [{}, {'name': 'host0'}, {'devices': []}]
-    for data in json_data:
-        with pytest.raises(OrchestratorValidationError):
-            InventoryNode.from_json(data)
-
-
-def test_service_description():
-    json_data = {
-        'nodename': 'test',
-        'service_type': 'mon',
-        'service_instance': 'a'
-    }
-    _test_resource(json_data, ServiceDescription, {'abc': False})
-
-
-def test_raise():
-    c = ReadCompletion()
-    c.exception = ZeroDivisionError()
-    with pytest.raises(ZeroDivisionError):
-        raise_if_exception(c)
-
-
-def test_rgwspec():
-    """
-    {
-        "rgw_zone": "zonename",
-        "rgw_frontend_port": 8080,
-        "rgw_zonegroup": "group",
-        "rgw_zone_user": "user",
-        "rgw_realm": "realm",
-        "count": 3
-    }
-    """
-    example = json.loads(test_rgwspec.__doc__.strip())
-    spec = RGWSpec.from_json(example)
-    assert spec.validate_add() is None
index 86a816f125fbecf183fdd41ae68e02a7953eafac..103aee7332099cd314f7a7b74c252b4606baef52 100644 (file)
@@ -1 +1,3 @@
 pytest-cov==2.7.1
+mock; python_version <= '3.3'
+../../python-common
diff --git a/src/pybind/mgr/tests/__init__.py b/src/pybind/mgr/tests/__init__.py
new file mode 100644 (file)
index 0000000..666875d
--- /dev/null
@@ -0,0 +1,34 @@
+from __future__ import absolute_import
+
+
+import os
+
+if 'UNITTEST' in os.environ:
+
+    # Mock ceph_module. Otherwise every module that is involved in a testcase and imports it will
+    # raise an ImportError
+
+    import sys
+
+    try:
+        from unittest import mock
+    except ImportError:
+        import mock
+
+    class M(object):
+        def __init__(self, *args):
+            super(M, self).__init__()
+            self._ceph_get_version = mock.Mock()
+            self._ceph_get = mock.MagicMock()
+            self._ceph_get_module_option = mock.MagicMock()
+            self._ceph_log = mock.MagicMock()
+            self._ceph_get_option = mock.MagicMock()
+            self._ceph_get_store = lambda _: ''
+            self._ceph_get_store_prefix = lambda _: {}
+
+
+    cm = mock.Mock()
+    cm.BaseMgrModule = M
+    cm.BaseMgrStandbyModule = M
+    sys.modules['ceph_module'] = cm
+    sys.modules['rados'] = mock.Mock()
diff --git a/src/pybind/mgr/tests/test_orchestrator.py b/src/pybind/mgr/tests/test_orchestrator.py
new file mode 100644 (file)
index 0000000..de50acb
--- /dev/null
@@ -0,0 +1,79 @@
+from __future__ import absolute_import
+import json
+
+import pytest
+
+from ceph.deployment import inventory
+from orchestrator import ReadCompletion, raise_if_exception, RGWSpec
+from orchestrator import InventoryNode, ServiceDescription
+from orchestrator import OrchestratorValidationError
+
+
+def _test_resource(data, resource_class, extra=None):
+    # ensure we can deserialize and serialize
+    rsc = resource_class.from_json(data)
+    rsc.to_json()
+
+    if extra:
+        # if there is an unexpected data provided
+        data.update(extra)
+        with pytest.raises(OrchestratorValidationError):
+            resource_class.from_json(data)
+
+
+def test_inventory():
+    json_data = {
+        'name': 'host0',
+        'devices': [
+            {
+                'sys_api': {
+                    'rotational': '1',
+                    'size': 1024,
+                },
+                'path': '/dev/sda',
+                'available': False,
+                'rejected_reasons': [],
+                'lvs': []
+            }
+        ]
+    }
+    _test_resource(json_data, InventoryNode, {'abc': False})
+    for devices in json_data['devices']:
+        _test_resource(devices, inventory.Device)
+
+    json_data = [{}, {'name': 'host0'}, {'devices': []}]
+    for data in json_data:
+        with pytest.raises(OrchestratorValidationError):
+            InventoryNode.from_json(data)
+
+
+def test_service_description():
+    json_data = {
+        'nodename': 'test',
+        'service_type': 'mon',
+        'service_instance': 'a'
+    }
+    _test_resource(json_data, ServiceDescription, {'abc': False})
+
+
+def test_raise():
+    c = ReadCompletion()
+    c.exception = ZeroDivisionError()
+    with pytest.raises(ZeroDivisionError):
+        raise_if_exception(c)
+
+
+def test_rgwspec():
+    """
+    {
+        "rgw_zone": "zonename",
+        "rgw_frontend_port": 8080,
+        "rgw_zonegroup": "group",
+        "rgw_zone_user": "user",
+        "rgw_realm": "realm",
+        "count": 3
+    }
+    """
+    example = json.loads(test_rgwspec.__doc__.strip())
+    spec = RGWSpec.from_json(example)
+    assert spec.validate_add() is None
index a9e837082956661b5701bdef321e4f917acda80e..4205dce13459f71d725392416de6d3d0aba67d2a 100644 (file)
@@ -3,5 +3,6 @@ envlist = py3
 skipsdist = true
 
 [testenv]
+setenv = UNITTEST = true
 deps = -rrequirements.txt
-commands = pytest --cov --cov-append --cov-report=term --doctest-modules mgr_util.py {posargs}
+commands = pytest --cov --cov-append --cov-report=term --doctest-modules {posargs:mgr_util.py tests/}
\ No newline at end of file