Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / test / system / st_rados_delete_pool.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2011 New Dream Network
7 *
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation.  See file COPYING.
12 *
13 */
14
15 #include "cross_process_sem.h"
16 #include "include/rados/librados.h"
17 #include "st_rados_delete_pool.h"
18 #include "systest_runnable.h"
19 #include "systest_settings.h"
20
21 #include <errno.h>
22
23 StRadosDeletePool::StRadosDeletePool(int argc, const char **argv,
24                                      CrossProcessSem *pool_setup_sem,
25                                      CrossProcessSem *delete_pool_sem,
26                                      const std::string &pool_name)
27     : SysTestRunnable(argc, argv),
28       m_pool_setup_sem(pool_setup_sem),
29       m_delete_pool_sem(delete_pool_sem),
30       m_pool_name(pool_name)
31 {
32 }
33
34 StRadosDeletePool::~StRadosDeletePool()
35 {
36 }
37
38 int StRadosDeletePool::run()
39 {
40   rados_t cl;
41   RETURN1_IF_NONZERO(rados_create(&cl, NULL));
42   rados_conf_parse_argv(cl, m_argc, m_argv);
43   RETURN1_IF_NONZERO(rados_conf_read_file(cl, NULL));
44   rados_conf_parse_env(cl, NULL);
45   RETURN1_IF_NONZERO(rados_connect(cl));
46   m_pool_setup_sem->wait();
47   m_pool_setup_sem->post();
48
49   rados_ioctx_t io_ctx;
50   rados_pool_create(cl, m_pool_name.c_str());
51   RETURN1_IF_NONZERO(rados_ioctx_create(cl, m_pool_name.c_str(), &io_ctx));
52   rados_ioctx_destroy(io_ctx);
53   printf("%s: deleting pool %s\n", get_id_str(), m_pool_name.c_str());
54   RETURN1_IF_NONZERO(rados_pool_delete(cl, m_pool_name.c_str()));
55   if (m_delete_pool_sem)
56     m_delete_pool_sem->post();
57   rados_shutdown(cl);
58   return 0;
59 }