Beispiel #1
0
    def test_host_not_subscribed(self):
        """Test the host subscriptons method for not subscribed error."""
        sub_url = 'https://{sat_host}:{port}/' \
            'api/v2/hosts/{host_id}/subscriptions'
        with requests_mock.Mocker() as mocker:
            url = construct_url(url=sub_url, sat_host='1.2.3.4', host_id=1)
            err_msg = {
                'displayMessage':
                'Host has not been registered '
                'with subscription-manager',
                'errors':
                ['Host has not been registered'
                 ' with subscription-manager']
            }  # noqa
            mocker.get(url, status_code=400, json=err_msg)
            result = request_host_details(
                self.scan_task, {
                    'job_id': self.scan_job.id,
                    'task_sequence_number': self.scan_task.id,
                    'scan_type': self.scan_task.scan_type,
                    'source_type': self.scan_task.source.source_type,
                    'source_name': self.scan_task.source.name
                }, 1, 'sys', url, url, {})

        process_results(self.api, [result], 1)
        inspect_results = self.scan_task.inspection_result.systems.all()
        sys_1_result = inspect_results.filter(name='sys_1').first()
        self.assertEqual(sys_1_result.name, 'sys_1')
        self.assertEqual(sys_1_result.status, 'failed')
Beispiel #2
0
 def test_processing_fields_with_err(self):
     """Test the post_processing with error."""
     host_field_url = 'https://{sat_host}:{port}/api/v2/hosts/{host_id}'
     with requests_mock.Mocker() as mocker:
         url = construct_url(url=host_field_url,
                             sat_host='1.2.3.4',
                             host_id=1)
         mocker.get(url, status_code=500)
         result = request_host_details(
             self.scan_task, {
                 'job_id': self.scan_job.id,
                 'task_sequence_number': self.scan_task.id,
                 'scan_type': self.scan_task.scan_type,
                 'source_type': self.scan_task.source.source_type,
                 'source_name': self.scan_task.source.name
             }, 1, 'sys', url, url, {})
         expected = {
             'unique_name': 'sys_1',
             'system_inspection_result': 'failed',
             'host_fields_response': {},
             'host_subscriptions_response': {}
         }
         self.assertEqual(result, expected)
         process_results(self.api, [result], 1)
         inspect_results = self.scan_task.inspection_result.systems.all()
         sys_1_result = inspect_results.filter(name='sys_1').first()
         self.assertEqual(sys_1_result.name, 'sys_1')
         self.assertEqual(sys_1_result.status, 'failed')
Beispiel #3
0
 def test_post_processing_err(self):
     """Test error flow & check that a failed system is marked."""
     response = {
         'unique_name': 'sys_1',
         'system_inspection_result': SystemInspectionResult.FAILED,
         'host_fields_response': {},
         'host_subscriptions_response': {}
     }
     process_results(self.api, [response], 1)
     inspect_results = self.scan_task.inspection_result.systems.all()
     sys_1_result = inspect_results.filter(name='sys_1').first()
     self.assertEqual(sys_1_result.name, 'sys_1')
     self.assertEqual(sys_1_result.status, 'failed')
Beispiel #4
0
    def test_processing_subs_err_nojson(self):
        """Test the flow of post processing with bad code and not json."""
        sub_url = 'https://{sat_host}:{port}/' \
            'api/v2/hosts/{host_id}/subscriptions'
        with requests_mock.Mocker() as mocker:
            url = construct_url(url=sub_url, sat_host='1.2.3.4', host_id=1)
            mocker.get(url, status_code=404, text='error message')
            result = request_host_details(
                self.scan_task, {
                    'job_id': self.scan_job.id,
                    'task_sequence_number': self.scan_task.id,
                    'scan_type': self.scan_task.scan_type,
                    'source_type': self.scan_task.source.source_type,
                    'source_name': self.scan_task.source.name
                }, 1, 'sys', url, url, {})

            process_results(self.api, [result], 1)
            inspect_results = self.scan_task.inspection_result.systems.all()
            sys_1_result = inspect_results.filter(name='sys_1').first()
            self.assertEqual(sys_1_result.name, 'sys_1')
            self.assertEqual(sys_1_result.status, 'failed')
Beispiel #5
0
 def test_post_processing(self):
     """Test process_results method with mock data."""
     fields_return_value = {
         'uuid': '00c7a108-48ec-4a97-835c-aa3369777f64',
         'hostname': 'mac52540071bafe.prov.lan',
         'registered_by': 'sat-r220-07.lab.eng.rdu2.redhat.com',
         'registration_time': '2017-12-04 13:33:52 UTC',
         'last_checkin_time': '2018-01-04 17:36:07 UTC',
         'katello_agent_installed': False,
         'os_name': 'RedHat 7.4',
         'organization': 'ACME',
         'virtual_host_uuid': '100',
         'virtual_host_name': 'vhost1',
         'virt_type': None,
         'kernel_version': None,
         'architecture': None,
         'is_virtualized': None,
         'cores': None,
         'num_sockets': None,
         'num_virtual_guests': 1,
         'virtual': 'hypervisor',
         'location': 'Raleigh',
         'ip_addresses': ['192.168.99.123'],
         'ipv6_addresses': ['fe80::5054:ff:fe24:946e']
     }
     subs_return_value = {
         'entitlements': [{
             'derived_entitlement': False,
             'name': 'Satellite Tools 6.3',
             'amount': 1,
             'account_number': None,
             'contract_number': None,
             'start_date': '2017-12-01 14:50:59 UTC',
             'end_date': '2047-11-24 14:50:59 UTC'
         }, {
             'derived_entitlement': True,
             'name': 'Employee SKU',
             'amount': 1,
             'account_number': 1212729,
             'contract_number': 10913844,
             'start_date': '2016-03-24 04:00:00 UTC',
             'end_date': '2022-01-01 04:59:59 UTC'
         }]
     }
     expected = {
         'uuid':
         '00c7a108-48ec-4a97-835c-aa3369777f64',
         'hostname':
         'mac52540071bafe.prov.lan',
         'registered_by':
         'sat-r220-07.lab.eng.rdu2.redhat.com',
         'registration_time':
         '2017-12-04 13:33:52 UTC',
         'last_checkin_time':
         '2018-01-04 17:36:07 UTC',
         'katello_agent_installed':
         False,
         'os_name':
         'RedHat 7.4',
         'organization':
         'ACME',
         'virtual_host_uuid':
         '100',
         'virtual_host_name':
         'vhost1',
         'num_virtual_guests':
         1,
         'virtual':
         'hypervisor',
         'location':
         'Raleigh',
         'ip_addresses': ['192.168.99.123'],
         'ipv6_addresses': ['fe80::5054:ff:fe24:946e'],
         'entitlements': [{
             'derived_entitlement': False,
             'name': 'Satellite Tools 6.3',
             'amount': 1,
             'account_number': None,
             'contract_number': None,
             'start_date': '2017-12-01 14:50:59 UTC',
             'end_date': '2047-11-24 14:50:59 UTC'
         }, {
             'derived_entitlement': True,
             'name': 'Employee SKU',
             'amount': 1,
             'account_number': 1212729,
             'contract_number': 10913844,
             'start_date': '2016-03-24 04:00:00 UTC',
             'end_date': '2022-01-01 04:59:59 UTC'
         }]
     }
     with patch('scanner.satellite.six.host_fields',
                return_value=fields_return_value) as mock_fields:
         with patch('scanner.satellite.six.host_subscriptions',
                    return_value=subs_return_value) as mock_subs:
             result = {
                 'unique_name': 'sys_1',
                 'system_inspection_result': SystemInspectionResult.SUCCESS,
                 'host_fields_response': fields_return_value,
                 'host_subscriptions_response': subs_return_value
             }
             process_results(self.api, [result], 1)
             inspect_results = \
                 self.scan_task.inspection_result.systems.all()
             sys_1_result = inspect_results.filter(name='sys_1').first()
             self.assertEqual(sys_1_result.name, 'sys_1')
             self.assertEqual(sys_1_result.status, 'success')
             result = {}
             for fact in sys_1_result.facts.all():
                 result[fact.name] = json.loads(fact.value)
             self.assertEqual(result, expected)
             mock_fields.assert_called_once_with(ANY, ANY)
             mock_subs.assert_called_once_with(ANY)
             mock_fields.assert_called_once_with(ANY, ANY)
             mock_subs.assert_called_once_with(ANY)