Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
haidaraM committed Sep 5, 2024
1 parent 59a4bf8 commit efb156a
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 10 deletions.
3 changes: 2 additions & 1 deletion ansibleplaybookgrapher/grapher.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def parse(
playbook_nodes = []
roles_usage: Dict[RoleNode, Set[PlayNode]] = {}

for playbook_file in self.playbook_filenames:
for counter, playbook_file in enumerate(self.playbook_filenames, 1):
playbook_parser = PlaybookParser(
playbook_filename=playbook_file,
tags=tags,
Expand All @@ -59,6 +59,7 @@ def parse(
group_roles_by_name=group_roles_by_name,
)
playbook_node = playbook_parser.parse()
playbook_node.index = counter
playbook_nodes.append(playbook_node)

# Update the usage of the roles
Expand Down
17 changes: 10 additions & 7 deletions tests/fixtures/json-schemas/v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "object",
"properties": {
"version": {
"description": "The version of the output",
"description": "The version of the JSON output",
"type": "integer"
},
"playbooks": {
Expand All @@ -14,7 +14,7 @@
"type": "object",
"properties": {
"type": {
"description": "Type of the node. For playbooks, this PlaybookNode",
"description": "Type of the node.",
"type": "string",
"pattern": "^PlaybookNode$"
},
Expand All @@ -29,10 +29,7 @@
"type": "string"
},
"index": {
"type": [
"integer",
"null"
]
"type": "integer"
},
"location": {
"$ref": "#/$defs/location"
Expand Down Expand Up @@ -143,7 +140,7 @@
],
"$defs": {
"task": {
"description": "An Ansible task",
"description": "An Ansible task or role",
"type": "object",
"properties": {
"type": {
Expand All @@ -155,12 +152,15 @@
"type": "string"
},
"name": {
"description": "The name of the task or role",
"type": "string"
},
"when": {
"description": "The condition on the task",
"type": "string"
},
"index": {
"description": "The index of the task",
"type": "integer"
},
"location": {
Expand All @@ -187,16 +187,19 @@
]
},
"location": {
"description": "The node location on the filesystem.",
"type": "object",
"properties": {
"type": {
"description": "The type of the location",
"type": "string",
"enum": [
"file",
"folder"
]
},
"path": {
"description": "Filesystem path",
"type": "string"
},
"line": {
Expand Down
2 changes: 1 addition & 1 deletion tests/test_graphviz_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ def test_multi_plays(request):
)


def test_multiple_playbooks(request):
def test_multi_playbooks(request):
"""
Test with multiple playbooks
"""
Expand Down
32 changes: 31 additions & 1 deletion tests/test_json_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,14 @@ def _common_tests(

playbooks = jq.compile(".playbooks[]").input(output).all()

plays = jq.compile(".playbooks[].plays").input(output).first()
plays = (
jq.compile(
'.. | objects | select(.type == "PlayNode" and (.id | startswith("play_")))'
)
.input(output)
.all()
)

pre_tasks = (
jq.compile(
'.. | objects | select(.type == "TaskNode" and (.id | startswith("pre_task_")))'
Expand Down Expand Up @@ -236,3 +243,26 @@ def test_group_roles_by_name(
post_tasks_number=post_tasks_number,
blocks_number=1,
)


def test_multi_playbooks(request):
"""
:param request:
:return:
"""
json_path, playbook_paths = run_grapher(
["multi-plays.yml", "relative_var_files.yml", "with_roles.yml"],
output_filename=request.node.name,
additional_args=["--include-role-tasks"],
)

_common_tests(
json_path,
playbooks_number=3,
plays_number=5,
pre_tasks_number=4,
roles_number=10,
tasks_number=35,
post_tasks_number=4,
)

0 comments on commit efb156a

Please sign in to comment.