Пример #1
0
    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)
 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_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)
 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()
Пример #5
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_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)