コード例 #1
0
 def test_processor_errored(self):
     """Test a task where the processor itself errors."""
     self.assertEqual(
         process.process(self.scan_task, {},
                         PROCESSOR_ERROR_KEY, ansible_result(''),
                         HOST),
         process.NO_DATA)
コード例 #2
0
 def test_no_processing(self):
     """Test a key that doesn't need to be processed."""
     self.assertEqual(
         process.process(self.scan_task, {},
                         NOT_A_KEY, ansible_result(process.NO_DATA),
                         HOST),
         ansible_result(process.NO_DATA))
コード例 #3
0
 def test_task_errored(self):
     """Test a task that errored on the remote machine."""
     self.assertEqual(
         process.process(self.scan_task, {},
                         TEST_KEY, ansible_result('error!', rc=1),
                         HOST),
         process.NO_DATA)
コード例 #4
0
    def handle_result(self, result):
        """Handle an incoming result object."""
        scan_data_log.safe_log_ansible_result(result, self.scan_task)
        # pylint: disable=protected-access
        result_obj = _construct_result(result)
        self.results.append(result_obj)
        logger.debug('%s', result_obj)

        # 'timeout' returns 124 on timeouts
        if result_obj[RESULT].get(FAILED) and \
           result_obj[RESULT].get(RC) == TIMEOUT_RC:
            logger.warning('Task %s timed out', result_obj[KEY])

        host = result_obj[HOST]
        results_to_store = normalize_result(result)
        host_facts = {}
        if result._task_fields.get('action') == 'set_fact' and \
                result.task_name == 'internal_host_started_processing_role':
            role_name = result._result.get(
                ANSIBLE_FACTS).get(STARTED_PROCESSING_ROLE)
            log_message = 'PROCESSING %s - ANSIBLE ROLE %s' % (host, role_name)
            self.scan_task.log_message(log_message)
        for key, value in results_to_store:
            if key == HOST_DONE:
                self._finalize_host(host, SystemInspectionResult.SUCCESS)
            else:
                processed_value = process.process(
                    self.scan_task, host_facts, key, value, host)
                host_facts[key] = processed_value

        if bool(host_facts):
            if host in self._ansible_facts:
                self._ansible_facts[host].update(host_facts)
            else:
                self._ansible_facts[host] = host_facts
コード例 #5
0
 def test_satisfied_dependency(self):
     """Test a key whose processor has a dependency, which is present."""
     self.assertEqual(
         process.process(self.scan_task,
                         {DEPENDENT_KEY: ansible_result('')},
                         NO_PROCESSOR_KEY, 'result',
                         HOST),
         'result')
コード例 #6
0
 def process_task_facts(self, task_facts, host):
     """Collect, process, and save task facts."""
     host_facts = {}
     for key, value in task_facts.items():
         if key == HOST_DONE:
             self._finalize_host(host, SystemInspectionResult.SUCCESS)
         else:
             processed_value = process.process(
                 self.scan_task, self._ansible_facts.get(host, {}),
                 key, value, host)
             host_facts[key] = processed_value
     if bool(host_facts) and host != UNKNOWN:
         if host in self._ansible_facts:
             self._ansible_facts[host].update(host_facts)
         else:
             self._ansible_facts[host] = host_facts
コード例 #7
0
 def test_skipped_task(self):
     """Test a task that Ansible skipped."""
     self.assertEqual(
         process.process(self.scan_task, {},
                         TEST_KEY, {'skipped': True},
                         HOST), process.NO_DATA)
コード例 #8
0
 def test_missing_dependency(self):
     """Test a key whose processor is missing a dependency."""
     self.assertEqual(
         process.process(self.scan_task, {},
                         DEPENDENT_KEY, ansible_result(process.NO_DATA),
                         HOST), process.NO_DATA)
コード例 #9
0
 def test_simple_processor(self):
     """Test a key whose processor succeeds."""
     self.assertEqual(
         process.process(self.scan_task, {},
                         TEST_KEY, ansible_result(process.NO_DATA),
                         HOST), 1)
コード例 #10
0
 def test_processing_bad_input(self):
     """Test a key that is not a task result, but needs processing."""
     self.assertEqual(
         process.process(self.scan_task, {},
                         TEST_KEY, 'foo', HOST),
         process.NO_DATA)
コード例 #11
0
 def test_not_result_sudo_error(self):
     """Test a value that is not a task result, but is a sudo error."""
     self.assertEqual(
         process.process(self.scan_task, {},
                         NOT_TASK_RESULT_KEY, process.SUDO_ERROR,
                         HOST), process.NO_DATA)
コード例 #12
0
 def test_not_result_no_processing(self):
     """Test a value that is not a task result, and needs no processing."""
     self.assertEqual(
         process.process(self.scan_task, {},
                         NOT_TASK_RESULT_KEY, 'foo',
                         HOST), 'foo')