Esempio n. 1
0
    def test_virt_guest(self, MockPopen):
        MockPopen.return_value.communicate.return_value = ['kvm', None]
        MockPopen.return_value.poll.return_value = 0

        hw = virt.VirtCollector()
        expected = {'virt.is_guest': True, 'virt.host_type': 'kvm'}
        self.assertEquals(expected, hw.get_all())
    def test_command_valid(self, MockPopen):
        MockPopen.return_value.communicate.return_value = ['this is valid', None]
        MockPopen.return_value.poll.return_value = 0

        # Pick up the mocked class
        hw = virt.VirtCollector(testing='testing')
        self.assertEqual('this is valid', hw.get_all()['virt.host_type'])
Esempio n. 3
0
 def test_virt_bare_metal(self, MockPopen):
     mock_process = MagicMock()
     mock_process.communicate.return_value = [b"", None]
     mock_process.poll.return_value = 0
     mock_process.__enter__.return_value = mock_process
     MockPopen.return_value = mock_process
     hw = virt.VirtCollector()
     expected = {"virt.is_guest": False, "virt.host_type": "Not Applicable"}
     self.assertEqual(expected, hw.get_all())
Esempio n. 4
0
    def test_command_valid(self, MockPopen):
        mock_process = MagicMock()
        mock_process.communicate.return_value = [b"this is valid", None]
        mock_process.poll.return_value = 0
        mock_process.__enter__.return_value = mock_process
        MockPopen.return_value = mock_process

        # Pick up the mocked class
        hw = virt.VirtCollector(testing="testing")
        self.assertEqual("this is valid", hw.get_all()["virt.host_type"])
Esempio n. 5
0
    def test_virt_guest(self, MockPopen):
        mock_process = MagicMock()
        mock_process.communicate.return_value = ['kvm', None]
        mock_process.poll.return_value = 0
        mock_process.__enter__.return_value = mock_process
        MockPopen.return_value = mock_process

        hw = virt.VirtCollector()
        expected = {'virt.is_guest': True, 'virt.host_type': 'kvm'}
        self.assertEqual(expected, hw.get_all())
Esempio n. 6
0
    def get_all(self):
        host_facts = {}

        firmware_collector = firmware_info.FirmwareCollector(
            prefix=self.prefix,
            testing=self.testing,
        )
        firmware_info_dict = firmware_collector.get_all()

        virt_collector = virt.VirtCollector(
            prefix=self.prefix,
            testing=self.testing,
            collected_hw_info=firmware_info_dict)
        virt_collector_info = virt_collector.get_all()

        cloud_collector = cloud_facts.CloudFactsCollector(
            prefix=self.prefix,
            testing=self.testing,
            collected_hw_info=firmware_info_dict)
        cloud_facts_info = cloud_collector.get_all()

        host_facts.update(cloud_facts_info)
        host_facts.update(virt_collector_info)
        host_facts.update(firmware_info_dict)

        locale_info = {}
        effective_locale = 'Unknown'
        # When there is no locale set (system variable LANG is unset),
        # then this is value returned by locale.getdefaultlocale()
        # Tuple contains: (language[_territory], encoding identifier)
        default_locale = (None, None)
        try:
            default_locale = locale.getdefaultlocale()
        except ValueError as err:
            log.warning(
                "Unable to get default locale (bad environment variable?): %s"
                % err)
        if default_locale[0] is not None:
            effective_locale = ".".join([_f for _f in default_locale if _f])
        locale_info['system.default_locale'] = effective_locale
        host_facts.update(locale_info)

        # Now, munging, kluges, special cases, etc
        # NOTE: we are passing the facts we've already collected into
        # cleanup_collector.
        cleanup_collector = cleanup.CleanupCollector(
            prefix=self.prefix,
            testing=self.testing,
            collected_hw_info=host_facts)
        cleanup_info = cleanup_collector.get_all()

        host_facts.update(cleanup_info)
        return host_facts
Esempio n. 7
0
    def get_all(self):
        host_facts = {}
        hardware_collector = hwprobe.HardwareCollector(prefix=self.prefix,
                                                       testing=self.testing)
        hardware_info = hardware_collector.get_all()

        firmware_collector = firmware_info.FirmwareCollector(
            prefix=self.prefix,
            testing=self.testing,
        )
        firmware_info_dict = firmware_collector.get_all()

        virt_collector = virt.VirtCollector(
            prefix=self.prefix,
            testing=self.testing,
            collected_hw_info=firmware_info_dict)
        virt_collector_info = virt_collector.get_all()

        host_facts.update(hardware_info)
        host_facts.update(virt_collector_info)
        host_facts.update(firmware_info_dict)

        default_rhsm_dir = rhsm.config.DEFAULT_CONFIG_DIR.rstrip('/')
        custom_facts_dir = os.path.join(default_rhsm_dir, self.facts_sub_dir)
        path_and_globs = [(custom_facts_dir, self.facts_glob)]

        custom_facts = custom.CustomFactsCollector(
            prefix=self.prefix,
            testing=self.testing,
            path_and_globs=path_and_globs)
        custom_facts_dict = custom_facts.get_all()
        host_facts.update(custom_facts_dict)

        locale_info = {}
        locale_info['system.default_locale'] = ".".join(
            locale.getdefaultlocale())
        host_facts.update(locale_info)

        # Now, munging, kluges, special cases, etc
        # NOTE: we are passing the facts we've already collected into
        # cleanup_collector.
        cleanup_collector = cleanup.CleanupCollector(
            prefix=self.prefix,
            testing=self.testing,
            collected_hw_info=host_facts)
        cleanup_info = cleanup_collector.get_all()

        host_facts.update(cleanup_info)
        return host_facts
    def get_all(self):
        host_facts = {}
        hardware_collector = hwprobe.HardwareCollector(
            prefix=self.prefix,
            testing=self.testing
        )
        hardware_info = hardware_collector.get_all()

        firmware_collector = firmware_info.FirmwareCollector(
            prefix=self.prefix,
            testing=self.testing,
        )
        firmware_info_dict = firmware_collector.get_all()

        virt_collector = virt.VirtCollector(
            prefix=self.prefix,
            testing=self.testing,
            collected_hw_info=firmware_info_dict
        )
        virt_collector_info = virt_collector.get_all()

        host_facts.update(hardware_info)
        host_facts.update(virt_collector_info)
        host_facts.update(firmware_info_dict)

        locale_info = {}
        effective_locale = 'Unknown'
        if locale.getdefaultlocale()[0] is not None:
            effective_locale = ".".join(filter(None, locale.getdefaultlocale()))
        locale_info['system.default_locale'] = effective_locale
        host_facts.update(locale_info)

        # Now, munging, kluges, special cases, etc
        # NOTE: we are passing the facts we've already collected into
        # cleanup_collector.
        cleanup_collector = cleanup.CleanupCollector(
            prefix=self.prefix,
            testing=self.testing,
            collected_hw_info=host_facts
        )
        cleanup_info = cleanup_collector.get_all()

        host_facts.update(cleanup_info)
        return host_facts
Esempio n. 9
0
 def test_virt_bare_metal(self, MockPopen):
     MockPopen.return_value.communicate.return_value = ['', None]
     MockPopen.return_value.poll.return_value = 0
     hw = virt.VirtCollector()
     expected = {'virt.is_guest': False, 'virt.host_type': 'Not Applicable'}
     self.assertEquals(expected, hw.get_all())