Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / test / system / rados_delete_pools_parallel.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_create_pool.h"
18 #include "st_rados_delete_pool.h"
19 #include "st_rados_list_objects.h"
20 #include "systest_runnable.h"
21 #include "systest_settings.h"
22
23 #include <errno.h>
24 #include <pthread.h>
25 #include <semaphore.h>
26 #include <sstream>
27 #include <stdarg.h>
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string>
31 #include <time.h>
32 #include <vector>
33
34 using std::ostringstream;
35 using std::string;
36 using std::vector;
37
38 static int g_num_objects = 50;
39
40 /*
41  * rados_delete_pools_parallel
42  *
43  * This tests creation and deletion races.
44  *
45  * EXPECT:            * can delete a pool while another user is using it
46  *                    * operations on pools return error codes after the pools
47  *                      are deleted
48  *
49  * DO NOT EXPECT      * hangs, crashes
50  */
51
52 const char *get_id_str()
53 {
54   return "main";
55 }
56
57 int main(int argc, const char **argv)
58 {
59   const char *num_objects = getenv("NUM_OBJECTS");
60   const std::string pool = get_temp_pool_name(argv[0]);
61   if (num_objects) {
62     g_num_objects = atoi(num_objects); 
63     if (g_num_objects == 0)
64       return 100;
65   }
66
67   CrossProcessSem *pool_setup_sem = NULL;
68   RETURN1_IF_NONZERO(CrossProcessSem::create(0, &pool_setup_sem));
69   CrossProcessSem *delete_pool_sem = NULL;
70   RETURN1_IF_NONZERO(CrossProcessSem::create(0, &delete_pool_sem));
71
72   // first test: create a pool, then delete that pool
73   {
74     StRadosCreatePool r1(argc, argv, NULL, pool_setup_sem, NULL,
75                          pool, 50, ".obj");
76     StRadosDeletePool r2(argc, argv, pool_setup_sem, NULL, pool);
77     vector < SysTestRunnable* > vec;
78     vec.push_back(&r1);
79     vec.push_back(&r2);
80     std::string error = SysTestRunnable::run_until_finished(vec);
81     if (!error.empty()) {
82       printf("test1: got error: %s\n", error.c_str());
83       return EXIT_FAILURE;
84     }
85   }
86
87   // second test: create a pool, the list objects in that pool while it's
88   // being deleted.
89   RETURN1_IF_NONZERO(pool_setup_sem->reinit(0));
90   RETURN1_IF_NONZERO(delete_pool_sem->reinit(0));
91   {
92     StRadosCreatePool r1(argc, argv, NULL, pool_setup_sem, NULL,
93                          pool, g_num_objects, ".obj");
94     StRadosDeletePool r2(argc, argv, delete_pool_sem, NULL, pool);
95     StRadosListObjects r3(argc, argv, pool, true, g_num_objects / 2,
96                           pool_setup_sem, NULL, delete_pool_sem);
97     vector < SysTestRunnable* > vec;
98     vec.push_back(&r1);
99     vec.push_back(&r2);
100     vec.push_back(&r3);
101     std::string error = SysTestRunnable::run_until_finished(vec);
102     if (!error.empty()) {
103       printf("test2: got error: %s\n", error.c_str());
104       return EXIT_FAILURE;
105     }
106   }
107
108   printf("******* SUCCESS **********\n"); 
109   return EXIT_SUCCESS;
110 }