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:
Ryan Petrello 2017-02-17 11:36:52 -05:00
parent 68fc75070d
commit bda089e3f5
2 changed files with 71 additions and 22 deletions

View File

@ -41,32 +41,31 @@ function ($q, Prompt, $filter, Wait, Rest, $state, ProcessErrors, InitiatePlaybo
}
});
// use the hosts data populate above to get the count
var count = {
ok : _.filter(hosts, function(o){
return !o.failures && !o.changed && o.ok > 0;
}),
skipped : _.filter(hosts, function(o){
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;
})
var total_hosts_by_state = {
ok: 0,
skipped: 0,
unreachable: 0,
failures: 0,
changed: 0
};
// turn the count into an actual count, rather than a list of host
// names
Object.keys(count).forEach(key => {
count[key] = count[key].length;
// each host belongs in at most *one* of these states depending on
// the state of its tasks
_.each(hosts, function(host) {
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
getEvents: function(url) {

View 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
});
});
});
});