mirror of
https://github.com/ansible/awx.git
synced 2026-03-01 16:58:46 -03:30
Modify filter_insights_api_response to take in the separate remediations
since it is accumulated via a different API call.
This commit is contained in:
@@ -5,5 +5,7 @@ import os
|
|||||||
dir_path = os.path.dirname(os.path.realpath(__file__))
|
dir_path = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
|
||||||
with open(os.path.join(dir_path, 'insights.json')) as data_file:
|
with open(os.path.join(dir_path, 'insights.json')) as data_file:
|
||||||
TEST_INSIGHTS_PLANS = json.loads(data_file.read())
|
TEST_INSIGHTS_PLANS = json.load(data_file)
|
||||||
|
|
||||||
|
with open(os.path.join(dir_path, 'insights_remediations.json')) as data_file:
|
||||||
|
TEST_INSIGHTS_REMEDIATIONS = json.load(data_file)['data']
|
||||||
|
|||||||
33
awx/main/tests/data/insights_remediations.json
Normal file
33
awx/main/tests/data/insights_remediations.json
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
{
|
||||||
|
"data": [
|
||||||
|
{
|
||||||
|
"id": "9197ba55-0abc-4028-9bbe-269e530f8bd5",
|
||||||
|
"name": "Fix Critical CVEs",
|
||||||
|
"created_by": {
|
||||||
|
"username": "jharting@redhat.com",
|
||||||
|
"first_name": "Jozef",
|
||||||
|
"last_name": "Hartinger"
|
||||||
|
},
|
||||||
|
"created_at": "2018-12-05T08:19:36.641Z",
|
||||||
|
"updated_by": {
|
||||||
|
"username": "jharting@redhat.com",
|
||||||
|
"first_name": "Jozef",
|
||||||
|
"last_name": "Hartinger"
|
||||||
|
},
|
||||||
|
"updated_at": "2018-12-05T08:19:36.641Z",
|
||||||
|
"issue_count": 0,
|
||||||
|
"system_count": 0,
|
||||||
|
"needs_reboot": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"meta": {
|
||||||
|
"count": 0,
|
||||||
|
"total": 0
|
||||||
|
},
|
||||||
|
"links": {
|
||||||
|
"first": null,
|
||||||
|
"last": null,
|
||||||
|
"next": null,
|
||||||
|
"previous": null
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,15 +3,16 @@
|
|||||||
|
|
||||||
|
|
||||||
from awx.main.utils.insights import filter_insights_api_response
|
from awx.main.utils.insights import filter_insights_api_response
|
||||||
from awx.main.tests.data.insights import TEST_INSIGHTS_PLANS
|
from awx.main.tests.data.insights import TEST_INSIGHTS_PLANS, TEST_INSIGHTS_REMEDIATIONS
|
||||||
|
|
||||||
|
|
||||||
def test_filter_insights_api_response():
|
def test_filter_insights_api_response():
|
||||||
actual = filter_insights_api_response(TEST_INSIGHTS_PLANS)
|
actual = filter_insights_api_response(TEST_INSIGHTS_PLANS, TEST_INSIGHTS_REMEDIATIONS)
|
||||||
|
|
||||||
assert actual['last_check_in'] == '2019-03-19T21:59:09.213151-04:00'
|
assert actual['last_check_in'] == '2019-03-19T21:59:09.213151-04:00'
|
||||||
assert len(actual['reports']) == 5
|
assert len(actual['reports']) == 5
|
||||||
assert len(actual['reports'][0]['maintenance_actions']) == 0
|
assert len(actual['reports'][0]['maintenance_actions']) == 1
|
||||||
|
assert actual['reports'][0]['maintenance_actions'][0]['name'] == "Fix Critical CVEs"
|
||||||
rule = actual['reports'][0]['rule']
|
rule = actual['reports'][0]['rule']
|
||||||
|
|
||||||
assert rule['severity'] == 'WARN'
|
assert rule['severity'] == 'WARN'
|
||||||
|
|||||||
@@ -11,11 +11,11 @@
|
|||||||
# reports[].rule.severity (str) -> active_reports[].rule.total_risk (int)
|
# reports[].rule.severity (str) -> active_reports[].rule.total_risk (int)
|
||||||
|
|
||||||
# reports[].rule.{ansible,ansible_fix} appears to be unused
|
# reports[].rule.{ansible,ansible_fix} appears to be unused
|
||||||
# reports[].maintenance_actions[] missing entirely, will be provided
|
# reports[].maintenance_actions[] missing entirely, is now provided
|
||||||
# by a different Insights endpoint
|
# by a different Insights endpoint
|
||||||
|
|
||||||
|
|
||||||
def filter_insights_api_response(json):
|
def filter_insights_api_response(reports, remediations):
|
||||||
severity_mapping = {
|
severity_mapping = {
|
||||||
1: 'INFO',
|
1: 'INFO',
|
||||||
2: 'WARN',
|
2: 'WARN',
|
||||||
@@ -24,14 +24,14 @@ def filter_insights_api_response(json):
|
|||||||
}
|
}
|
||||||
|
|
||||||
new_json = {}
|
new_json = {}
|
||||||
if 'checked_on' in json:
|
if 'checked_on' in reports:
|
||||||
new_json['last_check_in'] = json['checked_on']
|
new_json['last_check_in'] = reports['checked_on']
|
||||||
if 'active_reports' in json:
|
if 'active_reports' in reports:
|
||||||
new_json['reports'] = []
|
new_json['reports'] = []
|
||||||
for rep in json['active_reports']:
|
for rep in reports['active_reports']:
|
||||||
new_report = {
|
new_report = {
|
||||||
'rule': {},
|
'rule': {},
|
||||||
'maintenance_actions': [] # This will be populated by a different API call
|
'maintenance_actions': remediations
|
||||||
}
|
}
|
||||||
rule = rep.get('rule') or {}
|
rule = rep.get('rule') or {}
|
||||||
for k in ['description', 'summary']:
|
for k in ['description', 'summary']:
|
||||||
|
|||||||
@@ -9,8 +9,8 @@
|
|||||||
if(plan === null || plan === undefined){
|
if(plan === null || plan === undefined){
|
||||||
return "PLAN: Not Available <a href='https://access.redhat.com/insights/info/' target='_blank'>CREATE A NEW PLAN IN INSIGHTS</a>";
|
return "PLAN: Not Available <a href='https://access.redhat.com/insights/info/' target='_blank'>CREATE A NEW PLAN IN INSIGHTS</a>";
|
||||||
} else {
|
} else {
|
||||||
let name = (plan.maintenance_plan.name === null) ? "Unnamed Plan" : plan.maintenance_plan.name;
|
let name = (plan.name === null) ? "Unnamed Plan" : plan.name;
|
||||||
return `<a href="https://access.redhat.com/insights/planner/${plan.maintenance_plan.maintenance_id}" target="_blank">${name} (${plan.maintenance_plan.maintenance_id})</a>`;
|
return `<a href="https://cloud.redhat.com/insights/planner/${plan.id}" target="_blank">${name} (${plan.id})</a>`;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user