]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crushtool: add --show-location <id> command 2582/head
authorSage Weil <sage@redhat.com>
Sat, 27 Sep 2014 14:51:24 +0000 (07:51 -0700)
committerSage Weil <sage@redhat.com>
Sat, 27 Sep 2014 14:51:24 +0000 (07:51 -0700)
Include some tests.

Signed-off-by: Sage Weil <sage@redhat.com>
src/test/cli/crushtool/add-item.t
src/test/cli/crushtool/help.t
src/test/cli/crushtool/location.t [new file with mode: 0644]
src/test/cli/crushtool/test-map-big-1.crushmap [new file with mode: 0644]
src/tools/crushtool.cc

index f058b639c6144f721c3684fefc1f9e41f73537cd..0dd43c8bb7c556ab7c807189af28ee249a84a11b 100644 (file)
@@ -11,5 +11,8 @@
   $ crushtool -d five -o final
   $ cmp final "$TESTDIR/simple.template.five"
   $ crushtool -i five --update-item 1 2.0 osd1 --loc host host1 --loc cluster cluster0 -o six > /dev/null
+  $ crushtool -i five --show-location 1
+  cluster\tcluster0 (esc)
+  host\thost1 (esc)
   $ crushtool -d six -o final
   $ cmp final "$TESTDIR/simple.template.five"
index 3b489301c48d6837c499be5a45c60f8abaf12dad..9d7c8cc7c135ae146c52bb802122831ab30b8bc6 100644 (file)
@@ -29,6 +29,8 @@
                            reweight a given item (and adjust ancestor
                            weights as needed)
      -i mapfn --reweight   recalculate all bucket weights
+     -i mapfn --show-location id
+                           show location for given device id
      --show-utilization    show OSD usage
      --show utilization-all
                            include zero weight items
diff --git a/src/test/cli/crushtool/location.t b/src/test/cli/crushtool/location.t
new file mode 100644 (file)
index 0000000..4252f5c
--- /dev/null
@@ -0,0 +1,16 @@
+  $ crushtool -i $TESTDIR/test-map-big-1.crushmap --show-location 44
+  $ crushtool -i $TESTDIR/test-map-big-1.crushmap --show-location 16
+  $ crushtool -i $TESTDIR/test-map-big-1.crushmap --show-location 167
+  host\tp05151113587529 (esc)
+  rack\tRJ45 (esc)
+  room\t0513-R-0050 (esc)
+  root\tdefault (esc)
+  $ crushtool -i $TESTDIR/test-map-big-1.crushmap --show-location 258
+  host\tlxfssi44a06 (esc)
+  rack\tSI44 (esc)
+  root\tcastor (esc)
+  $ crushtool -i $TESTDIR/test-map-big-1.crushmap --show-location 87
+  host\tp05151113576052 (esc)
+  rack\tRJ43 (esc)
+  room\t0513-R-0050 (esc)
+  root\tdefault (esc)
diff --git a/src/test/cli/crushtool/test-map-big-1.crushmap b/src/test/cli/crushtool/test-map-big-1.crushmap
new file mode 100644 (file)
index 0000000..e0b0ae9
Binary files /dev/null and b/src/test/cli/crushtool/test-map-big-1.crushmap differ
index ccb0efda74a7c7d57b7158520e95347daa716073..b520255af24ad3d6c0355487e94a4ae4826fc836 100644 (file)
@@ -114,6 +114,8 @@ void usage()
   cout << "                         reweight a given item (and adjust ancestor\n"
        << "                         weights as needed)\n";
   cout << "   -i mapfn --reweight   recalculate all bucket weights\n";
+  cout << "   -i mapfn --show-location id\n";
+  cout << "                         show location for given device id\n";
   cout << "   --show-utilization    show OSD usage\n";
   cout << "   --show utilization-all\n";
   cout << "                         include zero weight items\n";
@@ -168,6 +170,7 @@ int main(int argc, const char **argv)
   bool decompile = false;
   bool test = false;
   bool display = false;
+  int full_location = -1;
   bool write_to_file = false;
   int verbose = 0;
   bool unsafe_tunables = false;
@@ -244,6 +247,7 @@ int main(int argc, const char **argv)
       compile = true;
     } else if (ceph_argparse_flag(args, i, "-t", "--test", (char*)NULL)) {
       test = true;
+    } else if (ceph_argparse_withint(args, i, &full_location, &err, "--show-location", (char*)NULL)) {
     } else if (ceph_argparse_flag(args, i, "-s", "--simulate", (char*)NULL)) {
       tester.set_random_placement();
     } else if (ceph_argparse_flag(args, i, "--enable-unsafe-tunables", (char*)NULL)) {
@@ -431,7 +435,7 @@ int main(int argc, const char **argv)
     exit(EXIT_FAILURE);
   }
   if (!compile && !decompile && !build && !test && !reweight && !adjust &&
-      add_item < 0 &&
+      add_item < 0 && full_location < 0 &&
       remove_name.empty() && reweight_name.empty()) {
     cerr << "no action specified; -h for help" << std::endl;
     exit(EXIT_FAILURE);
@@ -477,6 +481,15 @@ int main(int argc, const char **argv)
     crush.decode(p);
   }
 
+  if (full_location >= 0) {
+    map<string, string> loc = crush.get_full_location(full_location);
+    for (map<string,string>::iterator p = loc.begin();
+        p != loc.end();
+        ++p) {
+      cout << p->first << "\t" << p->second << std::endl;
+    }
+    exit(0);
+  }
   if (decompile) {
     CrushCompiler cc(crush, cerr, verbose);
     if (!outfn.empty()) {