From: Piotr Bartosiewicz Date: Mon, 26 Jan 2015 10:37:03 +0000 (+0100) Subject: Create zone api method support templateName parameter X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5ff143397f8038c6c292e00c22a44bca1bfdc9df;p=platform%2Fcore%2Fsecurity%2Fvasum.git Create zone api method support templateName parameter [Bug/Feature] Not implemented create zone parameter [Cause] N/A [Solution] N/A [Verification] Build, run tests Change-Id: I5dff390db6b82927b1f8f300f82212c2a534a571 --- diff --git a/client/vasum-client-impl.cpp b/client/vasum-client-impl.cpp index 9ca5de5..d27fad3 100644 --- a/client/vasum-client-impl.cpp +++ b/client/vasum-client-impl.cpp @@ -444,12 +444,9 @@ VsmStatus Client::vsm_set_active_zone(const char* id) noexcept VsmStatus Client::vsm_create_zone(const char* id, const char* tname) noexcept { assert(id); - if (tname) { - mStatus = Status(VSMCLIENT_OTHER_ERROR, "Named template isn't implemented"); - return vsm_get_status(); - } + const char* template_name = tname ? tname : "default"; - GVariant* args_in = g_variant_new("(s)", id); + GVariant* args_in = g_variant_new("(ss)", id, template_name); return callMethod(HOST_INTERFACE, api::host::METHOD_CREATE_ZONE, args_in); } diff --git a/client/vasum-client.h b/client/vasum-client.h index 6793722..ba21449 100644 --- a/client/vasum-client.h +++ b/client/vasum-client.h @@ -378,7 +378,7 @@ VsmStatus vsm_set_active_zone(VsmClient client, const char* id); * * @param[in] client vasum-server's client * @param[in] id zone id - * @param[in] tname template name, NULL for default + * @param[in] tname template name, NULL is equivalent to "default" * @return status of this function call */ VsmStatus vsm_create_zone(VsmClient client, const char* id, const char* tname); diff --git a/server/configs/daemon.conf.in b/server/configs/daemon.conf.in index 2040ccf..327e470 100644 --- a/server/configs/daemon.conf.in +++ b/server/configs/daemon.conf.in @@ -3,7 +3,7 @@ "zoneConfigs" : [], "zonesPath" : "${DATA_DIR}/.zones", "zoneImagePath" : "", - "zoneTemplatePath" : "/etc/vasum/templates/template.conf", + "zoneTemplateDir" : "/etc/vasum/templates/", "zoneNewConfigPrefix" : "/var/lib/vasum", "runMountPointPrefix" : "/var/run/zones", "defaultId" : "", diff --git a/server/configs/templates/template.conf b/server/configs/templates/default.conf similarity index 100% rename from server/configs/templates/template.conf rename to server/configs/templates/default.conf diff --git a/server/host-connection.cpp b/server/host-connection.cpp index a90a47c..4a8a2ac 100644 --- a/server/host-connection.cpp +++ b/server/host-connection.cpp @@ -352,10 +352,11 @@ void HostConnection::onMessageCall(const std::string& objectPath, if (methodName == api::host::METHOD_CREATE_ZONE) { const gchar* id = NULL; - g_variant_get(parameters, "(&s)", &id); + const gchar* templateName = NULL; + g_variant_get(parameters, "(&s&s)", &id, &templateName); if (mCreateZoneCallback){ - mCreateZoneCallback(id, result); + mCreateZoneCallback(id, templateName, result); } return; } diff --git a/server/host-connection.hpp b/server/host-connection.hpp index 39708ad..2d029c1 100644 --- a/server/host-connection.hpp +++ b/server/host-connection.hpp @@ -91,6 +91,7 @@ public: dbus::MethodResultBuilder::Pointer result )> SetActiveZoneCallback; typedef std::function CreateZoneCallback; typedef std::function" " " + " " " " " " " " diff --git a/server/zone-config.hpp b/server/zone-config.hpp index f92ca8f..02db1c4 100644 --- a/server/zone-config.hpp +++ b/server/zone-config.hpp @@ -137,6 +137,10 @@ struct ZoneConfig { ) }; +struct ZoneDynamicConfig { + //TODO a place for zone dynamic config (other than provisioning which has its own struct) + CONFIG_REGISTER_EMPTY +}; } // namespace vasum diff --git a/server/zone.cpp b/server/zone.cpp index e7ea3d6..1617bd6 100644 --- a/server/zone.cpp +++ b/server/zone.cpp @@ -79,6 +79,7 @@ Zone::Zone(const utils::Worker::Pointer& worker, mRootPath = (zonePath / fs::path("rootfs")).string(); const std::string dbPrefix = DB_PREFIX + mAdmin->getId(); + config::loadFromKVStoreWithJsonFile(dbPath, zoneConfigPath, mDynamicConfig, dbPrefix); mProvision.reset(new ZoneProvision(mRootPath, zoneConfigPath, dbPath, dbPrefix, mConfig.validLinkPrefixes)); } diff --git a/server/zone.hpp b/server/zone.hpp index ab24615..dbffc22 100644 --- a/server/zone.hpp +++ b/server/zone.hpp @@ -267,6 +267,7 @@ public: private: utils::Worker::Pointer mWorker; ZoneConfig mConfig; + ZoneDynamicConfig mDynamicConfig; std::vector mPermittedToSend; std::vector mPermittedToRecv; std::unique_ptr mConnectionTransport; diff --git a/server/zones-manager-config.hpp b/server/zones-manager-config.hpp index 38c17ac..3ae6e5a 100644 --- a/server/zones-manager-config.hpp +++ b/server/zones-manager-config.hpp @@ -55,9 +55,9 @@ struct ZonesManagerConfig { std::string zoneImagePath; /** - * A path where template configuration files for new zones reside + * A dir where template configuration files for new zones reside */ - std::string zoneTemplatePath; + std::string zoneTemplateDir; /** * Prefix added to a path for new zone configuration files @@ -94,7 +94,7 @@ struct ZonesManagerConfig { dbPath, zonesPath, zoneImagePath, - zoneTemplatePath, + zoneTemplateDir, zoneNewConfigPrefix, lxcTemplatePrefix, availableVTs, diff --git a/server/zones-manager.cpp b/server/zones-manager.cpp index 167f9f4..6acc128 100644 --- a/server/zones-manager.cpp +++ b/server/zones-manager.cpp @@ -163,7 +163,7 @@ ZonesManager::ZonesManager(const std::string& configPath) this, _1, _2)); mHostConnection.setCreateZoneCallback(bind(&ZonesManager::handleCreateZoneCall, - this, _1, _2)); + this, _1, _2, _3)); mHostConnection.setDestroyZoneCallback(bind(&ZonesManager::handleDestroyZoneCall, this, _1, _2)); @@ -998,6 +998,7 @@ int ZonesManager::getVTForNewZone() } void ZonesManager::handleCreateZoneCall(const std::string& id, + const std::string& templateName, dbus::MethodResultBuilder::Pointer result) { if (id.empty()) { @@ -1051,9 +1052,12 @@ void ZonesManager::handleCreateZoneCall(const std::string& id, return true; }; + std::string zoneTemplatePath = utils::createFilePath(mConfig.zoneTemplateDir, + templateName + ".conf"); + try { - LOGI("Generating config from " << mConfig.zoneTemplatePath << " to " << newConfigPath); - generateNewConfig(id, mConfig.zoneTemplatePath, newConfigPath); + LOGI("Generating config from " << zoneTemplatePath << " to " << newConfigPath); + generateNewConfig(id, zoneTemplatePath, newConfigPath); } catch (VasumException& e) { LOGE("Generate config failed: " << e.what()); diff --git a/server/zones-manager.hpp b/server/zones-manager.hpp index 755bc97..99dfa4b 100644 --- a/server/zones-manager.hpp +++ b/server/zones-manager.hpp @@ -184,6 +184,7 @@ private: void handleSetActiveZoneCall(const std::string& id, dbus::MethodResultBuilder::Pointer result); void handleCreateZoneCall(const std::string& id, + const std::string& templateName, dbus::MethodResultBuilder::Pointer result); void handleDestroyZoneCall(const std::string& id, dbus::MethodResultBuilder::Pointer result); diff --git a/tests/unit_tests/client/configs/ut-client/test-dbus-daemon.conf.in b/tests/unit_tests/client/configs/ut-client/test-dbus-daemon.conf.in index debc303..b51ee9a 100644 --- a/tests/unit_tests/client/configs/ut-client/test-dbus-daemon.conf.in +++ b/tests/unit_tests/client/configs/ut-client/test-dbus-daemon.conf.in @@ -6,7 +6,7 @@ "defaultId" : "ut-zones-manager-console1-dbus", "zonesPath" : "/tmp/ut-zones", "zoneImagePath" : "", - "zoneTemplatePath" : "no_need_for_templates_in_this_test", + "zoneTemplateDir" : "no_need_for_templates_in_this_test", "zoneNewConfigPrefix" : "@VSM_TEST_CONFIG_INSTALL_DIR@/client/ut-client/", "runMountPointPrefix" : "", "lxcTemplatePrefix" : "@VSM_TEST_LXC_TEMPLATES_INSTALL_DIR@", diff --git a/tests/unit_tests/server/configs/CMakeLists.txt b/tests/unit_tests/server/configs/CMakeLists.txt index fac9d99..fca8500 100644 --- a/tests/unit_tests/server/configs/CMakeLists.txt +++ b/tests/unit_tests/server/configs/CMakeLists.txt @@ -64,8 +64,8 @@ CONFIGURE_FILE(ut-zones-manager/zones/console3-dbus.conf.in ${CMAKE_BINARY_DIR}/ut-zones-manager/zones/console3-dbus.conf @ONLY) FILE(GLOB manager_zone_CONF_GEN ${CMAKE_BINARY_DIR}/ut-zones-manager/zones/*.conf) -CONFIGURE_FILE(ut-zones-manager/templates/template.conf.in - ${CMAKE_BINARY_DIR}/ut-zones-manager/templates/template.conf @ONLY) +CONFIGURE_FILE(ut-zones-manager/templates/default.conf.in + ${CMAKE_BINARY_DIR}/ut-zones-manager/templates/default.conf @ONLY) FILE(GLOB manager_zone_TEMPLATE_GEN ${CMAKE_BINARY_DIR}/ut-zones-manager/templates/*.conf) diff --git a/tests/unit_tests/server/configs/ut-server/buggy-daemon.conf.in b/tests/unit_tests/server/configs/ut-server/buggy-daemon.conf.in index 8deaa6f..a39bcb4 100644 --- a/tests/unit_tests/server/configs/ut-server/buggy-daemon.conf.in +++ b/tests/unit_tests/server/configs/ut-server/buggy-daemon.conf.in @@ -3,7 +3,7 @@ "zoneConfigs" : ["zones/zone1.conf", "missing/file/path/missing.conf", "zones/zone3.conf"], "zonesPath" : "/tmp/ut-zones", "zoneImagePath" : "", - "zoneTemplatePath" : "no_need_for_templates_in_this_test", + "zoneTemplateDir" : "no_need_for_templates_in_this_test", "zoneNewConfigPrefix" : "@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-server/", "runMountPointPrefix" : "", "defaultId" : "ut-server-zone1", diff --git a/tests/unit_tests/server/configs/ut-server/test-daemon.conf.in b/tests/unit_tests/server/configs/ut-server/test-daemon.conf.in index 7066583..932ee89 100644 --- a/tests/unit_tests/server/configs/ut-server/test-daemon.conf.in +++ b/tests/unit_tests/server/configs/ut-server/test-daemon.conf.in @@ -3,7 +3,7 @@ "zoneConfigs" : ["zones/zone1.conf", "zones/zone2.conf", "zones/zone3.conf"], "zonesPath" : "/tmp/ut-zones", "zoneImagePath" : "", - "zoneTemplatePath" : "no_need_for_templates_in_this_test", + "zoneTemplateDir" : "no_need_for_templates_in_this_test", "zoneNewConfigPrefix" : "@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-server/", "runMountPointPrefix" : "", "defaultId" : "ut-server-zone1", diff --git a/tests/unit_tests/server/configs/ut-zones-manager/buggy-daemon.conf.in b/tests/unit_tests/server/configs/ut-zones-manager/buggy-daemon.conf.in index a1fe350..50a95b2 100644 --- a/tests/unit_tests/server/configs/ut-zones-manager/buggy-daemon.conf.in +++ b/tests/unit_tests/server/configs/ut-zones-manager/buggy-daemon.conf.in @@ -5,7 +5,7 @@ "defaultId" : "ut-zones-manager-console1", "zonesPath" : "/tmp/ut-zones", "zoneImagePath" : "", - "zoneTemplatePath" : "@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-zones-manager/templates/template.conf", + "zoneTemplateDir" : "@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-zones-manager/templates/", "zoneNewConfigPrefix" : "@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-zones-manager/", "lxcTemplatePrefix" : "@VSM_TEST_LXC_TEMPLATES_INSTALL_DIR@", "availableVTs" : [], diff --git a/tests/unit_tests/server/configs/ut-zones-manager/empty-dbus-daemon.conf.in b/tests/unit_tests/server/configs/ut-zones-manager/empty-dbus-daemon.conf.in index 21faee1..83b1124 100644 --- a/tests/unit_tests/server/configs/ut-zones-manager/empty-dbus-daemon.conf.in +++ b/tests/unit_tests/server/configs/ut-zones-manager/empty-dbus-daemon.conf.in @@ -4,7 +4,7 @@ "defaultId" : "", "zonesPath" : "/tmp/ut-zones", "zoneImagePath" : "", - "zoneTemplatePath" : "@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-zones-manager/templates/template.conf", + "zoneTemplateDir" : "@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-zones-manager/templates/", "zoneNewConfigPrefix" : "/tmp/ut-zones/generated-configs/", "runMountPointPrefix" : "", "lxcTemplatePrefix" : "@VSM_TEST_LXC_TEMPLATES_INSTALL_DIR@", diff --git a/tests/unit_tests/server/configs/ut-zones-manager/templates/template.conf.in b/tests/unit_tests/server/configs/ut-zones-manager/templates/default.conf.in similarity index 100% rename from tests/unit_tests/server/configs/ut-zones-manager/templates/template.conf.in rename to tests/unit_tests/server/configs/ut-zones-manager/templates/default.conf.in diff --git a/tests/unit_tests/server/configs/ut-zones-manager/test-daemon.conf.in b/tests/unit_tests/server/configs/ut-zones-manager/test-daemon.conf.in index 73da57f..d8f1ad4 100644 --- a/tests/unit_tests/server/configs/ut-zones-manager/test-daemon.conf.in +++ b/tests/unit_tests/server/configs/ut-zones-manager/test-daemon.conf.in @@ -5,7 +5,7 @@ "defaultId" : "ut-zones-manager-console1", "zonesPath" : "/tmp/ut-zones", "zoneImagePath" : "", - "zoneTemplatePath" : "@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-zones-manager/templates/template.conf", + "zoneTemplateDir" : "@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-zones-manager/templates/", "zoneNewConfigPrefix" : "@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-zones-manager/", "lxcTemplatePrefix" : "@VSM_TEST_LXC_TEMPLATES_INSTALL_DIR@", "availableVTs" : [], diff --git a/tests/unit_tests/server/configs/ut-zones-manager/test-dbus-daemon.conf.in b/tests/unit_tests/server/configs/ut-zones-manager/test-dbus-daemon.conf.in index 3305552..4f8f6e8 100644 --- a/tests/unit_tests/server/configs/ut-zones-manager/test-dbus-daemon.conf.in +++ b/tests/unit_tests/server/configs/ut-zones-manager/test-dbus-daemon.conf.in @@ -6,7 +6,7 @@ "defaultId" : "ut-zones-manager-console1-dbus", "zonesPath" : "/tmp/ut-zones", "zoneImagePath" : "", - "zoneTemplatePath" : "@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-zones-manager/templates/template.conf", + "zoneTemplateDir" : "@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-zones-manager/templates/", "zoneNewConfigPrefix" : "@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-zones-manager/", "runMountPointPrefix" : "", "lxcTemplatePrefix" : "@VSM_TEST_LXC_TEMPLATES_INSTALL_DIR@", diff --git a/tests/unit_tests/server/ut-zones-manager.cpp b/tests/unit_tests/server/ut-zones-manager.cpp index 65f0f2b..b0ab2e2 100644 --- a/tests/unit_tests/server/ut-zones-manager.cpp +++ b/tests/unit_tests/server/ut-zones-manager.cpp @@ -78,6 +78,7 @@ const std::string FILE_CONTENT = "File content\n" "Line 2\n"; const std::string NON_EXISTANT_ZONE_ID = "NON_EXISTANT_ZONE_ID"; const std::string ZONES_PATH = "/tmp/ut-zones"; // the same as in daemon.conf +const std::string TEMPLATE_NAME = "default"; /** * Currently there is no way to propagate an error from async call @@ -326,6 +327,7 @@ public: } void callAsyncMethodCreateZone(const std::string& id, + const std::string& templateName, const VoidResultCallback& result) { auto asyncResult = [result](dbus::AsyncMethodCallResult& asyncMethodCallResult) { @@ -335,7 +337,7 @@ public: }; assert(isHost()); - GVariant* parameters = g_variant_new("(s)", id.c_str()); + GVariant* parameters = g_variant_new("(ss)", id.c_str(), templateName.c_str()); mClient->callMethodAsync(api::host::BUS_NAME, api::host::OBJECT_PATH, api::host::INTERFACE, @@ -1028,15 +1030,15 @@ BOOST_AUTO_TEST_CASE(CreateDestroyZoneTest) DbusAccessory dbus(DbusAccessory::HOST_ID); // create zone1 - dbus.callAsyncMethodCreateZone(zone1, resultCallback); + dbus.callAsyncMethodCreateZone(zone1, TEMPLATE_NAME, resultCallback); BOOST_REQUIRE(callDone.wait(EVENT_TIMEOUT)); // create zone2 - dbus.callAsyncMethodCreateZone(zone2, resultCallback); + dbus.callAsyncMethodCreateZone(zone2, TEMPLATE_NAME, resultCallback); BOOST_REQUIRE(callDone.wait(EVENT_TIMEOUT)); // create zone3 - dbus.callAsyncMethodCreateZone(zone3, resultCallback); + dbus.callAsyncMethodCreateZone(zone3, TEMPLATE_NAME, resultCallback); BOOST_REQUIRE(callDone.wait(EVENT_TIMEOUT)); cm.startAll(); @@ -1084,7 +1086,7 @@ BOOST_AUTO_TEST_CASE(CreateDestroyZonePersistenceTest) { ZonesManager cm(EMPTY_DBUS_CONFIG_PATH); DbusAccessory dbus(DbusAccessory::HOST_ID); - dbus.callAsyncMethodCreateZone(zone, resultCallback); + dbus.callAsyncMethodCreateZone(zone, TEMPLATE_NAME, resultCallback); BOOST_REQUIRE(callDone.wait(EVENT_TIMEOUT)); }