def setUp(self): super(RBDTestCase, self).setUp() def fake_execute(*args, **kwargs): return '', '' self._mox = mox.Mox() self.configuration = mox.MockObject(conf.Configuration) self.configuration.volume_tmp_dir = None self.configuration.rbd_pool = 'rbd' self.configuration.rbd_secret_uuid = None self.configuration.rbd_user = None self.configuration.append_config_values(mox.IgnoreArg()) self.driver = RBDDriver(execute=fake_execute, configuration=self.configuration) self._mox.ReplayAll()
class RBDTestCase(test.TestCase): def setUp(self): super(RBDTestCase, self).setUp() def fake_execute(*args, **kwargs): return '', '' self._mox = mox.Mox() self.configuration = mox.MockObject(conf.Configuration) self.configuration.volume_tmp_dir = None self.configuration.rbd_pool = 'rbd' self.configuration.rbd_secret_uuid = None self.configuration.rbd_user = None self.configuration.append_config_values(mox.IgnoreArg()) self.driver = RBDDriver(execute=fake_execute, configuration=self.configuration) self._mox.ReplayAll() def test_good_locations(self): locations = ['rbd://fsid/pool/image/snap', 'rbd://%2F/%2F/%2F/%2F', ] map(self.driver._parse_location, locations) def test_bad_locations(self): locations = ['rbd://image', 'http://path/to/somewhere/else', 'rbd://image/extra', 'rbd://image/', 'rbd://fsid/pool/image/', 'rbd://fsid/pool/image/snap/', 'rbd://///', ] for loc in locations: self.assertRaises(exception.ImageUnacceptable, self.driver._parse_location, loc) self.assertFalse(self.driver._is_cloneable(loc)) def test_cloneable(self): self.stubs.Set(self.driver, '_get_fsid', lambda: 'abc') location = 'rbd://abc/pool/image/snap' self.assertTrue(self.driver._is_cloneable(location)) def test_uncloneable_different_fsid(self): self.stubs.Set(self.driver, '_get_fsid', lambda: 'abc') location = 'rbd://def/pool/image/snap' self.assertFalse(self.driver._is_cloneable(location)) def test_uncloneable_unreadable(self): def fake_exc(*args): raise exception.ProcessExecutionError() self.stubs.Set(self.driver, '_get_fsid', lambda: 'abc') self.stubs.Set(self.driver, '_execute', fake_exc) location = 'rbd://abc/pool/image/snap' self.assertFalse(self.driver._is_cloneable(location)) def _copy_image(self): @contextlib.contextmanager def fake_temp_file(dir): class FakeTmp: def __init__(self, name): self.name = name yield FakeTmp('test') self.stubs.Set(tempfile, 'NamedTemporaryFile', fake_temp_file) self.stubs.Set(os.path, 'exists', lambda x: True) self.stubs.Set(image_utils, 'fetch_to_raw', lambda w, x, y, z: None) self.driver.copy_image_to_volume(None, {'name': 'test', 'size': 1}, FakeImageService(), None) def test_copy_image_no_volume_tmp(self): self.configuration.volume_tmp_dir = None self._copy_image() def test_copy_image_volume_tmp(self): self.configuration.volume_tmp_dir = '/var/run/cinder/tmp' self._copy_image() def test_update_volume_stats(self): def fake_stats(*args): return RADOS_DF_OUT, '' def fake_safe_get(*args): return "RBD" self.stubs.Set(self.driver, '_execute', fake_stats) self.stubs.Set(self.driver.configuration, 'safe_get', fake_safe_get) expected = dict( volume_backend_name='RBD', vendor_name='Open Source', driver_version=DRIVER_VERSION, storage_protocol='ceph', total_capacity_gb=914, free_capacity_gb=750, reserved_percentage=0) actual = self.driver.get_volume_stats(True) self.assertDictMatch(expected, actual) def test_update_volume_stats_error(self): def fake_exc(*args): raise exception.ProcessExecutionError() def fake_safe_get(*args): return "RBD" self.stubs.Set(self.driver, '_execute', fake_exc) self.stubs.Set(self.driver.configuration, 'safe_get', fake_safe_get) expected = dict( volume_backend_name='RBD', vendor_name='Open Source', driver_version=DRIVER_VERSION, storage_protocol='ceph', total_capacity_gb='unknown', free_capacity_gb='unknown', reserved_percentage=0) actual = self.driver.get_volume_stats(True) self.assertDictMatch(expected, actual)
class RBDTestCase(test.TestCase): def setUp(self): super(RBDTestCase, self).setUp() def fake_execute(*args, **kwargs): return '', '' self._mox = mox.Mox() self.configuration = mox.MockObject(conf.Configuration) self.configuration.volume_tmp_dir = None self.configuration.rbd_pool = 'rbd' self.configuration.rbd_secret_uuid = None self.configuration.rbd_user = None self.configuration.append_config_values(mox.IgnoreArg()) self.driver = RBDDriver(execute=fake_execute, configuration=self.configuration) self._mox.ReplayAll() def test_good_locations(self): locations = [ 'rbd://fsid/pool/image/snap', 'rbd://%2F/%2F/%2F/%2F', ] map(self.driver._parse_location, locations) def test_bad_locations(self): locations = [ 'rbd://image', 'http://path/to/somewhere/else', 'rbd://image/extra', 'rbd://image/', 'rbd://fsid/pool/image/', 'rbd://fsid/pool/image/snap/', 'rbd://///', ] for loc in locations: self.assertRaises(exception.ImageUnacceptable, self.driver._parse_location, loc) self.assertFalse(self.driver._is_cloneable(loc)) def test_cloneable(self): self.stubs.Set(self.driver, '_get_fsid', lambda: 'abc') location = 'rbd://abc/pool/image/snap' self.assertTrue(self.driver._is_cloneable(location)) def test_uncloneable_different_fsid(self): self.stubs.Set(self.driver, '_get_fsid', lambda: 'abc') location = 'rbd://def/pool/image/snap' self.assertFalse(self.driver._is_cloneable(location)) def test_uncloneable_unreadable(self): def fake_exc(*args): raise exception.ProcessExecutionError() self.stubs.Set(self.driver, '_get_fsid', lambda: 'abc') self.stubs.Set(self.driver, '_execute', fake_exc) location = 'rbd://abc/pool/image/snap' self.assertFalse(self.driver._is_cloneable(location)) def _copy_image(self): @contextlib.contextmanager def fake_temp_file(dir): class FakeTmp: def __init__(self, name): self.name = name yield FakeTmp('test') self.stubs.Set(tempfile, 'NamedTemporaryFile', fake_temp_file) self.stubs.Set(os.path, 'exists', lambda x: True) self.stubs.Set(image_utils, 'fetch_to_raw', lambda w, x, y, z: None) self.driver.copy_image_to_volume(None, { 'name': 'test', 'size': 1 }, FakeImageService(), None) def test_copy_image_no_volume_tmp(self): self.configuration.volume_tmp_dir = None self._copy_image() def test_copy_image_volume_tmp(self): self.configuration.volume_tmp_dir = '/var/run/cinder/tmp' self._copy_image() def test_update_volume_stats(self): def fake_stats(*args): return RADOS_DF_OUT, '' self.stubs.Set(self.driver, '_execute', fake_stats) expected = dict(volume_backend_name='RBD', vendor_name='Open Source', driver_version=DRIVER_VERSION, storage_protocol='ceph', total_capacity_gb=914, free_capacity_gb=750, reserved_percentage=0) actual = self.driver.get_volume_stats(True) self.assertDictMatch(expected, actual) def test_update_volume_stats_error(self): def fake_exc(*args): raise exception.ProcessExecutionError() self.stubs.Set(self.driver, '_execute', fake_exc) expected = dict(volume_backend_name='RBD', vendor_name='Open Source', driver_version=DRIVER_VERSION, storage_protocol='ceph', total_capacity_gb='unknown', free_capacity_gb='unknown', reserved_percentage=0) actual = self.driver.get_volume_stats(True) self.assertDictMatch(expected, actual)
def setUp(self): super(RBDTestCase, self).setUp() def fake_execute(*args): pass self.driver = RBDDriver(execute=fake_execute)
class RBDTestCase(test.TestCase): def setUp(self): super(RBDTestCase, self).setUp() def fake_execute(*args): pass self.driver = RBDDriver(execute=fake_execute) def test_good_locations(self): locations = [ 'rbd://fsid/pool/image/snap', 'rbd://%2F/%2F/%2F/%2F', ] map(self.driver._parse_location, locations) def test_bad_locations(self): locations = [ 'rbd://image', 'http://path/to/somewhere/else', 'rbd://image/extra', 'rbd://image/', 'rbd://fsid/pool/image/', 'rbd://fsid/pool/image/snap/', 'rbd://///', ] for loc in locations: self.assertRaises(exception.ImageUnacceptable, self.driver._parse_location, loc) self.assertFalse(self.driver._is_cloneable(loc)) def test_cloneable(self): self.stubs.Set(self.driver, '_get_fsid', lambda: 'abc') location = 'rbd://abc/pool/image/snap' self.assertTrue(self.driver._is_cloneable(location)) def test_uncloneable_different_fsid(self): self.stubs.Set(self.driver, '_get_fsid', lambda: 'abc') location = 'rbd://def/pool/image/snap' self.assertFalse(self.driver._is_cloneable(location)) def test_uncloneable_unreadable(self): def fake_exc(*args): raise exception.ProcessExecutionError() self.stubs.Set(self.driver, '_get_fsid', lambda: 'abc') self.stubs.Set(self.driver, '_execute', fake_exc) location = 'rbd://abc/pool/image/snap' self.assertFalse(self.driver._is_cloneable(location)) def _copy_image(self): @contextlib.contextmanager def fake_temp_file(dir): class FakeTmp: def __init__(self, name): self.name = name yield FakeTmp('test') self.stubs.Set(tempfile, 'NamedTemporaryFile', fake_temp_file) self.stubs.Set(os.path, 'exists', lambda x: True) self.driver.copy_image_to_volume(None, {'name': 'test'}, FakeImageService(), None) def test_copy_image_no_volume_tmp(self): self.flags(volume_tmp_dir=None) self._copy_image() def test_copy_image_volume_tmp(self): self.flags(volume_tmp_dir='/var/run/cinder/tmp') self._copy_image()