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 test_post_processor_write(post_processor: PostProcessor, tmpdir):
    """
    Test method write of the PostProcessor
    :param post_processor:
    :return:
    """
    svg_post_proccessed_path = tmpdir.join("test_post_processor_write.svg")
    post_processor.write(output_filename=svg_post_proccessed_path.strpath)

    assert svg_post_proccessed_path.check(file=1)
def test_post_processor_insert_tag(post_processor: PostProcessor):
    """
    Test method insert_tag of the PostProcessor
    :param post_processor:
    :return:
    """
    post_processor.insert_script_tag(0, attrib={'id': 'toto'})

    assert post_processor.root[0].tag == 'script'
    assert post_processor.root[0].get('id') == 'toto'
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
Пример #5
0
    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 fixture_simple_postprocessor(request):
    """
    Return a post processor without a graph representation and with the simple_playbook_no_postproccess
    :return:
    """
    try:
        svg_path = request.param
    except AttributeError:
        # if the svg is not provided, we use the simple one
        svg_path = SIMPLE_PLAYBOOK_SVG

    post_processor = PostProcessor(svg_path=svg_path)
    return post_processor