]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crush/CrushTester: allow testing by ruleset
authorSage Weil <sage@redhat.com>
Fri, 18 Sep 2015 13:40:13 +0000 (09:40 -0400)
committerLoic Dachary <ldachary@redhat.com>
Wed, 7 Oct 2015 15:37:35 +0000 (17:37 +0200)
Signed-off-by: Sage Weil <sage@redhat.com>
(cherry picked from commit aa238e5ed50f44a94caf84567267e4f6be8732a2)

Conflicts:
src/crush/CrushTester.cc
          in hammer the crushtool validation is via a shell
  and not via an internal subprocess utility
src/tools/crushtool.cc
  ceph_argparse_withint is preferred to ceph_argparse_witharg

src/crush/CrushTester.cc
src/crush/CrushTester.h
src/tools/crushtool.cc

index 9aada7b1eb938d5a067917f02ffe88bcd9eddaad..24db70ee6d8132be712dc700399a216f44c81e56 100644 (file)
@@ -359,7 +359,8 @@ void CrushTester::write_integer_indexed_scalar_data_string(vector<string> &dst,
 
 int CrushTester::test_with_crushtool(const string& crushtool,
                                      int max_id,
-                                     int timeout)
+                                     int timeout,
+                                    int ruleset)
 {
   string timeout_string = stringify(timeout);
   string opt_max_id = stringify(max_id);
@@ -372,6 +373,10 @@ int CrushTester::test_with_crushtool(const string& crushtool,
   cmd_args.push_back("--test");
   cmd_args.push_back("--check");
   cmd_args.push_back(opt_max_id.c_str());
+  if (ruleset >= 0) {
+    cmd_args.push_back("--ruleset");
+    cmd_args.push_back(stringify(ruleset).c_str());
+  }
   cmd_args.push_back(NULL);
 
   int pipefds[2];
@@ -539,6 +544,10 @@ int CrushTester::test()
         err << "rule " << r << " dne" << std::endl;
       continue;
     }
+    if (ruleset >= 0 &&
+       crush.get_rule_mask_ruleset(r) != ruleset) {
+      continue;
+    }
     int minr = min_rep, maxr = max_rep;
     if (min_rep < 0 || max_rep < 0) {
       minr = crush.get_rule_mask_min_size(r);
index 4f90aae940bc3ba798cdce244bbe294e44668b52..a9221c7be0204dbbbecdd6400e443417061449e4 100644 (file)
@@ -15,6 +15,7 @@ class CrushTester {
 
   map<int, int> device_weight;
   int min_rule, max_rule;
+  int ruleset;
   int min_x, max_x;
   int min_rep, max_rep;
 
@@ -168,6 +169,7 @@ public:
   CrushTester(CrushWrapper& c, ostream& eo)
     : crush(c), err(eo),
       min_rule(-1), max_rule(-1),
+      ruleset(-1),
       min_x(-1), max_x(-1),
       min_rep(-1), max_rep(-1),
       num_batches(1),
@@ -333,6 +335,10 @@ public:
     min_rule = max_rule = rule;
   }
 
+  void set_ruleset(int rs) {
+    ruleset = rs;
+  }
+
   /**
    * check if any bucket/nodes is referencing an unknown name or type
    * @param max_id rejects any non-bucket items with id less than this number,
@@ -344,7 +350,8 @@ public:
   int test();
   int test_with_crushtool(const string& crushtool,
                          int max_id = -1,
-                         int timeout = 0);
+                         int timeout = 0,
+                         int ruleset = -1);
 };
 
 #endif
index 3e36ac9870401c6aaa79b03df4e7ce79b5e081d5..d576b5ef83093cda68138986cb8a4e897597fb93 100644 (file)
@@ -433,6 +433,12 @@ int main(int argc, const char **argv)
        exit(EXIT_FAILURE);
       }
       tester.set_rule(x);
+    } else if (ceph_argparse_withint(args, i, &x, &err, "--ruleset", (char*)NULL)) {
+      if (!err.str().empty()) {
+       cerr << err.str() << std::endl;
+       exit(EXIT_FAILURE);
+      }
+      tester.set_ruleset(x);
     } else if (ceph_argparse_withint(args, i, &x, &err, "--batches", (char*)NULL)) {
       if (!err.str().empty()) {
        cerr << err.str() << std::endl;