]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/orchestrator: add tests to host, mgr and mon mgmt 26314/head
authorSebastian Wagner <sebastian.wagner@suse.com>
Thu, 7 Feb 2019 11:23:51 +0000 (12:23 +0100)
committerSebastian Wagner <sebastian.wagner@suse.com>
Thu, 7 Feb 2019 11:23:51 +0000 (12:23 +0100)
Signed-off-by: Sebastian Wagner <sebastian.wagner@suse.com>
qa/tasks/mgr/test_orchestrator_cli.py
src/pybind/mgr/orchestrator.py
src/pybind/mgr/orchestrator_cli/module.py
src/pybind/mgr/test_orchestrator/module.py

index 3caa956e3b0fe6e16ba54edd502705cf64c5eee8..c67a77274967050089460aaf621e42bf7b7df4a3 100644 (file)
@@ -104,3 +104,21 @@ class TestOrchestratorCli(MgrTestCase):
 
     def test_nfs_rm(self):
         self._orch_cmd("nfs", "rm", "service_name")
+
+    def test_host_ls(self):
+        out = self._orch_cmd("host", "ls")
+        self.assertEqual(out, "localhost\n")
+
+    def test_host_add(self):
+        self._orch_cmd("host", "add", "hostname")
+
+    def test_host_rm(self):
+        self._orch_cmd("host", "rm", "hostname")
+
+    def test_mon_update(self):
+        self._orch_cmd("mon", "update", "3")
+        self._orch_cmd("mon", "update", "3", "host1", "host2", "host3")
+        self._orch_cmd("mon", "update", "3", "host1:network", "host2:network", "host3:network")
+
+    def test_mgr_update(self):
+        self._orch_cmd("mgr", "update", "3")
index e440d9a71214f22adde67eb1447fdfcfe03c442e..fd28cce59ee2d0d0c14d91229a15844f93df30a3 100644 (file)
@@ -308,12 +308,12 @@ class Orchestrator(object):
         raise NotImplementedError()
 
     def update_mons(self, num, hosts):
-        # type: (int, List[List[str,str]]) -> WriteCompletion
+        # type: (int, List[Tuple[str,str]]) -> WriteCompletion
         """
         Update the number of cluster monitors.
 
         :param num: requested number of monitors.
-        :param hosts: list of hosts (optional)
+        :param hosts: list of hosts + network (optional)
         """
         raise NotImplementedError()
 
@@ -796,9 +796,10 @@ class InventoryNode(object):
     InventoryNode.
     """
     def __init__(self, name, devices):
+        # type: (str, List[InventoryDevice]) -> None
         assert isinstance(devices, list)
         self.name = name  # unique within cluster.  For example a hostname.
-        self.devices = devices  # type: List[InventoryDevice]
+        self.devices = devices
 
     def to_json(self):
         return {'name': self.name, 'devices': [d.to_json() for d in self.devices]}
index eed1abbe26c878fca15dde66361ce0c6b4b6bbd8..b54b68dca2a8a1d74819fbdf07683fb44db1b564 100644 (file)
@@ -49,8 +49,7 @@ class OrchestratorCli(orchestrator.OrchestratorClientMixin, MgrModule):
     def _add_host(self, host):
         completion = self.add_host(host)
         self._orchestrator_wait([completion])
-        result = "\n".join(map(lambda r: str(r), completion.result))
-        return HandleCommandResult(stdout=result)
+        return HandleCommandResult(stdout=str(completion.result))
 
     @CLIWriteCommand('orchestrator host rm',
                      "name=host,type=CephString,req=true",
@@ -59,8 +58,7 @@ class OrchestratorCli(orchestrator.OrchestratorClientMixin, MgrModule):
     def _remove_host(self, host):
         completion = self.remove_host(host)
         self._orchestrator_wait([completion])
-        result = "\n".join(map(lambda r: str(r), completion.result))
-        return HandleCommandResult(stdout=result)
+        return HandleCommandResult(stdout=str(completion.result))
 
     @CLIReadCommand('orchestrator host ls',
                     desc='List hosts')
@@ -306,7 +304,7 @@ Usage:
                      "name=hosts,type=CephString,n=N,req=false",
                      'Update the number of manager instances')
     @handle_exceptions
-    def _update_mgrs(self, num, hosts):
+    def _update_mgrs(self, num, hosts=None):
         hosts = hosts if hosts is not None else []
 
         if num <= 0:
@@ -315,15 +313,14 @@ Usage:
 
         completion = self.update_mgrs(num, hosts)
         self._orchestrator_wait([completion])
-        result = "\n".join(map(lambda r: str(r), completion.result))
-        return HandleCommandResult(stdout=result)
+        return HandleCommandResult(stdout=str(completion.result))
 
     @CLIWriteCommand('orchestrator mon update',
                      "name=num,type=CephInt,req=true "
                      "name=hosts,type=CephString,n=N,req=false",
                      'Update the number of monitor instances')
     @handle_exceptions
-    def _update_mons(self, num, hosts):
+    def _update_mons(self, num, hosts=None):
         hosts = hosts if hosts is not None else []
 
         if num <= 0:
@@ -351,8 +348,7 @@ Usage:
 
         completion = self.update_mons(num, hosts)
         self._orchestrator_wait([completion])
-        result = "\n".join(map(lambda r: str(r), completion.result))
-        return HandleCommandResult(stdout=result)
+        return HandleCommandResult(stdout=str(completion.result))
 
     @CLIWriteCommand('orchestrator set backend',
                      "name=module_name,type=CephString,req=true",
index de0a819eab953c276f4da134136174e98dfa5c29..a5397358e5640e2602d8660bfe1ea0695565a764 100644 (file)
@@ -125,7 +125,6 @@ class TestOrchestrator(MgrModule, orchestrator.Orchestrator):
 
     The implementation is similar to the Rook orchestrator, but simpler.
     """
-
     def _progress(self, *args, **kwargs):
         try:
             self.remote("progress", *args, **kwargs)
@@ -270,3 +269,26 @@ class TestOrchestrator(MgrModule, orchestrator.Orchestrator):
     @deferred_write("remove_stateless_service")
     def remove_stateless_service(self, service_type, id_):
         pass
+
+    @deferred_read
+    def get_hosts(self):
+        return [orchestrator.InventoryNode('localhost', [])]
+
+    @deferred_write("add_host")
+    def add_host(self, host):
+        assert isinstance(host, str)
+
+    @deferred_write("remove_host")
+    def remove_host(self, host):
+        assert isinstance(host, str)
+
+    @deferred_write("update_mgrs")
+    def update_mgrs(self, num, hosts):
+        assert not hosts or len(hosts) == num
+        assert all([isinstance(h, str) for h in hosts])
+
+    @deferred_write("update_mons")
+    def update_mons(self, num, hosts):
+        assert not hosts or len(hosts) == num
+        assert all([isinstance(h[0], str) for h in hosts])
+        assert all([isinstance(h[1], str) or h[1] is None for h in hosts])