Create zone api method support templateName parameter 68/35068/1
authorPiotr Bartosiewicz <p.bartosiewi@partner.samsung.com>
Mon, 26 Jan 2015 10:37:03 +0000 (11:37 +0100)
committerPiotr Bartosiewicz <p.bartosiewi@partner.samsung.com>
Fri, 6 Feb 2015 15:54:01 +0000 (16:54 +0100)
[Bug/Feature]   Not implemented create zone parameter
[Cause]         N/A
[Solution]      N/A
[Verification]  Build, run tests

Change-Id: I5dff390db6b82927b1f8f300f82212c2a534a571

23 files changed:
client/vasum-client-impl.cpp
client/vasum-client.h
server/configs/daemon.conf.in
server/configs/templates/default.conf [moved from server/configs/templates/template.conf with 100% similarity]
server/host-connection.cpp
server/host-connection.hpp
server/host-dbus-definitions.hpp
server/zone-config.hpp
server/zone.cpp
server/zone.hpp
server/zones-manager-config.hpp
server/zones-manager.cpp
server/zones-manager.hpp
tests/unit_tests/client/configs/ut-client/test-dbus-daemon.conf.in
tests/unit_tests/server/configs/CMakeLists.txt
tests/unit_tests/server/configs/ut-server/buggy-daemon.conf.in
tests/unit_tests/server/configs/ut-server/test-daemon.conf.in
tests/unit_tests/server/configs/ut-zones-manager/buggy-daemon.conf.in
tests/unit_tests/server/configs/ut-zones-manager/empty-dbus-daemon.conf.in
tests/unit_tests/server/configs/ut-zones-manager/templates/default.conf.in [moved from tests/unit_tests/server/configs/ut-zones-manager/templates/template.conf.in with 100% similarity]
tests/unit_tests/server/configs/ut-zones-manager/test-daemon.conf.in
tests/unit_tests/server/configs/ut-zones-manager/test-dbus-daemon.conf.in
tests/unit_tests/server/ut-zones-manager.cpp

index 9ca5de5..d27fad3 100644 (file)
@@ -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);
 }
 
index 6793722..ba21449 100644 (file)
@@ -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);
index 2040ccf..327e470 100644 (file)
@@ -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" : "",
index a90a47c..4a8a2ac 100644 (file)
@@ -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;
     }
index 39708ad..2d029c1 100644 (file)
@@ -91,6 +91,7 @@ public:
                                dbus::MethodResultBuilder::Pointer result
                               )> SetActiveZoneCallback;
     typedef std::function<void(const std::string& id,
+                               const std::string& templateName,
                                dbus::MethodResultBuilder::Pointer result
                               )> CreateZoneCallback;
     typedef std::function<void(const std::string& id,
index 47922b5..e757e53 100644 (file)
@@ -121,6 +121,7 @@ const std::string DEFINITION =
     "    </method>"
     "    <method name='" + METHOD_CREATE_ZONE + "'>"
     "      <arg type='s' name='id' direction='in'/>"
+    "      <arg type='s' name='templateName' direction='in'/>"
     "    </method>"
     "    <method name='" + METHOD_DESTROY_ZONE + "'>"
     "      <arg type='s' name='id' direction='in'/>"
index f92ca8f..02db1c4 100644 (file)
@@ -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
 
index e7ea3d6..1617bd6 100644 (file)
@@ -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));
 }
 
index ab24615..dbffc22 100644 (file)
@@ -267,6 +267,7 @@ public:
 private:
     utils::Worker::Pointer mWorker;
     ZoneConfig mConfig;
+    ZoneDynamicConfig mDynamicConfig;
     std::vector<boost::regex> mPermittedToSend;
     std::vector<boost::regex> mPermittedToRecv;
     std::unique_ptr<ZoneConnectionTransport> mConnectionTransport;
index 38c17ac..3ae6e5a 100644 (file)
@@ -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,
index 167f9f4..6acc128 100644 (file)
@@ -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());
index 755bc97..99dfa4b 100644 (file)
@@ -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);
index debc303..b51ee9a 100644 (file)
@@ -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@",
index fac9d99..fca8500 100644 (file)
@@ -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)
 
 
index 8deaa6f..a39bcb4 100644 (file)
@@ -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",
index 7066583..932ee89 100644 (file)
@@ -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",
index a1fe350..50a95b2 100644 (file)
@@ -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" : [],
index 21faee1..83b1124 100644 (file)
@@ -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@",
index 73da57f..d8f1ad4 100644 (file)
@@ -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" : [],
index 3305552..4f8f6e8 100644 (file)
@@ -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@",
index 65f0f2b..b0ab2e2 100644 (file)
@@ -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));
     }