From 175f54b67cb1b2e2de3b490d0727016f141c9cf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20L=C3=B6sche?= Date: Fri, 2 Feb 2024 16:13:34 +0100 Subject: [PATCH] [plugins/aws][fix] Find dangling plugin roots in graph and sanitize them (#1895) * [plugins/aws][fix] Find dangling plugin roots in graph and sanitize them * Remove cloud var --- plugins/aws/resoto_plugin_aws/__init__.py | 7 +++---- resotolib/resotolib/graph/__init__.py | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/plugins/aws/resoto_plugin_aws/__init__.py b/plugins/aws/resoto_plugin_aws/__init__.py index 4e4910a9a9..e996461cf3 100644 --- a/plugins/aws/resoto_plugin_aws/__init__.py +++ b/plugins/aws/resoto_plugin_aws/__init__.py @@ -88,9 +88,8 @@ def collect_aws(self) -> None: log.debug("plugin: AWS collecting resources") aws_config: AwsConfig = Config.aws assert self.core_feedback, "core_feedback is not set" - cloud = Cloud(id=self.cloud, name="AWS") - accounts = get_accounts(self.core_feedback.with_context(cloud.id)) + accounts = get_accounts(self.core_feedback.with_context(self.root.id)) if len(accounts) == 0: log.error("No accounts found") return @@ -123,8 +122,8 @@ def collect_aws(self) -> None: self.regions(profile=account.profile, partition=account.partition), ArgumentParser.args, Config.running_config, - self.core_feedback.with_context(cloud.id, account.dname), - cloud, + self.core_feedback.with_context(self.root.id, account.dname), + self.root, self.task_data or {}, ) for account in accounts diff --git a/resotolib/resotolib/graph/__init__.py b/resotolib/resotolib/graph/__init__.py index 25063b3301..9d9aa85384 100644 --- a/resotolib/resotolib/graph/__init__.py +++ b/resotolib/resotolib/graph/__init__.py @@ -484,6 +484,22 @@ def sanitize(graph: Graph, maybe_root: Optional[GraphRoot] = None) -> None: else: log.debug(f"Found unknown node {node.id} of type {node.kind}") + for node in list(graph.nodes): + if ( + isinstance(node, Cloud) + and node not in plugin_roots.values() + and len(list(graph.predecessors(node))) == 0 + and node.id in plugin_roots + ): + log.debug( + f"Found unconnected plugin root {node.id} with same id as existing plugin root" + " - moving child nodes to existing plugin root and removing unconnected plugin root" + ) + for node_child in list(graph.successors(node)): + graph.add_edge(plugin_roots[node.id], node_child) + graph.remove_edge(node, node_child) + graph.remove_node(node) + if len(graph_roots) > 0: for graph_root in graph_roots: log.debug(f"Moving children of graph root {graph_root.id}")