]> git.proxmox.com Git - ceph.git/blob - ceph/src/test/admin_socket_output_tests.cc
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / test / admin_socket_output_tests.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 <string>
16 #include <iostream>
17
18 #include "common/ceph_json.h"
19
20 // Test functions
21
22 // Example test function
23 /*
24 bool test_config_get_admin_socket(std::string& output) {
25 return std::string::npos != output.find("admin_socket") &&
26 std::string::npos != output.rfind(".asok");
27 }
28 */
29
30 bool test_dump_pgstate_history(std::string &output) {
31 JSONParser parser;
32 bool ret = parser.parse(output.c_str(), output.size());
33 if (!ret) {
34 std::cerr << "test_dump_pgstate_history: parse error" << std::endl;
35 return false;
36 }
37
38 JSONObjIter iter = parser.find_first();
39 if (iter.end()) { //Empty
40 std::cerr << "test_dump_pgstate_history: command output empty, failing"
41 << std::endl;
42 return false;
43 }
44 for (; !iter.end(); ++iter) {
45 if ((*iter)->get_name() == "pg") {
46 ret = !(*iter)->get_data().empty();
47 if (ret == false) {
48 std::cerr << "test_dump_pgstate_history: pg value empty, failing"
49 << std::endl;
50 std::cerr << "Dumping full output: " << std::endl;
51 std::cerr << output << std::endl;
52 break;
53 }
54 } else if ((*iter)->get_name() == "history") {
55 ret = std::string::npos != (*iter)->get_data().find("epoch") &&
56 std::string::npos != (*iter)->get_data().find("state") &&
57 std::string::npos != (*iter)->get_data().find("Initial") &&
58 std::string::npos != (*iter)->get_data().find("enter") &&
59 std::string::npos != (*iter)->get_data().find("exit");
60 if (ret == false) {
61 std::cerr << "test_dump_pgstate_history: Can't find expected values in "
62 "history object, failing"
63 << std::endl;
64 std::cerr << "Problem output was:" << std::endl;
65 std::cerr << (*iter)->get_data() << std::endl;
66 break;
67 }
68 }
69 }
70 return ret;
71 }