[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>
"cpuQuotaForeground" : -1,
"cpuQuotaBackground" : 1000,
"privilege" : 1,
+ "switchToDefaultAfterTimeout" : true,
"config" : "../libvirt-config/business.xml",
"networkConfig" : "../libvirt-config/business-network.xml",
"runMountPoint" : "business/run",
"cpuQuotaForeground" : -1,
"cpuQuotaBackground" : 1000,
"privilege" : 10,
+ "switchToDefaultAfterTimeout" : true,
"config" : "../libvirt-config/private.xml",
"networkConfig" : "../libvirt-config/private-network.xml",
"runMountPoint" : "private/run",
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.
*/
CONFIG_REGISTER
(
privilege,
+ switchToDefaultAfterTimeout,
config,
networkConfig,
cpuQuotaForeground,
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...");
// ContainerConnection API
/**
+ * @return Is switching to default container after timeout allowed?
+ */
+ bool isSwitchToDefaultAfterTimeoutAllowed() const;
+
+ /**
* Register notification request callback
*/
void setNotifyActiveContainerCallback(const NotifyActiveContainerCallback& callback);
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,
{
"privilege" : 10,
+ "switchToDefaultAfterTimeout" : true,
"config" : "@SC_TEST_CONFIG_INSTALL_DIR@/server/ut-container-admin/libvirt-config/buggy.xml",
"networkConfig" : "",
"cpuQuotaForeground" : -1,
{
"privilege" : 10,
+ "switchToDefaultAfterTimeout" : true,
"config" : "/this/is/a/missing/file/path/missing.xml",
"networkConfig" : "",
"cpuQuotaForeground" : -1,
{
"privilege" : 10,
+ "switchToDefaultAfterTimeout" : true,
"config" : "@SC_TEST_CONFIG_INSTALL_DIR@/server/ut-container-admin/libvirt-config/test-no-shutdown.xml",
"networkConfig" : "",
"cpuQuotaForeground" : -1,
{
"privilege" : 10,
+ "switchToDefaultAfterTimeout" : true,
"config" : "@SC_TEST_CONFIG_INSTALL_DIR@/server/ut-container-admin/libvirt-config/test.xml",
"networkConfig" : "",
"cpuQuotaForeground" : -1,
{
"privilege" : 10,
+ "switchToDefaultAfterTimeout" : true,
"config" : "/missing/file/path/libvirt.xml",
"networkConfig" : "../libvirt-config/network.xml",
"cpuQuotaForeground" : -1,
{
"privilege" : 10,
+ "switchToDefaultAfterTimeout" : true,
"config" : "../libvirt-config/test-dbus.xml",
"networkConfig" : "../libvirt-config/network.xml",
"cpuQuotaForeground" : -1,
{
"privilege" : 10,
+ "switchToDefaultAfterTimeout" : true,
"config" : "../libvirt-config/test.xml",
"networkConfig" : "../libvirt-config/network.xml",
"cpuQuotaForeground" : -1,
{
"privilege" : 20,
+ "switchToDefaultAfterTimeout" : true,
"config" : "../libvirt-config/console1-dbus.xml",
"networkConfig" : "../libvirt-config/network1.xml",
"cpuQuotaForeground" : -1,
{
"privilege" : 20,
+ "switchToDefaultAfterTimeout" : true,
"config" : "../libvirt-config/console1.xml",
"networkConfig" : "../libvirt-config/network1.xml",
"cpuQuotaForeground" : -1,
{
"privilege" : 20,
+ "switchToDefaultAfterTimeout" : false,
"config" : "../libvirt-config/console2-dbus.xml",
"networkConfig" : "../libvirt-config/network2.xml",
"cpuQuotaForeground" : -1,
{
"privilege" : 10,
+ "switchToDefaultAfterTimeout" : true,
"config" : "../libvirt-config/console2.xml",
"networkConfig" : "../libvirt-config/network2.xml",
"cpuQuotaForeground" : -1,
{
"privilege" : 20,
+ "switchToDefaultAfterTimeout" : true,
"config" : "../libvirt-config/console3-dbus.xml",
"networkConfig" : "../libvirt-config/network3.xml",
"cpuQuotaForeground" : -1,
{
"privilege" : 15,
+ "switchToDefaultAfterTimeout" : true,
"config" : "../libvirt-config/console3.xml",
"networkConfig" : "../libvirt-config/network3.xml",
"cpuQuotaForeground" : -1,
{
"privilege" : 10,
+ "switchToDefaultAfterTimeout" : true,
"config" : "",
"networkConfig" : "@SC_TEST_CONFIG_INSTALL_DIR@/server/ut-network-admin/libvirt-config/buggy-network.xml",
"cpuQuotaForeground" : -1,
{
"privilege" : 10,
+ "switchToDefaultAfterTimeout" : true,
"config" : "",
"networkConfig" : "",
"cpuQuotaForeground" : -1,
{
"privilege" : 10,
+ "switchToDefaultAfterTimeout" : true,
"config" : "",
"networkConfig" : "@SC_TEST_CONFIG_INSTALL_DIR@/server/ut-network-admin/libvirt-config/network.xml",
"cpuQuotaForeground" : -1,
{
"privilege" : 20,
+ "switchToDefaultAfterTimeout" : true,
"config" : "../libvirt-config/container1.xml",
"networkConfig" : "../libvirt-config/network1.xml",
"cpuQuotaForeground" : -1,
{
"privilege" : 10,
+ "switchToDefaultAfterTimeout" : true,
"config" : "../libvirt-config/container2.xml",
"networkConfig" : "../libvirt-config/network2.xml",
"cpuQuotaForeground" : -1,
{
"privilege" : 15,
+ "switchToDefaultAfterTimeout" : true,
"config" : "../libvirt-config/container3.xml",
"networkConfig" : "../libvirt-config/network3.xml",
"cpuQuotaForeground" : -1,
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()