]>
Commit | Line | Data |
---|---|---|
31f18b77 FG |
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", "Modify to run in vstart environment") | |
62 | ; | |
63 | auto parsed = | |
64 | po::command_line_parser(argc, argv).options(desc).allow_unregistered().run(); | |
65 | po::variables_map vm; | |
66 | po::store(parsed, vm); | |
67 | po::notify(vm); | |
68 | ||
69 | auto unrecognised = collect_unrecognized(parsed.options, po::include_positional); | |
70 | if(!unrecognised.empty()) { | |
71 | handle_unrecognised(std::move(unrecognised)); | |
72 | usage(desc); | |
73 | return 1; | |
74 | } | |
75 | if (vm.count("help") || vm.empty()) { | |
76 | usage(desc); | |
77 | return 2; | |
78 | } | |
79 | ||
80 | std::unique_ptr<AdminSocketOutput> asockout(new AdminSocketOutput); | |
81 | ||
82 | if (vm.count("vstart")) { | |
83 | asockout->mod_for_vstart(); | |
84 | } | |
85 | ||
86 | if(vm.count("all")) { | |
87 | asockout->add_target("all"); | |
88 | } else { | |
89 | if (vm.count("osd")) { | |
90 | asockout->add_target("osd"); | |
91 | } | |
92 | if (vm.count("mon")) { | |
93 | asockout->add_target("mon"); | |
94 | } | |
95 | if (vm.count("mgr")) { | |
96 | asockout->add_target("mgr"); | |
97 | } | |
98 | if (vm.count("mds")) { | |
99 | asockout->add_target("mds"); | |
100 | } | |
101 | if (vm.count("client")) { | |
102 | asockout->add_target("client"); | |
103 | } | |
104 | } | |
105 | ||
106 | // Postpone commands that may affect later commands | |
107 | ||
108 | asockout->postpone("mds", "force_readonly"); | |
109 | ||
110 | // Custom commands | |
111 | ||
112 | //Example: | |
113 | //asockout->add_command("osd", R"({"prefix":"config get", "var":"admin_socket"})"); | |
114 | ||
115 | // End custom commands | |
116 | ||
117 | // Tests | |
118 | //Example: | |
119 | //asockout->add_test("osd", R"({"prefix":"config get", "var":"admin_socket"})", test_config_get_admin_socket); | |
120 | ||
121 | asockout->add_test("osd", R"({"prefix":"dump_pgstate_history"})", test_dump_pgstate_history); | |
122 | ||
123 | // End tests | |
124 | ||
125 | asockout->exec(); | |
126 | ||
127 | return 0; | |
128 | } |