]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
common/TextTable: default to 2 spaces separating columns
authorSage Weil <sage@redhat.com>
Sat, 8 Feb 2020 19:13:11 +0000 (13:13 -0600)
committerSage Weil <sage@redhat.com>
Sun, 23 Feb 2020 21:46:30 +0000 (15:46 -0600)
This is what other projects and libraries default to, and it is more
legible.

Signed-off-by: Sage Weil <sage@redhat.com>
qa/standalone/crush/crush-choose-args.sh
qa/workunits/mon/config.sh
src/common/TextTable.cc
src/common/TextTable.h
src/test/test_texttable.cc

index d2c33cfed26226ffd3ac36fdea2893726b3789e2..daadc2a85711e45acd019bcb4c7b4f2bc59cc0e1 100755 (executable)
@@ -176,19 +176,19 @@ function TEST_reweight() {
 
     ceph osd crush weight-set reweight-compat osd.0 2 || return 1
     ceph osd crush tree
-    ceph osd crush tree | grep host | grep '6.00000  5.00000' || return 1
+    ceph osd crush tree | grep host | grep '6.00000   5.00000' || return 1
 
     run_osd $dir 2 || return 1
     ceph osd crush tree
-    ceph osd crush tree | grep host | grep '9.00000  5.00000' || return 1
+    ceph osd crush tree | grep host | grep '9.00000   5.00000' || return 1
 
     ceph osd crush reweight osd.2 4
     ceph osd crush tree
-    ceph osd crush tree | grep host | grep '10.00000  5.00000' || return 1
+    ceph osd crush tree | grep host | grep '10.00000   5.00000' || return 1
 
     ceph osd crush weight-set reweight-compat osd.2 4
     ceph osd crush tree
-    ceph osd crush tree | grep host | grep '10.00000  9.00000' || return 1
+    ceph osd crush tree | grep host | grep '10.00000   9.00000' || return 1
 }
 
 function TEST_move_bucket() {
@@ -203,37 +203,37 @@ function TEST_move_bucket() {
     ceph osd crush weight-set reweight-compat osd.0 2 || return 1
     ceph osd crush weight-set reweight-compat osd.1 2 || return 1
     ceph osd crush tree
-    ceph osd crush tree | grep HOST | grep '6.00000  4.00000' || return 1
+    ceph osd crush tree | grep HOST | grep '6.00000   4.00000' || return 1
 
     # moving a bucket adjusts the weights
     ceph osd crush add-bucket RACK rack root=default || return 1
     ceph osd crush move HOST rack=RACK || return 1
     ceph osd crush tree
-    ceph osd crush tree | grep HOST | grep '6.00000  4.00000' || return 1
-    ceph osd crush tree | grep RACK | grep '6.00000  4.00000' || return 1
+    ceph osd crush tree | grep HOST | grep '6.00000   4.00000' || return 1
+    ceph osd crush tree | grep RACK | grep '6.00000   4.00000' || return 1
 
     # weight-set reweight adjusts containing buckets
     ceph osd crush weight-set reweight-compat osd.0 1 || return 1
     ceph osd crush tree
-    ceph osd crush tree | grep HOST | grep '6.00000  3.00000' || return 1
-    ceph osd crush tree | grep RACK | grep '6.00000  3.00000' || return 1
+    ceph osd crush tree | grep HOST | grep '6.00000   3.00000' || return 1
+    ceph osd crush tree | grep RACK | grep '6.00000   3.00000' || return 1
 
     # moving a leaf resets its weight-set to the canonical weight...
     ceph config set mon osd_crush_update_weight_set true || return 1
     ceph osd crush add-bucket FOO host root=default || return 1
     ceph osd crush move osd.0 host=FOO || return 1
     ceph osd crush tree
-    ceph osd crush tree | grep osd.0 | grep '3.00000  3.00000' || return 1
-    ceph osd crush tree | grep HOST | grep '3.00000  2.00000' || return 1
-    ceph osd crush tree | grep RACK | grep '3.00000  2.00000' || return 1
+    ceph osd crush tree | grep osd.0 | grep '3.00000   3.00000' || return 1
+    ceph osd crush tree | grep HOST | grep '3.00000   2.00000' || return 1
+    ceph osd crush tree | grep RACK | grep '3.00000   2.00000' || return 1
 
     # ...or to zero.
     ceph config set mon osd_crush_update_weight_set false || return 1
     ceph osd crush move osd.1 host=FOO || return 1
     ceph osd crush tree
-    ceph osd crush tree | grep osd.0 | grep '3.00000  3.00000' || return 1
-    ceph osd crush tree | grep osd.1 | grep '3.00000        0' || return 1
-    ceph osd crush tree | grep FOO | grep '6.00000  3.00000' || return 1
+    ceph osd crush tree | grep osd.0 | grep '3.00000   3.00000' || return 1
+    ceph osd crush tree | grep osd.1 | grep '3.00000         0' || return 1
+    ceph osd crush tree | grep FOO | grep '6.00000   3.00000' || return 1
 }
 
 main crush-choose-args "$@"
index 981927bd0a5480f5de1af7e1cb4702bcae1e1609..36eab8f7ba3236fa3ac1f571c45711b62c179a8b 100755 (executable)
@@ -82,7 +82,7 @@ while ! ceph config show osd.0 | grep debug_asok | grep 99
 do
     sleep 1
 done
-ceph config show osd.0 | grep debug_asok | grep 'override mon'
+ceph config show osd.0 | grep debug_asok | grep 'override  mon'
 ceph tell osd.0 config unset debug_asok
 ceph tell osd.0 config unset debug_asok
 
index c94719a9589b5f6dc8c1365c1919e1469ab4f81a..8973c9e756cdfc93d1ea8ac41e5255171666e0d1 100644 (file)
@@ -70,7 +70,7 @@ std::ostream &operator<<(std::ostream &out, const TextTable &t)
     TextTable::TextTableColumn col = t.col[i];
     out << string(t.indent, ' ')
         << pad(col.heading, col.width, col.hd_align)
-       << ' ';
+       << t.column_separation;
   }
   out << endl;
 
@@ -79,7 +79,7 @@ std::ostream &operator<<(std::ostream &out, const TextTable &t)
       TextTable::TextTableColumn col = t.col[j];
       out << string(t.indent, ' ')
          << pad(t.row[i][j], col.width, col.col_align)
-         << ' ';
+         << t.column_separation;
     }
     out << endl;
   }
index 2d6ad3cc0b1d2459a2c16ffb03c39954d5af32ef..6702c00575cf7bf77470ffb290a0f3a5d8884397 100644 (file)
@@ -53,6 +53,7 @@ private:
   std::vector<TextTableColumn> col;    // column definitions
   unsigned int curcol, currow;         // col, row being inserted into
   unsigned int indent;                 // indent width when rendering
+  std::string column_separation = {"  "};
 
 protected:
   std::vector<std::vector<std::string> > row;  // row data array
@@ -82,6 +83,15 @@ public:
    */
   void set_indent(int i) { indent = i; }
 
+  /**
+   * Set column separation
+   *
+   * @param s String to separate columns
+   */
+  void set_column_separation(const std::string& s) {
+    column_separation = s;
+  }
+
   /**
    * Add item to table, perhaps on new row.
    * table << val1 << val2 << TextTable::endrow;
index 0d439d16c9c9b1a369f595d72fffb9afdc9ed5a4..25a82449c731c660486c90e56e1dcac102dfb33d 100644 (file)
@@ -29,7 +29,7 @@ TEST(TextTable, Alignment) {
   t << "1" << 2 << 3 << TextTable::endrow;
   std::ostringstream oss;
   oss << t;
-  ASSERT_STREQ("HEAD1 HEAD2 HEAD3 \n1       2       3 \n", oss.str().c_str());
+  ASSERT_STREQ("HEAD1  HEAD2  HEAD3  \n1        2        3  \n", oss.str().c_str());
 }
 
 TEST(TextTable, WidenAndClearShrink) {
@@ -43,14 +43,14 @@ TEST(TextTable, WidenAndClearShrink) {
   // validate wide output
   std::ostringstream oss;
   oss << t;
-  ASSERT_STREQ("1     \nwider \n", oss.str().c_str());
+  ASSERT_STREQ("1      \nwider  \n", oss.str().c_str());
   oss.str("");
 
   // reset, validate single-char width output
   t.clear();
   t << "s";
   oss << t;
-  ASSERT_STREQ("1 \ns \n", oss.str().c_str());
+  ASSERT_STREQ("1  \ns  \n", oss.str().c_str());
 }
 
 TEST(TextTable, Indent) {
@@ -61,7 +61,7 @@ TEST(TextTable, Indent) {
   t << "s";
   std::ostringstream oss;
   oss << t;
-  ASSERT_STREQ("          1 \n          s \n", oss.str().c_str());
+  ASSERT_STREQ("          1  \n          s  \n", oss.str().c_str());
 }