From b5bdd6d53e03b0bc0fac1be981f581a3797980f0 Mon Sep 17 00:00:00 2001 From: runsisi Date: Mon, 19 Jun 2017 11:29:31 +0800 Subject: [PATCH] test/unittest_rbd: add unit tests for image create timestamp Signed-off-by: runsisi --- src/test/cls_rbd/test_cls_rbd.cc | 15 +++++++++++ src/test/librbd/test_librbd.cc | 43 ++++++++++++++++++++++++++++++++ src/test/pybind/test_rbd.py | 5 ++++ 3 files changed, 63 insertions(+) diff --git a/src/test/cls_rbd/test_cls_rbd.cc b/src/test/cls_rbd/test_cls_rbd.cc index 6d0cc44ad55..186020024e9 100644 --- a/src/test/cls_rbd/test_cls_rbd.cc +++ b/src/test/cls_rbd/test_cls_rbd.cc @@ -421,6 +421,21 @@ TEST_F(TestClsRbd, get_object_prefix) ioctx.close(); } +TEST_F(TestClsRbd, get_create_timestamp) +{ + librados::IoCtx ioctx; + ASSERT_EQ(0, _rados.ioctx_create(_pool_name.c_str(), ioctx)); + + string oid = get_temp_image_name(); + ASSERT_EQ(0, create_image(&ioctx, oid, 0, 22, 0, oid, -1)); + + utime_t timestamp; + ASSERT_EQ(0, get_create_timestamp(&ioctx, oid, ×tamp)); + ASSERT_LT(0, timestamp.tv.tv_sec); + + ioctx.close(); +} + TEST_F(TestClsRbd, get_data_pool) { librados::IoCtx ioctx; diff --git a/src/test/librbd/test_librbd.cc b/src/test/librbd/test_librbd.cc index 17ebcd7e1a3..99354e93951 100644 --- a/src/test/librbd/test_librbd.cc +++ b/src/test/librbd/test_librbd.cc @@ -448,6 +448,49 @@ TEST_F(TestLibRBD, GetBlockNamePrefixPP) ASSERT_LT(0U, image.get_block_name_prefix().size()); } +TEST_F(TestLibRBD, TestGetCreateTimestamp) +{ + REQUIRE_FORMAT_V2(); + + rados_ioctx_t ioctx; + ASSERT_EQ(0, rados_ioctx_create(_cluster, m_pool_name.c_str(), &ioctx)); + + rbd_image_t image; + int order = 0; + std::string name = get_temp_image_name(); + + ASSERT_EQ(0, create_image(ioctx, name.c_str(), 0, &order)); + ASSERT_EQ(0, rbd_open(ioctx, name.c_str(), &image, NULL)); + + struct timespec timestamp; + ASSERT_EQ(0, rbd_get_create_timestamp(image, ×tamp)); + ASSERT_LT(0, timestamp.tv_sec); + + ASSERT_EQ(0, rbd_close(image)); + + rados_ioctx_destroy(ioctx); +} + +TEST_F(TestLibRBD, GetCreateTimestampPP) +{ + REQUIRE_FORMAT_V2(); + + librados::IoCtx ioctx; + ASSERT_EQ(0, _rados.ioctx_create(m_pool_name.c_str(), ioctx)); + + librbd::RBD rbd; + librbd::Image image; + int order = 0; + std::string name = get_temp_image_name(); + + ASSERT_EQ(0, create_image_pp(rbd, ioctx, name.c_str(), 0, &order)); + ASSERT_EQ(0, rbd.open(ioctx, image, name.c_str(), NULL)); + + struct timespec timestamp; + ASSERT_EQ(0, image.get_create_timestamp(×tamp)); + ASSERT_LT(0, timestamp.tv_sec); +} + TEST_F(TestLibRBD, OpenAio) { rados_ioctx_t ioctx; diff --git a/src/test/pybind/test_rbd.py b/src/test/pybind/test_rbd.py index b01b7390bfd..5e8e18d1904 100644 --- a/src/test/pybind/test_rbd.py +++ b/src/test/pybind/test_rbd.py @@ -335,6 +335,11 @@ class TestImage(object): def test_block_name_prefix(self): assert_not_equal(b'', self.image.block_name_prefix()) + def test_create_timestamp(self): + timestamp = self.image.create_timestamp() + assert_not_equal(0, timestamp.year) + assert_not_equal(1970, timestamp.year) + def test_invalidate_cache(self): self.image.write(b'abc', 0) eq(b'abc', self.image.read(0, 3)) -- 2.39.5