def test_results_multiple_servers(): result = RunnerResults({ 'contacted': { 'web.seantis.dev': {'rc': 0}, 'db.seantis.dev': {'rc': 1} } }) with pytest.raises(KeyError): result.rc() assert result.rc('web.seantis.dev') == 0 assert result.rc('db.seantis.dev') == 1
def evaluate_results(self, callback): """ prepare the result of runner call for use with RunnerResults. """ for server, result in callback.unreachable.items(): log.error(u'{} could not be reached'.format(server)) log.debug(u'ansible-output =>\n{}'.format(pformat(result))) if self.api.ignore_unreachable: continue self.trigger_event(server, 'on_unreachable_host', (self, server)) for server, answer in callback.contacted.items(): success = answer['success'] result = answer['result'] # none of the modules in our tests hit the 'failed' result # codepath (which seems to not be implemented by all modules) # seo we ignore this branch since it's rather trivial if result.get('failed'): # pragma: no cover success = False if 'rc' in result: if self.api.is_valid_return_code(result['rc']): success = True # Add success to result result['success'] = success if not success: log.error(u'{} failed on {}'.format(self, server)) log.debug(u'ansible-output =>\n{}'.format(pformat(result))) if self.api.ignore_errors: continue self.trigger_event(server, 'on_module_error', (self, server, result)) # XXX this is a weird structure because RunnerResults still works # like it did with Ansible 1.x, where the results where structured # like this return RunnerResults({ 'contacted': { server: answer['result'] for server, answer in callback.contacted.items() }, 'unreachable': { server: result for server, result in callback.unreachable.items() } })
def test_results_multiple_servers(): result = RunnerResults({ 'contacted': { 'web.seantis.dev': {'rc': 0}, 'db.seantis.dev': {'rc': 1} } }) with pytest.raises(KeyError): result.rc() assert result.rc('web.seantis.dev') == 0 assert result.rc('db.seantis.dev') == 1
def evaluate_results(self, callback): """ prepare the result of runner call for use with RunnerResults. """ for server, result in callback.unreachable.items(): log.error(u'{} could not be reached'.format(server)) log.debug(u'ansible-output =>\n{}'.format(pformat(result))) if self.api.ignore_unreachable: continue self.trigger_event(server, 'on_unreachable_host', (self, server)) for server, answer in callback.contacted.items(): success = answer['success'] result = answer['result'] if result.get('failed'): success = False if 'rc' in result: if self.api.is_valid_return_code(result['rc']): success = True if not success: log.error(u'{} failed on {}'.format(self, server)) log.debug(u'ansible-output =>\n{}'.format(pformat(result))) if self.api.ignore_errors: continue self.trigger_event(server, 'on_module_error', (self, server, result)) # XXX this is a weird structure because RunnerResults still works # like it did with Ansible 1.x, where the results where structured # like this return RunnerResults({ 'contacted': { server: answer['result'] for server, answer in callback.contacted.items() } })