#include "test/rbd_mirror/test_mock_fixture.h"
#include "librbd/journal/TypeTraits.h"
-#include "librbd/mirror/GetInfoRequest.h"
#include "tools/rbd_mirror/BaseRequest.h"
#include "tools/rbd_mirror/InstanceWatcher.h"
#include "tools/rbd_mirror/Threads.h"
};
} // anonymous namespace
-
-namespace mirror {
-
-template<>
-struct GetInfoRequest<librbd::MockTestImageCtx> {
- static GetInfoRequest* s_instance;
- cls::rbd::MirrorImage *mirror_image;
- PromotionState *promotion_state;
- Context *on_finish = nullptr;
-
- static GetInfoRequest* create(librbd::MockTestImageCtx &image_ctx,
- cls::rbd::MirrorImage *mirror_image,
- PromotionState *promotion_state,
- std::string* primary_mirror_uuid,
- Context *on_finish) {
- ceph_assert(s_instance != nullptr);
- s_instance->mirror_image = mirror_image;
- s_instance->promotion_state = promotion_state;
- s_instance->on_finish = on_finish;
- return s_instance;
- }
-
- GetInfoRequest() {
- ceph_assert(s_instance == nullptr);
- s_instance = this;
- }
- ~GetInfoRequest() {
- s_instance = nullptr;
- }
-
- MOCK_METHOD0(send, void());
-};
-
-GetInfoRequest<librbd::MockTestImageCtx>* GetInfoRequest<librbd::MockTestImageCtx>::s_instance = nullptr;
-
-} // namespace mirror
} // namespace librbd
namespace rbd {
typedef PrepareLocalImageRequest<librbd::MockTestImageCtx> MockPrepareLocalImageRequest;
typedef PrepareRemoteImageRequest<librbd::MockTestImageCtx> MockPrepareRemoteImageRequest;
typedef StateBuilder<librbd::MockTestImageCtx> MockStateBuilder;
- typedef librbd::mirror::GetInfoRequest<librbd::MockTestImageCtx> MockGetMirrorInfoRequest;
typedef std::list<cls::journal::Tag> Tags;
void SetUp() override {
}));
}
- void expect_get_remote_mirror_info(
- MockGetMirrorInfoRequest &mock_get_mirror_info_request,
- const cls::rbd::MirrorImage &mirror_image,
- librbd::mirror::PromotionState promotion_state, int r) {
- EXPECT_CALL(mock_get_mirror_info_request, send())
- .WillOnce(Invoke([this, &mock_get_mirror_info_request, mirror_image,
- promotion_state, r]() {
- *mock_get_mirror_info_request.mirror_image = mirror_image;
- *mock_get_mirror_info_request.promotion_state = promotion_state;
- m_threads->work_queue->queue(
- mock_get_mirror_info_request.on_finish, r);
- }));
- }
-
void expect_create_local_image(MockStateBuilder& mock_state_builder,
const std::string& local_image_id, int r) {
EXPECT_CALL(mock_state_builder,
expect_open_image(mock_open_image_request, m_remote_io_ctx,
mock_remote_image_ctx.id, mock_remote_image_ctx, 0);
- // test if remote image is primary
- MockGetMirrorInfoRequest mock_get_mirror_info_request;
- expect_get_remote_mirror_info(mock_get_mirror_info_request,
- {cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "uuid",
- cls::rbd::MIRROR_IMAGE_STATE_ENABLED},
- librbd::mirror::PROMOTION_STATE_PRIMARY, 0);
-
// open the local image
librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx);
MockOpenLocalImageRequest mock_open_local_image_request;
expect_open_image(mock_open_image_request, m_remote_io_ctx,
mock_remote_image_ctx.id, mock_remote_image_ctx, 0);
- // test if remote image is primary
- MockGetMirrorInfoRequest mock_get_mirror_info_request;
- expect_get_remote_mirror_info(mock_get_mirror_info_request,
- {cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "uuid",
- cls::rbd::MIRROR_IMAGE_STATE_ENABLED},
- librbd::mirror::PROMOTION_STATE_PRIMARY, 0);
-
// open the local image
librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx);
MockOpenLocalImageRequest mock_open_local_image_request;
expect_open_image(mock_open_image_request, m_remote_io_ctx,
mock_remote_image_ctx.id, mock_remote_image_ctx, 0);
- // test if remote image is primary
- MockGetMirrorInfoRequest mock_get_mirror_info_request;
- expect_get_remote_mirror_info(mock_get_mirror_info_request,
- {cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "uuid",
- cls::rbd::MIRROR_IMAGE_STATE_ENABLED},
- librbd::mirror::PROMOTION_STATE_PRIMARY, 0);
-
// open the local image
librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx);
MockOpenLocalImageRequest mock_open_local_image_request;
expect_open_image(mock_open_image_request, m_remote_io_ctx,
mock_remote_image_ctx.id, mock_remote_image_ctx, 0);
- // test if remote image is primary
- MockGetMirrorInfoRequest mock_get_mirror_info_request;
- expect_get_remote_mirror_info(mock_get_mirror_info_request,
- {cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "uuid",
- cls::rbd::MIRROR_IMAGE_STATE_ENABLED},
- librbd::mirror::PROMOTION_STATE_PRIMARY, 0);
-
// open the local image
librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx);
MockOpenLocalImageRequest mock_open_local_image_request;
expect_open_image(mock_open_image_request, m_remote_io_ctx,
mock_remote_image_ctx.id, mock_remote_image_ctx, 0);
- // test if remote image is primary
- MockGetMirrorInfoRequest mock_get_mirror_info_request;
- expect_get_remote_mirror_info(mock_get_mirror_info_request,
- {cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "uuid",
- cls::rbd::MIRROR_IMAGE_STATE_ENABLED},
- librbd::mirror::PROMOTION_STATE_PRIMARY, 0);
-
// create local image
expect_create_local_image(mock_state_builder, "local image id", -EINVAL);
expect_open_image(mock_open_image_request, m_remote_io_ctx,
mock_remote_image_ctx.id, mock_remote_image_ctx, 0);
- // test if remote image is primary
- MockGetMirrorInfoRequest mock_get_mirror_info_request;
- expect_get_remote_mirror_info(mock_get_mirror_info_request,
- {cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "uuid",
- cls::rbd::MIRROR_IMAGE_STATE_ENABLED},
- librbd::mirror::PROMOTION_STATE_PRIMARY, 0);
-
// open the local image
librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx);
MockOpenLocalImageRequest mock_open_local_image_request;
expect_open_image(mock_open_image_request, m_remote_io_ctx,
mock_remote_image_ctx.id, mock_remote_image_ctx, 0);
- // test if remote image is primary
- MockGetMirrorInfoRequest mock_get_mirror_info_request;
- expect_get_remote_mirror_info(mock_get_mirror_info_request,
- {cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "uuid",
- cls::rbd::MIRROR_IMAGE_STATE_ENABLED},
- librbd::mirror::PROMOTION_STATE_PRIMARY, 0);
-
// open the local image
librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx);
MockOpenLocalImageRequest mock_open_local_image_request;
expect_open_image(mock_open_image_request, m_remote_io_ctx,
mock_remote_image_ctx.id, mock_remote_image_ctx, 0);
- // test if remote image is primary
- MockGetMirrorInfoRequest mock_get_mirror_info_request;
- expect_get_remote_mirror_info(mock_get_mirror_info_request,
- {cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "uuid",
- cls::rbd::MIRROR_IMAGE_STATE_ENABLED},
- librbd::mirror::PROMOTION_STATE_PRIMARY, 0);
-
// open the local image
librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx);
MockOpenLocalImageRequest mock_open_local_image_request;
expect_open_image(mock_open_image_request, m_remote_io_ctx,
mock_remote_image_ctx.id, mock_remote_image_ctx, 0);
- // test if remote image is primary
- MockGetMirrorInfoRequest mock_get_mirror_info_request;
- expect_get_remote_mirror_info(mock_get_mirror_info_request,
- {cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "uuid",
- cls::rbd::MIRROR_IMAGE_STATE_ENABLED},
- librbd::mirror::PROMOTION_STATE_PRIMARY, 0);
-
// open the local image
librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx);
MockOpenLocalImageRequest mock_open_local_image_request;
expect_open_image(mock_open_image_request, m_remote_io_ctx,
mock_remote_image_ctx.id, mock_remote_image_ctx, 0);
- // test if remote image is primary
- MockGetMirrorInfoRequest mock_get_mirror_info_request;
- expect_get_remote_mirror_info(mock_get_mirror_info_request,
- {cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "uuid",
- cls::rbd::MIRROR_IMAGE_STATE_ENABLED},
- librbd::mirror::PROMOTION_STATE_PRIMARY, 0);
-
// open the local image
librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx);
MockOpenLocalImageRequest mock_open_local_image_request;
expect_open_image(mock_open_image_request, m_remote_io_ctx,
mock_remote_image_ctx.id, mock_remote_image_ctx, 0);
- // test if remote image is primary
- MockGetMirrorInfoRequest mock_get_mirror_info_request;
- expect_get_remote_mirror_info(mock_get_mirror_info_request,
- {cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "uuid",
- cls::rbd::MIRROR_IMAGE_STATE_ENABLED},
- librbd::mirror::PROMOTION_STATE_PRIMARY, 0);
-
// open the local image
librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx);
MockOpenLocalImageRequest mock_open_local_image_request;
expect_open_image(mock_open_image_request, m_remote_io_ctx,
mock_remote_image_ctx.id, mock_remote_image_ctx, 0);
- // test if remote image is primary
- MockGetMirrorInfoRequest mock_get_mirror_info_request;
- expect_get_remote_mirror_info(mock_get_mirror_info_request,
- {cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "uuid",
- cls::rbd::MIRROR_IMAGE_STATE_ENABLED},
- librbd::mirror::PROMOTION_STATE_PRIMARY, 0);
-
// open the local image
librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx);
MockOpenLocalImageRequest mock_open_local_image_request;