]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
test: stub test cases for rbd-mirror image bootstrap
authorJason Dillaman <dillaman@redhat.com>
Sat, 9 Apr 2016 17:30:56 +0000 (13:30 -0400)
committerJason Dillaman <dillaman@redhat.com>
Tue, 10 May 2016 17:43:35 +0000 (13:43 -0400)
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
(cherry picked from commit d0f732877213ba9eec9d3158b839c5a4c796e7ab)

src/test/Makefile-client.am
src/test/librbd/mock/MockImageCtx.h
src/test/librbd/mock/MockImageState.h
src/test/librbd/mock/MockJournal.cc [new file with mode: 0644]
src/test/librbd/mock/MockJournal.h
src/test/rbd_mirror/image_replayer/test_mock_BootstrapRequest.cc [new file with mode: 0644]
src/test/rbd_mirror/test_mock_ImageReplayer.cc
src/tools/rbd_mirror/ImageReplayer.cc
src/tools/rbd_mirror/image_replayer/BootstrapRequest.cc

index b5c5f0d755c926648213decd5b68ea2870657a6b..66ab55f87f6e4bb2bb095318f7acf291ece5a467 100644 (file)
@@ -375,7 +375,8 @@ librbd_test_la_CXXFLAGS = $(UNITTEST_CXXFLAGS)
 noinst_LTLIBRARIES += librbd_test.la
 
 librbd_test_mock_la_SOURCES = \
-       test/librbd/mock/MockImageCtx.cc
+       test/librbd/mock/MockImageCtx.cc \
+       test/librbd/mock/MockJournal.cc
 librbd_test_mock_la_CXXFLAGS = $(UNITTEST_CXXFLAGS)
 noinst_LTLIBRARIES += librbd_test_mock.la
 
@@ -472,6 +473,7 @@ unittest_rbd_mirror_SOURCES = \
        test/rbd_mirror/test_mock_fixture.cc \
        test/rbd_mirror/test_mock_ImageReplayer.cc \
        test/rbd_mirror/test_mock_ImageSync.cc \
+       test/rbd_mirror/image_replayer/test_mock_BootstrapRequest.cc \
        test/rbd_mirror/image_sync/test_mock_ImageCopyRequest.cc \
        test/rbd_mirror/image_sync/test_mock_ObjectCopyRequest.cc \
        test/rbd_mirror/image_sync/test_mock_SnapshotCopyRequest.cc \
index 170e9a141f004232b0a2843632eb8f6d0062ac61..034db1c9f60bad2c914c7d00c55c9e7b5aab4822 100644 (file)
@@ -63,6 +63,8 @@ struct MockImageCtx {
       size(image_ctx.size),
       features(image_ctx.features),
       flags(image_ctx.flags),
+      stripe_unit(image_ctx.stripe_unit),
+      stripe_count(image_ctx.stripe_count),
       object_prefix(image_ctx.object_prefix),
       header_oid(image_ctx.header_oid),
       id(image_ctx.id),
@@ -199,6 +201,8 @@ struct MockImageCtx {
   uint64_t size;
   uint64_t features;
   uint64_t flags;
+  uint64_t stripe_unit;
+  uint64_t stripe_count;
   std::string object_prefix;
   std::string header_oid;
   std::string id;
index 8f5f206fb6222ed792abe41c535eabaa1d74f214..8d2ad117f7a96c60dddeb82c60c0d9e6b6b341e7 100644 (file)
@@ -14,6 +14,8 @@ struct MockImageState {
   MOCK_CONST_METHOD0(is_refresh_required, bool());
   MOCK_METHOD1(refresh, void(Context*));
 
+  MOCK_METHOD1(open, void(Context*));
+
   MOCK_METHOD0(close, int());
   MOCK_METHOD1(close, void(Context*));
 };
diff --git a/src/test/librbd/mock/MockJournal.cc b/src/test/librbd/mock/MockJournal.cc
new file mode 100644 (file)
index 0000000..a9e9886
--- /dev/null
@@ -0,0 +1,10 @@
+// -*- mode:C; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+
+#include "test/librbd/mock/MockJournal.h"
+
+namespace librbd {
+
+MockJournal *MockJournal::s_instance = nullptr;
+
+} // namespace librbd
index a4637a4c6c5f0b585b3532852de47e087e10b24e..a80eead3dd3db862f1ff590cc705dd0ab800a124 100644 (file)
 namespace librbd {
 
 struct MockJournal {
+  static MockJournal *s_instance;
+  static MockJournal *get_instance() {
+    assert(s_instance != nullptr);
+    return s_instance;
+  }
+
+  template <typename ImageCtxT>
+  static int is_tag_owner(ImageCtxT *image_ctx, bool *is_tag_owner) {
+    return get_instance()->is_tag_owner(is_tag_owner);
+  }
+
+  MockJournal() {
+    s_instance = this;
+  }
+
   MOCK_CONST_METHOD0(is_journal_ready, bool());
   MOCK_CONST_METHOD0(is_journal_replaying, bool());
 
   MOCK_METHOD1(wait_for_journal_ready, void(Context *));
 
   MOCK_CONST_METHOD0(is_tag_owner, bool());
+  MOCK_CONST_METHOD1(is_tag_owner, int(bool *));
   MOCK_METHOD6(allocate_tag, void(const std::string &mirror_uuid,
                                   const std::string &predecessor_mirror_uuid,
                                   bool predecessor_commit_valid,
@@ -27,6 +43,8 @@ struct MockJournal {
   MOCK_METHOD1(open, void(Context *));
   MOCK_METHOD1(close, void(Context *));
 
+  MOCK_CONST_METHOD0(get_tag_data, journal::TagData());
+
   MOCK_METHOD0(allocate_op_tid, uint64_t());
 
   MOCK_METHOD3(append_op_event_mock, void(uint64_t, const journal::EventEntry&,
diff --git a/src/test/rbd_mirror/image_replayer/test_mock_BootstrapRequest.cc b/src/test/rbd_mirror/image_replayer/test_mock_BootstrapRequest.cc
new file mode 100644 (file)
index 0000000..0cec3a2
--- /dev/null
@@ -0,0 +1,126 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+
+#include "test/rbd_mirror/test_mock_fixture.h"
+#include "librbd/journal/TypeTraits.h"
+#include "tools/rbd_mirror/ImageSync.h"
+#include "tools/rbd_mirror/image_replayer/BootstrapRequest.h"
+#include "tools/rbd_mirror/image_replayer/CloseImageRequest.h"
+#include "tools/rbd_mirror/image_replayer/OpenLocalImageRequest.h"
+#include "test/journal/mock/MockJournaler.h"
+#include "test/librbd/mock/MockImageCtx.h"
+
+namespace librbd {
+namespace journal {
+
+template <>
+struct TypeTraits<librbd::MockImageCtx> {
+  typedef ::journal::MockJournaler Journaler;
+};
+
+} // namespace journal
+} // namespace librbd
+
+namespace rbd {
+namespace mirror {
+
+class ProgressContext;
+
+template<>
+struct ImageSync<librbd::MockImageCtx> {
+  static ImageSync* s_instance;
+  Context *on_finish = nullptr;
+
+  static ImageSync* create(librbd::MockImageCtx *local_image_ctx,
+                           librbd::MockImageCtx *remote_image_ctx,
+                           SafeTimer *timer, Mutex *timer_lock,
+                           const std::string &mirror_uuid,
+                           ::journal::MockJournaler *journaler,
+                           librbd::journal::MirrorPeerClientMeta *client_meta,
+                           Context *on_finish,
+                           ProgressContext *progress_ctx = nullptr) {
+    assert(s_instance != nullptr);
+    return s_instance;
+  }
+
+  ImageSync() {
+    assert(s_instance == nullptr);
+    s_instance = this;
+  }
+
+  MOCK_METHOD0(start, void());
+};
+
+ImageSync<librbd::MockImageCtx>* ImageSync<librbd::MockImageCtx>::s_instance = nullptr;
+
+namespace image_replayer {
+
+template<>
+struct CloseImageRequest<librbd::MockImageCtx> {
+  static CloseImageRequest* s_instance;
+  Context *on_finish = nullptr;
+
+  static CloseImageRequest* create(librbd::MockImageCtx **image_ctx,
+                                   ContextWQ *work_queue, bool destroy_only,
+                                   Context *on_finish) {
+    assert(s_instance != nullptr);
+    s_instance->on_finish = on_finish;
+    return s_instance;
+  }
+
+  CloseImageRequest() {
+    assert(s_instance == nullptr);
+    s_instance = this;
+  }
+
+  MOCK_METHOD0(send, void());
+};
+
+template<>
+struct OpenLocalImageRequest<librbd::MockImageCtx> {
+  static OpenLocalImageRequest* s_instance;
+  Context *on_finish = nullptr;
+
+  static OpenLocalImageRequest* create(librados::IoCtx &local_io_ctx,
+                                       librbd::MockImageCtx **local_image_ctx,
+                                       const std::string &local_image_name,
+                                       const std::string &local_image_id,
+                                       ContextWQ *work_queue,
+                                       Context *on_finish) {
+    assert(s_instance != nullptr);
+    s_instance->on_finish = on_finish;
+    return s_instance;
+  }
+
+  OpenLocalImageRequest() {
+    assert(s_instance == nullptr);
+    s_instance = this;
+  }
+
+  MOCK_METHOD0(send, void());
+};
+
+CloseImageRequest<librbd::MockImageCtx>* CloseImageRequest<librbd::MockImageCtx>::s_instance = nullptr;
+OpenLocalImageRequest<librbd::MockImageCtx>* OpenLocalImageRequest<librbd::MockImageCtx>::s_instance = nullptr;
+
+} // namespace image_replayer
+} // namespace mirror
+} // namespace rbd
+
+// template definitions
+#include "tools/rbd_mirror/image_replayer/BootstrapRequest.cc"
+template class rbd::mirror::image_replayer::BootstrapRequest<librbd::MockImageCtx>;
+
+namespace rbd {
+namespace mirror {
+namespace image_replayer {
+
+class TestMockImageReplayerBootstrapRequest : public TestMockFixture {
+public:
+  typedef BootstrapRequest<librbd::MockImageCtx> MockBootstrapRequest;
+
+};
+
+} // namespace image_replayer
+} // namespace mirror
+} // namespace rbd
index a2785f11c55459245194f6d27623d10a02f3b341..4ec594f553b0ef0eeeb73c64ca185ec54c23fdd1 100644 (file)
@@ -6,7 +6,6 @@
 #include "tools/rbd_mirror/ImageReplayer.h"
 #include "tools/rbd_mirror/image_replayer/BootstrapRequest.h"
 #include "tools/rbd_mirror/image_replayer/CloseImageRequest.h"
-#include "tools/rbd_mirror/image_replayer/OpenLocalImageRequest.h"
 #include "test/journal/mock/MockJournaler.h"
 #include "test/librbd/mock/MockImageCtx.h"
 #include "test/librbd/mock/MockJournal.h"
@@ -101,30 +100,6 @@ struct CloseImageRequest<librbd::MockImageReplayerImageCtx> {
   MOCK_METHOD0(send, void());
 };
 
-template<>
-struct OpenLocalImageRequest<librbd::MockImageReplayerImageCtx> {
-  static OpenLocalImageRequest* s_instance;
-  Context *on_finish = nullptr;
-
-  static OpenLocalImageRequest* create(librados::IoCtx &local_io_ctx,
-                                       librbd::MockImageReplayerImageCtx **local_image_ctx,
-                                       const std::string &local_image_name,
-                                       const std::string &local_image_id,
-                                       ContextWQ *work_queue,
-                                       Context *on_finish) {
-    assert(s_instance != nullptr);
-    s_instance->on_finish = on_finish;
-    return s_instance;
-  }
-
-  OpenLocalImageRequest() {
-    assert(s_instance == nullptr);
-    s_instance = this;
-  }
-
-  MOCK_METHOD0(send, void());
-};
-
 template<>
 struct ReplayStatusFormatter<librbd::MockImageReplayerImageCtx> {
   static ReplayStatusFormatter* s_instance;
@@ -145,7 +120,6 @@ struct ReplayStatusFormatter<librbd::MockImageReplayerImageCtx> {
 
 BootstrapRequest<librbd::MockImageReplayerImageCtx>* BootstrapRequest<librbd::MockImageReplayerImageCtx>::s_instance = nullptr;
 CloseImageRequest<librbd::MockImageReplayerImageCtx>* CloseImageRequest<librbd::MockImageReplayerImageCtx>::s_instance = nullptr;
-OpenLocalImageRequest<librbd::MockImageReplayerImageCtx>* OpenLocalImageRequest<librbd::MockImageReplayerImageCtx>::s_instance = nullptr;
 ReplayStatusFormatter<librbd::MockImageReplayerImageCtx>* ReplayStatusFormatter<librbd::MockImageReplayerImageCtx>::s_instance = nullptr;
 
 } // namespace image_replayer
index 73ac410945d7740816dc29d745906f17b8c44a08..203b78c10f7b4f5ee8f2483b81ee2206bd884f0c 100644 (file)
@@ -22,7 +22,6 @@
 #include "Threads.h"
 #include "tools/rbd_mirror/image_replayer/BootstrapRequest.h"
 #include "tools/rbd_mirror/image_replayer/CloseImageRequest.h"
-#include "tools/rbd_mirror/image_replayer/OpenLocalImageRequest.h"
 #include "tools/rbd_mirror/image_replayer/ReplayStatusFormatter.h"
 
 #define dout_subsys ceph_subsys_rbd_mirror
index 760992de95d613d7e111dfee8129c5f895088fce..6f7210e224a80bd943a88cb3e80b818b8b6d82d9 100644 (file)
@@ -530,8 +530,8 @@ void BootstrapRequest<I>::handle_get_remote_tags(int r) {
       local_image_ctx->journal->get_tag_data();
     dout(20) << ": local tag data: " << tag_data << dendl;
 
-    if (!((tag_data.mirror_uuid == librbd::Journal<I>::ORPHAN_MIRROR_UUID &&
-           remote_tag_data.mirror_uuid == librbd::Journal<I>::ORPHAN_MIRROR_UUID &&
+    if (!((tag_data.mirror_uuid == librbd::Journal<>::ORPHAN_MIRROR_UUID &&
+           remote_tag_data.mirror_uuid == librbd::Journal<>::ORPHAN_MIRROR_UUID &&
            remote_tag_data.predecessor_mirror_uuid == m_local_mirror_uuid) ||
           (tag_data.mirror_uuid == m_remote_mirror_uuid &&
            m_client_meta->state == librbd::journal::MIRROR_PEER_STATE_REPLAYING))) {