From 0e6b623572ff99c28428465b4f6a51cfe60d446a Mon Sep 17 00:00:00 2001 From: Kiefer Chang Date: Mon, 3 Aug 2020 19:20:08 +0800 Subject: [PATCH] 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) --- src/pybind/mgr/dashboard/controllers/host.py | 2 +- src/pybind/mgr/dashboard/tests/test_host.py | 30 +++++++++++++------- 2 files changed, 21 insertions(+), 11 deletions(-) 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']) -- 2.47.3