Esempio n. 1
0
 def test_host_details_virt_guest(self, mock_serverproxy):
     """Test host_details method with mock data for virt guest."""
     expected = {
         'uuid': 1,
         'name': 'sys1',
         'hostname': 'sys1_hostname',
         'last_checkin_time': '',
         'registration_time': 'datetime',
         'architecture': 'x86',
         'kernel_version': 'kernel',
         'cores': 2,
         'num_sockets': 2,
         'os_release': '7server',
         'entitlements': [{
             'name': 'ent1'
         }],
         'ip_addresses': ['1.2.3.4'],
         'mac_addresses': ['1:a:2:b:3:c'],
         'is_virtualized': True,
         'virtual_host': 2,
         'virtual_host_name': 'sys2'
     }
     client = mock_serverproxy.return_value
     client.auth.login.return_value = 'key'
     client.auth.logout.return_value = 'key'
     client.system.get_uuid.return_value = ''
     cpu = {'arch': 'x86', 'count': 2, 'socket_count': 2}
     client.system.get_cpu.return_value = cpu
     system_details = {'hostname': 'sys1_hostname', 'release': '7server'}
     client.system.get_details.return_value = system_details
     client.system.get_running_kernel.return_value = 'kernel'
     client.system.get_entitlements.return_value = ['ent1']
     net_devices = [{
         'interface': 'eth0',
         'ip': '1.2.3.4',
         'hardware_address': '1:a:2:b:3:c'
     }]
     client.system.get_network_devices.return_value = net_devices
     client.system.get_registration_date.return_value = 'datetime'
     virt = {2: {'uuid': 2, 'name': 'sys2', 'num_virtual_guests': 3}}
     raw_result = request_host_details(host_id=1,
                                       host_name='sys1',
                                       last_checkin='',
                                       scan_task=self.scan_task,
                                       request_options={},
                                       logging_options=None)
     self.api.process_results([raw_result], virt, {1: 2}, [])
     inspect_results = \
         self.scan_task.inspection_result.systems.all()
     sys_1_result = inspect_results.filter(name='sys1_1').first()
     self.assertEqual(sys_1_result.name, 'sys1_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)
Esempio n. 2
0
    def test_host_details_with_err(self, mock_serverproxy):
        """Test the host details with an error."""
        client = mock_serverproxy.return_value
        client.auth.login.side_effect = mock_xml_fault
        virt = {2: {'uuid': 2, 'name': 'sys2', 'num_virtual_guests': 3}}
        raw_result = request_host_details(host_id=2,
                                          host_name='sys2',
                                          last_checkin='',
                                          scan_task=self.scan_task,
                                          request_options={},
                                          logging_options=None)

        self.api.process_results([raw_result], virt, {1: 2}, [])
        inspect_results = \
            self.scan_task.inspection_result.systems.all()
        sys_1_result = inspect_results.filter(name='sys2_2').first()
        self.assertEqual(sys_1_result.name, 'sys2_2')
        self.assertEqual(sys_1_result.status, 'failed')
        result = {}
        for fact in sys_1_result.facts.all():
            result[fact.name] = json.loads(fact.value)
        self.assertEqual(result, {})