]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
test/unittest_rbd: add unit tests for image create timestamp
authorrunsisi <runsisi@zte.com.cn>
Mon, 19 Jun 2017 03:29:31 +0000 (11:29 +0800)
committerrunsisi <runsisi@zte.com.cn>
Tue, 20 Jun 2017 05:52:06 +0000 (13:52 +0800)
Signed-off-by: runsisi <runsisi@zte.com.cn>
src/test/cls_rbd/test_cls_rbd.cc
src/test/librbd/test_librbd.cc
src/test/pybind/test_rbd.py

index 6d0cc44ad551e88ce48ff9cc5561cbcd4dee659b..186020024e92b692877568bca054328d3d5b0ab4 100644 (file)
@@ -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, &timestamp));
+  ASSERT_LT(0, timestamp.tv.tv_sec);
+
+  ioctx.close();
+}
+
 TEST_F(TestClsRbd, get_data_pool)
 {
   librados::IoCtx ioctx;
index 17ebcd7e1a3bd831040cb2f247b7422a73e1478e..99354e93951956696ea7dcbb42846d96ada6a3cf 100644 (file)
@@ -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, &timestamp));
+  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(&timestamp));
+  ASSERT_LT(0, timestamp.tv_sec);
+}
+
 TEST_F(TestLibRBD, OpenAio)
 {
   rados_ioctx_t ioctx;
index b01b7390bfdf640a051254a8115808f3562c04d7..5e8e18d19043366503cda6b27e8fff1a96f29fa4 100644 (file)
@@ -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))