From 79d6034f4e295b58579164c7ee3f45d2ef1be97c Mon Sep 17 00:00:00 2001 From: Tim Serong Date: Wed, 19 Jun 2019 16:24:19 +1000 Subject: [PATCH] mgr/deepsea: gracefully handle nonexistent nodes in {service,device} ls Signed-off-by: Tim Serong --- src/pybind/mgr/deepsea/module.py | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/pybind/mgr/deepsea/module.py b/src/pybind/mgr/deepsea/module.py index e223ad46f26c7..1d07b01d07368 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 = [] -- 2.39.5