]> git.proxmox.com Git - ceph.git/blob - ceph/src/test/test_admin_socket_output.cc
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / test / test_admin_socket_output.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) 2017 Red Hat
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 <algorithm> // for move
16 #include <iostream> // for ostream
17 #include <memory> // for unique_ptr
18 #include <string> // for operator<<
19 #include <vector> // for vector
20 #include <boost/program_options/option.hpp> // for program_opt...
21 #include <boost/program_options/options_description.hpp> // for options_des...
22 #include <boost/program_options/parsers.hpp> // for basic_comma...
23 #include <boost/program_options/variables_map.hpp> // for variables_map
24 #include <boost/program_options/parsers.hpp> // for basic_comma...
25
26 #include "admin_socket_output.h"
27 #include "admin_socket_output_tests.h"
28
29 namespace po = boost::program_options;
30
31 void usage(po::options_description desc) {
32 std::cout << desc << std::endl;
33 }
34
35 void handle_unrecognised(std::vector<std::string>&& unrecognised) {
36 for (auto& un : unrecognised) {
37 std::cout << "Unrecognized Parameter: " << un << std::endl;
38 }
39 }
40
41 // Test functions:
42 // See admin_socket_output_tests.h
43
44 int main(int argc, char** argv) {
45
46 po::options_description desc("Allowed options");
47 desc.add_options()
48 ("help,h", "produce help message")
49 ("all", "implies"
50 " --osd"
51 " --mon"
52 " --mgr"
53 " --mds"
54 " --client"
55 " --vstart")
56 ("osd", "Test osd admin socket output")
57 ("mon", "Test mon admin socket output")
58 ("mgr", "Test mgr admin socket output")
59 ("mds", "Test mds admin socket output")
60 ("client", "Test client (includes rgw) admin socket output")
61 ("vstart", po::value<std::string>()->implicit_value("./out"),
62 "Modify to run in vstart environment")
63 ;
64 auto parsed =
65 po::command_line_parser(argc, argv).options(desc).allow_unregistered().run();
66 po::variables_map vm;
67 po::store(parsed, vm);
68 po::notify(vm);
69
70 auto unrecognised = collect_unrecognized(parsed.options, po::include_positional);
71 if(!unrecognised.empty()) {
72 handle_unrecognised(std::move(unrecognised));
73 usage(desc);
74 return 1;
75 }
76 if (vm.count("help") || vm.empty()) {
77 usage(desc);
78 return 2;
79 }
80
81 std::unique_ptr<AdminSocketOutput> asockout(new AdminSocketOutput);
82
83 if (vm.count("vstart")) {
84 asockout->mod_for_vstart(vm["vstart"].as<std::string>());
85 }
86
87 if(vm.count("all")) {
88 asockout->add_target("all");
89 } else {
90 if (vm.count("osd")) {
91 asockout->add_target("osd");
92 }
93 if (vm.count("mon")) {
94 asockout->add_target("mon");
95 }
96 if (vm.count("mgr")) {
97 asockout->add_target("mgr");
98 }
99 if (vm.count("mds")) {
100 asockout->add_target("mds");
101 }
102 if (vm.count("client")) {
103 asockout->add_target("client");
104 }
105 }
106
107 // Postpone commands that may affect later commands
108
109 asockout->postpone("mds", "force_readonly");
110
111 // Custom commands
112
113 //Example:
114 //asockout->add_command("osd", R"({"prefix":"config get", "var":"admin_socket"})");
115
116 // End custom commands
117
118 // Tests
119 //Example:
120 //asockout->add_test("osd", R"({"prefix":"config get", "var":"admin_socket"})", test_config_get_admin_socket);
121
122 asockout->add_test("osd", R"({"prefix":"dump_pgstate_history"})", test_dump_pgstate_history);
123
124 // End tests
125
126 asockout->exec();
127
128 return 0;
129 }