Exemplo n.º 1
0
    def test_udevadm_uuid(self):
        module = Mock()
        module.run_command = Mock(return_value=(0, UDEVADM_OUTPUT, ''))  # (rc, out, err)
        lh = linux.LinuxHardware(module=module, load_on_init=False)
        udevadm_uuid = lh._udevadm_uuid('mock_device')

        self.assertEqual(udevadm_uuid, '57b1a3e7-9019-4747-9809-7ec52bba9179')
Exemplo n.º 2
0
    def test_get_mount_facts(self,
                             mock_get_mount_size,
                             mock_lsblk_uuid,
                             mock_find_bind_mounts,
                             mock_mtab_entries,
                             mock_udevadm_uuid):
        module = Mock()
        # Returns a LinuxHardware-ish
        lh = linux.LinuxHardware(module=module, load_on_init=False)

        # Nothing returned, just self.facts modified as a side effect
        mount_facts = lh.get_mount_facts()
        self.assertIsInstance(mount_facts, dict)
        self.assertIn('mounts', mount_facts)
        self.assertIsInstance(mount_facts['mounts'], list)
        self.assertIsInstance(mount_facts['mounts'][0], dict)

        home_expected = {'block_available': 1001578731,
                         'block_size': 4096,
                         'block_total': 105871006,
                         'block_used': 5713133,
                         'device': '/dev/mapper/fedora_dhcp129--186-home',
                         'fstype': 'ext4',
                         'inode_available': 26860880,
                         'inode_total': 26902528,
                         'inode_used': 41648,
                         'mount': '/home',
                         'options': 'rw,seclabel,relatime,data=ordered',
                         'size_available': 410246647808,
                         'size_total': 433647640576,
                         'uuid': 'N/A'}
        home_info = [x for x in mount_facts['mounts'] if x['mount'] == '/home'][0]

        self.maxDiff = 4096
        self.assertDictEqual(home_info, home_expected)
Exemplo n.º 3
0
    def test_find_bind_mounts_non_zero(self, mock_run_findmnt):
        module = Mock()
        lh = linux.LinuxHardware(module=module, load_on_init=False)
        bind_mounts = lh._find_bind_mounts()

        self.assertIsInstance(bind_mounts, set)
        self.assertEqual(len(bind_mounts), 0)
Exemplo n.º 4
0
    def test_lsblk_uuid_non_zero(self, mock_run_lsblk):
        module = Mock()
        lh = linux.LinuxHardware(module=module, load_on_init=False)
        lsblk_uuids = lh._lsblk_uuid()

        self.assertIsInstance(lsblk_uuids, dict)
        self.assertEqual(len(lsblk_uuids), 0)
Exemplo n.º 5
0
    def test_get_mtab_entries(self, mock_get_file_content):

        module = Mock()
        lh = linux.LinuxHardware(module=module, load_on_init=False)
        mtab_entries = lh._mtab_entries()
        self.assertIsInstance(mtab_entries, list)
        self.assertIsInstance(mtab_entries[0], list)
        self.assertEqual(len(mtab_entries), 38)
Exemplo n.º 6
0
    def test_lsblk_uuid_no_lsblk(self):
        module = Mock()
        module.get_bin_path = Mock(return_value=None)
        lh = linux.LinuxHardware(module=module, load_on_init=False)
        lsblk_uuids = lh._lsblk_uuid()

        self.assertIsInstance(lsblk_uuids, dict)
        self.assertEqual(len(lsblk_uuids), 0)
Exemplo n.º 7
0
    def test_find_bind_mounts_no_findmnts(self):
        module = Mock()
        module.get_bin_path = Mock(return_value=None)
        lh = linux.LinuxHardware(module=module, load_on_init=False)
        bind_mounts = lh._find_bind_mounts()

        self.assertIsInstance(bind_mounts, set)
        self.assertEqual(len(bind_mounts), 0)
Exemplo n.º 8
0
 def test_lsblk_uuid_dev_with_space_in_name(self, mock_run_lsblk):
     module = Mock()
     lh = linux.LinuxHardware(module=module, load_on_init=False)
     lsblk_uuids = lh._lsblk_uuid()
     self.assertIsInstance(lsblk_uuids, dict)
     self.assertIn(b'/dev/loop0', lsblk_uuids)
     self.assertIn(b'/dev/sda1', lsblk_uuids)
     self.assertEqual(lsblk_uuids[b'/dev/mapper/an-example-mapper with a space in the name'], b'84639acb-013f-4d2f-9392-526a572b4373')
     self.assertEqual(lsblk_uuids[b'/dev/sda1'], b'32caaec3-ef40-4691-a3b6-438c3f9bc1c0')
Exemplo n.º 9
0
    def test_lsblk_uuid(self, mock_run_lsblk):
        module = Mock()
        lh = linux.LinuxHardware(module=module, load_on_init=False)
        lsblk_uuids = lh._lsblk_uuid()

        self.assertIsInstance(lsblk_uuids, dict)
        self.assertIn(b'/dev/loop9', lsblk_uuids)
        self.assertIn(b'/dev/sda1', lsblk_uuids)
        self.assertEqual(lsblk_uuids[b'/dev/sda1'], b'32caaec3-ef40-4691-a3b6-438c3f9bc1c0')
Exemplo n.º 10
0
    def test_find_bind_mounts(self, mock_run_findmnt):
        module = Mock()
        lh = linux.LinuxHardware(module=module, load_on_init=False)
        bind_mounts = lh._find_bind_mounts()

        # If bind_mounts becomes another seq type, feel free to change
        self.assertIsInstance(bind_mounts, set)
        self.assertEqual(len(bind_mounts), 1)
        self.assertIn('/not/a/real/bind_mount', bind_mounts)
Exemplo n.º 11
0
def test_get_cpu_info(mocker):
    module = mocker.Mock()
    inst = linux.LinuxHardware(module)

    mocker.patch('os.path.exists', return_value=False)
    mocker.patch('os.access', return_value=True)
    for test in CPU_INFO_TEST_SCENARIOS:
        mocker.patch('assible.module_utils.facts.hardware.linux.get_file_lines', side_effect=[[], test['cpuinfo']])
        mocker.patch('os.sched_getaffinity', create=True, return_value=test['sched_getaffinity'])
        module.run_command.return_value = (0, test['nproc_out'], '')
        collected_facts = {'assible_architecture': test['architecture']}

        assert test['expected_result'] == inst.get_cpu_facts(collected_facts=collected_facts)
Exemplo n.º 12
0
def test_get_cpu_info_missing_arch(mocker):
    module = mocker.Mock()
    inst = linux.LinuxHardware(module)

    # ARM and Power will report incorrect processor count if architecture is not available
    mocker.patch('os.path.exists', return_value=False)
    mocker.patch('os.access', return_value=True)
    for test in CPU_INFO_TEST_SCENARIOS:
        mocker.patch('assible.module_utils.facts.hardware.linux.get_file_lines', side_effect=[[], test['cpuinfo']])
        mocker.patch('os.sched_getaffinity', create=True, return_value=test['sched_getaffinity'])

        module.run_command.return_value = (0, test['nproc_out'], '')

        test_result = inst.get_cpu_facts()

        if test['architecture'].startswith(('armv', 'aarch', 'ppc')):
            assert test['expected_result'] != test_result
        else:
            assert test['expected_result'] == test_result