def test_network_interfaces_just_lo_ethtool_no_get_ipv4_addresses(
            self, MockGetInterfacesInfo, MockGetDevices):

        hw = hwprobe.HardwareCollector()
        MockGetDevices.return_value = ['lo']
        mock_info = Mock(mac_address="00:00:00:00:00:00",
                         device="lo",
                         ipv4_address="127.0.0.1",
                         ipv4_netmask="24",
                         ipv4_broadcast="Unknown")
        mock_info.get_ipv6_addresses.return_value = []

        # mock etherinfo not having a get_ipv4_addresses method
        # if this fails, you need a mock that supports deleting
        # attributes from mocks, ala mock 1.0+
        try:
            del mock_info.get_ipv4_addresses
        except AttributeError:
            self.fail(
                "You probably need a newer version of 'mock' installed, 1.0 or newer"
            )

        MockGetInterfacesInfo.return_value = [mock_info]

        net_int = hw.get_network_interfaces()
        self.assertEqual(net_int['net.interface.lo.ipv4_address'], '127.0.0.1')
        self.assertFalse('net.interface.lo.mac_address' in net_int)
 def test_meminfo(self):
     hw = hwprobe.HardwareCollector()
     mem = hw.get_mem_info()
     # not great tests, but alas
     self.assertEqual(len(mem), 2)
     for key in mem:
         assert key in ['memory.memtotal', 'memory.swaptotal']
Ejemplo n.º 3
0
    def test_distro_with_os_release(self, mock_exists):
        """
        Test reading release information from /etc/os-release
        """

        def mock_os_path_exists(path):
            """
            This method mock missing /etc/redhat-release
            :param path: of this file
            :return: False for /etc/redhat-release and True for any other file
            """
            if path == "/etc/redhat-release":
                return False
            else:
                return True

        mock_exists.side_effect = mock_os_path_exists
        hw = hwprobe.HardwareCollector()
        expected = {
            "distribution.version": "42",
            "distribution.name": "Awesome OS",
            "distribution.id": "Go4It",
            "distribution.version.modifier": "",
        }
        self.assertEqual(hw.get_release_info(), expected)
 def test_lscpu_ignores_locale(self):
     hw_check_topo = hwprobe.HardwareCollector()
     facts = hw_check_topo.get_ls_cpu_info()
     # if all values can be encoded as ascii, then lscpu is not using JP locale
     for key, value in facts.items():
         key.encode('ascii')
         value.encode('ascii')
Ejemplo n.º 5
0
 def test_mocked_json_parser(self, mock_access, mock_check_json, mock_check_output):
     mock_access.return_value = True
     mock_check_json.return_value = True
     mock_check_output.return_value = LSCPU_JSON_OUTPUT
     hw_check = hwprobe.HardwareCollector()
     facts = hw_check.get_ls_cpu_info()
     self.assertEqual(LSCPU_JSON_EXPECTED, facts)
Ejemplo n.º 6
0
 def __init__(self):
     self.collectors = [
         collector.StaticFactsCollector(),
         host_collector.HostCollector(),
         hwprobe.HardwareCollector(),
         custom.CustomFactsCollector(),
     ]
 def setUp(self):
     # Note this is patching an *instance* of HardwareCollector, not the class.
     self.hw_check_topo = hwprobe.HardwareCollector()
     self.hw_check_topo_patcher = patch.object(self.hw_check_topo,
                                               'check_for_cpu_topo',
                                               Mock(return_value=True))
     self.hw_check_topo_patcher.start()
     super(HardwareProbeTest, self).setUp()
 def test_networkinfo(self):
     hw = hwprobe.HardwareCollector()
     net = hw.get_network_info()
     expected = set([
         'network.fqdn', 'network.hostname', 'network.ipv4_address',
         'network.ipv6_address'
     ])
     self.assertEqual(expected, set(net.keys()))
Ejemplo n.º 9
0
 def __init__(self):
     self.collectors = [
         collector.StaticFactsCollector(),
         host_collector.HostCollector(),
         hwprobe.HardwareCollector(),
         custom.CustomFactsCollector(),
         insights.InsightsCollector(),
         kpatch.KPatchCollector()
     ]
Ejemplo n.º 10
0
 def test_distro_with_platform(self, MockExists):
     MockExists.return_value = False
     hw = hwprobe.HardwareCollector()
     expected = {
         'distribution.version': '42',
         'distribution.name': 'Awesome OS',
         'distribution.id': 'Go4It',
         'distribution.version.modifier': 'Unknown'
     }
     self.assertEqual(hw.get_release_info(), expected)
Ejemplo n.º 11
0
 def test_distro_newline_in_release(self, MockOpen, MockExists):
     hw = hwprobe.HardwareCollector()
     MockExists.side_effect = [False, True]
     MockOpen.return_value.readline.return_value = "Awesome OS release 42 (Go4It)\n\n"
     expected = {
         "distribution.version": "42",
         "distribution.name": "Awesome OS",
         "distribution.id": "Go4It",
         "distribution.version.modifier": "",
     }
     self.assertEqual(hw.get_release_info(), expected)
Ejemplo n.º 12
0
 def test_distro_newline_in_release(self, MockOpen, MockExists):
     hw = hwprobe.HardwareCollector()
     MockExists.side_effect = [False, True]
     MockOpen.return_value.readline.return_value = "Awesome OS release 42 (Go4It)\n\n"
     expected = {
         'distribution.version': '42',
         'distribution.name': 'Awesome OS',
         'distribution.id': 'Go4It',
         'distribution.version.modifier': ''
     }
     self.assertEqual(hw.get_release_info(), expected)
Ejemplo n.º 13
0
 def test_distro_os_release_colon(self, MockOpen, MockExists):
     MockExists.return_value = True
     hw = hwprobe.HardwareCollector()
     with patch("rhsmlib.facts.hwprobe.platform"):
         MockOpen.return_value.readlines.return_value = OS_RELEASE_COLON.split("\n")
         expected = {
             "distribution.version": "42",
             "distribution.name": "Awesome OS",
             "distribution.id": "Go4It",
             "distribution.version.modifier": "be:ta",
         }
         self.assertEqual(hw.get_release_info(), expected)
Ejemplo n.º 14
0
 def test_manual_distro_with_modifier(self, MockOpen, MockExists):
     MockExists.side_effect = [False, True]
     hw = hwprobe.HardwareCollector()
     with patch("rhsmlib.facts.hwprobe.platform"):
         MockOpen.return_value.readline.return_value = "Awesome OS release 42 Mega (Go4It)"
         expected = {
             "distribution.version": "42",
             "distribution.name": "Awesome OS",
             "distribution.id": "Go4It",
             "distribution.version.modifier": "mega",
         }
         self.assertEqual(hw.get_release_info(), expected)
Ejemplo n.º 15
0
 def test_distro_os_release_colon(self, MockOpen, MockExists):
     MockExists.return_value = True
     hw = hwprobe.HardwareCollector()
     with patch('rhsmlib.facts.hwprobe.platform'):
         MockOpen.return_value.readlines.return_value = OS_RELEASE_COLON.split('\n')
         expected = {
             'distribution.version': '42',
             'distribution.name': 'Awesome OS',
             'distribution.id': 'Go4It',
             'distribution.version.modifier': 'be:ta'
         }
         self.assertEquals(hw.get_release_info(), expected)
Ejemplo n.º 16
0
 def test_manual_distro_bogus_content_os_release(self, MockOpen, MockExists):
     hw = hwprobe.HardwareCollector()
     with patch('rhsmlib.facts.hwprobe.platform'):
         MockExists.return_value = True
         MockOpen.return_value.readlines.return_value = ["This is not really a release file of any sort"]
         expected = {
             'distribution.version': 'Unknown',
             'distribution.name': 'Unknown',
             'distribution.id': 'Unknown',
             'distribution.version.modifier': ''
         }
         self.assertEquals(hw.get_release_info(), expected)
Ejemplo n.º 17
0
 def test_distro_bogus_content_no_platform_module(self, MockOpen, MockExists):
     hw = hwprobe.HardwareCollector()
     MockExists.side_effect = [False, True]
     with patch('rhsmlib.facts.hwprobe.platform'):
         MockOpen.return_value.readline.return_value = "this is not really a release file of any sort"
         expected = {
             'distribution.version': 'Unknown',
             'distribution.name': 'Unknown',
             'distribution.id': 'Unknown',
             'distribution.version.modifier': ''
         }
         self.assertEquals(hw.get_release_info(), expected)
Ejemplo n.º 18
0
    def test_network_interfaces_just_lo(self, MockGetInterfacesInfo, MockGetDevices):
        hw = hwprobe.HardwareCollector()
        MockGetDevices.return_value = ["lo"]
        mock_info = Mock(mac_address="00:00:00:00:00:00", device="lo")

        mock_info.get_ipv6_addresses.return_value = []
        mock_ipv4 = Mock(address="127.0.0.1", netmask="24", broadcase="Unknown")
        mock_info.get_ipv4_addresses = Mock(return_value=[mock_ipv4])
        MockGetInterfacesInfo.return_value = [mock_info]
        net_int = hw.get_network_interfaces()
        self.assertEqual(net_int["net.interface.lo.ipv4_address"], "127.0.0.1")
        self.assertFalse("net.interface.lo.mac_address" in net_int)
Ejemplo n.º 19
0
 def test_manual_distro_with_modifier(self, MockOpen, MockExists):
     MockExists.side_effect = [False, True]
     hw = hwprobe.HardwareCollector()
     with patch('rhsmlib.facts.hwprobe.platform'):
         MockOpen.return_value.readline.return_value = "Awesome OS release 42 Mega (Go4It)"
         expected = {
             'distribution.version': '42',
             'distribution.name': 'Awesome OS',
             'distribution.id': 'Go4It',
             'distribution.version.modifier': 'mega'
         }
         self.assertEqual(hw.get_release_info(), expected)
Ejemplo n.º 20
0
    def test_network_interfaces_sit(self, MockGetInterfacesInfo, MockGetDevices):
        hw = hwprobe.HardwareCollector()
        MockGetDevices.return_value = ["sit0"]
        mock_ipv6 = Mock(address="::1", netmask="/128", scope="global")

        mock_info = Mock(mac_address="00:00:00:00:00:00", device="sit0")
        mock_info.get_ipv6_addresses.return_value = [mock_ipv6]
        mock_info.get_ipv4_addresses.return_value = []
        MockGetInterfacesInfo.return_value = [mock_info]

        net_int = hw.get_network_interfaces()
        # ignore mac address for sit* interfaces (bz #838123)
        self.assertFalse("net.interface.sit0.mac_address" in net_int)
Ejemplo n.º 21
0
    def test_network_interfaces_just_lo_ipv6(self, MockGetInterfacesInfo, MockGetDevices):
        hw = hwprobe.HardwareCollector()
        MockGetDevices.return_value = ["lo"]

        mock_ipv6 = Mock(address="::1", netmask="/128", scope="global")

        mock_info = Mock(mac_address="00:00:00:00:00:00", device="lo")
        mock_info.get_ipv6_addresses.return_value = [mock_ipv6]
        mock_info.get_ipv4_addresses.return_value = []
        MockGetInterfacesInfo.return_value = [mock_info]

        net_int = hw.get_network_interfaces()
        self.assertEqual(net_int["net.interface.lo.ipv6_address.global"], "::1")
        self.assertFalse("net.interface.lo.mac_address" in net_int)
Ejemplo n.º 22
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)

        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
Ejemplo n.º 23
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
Ejemplo n.º 24
0
    def test_network_interfaces_multiple_ipv6(self, MockGetInterfacesInfo, MockGetDevices):
        hw = hwprobe.HardwareCollector()

        MockGetDevices.return_value = ['eth0']
        mock_info = Mock(mac_address="00:00:00:00:00:00", device="eth0")
        mock_info.get_ipv4_addresses.return_value = []
        mock_ipv6s = [Mock(address="::1", netmask="/128", scope="link"),
                      Mock(address="fe80::f00d:f00d:f00d:f00d", netmask="/64", scope="link")]
        mock_info.get_ipv6_addresses = Mock(return_value=mock_ipv6s)
        MockGetInterfacesInfo.return_value = [mock_info]

        net_int = hw.get_network_interfaces()

        self.assertEqual(net_int['net.interface.eth0.ipv6_address.link'], '::1')
        self.assertEqual(net_int['net.interface.eth0.ipv6_address.link_list'], '::1, fe80::f00d:f00d:f00d:f00d')
Ejemplo n.º 25
0
    def test_network_interfaces_multiple_ipv4(self, MockGetInterfacesInfo, MockGetDevices):
        hw = hwprobe.HardwareCollector()

        MockGetDevices.return_value = ['eth0']
        mock_info = Mock(mac_address="00:00:00:00:00:00", device="eth0")
        mock_info.get_ipv6_addresses.return_value = []
        mock_ipv4s = [Mock(address="10.0.0.1", netmask="24", broadcast="Unknown"),
                      Mock(address="10.0.0.2", netmask="24", broadcast="Unknown")]
        mock_info.get_ipv4_addresses = Mock(return_value=mock_ipv4s)
        MockGetInterfacesInfo.return_value = [mock_info]

        net_int = hw.get_network_interfaces()

        self.assertEquals(net_int['net.interface.eth0.ipv4_address'], '10.0.0.2')
        self.assertEquals(net_int['net.interface.eth0.ipv4_address_list'], '10.0.0.1, 10.0.0.2')
    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
Ejemplo n.º 27
0
    def test_last_boot(self, mock_exists):
        """
        Test reading release information from /proc/uptime
        """

        def mock_os_path_exists(path):
            """
            This method mock missing /proc/uptime
            :param path: of this file
            :return: False for /proc/uptime and True for any other file
            """
            if path == "/proc/uptime":
                return False
            else:
                return True

        mock_exists.side_effect = mock_os_path_exists
        hw = hwprobe.HardwareCollector()
        last_boot_dict = hw.get_last_boot()
        last_boot = last_boot_dict["last_boot"]
        self.assertTrue(last_boot.endswith(" UTC"))
Ejemplo n.º 28
0
Archivo: base.py Proyecto: Lorquas/rhsm
        # Default is an empty FactsCollector
        self.facts_collector = self.facts_collector_class()

    @util.dbus_service_method(dbus_interface=constants.FACTS_DBUS_INTERFACE,
                              out_signature='a{ss}')
    @util.dbus_handle_exceptions
    def GetFacts(self, sender=None):
        collection = self.facts_collector.collect()
        cleaned = dict([(str(key), str(value))
                        for key, value in list(collection.data.items())])
        return dbus.Dictionary(cleaned, signature="ss")


def class_factory(name, facts_collector=None):
    """Function used for creating subclasses of class BaseFact"""
    def __init__(self, conn=None, object_path=None, bus_name=None):
        super(self.__class__, self).__init__(conn=conn,
                                             object_path=object_path,
                                             bus_name=bus_name)
        self.facts_collector = facts_collector

    return type(name, (BaseFacts, ), {"__init__": __init__})


AllFacts = class_factory('AllFacts', all.AllFactsCollector())
HostFacts = class_factory('HostFacts', host_collector.HostCollector())
HardwareFacts = class_factory('HardwareFacts', hwprobe.HardwareCollector())
CustomFacts = class_factory('CustomFacts', custom.CustomFactsCollector())
StaticFacts = class_factory('StaticFacts', collector.StaticFactsCollector())
Ejemplo n.º 29
0
 def test_get_slave_hwaddr_alb(self, MockOpen):
     MockOpen.return_value = six.StringIO(PROC_BONDING_ALB)
     hw = hwprobe.HardwareCollector()
     slave_hw = hw._get_slave_hwaddr("bond0", "eth0")
     # note we .upper the result
     self.assertEqual("52:54:00:07:03:BA", slave_hw)
Ejemplo n.º 30
0
 def test_network_interfaces_none(self, MockGetInterfacesInfo,
                                  MockGetDevices):
     hw = hwprobe.HardwareCollector()
     net_int = hw.get_network_interfaces()
     self.assertEqual(net_int, {})