From: Kiefer Chang Date: Mon, 3 Aug 2020 11:20:08 +0000 (+0800) Subject: mgr/dashboard: Fix host attributes like labels are not returned X-Git-Tag: v15.2.5~39^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F36678%2Fhead;p=ceph.git mgr/dashboard: Fix host attributes like labels are not returned 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 (cherry picked from commit 8f393f8e1bc2f5b20d2582aa48cefef23edc2153) --- diff --git a/src/pybind/mgr/dashboard/controllers/host.py b/src/pybind/mgr/dashboard/controllers/host.py index 0426708e7e26..ff3b2123b2a7 100644 --- a/src/pybind/mgr/dashboard/controllers/host.py +++ b/src/pybind/mgr/dashboard/controllers/host.py @@ -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) diff --git a/src/pybind/mgr/dashboard/tests/test_host.py b/src/pybind/mgr/dashboard/tests/test_host.py index 17683232bb6a..ab7286074b73 100644 --- a/src/pybind/mgr/dashboard/tests/test_host.py +++ b/src/pybind/mgr/dashboard/tests/test_host.py @@ -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'])