]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: Fix host attributes like labels are not returned 36678/head
authorKiefer Chang <kiefer.chang@suse.com>
Mon, 3 Aug 2020 11:20:08 +0000 (19:20 +0800)
committerKiefer Chang <kiefer.chang@suse.com>
Mon, 17 Aug 2020 06:54:18 +0000 (14:54 +0800)
The problem only happens when a host is reported both from Ceph and the
Orchestrator. There is an error on merging Ceph hosts with Orchestrator
hosts. The unit test is refined to test this case.

Fixes: https://tracker.ceph.com/issues/46761
Signed-off-by: Kiefer Chang <kiefer.chang@suse.com>
(cherry picked from commit 8f393f8e1bc2f5b20d2582aa48cefef23edc2153)

src/pybind/mgr/dashboard/controllers/host.py
src/pybind/mgr/dashboard/tests/test_host.py

index 0426708e7e261500274d0393470d8354dccd2c18..ff3b2123b2a72eb7fc95b61eb63faea83fb33460 100644 (file)
@@ -46,7 +46,7 @@ def merge_hosts_by_hostname(ceph_hosts, orch_hosts):
     for host in hosts:
         hostname = host['hostname']
         if hostname in orch_hosts_map:
-            host = merge_dicts(host, orch_hosts_map[hostname])
+            host.update(orch_hosts_map[hostname])
             host['sources']['orchestrator'] = True
             orch_hosts_map.pop(hostname)
 
index 17683232bb6aaa7b1204dabfc290aeec08abed45..ab7286074b7386b53adb88a99756a2ffdc8e3c31 100644 (file)
@@ -163,27 +163,37 @@ class TestHosts(unittest.TestCase):
         fake_client = mock.Mock()
         fake_client.available.return_value = True
         fake_client.hosts.list.return_value = [
-            HostSpec('node1'), HostSpec('node2')
+            HostSpec('node1', labels=['foo', 'bar']),
+            HostSpec('node2', labels=['bar'])
         ]
         instance.return_value = fake_client
 
         hosts = get_hosts()
         self.assertEqual(len(hosts), 3)
-        check_sources = {
+        checks = {
             'localhost': {
-                'ceph': True,
-                'orchestrator': False
+                'sources': {
+                    'ceph': True,
+                    'orchestrator': False
+                },
+                'labels': []
             },
             'node1': {
-                'ceph': True,
-                'orchestrator': True
+                'sources': {
+                    'ceph': True,
+                    'orchestrator': True
+                },
+                'labels': ['bar', 'foo']
             },
             'node2': {
-                'ceph': False,
-                'orchestrator': True
+                'sources': {
+                    'ceph': False,
+                    'orchestrator': True
+                },
+                'labels': ['bar']
             }
         }
         for host in hosts:
             hostname = host['hostname']
-            sources = host['sources']
-            self.assertDictEqual(sources, check_sources[hostname])
+            self.assertDictEqual(host['sources'], checks[hostname]['sources'])
+            self.assertListEqual(host['labels'], checks[hostname]['labels'])