]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
config: add test for override ordering, comment
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Thu, 14 Apr 2011 20:45:13 +0000 (13:45 -0700)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Thu, 14 Apr 2011 22:52:53 +0000 (15:52 -0700)
Signed-off-by: Colin McCabe <colin.mccabe@dreamhost.com>
src/common/config.cc
src/test/confutils.cc

index 6596d9a42e8aed3fa9c79473cfcca2c6997fb355..5b678b75d3c3eab80c0b1677cd92050f1b5fc5f6 100644 (file)
@@ -699,6 +699,11 @@ get_val(const char *key, char **buf, int len) const
   return -ENOENT;
 }
 
+/* The order of the sections here is important.  The first section in the
+ * vector is the "highest priority" section; if we find it there, we'll stop
+ * looking. The lowest priority section is the one we look in only if all
+ * others had nothing.  This should always be the global section.
+ */
 void md_config_t::
 get_my_sections(std::vector <std::string> &sections)
 {
index a63d34022c4298f6f8ad80a5ef13c620218b5a6a..875fbbcb7fa51f9337f0b4d3fae8d006cf706021 100644 (file)
@@ -12,6 +12,7 @@
  *
  */
 #include "common/ConfUtils.h"
+#include "common/config.h"
 #include "common/errno.h"
 #include "gtest/gtest.h"
 #include "include/buffer.h"
@@ -245,6 +246,17 @@ const char unicode_config_1[] = "\
 [osd0]\n\
 ";
 
+const char override_config_1[] = "\
+[global]\n\
+        log file =           global_log\n\
+[mds]\n\
+        log file =           mds_log\n\
+[osd]\n\
+        log file =           osd_log\n\
+[osd0]\n\
+        log file =           osd0_log\n\
+";
+
 TEST(Whitespace, ConfUtils) {
   std::string test0("");
   ConfFile::trim_whitespace(test0, false);
@@ -445,3 +457,26 @@ TEST(EscapingFiles, ConfUtils) {
   ASSERT_EQ(cf2.read("mon", "keyring", val), 0);
   ASSERT_EQ(val, "backslash\\");
 }
+
+TEST(Overrides, ConfUtils) {
+  md_config_t conf;
+  std::deque<std::string> err;
+  std::string override_conf_1_f(next_tempfile(override_config_1));
+
+  std::list<std::string> conf_files;
+  conf_files.push_back(override_conf_1_f);
+  conf.name.set(CEPH_ENTITY_TYPE_MON, "0");
+  conf.parse_config_files(conf_files, &err);
+  ASSERT_EQ(err.size(), 0U);
+  ASSERT_EQ(conf.log_file, "global_log");
+
+  conf.name.set(CEPH_ENTITY_TYPE_MDS, "a");
+  conf.parse_config_files(conf_files, &err);
+  ASSERT_EQ(err.size(), 0U);
+  ASSERT_EQ(conf.log_file, "mds_log");
+
+  conf.name.set(CEPH_ENTITY_TYPE_OSD, "0");
+  conf.parse_config_files(conf_files, &err);
+  ASSERT_EQ(err.size(), 0U);
+  ASSERT_EQ(conf.log_file, "osd0_log");
+}