Skip to content

Commit

Permalink
fix: get_jobs exception when single job entry (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
alperenkose authored Apr 8, 2024
1 parent 2f63295 commit 7650bbb
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
9 changes: 7 additions & 2 deletions panos_upgrade_assurance/firewall_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1393,11 +1393,16 @@ def get_jobs(self) -> dict:
jobs = self.op_parser(cmd="show jobs all")
results = dict()

if jobs:
for job in jobs["job"]:
job_results = jobs.get("job") if isinstance(jobs, dict) else None
if isinstance(job_results, list):
for job in job_results:
jid = job["id"]
job.pop("id")
results[jid] = job
elif isinstance(job_results, dict): # single job entry - FW just started up
jid = job_results["id"]
job_results.pop("id")
results[jid] = job_results

return results

Expand Down
50 changes: 50 additions & 0 deletions tests/test_firewall_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1429,6 +1429,56 @@ def test_get_jobs(self, fw_proxy_mock):
},
}

def test_get_jobs_single_job(self, fw_proxy_mock):
xml_text = """
<response status="success">
<result>
<job>
<tenq>2023/08/07 03:59:57</tenq>
<tdeq>03:59:57</tdeq>
<id>1</id>
<user/>
<type>AutoCom</type>
<status>FIN</status>
<queued>NO</queued>
<stoppable>no</stoppable>
<result>OK</result>
<tfin>2023/08/07 04:00:28</tfin>
<description/>
<positionInQ>0</positionInQ>
<progress>100</progress>
<details>
<line>Configuration committed successfully</line>
<line>Successfully committed last configuration</line>
</details>
<warnings/>
</job>
</result>
</response>
"""

raw_response = ET.fromstring(xml_text)
fw_proxy_mock.op.return_value = raw_response

assert fw_proxy_mock.get_jobs() == {
"1": {
"tenq": "2023/08/07 03:59:57",
"tdeq": "03:59:57",
"user": None,
"type": "AutoCom",
"status": "FIN",
"queued": "NO",
"stoppable": "no",
"result": "OK",
"tfin": "2023/08/07 04:00:28",
"description": None,
"positionInQ": "0",
"progress": "100",
"details": {"line": ["Configuration committed successfully", "Successfully committed last configuration"]},
"warnings": None,
},
}

def test_get_jobs_no_jobs(self, fw_proxy_mock):
xml_text = """
<response status="success">
Expand Down

0 comments on commit 7650bbb

Please sign in to comment.