Skip to content

Commit

Permalink
feat(check): feat check for running jobs (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
FoSix authored Aug 10, 2023
1 parent 9a65d7f commit 1107dc4
Show file tree
Hide file tree
Showing 11 changed files with 414 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,6 @@ poetry.lock
sidebar.json
.python-version
requirements.txt
openssl.cnf
.coverage
coverage.xml
20 changes: 20 additions & 0 deletions docs/panos-upgrade-assurance/api/check_firewall.md
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,26 @@ __Returns__
* [`CheckStatus.ERROR`](/panos/docs/panos-upgrade-assurance/api/utils#class-checkstatus) when the certificate's
properties (installed or required) are not supported.

### `CheckFirewall.check_non_finished_jobs`

```python
def check_non_finished_jobs() -> CheckResult
```

Check for any job with status different than FIN.

__Returns__


`CheckResult`: Object of [`CheckResult`](/panos/docs/panos-upgrade-assurance/api/utils#class-checkresult) class taking value of:

* [`CheckStatus.SUCCESS`](/panos/docs/panos-upgrade-assurance/api/utils#class-checkstatus) when all jobs are in FIN state.
* [`CheckStatus.FAIL`](/panos/docs/panos-upgrade-assurance/api/utils#class-checkstatus) otherwise, `CheckResult.reason`
field contains information about the 1<sup>st</sup> job found with status different than FIN (job ID and the actual
status).
* [`CheckStatus.SKIPPED`](/panos/docs/panos-upgrade-assurance/api/utils#class-checkstatus) when there are no jobs on a
device.

### `CheckFirewall.get_content_db_version`

```python
Expand Down
68 changes: 68 additions & 0 deletions docs/panos-upgrade-assurance/api/firewall_proxy.md
Original file line number Diff line number Diff line change
Expand Up @@ -956,3 +956,71 @@ __Returns__
}
```

### `FirewallProxy.get_jobs`

```python
def get_jobs() -> dict
```

Get details on all jobs.

This method retrieves all jobs and their details, this means running, pending, finished, etc.

The actual API command is `show jobs all`.

__Returns__


`dict`: All jobs found on the device, indexed by the ID of a job.

```python showLineNumbers title="Sample output"
{'1': {'description': None,
'details': {'line': ['ID population failed',
'Client logrcvr registered in the middle of a '
'commit/validate. Aborting current '
'commit/validate.',
'Commit failed',
'Failed to commit policy to device']},
'positionInQ': '0',
'progress': '100',
'queued': 'NO',
'result': 'FAIL',
'status': 'FIN',
'stoppable': 'no',
'tdeq': '00:28:32',
'tenq': '2023/08/01 00:28:32',
'tfin': '2023/08/01 00:28:36',
'type': 'AutoCom',
'user': None,
'warnings': None},
'2': {'description': None,
'details': {'line': ['Configuration committed successfully',
'Successfully committed last configuration']},
'positionInQ': '0',
'progress': '100',
'queued': 'NO',
'result': 'OK',
'status': 'FIN',
'stoppable': 'no',
'tdeq': '00:28:40',
'tenq': '2023/08/01 00:28:40',
'tfin': '2023/08/01 00:29:20',
'type': 'AutoCom',
'user': None,
'warnings': None},
'3': {'description': None,
'details': None,
'positionInQ': '0',
'progress': '30',
'queued': 'NO',
'result': 'PEND',
'status': 'ACT',
'stoppable': 'yes',
'tdeq': '00:58:59',
'tenq': '2023/08/01 00:58:59',
'tfin': None,
'type': 'Downld',
'user': None,
'warnings': None}}
```

10 changes: 10 additions & 0 deletions docs/panos-upgrade-assurance/configuration_details.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ checks_configuration = [
"active_support",
'candidate_config',
'expired_licenses',
'jobs',
'ntp_sync',
'panorama',
# tests below have optional configuration
Expand Down Expand Up @@ -296,6 +297,7 @@ checks_configuration:
- "active_support"
- "candidate_config"
- "expired_licenses"
- "jobs"
- "ntp_sync"
- "panorama"
# tests below have optional configuration
Expand Down Expand Up @@ -704,6 +706,14 @@ checks_configuration:
</Tabs>
```

### `jobs`

Verify if there are any running/pending jobs in the job queue. Any job with a status different than `FIN` will cause
the check to fail.

Does not require configuration.

**Method**: [`CheckFirewall.check_non_finished_jobs()`](/panos/docs/panos-upgrade-assurance/api/check_firewall#checkfirewallcheck_non_finished_jobs)

### `ntp_sync`

Expand Down
3 changes: 3 additions & 0 deletions examples/low_level_methods/run_low_level_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,7 @@

print(f"\n certificates: {firewall.get_certificates()}")

print(f"\n jobs: {firewall.get_jobs()}")


print()
41 changes: 21 additions & 20 deletions examples/readiness_checks/run_readiness_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,18 @@
check_node = CheckFirewall(firewall)

checks = [
# "all",
# "panorama",
# "ntp_sync",
# "candidate_config",
# "active_support",
# # checks below have optional configuration
# {"ha": {"skip_config_sync": True, "ignore_non_functional": True}},
# {"content_version": {"version": "8635-7675"}},
# {"expired_licenses": {"skip_licenses": ["Threat Prevention"]}},
# {"planes_clock_sync": {"diff_threshold": 2}},
# {"free_disk_space": {"image_version": "10.1.6-h6"}},
"all",
"panorama",
"ntp_sync",
"candidate_config",
"active_support",
"jobs",
# checks below have optional configuration
{"ha": {"skip_config_sync": True, "ignore_non_functional": True}},
{"content_version": {"version": "8635-7675"}},
{"expired_licenses": {"skip_licenses": ["Threat Prevention"]}},
{"planes_clock_sync": {"diff_threshold": 2}},
{"free_disk_space": {"image_version": "10.1.6-h6"}},
{
"certificates_requirements": {
"ecdsa": {
Expand All @@ -102,15 +103,15 @@
}
},
# checks below require additional configuration
# {
# "session_exist": {
# "source": "134.238.135.137",
# "destination": "10.1.0.4",
# "dest_port": "80",
# }
# },
# {"arp_entry_exist": {"ip": "10.0.1.1"}},
# {"ip_sec_tunnel_status": {"tunnel_name": "ipsec_tun"}},
{
"session_exist": {
"source": "134.238.135.137",
"destination": "10.1.0.4",
"dest_port": "80",
}
},
{"arp_entry_exist": {"ip": "10.0.1.1"}},
{"ip_sec_tunnel_status": {"tunnel_name": "ipsec_tun"}},
]

check_readiness = check_node.run_readiness_checks(
Expand Down
33 changes: 33 additions & 0 deletions panos_upgrade_assurance/check_firewall.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def __init__(self, node: FirewallProxy, skip_force_locale: Optional[bool] = Fals
CheckType.FREE_DISK_SPACE: self.check_free_disk_space,
CheckType.MP_DP_CLOCK_SYNC: self.check_mp_dp_sync,
CheckType.CERTS: self.check_ssl_cert_requirements,
CheckType.JOBS: self.check_non_finished_jobs,
}
if not skip_force_locale:
locale.setlocale(
Expand Down Expand Up @@ -870,6 +871,38 @@ def check_ssl_cert_requirements(self, rsa: dict = {}, ecdsa: dict = {}) -> Check
result.status = CheckStatus.SUCCESS
return result

def check_non_finished_jobs(self) -> CheckResult:
"""Check for any job with status different than FIN.
# Returns
CheckResult: Object of [`CheckResult`](/panos/docs/panos-upgrade-assurance/api/utils#class-checkresult) class taking \
value of:
* [`CheckStatus.SUCCESS`](/panos/docs/panos-upgrade-assurance/api/utils#class-checkstatus) when all jobs are in FIN state.
* [`CheckStatus.FAIL`](/panos/docs/panos-upgrade-assurance/api/utils#class-checkstatus) otherwise, `CheckResult.reason`
field contains information about the 1<sup>st</sup> job found with status different than FIN (job ID and the actual
status).
* [`CheckStatus.SKIPPED`](/panos/docs/panos-upgrade-assurance/api/utils#class-checkstatus) when there are no jobs on a
device.
"""
result = CheckResult()

all_jobs = self._node.get_jobs()

if all_jobs:
for jid, job in all_jobs.items():
if job["status"] != "FIN":
result.reason = f"At least one job (ID={jid}) is not in finished state (state={job['status']})."
return result
result.status = CheckStatus.SUCCESS
return result
else:
result.status = CheckStatus.SKIPPED
result.reason = "No jobs found on device. This is unusual, please investigate."
return result

def get_content_db_version(self) -> Dict[str, str]:
"""Get Content DB version.
Expand Down
74 changes: 74 additions & 0 deletions panos_upgrade_assurance/firewall_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1093,3 +1093,77 @@ def get_certificates(self) -> dict:
result[cert_name] = certificate

return result

def get_jobs(self) -> dict:
"""Get details on all jobs.
This method retrieves all jobs and their details, this means running, pending, finished, etc.
The actual API command is `show jobs all`.
# Returns
dict: All jobs found on the device, indexed by the ID of a job.
```python showLineNumbers title="Sample output"
{'1': {'description': None,
'details': {'line': ['ID population failed',
'Client logrcvr registered in the middle of a '
'commit/validate. Aborting current '
'commit/validate.',
'Commit failed',
'Failed to commit policy to device']},
'positionInQ': '0',
'progress': '100',
'queued': 'NO',
'result': 'FAIL',
'status': 'FIN',
'stoppable': 'no',
'tdeq': '00:28:32',
'tenq': '2023/08/01 00:28:32',
'tfin': '2023/08/01 00:28:36',
'type': 'AutoCom',
'user': None,
'warnings': None},
'2': {'description': None,
'details': {'line': ['Configuration committed successfully',
'Successfully committed last configuration']},
'positionInQ': '0',
'progress': '100',
'queued': 'NO',
'result': 'OK',
'status': 'FIN',
'stoppable': 'no',
'tdeq': '00:28:40',
'tenq': '2023/08/01 00:28:40',
'tfin': '2023/08/01 00:29:20',
'type': 'AutoCom',
'user': None,
'warnings': None},
'3': {'description': None,
'details': None,
'positionInQ': '0',
'progress': '30',
'queued': 'NO',
'result': 'PEND',
'status': 'ACT',
'stoppable': 'yes',
'tdeq': '00:58:59',
'tenq': '2023/08/01 00:58:59',
'tfin': None,
'type': 'Downld',
'user': None,
'warnings': None}}
```
"""
jobs = self.op_parser(cmd="show jobs all")
results = dict()

if jobs:
for job in jobs["job"]:
jid = job["id"]
job.pop("id")
results[jid] = job

return results
1 change: 1 addition & 0 deletions panos_upgrade_assurance/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class CheckType:
FREE_DISK_SPACE = "free_disk_space"
MP_DP_CLOCK_SYNC = "planes_clock_sync"
CERTS = "certificates_requirements"
JOBS = "jobs"


class SnapType:
Expand Down
Loading

0 comments on commit 1107dc4

Please sign in to comment.