]> git.proxmox.com Git - ceph.git/blob - ceph/src/test/admin_socket_output.h
update ceph source to reef 18.2.0
[ceph.git] / ceph / src / test / admin_socket_output.h
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 #ifndef CEPH_ADMIN_SOCKET_OUTPUT_H
16 #define CEPH_ADMIN_SOCKET_OUTPUT_H
17
18 #include <filesystem>
19 #include <string>
20 #include <map>
21 #include <set>
22 #include <vector>
23
24 namespace fs = std::filesystem;
25
26 using socket_results = std::map<std::string, std::string>;
27 using test_functions =
28 std::vector<std::pair<std::string, bool (*)(std::string &)>>;
29
30 class AdminSocketClient;
31
32 class AdminSocketOutput {
33 public:
34 AdminSocketOutput() {}
35
36 void add_target(const std::string &target);
37 void add_command(const std::string &target, const std::string &command);
38 void add_test(const std::string &target, const std::string &command,
39 bool (*test)(std::string &));
40 void postpone(const std::string &target, const std::string &command);
41
42 void exec();
43
44 void mod_for_vstart(const std::string& dir) {
45 socketdir = dir;
46 prefix = "";
47 }
48
49 private:
50 bool init_directories() const {
51 std::cout << "Checking " << socketdir << std::endl;
52 return exists(socketdir) && is_directory(socketdir);
53 }
54
55 bool init_sockets();
56 bool gather_socket_output();
57 std::string get_result(const std::string &target, const std::string &command) const;
58
59 std::pair<std::string, std::string>
60 run_command(AdminSocketClient &client, const std::string &raw_command,
61 bool send_untouched = false);
62
63 bool run_tests() const;
64
65 std::set<std::string> targets;
66 std::map<std::string, std::string> sockets;
67 std::map<std::string, socket_results> results;
68 std::map<std::string, std::vector<std::string>> custom_commands;
69 std::map<std::string, std::vector<std::string>> postponed_commands;
70 std::map<std::string, test_functions> tests;
71
72 std::string prefix = "ceph-";
73 fs::path socketdir = "/var/run/ceph";
74 };
75
76 #endif // CEPH_ADMIN_SOCKET_OUTPUT_H