def test_post_processor_with_graph_representation(post_processor: PostProcessor, tmpdir): """ Test the post processor a graph representation :param post_processor: :param tmpdir: :return: """ graph_represention = GraphRepresentation() svg_post_proccessed_path = tmpdir.join("simple_playbook_postproccess_graph.svg") play_id = "play_hostsall" # link from play to task edges graph_represention.add_link(play_id, "play_hostsallpost_taskPosttask1") graph_represention.add_link(play_id, "play_hostsallpost_taskPosttask2") post_processor.post_process(graph_represention) post_processor.write(output_filename=svg_post_proccessed_path.strpath) assert svg_post_proccessed_path.check(file=1) root = etree.parse(svg_post_proccessed_path.strpath).getroot() _assert_common_svg(root) assert len(root.xpath("ns:g/*[@id='%s']//ns:link" % play_id, namespaces={'ns': SVG_NAMESPACE})) == 2
def run(self): super(GrapherCLI, self).run() loader, inventory, variable_manager = CLI._play_prereqs() # Looks like the display is a singleton. This instruction will NOT return a new instance. # This is why we set the verbosity later because someone set it before us. display = Display() display.verbosity = self.options.verbosity grapher = PlaybookGrapher( data_loader=loader, inventory_manager=inventory, variable_manager=variable_manager, display=display, tags=self.options.tags, skip_tags=self.options.skip_tags, playbook_filename=self.options.playbook_filename, include_role_tasks=self.options.include_role_tasks) grapher.make_graph() svg_path = grapher.render_graph(self.options.output_filename, self.options.save_dot_file) post_processor = PostProcessor(svg_path=svg_path) post_processor.post_process( graph_representation=grapher.graph_representation) post_processor.write() display.display(f"fThe graph has been exported to {svg_path}") return svg_path
def test_post_processor_without_graph_representation(post_processor: PostProcessor, tmpdir): """ Test the post processor without a graph representation :param post_processor: :param tmpdir: :return: """ svg_post_proccessed_path = tmpdir.join("simple_playbook_postproccess_no_graph.svg") post_processor.post_process() post_processor.write(output_filename=svg_post_proccessed_path.strpath) assert svg_post_proccessed_path.check(file=1) root = etree.parse(svg_post_proccessed_path.strpath).getroot() _assert_common_svg(root) # no links should be in the svg when there is no graph_representation assert len(root.xpath("//ns:links", namespaces={'ns': SVG_NAMESPACE})) == 0