]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: tweak native-format migration source-spec
authorJason Dillaman <dillaman@redhat.com>
Tue, 20 Oct 2020 21:05:30 +0000 (17:05 -0400)
committerJason Dillaman <dillaman@redhat.com>
Sun, 1 Nov 2020 14:22:38 +0000 (09:22 -0500)
Renamed "format" property to "type" and always include the original
"image_id".

Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/librbd/migration/NativeFormat.cc
src/test/librbd/test_librbd.cc

index d7112b1fe6b4dc6d7e7c5c38fabeb5e69b78484a..b6e0282341463af51a59b81f97a542ee83e7890d 100644 (file)
 namespace librbd {
 namespace migration {
 
+namespace {
+
+const std::string TYPE_KEY{"type"};
+const std::string POOL_ID_KEY{"pool_id"};
+const std::string POOL_NAMESPACE_KEY{"pool_namespace"};
+const std::string IMAGE_NAME_KEY{"image_name"};
+const std::string IMAGE_ID_KEY{"image_id"};
+
+} // anonymous namespace
+
 template <typename I>
 std::string NativeFormat<I>::build_source_spec(
     int64_t pool_id, const std::string& pool_namespace,
     const std::string& image_name, const std::string& image_id) {
   json_spirit::mObject source_spec;
-  source_spec["type"] = "native";
-  source_spec["pool_id"] = pool_id;
-  source_spec["pool_namespace"] = pool_namespace;
+  source_spec[TYPE_KEY] = "native";
+  source_spec[POOL_ID_KEY] = pool_id;
+  source_spec[POOL_NAMESPACE_KEY] = pool_namespace;
+  source_spec[IMAGE_NAME_KEY] = image_name;
   if (!image_id.empty()) {
-    source_spec["image_id"] = image_id;
-  } else {
-    source_spec["image_name"] = image_name;
+    source_spec[IMAGE_ID_KEY] = image_id;
   }
   return json_spirit::write(source_spec);
 }
index fa556fc6a6f3323ed4b25537b5c3cad8dace2bc6..bbd400713632afe219754c57e47ff436dff578d8 100644 (file)
@@ -7452,11 +7452,11 @@ TEST_F(TestLibRBD, MigrationPP) {
   json_spirit::mValue json_source_spec;
   json_spirit::read(source_spec, json_source_spec);
   json_spirit::mObject json_source_spec_obj = json_source_spec.get_obj();
+  ASSERT_EQ("native", json_source_spec_obj["type"].get_str());
   ASSERT_EQ(ioctx.get_id(), json_source_spec_obj["pool_id"].get_int64());
   ASSERT_EQ("", json_source_spec_obj["pool_namespace"].get_str());
-  if (old_format) {
-    ASSERT_EQ(1, json_source_spec_obj.count("image_name"));
-  } else {
+  ASSERT_EQ(1, json_source_spec_obj.count("image_name"));
+  if (!old_format) {
     ASSERT_EQ(1, json_source_spec_obj.count("image_id"));
   }
   ASSERT_EQ(0, image.close());