From: Tim Serong Date: Wed, 19 Jun 2019 06:24:19 +0000 (+1000) Subject: mgr/deepsea: gracefully handle nonexistent nodes in {service,device} ls X-Git-Tag: v15.1.0~2201^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=79d6034f4e295b58579164c7ee3f45d2ef1be97c;p=ceph.git mgr/deepsea: gracefully handle nonexistent nodes in {service,device} ls Signed-off-by: Tim Serong --- diff --git a/src/pybind/mgr/deepsea/module.py b/src/pybind/mgr/deepsea/module.py index e223ad46f26..1d07b01d073 100644 --- a/src/pybind/mgr/deepsea/module.py +++ b/src/pybind/mgr/deepsea/module.py @@ -134,9 +134,13 @@ class DeepSeaOrchestrator(MgrModule, orchestrator.Orchestrator): return orchestrator.TrivialReadCompletion( orchestrator.InventoryNode.from_nested_items(self.inventory_cache.items())) elif node_filter.labels is None: - return orchestrator.TrivialReadCompletion( - orchestrator.InventoryNode.from_nested_items( - self.inventory_cache.items_filtered(node_filter.nodes))) + try: + return orchestrator.TrivialReadCompletion( + orchestrator.InventoryNode.from_nested_items( + self.inventory_cache.items_filtered(node_filter.nodes))) + except KeyError: + # items_filtered() will raise KeyError if passed a node name that doesn't exist + return orchestrator.TrivialReadCompletion([]) def process_result(event_data): result = [] @@ -185,13 +189,17 @@ class DeepSeaOrchestrator(MgrModule, orchestrator.Orchestrator): self.service_cache.remove_outdated() if not self.service_cache.any_outdated() and not refresh: # Let's hope the services are complete. - node_filter = [node_name] if node_name else None - services_by_node = [d[1].data for d in self.service_cache.items_filtered(node_filter)] - services = [orchestrator.ServiceDescription.from_json(s) for services in services_by_node for s in services] - services = [s for s in services if - (True if service_type is None else s.service_type == service_type) and - (True if service_id is None else s.service_instance == service_id)] - return orchestrator.TrivialReadCompletion(services) + try: + node_filter = [node_name] if node_name else None + services_by_node = [d[1].data for d in self.service_cache.items_filtered(node_filter)] + services = [orchestrator.ServiceDescription.from_json(s) for services in services_by_node for s in services] + services = [s for s in services if + (True if service_type is None else s.service_type == service_type) and + (True if service_id is None else s.service_instance == service_id)] + return orchestrator.TrivialReadCompletion(services) + except KeyError: + # items_filtered() will raise KeyError if passed a node name that doesn't exist + return orchestrator.TrivialReadCompletion([]) def process_result(event_data): result = []