def test_get_all_block_devices_when_oserror_is_enoent(self):
        driver = host_driver.HostDriver()
        oserror = OSError(errno.ENOENT, "")
        with mock.patch('os.listdir', side_effect=oserror):
            block_devices = driver.get_all_block_devices()

        self.assertEqual([], block_devices)
    def test_get_all_block_devices(self):
        fake_dev = ['device1', 'device2']
        expected = ['/dev/disk/by-path/' + dev for dev in fake_dev]

        driver = host_driver.HostDriver()
        with mock.patch('os.listdir', return_value=fake_dev):
            actual = driver.get_all_block_devices()

        self.assertEqual(expected, actual)
Esempio n. 3
0
    def __init__(self, root_helper: str, driver=None, execute=None,
                 *args, **kwargs):
        self._linuxscsi = linuxscsi.LinuxSCSI(root_helper, execute=execute)

        if not driver:
            driver = host_driver.HostDriver()
        self.set_driver(driver)

        super(BaseLinuxConnector, self).__init__(root_helper, execute=execute,
                                                 *args, **kwargs)
 def test_get_all_block_devices_when_oserror_is_not_enoent(self):
     driver = host_driver.HostDriver()
     oserror = OSError(errno.ENOMEM, "")
     with mock.patch('os.listdir', side_effect=oserror):
         self.assertRaises(OSError, driver.get_all_block_devices)