]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
test/librados_test_stub: handle assert_version
authorOr Ozeri <oro@il.ibm.com>
Thu, 30 Jul 2020 17:15:53 +0000 (20:15 +0300)
committerOr Ozeri <oro@il.ibm.com>
Fri, 31 Jul 2020 04:05:19 +0000 (07:05 +0300)
This commits adds a proper handling of the assert_version API in RADOS.

Signed-off-by: Or Ozeri <oro@il.ibm.com>
src/test/librados_test_stub/LibradosTestStub.cc
src/test/librados_test_stub/MockTestMemIoCtxImpl.h
src/test/librados_test_stub/NeoradosTestStub.cc
src/test/librados_test_stub/TestIoCtxImpl.h
src/test/librados_test_stub/TestMemIoCtxImpl.cc
src/test/librados_test_stub/TestMemIoCtxImpl.h

index a90b0966d2480a2fb72214b4f0aba3bba626dbe4..c0e2912c8063d0b7ae49c3c4611661b35a61ca3f 100644 (file)
@@ -815,6 +815,11 @@ void ObjectOperation::assert_exists() {
   o->ops.push_back(std::bind(&TestIoCtxImpl::assert_exists, _1, _2, _4));
 }
 
+void ObjectOperation::assert_version(uint64_t ver) {
+  TestObjectOperationImpl *o = reinterpret_cast<TestObjectOperationImpl*>(impl);
+  o->ops.push_back(std::bind(&TestIoCtxImpl::assert_version, _1, _2, ver));
+}
+
 void ObjectOperation::exec(const char *cls, const char *method,
                            bufferlist& inbl) {
   TestObjectOperationImpl *o = reinterpret_cast<TestObjectOperationImpl*>(impl);
index 765af67367f1525011f40822738bbf93c0875bcd..4ea625eac08fa9a8be4906a2140211512d91026b 100644 (file)
@@ -68,6 +68,11 @@ public:
     return TestMemIoCtxImpl::assert_exists(oid, snap_id);
   }
 
+  MOCK_METHOD2(assert_version, int(const std::string &, uint64_t));
+  int do_assert_version(const std::string &oid, uint64_t ver) {
+    return TestMemIoCtxImpl::assert_version(oid, ver);
+  }
+
   MOCK_METHOD3(create, int(const std::string&, bool, const SnapContext &));
   int do_create(const std::string& oid, bool exclusive,
                 const SnapContext &snapc) {
@@ -213,6 +218,7 @@ public:
     ON_CALL(*this, aio_watch(_, _, _, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_aio_watch));
     ON_CALL(*this, aio_unwatch(_, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_aio_unwatch));
     ON_CALL(*this, assert_exists(_, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_assert_exists));
+    ON_CALL(*this, assert_version(_, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_assert_version));
     ON_CALL(*this, create(_, _, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_create));
     ON_CALL(*this, cmpext(_, _, _, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_cmpext));
     ON_CALL(*this, exec(_, _, _, _, _, _, _, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_exec));
index 533b959701ec81989270ff26553ac6a86382b0da..6a6a7ead8d694ce0f63f68759101e72990be6a86 100644 (file)
@@ -242,6 +242,12 @@ void Op::assert_exists() {
     &librados::TestIoCtxImpl::assert_exists, _1, _2, _4));
 }
 
+void Op::assert_version(uint64_t ver) {
+  auto o = *reinterpret_cast<librados::TestObjectOperationImpl**>(&impl);
+  o->ops.push_back(std::bind(
+          &librados::TestIoCtxImpl::assert_version, _1, _2, ver));
+}
+
 void Op::cmpext(uint64_t off, ceph::buffer::list&& cmp_bl, std::size_t* s) {
   auto o = *reinterpret_cast<librados::TestObjectOperationImpl**>(&impl);
   librados::ObjectOperationTestImpl op = std::bind(
index 8d8a07dfded59c426e06397adf572d4d394df7e2..2ebc42edd7920d95b6894ed097283e4046c7e8ba 100644 (file)
@@ -99,6 +99,7 @@ public:
   virtual int append(const std::string& oid, const bufferlist &bl,
                      const SnapContext &snapc) = 0;
   virtual int assert_exists(const std::string &oid, uint64_t snap_id) = 0;
+  virtual int assert_version(const std::string &oid, uint64_t ver) = 0;
 
   virtual int create(const std::string& oid, bool exclusive,
                      const SnapContext &snapc) = 0;
index eac85643d766650c9229f126bed96c98282e5560..ae7f6fafed1a890a88a3dd61fb4b586490d8ded8 100644 (file)
@@ -99,6 +99,26 @@ int TestMemIoCtxImpl::assert_exists(const std::string &oid, uint64_t snap_id) {
   return 0;
 }
 
+int TestMemIoCtxImpl::assert_version(const std::string &oid, uint64_t ver) {
+  if (m_client->is_blacklisted()) {
+    return -EBLACKLISTED;
+  }
+
+  std::shared_lock l{m_pool->file_lock};
+  TestMemCluster::SharedFile file = get_file(oid, false, CEPH_NOSNAP, {});
+  if (file == NULL || !file->exists) {
+    return -ENOENT;
+  }
+  if (ver < file->objver) {
+    return -ERANGE;
+  }
+  if (ver > file->objver) {
+    return -EOVERFLOW;
+  }
+
+  return 0;
+}
+
 int TestMemIoCtxImpl::create(const std::string& oid, bool exclusive,
                              const SnapContext &snapc) {
   if (get_snap_read() != CEPH_NOSNAP) {
index d4be453868f268b8df63cef173e0e449fb344262..9b9042262362fcb25427b4f84714c3dbce48c51b 100644 (file)
@@ -27,6 +27,7 @@ public:
              const SnapContext &snapc) override;
 
   int assert_exists(const std::string &oid, uint64_t snap_id) override;
+  int assert_version(const std::string &oid, uint64_t ver) override;
 
   int create(const std::string& oid, bool exclusive,
              const SnapContext &snapc) override;