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.scan_task.update_stats('TEST_SAT.', sys_scanned=0) self.api = SatelliteSixV2(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()
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.scan_task.update_stats('TEST_SAT.', sys_scanned=0) self.api = SatelliteSixV2(self.scan_job, self.scan_task)
def create(satellite_version, api_version, scan_task): """Create the appropriate SatelliteInterface.""" if satellite_version is None: return None if satellite_version == SATELLITE_VERSION_5: return SatelliteFive(scan_task) if api_version == 1: return SatelliteSixV1(scan_task) if api_version == 2: return SatelliteSixV2(scan_task) return None
def create(satellite_version, api_version, scan_task, conn_result, inspect_result=None): """Create the appropriate SatelliteInterface.""" if satellite_version is None: return None if satellite_version == SourceOptions.SATELLITE_VERSION_5: return SatelliteFive(scan_task, conn_result, inspect_result) if api_version == 1: return SatelliteSixV1(scan_task, conn_result, inspect_result) if api_version == 2: return SatelliteSixV2(scan_task, conn_result, inspect_result) return None
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)
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_task = ScanTask(scan_type=ScanTask.SCAN_TYPE_CONNECT, source=self.source, sequence_number=1, start_time=datetime.utcnow()) self.scan_task.save() self.scan_task.update_stats('TEST_SAT.', sys_scanned=0) self.scan_job = ScanJob(scan_type=ScanTask.SCAN_TYPE_CONNECT) self.scan_job.save() self.scan_job.tasks.add(self.scan_task) self.conn_results = JobConnectionResult() self.conn_results.save() self.scan_job.connection_results = self.conn_results self.scan_job.save() self.conn_result = TaskConnectionResult(scan_task=self.scan_task, source=self.source) self.conn_result.save() self.inspect_result = TaskInspectionResult(scan_task=self.scan_task, source=self.source) self.inspect_result.save() self.api = SatelliteSixV2(self.scan_task, self.conn_result, self.inspect_result)