]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/cephadm: fix tests
authorSage Weil <sage@redhat.com>
Fri, 14 Feb 2020 18:50:32 +0000 (12:50 -0600)
committerSage Weil <sage@redhat.com>
Tue, 18 Feb 2020 21:50:01 +0000 (15:50 -0600)
Signed-off-by: Sage Weil <sage@redhat.com>
src/pybind/mgr/cephadm/tests/test_cephadm.py

index cf9b1bfe3c23d6206533dea9d986e573e011fb7c..afc54164d55084933eb077d42ff131efc5715194 100644 (file)
@@ -57,20 +57,26 @@ class TestCephadm(object):
 
     @mock.patch("cephadm.module.CephadmOrchestrator._get_connection")
     @mock.patch("cephadm.module.CephadmOrchestrator._run_cephadm", _run_cephadm('[]'))
-    def test_host(self, _get_connection, cephadm_module):
+    @mock.patch("cephadm.module.CephadmOrchestrator._daemon_cache_save_host")
+    @mock.patch("cephadm.module.CephadmOrchestrator._daemon_cache_rm_host")
+    def test_host(self, _get_connection, _save_host, _rm_host, cephadm_module):
         with self._with_host(cephadm_module, 'test'):
             assert wait(cephadm_module, cephadm_module.get_hosts()) == [InventoryNode('test')]
         c = cephadm_module.get_hosts()
         assert wait(cephadm_module, c) == []
 
     @mock.patch("cephadm.module.CephadmOrchestrator._run_cephadm", _run_cephadm('[]'))
-    def test_service_ls(self, cephadm_module):
+    @mock.patch("cephadm.module.CephadmOrchestrator._daemon_cache_save_host")
+    @mock.patch("cephadm.module.CephadmOrchestrator._daemon_cache_rm_host")
+    def test_service_ls(self, _save_host, _rm_host, cephadm_module):
         with self._with_host(cephadm_module, 'test'):
             c = cephadm_module.list_daemons(refresh=True)
             assert wait(cephadm_module, c) == []
 
     @mock.patch("cephadm.module.CephadmOrchestrator._run_cephadm", _run_cephadm('[]'))
-    def test_device_ls(self, cephadm_module):
+    @mock.patch("cephadm.module.CephadmOrchestrator._daemon_cache_save_host")
+    @mock.patch("cephadm.module.CephadmOrchestrator._daemon_cache_rm_host")
+    def test_device_ls(self, _save_host, _rm_host, cephadm_module):
         with self._with_host(cephadm_module, 'test'):
             c = cephadm_module.get_inventory()
             assert wait(cephadm_module, c) == [InventoryNode('test')]
@@ -90,7 +96,9 @@ class TestCephadm(object):
     @mock.patch("cephadm.module.CephadmOrchestrator.send_command")
     @mock.patch("cephadm.module.CephadmOrchestrator.mon_command", mon_command)
     @mock.patch("cephadm.module.CephadmOrchestrator._get_connection")
-    def test_daemon_action(self, _send_command, _get_connection, cephadm_module):
+    @mock.patch("cephadm.module.CephadmOrchestrator._daemon_cache_save_host")
+    @mock.patch("cephadm.module.CephadmOrchestrator._daemon_cache_rm_host")
+    def test_daemon_action(self, _send_command, _get_connection, _save_host, _rm_host, cephadm_module):
         cephadm_module.service_cache_timeout = 10
         with self._with_host(cephadm_module, 'test'):
             c = cephadm_module.list_daemons(refresh=True)
@@ -107,7 +115,9 @@ class TestCephadm(object):
     @mock.patch("cephadm.module.CephadmOrchestrator.send_command")
     @mock.patch("cephadm.module.CephadmOrchestrator.mon_command", mon_command)
     @mock.patch("cephadm.module.CephadmOrchestrator._get_connection")
-    def test_mon_update(self, _send_command, _get_connection, cephadm_module):
+    @mock.patch("cephadm.module.CephadmOrchestrator._daemon_cache_save_host")
+    @mock.patch("cephadm.module.CephadmOrchestrator._daemon_cache_rm_host")
+    def test_mon_update(self, _send_command, _get_connection, _save_host, _rm_host, cephadm_module):
         with self._with_host(cephadm_module, 'test'):
             ps = PlacementSpec(hosts=['test:0.0.0.0=a'], count=1)
             c = cephadm_module.apply_mon(ServiceSpec(placement=ps))
@@ -117,7 +127,9 @@ class TestCephadm(object):
     @mock.patch("cephadm.module.CephadmOrchestrator.send_command")
     @mock.patch("cephadm.module.CephadmOrchestrator.mon_command", mon_command)
     @mock.patch("cephadm.module.CephadmOrchestrator._get_connection")
-    def test_mgr_update(self, _send_command, _get_connection, cephadm_module):
+    @mock.patch("cephadm.module.CephadmOrchestrator._daemon_cache_save_host")
+    @mock.patch("cephadm.module.CephadmOrchestrator._daemon_cache_rm_host")
+    def test_mgr_update(self, _send_command, _get_connection, _save_host, _rm_host, cephadm_module):
         with self._with_host(cephadm_module, 'test'):
             ps = PlacementSpec(hosts=['test:0.0.0.0=a'], count=1)
             c = cephadm_module.apply_mgr(ServiceSpec(placement=ps))
@@ -129,7 +141,9 @@ class TestCephadm(object):
     @mock.patch("cephadm.module.CephadmOrchestrator.send_command")
     @mock.patch("cephadm.module.CephadmOrchestrator.mon_command", mon_command)
     @mock.patch("cephadm.module.CephadmOrchestrator._get_connection")
-    def test_create_osds(self, _send_command, _get_connection, cephadm_module):
+    @mock.patch("cephadm.module.CephadmOrchestrator._daemon_cache_save_host")
+    @mock.patch("cephadm.module.CephadmOrchestrator._daemon_cache_rm_host")
+    def test_create_osds(self, _send_command, _get_connection, _save_host, _rm_host, cephadm_module):
         with self._with_host(cephadm_module, 'test'):
             dg = DriveGroupSpec('test', data_devices=DeviceSelection(paths=['']))
             c = cephadm_module.create_osds([dg])
@@ -147,7 +161,9 @@ class TestCephadm(object):
             )
         ])
     ))
-    def test_remove_osds(self, cephadm_module):
+    @mock.patch("cephadm.module.CephadmOrchestrator._daemon_cache_save_host")
+    @mock.patch("cephadm.module.CephadmOrchestrator._daemon_cache_rm_host")
+    def test_remove_osds(self, _save_host, _rm_host, cephadm_module):
         with self._with_host(cephadm_module, 'test'):
             c = cephadm_module.list_daemons(refresh=True)
             wait(cephadm_module, c)
@@ -159,7 +175,9 @@ class TestCephadm(object):
     @mock.patch("cephadm.module.CephadmOrchestrator.send_command")
     @mock.patch("cephadm.module.CephadmOrchestrator.mon_command", mon_command)
     @mock.patch("cephadm.module.CephadmOrchestrator._get_connection")
-    def test_mds(self, _send_command, _get_connection, cephadm_module):
+    @mock.patch("cephadm.module.CephadmOrchestrator._daemon_cache_save_host")
+    @mock.patch("cephadm.module.CephadmOrchestrator._daemon_cache_rm_host")
+    def test_mds(self, _send_command, _get_connection, _save_host, _rm_host, cephadm_module):
         with self._with_host(cephadm_module, 'test'):
             ps = PlacementSpec(hosts=['test'], count=1)
             c = cephadm_module.add_mds(ServiceSpec('name', placement=ps))
@@ -170,7 +188,9 @@ class TestCephadm(object):
     @mock.patch("cephadm.module.CephadmOrchestrator.send_command")
     @mock.patch("cephadm.module.CephadmOrchestrator.mon_command", mon_command)
     @mock.patch("cephadm.module.CephadmOrchestrator._get_connection")
-    def test_rgw(self, _send_command, _get_connection, cephadm_module):
+    @mock.patch("cephadm.module.CephadmOrchestrator._daemon_cache_save_host")
+    @mock.patch("cephadm.module.CephadmOrchestrator._daemon_cache_rm_host")
+    def test_rgw(self, _send_command, _get_connection, _save_host, _rm_host, cephadm_module):
 
         with self._with_host(cephadm_module, 'test'):
             ps = PlacementSpec(hosts=['test'], count=1)
@@ -183,7 +203,9 @@ class TestCephadm(object):
     @mock.patch("cephadm.module.CephadmOrchestrator.send_command")
     @mock.patch("cephadm.module.CephadmOrchestrator.mon_command", mon_command)
     @mock.patch("cephadm.module.CephadmOrchestrator._get_connection")
-    def test_rgw_update(self, _send_command, _get_connection, cephadm_module):
+    @mock.patch("cephadm.module.CephadmOrchestrator._daemon_cache_save_host")
+    @mock.patch("cephadm.module.CephadmOrchestrator._daemon_cache_rm_host")
+    def test_rgw_update(self, _send_command, _get_connection, _save_host, _rm_host, cephadm_module):
 
         with self._with_host(cephadm_module, 'host1'):
             with self._with_host(cephadm_module, 'host2'):
@@ -201,7 +223,10 @@ class TestCephadm(object):
     @mock.patch("cephadm.module.CephadmOrchestrator.send_command")
     @mock.patch("cephadm.module.CephadmOrchestrator.mon_command", mon_command)
     @mock.patch("cephadm.module.CephadmOrchestrator._get_connection")
-    def test_rgw_update_fail(self, _send_command, _get_connection, cephadm_module):
+    @mock.patch("cephadm.module.CephadmOrchestrator._daemon_cache_save_host")
+    @mock.patch("cephadm.module.CephadmOrchestrator._daemon_cache_rm_host")
+    @mock.patch("cephadm.module.CephadmOrchestrator.serve", None)
+    def test_rgw_update_fail(self, _send_command, _get_connection, _save_host, _rm_host, cephadm_module):
 
         with self._with_host(cephadm_module, 'host1'):
             with self._with_host(cephadm_module, 'host2'):
@@ -215,9 +240,13 @@ class TestCephadm(object):
                 [out] = wait(cephadm_module, c)
                 match_glob(out, "Deployed rgw.realm.zone2.host2.* on host 'host2'")
 
+                c = cephadm_module.list_daemons()
+                r = wait(cephadm_module, c)
+                assert len(r) == 2
+
                 with pytest.raises(OrchestratorError):
                     ps = PlacementSpec(hosts=['host1', 'host2'], count=2)
-                    c = cephadm_module.apply_rgw(RGWSpec('realm', 'zone1', placement=ps))
+                    c = cephadm_module.add_rgw(RGWSpec('realm', 'zone1', placement=ps))
                     [out] = wait(cephadm_module, c)
 
 
@@ -233,7 +262,9 @@ class TestCephadm(object):
             )
         ])
     ))
-    def test_remove_daemon(self, cephadm_module):
+    @mock.patch("cephadm.module.CephadmOrchestrator._daemon_cache_save_host")
+    @mock.patch("cephadm.module.CephadmOrchestrator._daemon_cache_rm_host")
+    def test_remove_daemon(self, _save_host, _rm_host, cephadm_module):
         with self._with_host(cephadm_module, 'test'):
             c = cephadm_module.list_daemons(refresh=True)
             wait(cephadm_module, c)
@@ -253,7 +284,9 @@ class TestCephadm(object):
             )
         ])
     ))
-    def test_remove_service(self, cephadm_module):
+    @mock.patch("cephadm.module.CephadmOrchestrator._daemon_cache_save_host")
+    @mock.patch("cephadm.module.CephadmOrchestrator._daemon_cache_rm_host")
+    def test_remove_service(self, _save_host, _rm_host, cephadm_module):
         with self._with_host(cephadm_module, 'test'):
             c = cephadm_module.list_daemons(refresh=True)
             wait(cephadm_module, c)
@@ -265,7 +298,9 @@ class TestCephadm(object):
     @mock.patch("cephadm.module.CephadmOrchestrator.send_command")
     @mock.patch("cephadm.module.CephadmOrchestrator.mon_command", mon_command)
     @mock.patch("cephadm.module.CephadmOrchestrator._get_connection")
-    def test_rbd_mirror(self, _send_command, _get_connection, cephadm_module):
+    @mock.patch("cephadm.module.CephadmOrchestrator._daemon_cache_save_host")
+    @mock.patch("cephadm.module.CephadmOrchestrator._daemon_cache_rm_host")
+    def test_rbd_mirror(self, _send_command, _get_connection, _save_host, _rm_host, cephadm_module):
         with self._with_host(cephadm_module, 'test'):
             ps = PlacementSpec(hosts=['test'], count=1)
             c = cephadm_module.add_rbd_mirror(ServiceSpec(name='name', placement=ps))
@@ -277,26 +312,23 @@ class TestCephadm(object):
     @mock.patch("cephadm.module.CephadmOrchestrator.send_command")
     @mock.patch("cephadm.module.CephadmOrchestrator.mon_command", mon_command)
     @mock.patch("cephadm.module.CephadmOrchestrator._get_connection")
-    def test_prometheus(self, _send_command, _get_connection, cephadm_module):
+    @mock.patch("cephadm.module.CephadmOrchestrator._daemon_cache_save_host")
+    @mock.patch("cephadm.module.CephadmOrchestrator._daemon_cache_rm_host")
+    def test_prometheus(self, _send_command, _get_connection, _save_host, _rm_host, cephadm_module):
         with self._with_host(cephadm_module, 'test'):
             ps = PlacementSpec(hosts=['test'], count=1)
 
             c = cephadm_module.add_prometheus(ServiceSpec(placement=ps))
             [out] = wait(cephadm_module, c)
-            assert "Deployed prometheus." in out
-            assert " on host 'test'" in out
-
-            ps = PlacementSpec(hosts=['test'], count=2)
-            c = cephadm_module.apply_prometheus(ServiceSpec(placement=ps))
-            [out] = wait(cephadm_module, c)
-            assert "Deployed prometheus." in out
-            assert " on host 'test'" in out
+            match_glob(out, "Deployed prometheus.* on host 'test'")
 
     @mock.patch("cephadm.module.CephadmOrchestrator._run_cephadm", _run_cephadm('{}'))
     @mock.patch("cephadm.module.CephadmOrchestrator.send_command")
     @mock.patch("cephadm.module.CephadmOrchestrator.mon_command", mon_command)
     @mock.patch("cephadm.module.CephadmOrchestrator._get_connection")
-    def test_blink_device_light(self, _send_command, _get_connection, cephadm_module):
+    @mock.patch("cephadm.module.CephadmOrchestrator._daemon_cache_save_host")
+    @mock.patch("cephadm.module.CephadmOrchestrator._daemon_cache_rm_host")
+    def test_blink_device_light(self, _send_command, _get_connection, _save_host, _rm_host, cephadm_module):
         with self._with_host(cephadm_module, 'test'):
             c = cephadm_module.blink_device_light('ident', True, [('test', '', '')])
             assert wait(cephadm_module, c) == ['Set ident light for test: on']