Skip to content
Snippets Groups Projects
Commit 8dc91af8 authored by Karel van Klink's avatar Karel van Klink :smiley_cat:
Browse files

Update requirements, fine-tune Vale

parent 71de4969
No related branches found
No related tags found
1 merge request!42less verbose Nokia output
Pipeline #83916 passed
...@@ -18,6 +18,9 @@ proselint.Annotations = NO ...@@ -18,6 +18,9 @@ proselint.Annotations = NO
proselint.Typography = warning proselint.Typography = warning
; Same applies for not using contractions ; Same applies for not using contractions
Microsoft.Contractions = warning Microsoft.Contractions = warning
Microsoft.Headings = NO
TokenIgnores = (:class:`\S+`)
[formats] [formats]
py = rst py = rst
...@@ -46,8 +46,7 @@ class PlaybookLaunchResponse(BaseModel): ...@@ -46,8 +46,7 @@ class PlaybookLaunchResponse(BaseModel):
def playbook_launch_success(job_id: str) -> PlaybookLaunchResponse: def playbook_launch_success(job_id: str) -> PlaybookLaunchResponse:
"""Return a :class:`PlaybookLaunchResponse` for the successful start of a playbook execution. """Return a :class:`PlaybookLaunchResponse` for the successful start of a playbook execution.
:return PlaybookLaunchResponse: A playbook launch response that's :return PlaybookLaunchResponse: A playbook launch response that's successful.
successful.
""" """
return PlaybookLaunchResponse(status=PlaybookJobStatus.OK, job_id=job_id) return PlaybookLaunchResponse(status=PlaybookJobStatus.OK, job_id=job_id)
...@@ -55,8 +54,7 @@ def playbook_launch_success(job_id: str) -> PlaybookLaunchResponse: ...@@ -55,8 +54,7 @@ def playbook_launch_success(job_id: str) -> PlaybookLaunchResponse:
def playbook_launch_error(reason: str) -> PlaybookLaunchResponse: def playbook_launch_error(reason: str) -> PlaybookLaunchResponse:
"""Return a :class:`PlaybookLaunchResponse` for the erroneous start of a playbook execution. """Return a :class:`PlaybookLaunchResponse` for the erroneous start of a playbook execution.
:return PlaybookLaunchResponse: A playbook launch response that's :return PlaybookLaunchResponse: A playbook launch response that's unsuccessful.
unsuccessful.
""" """
return PlaybookLaunchResponse(status=PlaybookJobStatus.ERROR, info=reason) return PlaybookLaunchResponse(status=PlaybookJobStatus.ERROR, info=reason)
...@@ -64,7 +62,7 @@ def playbook_launch_error(reason: str) -> PlaybookLaunchResponse: ...@@ -64,7 +62,7 @@ def playbook_launch_error(reason: str) -> PlaybookLaunchResponse:
def _process_json_output(runner: ansible_runner.Runner) -> list[dict[Any, Any]]: # ignore: C901 def _process_json_output(runner: ansible_runner.Runner) -> list[dict[Any, Any]]: # ignore: C901
"""Handle Ansible runner output, and filter out redundant an overly verbose messages. """Handle Ansible runner output, and filter out redundant an overly verbose messages.
:param ansible_runner.Runner runner: The result of an Ansible playbook execution. :param :class:`ansible_runner.Runner` runner: Ansible runner that has already executed a playbook.
:return: A filtered dictionary that contains only the relevant parts of the output from executing an Ansible :return: A filtered dictionary that contains only the relevant parts of the output from executing an Ansible
playbook. playbook.
:rtype: list[dict[Any, Any]] :rtype: list[dict[Any, Any]]
...@@ -90,8 +88,8 @@ def _process_json_output(runner: ansible_runner.Runner) -> list[dict[Any, Any]]: ...@@ -90,8 +88,8 @@ def _process_json_output(runner: ansible_runner.Runner) -> list[dict[Any, Any]]:
if "res" in task_output["event_data"] and ( if "res" in task_output["event_data"] and (
int(runner.rc) != 0 or task_output["event_data"]["res"]["changed"] is True int(runner.rc) != 0 or task_output["event_data"]["res"]["changed"] is True
): ):
# The line contains result data, and must either consist of a change, or the playbook failed, and we # The line contains result data, and must either consist of a change, or the playbook failed, and all
# want all steps, including those that didn't make changes. # steps should be included, including those that didn't make changes.
task_result = task_output["event_data"]["res"] task_result = task_output["event_data"]["res"]
# Remove redundant ansible-related keys. # Remove redundant ansible-related keys.
...@@ -108,8 +106,8 @@ def _process_json_output(runner: ansible_runner.Runner) -> list[dict[Any, Any]]: ...@@ -108,8 +106,8 @@ def _process_json_output(runner: ansible_runner.Runner) -> list[dict[Any, Any]]:
task_result.pop("diff", None) task_result.pop("diff", None)
elif "diff" in task_result and "before" in task_result["diff"] and "after" in task_result["diff"]: elif "diff" in task_result and "before" in task_result["diff"] and "after" in task_result["diff"]:
# Nokia-specific # Nokia-specific
# We have a chunk of Nokia config, and we would like to show the actual diff, not a full before and # This is a chunk of Nokia config, and the actual difference must be calculated now, instead of
# after. # simply returning the before and after.
before_parsed = xmltodict.parse(task_result["diff"]["before"]) before_parsed = xmltodict.parse(task_result["diff"]["before"])
after_parsed = xmltodict.parse(task_result["diff"]["after"]) after_parsed = xmltodict.parse(task_result["diff"]["after"])
# Only leave the diff in the resulting output # Only leave the diff in the resulting output
...@@ -169,15 +167,10 @@ def run_playbook(playbook_path: str, extra_vars: dict, inventory: str, callback: ...@@ -169,15 +167,10 @@ def run_playbook(playbook_path: str, extra_vars: dict, inventory: str, callback:
:param str playbook_path: playbook to be executed. :param str playbook_path: playbook to be executed.
:param dict extra_vars: Any extra vars needed for the playbook to run. :param dict extra_vars: Any extra vars needed for the playbook to run.
:param [str] inventory: The inventory that the playbook is executed :param [str] inventory: The inventory that the playbook is executed against.
against. :param :class:`HttpUrl` callback: Callback URL where the playbook should send a status update when execution is
completed. This is used for workflow-orchestrator to continue with the next step in a workflow.
:param :class:`HttpUrl` callback: Callback URL where the playbook should send a status :return: Result of playbook launch, this could either be successful or unsuccessful.
update when execution is completed. This is used for
workflow-orchestrator to continue with the next step in a workflow.
:return: Result of playbook launch, this could either be successful or
unsuccessful.
:rtype: :class:`PlaybookLaunchResponse` :rtype: :class:`PlaybookLaunchResponse`
""" """
......
...@@ -22,7 +22,7 @@ ruff ...@@ -22,7 +22,7 @@ ruff
types-setuptools types-setuptools
types-requests types-requests
ansible-core~=2.14.0 ansible-core~=2.15.1
ansible_merge_vars ansible_merge_vars
GitPython GitPython
jinja2==3.1.1 jinja2==3.1.1
......
...@@ -18,6 +18,8 @@ setup( ...@@ -18,6 +18,8 @@ setup(
"ncclient", "ncclient",
"xmltodict", "xmltodict",
"netaddr", "netaddr",
"jmespath~=1.0.0",
"dictdiffer~=0.9.0",
"ansible-runner==2.3.3", "ansible-runner==2.3.3",
], ],
license="MIT", license="MIT",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment