]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
pybind/mgr: tox.ini add nooptional testenv
authorSebastian Wagner <sewagner@redhat.com>
Mon, 6 Sep 2021 10:21:58 +0000 (12:21 +0200)
committerSebastian Wagner <sewagner@redhat.com>
Mon, 6 Sep 2021 10:27:28 +0000 (12:27 +0200)
To verify cephadm properly works as expected without asyncssh installed

Signed-off-by: Sebastian Wagner <sewagner@redhat.com>
src/pybind/mgr/CMakeLists.txt
src/pybind/mgr/cephadm/tests/test_cephadm.py
src/pybind/mgr/cephadm/tests/test_ssh.py [new file with mode: 0644]
src/pybind/mgr/requirements-required.txt [new file with mode: 0644]
src/pybind/mgr/requirements.txt
src/pybind/mgr/tox.ini

index 5193f05f43d3b79eabe231ba44782c0a963734ca..8fcb62a8a834950a985f9bc9818998add9613d4a 100644 (file)
@@ -13,7 +13,7 @@ if(WITH_MGR_ROOK_CLIENT)
 endif()
 if(WITH_TESTS)
   include(AddCephTest)
-  add_tox_test(mgr ${CMAKE_CURRENT_SOURCE_DIR} TOX_ENVS py3 mypy flake8 jinjalint)
+  add_tox_test(mgr ${CMAKE_CURRENT_SOURCE_DIR} TOX_ENVS py3 mypy flake8 jinjalint nooptional)
 endif()
 
 # Location needs to match default setting for mgr_module_path, currently:
index c2e845351487aa378562a378a11e8a33aa1cec17..2cde6ce1415d966af964deb36aab82b32945c698 100644 (file)
@@ -1,11 +1,4 @@
 import json
-try:
-    # AsyncMock was not added until python 3.8
-    from unittest.mock import AsyncMock
-except ImportError:
-    from asyncmock import AsyncMock
-except ImportError:
-    AsyncMock = None
 
 from contextlib import contextmanager
 
@@ -22,8 +15,6 @@ try:
 except ImportError:
     pass
 
-from asyncssh.misc import ConnectionLost
-
 from ceph.deployment.service_spec import ServiceSpec, PlacementSpec, RGWSpec, \
     NFSServiceSpec, IscsiServiceSpec, HostPlacementSpec, CustomContainerSpec
 from ceph.deployment.drive_selection.selector import DriveSelection
@@ -1084,32 +1075,6 @@ spec:
             assert_rm_daemon(cephadm_module, spec.service_name(), 'host1')  # verifies ok-to-stop
             assert_rm_daemon(cephadm_module, spec.service_name(), 'host2')
 
-    @mock.patch("cephadm.ssh.SSHManager.execute_command")
-    @mock.patch("cephadm.ssh.SSHManager.check_execute_command")
-    def test_offline(self, check_execute_command, execute_command, cephadm_module):
-        check_execute_command.return_value = ''
-        execute_command.return_value = '', '', 0
-
-        if not AsyncMock:
-            # can't run this test if we could not import AsyncMock
-            return
-        mock_connect = AsyncMock(return_value='')
-        with mock.patch("asyncssh.connect", new=mock_connect) as asyncssh_connect:
-            with with_host(cephadm_module, 'test'):
-                asyncssh_connect.side_effect = ConnectionLost('reason')
-                code, out, err = cephadm_module.check_host('test')
-                assert out == ''
-                assert "Host 'test' not found" in err
-
-                out = wait(cephadm_module, cephadm_module.get_hosts())[0].to_json()
-                assert out == HostSpec('test', '1.2.3.4', status='Offline').to_json()
-
-                asyncssh_connect.return_value = mock.MagicMock()
-                asyncssh_connect.side_effect = None
-                assert CephadmServe(cephadm_module)._check_host('test') is None
-                out = wait(cephadm_module, cephadm_module.get_hosts())[0].to_json()
-                assert out == HostSpec('test', '1.2.3.4').to_json()
-
     @mock.patch("cephadm.serve.CephadmServe._run_cephadm", _run_cephadm('{}'))
     def test_dont_touch_offline_or_maintenance_host_daemons(self, cephadm_module):
         # test daemons on offline/maint hosts not removed when applying specs
diff --git a/src/pybind/mgr/cephadm/tests/test_ssh.py b/src/pybind/mgr/cephadm/tests/test_ssh.py
new file mode 100644 (file)
index 0000000..288217b
--- /dev/null
@@ -0,0 +1,55 @@
+from unittest import mock
+try:
+    # AsyncMock was not added until python 3.8
+    from unittest.mock import AsyncMock
+except ImportError:
+    from asyncmock import AsyncMock
+except ImportError:
+    AsyncMock = None
+import pytest
+
+try:
+    from asyncssh.misc import ConnectionLost
+except ImportError:
+    ConnectionLost = None
+
+from ceph.deployment.hostspec import HostSpec
+
+from cephadm import CephadmOrchestrator
+from cephadm.serve import CephadmServe
+from cephadm.tests.fixtures import with_host, wait
+
+
+@pytest.mark.skipif(ConnectionLost is None, reason='no asyncssh')
+class TestWithSSH:
+    @mock.patch("cephadm.ssh.SSHManager.execute_command")
+    @mock.patch("cephadm.ssh.SSHManager.check_execute_command")
+    def test_offline(self, check_execute_command, execute_command, cephadm_module):
+        check_execute_command.return_value = ''
+        execute_command.return_value = '', '', 0
+
+        if not AsyncMock:
+            # can't run this test if we could not import AsyncMock
+            return
+        mock_connect = AsyncMock(return_value='')
+        with mock.patch("asyncssh.connect", new=mock_connect) as asyncssh_connect:
+            with with_host(cephadm_module, 'test'):
+                asyncssh_connect.side_effect = ConnectionLost('reason')
+                code, out, err = cephadm_module.check_host('test')
+                assert out == ''
+                assert "Host 'test' not found" in err
+
+                out = wait(cephadm_module, cephadm_module.get_hosts())[0].to_json()
+                assert out == HostSpec('test', '1.2.3.4', status='Offline').to_json()
+
+                asyncssh_connect.return_value = mock.MagicMock()
+                asyncssh_connect.side_effect = None
+                assert CephadmServe(cephadm_module)._check_host('test') is None
+                out = wait(cephadm_module, cephadm_module.get_hosts())[0].to_json()
+                assert out == HostSpec('test', '1.2.3.4').to_json()
+
+
+@pytest.mark.skipif(ConnectionLost is not None, reason='asyncssh')
+class TestWithoutSSH:
+    def test_can_run(self, cephadm_module: CephadmOrchestrator):
+        assert cephadm_module.can_run() == (False, "loading asyncssh library:No module named 'asyncssh'")
diff --git a/src/pybind/mgr/requirements-required.txt b/src/pybind/mgr/requirements-required.txt
new file mode 100644 (file)
index 0000000..49ea088
--- /dev/null
@@ -0,0 +1,14 @@
+-e../../python-common
+asyncmock
+cherrypy
+jsonpatch
+Jinja2
+pecan
+prettytable
+pyfakefs
+pyOpenSSL
+pytest-cov==2.7.1
+pyyaml
+requests-mock
+scipy
+werkzeug
index 9b315e4562a65292be9efcdbb0ac28f82fa06300..617b6dee2d35765d33d74bd75e99ce60772e3e96 100644 (file)
@@ -1,17 +1,3 @@
-pytest-cov==2.7.1
--e../../python-common
-kubernetes
-requests-mock
-pyyaml
-prettytable
-pyOpenSSL
-Jinja2
-pyfakefs
+-rrequirements-required.txt
 asyncssh
-asyncmock
-
-jsonpatch
-pecan
-scipy
-cherrypy
-werkzeug
+kubernetes
index 0165f77ddbe1563ee1d8068ee93d95a3b3c0b9ac..2256d996bfcf367308234afa1e2dbe0cb07a8dc3 100644 (file)
@@ -6,6 +6,7 @@ envlist =
     fix
     flake8
     jinjalint
+    nooptional
 skipsdist = true
 requires = cython
 
@@ -45,6 +46,17 @@ deps =
 commands =
     pytest --doctest-modules {posargs:}
 
+[testenv:nooptional]
+setenv =
+    UNITTEST = true
+    PYTHONPATH = $PYTHONPATH:..
+deps =
+    cython
+    -rrequirements-required.txt
+commands =
+    pytest {posargs:cephadm/tests/test_ssh.py}
+
+
 [testenv:mypy]
 setenv =
     MYPYPATH = {toxinidir}/..