From: Jason Dillaman Date: Tue, 20 Oct 2020 21:05:30 +0000 (-0400) Subject: librbd: tweak native-format migration source-spec X-Git-Tag: v17.0.0~734^2~18 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=c87fe97761909dcffb876f3e98c850399b564e38;p=ceph.git librbd: tweak native-format migration source-spec Renamed "format" property to "type" and always include the original "image_id". Signed-off-by: Jason Dillaman --- diff --git a/src/librbd/migration/NativeFormat.cc b/src/librbd/migration/NativeFormat.cc index d7112b1fe6b4d..b6e0282341463 100644 --- a/src/librbd/migration/NativeFormat.cc +++ b/src/librbd/migration/NativeFormat.cc @@ -20,18 +20,27 @@ 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 std::string NativeFormat::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); } diff --git a/src/test/librbd/test_librbd.cc b/src/test/librbd/test_librbd.cc index fa556fc6a6f33..bbd400713632a 100644 --- a/src/test/librbd/test_librbd.cc +++ b/src/test/librbd/test_librbd.cc @@ -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());