def test_scan_with_options(self, mock_run):
        """Setup second scan with scan and source options."""
        # setup source with paramiko option for scan
        source_options = SourceOptions()
        source_options.save()
        self.source = Source(name='source2',
                             port=22,
                             options=source_options,
                             hosts='["1.2.3.4"]')
        self.source.save()
        self.source.credentials.add(self.cred)

        # setup scan with options
        extended = ExtendedProductSearchOptions()
        extended.save()
        scan_options = ScanOptions(enabled_extended_product_search=extended)
        scan_options.save()

        self.scan_job, self.scan_task = create_scan_job(
            self.source,
            ScanTask.SCAN_TYPE_INSPECT,
            'scan2',
            scan_options=scan_options)

        # run scan
        scanner = InspectTaskRunner(self.scan_job, self.scan_task)

        scanner.connect_scan_task = self.connect_scan_task
        scanner._inspect_scan(self.host_list)
        mock_run.assert_called_with(ANY)
Example #2
0
 def test_inspect_scan_error(self, mock_scan):
     """Test scan flow with mocked manager and failure."""
     scanner = InspectTaskRunner(self.scan_job, self.inspect_scan_task,
                                 self.inspect_results)
     scan_task_status = scanner.run()
     mock_scan.assert_called_with()
     self.assertEqual(scan_task_status, ScanTask.FAILED)
 def test_cancel_inspect(self):
     """Test cancel of inspect."""
     scanner = InspectTaskRunner(self.scan_job, self.scan_task)
     with self.assertRaises(NetworkCancelException):
         scanner.connect_scan_task = self.connect_scan_task
         scanner._inspect_scan(Value('i', ScanJob.JOB_TERMINATE_CANCEL),
                               self.host_list)
Example #4
0
 def test_inspect_scan_error(self, mock_scan):
     """Test scan flow with mocked manager and failure."""
     scanner = InspectTaskRunner(
         self.scan_job, self.scan_task)
     scan_task_status = scanner.run(Value('i', ScanJob.JOB_RUN))
     mock_scan.assert_called_with(self.host_list)
     self.assertEqual(scan_task_status[1], ScanTask.FAILED)
 def test_pause_inspect(self):
     """Test pause of inspect."""
     scanner = InspectTaskRunner(self.scan_job, self.scan_task)
     with self.assertRaises(NetworkPauseException):
         scanner.connect_scan_task = self.connect_scan_task
         scanner._inspect_scan(Value('i', ScanJob.JOB_TERMINATE_PAUSE),
                               self.host_list)
 def test_inspect_scan_failure(self, mock_run):
     """Test scan flow with mocked manager and failure."""
     mock_run.side_effect = AnsibleRunnerException()
     scanner = InspectTaskRunner(self.scan_job, self.scan_task)
     scanner.connect_scan_task = self.connect_scan_task
     with self.assertRaises(AnsibleRunnerException):
         scanner._inspect_scan(Value('i', ScanJob.JOB_RUN), self.host_list)
         mock_run.assert_called()
Example #7
0
 def test_ssh_crash(self):
     """Simulate an ssh crash."""
     scanner = InspectTaskRunner(self.scan_job, self.scan_task)
     path = os.path.abspath(
         os.path.join(os.path.dirname(__file__),
                      '../../../test_util/crash.py'))
     _, result = scanner._inspect_scan(self.host_list,
                                       base_ssh_executable=path)
     self.assertEqual(result, ScanTask.FAILED)
Example #8
0
    def test_inspect_scan_failure(self, mock_run):
        """Test scan flow with mocked manager and failure."""
        scanner = InspectTaskRunner(self.scan_job, self.scan_task)

        # Init for unit test as run is not called
        scanner.connect_scan_task = self.connect_scan_task
        with self.assertRaises(AnsibleError):
            scanner._inspect_scan(self.host_list)
            mock_run.assert_called()
 def test_modifying_log_level(self, mock_run):
     """Test modifying the log level."""
     mock_run.return_value.status = 'successful'
     scanner = InspectTaskRunner(self.scan_job, self.scan_task)
     scanner._inspect_scan(Value('i', ScanJob.JOB_RUN), self.host_list)
     mock_run.assert_called()
     calls = mock_run.mock_calls
     # Check to see if the parameter was passed into the runner.run()
     self.assertIn('verbosity=1', str(calls[0]))
 def test_ssh_hang(self):
     """Simulate an ssh hang."""
     scanner = InspectTaskRunner(self.scan_job, self.scan_task)
     path = os.path.abspath(
         os.path.join(os.path.dirname(__file__), 'test_util/hang.py'))
     scanner._inspect_scan(Value('i', ScanJob.JOB_RUN),
                           self.host_list,
                           base_ssh_executable=path,
                           ssh_timeout='0.1s')
Example #11
0
 def test_ssh_hang(self):
     """Simulate an ssh hang."""
     scanner = InspectTaskRunner(self.scan_job, self.scan_task)
     path = os.path.abspath(
         os.path.join(os.path.dirname(__file__),
                      '../../../test_util/hang.py'))
     scanner._inspect_scan(self.host_list,
                           roles=['redhat_release'],
                           base_ssh_executable=path,
                           ssh_timeout='0.1s')
Example #12
0
 def test_inspect_scan_fail_no_facts(self, mock_run):
     """Test running a inspect scan with mocked connection."""
     expected = ([('1.2.3.4', {'name': 'cred1'})], [])
     mock_run.return_value = expected
     with requests_mock.Mocker() as mocker:
         mocker.post(self.fact_endpoint, status_code=201, json={'id': 1})
         scanner = InspectTaskRunner(self.scan_job, self.scan_task)
         scan_task_status = scanner.run()
         mock_run.assert_called_with(ANY)
         self.assertEqual(scan_task_status[1], ScanTask.FAILED)
 def test_inspect_scan_fail_no_facts(self, mock_run):
     """Test running a inspect scan with mocked connection."""
     mock_run.return_value.status = 'successful'
     with requests_mock.Mocker() as mocker:
         mocker.post(self.fact_endpoint, status_code=201, json={'id': 1})
         scanner = InspectTaskRunner(self.scan_job, self.scan_task)
         scanner.connect_scan_task = self.connect_scan_task
         scan_task_status = scanner.run(Value('i', ScanJob.JOB_RUN))
         mock_run.assert_called()
         self.assertEqual(scan_task_status[1], ScanTask.FAILED)
 def test_no_reachable_host(self, discovery):
     """Test no reachable host."""
     discovery.return_value = [], [], [], []
     scanner = InspectTaskRunner(self.scan_job, self.scan_task)
     scan_task_status = scanner.run(Value('i', ScanJob.JOB_RUN))
     self.assertEqual(scan_task_status[1], ScanTask.FAILED)
 def test_run_manager_interupt(self):
     """Test manager interupt for inspect run method."""
     scanner = InspectTaskRunner(self.scan_job, self.scan_task)
     terminate = Value('i', ScanJob.JOB_TERMINATE_CANCEL)
     scan_task_status = scanner.run(terminate)
     self.assertEqual(scan_task_status[1], ScanTask.CANCELED)