Exemplo n.º 1
0
    def setUp(self):
        super(RBDTestCase, self).setUp()

        def fake_execute(*args):
            pass

        self.driver = RBDDriver(execute=fake_execute)
Exemplo n.º 2
0
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))
Exemplo n.º 3
0
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))
Exemplo n.º 4
0
    def setUp(self):
        super(RBDTestCase, self).setUp()

        def fake_execute(*args):
            pass
        self.driver = RBDDriver(execute=fake_execute)
Exemplo n.º 5
0
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()