Пример #1
0
    def test_lookup_disk(self, mock_os_listdir, mock_os_path_exists,
                         mock_os_path_realpath, mock_mpath):
        serial = "SERIAL123"
        mock_os_listdir.return_value = [
            "sda_%s-part1" % serial,
            "sda_%s" % serial, "other"
        ]
        mock_os_path_exists.return_value = True
        mock_os_path_realpath.return_value = "/dev/sda"
        mock_mpath.is_mpath_device.return_value = False
        mock_mpath.is_mpath_member.return_value = False

        path = block.lookup_disk(serial)

        mock_os_listdir.assert_called_with("/dev/disk/by-id/")
        mock_os_path_realpath.assert_called_with("/dev/disk/by-id/sda_%s" %
                                                 serial)
        self.assertTrue(mock_os_path_exists.called)
        self.assertEqual(path, "/dev/sda")

        with self.assertRaises(ValueError):
            mock_os_path_exists.return_value = False
            block.lookup_disk(serial)

        with self.assertRaises(ValueError):
            mock_os_path_exists.return_value = True
            mock_os_listdir.return_value = ["other"]
            block.lookup_disk(serial)
Пример #2
0
    def test_lookup_disk_find_wwn(self, mock_os_listdir, mock_os_path_exists,
                                  mock_os_path_realpath, mock_mpath):
        wwn = "eui.0025388b710116a1"
        expected_link = 'nvme-%s' % wwn
        device = '/wark/nvme0n1'
        mock_os_listdir.return_value = [
            "nvme-eui.0025388b710116a1",
            "nvme-eui.0025388b710116a1-part1",
            "nvme-eui.0025388b710116a1-part2",
        ]
        mock_os_path_exists.return_value = True
        mock_os_path_realpath.return_value = device
        mock_mpath.is_mpath_device.return_value = False

        path = block.lookup_disk(wwn)

        mock_os_listdir.assert_called_with("/dev/disk/by-id/")
        mock_os_path_realpath.assert_called_with("/dev/disk/by-id/" +
                                                 expected_link)
        self.assertTrue(mock_os_path_exists.called)
        self.assertEqual(device, path)