]>
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 <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 | ||
9f95a23c TL |
38 | JSONObjIter iterone = parser.find_first(); |
39 | if (iterone.end()) { //Empty | |
11fdf7f2 TL |
40 | std::cerr << "test_dump_pgstate_history: command output empty, failing" |
41 | << std::endl; | |
42 | return false; | |
43 | } | |
9f95a23c | 44 | |
f67539c2 | 45 | unsigned int total = 0; |
9f95a23c TL |
46 | if ((*iterone)->get_name() == "pgs") { |
47 | JSONObjIter iter = (*(*iterone)->find_first())->find_first(); | |
48 | for (; !iter.end(); ++iter) { | |
49 | if ((*iter)->get_name() == "pg") { | |
50 | ret = !(*iter)->get_data().empty(); | |
51 | if (ret == false) { | |
52 | std::cerr << "test_dump_pgstate_history: pg value empty, failing" | |
53 | << std::endl; | |
54 | std::cerr << "Dumping full output: " << std::endl; | |
55 | std::cerr << output << std::endl; | |
56 | break; | |
57 | } | |
58 | total++; | |
59 | } else if ((*iter)->get_name() == "history") { | |
60 | ret = std::string::npos != (*iter)->get_data().find("epoch") && | |
61 | std::string::npos != (*iter)->get_data().find("state") && | |
62 | std::string::npos != (*iter)->get_data().find("enter") && | |
63 | std::string::npos != (*iter)->get_data().find("exit"); | |
64 | if (ret == false) { | |
65 | std::cerr << "test_dump_pgstate_history: Can't find expected values in " | |
66 | "history object, failing" | |
67 | << std::endl; | |
68 | std::cerr << "Problem output was:" << std::endl; | |
69 | std::cerr << (*iter)->get_data() << std::endl; | |
70 | break; | |
71 | } | |
72 | total++; | |
73 | } else if ((*iter)->get_name() == "currently") { | |
74 | ret = !(*iter)->get_data().empty(); | |
75 | if (ret == false) { | |
76 | std::cerr << "test_dump_pgstate_history: currently value empty, failing" | |
77 | << std::endl; | |
78 | std::cerr << "Dumping full output: " << std::endl; | |
79 | std::cerr << output << std::endl; | |
80 | break; | |
81 | } | |
82 | total++; | |
83 | } else { | |
84 | std::cerr << "test_dump_pgstate_history: unrecognised field " << (*iter)->get_name() | |
85 | << ", failing" << std::endl; | |
31f18b77 FG |
86 | std::cerr << "Dumping full output: " << std::endl; |
87 | std::cerr << output << std::endl; | |
88 | break; | |
89 | } | |
31f18b77 | 90 | } |
9f95a23c TL |
91 | } else { |
92 | std::cerr << "test_dump_pgstate_history: unrecognised format, failing" | |
93 | << std::endl; | |
94 | std::cerr << "Dumping full output: " << std::endl; | |
95 | std::cerr << output << std::endl; | |
96 | return false; | |
31f18b77 | 97 | } |
9f95a23c TL |
98 | |
99 | if (total != 3) { | |
100 | std::cerr << "Could not find required elements, failing" << std::endl; | |
101 | std::cerr << "Dumping full output: " << std::endl; | |
102 | std::cerr << output << std::endl; | |
103 | return false; | |
104 | } | |
105 | ||
31f18b77 FG |
106 | return ret; |
107 | } |