def test_run_with_sat_cancel(self):
        """Test the running inspect task with satellite cancelled."""
        scan_job, inspect_task = self.create_scan_job()
        task = InspectTaskRunner(scan_job, inspect_task)

        status = task.run(Value('i', ScanJob.JOB_TERMINATE_CANCEL))
        self.assertEqual(status[1], ScanTask.CANCELED)
Exemple #2
0
    def test_run_with_sat_pause(self):
        """Test the running connect task with satellite paused."""
        scan_job, inspect_task = self.create_scan_job()
        task = InspectTaskRunner(scan_job, inspect_task)

        status = task.run(Value('i', ScanJob.JOB_TERMINATE_PAUSE))
        self.assertEqual(status[1], ScanTask.PAUSED)
 def test_run_unknown_sat(self):
     """Test running the inspect scan for unknown sat."""
     scan_job, inspect_task = self.create_scan_job()
     task = InspectTaskRunner(scan_job, inspect_task)
     with patch('scanner.satellite.connect.utils.status',
                return_value=(None, None, None)) as mock_sat_status:
         status = task.run(Value('i', ScanJob.JOB_RUN))
         mock_sat_status.assert_called_once_with(ANY)
         self.assertEqual(status[1], ScanTask.FAILED)
Exemple #4
0
 def test_run_sat5_bad_status(self):
     """Test the running connect task for Satellite 5."""
     scan_job, inspect_task = self.create_scan_job()
     task = InspectTaskRunner(scan_job, inspect_task)
     with patch('scanner.satellite.connect.utils.status',
                return_value=(401, None,
                              SATELLITE_VERSION_5)) as mock_sat_status:
         status = task.run(Value('i', ScanJob.JOB_RUN))
         mock_sat_status.assert_called_once_with(ANY)
         self.assertEqual(status[1], ScanTask.FAILED)
Exemple #5
0
    def test_run_failed_prereq(self):
        """Test the running connect task with no source options."""
        scan_job, inspect_task = self.create_scan_job()
        connect_task = inspect_task.prerequisites.first()
        connect_task.status = ScanTask.FAILED
        connect_task.save()
        task = InspectTaskRunner(scan_job, inspect_task)
        status = task.run(Value('i', ScanJob.JOB_RUN))

        self.assertEqual(status[1], ScanTask.FAILED)
Exemple #6
0
    def test_run_with_timeout(self):
        """Test the running connect task with timeout error."""
        scan_job, inspect_task = self.create_scan_job()
        task = InspectTaskRunner(scan_job, inspect_task)

        with patch('scanner.satellite.connect.utils.status',
                   side_effect=mock_timeout_error) as mock_sat_status:
            status = task.run(Value('i', ScanJob.JOB_RUN))
            mock_sat_status.assert_called_once_with(ANY)
            self.assertEqual(status[1], ScanTask.FAILED)
Exemple #7
0
    def test_run_with_sat_err(self):
        """Test the running connect task with satellite error."""
        scan_job, inspect_task = self.create_scan_job()
        task = InspectTaskRunner(scan_job, inspect_task)

        with patch('scanner.satellite.connect.utils.status',
                   side_effect=mock_sat_exception) as mock_sat_status:
            status = task.run()
            mock_sat_status.assert_called_once_with(ANY)
            self.assertEqual(status[1], ScanTask.FAILED)
Exemple #8
0
    def test_run_with_excep(self):
        """Test the running connect task with general exception."""
        scan_job, inspect_task = self.create_scan_job()
        task = InspectTaskRunner(scan_job, inspect_task)

        with patch('scanner.satellite.connect.utils.status',
                   side_effect=mock_exception) as mock_sat_status:
            with self.assertRaises(Exception):
                status = task.run(Value('i', ScanJob.JOB_RUN))
                mock_sat_status.assert_called_once_with(ANY)
                self.assertEqual(status[1], ScanTask.FAILED)
Exemple #9
0
    def test_run_sat6_bad_api_version(self):
        """Test the running connect task for Sat6 with bad api version."""
        scan_job, inspect_task = self.create_scan_job()
        task = InspectTaskRunner(scan_job, inspect_task)

        with patch('scanner.satellite.connect.utils.status',
                   return_value=(200, 3,
                                 SATELLITE_VERSION_6)) as mock_sat_status:
            status = task.run()
            mock_sat_status.assert_called_once_with(ANY)
            self.assertEqual(status[1], ScanTask.FAILED)
    def test_run_failed_prereq(self):
        """Test the running connect task with no source options."""
        self.scan_task.prerequisites.all().delete()
        conn_task = ScanTask(scan_type=ScanTask.SCAN_TYPE_CONNECT,
                             source=self.source, sequence_number=1)
        conn_task.status = ScanTask.FAILED
        conn_task.save()
        self.scan_task.prerequisites.add(conn_task)
        task = InspectTaskRunner(self.scan_job, self.scan_task)
        status = task.run()

        self.assertEqual(status[1], ScanTask.FAILED)
Exemple #11
0
    def test_run_with_sat(self):
        """Test the running connect task with satellite."""
        scan_job, inspect_task = self.create_scan_job()
        task = InspectTaskRunner(scan_job, inspect_task)

        with patch('scanner.satellite.connect.utils.status',
                   return_value=(200, 2,
                                 SATELLITE_VERSION_6)) as mock_sat_status:
            with patch.object(SatelliteSixV2, 'hosts_facts') as mock_facts:
                status = task.run(Value('i', ScanJob.JOB_RUN))
                mock_sat_status.assert_called_once_with(ANY)
                mock_facts.assert_called_once_with(ANY)
                self.assertEqual(status[1], ScanTask.COMPLETED)
 def test_run_sat5_bad_status(self):
     """Test the running connect task for Satellite 5."""
     options = SourceOptions(
         satellite_version=SourceOptions.SATELLITE_VERSION_5)
     options.save()
     self.source.options = options
     self.source.save()
     task = InspectTaskRunner(self.scan_job, self.scan_task)
     with patch('scanner.satellite.connect.utils.status',
                return_value=(401, None)) as mock_sat_status:
         status = task.run()
         mock_sat_status.assert_called_once_with(ANY, ANY)
         self.assertEqual(status[1], ScanTask.FAILED)
    def test_run_with_excep(self):
        """Test the running connect task with general exception."""
        options = SourceOptions(
            satellite_version=SourceOptions.SATELLITE_VERSION_62)
        options.save()
        self.source.options = options
        self.source.save()
        task = InspectTaskRunner(self.scan_job, self.scan_task)

        with patch('scanner.satellite.connect.utils.status',
                   side_effect=mock_exception) as mock_sat_status:
            status = task.run()
            mock_sat_status.assert_called_once_with(ANY, ANY)
            self.assertEqual(status[1], ScanTask.FAILED)
    def test_run_with_sat(self):
        """Test the running connect task with satellite."""
        options = SourceOptions(
            satellite_version=SourceOptions.SATELLITE_VERSION_62)
        options.save()
        self.source.options = options
        self.source.save()
        task = InspectTaskRunner(self.scan_job, self.scan_task)

        with patch('scanner.satellite.connect.utils.status',
                   return_value=(200, 2)) as mock_sat_status:
            with patch.object(SatelliteSixV2, 'hosts_facts') as mock_facts:
                status = task.run()
                mock_sat_status.assert_called_once_with(ANY, ANY)
                mock_facts.assert_called_once_with()
                self.assertEqual(status[1], ScanTask.COMPLETED)
    def test_run_no_source_options(self):
        """Test the running connect task with no source options."""
        task = InspectTaskRunner(self.scan_job, self.scan_task)
        status = task.run()

        self.assertEqual(status[1], ScanTask.FAILED)