Example #1
0
    def test_expand_sys_conn_result(self):
        """Test view expand_sys_conn_result."""
        scan_job = ScanJob(scan_type=ScanTask.SCAN_TYPE_CONNECT)
        scan_job.save()
        scan_job.sources.add(self.source)

        # Job in created state
        self.assertEqual(scan_job.status, ScanTask.CREATED)
        tasks = scan_job.tasks.all()
        self.assertEqual(len(tasks), 0)

        # Queue job to run
        scan_job.queue()

        conn_task = scan_job.tasks.first()

        conn_result = ConnectionResult(source=conn_task.source,
                                       scan_task=conn_task)
        conn_result.save()

        sys_result = SystemConnectionResult(
            name='Foo',
            credential=self.cred,
            status=SystemConnectionResult.SUCCESS)
        sys_result.save()
        conn_result.systems.add(sys_result)
        conn_result.save()

        result = expand_sys_conn_result(conn_result)
        self.assertEqual(result[0]['credential']['name'], 'cred1')
Example #2
0
    def record_result(self, name, source, credential, status):
        """Record a new result, either a connection success or a failure."""
        sys_result = SystemConnectionResult(
            name=name,
            source=source,
            credential=credential,
            status=status,
            task_connection_result=self.scan_task.connection_result)
        sys_result.save()

        if status == SystemConnectionResult.SUCCESS:
            message = '%s with %s' % (name, credential.name)
            self.scan_task.increment_stats(message,
                                           increment_sys_scanned=True,
                                           prefix='CONNECTED')
        elif status == SystemConnectionResult.UNREACHABLE:
            message = '%s is UNREACHABLE' % (name)
            self.scan_task.increment_stats(message,
                                           increment_sys_unreachable=True,
                                           prefix='FAILED')
        else:
            if credential is not None:
                message = '%s with %s' % (name, credential.name)
            else:
                message = '%s has no valid credentials' % name

            self.scan_task.increment_stats(message,
                                           increment_sys_failed=True,
                                           prefix='FAILED')

        self._remaining_hosts.remove(name)
Example #3
0
    def _store_connect_result(self, connected, failed_hosts):
        result = {}
        conn_result = ConnectionResult(scan_task=self.scan_task,
                                       source=self.scan_task.source)
        conn_result.save()

        for success in connected:
            result[success[0]] = success[1]
            # pylint: disable=no-member
            cred = Credential.objects.get(pk=success[1]['id'])
            sys_result = SystemConnectionResult(
                name=success[0],
                status=SystemConnectionResult.SUCCESS,
                credential=cred)
            sys_result.save()
            conn_result.systems.add(sys_result)

        for failed in failed_hosts:
            result[failed] = None
            sys_result = SystemConnectionResult(
                name=failed, status=SystemConnectionResult.FAILED)
            sys_result.save()
            conn_result.systems.add(sys_result)

        conn_result.save()
        self.conn_results.save()
        self.conn_results.results.add(conn_result)
        self.conn_results.save()

        return result
Example #4
0
    def setUp(self):
        """Create test case setup."""
        self.cred = Credential(name='cred1',
                               cred_type=Credential.SATELLITE_CRED_TYPE,
                               username='******',
                               password='******',
                               become_password=None,
                               become_method=None,
                               become_user=None,
                               ssh_keyfile=None)
        self.cred.save()

        self.source = Source(name='source1', port=443, hosts='["1.2.3.4"]')

        self.source.save()
        self.source.credentials.add(self.cred)

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

        self.api = SatelliteFive(self.scan_job, self.scan_task)
        connection_results = TaskConnectionResult()
        connection_results.save()
        self.api.connect_scan_task.connection_result = connection_results
        self.api.connect_scan_task.connection_result.save()

        sys_result = SystemConnectionResult(
            name='sys1_1', status=SystemInspectionResult.SUCCESS)
        sys_result.save()
        self.api.connect_scan_task.connection_result.systems.add(sys_result)
        self.api.connect_scan_task.connection_result.save()
        self.api.connect_scan_task.save()
Example #5
0
    def setUp(self):
        """Create test case setup."""
        self.cred = Credential(
            name='cred1',
            username='******',
            password='******',
            ssh_keyfile=None,
            become_method=None,
            become_user=None,
            become_password=None)
        self.cred.save()

        hc_serializer = CredentialSerializer(self.cred)
        self.cred_data = hc_serializer.data

        self.source = Source(
            name='source1',
            port=22,
            hosts='["1.2.3.4"]')
        self.source.save()
        self.source.credentials.add(self.cred)

        self.host_list = [('1.2.3.4', self.cred_data)]

        # setup scan options

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

        self.connect_scan_task = self.scan_task.prerequisites.first()
        self.connect_scan_task.update_stats(
            'TEST NETWORK CONNECT.', sys_failed=0)

        success_sys = SystemConnectionResult(
            name='1.2.3.4', credential=self.cred,
            status=SystemConnectionResult.SUCCESS)
        success_sys.save()
        failed_sys = SystemConnectionResult(
            name='1.1.1.2', status=SystemConnectionResult.FAILED)
        failed_sys.save()
        conn_result = self.connect_scan_task.connection_result
        conn_result.systems.add(success_sys)
        conn_result.systems.add(failed_sys)
        conn_result.save()

        self.connect_scan_task.update_stats(
            'TEST_VC.', sys_count=2, sys_failed=1, sys_scanned=1)
        self.connect_scan_task.complete()

        self.scan_task.update_stats(
            'TEST NETWORK INSPECT.', sys_failed=0)

        self.fact_endpoint = 'http://testserver' + reverse('facts-list')

        self.scan_job.save()

        scan_data_log.disable_log_for_test()
    def setUp(self):
        """Create test case setup."""
        self.cred = Credential(name='cred1',
                               username='******',
                               password='******',
                               ssh_keyfile=None,
                               become_method=None,
                               become_user=None,
                               become_password=None)
        self.cred.save()

        hc_serializer = CredentialSerializer(self.cred)
        self.cred_data = hc_serializer.data

        # setup source for scan
        self.source = Source(name='source1', port=22, hosts='["1.2.3.4"]')
        self.source.save()
        self.source.credentials.add(self.cred)

        self.host_list = [('1.2.3.4', self.cred_data)]

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

        self.connect_scan_task = self.scan_task.prerequisites.first()
        self.connect_scan_task.update_stats('TEST NETWORK CONNECT.',
                                            sys_failed=0)

        conn_result = self.connect_scan_task.connection_result
        success_sys = SystemConnectionResult(
            name='1.2.3.4',
            credential=self.cred,
            status=SystemConnectionResult.SUCCESS,
            task_connection_result=conn_result)
        success_sys.save()
        failed_sys = SystemConnectionResult(
            name='1.1.1.2',
            status=SystemConnectionResult.FAILED,
            task_connection_result=conn_result)
        failed_sys.save()
        conn_result.save()

        self.connect_scan_task.update_stats('TEST_VC.',
                                            sys_count=2,
                                            sys_failed=1,
                                            sys_scanned=1)
        self.connect_scan_task.complete()

        self.scan_task.update_stats('TEST NETWORK INSPECT.', sys_failed=0)

        self.fact_endpoint = 'http://testserver' + reverse('reports-list')

        self.scan_job.save()
        self.stop_states = [
            ScanJob.JOB_TERMINATE_CANCEL, ScanJob.JOB_TERMINATE_PAUSE
        ]
        self.interrupt = Mock(value=ScanJob.JOB_RUN)
Example #7
0
    def _store_connect_data(self, connected, credential, source):
        # Update the scan counts
        self.scan_task.update_stats(
            'INITIAL VCENTER CONNECT STATS.', sys_count=len(connected))

        for system in connected:
            sys_result = SystemConnectionResult(
                name=system, status=SystemConnectionResult.SUCCESS,
                credential=credential, source=source)
            sys_result.save()
            self.scan_task.connection_result.systems.add(sys_result)
            self.scan_task.increment_stats(
                sys_result.name, increment_sys_scanned=True)

        self.scan_task.connection_result.save()
Example #8
0
    def record_conn_result(self, name, credential):
        """Record a new result.

        :param name: The host name
        :param credential: The authentication credential
        """
        sys_result = SystemConnectionResult(
            name=name,
            credential=credential,
            status=SystemConnectionResult.SUCCESS)
        sys_result.save()

        self.conn_result.systems.add(sys_result)
        self.conn_result.save()

        self.scan_task.increment_stats(name, increment_sys_scanned=True)
Example #9
0
    def test_expand_sys_conn_result(self):
        """Test view expand_sys_conn_result."""
        # pylint: disable=no-member
        _, scan_task = create_scan_job(
            self.source, ScanTask.SCAN_TYPE_CONNECT)

        sys_result = SystemConnectionResult(name='Foo',
                                            credential=self.cred,
                                            status=SystemConnectionResult
                                            .SUCCESS)
        sys_result.save()
        conn_result = scan_task.connection_result
        conn_result.systems.add(sys_result)
        conn_result.save()

        result = expand_sys_conn_result(conn_result)
        self.assertEqual(result[0]['credential']['name'], 'cred1')
Example #10
0
    def test_expand_conn_results(self):
        """Test view expand_conn_results."""
        # pylint: disable=no-member
        scan_job, scan_task = create_scan_job(
            self.source, ScanTask.SCAN_TYPE_CONNECT)

        sys_result = SystemConnectionResult(name='Foo',
                                            credential=self.cred,
                                            status=SystemConnectionResult
                                            .SUCCESS)
        sys_result.save()
        conn_result = scan_task.connection_result
        conn_result.systems.add(sys_result)
        conn_result.save()

        conn_results_json = {'task_results': [{}]}
        expand_conn_results(scan_job.connection_results, conn_results_json)
        self.assertEqual(
            conn_results_json['task_results'][0]['systems'][0]['name'], 'Foo')
Example #11
0
    def test_hosts_facts(self, mock_pool):
        """Test the hosts_facts method."""
        scan_options = ScanOptions(max_concurrency=10)
        scan_options.save()
        scan_job, scan_task = create_scan_job(self.source,
                                              ScanTask.SCAN_TYPE_INSPECT,
                                              scan_name='test_62',
                                              scan_options=scan_options)
        scan_task.update_stats('TEST_SAT.', sys_scanned=0)
        api = SatelliteSixV2(scan_job, scan_task)
        job_conn_result = JobConnectionResult()
        job_conn_result.save()
        connection_results = TaskConnectionResult(
            job_connection_result=job_conn_result)
        connection_results.save()
        api.connect_scan_task.connection_result = connection_results
        api.connect_scan_task.connection_result.save()

        sys_result = SystemConnectionResult(
            name='sys1_1',
            status=SystemInspectionResult.SUCCESS,
            task_connection_result=api.connect_scan_task.connection_result)
        sys_result.save()
        api.connect_scan_task.save()
        hosts_url = 'https://{sat_host}:{port}/api/v2/hosts'
        with requests_mock.Mocker() as mocker:
            url = construct_url(url=hosts_url, sat_host='1.2.3.4')
            jsonresult = {
                'total': 1,
                'subtotal': 1,
                'page': 1,
                'per_page': 100,
                'results': [{
                    'id': 10,
                    'name': 'sys10'
                }]
            }  # noqa
            mocker.get(url, status_code=200, json=jsonresult)
            api.hosts_facts(Value('i', ScanJob.JOB_RUN))
            inspect_result = scan_task.inspection_result
            self.assertEqual(len(inspect_result.systems.all()), 1)
Example #12
0
    def test_expand_conn_results(self):
        """Test view expand_conn_results."""
        scan_job = ScanJob(scan_type=ScanTask.SCAN_TYPE_CONNECT)
        scan_job.save()
        scan_job.sources.add(self.source)

        # Job in created state
        self.assertEqual(scan_job.status, ScanTask.CREATED)
        tasks = scan_job.tasks.all()
        self.assertEqual(len(tasks), 0)

        # Queue job to run
        scan_job.queue()

        conn_task = scan_job.tasks.first()

        conn_results = JobConnectionResult()
        conn_results.save()
        scan_job.connection_results = conn_results
        scan_job.save()

        conn_result = TaskConnectionResult(source=conn_task.source,
                                           scan_task=conn_task)
        conn_result.save()

        conn_results.results.add(conn_result)
        conn_results.save()

        sys_result = SystemConnectionResult(
            name='Foo',
            credential=self.cred,
            status=SystemConnectionResult.SUCCESS)
        sys_result.save()
        conn_result.systems.add(sys_result)
        conn_result.save()

        conn_results_json = {'results': [{}]}
        expand_conn_results(conn_results, conn_results_json)
        self.assertEqual(conn_results_json['results'][0]['systems'][0]['name'],
                         'Foo')
Example #13
0
    def record_result(self, name, credential, status):
        """Record a new result, either a connection success or a failure."""
        sys_result = SystemConnectionResult(name=name,
                                            credential=credential,
                                            status=status)
        sys_result.save()

        self.conn_result.systems.add(sys_result)
        self.conn_result.save()

        if status == SystemConnectionResult.SUCCESS:
            message = '%s with %s' % (name, credential.name)
            self.scan_task.increment_stats(message, increment_sys_scanned=True)
        else:
            if credential is not None:
                message = '%s with %s' % (name, credential.name)
            else:
                message = '%s has no valid credentials' % name

            self.scan_task.increment_stats(message, increment_sys_failed=True)

        self._remaining_hosts.remove(name)
Example #14
0
    def _store_connect_data(self, connected, credential):
        conn_result = ConnectionResult(source=self.scan_task.source,
                                       scan_task=self.scan_task)
        conn_result.save()

        for system in connected:
            sys_result = SystemConnectionResult(
                name=system, status=SystemConnectionResult.SUCCESS,
                credential=credential)
            sys_result.save()
            conn_result.systems.add(sys_result)

        conn_result.save()
        self.conn_results.save()
        self.conn_results.results.add(conn_result)
        self.conn_results.save()

        # Update the scan counts
        if self.scan_task.systems_count is None:
            self.scan_task.systems_count = len(connected)
            self.scan_task.systems_scanned = 0
        self.scan_task.systems_scanned = len(connected)
        self.scan_task.save()
Example #15
0
    def test_details(self):
        """Get ScanJob result details by primary key."""
        # pylint: disable=no-member
        scan_job, scan_task = create_scan_job(
            self.source, ScanTask.SCAN_TYPE_INSPECT)

        # Create a connection system result
        sys_result = SystemConnectionResult(name='Foo',
                                            credential=self.cred,
                                            status=SystemConnectionResult
                                            .SUCCESS)
        sys_result.save()
        conn_result = scan_task.prerequisites.first().connection_result
        conn_result.systems.add(sys_result)
        conn_result.save()

        # Create an inspection system result
        sys_result = SystemInspectionResult(name='Foo',
                                            status=SystemConnectionResult
                                            .SUCCESS)
        sys_result.save()

        fact = RawFact(name='fact_key', value='"fact_value"')
        fact.save()
        sys_result.facts.add(fact)
        sys_result.save()

        inspect_result = scan_task.inspection_result
        inspect_result.systems.add(sys_result)
        inspect_result.save()
        scan_job.save()

        url = reverse('scanjob-detail', args=(scan_job.id,)) + 'results/'
        response = self.client.get(url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        json_response = response.json()
        self.assertIn('connection_results', json_response)
        self.assertIn('inspection_results', json_response)

        self.assertEqual(
            json_response, {
                'connection_results': {'task_results': [
                    {'source':
                     {'id': 1, 'name': 'source1', 'source_type': 'network'},
                     'systems':
                     [{'name': 'Foo', 'credential':
                       {'id': 1, 'name': 'cred1'},
                       'status': 'success'}]}]},
                'inspection_results': {'task_results': [
                    {'source':
                     {'id': 1, 'name': 'source1', 'source_type': 'network'},
                     'systems':
                     [{'name': 'Foo', 'status': 'success',
                       'facts': [
                           {'name': 'fact_key', 'value': 'fact_value'}]}]}]}})
Example #16
0
    def test_delete_scan_cascade(self, start_scan):
        """Delete a scan and its related data."""
        # pylint: disable=no-member
        scan_job, scan_task = create_scan_job(
            self.source, ScanTask.SCAN_TYPE_INSPECT)

        scan = scan_job.scan
        scan_id = scan.id

        self.create_job_expect_201(scan_id)

        # Create a connection system result
        sys_result = SystemConnectionResult(name='Foo',
                                            credential=self.cred,
                                            status=SystemConnectionResult
                                            .SUCCESS)
        sys_result.save()
        conn_result = scan_task.prerequisites.first().connection_result
        conn_result.systems.add(sys_result)
        conn_result.save()

        # Create an inspection system result
        sys_result = SystemInspectionResult(name='Foo',
                                            status=SystemConnectionResult
                                            .SUCCESS)
        sys_result.save()

        fact = RawFact(name='fact_key', value='"fact_value"')
        fact.save()
        sys_result.facts.add(fact)
        sys_result.save()

        inspect_result = scan_task.inspection_result
        inspect_result.systems.add(sys_result)
        inspect_result.save()
        scan_job.save()

        job_count = len(scan.jobs.all())
        self.assertNotEqual(job_count, 0)
        url = reverse('scan-detail', args=(scan_id,))
        response = self.client.delete(url, format='json')
        self.assertEqual(response.status_code,
                         status.HTTP_204_NO_CONTENT)
        job_count = len(scan.jobs.all())
        self.assertEqual(job_count, 0)
Example #17
0
    def setUp(self):
        """Create test case setup."""
        self.cred = Credential(
            name='cred1',
            username='******',
            password='******',
            ssh_keyfile=None,
            become_method=None,
            become_user=None,
            become_password=None)
        self.cred.save()

        hc_serializer = CredentialSerializer(self.cred)
        self.cred_data = hc_serializer.data

        self.source = Source(
            name='source1',
            port=22,
            hosts='["1.2.3.4"]')
        self.source.save()
        self.source.credentials.add(self.cred)

        self.host_list = [('1.2.3.4', self.cred_data)]
        self.connect_scan_task = ScanTask(source=self.source,
                                          scan_type=ScanTask.SCAN_TYPE_CONNECT,
                                          status=ScanTask.COMPLETED,
                                          start_time=datetime.utcnow())
        self.connect_scan_task.update_stats(
            'TEST NETWORK CONNECT.', sys_failed=0)

        self.inspect_scan_task = ScanTask(source=self.source,
                                          scan_type=ScanTask.SCAN_TYPE_INSPECT,
                                          start_time=datetime.utcnow())
        self.inspect_scan_task.update_stats(
            'TEST NETWORK INSPECT.', sys_failed=0)
        self.inspect_scan_task.prerequisites.add(self.connect_scan_task)
        self.inspect_scan_task.save()

        self.scan_job = ScanJob(scan_type=ScanTask.SCAN_TYPE_INSPECT)
        self.scan_job.save()

        self.scan_job.tasks.add(self.connect_scan_task)
        self.scan_job.tasks.add(self.inspect_scan_task)
        scan_options = ScanOptions()
        scan_options.disable_optional_products = {'jboss_eap': False,
                                                  'jboss_fuse': False,
                                                  'jboss_brms': False}
        scan_options.save()
        self.scan_job.options = scan_options
        self.scan_job.save()

        self.fact_endpoint = 'http://testserver' + reverse('facts-list')

        self.conn_results = JobConnectionResult()
        self.conn_results.save()
        self.scan_job.connection_results = self.conn_results

        self.conn_result = TaskConnectionResult(
            scan_task=self.connect_scan_task, source=self.source)
        self.conn_result.save()

        success_sys = SystemConnectionResult(
            name='1.2.3.4', credential=self.cred,
            status=SystemConnectionResult.SUCCESS)
        success_sys.save()
        failed_sys = SystemConnectionResult(
            name='1.1.1.2', status=SystemConnectionResult.FAILED)
        failed_sys.save()
        self.conn_result.systems.add(success_sys)
        self.conn_result.systems.add(failed_sys)
        self.conn_result.save()
        self.conn_results.results.add(self.conn_result)
        self.conn_results.save()
        self.scan_job.connection_results = self.conn_results

        self.inspect_results = JobInspectionResult()
        self.inspect_results.save()
        self.scan_job.inspection_results = self.inspect_results

        self.scan_job.save()
Example #18
0
    def test_merge_jobs_success(self):
        """Test merge jobs success."""
        # pylint: disable=no-member
        scan_job1, scan_task1 = create_scan_job(
            self.source, ScanTask.SCAN_TYPE_INSPECT,
            scan_name='test1')

        scan_job2, scan_task2 = create_scan_job(
            self.source, ScanTask.SCAN_TYPE_INSPECT,
            scan_name='test2')

        # Create a connection system result
        connect_sys_result = SystemConnectionResult(
            name='Foo',
            credential=self.cred,
            status=SystemConnectionResult
            .SUCCESS)
        connect_sys_result.save()

        # Create an inspection system result
        inspect_sys_result = SystemInspectionResult(
            name='Foo',
            status=SystemConnectionResult
            .SUCCESS)
        inspect_sys_result.save()

        fact = RawFact(name='fact_key', value='"fact_value"')
        fact.save()
        inspect_sys_result.facts.add(fact)
        inspect_sys_result.save()

        conn_result = scan_task1.prerequisites.first().connection_result
        conn_result.systems.add(connect_sys_result)
        conn_result.save()

        inspect_result = scan_task1.inspection_result
        inspect_result.systems.add(inspect_sys_result)
        inspect_result.save()
        scan_task1.status = ScanTask.COMPLETED
        scan_task1.save()

        conn_result = scan_task2.prerequisites.first().connection_result
        conn_result.systems.add(connect_sys_result)
        conn_result.save()

        inspect_result = scan_task2.inspection_result
        inspect_result.systems.add(inspect_sys_result)
        inspect_result.save()
        scan_task1.status = ScanTask.COMPLETED
        scan_task1.save()

        scan_job1.status = ScanTask.COMPLETED
        scan_job1.save()

        scan_job2.status = ScanTask.COMPLETED
        scan_job2.save()

        url = reverse('scanjob-merge')
        data = {'jobs': [scan_job1.id, scan_job2.id]}
        response = self.client.put(url, json.dumps(data),
                                   content_type='application/json',
                                   format='json')
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        json_response = response.json()
        expected = {'id': 1, 'sources':
                    [{'source_id': 1,
                      'source_type': 'network',
                      'facts': [{'fact_key': 'fact_value'}]},
                     {'source_id': 1,
                      'source_type': 'network',
                      'facts': [{'fact_key': 'fact_value'}]}],
                    'status': 'complete'}
        self.assertEqual(
            json_response, expected)
Example #19
0
    def test_details(self, start_scan):
        """Get ScanJob result details by primary key."""
        scan_job = ScanJob(scan_type=ScanTask.SCAN_TYPE_INSPECT)
        scan_job.save()
        scan_job.sources.add(self.source)

        # Job in created state
        self.assertEqual(scan_job.status, ScanTask.CREATED)
        tasks = scan_job.tasks.all()
        self.assertEqual(len(tasks), 0)

        # Queue job to run
        scan_job.queue()

        conn_task = scan_job.tasks.first()

        conn_results = ConnectionResults(scan_job=scan_job)
        conn_results.save()

        conn_result = ConnectionResult(source=conn_task.source,
                                       scan_task=conn_task)
        conn_result.save()

        conn_results.results.add(conn_result)
        conn_results.save()

        sys_result = SystemConnectionResult(
            name='Foo',
            credential=self.cred,
            status=SystemConnectionResult.SUCCESS)
        sys_result.save()
        conn_result.systems.add(sys_result)
        conn_result.save()

        inspect_task = scan_job.tasks.all()[1]

        inspect_results = InspectionResults(scan_job=scan_job)
        inspect_results.save()

        inspect_result = InspectionResult(source=inspect_task.source,
                                          scan_task=inspect_task)
        inspect_result.save()

        inspect_results.results.add(inspect_result)
        inspect_results.save()

        sys_result = SystemInspectionResult(
            name='Foo', status=SystemConnectionResult.SUCCESS)
        sys_result.save()

        fact = RawFact(name='foo', value='value')
        fact.save()
        sys_result.facts.add(fact)
        sys_result.save()

        inspect_result.systems.add(sys_result)
        inspect_result.save()

        url = reverse('scanjob-detail', args=(scan_job.id, )) + 'results/'
        response = self.client.get(url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        json_response = response.json()
        self.assertIn('connection_results', json_response)
        self.assertIn('inspection_results', json_response)

        self.assertEqual(
            json_response, {
                'connection_results': {
                    'scan_job': 1,
                    'results': []
                },
                'inspection_results': {
                    'scan_job': 1,
                    'results': []
                }
            })
Example #20
0
    def setUp(self):
        """Create test case setup."""
        self.cred = Credential(name='cred1',
                               username='******',
                               password='******',
                               sudo_password=None,
                               ssh_keyfile=None)
        self.cred.save()

        self.source = Source(name='source1', port=22)
        self.source.save()
        self.source.credentials.add(self.cred)

        self.host = HostRange(host_range='1.2.3.4', source_id=self.source.id)
        self.host.save()

        self.source.hosts.add(self.host)

        self.connect_scan_task = ScanTask(source=self.source,
                                          scan_type=ScanTask.SCAN_TYPE_CONNECT,
                                          status=ScanTask.COMPLETED)
        self.connect_scan_task.systems_failed = 0
        self.connect_scan_task.save()

        self.inspect_scan_task = ScanTask(source=self.source,
                                          scan_type=ScanTask.SCAN_TYPE_INSPECT)
        self.inspect_scan_task.systems_failed = 0
        self.inspect_scan_task.save()
        self.inspect_scan_task.prerequisites.add(self.connect_scan_task)
        self.inspect_scan_task.save()

        self.scan_job = ScanJob(scan_type=ScanTask.SCAN_TYPE_INSPECT)
        self.scan_job.save()

        self.scan_job.tasks.add(self.connect_scan_task)
        self.scan_job.tasks.add(self.inspect_scan_task)
        scan_options = ScanOptions()
        scan_options.save()
        self.scan_job.options = scan_options
        self.scan_job.save()

        self.fact_endpoint = 'http://testserver' + reverse('facts-list')

        self.conn_results = ConnectionResults(scan_job=self.scan_job)
        self.conn_results.save()

        self.conn_result = ConnectionResult(scan_task=self.connect_scan_task,
                                            source=self.source)
        self.conn_result.save()

        success_sys = SystemConnectionResult(
            name='1.2.3.4',
            credential=self.cred,
            status=SystemConnectionResult.SUCCESS)
        success_sys.save()
        failed_sys = SystemConnectionResult(
            name='1.1.1.2', status=SystemConnectionResult.FAILED)
        failed_sys.save()
        self.conn_result.systems.add(success_sys)
        self.conn_result.systems.add(failed_sys)
        self.conn_result.save()
        self.conn_results.results.add(self.conn_result)
        self.conn_results.save()

        self.inspect_results = InspectionResults(scan_job=self.scan_job)
        self.inspect_results.save()