Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / test / librbd / test_fixture.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 #include "include/int_types.h"
4 #include "include/rados/librados.h"
5 #include "include/rbd/librbd.hpp"
6 #include "librbd/ImageCtx.h"
7 #include "gtest/gtest.h"
8 #include <set>
9 #include <string>
10
11 using namespace ceph;
12
13 class TestFixture : public ::testing::Test {
14 public:
15
16   TestFixture();
17
18   static void SetUpTestCase();
19   static void TearDownTestCase();
20
21   static std::string get_temp_image_name();
22
23   void SetUp() override;
24   void TearDown() override;
25
26   int open_image(const std::string &image_name, librbd::ImageCtx **ictx);
27   void close_image(librbd::ImageCtx *ictx);
28
29   int snap_create(librbd::ImageCtx &ictx, const std::string &snap_name);
30   int snap_protect(librbd::ImageCtx &ictx, const std::string &snap_name);
31
32   int flatten(librbd::ImageCtx &ictx, librbd::ProgressContext &prog_ctx);
33
34   int lock_image(librbd::ImageCtx &ictx, ClsLockType lock_type,
35                  const std::string &cookie);
36   int unlock_image();
37
38   int acquire_exclusive_lock(librbd::ImageCtx &ictx);
39
40   static std::string _pool_name;
41   static librados::Rados _rados;
42   static rados_t _cluster;
43   static uint64_t _image_number;
44   static std::string _data_pool;
45
46   librados::IoCtx m_ioctx;
47   librbd::RBD m_rbd;
48
49   std::string m_image_name;
50   uint64_t m_image_size;
51
52   std::set<librbd::ImageCtx *> m_ictxs;
53
54   std::string m_lock_object;
55   std::string m_lock_cookie;
56 };