Exemple #1
0
class TestClone(object):
    @require_features([RBD_FEATURE_LAYERING])
    def setUp(self):
        global ioctx
        global features
        self.rbd = RBD()
        create_image()
        self.image = Image(ioctx, IMG_NAME)
        data = rand_data(256)
        self.image.write(data, IMG_SIZE / 2)
        self.image.create_snap("snap1")
        global features
        self.image.protect_snap("snap1")
        self.rbd.clone(ioctx, IMG_NAME, "snap1", ioctx, "clone", features)
        self.clone = Image(ioctx, "clone")

    def tearDown(self):
        global ioctx
        self.clone.close()
        self.rbd.remove(ioctx, "clone")
        self.image.unprotect_snap("snap1")
        self.image.remove_snap("snap1")
        self.image.close()
        remove_image()

    def test_unprotected(self):
        self.image.create_snap("snap2")
        global features
        assert_raises(InvalidArgument, self.rbd.clone, ioctx, IMG_NAME, "snap2", ioctx, "clone2", features)
        self.image.remove_snap("snap2")

    def test_unprotect_with_children(self):
        global features
        # can't remove a snapshot that has dependent clones
        assert_raises(ImageBusy, self.image.remove_snap, "snap1")

        # validate parent info of clone created by TestClone.setUp
        (pool, image, snap) = self.clone.parent_info()
        eq(pool, "rbd")
        eq(image, IMG_NAME)
        eq(snap, "snap1")

        # create a new pool...
        rados.create_pool("rbd2")
        other_ioctx = rados.open_ioctx("rbd2")

        # ...with a clone of the same parent
        self.rbd.clone(ioctx, IMG_NAME, "snap1", other_ioctx, "other_clone", features)
        self.other_clone = Image(other_ioctx, "other_clone")
        # validate its parent info
        (pool, image, snap) = self.other_clone.parent_info()
        eq(pool, "rbd")
        eq(image, IMG_NAME)
        eq(snap, "snap1")

        # can't unprotect snap with children
        assert_raises(ImageBusy, self.image.unprotect_snap, "snap1")

        # 2 children, check that cannot remove the parent snap
        assert_raises(ImageBusy, self.image.remove_snap, "snap1")

        # close and remove other pool's clone
        self.other_clone.close()
        self.rbd.remove(other_ioctx, "other_clone")

        # check that we cannot yet remove the parent snap
        assert_raises(ImageBusy, self.image.remove_snap, "snap1")

        other_ioctx.close()
        rados.delete_pool("rbd2")

        # unprotect, remove parent snap happen in cleanup, and should succeed

    def test_stat(self):
        image_info = self.image.stat()
        clone_info = self.clone.stat()
        eq(clone_info["size"], image_info["size"])
        eq(clone_info["size"], self.clone.overlap())

    def test_resize_stat(self):
        self.clone.resize(IMG_SIZE / 2)
        image_info = self.image.stat()
        clone_info = self.clone.stat()
        eq(clone_info["size"], IMG_SIZE / 2)
        eq(image_info["size"], IMG_SIZE)
        eq(self.clone.overlap(), IMG_SIZE / 2)

        self.clone.resize(IMG_SIZE * 2)
        image_info = self.image.stat()
        clone_info = self.clone.stat()
        eq(clone_info["size"], IMG_SIZE * 2)
        eq(image_info["size"], IMG_SIZE)
        eq(self.clone.overlap(), IMG_SIZE / 2)

    def test_resize_io(self):
        parent_data = self.image.read(IMG_SIZE / 2, 256)
        self.clone.resize(IMG_SIZE / 2 + 128)
        child_data = self.clone.read(IMG_SIZE / 2, 128)
        eq(child_data, parent_data[:128])
        self.clone.resize(IMG_SIZE)
        child_data = self.clone.read(IMG_SIZE / 2, 256)
        eq(child_data, parent_data[:128] + ("\0" * 128))
        self.clone.resize(IMG_SIZE / 2 + 1)
        child_data = self.clone.read(IMG_SIZE / 2, 1)
        eq(child_data, parent_data[0])
        self.clone.resize(0)
        self.clone.resize(IMG_SIZE)
        child_data = self.clone.read(IMG_SIZE / 2, 256)
        eq(child_data, "\0" * 256)

    def test_read(self):
        parent_data = self.image.read(IMG_SIZE / 2, 256)
        child_data = self.clone.read(IMG_SIZE / 2, 256)
        eq(child_data, parent_data)

    def test_write(self):
        parent_data = self.image.read(IMG_SIZE / 2, 256)
        new_data = rand_data(256)
        self.clone.write(new_data, IMG_SIZE / 2 + 256)
        child_data = self.clone.read(IMG_SIZE / 2 + 256, 256)
        eq(child_data, new_data)
        child_data = self.clone.read(IMG_SIZE / 2, 256)
        eq(child_data, parent_data)
        parent_data = self.image.read(IMG_SIZE / 2 + 256, 256)
        eq(parent_data, "\0" * 256)

    def test_list_children(self):
        global ioctx
        global features
        self.image.set_snap("snap1")
        eq(self.image.list_children(), [("rbd", "clone")])
        self.clone.close()
        self.rbd.remove(ioctx, "clone")
        eq(self.image.list_children(), [])

        expected_children = []
        for i in xrange(10):
            self.rbd.clone(ioctx, IMG_NAME, "snap1", ioctx, "clone%d" % i, features)
            expected_children.append(("rbd", "clone%d" % i))
            eq(self.image.list_children(), expected_children)

        for i in xrange(10):
            self.rbd.remove(ioctx, "clone%d" % i)
            expected_children.pop(0)
            eq(self.image.list_children(), expected_children)

        eq(self.image.list_children(), [])
        self.rbd.clone(ioctx, IMG_NAME, "snap1", ioctx, "clone", features)
        eq(self.image.list_children(), [("rbd", "clone")])
        self.clone = Image(ioctx, "clone")

    def test_flatten_errors(self):
        # test that we can't flatten a non-clone
        assert_raises(InvalidArgument, self.image.flatten)

        # test that we can't flatten a snapshot
        self.clone.create_snap("snap2")
        self.clone.set_snap("snap2")
        assert_raises(ReadOnlyImage, self.clone.flatten)
        self.clone.remove_snap("snap2")

    def check_flatten_with_order(self, new_order):
        global ioctx
        global features
        self.rbd.clone(ioctx, IMG_NAME, "snap1", ioctx, "clone2", features, new_order)
        # with Image(ioctx, 'clone2') as clone:
        clone2 = Image(ioctx, "clone2")
        clone2.flatten()
        eq(clone2.overlap(), 0)
        clone2.close()
        self.rbd.remove(ioctx, "clone2")

        # flatten after resizing to non-block size
        self.rbd.clone(ioctx, IMG_NAME, "snap1", ioctx, "clone2", features, new_order)
        with Image(ioctx, "clone2") as clone:
            clone.resize(IMG_SIZE / 2 - 1)
            clone.flatten()
            eq(0, clone.overlap())
        self.rbd.remove(ioctx, "clone2")

        # flatten after resizing to non-block size
        self.rbd.clone(ioctx, IMG_NAME, "snap1", ioctx, "clone2", features, new_order)
        with Image(ioctx, "clone2") as clone:
            clone.resize(IMG_SIZE / 2 + 1)
            clone.flatten()
            eq(clone.overlap(), 0)
        self.rbd.remove(ioctx, "clone2")

    def test_flatten_basic(self):
        self.check_flatten_with_order(IMG_ORDER)

    def test_flatten_smaller_order(self):
        self.check_flatten_with_order(IMG_ORDER - 2)

    def test_flatten_larger_order(self):
        self.check_flatten_with_order(IMG_ORDER + 2)

    def test_flatten_drops_cache(self):
        global ioctx
        global features
        self.rbd.clone(ioctx, IMG_NAME, "snap1", ioctx, "clone2", features, IMG_ORDER)
        with Image(ioctx, "clone2") as clone:
            with Image(ioctx, "clone2") as clone2:
                # cache object non-existence
                data = clone.read(IMG_SIZE / 2, 256)
                clone2_data = clone2.read(IMG_SIZE / 2, 256)
                eq(data, clone2_data)
                clone.flatten()
                assert_raises(ImageNotFound, clone.parent_info)
                assert_raises(ImageNotFound, clone2.parent_info)
                after_flatten = clone.read(IMG_SIZE / 2, 256)
                eq(data, after_flatten)
                after_flatten = clone2.read(IMG_SIZE / 2, 256)
                eq(data, after_flatten)
        self.rbd.remove(ioctx, "clone2")
Exemple #2
0
class TestClone(object):
    @require_features([RBD_FEATURE_LAYERING])
    def setUp(self):
        global ioctx
        global features
        self.rbd = RBD()
        create_image()
        self.image = Image(ioctx, image_name)
        data = rand_data(256)
        self.image.write(data, IMG_SIZE // 2)
        self.image.create_snap('snap1')
        global features
        self.image.protect_snap('snap1')
        self.clone_name = get_temp_image_name()
        self.rbd.clone(ioctx, image_name, 'snap1', ioctx, self.clone_name,
                       features)
        self.clone = Image(ioctx, self.clone_name)

    def tearDown(self):
        global ioctx
        self.clone.close()
        self.rbd.remove(ioctx, self.clone_name)
        self.image.unprotect_snap('snap1')
        self.image.remove_snap('snap1')
        self.image.close()
        remove_image()

    @require_features([RBD_FEATURE_STRIPINGV2])
    def test_with_params(self):
        global features
        self.image.create_snap('snap2')
        self.image.protect_snap('snap2')
        clone_name2 = get_temp_image_name()
        self.rbd.clone(ioctx, image_name, 'snap2', ioctx, clone_name2,
                       features,
                       self.image.stat()['order'], self.image.stripe_unit(),
                       self.image.stripe_count())
        self.rbd.remove(ioctx, clone_name2)
        self.image.unprotect_snap('snap2')
        self.image.remove_snap('snap2')

    def test_unprotected(self):
        self.image.create_snap('snap2')
        global features
        clone_name2 = get_temp_image_name()
        assert_raises(InvalidArgument, self.rbd.clone, ioctx, image_name,
                      'snap2', ioctx, clone_name2, features)
        self.image.remove_snap('snap2')

    def test_unprotect_with_children(self):
        global features
        # can't remove a snapshot that has dependent clones
        assert_raises(ImageBusy, self.image.remove_snap, 'snap1')

        # validate parent info of clone created by TestClone.setUp
        (pool, image, snap) = self.clone.parent_info()
        eq(pool, pool_name)
        eq(image, image_name)
        eq(snap, 'snap1')

        # create a new pool...
        pool_name2 = get_temp_pool_name()
        rados.create_pool(pool_name2)
        other_ioctx = rados.open_ioctx(pool_name2)

        # ...with a clone of the same parent
        other_clone_name = get_temp_image_name()
        self.rbd.clone(ioctx, image_name, 'snap1', other_ioctx,
                       other_clone_name, features)
        self.other_clone = Image(other_ioctx, other_clone_name)
        # validate its parent info
        (pool, image, snap) = self.other_clone.parent_info()
        eq(pool, pool_name)
        eq(image, image_name)
        eq(snap, 'snap1')

        # can't unprotect snap with children
        assert_raises(ImageBusy, self.image.unprotect_snap, 'snap1')

        # 2 children, check that cannot remove the parent snap
        assert_raises(ImageBusy, self.image.remove_snap, 'snap1')

        # close and remove other pool's clone
        self.other_clone.close()
        self.rbd.remove(other_ioctx, other_clone_name)

        # check that we cannot yet remove the parent snap
        assert_raises(ImageBusy, self.image.remove_snap, 'snap1')

        other_ioctx.close()
        rados.delete_pool(pool_name2)

        # unprotect, remove parent snap happen in cleanup, and should succeed

    def test_stat(self):
        image_info = self.image.stat()
        clone_info = self.clone.stat()
        eq(clone_info['size'], image_info['size'])
        eq(clone_info['size'], self.clone.overlap())

    def test_resize_stat(self):
        self.clone.resize(IMG_SIZE // 2)
        image_info = self.image.stat()
        clone_info = self.clone.stat()
        eq(clone_info['size'], IMG_SIZE // 2)
        eq(image_info['size'], IMG_SIZE)
        eq(self.clone.overlap(), IMG_SIZE // 2)

        self.clone.resize(IMG_SIZE * 2)
        image_info = self.image.stat()
        clone_info = self.clone.stat()
        eq(clone_info['size'], IMG_SIZE * 2)
        eq(image_info['size'], IMG_SIZE)
        eq(self.clone.overlap(), IMG_SIZE // 2)

    def test_resize_io(self):
        parent_data = self.image.read(IMG_SIZE // 2, 256)
        self.image.resize(0)
        self.clone.resize(IMG_SIZE // 2 + 128)
        child_data = self.clone.read(IMG_SIZE // 2, 128)
        eq(child_data, parent_data[:128])
        self.clone.resize(IMG_SIZE)
        child_data = self.clone.read(IMG_SIZE // 2, 256)
        eq(child_data, parent_data[:128] + (b'\0' * 128))
        self.clone.resize(IMG_SIZE // 2 + 1)
        child_data = self.clone.read(IMG_SIZE // 2, 1)
        eq(child_data, parent_data[0:1])
        self.clone.resize(0)
        self.clone.resize(IMG_SIZE)
        child_data = self.clone.read(IMG_SIZE // 2, 256)
        eq(child_data, b'\0' * 256)

    def test_read(self):
        parent_data = self.image.read(IMG_SIZE // 2, 256)
        child_data = self.clone.read(IMG_SIZE // 2, 256)
        eq(child_data, parent_data)

    def test_write(self):
        parent_data = self.image.read(IMG_SIZE // 2, 256)
        new_data = rand_data(256)
        self.clone.write(new_data, IMG_SIZE // 2 + 256)
        child_data = self.clone.read(IMG_SIZE // 2 + 256, 256)
        eq(child_data, new_data)
        child_data = self.clone.read(IMG_SIZE // 2, 256)
        eq(child_data, parent_data)
        parent_data = self.image.read(IMG_SIZE // 2 + 256, 256)
        eq(parent_data, b'\0' * 256)

    def check_children(self, expected):
        actual = self.image.list_children()
        # dedup for cache pools until
        # http://tracker.ceph.com/issues/8187 is fixed
        deduped = set([(pool_name, image[1]) for image in actual])
        eq(deduped, set(expected))

    def test_list_children(self):
        global ioctx
        global features
        self.image.set_snap('snap1')
        self.check_children([(pool_name, self.clone_name)])
        self.clone.close()
        self.rbd.remove(ioctx, self.clone_name)
        eq(self.image.list_children(), [])

        clone_name = get_temp_image_name() + '_'
        expected_children = []
        for i in range(10):
            self.rbd.clone(ioctx, image_name, 'snap1', ioctx,
                           clone_name + str(i), features)
            expected_children.append((pool_name, clone_name + str(i)))
            self.check_children(expected_children)

        for i in range(10):
            self.rbd.remove(ioctx, clone_name + str(i))
            expected_children.pop(0)
            self.check_children(expected_children)

        eq(self.image.list_children(), [])
        self.rbd.clone(ioctx, image_name, 'snap1', ioctx, self.clone_name,
                       features)
        self.check_children([(pool_name, self.clone_name)])
        self.clone = Image(ioctx, self.clone_name)

    def test_flatten_errors(self):
        # test that we can't flatten a non-clone
        assert_raises(InvalidArgument, self.image.flatten)

        # test that we can't flatten a snapshot
        self.clone.create_snap('snap2')
        self.clone.set_snap('snap2')
        assert_raises(ReadOnlyImage, self.clone.flatten)
        self.clone.remove_snap('snap2')

    def check_flatten_with_order(self, new_order):
        global ioctx
        global features
        clone_name2 = get_temp_image_name()
        self.rbd.clone(ioctx, image_name, 'snap1', ioctx, clone_name2,
                       features, new_order)
        #with Image(ioctx, 'clone2') as clone:
        clone2 = Image(ioctx, clone_name2)
        clone2.flatten()
        eq(clone2.overlap(), 0)
        clone2.close()
        self.rbd.remove(ioctx, clone_name2)

        # flatten after resizing to non-block size
        self.rbd.clone(ioctx, image_name, 'snap1', ioctx, clone_name2,
                       features, new_order)
        with Image(ioctx, clone_name2) as clone:
            clone.resize(IMG_SIZE // 2 - 1)
            clone.flatten()
            eq(0, clone.overlap())
        self.rbd.remove(ioctx, clone_name2)

        # flatten after resizing to non-block size
        self.rbd.clone(ioctx, image_name, 'snap1', ioctx, clone_name2,
                       features, new_order)
        with Image(ioctx, clone_name2) as clone:
            clone.resize(IMG_SIZE // 2 + 1)
            clone.flatten()
            eq(clone.overlap(), 0)
        self.rbd.remove(ioctx, clone_name2)

    def test_flatten_basic(self):
        self.check_flatten_with_order(IMG_ORDER)

    def test_flatten_smaller_order(self):
        self.check_flatten_with_order(IMG_ORDER - 2)

    def test_flatten_larger_order(self):
        self.check_flatten_with_order(IMG_ORDER + 2)

    def test_flatten_drops_cache(self):
        global ioctx
        global features
        clone_name2 = get_temp_image_name()
        self.rbd.clone(ioctx, image_name, 'snap1', ioctx, clone_name2,
                       features, IMG_ORDER)
        with Image(ioctx, clone_name2) as clone:
            with Image(ioctx, clone_name2) as clone2:
                # cache object non-existence
                data = clone.read(IMG_SIZE // 2, 256)
                clone2_data = clone2.read(IMG_SIZE // 2, 256)
                eq(data, clone2_data)
                clone.flatten()
                assert_raises(ImageNotFound, clone.parent_info)
                assert_raises(ImageNotFound, clone2.parent_info)
                after_flatten = clone.read(IMG_SIZE // 2, 256)
                eq(data, after_flatten)
                after_flatten = clone2.read(IMG_SIZE // 2, 256)
                eq(data, after_flatten)
        self.rbd.remove(ioctx, clone_name2)

    def test_flatten_multi_level(self):
        self.clone.create_snap('snap2')
        self.clone.protect_snap('snap2')
        clone_name3 = get_temp_image_name()
        self.rbd.clone(ioctx, self.clone_name, 'snap2', ioctx, clone_name3,
                       features)
        self.clone.flatten()
        with Image(ioctx, clone_name3) as clone3:
            clone3.flatten()
        self.clone.unprotect_snap('snap2')
        self.clone.remove_snap('snap2')
        self.rbd.remove(ioctx, clone_name3)

    def test_resize_flatten_multi_level(self):
        self.clone.create_snap('snap2')
        self.clone.protect_snap('snap2')
        clone_name3 = get_temp_image_name()
        self.rbd.clone(ioctx, self.clone_name, 'snap2', ioctx, clone_name3,
                       features)
        self.clone.resize(1)
        orig_data = self.image.read(0, 256)
        with Image(ioctx, clone_name3) as clone3:
            clone3_data = clone3.read(0, 256)
            eq(orig_data, clone3_data)
        self.clone.flatten()
        with Image(ioctx, clone_name3) as clone3:
            clone3_data = clone3.read(0, 256)
            eq(orig_data, clone3_data)
        self.rbd.remove(ioctx, clone_name3)
        self.clone.unprotect_snap('snap2')
        self.clone.remove_snap('snap2')
Exemple #3
0
class TestClone(object):

    @require_features([RBD_FEATURE_LAYERING])
    def setUp(self):
        global ioctx
        global features
        self.rbd = RBD()
        create_image()
        self.image = Image(ioctx, image_name)
        data = rand_data(256)
        self.image.write(data, IMG_SIZE / 2)
        self.image.create_snap('snap1')
        global features
        self.image.protect_snap('snap1')
        self.clone_name = get_temp_image_name()
        self.rbd.clone(ioctx, image_name, 'snap1', ioctx, self.clone_name,
                       features)
        self.clone = Image(ioctx, self.clone_name)

    def tearDown(self):
        global ioctx
        self.clone.close()
        self.rbd.remove(ioctx, self.clone_name)
        self.image.unprotect_snap('snap1')
        self.image.remove_snap('snap1')
        self.image.close()
        remove_image()

    def test_unprotected(self):
        self.image.create_snap('snap2')
        global features
        clone_name2 = get_temp_image_name()
        assert_raises(InvalidArgument, self.rbd.clone, ioctx, image_name,
                      'snap2', ioctx, clone_name2, features)
        self.image.remove_snap('snap2')

    def test_unprotect_with_children(self):
        global features
        # can't remove a snapshot that has dependent clones
        assert_raises(ImageBusy, self.image.remove_snap, 'snap1')

        # validate parent info of clone created by TestClone.setUp
        (pool, image, snap) = self.clone.parent_info()
        eq(pool, pool_name)
        eq(image, image_name)
        eq(snap, 'snap1')

        # create a new pool...
        pool_name2 = get_temp_pool_name()
        rados.create_pool(pool_name2)
        other_ioctx = rados.open_ioctx(pool_name2)

        # ...with a clone of the same parent
        other_clone_name = get_temp_image_name()
        self.rbd.clone(ioctx, image_name, 'snap1', other_ioctx,
                       other_clone_name, features)
        self.other_clone = Image(other_ioctx, other_clone_name)
        # validate its parent info
        (pool, image, snap) = self.other_clone.parent_info()
        eq(pool, pool_name)
        eq(image, image_name)
        eq(snap, 'snap1')

        # can't unprotect snap with children
        assert_raises(ImageBusy, self.image.unprotect_snap, 'snap1')

        # 2 children, check that cannot remove the parent snap
        assert_raises(ImageBusy, self.image.remove_snap, 'snap1')

        # close and remove other pool's clone
        self.other_clone.close()
        self.rbd.remove(other_ioctx, other_clone_name)

        # check that we cannot yet remove the parent snap
        assert_raises(ImageBusy, self.image.remove_snap, 'snap1')

        other_ioctx.close()
        rados.delete_pool(pool_name2)

        # unprotect, remove parent snap happen in cleanup, and should succeed

    def test_stat(self):
        image_info = self.image.stat()
        clone_info = self.clone.stat()
        eq(clone_info['size'], image_info['size'])
        eq(clone_info['size'], self.clone.overlap())

    def test_resize_stat(self):
        self.clone.resize(IMG_SIZE / 2)
        image_info = self.image.stat()
        clone_info = self.clone.stat()
        eq(clone_info['size'], IMG_SIZE / 2)
        eq(image_info['size'], IMG_SIZE)
        eq(self.clone.overlap(), IMG_SIZE / 2)

        self.clone.resize(IMG_SIZE * 2)
        image_info = self.image.stat()
        clone_info = self.clone.stat()
        eq(clone_info['size'], IMG_SIZE * 2)
        eq(image_info['size'], IMG_SIZE)
        eq(self.clone.overlap(), IMG_SIZE / 2)

    def test_resize_io(self):
        parent_data = self.image.read(IMG_SIZE / 2, 256)
        self.image.resize(0)
        self.clone.resize(IMG_SIZE / 2 + 128)
        child_data = self.clone.read(IMG_SIZE / 2, 128)
        eq(child_data, parent_data[:128])
        self.clone.resize(IMG_SIZE)
        child_data = self.clone.read(IMG_SIZE / 2, 256)
        eq(child_data, parent_data[:128] + ('\0' * 128))
        self.clone.resize(IMG_SIZE / 2 + 1)
        child_data = self.clone.read(IMG_SIZE / 2, 1)
        eq(child_data, parent_data[0])
        self.clone.resize(0)
        self.clone.resize(IMG_SIZE)
        child_data = self.clone.read(IMG_SIZE / 2, 256)
        eq(child_data, '\0' * 256)

    def test_read(self):
        parent_data = self.image.read(IMG_SIZE / 2, 256)
        child_data = self.clone.read(IMG_SIZE / 2, 256)
        eq(child_data, parent_data)

    def test_write(self):
        parent_data = self.image.read(IMG_SIZE / 2, 256)
        new_data = rand_data(256)
        self.clone.write(new_data, IMG_SIZE / 2 + 256)
        child_data = self.clone.read(IMG_SIZE / 2 + 256, 256)
        eq(child_data, new_data)
        child_data = self.clone.read(IMG_SIZE / 2, 256)
        eq(child_data, parent_data)
        parent_data = self.image.read(IMG_SIZE / 2 + 256, 256)
        eq(parent_data, '\0' * 256)

    def check_children(self, expected):
        actual = self.image.list_children()
        # dedup for cache pools until
        # http://tracker.ceph.com/issues/8187 is fixed
        deduped = set([(pool_name, image[1]) for image in actual])
        eq(deduped, set(expected))

    def test_list_children(self):
        global ioctx
        global features
        self.image.set_snap('snap1')
        self.check_children([(pool_name, self.clone_name)])
        self.clone.close()
        self.rbd.remove(ioctx, self.clone_name)
        eq(self.image.list_children(), [])

        clone_name = get_temp_image_name() + '_'
        expected_children = []
        for i in xrange(10):
            self.rbd.clone(ioctx, image_name, 'snap1', ioctx,
                           clone_name + str(i), features)
            expected_children.append((pool_name, clone_name + str(i)))
            self.check_children(expected_children)

        for i in xrange(10):
            self.rbd.remove(ioctx, clone_name + str(i))
            expected_children.pop(0)
            self.check_children(expected_children)

        eq(self.image.list_children(), [])
        self.rbd.clone(ioctx, image_name, 'snap1', ioctx, self.clone_name,
                       features)
        self.check_children([(pool_name, self.clone_name)])
        self.clone = Image(ioctx, self.clone_name)

    def test_flatten_errors(self):
        # test that we can't flatten a non-clone
        assert_raises(InvalidArgument, self.image.flatten)

        # test that we can't flatten a snapshot
        self.clone.create_snap('snap2')
        self.clone.set_snap('snap2')
        assert_raises(ReadOnlyImage, self.clone.flatten)
        self.clone.remove_snap('snap2')

    def check_flatten_with_order(self, new_order):
        global ioctx
        global features
        clone_name2 = get_temp_image_name()
        self.rbd.clone(ioctx, image_name, 'snap1', ioctx, clone_name2,
                       features, new_order)
        #with Image(ioctx, 'clone2') as clone:
        clone2 = Image(ioctx, clone_name2)
        clone2.flatten()
        eq(clone2.overlap(), 0)
        clone2.close()
        self.rbd.remove(ioctx, clone_name2)

        # flatten after resizing to non-block size
        self.rbd.clone(ioctx, image_name, 'snap1', ioctx, clone_name2,
                       features, new_order)
        with Image(ioctx, clone_name2) as clone:
            clone.resize(IMG_SIZE / 2 - 1)
            clone.flatten()
            eq(0, clone.overlap())
        self.rbd.remove(ioctx, clone_name2)

        # flatten after resizing to non-block size
        self.rbd.clone(ioctx, image_name, 'snap1', ioctx, clone_name2,
                       features, new_order)
        with Image(ioctx, clone_name2) as clone:
            clone.resize(IMG_SIZE / 2 + 1)
            clone.flatten()
            eq(clone.overlap(), 0)
        self.rbd.remove(ioctx, clone_name2)

    def test_flatten_basic(self):
        self.check_flatten_with_order(IMG_ORDER)

    def test_flatten_smaller_order(self):
        self.check_flatten_with_order(IMG_ORDER - 2)

    def test_flatten_larger_order(self):
        self.check_flatten_with_order(IMG_ORDER + 2)

    def test_flatten_drops_cache(self):
        global ioctx
        global features
        clone_name2 = get_temp_image_name()
        self.rbd.clone(ioctx, image_name, 'snap1', ioctx, clone_name2,
                       features, IMG_ORDER)
        with Image(ioctx, clone_name2) as clone:
            with Image(ioctx, clone_name2) as clone2:
                # cache object non-existence
                data = clone.read(IMG_SIZE / 2, 256)
                clone2_data = clone2.read(IMG_SIZE / 2, 256)
                eq(data, clone2_data)
                clone.flatten()
                assert_raises(ImageNotFound, clone.parent_info)
                assert_raises(ImageNotFound, clone2.parent_info)
                after_flatten = clone.read(IMG_SIZE / 2, 256)
                eq(data, after_flatten)
                after_flatten = clone2.read(IMG_SIZE / 2, 256)
                eq(data, after_flatten)
        self.rbd.remove(ioctx, clone_name2)

    def test_flatten_multi_level(self):
        self.clone.create_snap('snap2')
        self.clone.protect_snap('snap2')
        clone_name3 = get_temp_image_name()
        self.rbd.clone(ioctx, self.clone_name, 'snap2', ioctx, clone_name3,
                       features)
        self.clone.flatten()
        with Image(ioctx, clone_name3) as clone3:
            clone3.flatten()
        self.clone.unprotect_snap('snap2')
        self.clone.remove_snap('snap2')
        self.rbd.remove(ioctx, clone_name3)

    def test_resize_flatten_multi_level(self):
        self.clone.create_snap('snap2')
        self.clone.protect_snap('snap2')
        clone_name3 = get_temp_image_name()
        self.rbd.clone(ioctx, self.clone_name, 'snap2', ioctx, clone_name3,
                       features)
        self.clone.resize(1)
        orig_data = self.image.read(0, 256)
        with Image(ioctx, clone_name3) as clone3:
            clone3_data = clone3.read(0, 256)
            eq(orig_data, clone3_data)
        self.clone.flatten()
        with Image(ioctx, clone_name3) as clone3:
            clone3_data = clone3.read(0, 256)
            eq(orig_data, clone3_data)
        self.rbd.remove(ioctx, clone_name3)
        self.clone.unprotect_snap('snap2')
        self.clone.remove_snap('snap2')
Exemple #4
0
class TestClone(object):

    @require_features([RBD_FEATURE_LAYERING])
    def setUp(self):
        global ioctx
        global features
        self.rbd = RBD()
        create_image()
        self.image = Image(ioctx, IMG_NAME)
        data = rand_data(256)
        self.image.write(data, IMG_SIZE / 2)
        self.image.create_snap('snap1')
        global features
        self.image.protect_snap('snap1')
        self.rbd.clone(ioctx, IMG_NAME, 'snap1', ioctx, 'clone', features)
        self.clone = Image(ioctx, 'clone')

    def tearDown(self):
        global ioctx
        self.clone.close()
        self.rbd.remove(ioctx, 'clone')
        self.image.unprotect_snap('snap1')
        self.image.remove_snap('snap1')
        self.image.close()
        remove_image()

    def test_unprotected(self):
        self.image.create_snap('snap2')
        global features
        assert_raises(InvalidArgument, self.rbd.clone, ioctx, IMG_NAME, 'snap2', ioctx, 'clone2', features)
        self.image.remove_snap('snap2')

    def test_unprotect_with_children(self):
        global features
        # can't remove a snapshot that has dependent clones
        assert_raises(ImageBusy, self.image.remove_snap, 'snap1')

        # validate parent info of clone created by TestClone.setUp
        (pool, image, snap) = self.clone.parent_info()
        eq(pool, 'rbd')
        eq(image, IMG_NAME)
        eq(snap, 'snap1')

        # create a new pool...
        rados.create_pool('rbd2')
        other_ioctx = rados.open_ioctx('rbd2')

        # ...with a clone of the same parent
        self.rbd.clone(ioctx, IMG_NAME, 'snap1', other_ioctx, 'other_clone', features)
        self.other_clone = Image(other_ioctx, 'other_clone')
        # validate its parent info
        (pool, image, snap) = self.other_clone.parent_info()
        eq(pool, 'rbd')
        eq(image, IMG_NAME)
        eq(snap, 'snap1')

        # can't unprotect snap with children
        assert_raises(ImageBusy, self.image.unprotect_snap, 'snap1')

        # 2 children, check that cannot remove the parent snap
        assert_raises(ImageBusy, self.image.remove_snap, 'snap1')

        # close and remove other pool's clone
        self.other_clone.close()
        self.rbd.remove(other_ioctx, 'other_clone')

        # check that we cannot yet remove the parent snap
        assert_raises(ImageBusy, self.image.remove_snap, 'snap1')

        other_ioctx.close()
        rados.delete_pool('rbd2')

        # unprotect, remove parent snap happen in cleanup, and should succeed

    def test_stat(self):
        image_info = self.image.stat()
        clone_info = self.clone.stat()
        eq(clone_info['size'], image_info['size'])
        eq(clone_info['size'], self.clone.overlap())

    def test_resize_stat(self):
        self.clone.resize(IMG_SIZE / 2)
        image_info = self.image.stat()
        clone_info = self.clone.stat()
        eq(clone_info['size'], IMG_SIZE / 2)
        eq(image_info['size'], IMG_SIZE)
        eq(self.clone.overlap(), IMG_SIZE / 2)

        self.clone.resize(IMG_SIZE * 2)
        image_info = self.image.stat()
        clone_info = self.clone.stat()
        eq(clone_info['size'], IMG_SIZE * 2)
        eq(image_info['size'], IMG_SIZE)
        eq(self.clone.overlap(), IMG_SIZE / 2)

    def test_resize_io(self):
        parent_data = self.image.read(IMG_SIZE / 2, 256)
        self.clone.resize(IMG_SIZE / 2 + 128)
        child_data = self.clone.read(IMG_SIZE / 2, 128)
        eq(child_data, parent_data[:128])
        self.clone.resize(IMG_SIZE)
        child_data = self.clone.read(IMG_SIZE / 2, 256)
        eq(child_data, parent_data[:128] + ('\0' * 128))
        self.clone.resize(IMG_SIZE / 2 + 1)
        child_data = self.clone.read(IMG_SIZE / 2, 1)
        eq(child_data, parent_data[0])
        self.clone.resize(0)
        self.clone.resize(IMG_SIZE)
        child_data = self.clone.read(IMG_SIZE / 2, 256)
        eq(child_data, '\0' * 256)

    def test_read(self):
        parent_data = self.image.read(IMG_SIZE / 2, 256)
        child_data = self.clone.read(IMG_SIZE / 2, 256)
        eq(child_data, parent_data)

    def test_write(self):
        parent_data = self.image.read(IMG_SIZE / 2, 256)
        new_data = rand_data(256)
        self.clone.write(new_data, IMG_SIZE / 2 + 256)
        child_data = self.clone.read(IMG_SIZE / 2 + 256, 256)
        eq(child_data, new_data)
        child_data = self.clone.read(IMG_SIZE / 2, 256)
        eq(child_data, parent_data)
        parent_data = self.image.read(IMG_SIZE / 2 + 256, 256)
        eq(parent_data, '\0' * 256)

    def test_list_children(self):
        global ioctx
        global features
        self.image.set_snap('snap1')
        eq(self.image.list_children(), [('rbd', 'clone')])
        self.rbd.remove(ioctx, 'clone')
        eq(self.image.list_children(), [])

        expected_children = []
        for i in xrange(10):
            self.rbd.clone(ioctx, IMG_NAME, 'snap1', ioctx, 'clone%d' % i, features)
            expected_children.append(('rbd', 'clone%d' % i))
            eq(self.image.list_children(), expected_children)

        for i in xrange(10):
            self.rbd.remove(ioctx, 'clone%d' % i)
            expected_children.pop(0)
            eq(self.image.list_children(), expected_children)

        eq(self.image.list_children(), [])
        self.rbd.clone(ioctx, IMG_NAME, 'snap1', ioctx, 'clone', features)
        eq(self.image.list_children(), [('rbd', 'clone')])
Exemple #5
0
class TestClone(object):
    @require_features([RBD_FEATURE_LAYERING])
    def setUp(self):
        global ioctx
        global features
        self.rbd = RBD()
        create_image()
        self.image = Image(ioctx, IMG_NAME)
        data = rand_data(256)
        self.image.write(data, IMG_SIZE / 2)
        self.image.create_snap('snap1')
        global features
        self.image.protect_snap('snap1')
        self.rbd.clone(ioctx, IMG_NAME, 'snap1', ioctx, 'clone', features)
        self.clone = Image(ioctx, 'clone')

    def tearDown(self):
        global ioctx
        self.clone.close()
        self.rbd.remove(ioctx, 'clone')
        self.image.unprotect_snap('snap1')
        self.image.remove_snap('snap1')
        self.image.close()
        remove_image()

    def test_unprotected(self):
        self.image.create_snap('snap2')
        global features
        assert_raises(InvalidArgument, self.rbd.clone, ioctx, IMG_NAME,
                      'snap2', ioctx, 'clone2', features)
        self.image.remove_snap('snap2')

    def test_unprotect_with_children(self):
        global features
        # can't remove a snapshot that has dependent clones
        assert_raises(ImageBusy, self.image.remove_snap, 'snap1')

        # validate parent info of clone created by TestClone.setUp
        (pool, image, snap) = self.clone.parent_info()
        eq(pool, 'rbd')
        eq(image, IMG_NAME)
        eq(snap, 'snap1')

        # create a new pool...
        rados.create_pool('rbd2')
        other_ioctx = rados.open_ioctx('rbd2')

        # ...with a clone of the same parent
        self.rbd.clone(ioctx, IMG_NAME, 'snap1', other_ioctx, 'other_clone',
                       features)
        self.other_clone = Image(other_ioctx, 'other_clone')
        # validate its parent info
        (pool, image, snap) = self.other_clone.parent_info()
        eq(pool, 'rbd')
        eq(image, IMG_NAME)
        eq(snap, 'snap1')

        # 2 children, check that cannot remove the parent snap
        assert_raises(ImageBusy, self.image.remove_snap, 'snap1')

        # close and remove other pool's clone
        self.other_clone.close()
        self.rbd.remove(other_ioctx, 'other_clone')

        # check that we cannot yet remove the parent snap
        assert_raises(ImageBusy, self.image.remove_snap, 'snap1')

        other_ioctx.close()
        rados.delete_pool('rbd2')

        # unprotect, remove parent snap happen in cleanup, and should succeed

    def test_stat(self):
        image_info = self.image.stat()
        clone_info = self.clone.stat()
        eq(clone_info['size'], image_info['size'])
        eq(clone_info['size'], self.clone.overlap())

    def test_resize_stat(self):
        self.clone.resize(IMG_SIZE / 2)
        image_info = self.image.stat()
        clone_info = self.clone.stat()
        eq(clone_info['size'], IMG_SIZE / 2)
        eq(image_info['size'], IMG_SIZE)
        eq(self.clone.overlap(), IMG_SIZE / 2)

        self.clone.resize(IMG_SIZE * 2)
        image_info = self.image.stat()
        clone_info = self.clone.stat()
        eq(clone_info['size'], IMG_SIZE * 2)
        eq(image_info['size'], IMG_SIZE)
        eq(self.clone.overlap(), IMG_SIZE / 2)

    def test_resize_io(self):
        parent_data = self.image.read(IMG_SIZE / 2, 256)
        self.clone.resize(IMG_SIZE / 2 + 128)
        child_data = self.clone.read(IMG_SIZE / 2, 128)
        eq(child_data, parent_data[:128])
        self.clone.resize(IMG_SIZE)
        child_data = self.clone.read(IMG_SIZE / 2, 256)
        eq(child_data, parent_data[:128] + ('\0' * 128))
        self.clone.resize(IMG_SIZE / 2 + 1)
        child_data = self.clone.read(IMG_SIZE / 2, 1)
        eq(child_data, parent_data[0])
        self.clone.resize(0)
        self.clone.resize(IMG_SIZE)
        child_data = self.clone.read(IMG_SIZE / 2, 256)
        eq(child_data, '\0' * 256)

    def test_read(self):
        parent_data = self.image.read(IMG_SIZE / 2, 256)
        child_data = self.clone.read(IMG_SIZE / 2, 256)
        eq(child_data, parent_data)

    def test_write(self):
        parent_data = self.image.read(IMG_SIZE / 2, 256)
        new_data = rand_data(256)
        self.clone.write(new_data, IMG_SIZE / 2 + 256)
        child_data = self.clone.read(IMG_SIZE / 2 + 256, 256)
        eq(child_data, new_data)
        child_data = self.clone.read(IMG_SIZE / 2, 256)
        eq(child_data, parent_data)
        parent_data = self.image.read(IMG_SIZE / 2 + 256, 256)
        eq(parent_data, '\0' * 256)

    def test_list_children(self):
        global ioctx
        global features
        self.image.set_snap('snap1')
        eq(self.image.list_children(), [('rbd', 'clone')])
        self.rbd.remove(ioctx, 'clone')
        eq(self.image.list_children(), [])

        expected_children = []
        for i in xrange(10):
            self.rbd.clone(ioctx, IMG_NAME, 'snap1', ioctx, 'clone%d' % i,
                           features)
            expected_children.append(('rbd', 'clone%d' % i))
            eq(self.image.list_children(), expected_children)

        for i in xrange(10):
            self.rbd.remove(ioctx, 'clone%d' % i)
            expected_children.pop(0)
            eq(self.image.list_children(), expected_children)

        eq(self.image.list_children(), [])
        self.rbd.clone(ioctx, IMG_NAME, 'snap1', ioctx, 'clone', features)
        eq(self.image.list_children(), [('rbd', 'clone')])
Exemple #6
0
class TestClone(object):
    @require_features([RBD_FEATURE_LAYERING])
    def setUp(self):
        global ioctx
        global features
        self.rbd = RBD()
        create_image()
        self.image = Image(ioctx, IMG_NAME)
        data = rand_data(256)
        self.image.write(data, IMG_SIZE / 2)
        self.image.create_snap('snap1')
        global features
        self.image.protect_snap('snap1')
        self.rbd.clone(ioctx, IMG_NAME, 'snap1', ioctx, 'clone', features)
        self.clone = Image(ioctx, 'clone')

    def tearDown(self):
        global ioctx
        self.clone.close()
        self.rbd.remove(ioctx, 'clone')
        self.image.unprotect_snap('snap1')
        self.image.remove_snap('snap1')
        self.image.close()
        remove_image()

    def test_unprotected(self):
        self.image.create_snap('snap2')
        global features
        assert_raises(InvalidArgument, self.rbd.clone, ioctx, IMG_NAME,
                      'snap2', ioctx, 'clone2', features)
        self.image.remove_snap('snap2')

    def test_unprotect_with_children(self):
        global features
        # can't remove a snapshot that has dependent clones
        assert_raises(ImageBusy, self.image.remove_snap, 'snap1')

        # validate parent info of clone created by TestClone.setUp
        (pool, image, snap) = self.clone.parent_info()
        eq(pool, 'rbd')
        eq(image, IMG_NAME)
        eq(snap, 'snap1')

        # create a new pool...
        rados.create_pool('rbd2')
        other_ioctx = rados.open_ioctx('rbd2')

        # ...with a clone of the same parent
        self.rbd.clone(ioctx, IMG_NAME, 'snap1', other_ioctx, 'other_clone',
                       features)
        self.other_clone = Image(other_ioctx, 'other_clone')
        # validate its parent info
        (pool, image, snap) = self.other_clone.parent_info()
        eq(pool, 'rbd')
        eq(image, IMG_NAME)
        eq(snap, 'snap1')

        # can't unprotect snap with children
        assert_raises(ImageBusy, self.image.unprotect_snap, 'snap1')

        # 2 children, check that cannot remove the parent snap
        assert_raises(ImageBusy, self.image.remove_snap, 'snap1')

        # close and remove other pool's clone
        self.other_clone.close()
        self.rbd.remove(other_ioctx, 'other_clone')

        # check that we cannot yet remove the parent snap
        assert_raises(ImageBusy, self.image.remove_snap, 'snap1')

        other_ioctx.close()
        rados.delete_pool('rbd2')

        # unprotect, remove parent snap happen in cleanup, and should succeed

    def test_stat(self):
        image_info = self.image.stat()
        clone_info = self.clone.stat()
        eq(clone_info['size'], image_info['size'])
        eq(clone_info['size'], self.clone.overlap())

    def test_resize_stat(self):
        self.clone.resize(IMG_SIZE / 2)
        image_info = self.image.stat()
        clone_info = self.clone.stat()
        eq(clone_info['size'], IMG_SIZE / 2)
        eq(image_info['size'], IMG_SIZE)
        eq(self.clone.overlap(), IMG_SIZE / 2)

        self.clone.resize(IMG_SIZE * 2)
        image_info = self.image.stat()
        clone_info = self.clone.stat()
        eq(clone_info['size'], IMG_SIZE * 2)
        eq(image_info['size'], IMG_SIZE)
        eq(self.clone.overlap(), IMG_SIZE / 2)

    def test_resize_io(self):
        parent_data = self.image.read(IMG_SIZE / 2, 256)
        self.clone.resize(IMG_SIZE / 2 + 128)
        child_data = self.clone.read(IMG_SIZE / 2, 128)
        eq(child_data, parent_data[:128])
        self.clone.resize(IMG_SIZE)
        child_data = self.clone.read(IMG_SIZE / 2, 256)
        eq(child_data, parent_data[:128] + ('\0' * 128))
        self.clone.resize(IMG_SIZE / 2 + 1)
        child_data = self.clone.read(IMG_SIZE / 2, 1)
        eq(child_data, parent_data[0])
        self.clone.resize(0)
        self.clone.resize(IMG_SIZE)
        child_data = self.clone.read(IMG_SIZE / 2, 256)
        eq(child_data, '\0' * 256)

    def test_read(self):
        parent_data = self.image.read(IMG_SIZE / 2, 256)
        child_data = self.clone.read(IMG_SIZE / 2, 256)
        eq(child_data, parent_data)

    def test_write(self):
        parent_data = self.image.read(IMG_SIZE / 2, 256)
        new_data = rand_data(256)
        self.clone.write(new_data, IMG_SIZE / 2 + 256)
        child_data = self.clone.read(IMG_SIZE / 2 + 256, 256)
        eq(child_data, new_data)
        child_data = self.clone.read(IMG_SIZE / 2, 256)
        eq(child_data, parent_data)
        parent_data = self.image.read(IMG_SIZE / 2 + 256, 256)
        eq(parent_data, '\0' * 256)

    def test_list_children(self):
        global ioctx
        global features
        self.image.set_snap('snap1')
        eq(self.image.list_children(), [('rbd', 'clone')])
        self.clone.close()
        self.rbd.remove(ioctx, 'clone')
        eq(self.image.list_children(), [])

        expected_children = []
        for i in xrange(10):
            self.rbd.clone(ioctx, IMG_NAME, 'snap1', ioctx, 'clone%d' % i,
                           features)
            expected_children.append(('rbd', 'clone%d' % i))
            eq(self.image.list_children(), expected_children)

        for i in xrange(10):
            self.rbd.remove(ioctx, 'clone%d' % i)
            expected_children.pop(0)
            eq(self.image.list_children(), expected_children)

        eq(self.image.list_children(), [])
        self.rbd.clone(ioctx, IMG_NAME, 'snap1', ioctx, 'clone', features)
        eq(self.image.list_children(), [('rbd', 'clone')])
        self.clone = Image(ioctx, 'clone')

    def test_flatten_errors(self):
        # test that we can't flatten a non-clone
        assert_raises(InvalidArgument, self.image.flatten)

        # test that we can't flatten a snapshot
        self.clone.create_snap('snap2')
        self.clone.set_snap('snap2')
        assert_raises(ReadOnlyImage, self.clone.flatten)
        self.clone.remove_snap('snap2')

    def check_flatten_with_order(self, new_order):
        global ioctx
        global features
        self.rbd.clone(ioctx, IMG_NAME, 'snap1', ioctx, 'clone2', features,
                       new_order)
        #with Image(ioctx, 'clone2') as clone:
        clone2 = Image(ioctx, 'clone2')
        clone2.flatten()
        eq(clone2.overlap(), 0)
        clone2.close()
        self.rbd.remove(ioctx, 'clone2')

        # flatten after resizing to non-block size
        self.rbd.clone(ioctx, IMG_NAME, 'snap1', ioctx, 'clone2', features,
                       new_order)
        with Image(ioctx, 'clone2') as clone:
            clone.resize(IMG_SIZE / 2 - 1)
            clone.flatten()
            eq(0, clone.overlap())
        self.rbd.remove(ioctx, 'clone2')

        # flatten after resizing to non-block size
        self.rbd.clone(ioctx, IMG_NAME, 'snap1', ioctx, 'clone2', features,
                       new_order)
        with Image(ioctx, 'clone2') as clone:
            clone.resize(IMG_SIZE / 2 + 1)
            clone.flatten()
            eq(clone.overlap(), 0)
        self.rbd.remove(ioctx, 'clone2')

    def test_flatten_basic(self):
        self.check_flatten_with_order(IMG_ORDER)

    def test_flatten_smaller_order(self):
        self.check_flatten_with_order(IMG_ORDER - 2)

    def test_flatten_larger_order(self):
        self.check_flatten_with_order(IMG_ORDER + 2)

    def test_flatten_drops_cache(self):
        global ioctx
        global features
        self.rbd.clone(ioctx, IMG_NAME, 'snap1', ioctx, 'clone2', features,
                       IMG_ORDER)
        with Image(ioctx, 'clone2') as clone:
            with Image(ioctx, 'clone2') as clone2:
                # cache object non-existence
                data = clone.read(IMG_SIZE / 2, 256)
                clone2_data = clone2.read(IMG_SIZE / 2, 256)
                eq(data, clone2_data)
                clone.flatten()
                assert_raises(ImageNotFound, clone.parent_info)
                assert_raises(ImageNotFound, clone2.parent_info)
                after_flatten = clone.read(IMG_SIZE / 2, 256)
                eq(data, after_flatten)
                after_flatten = clone2.read(IMG_SIZE / 2, 256)
                eq(data, after_flatten)
        self.rbd.remove(ioctx, 'clone2')