]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/test/rbd_mirror/test_mock_ImageSync.cc
import 15.2.0 Octopus source
[ceph.git] / ceph / src / test / rbd_mirror / test_mock_ImageSync.cc
index 339f59e86de61f337586d5cbde388fe900eaa8dc..743418325ced0d1d65802ed057b3d3063d13453c 100644 (file)
@@ -4,11 +4,9 @@
 #include "test/rbd_mirror/test_mock_fixture.h"
 #include "include/rbd/librbd.hpp"
 #include "librbd/DeepCopyRequest.h"
-#include "librbd/journal/Types.h"
-#include "librbd/journal/TypeTraits.h"
-#include "test/journal/mock/MockJournaler.h"
 #include "test/librados_test_stub/MockTestMemIoCtxImpl.h"
 #include "test/librbd/mock/MockImageCtx.h"
+#include "test/rbd_mirror/mock/image_sync/MockSyncPointHandler.h"
 #include "tools/rbd_mirror/ImageSync.h"
 #include "tools/rbd_mirror/Threads.h"
 #include "tools/rbd_mirror/image_sync/SyncPointCreateRequest.h"
@@ -26,15 +24,6 @@ struct MockTestImageCtx : public librbd::MockImageCtx {
 
 } // anonymous namespace
 
-namespace journal {
-
-template <>
-struct TypeTraits<librbd::MockTestImageCtx> {
-  typedef ::journal::MockJournaler Journaler;
-};
-
-} // namespace journal
-
 template <>
 class DeepCopyRequest<librbd::MockTestImageCtx> {
 public:
@@ -44,8 +33,9 @@ public:
   static DeepCopyRequest* create(
       librbd::MockTestImageCtx *src_image_ctx,
       librbd::MockTestImageCtx *dst_image_ctx,
-      librados::snap_t snap_id_start, librados::snap_t snap_id_end,
-      bool flatten, const librbd::deep_copy::ObjectNumber &object_number,
+      librados::snap_t src_snap_id_start, librados::snap_t src_snap_id_end,
+      librados::snap_t dst_snap_id_start, bool flatten,
+      const librbd::deep_copy::ObjectNumber &object_number,
       ContextWQ *work_queue, SnapSeqs *snap_seqs, ProgressContext *prog_ctx,
       Context *on_finish) {
     ceph_assert(s_instance != nullptr);
@@ -78,6 +68,18 @@ template class rbd::mirror::ImageSync<librbd::MockTestImageCtx>;
 namespace rbd {
 namespace mirror {
 
+template <>
+struct Threads<librbd::MockTestImageCtx> {
+  ceph::mutex &timer_lock;
+  SafeTimer *timer;
+  ContextWQ *work_queue;
+
+  Threads(Threads<librbd::ImageCtx> *threads)
+    : timer_lock(threads->timer_lock), timer(threads->timer),
+      work_queue(threads->work_queue) {
+  }
+};
+
 template<>
 struct InstanceWatcher<librbd::MockTestImageCtx> {
   MOCK_METHOD2(notify_sync_request, void(const std::string, Context *));
@@ -95,8 +97,7 @@ public:
 
   static SyncPointCreateRequest* create(librbd::MockTestImageCtx *remote_image_ctx,
                                         const std::string &mirror_uuid,
-                                        journal::MockJournaler *journaler,
-                                        librbd::journal::MirrorPeerClientMeta *client_meta,
+                                        image_sync::SyncPointHandler* sync_point_handler,
                                         Context *on_finish) {
     ceph_assert(s_instance != nullptr);
     s_instance->on_finish = on_finish;
@@ -118,8 +119,7 @@ public:
 
   static SyncPointPruneRequest* create(librbd::MockTestImageCtx *remote_image_ctx,
                                        bool sync_complete,
-                                       journal::MockJournaler *journaler,
-                                       librbd::journal::MirrorPeerClientMeta *client_meta,
+                                       image_sync::SyncPointHandler* sync_point_handler,
                                        Context *on_finish) {
     ceph_assert(s_instance != nullptr);
     s_instance->on_finish = on_finish;
@@ -139,6 +139,7 @@ SyncPointPruneRequest<librbd::MockTestImageCtx>* SyncPointPruneRequest<librbd::M
 } // namespace image_sync
 
 using ::testing::_;
+using ::testing::DoAll;
 using ::testing::InSequence;
 using ::testing::Invoke;
 using ::testing::Return;
@@ -148,10 +149,12 @@ using ::testing::InvokeWithoutArgs;
 
 class TestMockImageSync : public TestMockFixture {
 public:
+  typedef Threads<librbd::MockTestImageCtx> MockThreads;
   typedef ImageSync<librbd::MockTestImageCtx> MockImageSync;
   typedef InstanceWatcher<librbd::MockTestImageCtx> MockInstanceWatcher;
   typedef image_sync::SyncPointCreateRequest<librbd::MockTestImageCtx> MockSyncPointCreateRequest;
   typedef image_sync::SyncPointPruneRequest<librbd::MockTestImageCtx> MockSyncPointPruneRequest;
+  typedef image_sync::MockSyncPointHandler MockSyncPointHandler;
   typedef librbd::DeepCopyRequest<librbd::MockTestImageCtx> MockImageCopyRequest;
 
   void SetUp() override {
@@ -197,9 +200,8 @@ public:
           if (r == 0) {
             mock_local_image_ctx.snap_ids[{cls::rbd::UserSnapshotNamespace(),
                                           "snap1"}] = 123;
-            m_client_meta.sync_points.emplace_back(cls::rbd::UserSnapshotNamespace(),
-                                                  "snap1",
-                                                  boost::none);
+            m_sync_points.emplace_back(cls::rbd::UserSnapshotNamespace(),
+                                       "snap1", "", boost::none);
           }
           m_threads->work_queue->queue(mock_sync_point_create_request.on_finish, r);
         }));
@@ -212,9 +214,10 @@ public:
         }));
   }
 
-  void expect_flush_sync_point(journal::MockJournaler &mock_journaler, int r) {
-    EXPECT_CALL(mock_journaler, update_client(_, _))
-      .WillOnce(WithArg<1>(CompleteContext(r)));
+  void expect_flush_sync_point(MockSyncPointHandler& mock_sync_point_handler,
+                               int r) {
+    EXPECT_CALL(mock_sync_point_handler, update_sync_points(_, _, false, _))
+      .WillOnce(WithArg<3>(CompleteContext(r)));
   }
 
   void expect_prune_sync_point(MockSyncPointPruneRequest &mock_sync_point_prune_request,
@@ -222,12 +225,12 @@ public:
     EXPECT_CALL(mock_sync_point_prune_request, send())
       .WillOnce(Invoke([this, &mock_sync_point_prune_request, sync_complete, r]() {
           ASSERT_EQ(sync_complete, mock_sync_point_prune_request.sync_complete);
-          if (r == 0 && !m_client_meta.sync_points.empty()) {
+          if (r == 0 && !m_sync_points.empty()) {
             if (sync_complete) {
-              m_client_meta.sync_points.pop_front();
+              m_sync_points.pop_front();
             } else {
-              while (m_client_meta.sync_points.size() > 1) {
-                m_client_meta.sync_points.pop_back();
+              while (m_sync_points.size() > 1) {
+                m_sync_points.pop_back();
               }
             }
           }
@@ -235,88 +238,114 @@ public:
         }));
   }
 
-  MockImageSync *create_request(librbd::MockTestImageCtx &mock_remote_image_ctx,
+  void expect_get_snap_seqs(MockSyncPointHandler& mock_sync_point_handler) {
+    EXPECT_CALL(mock_sync_point_handler, get_snap_seqs())
+      .WillRepeatedly(Return(librbd::SnapSeqs{}));
+  }
+
+  void expect_get_sync_points(MockSyncPointHandler& mock_sync_point_handler) {
+    EXPECT_CALL(mock_sync_point_handler, get_sync_points())
+      .WillRepeatedly(Invoke([this]() {
+                        return m_sync_points;
+                      }));
+  }
+
+  MockImageSync *create_request(MockThreads& mock_threads,
+                                librbd::MockTestImageCtx &mock_remote_image_ctx,
                                 librbd::MockTestImageCtx &mock_local_image_ctx,
-                                journal::MockJournaler &mock_journaler,
+                                MockSyncPointHandler& mock_sync_point_handler,
                                 MockInstanceWatcher &mock_instance_watcher,
                                 Context *ctx) {
-    return new MockImageSync(&mock_local_image_ctx, &mock_remote_image_ctx,
-                             m_threads->timer, &m_threads->timer_lock,
-                             "mirror-uuid", &mock_journaler, &m_client_meta,
-                             m_threads->work_queue, &mock_instance_watcher,
-                             ctx);
+    return new MockImageSync(&mock_threads, &mock_local_image_ctx,
+                             &mock_remote_image_ctx,
+                             "mirror-uuid", &mock_sync_point_handler,
+                             &mock_instance_watcher, nullptr, ctx);
   }
 
   librbd::ImageCtx *m_remote_image_ctx;
   librbd::ImageCtx *m_local_image_ctx;
-  librbd::journal::MirrorPeerClientMeta m_client_meta;
+
+  image_sync::SyncPoints m_sync_points;
 };
 
 TEST_F(TestMockImageSync, SimpleSync) {
+  MockThreads mock_threads(m_threads);
   librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx);
   librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx);
-  journal::MockJournaler mock_journaler;
+  MockSyncPointHandler mock_sync_point_handler;
   MockInstanceWatcher mock_instance_watcher;
   MockImageCopyRequest mock_image_copy_request;
   MockSyncPointCreateRequest mock_sync_point_create_request;
   MockSyncPointPruneRequest mock_sync_point_prune_request;
 
+  expect_get_snap_seqs(mock_sync_point_handler);
+  expect_get_sync_points(mock_sync_point_handler);
+
   InSequence seq;
   expect_notify_sync_request(mock_instance_watcher, mock_local_image_ctx.id, 0);
   expect_create_sync_point(mock_local_image_ctx, mock_sync_point_create_request, 0);
   expect_get_snap_id(mock_remote_image_ctx);
   expect_copy_image(mock_image_copy_request, 0);
-  expect_flush_sync_point(mock_journaler, 0);
+  expect_flush_sync_point(mock_sync_point_handler, 0);
   expect_prune_sync_point(mock_sync_point_prune_request, true, 0);
   expect_notify_sync_complete(mock_instance_watcher, mock_local_image_ctx.id);
 
   C_SaferCond ctx;
-  MockImageSync *request = create_request(mock_remote_image_ctx,
-                                          mock_local_image_ctx, mock_journaler,
+  MockImageSync *request = create_request(mock_threads, mock_remote_image_ctx,
+                                          mock_local_image_ctx,
+                                          mock_sync_point_handler,
                                           mock_instance_watcher, &ctx);
   request->send();
   ASSERT_EQ(0, ctx.wait());
 }
 
 TEST_F(TestMockImageSync, RestartSync) {
+  MockThreads mock_threads(m_threads);
   librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx);
   librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx);
-  journal::MockJournaler mock_journaler;
+  MockSyncPointHandler mock_sync_point_handler;
   MockInstanceWatcher mock_instance_watcher;
   MockImageCopyRequest mock_image_copy_request;
   MockSyncPointCreateRequest mock_sync_point_create_request;
   MockSyncPointPruneRequest mock_sync_point_prune_request;
 
-  m_client_meta.sync_points = {{cls::rbd::UserSnapshotNamespace(), "snap1", boost::none},
-                               {cls::rbd::UserSnapshotNamespace(), "snap2", "snap1", boost::none}};
+  m_sync_points = {{cls::rbd::UserSnapshotNamespace(), "snap1", "", boost::none},
+                   {cls::rbd::UserSnapshotNamespace(), "snap2", "snap1", boost::none}};
   mock_local_image_ctx.snap_ids[{cls::rbd::UserSnapshotNamespace(), "snap1"}] = 123;
   mock_local_image_ctx.snap_ids[{cls::rbd::UserSnapshotNamespace(), "snap2"}] = 234;
 
   expect_test_features(mock_local_image_ctx);
+  expect_get_snap_seqs(mock_sync_point_handler);
+  expect_get_sync_points(mock_sync_point_handler);
 
   InSequence seq;
   expect_notify_sync_request(mock_instance_watcher, mock_local_image_ctx.id, 0);
   expect_prune_sync_point(mock_sync_point_prune_request, false, 0);
   expect_get_snap_id(mock_remote_image_ctx);
   expect_copy_image(mock_image_copy_request, 0);
-  expect_flush_sync_point(mock_journaler, 0);
+  expect_flush_sync_point(mock_sync_point_handler, 0);
   expect_prune_sync_point(mock_sync_point_prune_request, true, 0);
   expect_notify_sync_complete(mock_instance_watcher, mock_local_image_ctx.id);
 
   C_SaferCond ctx;
-  MockImageSync *request = create_request(mock_remote_image_ctx,
-                                          mock_local_image_ctx, mock_journaler,
+  MockImageSync *request = create_request(mock_threads, mock_remote_image_ctx,
+                                          mock_local_image_ctx,
+                                          mock_sync_point_handler,
                                           mock_instance_watcher, &ctx);
   request->send();
   ASSERT_EQ(0, ctx.wait());
 }
 
 TEST_F(TestMockImageSync, CancelNotifySyncRequest) {
+  MockThreads mock_threads(m_threads);
   librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx);
   librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx);
-  journal::MockJournaler mock_journaler;
+  MockSyncPointHandler mock_sync_point_handler;
   MockInstanceWatcher mock_instance_watcher;
 
+  expect_get_snap_seqs(mock_sync_point_handler);
+  expect_get_sync_points(mock_sync_point_handler);
+
   InSequence seq;
   Context *on_sync_start = nullptr;
   C_SaferCond notify_sync_ctx;
@@ -336,8 +365,9 @@ TEST_F(TestMockImageSync, CancelNotifySyncRequest) {
         }));
 
   C_SaferCond ctx;
-  MockImageSync *request = create_request(mock_remote_image_ctx,
-                                          mock_local_image_ctx, mock_journaler,
+  MockImageSync *request = create_request(mock_threads, mock_remote_image_ctx,
+                                          mock_local_image_ctx,
+                                          mock_sync_point_handler,
                                           mock_instance_watcher, &ctx);
   request->get();
   request->send();
@@ -351,15 +381,18 @@ TEST_F(TestMockImageSync, CancelNotifySyncRequest) {
 }
 
 TEST_F(TestMockImageSync, CancelImageCopy) {
+  MockThreads mock_threads(m_threads);
   librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx);
   librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx);
-  journal::MockJournaler mock_journaler;
+  MockSyncPointHandler mock_sync_point_handler;
   MockInstanceWatcher mock_instance_watcher;
   MockImageCopyRequest mock_image_copy_request;
   MockSyncPointCreateRequest mock_sync_point_create_request;
   MockSyncPointPruneRequest mock_sync_point_prune_request;
 
-  m_client_meta.sync_points = {{cls::rbd::UserSnapshotNamespace(), "snap1", boost::none}};
+  m_sync_points = {{cls::rbd::UserSnapshotNamespace(), "snap1", "", boost::none}};
+  expect_get_snap_seqs(mock_sync_point_handler);
+  expect_get_sync_points(mock_sync_point_handler);
 
   InSequence seq;
   expect_notify_sync_request(mock_instance_watcher, mock_local_image_ctx.id, 0);
@@ -377,8 +410,9 @@ TEST_F(TestMockImageSync, CancelImageCopy) {
   expect_notify_sync_complete(mock_instance_watcher, mock_local_image_ctx.id);
 
   C_SaferCond ctx;
-  MockImageSync *request = create_request(mock_remote_image_ctx,
-                                          mock_local_image_ctx, mock_journaler,
+  MockImageSync *request = create_request(mock_threads, mock_remote_image_ctx,
+                                          mock_local_image_ctx,
+                                          mock_sync_point_handler,
                                           mock_instance_watcher, &ctx);
   request->get();
   request->send();
@@ -393,18 +427,24 @@ TEST_F(TestMockImageSync, CancelImageCopy) {
 }
 
 TEST_F(TestMockImageSync, CancelAfterCopyImage) {
+  MockThreads mock_threads(m_threads);
   librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx);
   librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx);
-  journal::MockJournaler mock_journaler;
+  MockSyncPointHandler mock_sync_point_handler;
   MockInstanceWatcher mock_instance_watcher;
   MockImageCopyRequest mock_image_copy_request;
   MockSyncPointCreateRequest mock_sync_point_create_request;
   MockSyncPointPruneRequest mock_sync_point_prune_request;
 
   C_SaferCond ctx;
-  MockImageSync *request = create_request(mock_remote_image_ctx,
-                                          mock_local_image_ctx, mock_journaler,
+  MockImageSync *request = create_request(mock_threads, mock_remote_image_ctx,
+                                          mock_local_image_ctx,
+                                          mock_sync_point_handler,
                                           mock_instance_watcher, &ctx);
+
+  expect_get_snap_seqs(mock_sync_point_handler);
+  expect_get_sync_points(mock_sync_point_handler);
+
   InSequence seq;
   expect_notify_sync_request(mock_instance_watcher, mock_local_image_ctx.id, 0);
   expect_create_sync_point(mock_local_image_ctx, mock_sync_point_create_request, 0);