summaryrefslogtreecommitdiffstats
path: root/src/test/test_admin_socket_output.cc
blob: 9ce244e6341f8ec1835cfda41c9e52c0f7850fe1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
/*
 * Ceph - scalable distributed file system
 *
 * Copyright (C) 2017 Red Hat
 *
 * This is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License version 2.1, as published by the Free Software
 * Foundation.  See file COPYING.
 *
 */

#include <algorithm>                                      // for move
#include <iostream>                                       // for ostream
#include <memory>                                         // for unique_ptr
#include <string>                                         // for operator<<
#include <vector>                                         // for vector
#include <boost/program_options/option.hpp>               // for program_opt...
#include <boost/program_options/options_description.hpp>  // for options_des...
#include <boost/program_options/parsers.hpp>              // for basic_comma...
#include <boost/program_options/variables_map.hpp>        // for variables_map
#include <boost/program_options/parsers.hpp>              // for basic_comma...

#include "admin_socket_output.h"
#include "admin_socket_output_tests.h"

namespace po = boost::program_options;

void usage(po::options_description desc) {
  std::cout << desc << std::endl;
}

void handle_unrecognised(std::vector<std::string>&& unrecognised) {
  for (auto& un : unrecognised) {
    std::cout << "Unrecognized Parameter: " << un << std::endl;
  }
}

// Test functions:
// See admin_socket_output_tests.h

int main(int argc, char** argv) {

  po::options_description desc("Allowed options");
  desc.add_options()
    ("help,h", "produce help message")
    ("all", "implies"
     " --osd"
     " --mon"
     " --mgr"
     " --mds"
     " --client"
     " --vstart")
    ("osd", "Test osd admin socket output")
    ("mon", "Test mon admin socket output")
    ("mgr", "Test mgr admin socket output")
    ("mds", "Test mds admin socket output")
    ("client", "Test client (includes rgw) admin socket output")
    ("vstart", po::value<std::string>()->implicit_value("./out"),
     "Modify to run in vstart environment")
    ;
  auto parsed =
    po::command_line_parser(argc, argv).options(desc).allow_unregistered().run();
  po::variables_map vm;
  po::store(parsed, vm);
  po::notify(vm);

  auto unrecognised = collect_unrecognized(parsed.options, po::include_positional);
  if(!unrecognised.empty()) {
    handle_unrecognised(std::move(unrecognised));
    usage(desc);
    return 1;
  }
  if (vm.count("help") || vm.empty()) {
    usage(desc);
    return 2;
  }

  std::unique_ptr<AdminSocketOutput> asockout(new AdminSocketOutput);

  if (vm.count("vstart")) {
    asockout->mod_for_vstart(vm["vstart"].as<std::string>());
  }

  if(vm.count("all")) {
    asockout->add_target("all");
  } else {
    if (vm.count("osd")) {
      asockout->add_target("osd");
    }
    if (vm.count("mon")) {
      asockout->add_target("mon");
    }
    if (vm.count("mgr")) {
      asockout->add_target("mgr");
    }
    if (vm.count("mds")) {
      asockout->add_target("mds");
    }
    if (vm.count("client")) {
      asockout->add_target("client");
    }
  }

  // Postpone commands that may affect later commands

  asockout->postpone("mds", "force_readonly");

  // Custom commands

  //Example:
  //asockout->add_command("osd", R"({"prefix":"config get", "var":"admin_socket"})");

  // End custom commands

  // Tests
  //Example:
  //asockout->add_test("osd", R"({"prefix":"config get", "var":"admin_socket"})", test_config_get_admin_socket);

  asockout->add_test("osd", R"({"prefix":"dump_pgstate_history"})", test_dump_pgstate_history);

  // End tests

  asockout->exec();

  return 0;
}