mirror of
https://github.com/ansible/awx.git
synced 2026-03-19 01:47:31 -02:30
properly count hosts based on job event task state
the intention of the host summary view is that each host belongs in at most *one* state - determined by the state of the tasks that ran on it. this change examines each host for a job and determines its state based on whether tasks passed, resulted in changes, were skipped, failed, etc... see: #5407
This commit is contained in:
@@ -41,32 +41,31 @@ function ($q, Prompt, $filter, Wait, Rest, $state, ProcessErrors, InitiatePlaybo
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// use the hosts data populate above to get the count
|
var total_hosts_by_state = {
|
||||||
var count = {
|
ok: 0,
|
||||||
ok : _.filter(hosts, function(o){
|
skipped: 0,
|
||||||
return !o.failures && !o.changed && o.ok > 0;
|
unreachable: 0,
|
||||||
}),
|
failures: 0,
|
||||||
skipped : _.filter(hosts, function(o){
|
changed: 0
|
||||||
return o.skipped > 0;
|
|
||||||
}),
|
|
||||||
unreachable : _.filter(hosts, function(o){
|
|
||||||
return o.dark > 0;
|
|
||||||
}),
|
|
||||||
failures : _.filter(hosts, function(o){
|
|
||||||
return o.failures > 0;
|
|
||||||
}),
|
|
||||||
changed : _.filter(hosts, function(o){
|
|
||||||
return o.changed > 0;
|
|
||||||
})
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// turn the count into an actual count, rather than a list of host
|
// each host belongs in at most *one* of these states depending on
|
||||||
// names
|
// the state of its tasks
|
||||||
Object.keys(count).forEach(key => {
|
_.each(hosts, function(host) {
|
||||||
count[key] = count[key].length;
|
if (host.dark > 0){
|
||||||
|
total_hosts_by_state.unreachable++;
|
||||||
|
} else if (host.failures > 0){
|
||||||
|
total_hosts_by_state.failures++;
|
||||||
|
} else if (host.changed > 0){
|
||||||
|
total_hosts_by_state.changed++;
|
||||||
|
} else if (host.ok > 0){
|
||||||
|
total_hosts_by_state.ok++;
|
||||||
|
} else if (host.skipped > 0){
|
||||||
|
total_hosts_by_state.skipped++;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return count;
|
return total_hosts_by_state;
|
||||||
},
|
},
|
||||||
// rest call to grab previously complete job_events
|
// rest call to grab previously complete job_events
|
||||||
getEvents: function(url) {
|
getEvents: function(url) {
|
||||||
|
|||||||
50
awx/ui/tests/spec/job-results/job-results.service-test.js
Normal file
50
awx/ui/tests/spec/job-results/job-results.service-test.js
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
describe('jobResultsService', () => {
|
||||||
|
let jobResultsService;
|
||||||
|
|
||||||
|
beforeEach(angular.mock.module('Tower'));
|
||||||
|
|
||||||
|
beforeEach(angular.mock.inject(( _jobResultsService_) => {
|
||||||
|
jobResultsService = _jobResultsService_;
|
||||||
|
}));
|
||||||
|
|
||||||
|
describe('getCountsFromStatsEvent()', () => {
|
||||||
|
it('properly counts hosts based on task state', () => {
|
||||||
|
let event_data = {
|
||||||
|
"skipped": {
|
||||||
|
"skipped-host": 5 // this host skipped all 5 tasks
|
||||||
|
},
|
||||||
|
"ok": {
|
||||||
|
"ok-host": 5, // this host was ok on all 5 tasks
|
||||||
|
"changed-host": 4 // this host had 4 ok tasks, had 1 changed task
|
||||||
|
},
|
||||||
|
"changed": {
|
||||||
|
"changed-host": 1
|
||||||
|
},
|
||||||
|
"failures": {
|
||||||
|
"failed-host": 1 // this host had a failed task
|
||||||
|
},
|
||||||
|
"dark": {
|
||||||
|
"unreachable-host": 1 // this host was unreachable
|
||||||
|
},
|
||||||
|
"processed": {
|
||||||
|
"ok-host": 1,
|
||||||
|
"changed-host": 1,
|
||||||
|
"skipped-host": 1,
|
||||||
|
"failed-host": 1,
|
||||||
|
"unreachable-host": 1
|
||||||
|
},
|
||||||
|
"playbook_uuid": "c23d8872-c92a-4e96-9f78-abe6fef38f33",
|
||||||
|
"playbook": "some_playbook.yml",
|
||||||
|
};
|
||||||
|
expect(jobResultsService.getCountsFromStatsEvent(event_data)).toEqual({
|
||||||
|
'ok': 1,
|
||||||
|
'skipped': 1,
|
||||||
|
'unreachable': 1,
|
||||||
|
'failures': 1,
|
||||||
|
'changed': 1
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user