示例#1
0
 def test_distro_newline_in_release(self, MockOpen, MockExists):
     reload(hwprobe)
     hw = hwprobe.Hardware()
     MockExists.side_effect = [False, True]
     MockOpen.return_value.readline.return_value = "Awesome OS release 42 (Go4It)\n\n"
     self.assertEquals(
         hw.get_release_info(), {
             'distribution.version': '42',
             'distribution.name': 'Awesome OS',
             'distribution.id': 'Go4It'
         })
 def test_default_virt_uuid_guest_with_uuid(self):
     """Check that virt guest systems dont set an 'Unknown' virt.uuid if virt.uuid is found."""
     reload(hwprobe)
     hw = hwprobe.Hardware()
     hw.allhw['virt.host_type'] = 'kvm'
     hw.allhw['virt.is_guest'] = True
     fake_virt_uuid = 'this-is-a-weird-uuid'
     hw.allhw['dmi.system.uuid'] = fake_virt_uuid
     hw.get_virt_uuid()
     self.assertTrue('virt.uuid' in hw.allhw)
     self.assertEquals(fake_virt_uuid, hw.allhw['virt.uuid'])
 def test_manual_distro_with_modifier(self, MockOpen, MockExists):
     reload(hwprobe)
     MockExists.side_effect = [False, True]
     hw = hwprobe.Hardware()
     hwprobe.platform = None
     MockOpen.return_value.readline.return_value = "Awesome OS release 42 Mega (Go4It)"
     self.assertEquals(
         hw.get_release_info(), {
             'distribution.version': '42',
             'distribution.name': 'Awesome OS',
             'distribution.id': 'Go4It',
             'distribution.version.modifier': 'mega'
         })
 def test_distro_with_platform(self, MockOpen, MockExists):
     reload(hwprobe)
     MockExists.return_value = False
     hw = hwprobe.Hardware()
     MockOpen.return_value.readline.return_value = "Awesome OS release 42 (Go4It)"
     MockOpen.return_value.read.return_value = "Awesome OS release 42 (Go4It)"
     self.assertEquals(
         hw.get_release_info(), {
             'distribution.version': '42',
             'distribution.name': 'Awesome OS',
             'distribution.id': 'Go4It',
             'distribution.version.modifier': 'Unknown'
         })
示例#5
0
    def test_parse_s390_sysinfo(self):
        cpu_count = 24
        sysinfo_lines = ["CPU Topology SW:      0 0 0 4 6 4"]

        reload(hwprobe)
        hw = hwprobe.Hardware()

        ret = hw._parse_s390x_sysinfo_topology(cpu_count, sysinfo_lines)

        self.assertEquals(24, ret['socket_count'])
        self.assertEquals(4, ret['book_count'])
        self.assertEquals(6, ret['sockets_per_book'])
        self.assertEquals(4, ret['cores_per_socket'])
 def test_distro_bogus_content_no_platform_module(self, MockOpen,
                                                  MockExists):
     reload(hwprobe)
     hw = hwprobe.Hardware()
     MockExists.side_effect = [False, True]
     hwprobe.platform = None
     MockOpen.return_value.readline.return_value = "this is not really a release file of any sort"
     self.assertEquals(
         hw.get_release_info(), {
             'distribution.version': 'Unknown',
             'distribution.name': 'Unknown',
             'distribution.id': 'Unknown'
         })
示例#7
0
    def test_cpu_info(self, MockListdir):
        reload(hwprobe)
        hw = hwprobe.Hardware()

        MockSocketId = Mock()
        MockListdir.return_value = ["cpu0", "cpu1"]
        MockSocketId.return_value = "0"
        hw._getSocketIdForCpu = MockSocketId
        self.assertEquals(hw.getCpuInfo(), {
            'cpu.cpu(s)': 2,
            'cpu.core(s)_per_socket': 2,
            'cpu.cpu_socket(s)': 1
        })
 def test_distro_os_release(self, MockOpen, MockExists):
     reload(hwprobe)
     MockExists.return_value = True
     hw = hwprobe.Hardware()
     hwprobe.platform = None
     MockOpen.return_value.readlines.return_value = OS_RELEASE.split('\n')
     self.assertEquals(
         hw.get_release_info(), {
             'distribution.version': '42',
             'distribution.name': 'Awesome OS',
             'distribution.id': 'Go4It',
             'distribution.version.modifier': 'beta'
         })
示例#9
0
    def test_cpu_info_lots_cpu(self, MockListdir):
        reload(hwprobe)
        hw = hwprobe.Hardware()

        MockSocketId = Mock()
        MockListdir.return_value = ["cpu%s" % i for i in range(0, 2000)]
        MockSocketId.return_value = "0"
        hw._getSocketIdForCpu = MockSocketId
        self.assertEquals(
            hw.getCpuInfo(), {
                'cpu.cpu(s)': 2000,
                'cpu.core(s)_per_socket': 2000,
                'cpu.cpu_socket(s)': 1
            })
示例#10
0
    def test_network_interfaces_sit(self, MockGetInterfacesInfo,
                                    MockGetDevices):
        reload(hwprobe)
        hw = hwprobe.Hardware()
        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)
示例#11
0
 def test_manual_distro_bogus_content_os_release(self, MockOpen,
                                                 MockExists):
     reload(hwprobe)
     hw = hwprobe.Hardware()
     hwprobe.platform = None
     MockExists.return_value = True
     MockOpen.return_value.readlines.return_value = [
         "This is not really a release file of any sort"
     ]
     self.assertEquals(
         hw.get_release_info(), {
             'distribution.version': 'Unknown',
             'distribution.name': 'Unknown',
             'distribution.id': 'Unknown'
         })
示例#12
0
    def test_network_interfaces_just_lo(self, MockGetInterfacesInfo, MockGetDevices):
        reload(hwprobe)
        hw = hwprobe.Hardware()
        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.assertEquals(net_int['net.interface.lo.ipv4_address'], '127.0.0.1')
        self.assertFalse('net.interface.lo.mac_address' in net_int)
示例#13
0
    def test_cpu_info_s390_sysinfo(self, mock_list_dir, mock_read_sysinfo,
                                   mock_has_sysinfo):

        mock_list_dir.return_value = ["cpu%s" % i for i in range(0, 20)]
        mock_has_sysinfo.return_value = True
        mock_read_sysinfo.return_value = ["CPU Topology SW:      0 0 0 4 6 4"]

        hw = hwprobe.Hardware()
        hw.arch = "s390x"
        hw.check_for_cpu_topo = Mock(return_value=True)

        def count_cpumask(cpu, field):
            return self.cpumask_vals[field]

        # 20 cpus
        # 24 cores, 1 threads per core
        # 1 thread per core, 1 core per socket, 1 socket per book via /sys, but
        # /proc/sysinfo says 4 books of 6 sockets of 4 cores
        #
        # even though we have cpu topo from sysinfo, we also have
        # info from the kernel, which we use in that case
        #
        # and we prefer /proc/sysinfo
        # how do 24 sockets have 20 cpu? The hardware itself
        # has 96 cpus. 54 of those are enabled at the
        # hardware level. Of those 51, 21 are "configured".
        # The LPAR is setup to use 20 of those 21 cpus
        # (and in this setup, actually only 18 of those
        # are "configured").
        self.cpumask_vals = {
            'thread_siblings_list': 1,
            'core_siblings_list': 1,
            'book_siblings_list': 1
        }

        # for this case, we prefer the sysinfo numbers
        hw.count_cpumask_entries = Mock(side_effect=count_cpumask)
        self.assert_equal_dict(
            {
                'cpu.cpu(s)': 20,
                'cpu.socket(s)_per_book': 6,
                'cpu.core(s)_per_socket': 4,
                'cpu.thread(s)_per_core': 1,
                'cpu.book(s)': 4,
                'cpu.cpu_socket(s)': 24,
                'cpu.topology_source': 's390x sysinfo'
            }, hw.get_cpu_info())
示例#14
0
    def test_network_interfaces_just_lo_ipv6(self, MockGetInterfacesInfo,
                                             MockGetDevices):
        reload(hwprobe)
        hw = hwprobe.Hardware()
        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.assertEquals(net_int['net.interface.lo.ipv6_address.global'],
                          '::1')
        self.assertFalse('net.interface.lo.mac_address' in net_int)
示例#15
0
    def test_network_interfaces_multiple_ipv4(self, MockGetInterfacesInfo, MockGetDevices):
        reload(hwprobe)
        hw = hwprobe.Hardware()

        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')
示例#16
0
    def test_cpu_info_no_topo(self, mock_list_dir):
        reload(hwprobe)
        hw = hwprobe.Hardware()

        def count_cpumask(cpu, field):
            return self.cpumask_vals[field]

        self.cpumask_vals = {'thread_siblings_list': None,
                             'core_siblings_list': None,
                             'book_siblings_list': None}

        mock_list_dir.return_value = ["cpu%s" % i for i in range(0, 16)]
        hw.count_cpumask_entries = Mock(side_effect=count_cpumask)

        self.assert_equal_dict({'cpu.cpu(s)': 16,
                                'cpu.core(s)_per_socket': 1,
                                'cpu.cpu_socket(s)': 16,
                                'cpu.thread(s)_per_core': 1,
                                'cpu.topology_source': "fallback one socket"},
                               hw.get_cpu_info())
示例#17
0
    def test_network_interfaces_multiple_ipv4(self, MockGetInterfacesInfo, MockGetDevices):
        reload(hwprobe)
        hw = hwprobe.Hardware()

        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()

        # FIXME/TODO/NOTE: We currently expect to get just the last interface
        # listed in this scenario. But... that is wrong. We should really
        # be supporting multiple addresses per interface in some yet
        # undetermined fashion
        self.assertEquals(net_int['net.interface.eth0.ipv4_address'], '10.0.0.2')
示例#18
0
    def test_cpu_info(self, mock_list_dir, mock_count):
        reload(hwprobe)
        hw = hwprobe.Hardware()

        def count_cpumask(cpu, field):
            return self.cpumask_vals[field]

        self.cpumask_vals = {'thread_siblings_list': 1,
                             'core_siblings_list': 2,
                             'book_siblings_list': None}

        mock_list_dir.return_value = ["cpu0", "cpu1"]
        hw.count_cpumask_entries = Mock(side_effect=count_cpumask)
        #print hw.get_cpu_info()
        self.assert_equal_dict({'cpu.cpu(s)': 2,
                                'cpu.core(s)_per_socket': 2,
                                'cpu.cpu_socket(s)': 1,
                                'cpu.thread(s)_per_core': 1,
                                'cpu.topology_source':
                                    'kernel /sys cpu sibling lists'},
                               hw.get_cpu_info())
示例#19
0
    def test_cpu_info_lots_cpu(self, mock_list_dir):
        reload(hwprobe)
        hw = hwprobe.Hardware()

        mock_list_dir.return_value = ["cpu%s" % i for i in range(0, 2000)]

        def count_cpumask(cpu, field):
            vals = {'thread_siblings_list': 1,
                    #'core_siblings_list': 2,
                    'core_siblings_list': 2000,
                    'book_siblings_list': None}
            return vals[field]

        hw.count_cpumask_entries = Mock(side_effect=count_cpumask)
        self.assert_equal_dict({'cpu.cpu(s)': 2000,
                               'cpu.core(s)_per_socket': 2000,
                               'cpu.thread(s)_per_core': 1,
                               'cpu.cpu_socket(s)': 1,
                               'cpu.topology_source':
                                    'kernel /sys cpu sibling lists'},
                               hw.get_cpu_info(),
)
示例#20
0
    def test_cpu_info_other_files(self, MockListdir):
        reload(hwprobe)
        hw = hwprobe.Hardware()

        MockSocketId = Mock()
        MockListdir.return_value = [
            "cpu0",
            "cpu1",  # normal cpu ids (valid)
            "cpu123123",  # big cpu   (valid)
            "cpu_",  # not valid
            "cpufreq",  # this exists but is not a cpu
            "cpuidle",  # also exists
            "cpu0foo",  # only cpuN are valid
            "cpu11111111 ",  # trailing space, not valie
            "cpu00"
        ]  # odd name, but valid I guess
        MockSocketId.return_value = "0"
        hw._getSocketIdForCpu = MockSocketId
        self.assertEquals(hw.getCpuInfo(), {
            'cpu.cpu(s)': 4,
            'cpu.core(s)_per_socket': 4,
            'cpu.cpu_socket(s)': 1
        })
示例#21
0
 def test_get_arch(self):
     reload(hwprobe)
     hw = hwprobe.Hardware()
     arch = hw.get_arch()
     import platform
     self.assertEquals(platform.machine(), arch)
示例#22
0
 def test_get_platform_specific_info_provider(self):
     reload(hwprobe)
     hw = hwprobe.Hardware()
     info_provider = hw.get_platform_specific_info_provider()
     self.assertTrue(info_provider is not None)
示例#23
0
 def test_get_platform_specific_info_provider_not_dmi(self, mock_get_arch):
     mock_get_arch.return_value = "s390x"
     hw = hwprobe.Hardware()
     info_provider = hw.get_platform_specific_info_provider()
     self.assertEquals(hwprobe.GenericPlatformSpecificInfoProvider,
                       info_provider)
示例#24
0
 def test_network_interfaces_none(self, MockGetInterfacesInfo, MockGetDevices):
     reload(hwprobe)
     hw = hwprobe.Hardware()
     net_int = hw.get_network_interfaces()
     self.assertEquals(net_int, {})
示例#25
0
 def test_distro(self, MockOpen):
     reload(hwprobe)
     hw = hwprobe.Hardware()
     MockOpen.return_value.readline.return_value = "Awesome OS release 42 (Go4It)"
     self.assertEquals(hw.get_release_info(), {'distribution.version': '42', 'distribution.name': 'Awesome OS', 'distribution.id': 'Go4It'})
示例#26
0
 def test_distro_no_release(self, MockOpen):
     reload(hwprobe)
     hw = hwprobe.Hardware()
     MockOpen.side_effect = IOError()
     self.assertRaises(IOError, hw.get_release_info)
示例#27
0
 def test_network_interfaces(self):
     reload(hwprobe)
     hw = hwprobe.Hardware()
     net_int = hw.getNetworkInterfaces()
     self.assertEquals(net_int['net.interface.lo.ipv4_address'],
                       '127.0.0.1')
示例#28
0
 def reload(self):
     reload(hwprobe)
     hw = hwprobe.Hardware()
     hw.check_for_cpu_topo = self._cpu_topo_check
     return hw
示例#29
0
 def test_networkinfo(self):
     reload(hwprobe)
     hw = hwprobe.Hardware()
     net = hw.get_network_info()
     expected = set(['network.fqdn', 'network.hostname', 'network.ipv4_address', 'network.ipv6_address'])
     self.assertEqual(expected, set(net.keys()))