Add flag in container config allowing switch to default after timeout 98/23698/8
authorLukasz Kostyra <l.kostyra@samsung.com>
Tue, 1 Jul 2014 13:08:26 +0000 (15:08 +0200)
committerLukasz Pawelczyk <l.pawelczyk@samsung.com>
Thu, 10 Jul 2014 15:49:21 +0000 (08:49 -0700)
[Feature]       Flag in container config which allows switching to default container when timeout
                occurs.
[Cause]         Some containers might want to forbid switching to default container after timeout.
[Solution]      Add flag switchToDefaultAfterTimeout allowing such switch in container config.
[Verification]  Build, install, run tests. All should pass.

Change-Id: Icdcfc007c0a11126fe243988878a2c918d6bdf13
Signed-off-by: Lukasz Kostyra <l.kostyra@samsung.com>
26 files changed:
server/configs/containers/business.conf
server/configs/containers/private.conf
server/container-config.hpp
server/container.cpp
server/container.hpp
server/containers-manager.cpp
tests/unit_tests/server/configs/ut-container-admin/containers/buggy.conf.in
tests/unit_tests/server/configs/ut-container-admin/containers/missing.conf
tests/unit_tests/server/configs/ut-container-admin/containers/test-no-shutdown.conf.in
tests/unit_tests/server/configs/ut-container-admin/containers/test.conf.in
tests/unit_tests/server/configs/ut-container/containers/buggy.conf
tests/unit_tests/server/configs/ut-container/containers/test-dbus.conf
tests/unit_tests/server/configs/ut-container/containers/test.conf
tests/unit_tests/server/configs/ut-containers-manager/containers/console1-dbus.conf
tests/unit_tests/server/configs/ut-containers-manager/containers/console1.conf
tests/unit_tests/server/configs/ut-containers-manager/containers/console2-dbus.conf
tests/unit_tests/server/configs/ut-containers-manager/containers/console2.conf
tests/unit_tests/server/configs/ut-containers-manager/containers/console3-dbus.conf
tests/unit_tests/server/configs/ut-containers-manager/containers/console3.conf
tests/unit_tests/server/configs/ut-network-admin/containers/buggy.conf.in
tests/unit_tests/server/configs/ut-network-admin/containers/missing.conf
tests/unit_tests/server/configs/ut-network-admin/containers/test.conf.in
tests/unit_tests/server/configs/ut-server/containers/container1.conf
tests/unit_tests/server/configs/ut-server/containers/container2.conf
tests/unit_tests/server/configs/ut-server/containers/container3.conf
tests/unit_tests/server/ut-containers-manager.cpp

index 80efdd4..f16ccb4 100644 (file)
@@ -2,6 +2,7 @@
     "cpuQuotaForeground" : -1,
     "cpuQuotaBackground" : 1000,
     "privilege" : 1,
+    "switchToDefaultAfterTimeout" : true,
     "config" : "../libvirt-config/business.xml",
     "networkConfig" : "../libvirt-config/business-network.xml",
     "runMountPoint" : "business/run",
index 3984476..cde88c3 100644 (file)
@@ -2,6 +2,7 @@
     "cpuQuotaForeground" : -1,
     "cpuQuotaBackground" : 1000,
     "privilege" : 10,
+    "switchToDefaultAfterTimeout" : true,
     "config" : "../libvirt-config/private.xml",
     "networkConfig" : "../libvirt-config/private-network.xml",
     "runMountPoint" : "private/run",
index d5a3038..f5f202e 100644 (file)
@@ -43,6 +43,12 @@ struct ContainerConfig {
     int privilege;
 
     /**
+     * Allow switching to default container after timeout.
+     * Setting this to false will disable switching to default container after timeout.
+     */
+    bool switchToDefaultAfterTimeout;
+
+    /**
      * Container's libvirt (XML) config file.
      * Location can be relative to the Container's config file.
      */
@@ -83,6 +89,7 @@ struct ContainerConfig {
     CONFIG_REGISTER
     (
         privilege,
+        switchToDefaultAfterTimeout,
         config,
         networkConfig,
         cpuQuotaForeground,
index f8a8798..96ca936 100644 (file)
@@ -182,6 +182,11 @@ bool Container::isPaused()
     return mAdmin->isPaused();
 }
 
+bool Container::isSwitchToDefaultAfterTimeoutAllowed() const
+{
+    return mConfig.switchToDefaultAfterTimeout;
+}
+
 void Container::onNameLostCallback()
 {
     LOGI(getId() << ": A connection to the DBUS server has been lost, reconnecting...");
index 8ab37d8..4c1c879 100644 (file)
@@ -129,6 +129,11 @@ public:
     // ContainerConnection API
 
     /**
+     * @return Is switching to default container after timeout allowed?
+     */
+    bool isSwitchToDefaultAfterTimeoutAllowed() const;
+
+    /**
      * Register notification request callback
      */
     void setNotifyActiveContainerCallback(const NotifyActiveContainerCallback& callback);
index 2f8e8dd..657c7bf 100644 (file)
@@ -224,8 +224,15 @@ void ContainersManager::notifyActiveContainerHandler(const std::string& caller,
 
 void ContainersManager::displayOffHandler(const std::string& /*caller*/)
 {
-    LOGI("Switching to default container " << mConfig.defaultId);
-    focus(mConfig.defaultId);
+    // get config of currently set container and switch if switchToDefaultAfterTimeout is true
+    const std::string activeContainerName = getRunningForegroundContainerId();
+    const auto& activeContainer = mContainers.find(activeContainerName);
+
+    if (activeContainer != mContainers.end() &&
+        activeContainer->second->isSwitchToDefaultAfterTimeoutAllowed()) {
+        LOGI("Switching to default container " << mConfig.defaultId);
+        focus(mConfig.defaultId);
+    }
 }
 
 void ContainersManager::handleContainerMoveFileRequest(const std::string& srcContainerId,
index e06bf63..341052b 100644 (file)
@@ -1,5 +1,6 @@
 {
     "privilege" : 10,
+    "switchToDefaultAfterTimeout" : true,
     "config" : "@SC_TEST_CONFIG_INSTALL_DIR@/server/ut-container-admin/libvirt-config/buggy.xml",
     "networkConfig" : "",
     "cpuQuotaForeground" : -1,
index 55d6852..7ac04e9 100644 (file)
@@ -1,5 +1,6 @@
 {
     "privilege" : 10,
+    "switchToDefaultAfterTimeout" : true,
     "config" : "/this/is/a/missing/file/path/missing.xml",
     "networkConfig" : "",
     "cpuQuotaForeground" : -1,
index 6d01a50..8f4da35 100644 (file)
@@ -1,5 +1,6 @@
 {
     "privilege" : 10,
+    "switchToDefaultAfterTimeout" : true,
     "config" : "@SC_TEST_CONFIG_INSTALL_DIR@/server/ut-container-admin/libvirt-config/test-no-shutdown.xml",
     "networkConfig" : "",
     "cpuQuotaForeground" : -1,
index 518aa4c..badc3da 100644 (file)
@@ -1,5 +1,6 @@
 {
     "privilege" : 10,
+    "switchToDefaultAfterTimeout" : true,
     "config" : "@SC_TEST_CONFIG_INSTALL_DIR@/server/ut-container-admin/libvirt-config/test.xml",
     "networkConfig" : "",
     "cpuQuotaForeground" : -1,
index d5ccd1e..0dc866a 100644 (file)
@@ -1,5 +1,6 @@
 {
     "privilege" : 10,
+    "switchToDefaultAfterTimeout" : true,
     "config" : "/missing/file/path/libvirt.xml",
     "networkConfig" : "../libvirt-config/network.xml",
     "cpuQuotaForeground" : -1,
index fde05d8..bf35f07 100644 (file)
@@ -1,5 +1,6 @@
 {
     "privilege" : 10,
+    "switchToDefaultAfterTimeout" : true,
     "config" : "../libvirt-config/test-dbus.xml",
     "networkConfig" : "../libvirt-config/network.xml",
     "cpuQuotaForeground" : -1,
index e1769c3..dc81e44 100644 (file)
@@ -1,5 +1,6 @@
 {
     "privilege" : 10,
+    "switchToDefaultAfterTimeout" : true,
     "config" : "../libvirt-config/test.xml",
     "networkConfig" : "../libvirt-config/network.xml",
     "cpuQuotaForeground" : -1,
index 55dfeb5..ef49f19 100644 (file)
@@ -1,5 +1,6 @@
 {
     "privilege" : 20,
+    "switchToDefaultAfterTimeout" : true,
     "config" : "../libvirt-config/console1-dbus.xml",
     "networkConfig" : "../libvirt-config/network1.xml",
     "cpuQuotaForeground" : -1,
index 61668c8..b26e02e 100644 (file)
@@ -1,5 +1,6 @@
 {
     "privilege" : 20,
+    "switchToDefaultAfterTimeout" : true,
     "config" : "../libvirt-config/console1.xml",
     "networkConfig" : "../libvirt-config/network1.xml",
     "cpuQuotaForeground" : -1,
index 713cb02..76c5e49 100644 (file)
@@ -1,5 +1,6 @@
 {
     "privilege" : 20,
+    "switchToDefaultAfterTimeout" : false,
     "config" : "../libvirt-config/console2-dbus.xml",
     "networkConfig" : "../libvirt-config/network2.xml",
     "cpuQuotaForeground" : -1,
index 10e5cef..f609a85 100644 (file)
@@ -1,5 +1,6 @@
 {
     "privilege" : 10,
+    "switchToDefaultAfterTimeout" : true,
     "config" : "../libvirt-config/console2.xml",
     "networkConfig" : "../libvirt-config/network2.xml",
     "cpuQuotaForeground" : -1,
index 70ff251..592cbfa 100644 (file)
@@ -1,5 +1,6 @@
 {
     "privilege" : 20,
+    "switchToDefaultAfterTimeout" : true,
     "config" : "../libvirt-config/console3-dbus.xml",
     "networkConfig" : "../libvirt-config/network3.xml",
     "cpuQuotaForeground" : -1,
index 8ccf55b..e249df7 100644 (file)
@@ -1,5 +1,6 @@
 {
     "privilege" : 15,
+    "switchToDefaultAfterTimeout" : true,
     "config" : "../libvirt-config/console3.xml",
     "networkConfig" : "../libvirt-config/network3.xml",
     "cpuQuotaForeground" : -1,
index be3f7c1..2b88e29 100644 (file)
@@ -1,5 +1,6 @@
 {
     "privilege" : 10,
+    "switchToDefaultAfterTimeout" : true,
     "config" : "",
     "networkConfig" : "@SC_TEST_CONFIG_INSTALL_DIR@/server/ut-network-admin/libvirt-config/buggy-network.xml",
     "cpuQuotaForeground" : -1,
index f418503..ca580a1 100644 (file)
@@ -1,5 +1,6 @@
 {
     "privilege" : 10,
+    "switchToDefaultAfterTimeout" : true,
     "config" : "",
     "networkConfig" : "",
     "cpuQuotaForeground" : -1,
index 771a93b..547c6cd 100644 (file)
@@ -1,5 +1,6 @@
 {
     "privilege" : 10,
+    "switchToDefaultAfterTimeout" : true,
     "config" : "",
     "networkConfig" : "@SC_TEST_CONFIG_INSTALL_DIR@/server/ut-network-admin/libvirt-config/network.xml",
     "cpuQuotaForeground" : -1,
index 952decf..f93690a 100644 (file)
@@ -1,5 +1,6 @@
 {
     "privilege" : 20,
+    "switchToDefaultAfterTimeout" : true,
     "config" : "../libvirt-config/container1.xml",
     "networkConfig" : "../libvirt-config/network1.xml",
     "cpuQuotaForeground" : -1,
index 4e6de09..f519018 100644 (file)
@@ -1,5 +1,6 @@
 {
     "privilege" : 10,
+    "switchToDefaultAfterTimeout" : true,
     "config" : "../libvirt-config/container2.xml",
     "networkConfig" : "../libvirt-config/network2.xml",
     "cpuQuotaForeground" : -1,
index 9170c54..3c5989e 100644 (file)
@@ -1,5 +1,6 @@
 {
     "privilege" : 15,
+    "switchToDefaultAfterTimeout" : true,
     "config" : "../libvirt-config/container3.xml",
     "networkConfig" : "../libvirt-config/network3.xml",
     "cpuQuotaForeground" : -1,
index 0182cb8..bf91d9f 100644 (file)
@@ -448,5 +448,53 @@ BOOST_AUTO_TEST_CASE(MoveFileTest)
     fs::remove_all(CONTAINER2PATH, ec);
 }
 
+BOOST_AUTO_TEST_CASE(AllowSwitchToDefaultTest)
+{
+    ContainersManager cm(TEST_DBUS_CONFIG_PATH);
+    BOOST_REQUIRE_NO_THROW(cm.startAll());
+
+    std::vector<std::unique_ptr<DbusAccessory>> clients;
+    for (int i = 1; i <= TEST_DBUS_CONNECTION_CONTAINERS_COUNT; ++i) {
+        clients.push_back(std::unique_ptr<DbusAccessory>(new DbusAccessory(i)));
+    }
+
+    for (auto& client : clients) {
+        client->setName(fake_power_manager_api::BUS_NAME);
+    }
+
+    std::mutex condMutex;
+    std::unique_lock<std::mutex> condLock(condMutex);
+    std::condition_variable condition;
+    auto cond = [&cm]() -> bool {
+        return cm.getRunningForegroundContainerId() == "ut-containers-manager-console1-dbus";
+    };
+
+    for (auto& client : clients) {
+        // focus non-default container with allowed switching
+        BOOST_REQUIRE_NO_THROW(cm.focus("ut-containers-manager-console3-dbus"));
+
+        // emit signal from dbus connection
+        BOOST_REQUIRE_NO_THROW(client->emitSignal(fake_power_manager_api::OBJECT_PATH,
+                                                  fake_power_manager_api::INTERFACE,
+                                                  fake_power_manager_api::SIGNAL_DISPLAY_OFF,
+                                                  nullptr));
+
+        // check if default container has focus
+        BOOST_CHECK(condition.wait_for(condLock, std::chrono::milliseconds(EVENT_TIMEOUT), cond));
+
+        // focus non-default container with disabled switching
+        BOOST_REQUIRE_NO_THROW(cm.focus("ut-containers-manager-console2-dbus"));
+
+        // emit signal from dbus connection
+        BOOST_REQUIRE_NO_THROW(client->emitSignal(fake_power_manager_api::OBJECT_PATH,
+                                                  fake_power_manager_api::INTERFACE,
+                                                  fake_power_manager_api::SIGNAL_DISPLAY_OFF,
+                                                  nullptr));
+
+        // now default container should not be focused
+        BOOST_CHECK(!condition.wait_for(condLock, std::chrono::milliseconds(EVENT_TIMEOUT), cond));
+    }
+}
+
 
 BOOST_AUTO_TEST_SUITE_END()