From ac0a215826052e4c0e1e88b446579aea841206ed Mon Sep 17 00:00:00 2001 From: Piotr Bartosiewicz Date: Fri, 5 Dec 2014 15:57:49 +0100 Subject: [PATCH 01/16] Fix ipc threading issues [Bug/Feature] N/A [Cause] N/A [Solution] N/A [Verification] Build, install, run tests Change-Id: I0f403bdb9dd535186a7c1fa10a486da265858ad7 --- common/ipc/internals/processor.cpp | 6 ++--- common/ipc/internals/processor.hpp | 2 +- tests/unit_tests/ipc/ut-ipc.cpp | 48 ++++++++++++++++++++------------------ 3 files changed, 29 insertions(+), 27 deletions(-) diff --git a/common/ipc/internals/processor.cpp b/common/ipc/internals/processor.cpp index 5565124..b134b08 100644 --- a/common/ipc/internals/processor.cpp +++ b/common/ipc/internals/processor.cpp @@ -325,18 +325,18 @@ bool Processor::handleInput(const PeerID peerID, const Socket& socket) if (mMethodsCallbacks.count(methodID)) { // Method std::shared_ptr methodCallbacks = mMethodsCallbacks.at(methodID); - mCallsMutex.unlock(); + lock.unlock(); return onRemoteCall(peerID, socket, methodID, messageID, methodCallbacks); } else if (mSignalsCallbacks.count(methodID)) { // Signal std::shared_ptr signalCallbacks = mSignalsCallbacks.at(methodID); - mCallsMutex.unlock(); + lock.unlock(); return onRemoteSignal(peerID, socket, methodID, messageID, signalCallbacks); } else { // Nothing - mCallsMutex.unlock(); + lock.unlock(); LOGW("No method or signal callback for methodID: " << methodID); removePeerInternal(peerID, Status::NAUGHTY_PEER); return true; diff --git a/common/ipc/internals/processor.hpp b/common/ipc/internals/processor.hpp index 8fc17fb..da2a5b9 100644 --- a/common/ipc/internals/processor.hpp +++ b/common/ipc/internals/processor.hpp @@ -243,7 +243,7 @@ public: private: typedef std::function& data)> SerializeCallback; typedef std::function(int fd)> ParseCallback; - typedef std::lock_guard Lock; + typedef std::unique_lock Lock; struct EmptyData { CONFIG_REGISTER_EMPTY diff --git a/tests/unit_tests/ipc/ut-ipc.cpp b/tests/unit_tests/ipc/ut-ipc.cpp index 88696fe..b8b9e95 100644 --- a/tests/unit_tests/ipc/ut-ipc.cpp +++ b/tests/unit_tests/ipc/ut-ipc.cpp @@ -102,14 +102,12 @@ struct ThrowOnAcceptData { template void accept(Visitor) { - LOGE("Serialization and parsing failed"); - throw std::exception(); + throw std::runtime_error("intentional failure in accept"); } template void accept(Visitor) const { - LOGE("Const Serialization and parsing failed"); - throw std::exception(); + throw std::runtime_error("intentional failure in accept const"); } }; @@ -139,11 +137,11 @@ PeerID connect(Service& s, Client& c) // Connects the Client to the Service and returns Clients PeerID std::mutex mutex; - std::unique_lock lock(mutex); std::condition_variable cv; - unsigned int peerID = 0; - auto newPeerCallback = [&cv, &peerID](unsigned int newPeerID) { + PeerID peerID = 0; + auto newPeerCallback = [&cv, &peerID, &mutex](const PeerID newPeerID) { + std::unique_lock lock(mutex); peerID = newPeerID; cv.notify_one(); }; @@ -156,6 +154,7 @@ PeerID connect(Service& s, Client& c) c.start(); + std::unique_lock lock(mutex); BOOST_CHECK(cv.wait_for(lock, std::chrono::milliseconds(1000), [&peerID]() { return peerID != 0; })); @@ -322,22 +321,23 @@ BOOST_AUTO_TEST_CASE(AsyncClientToServiceEcho) Client c(socketPath); c.start(); - std::mutex mtx; - std::unique_lock lck(mtx); + std::mutex mutex; std::condition_variable cv; //Async call std::shared_ptr sentData(new SendData(34)); std::shared_ptr recvData; - auto dataBack = [&cv, &recvData](ipc::Status status, std::shared_ptr& data) { + auto dataBack = [&cv, &recvData, &mutex](ipc::Status status, std::shared_ptr& data) { BOOST_CHECK(status == ipc::Status::OK); + std::unique_lock lock(mutex); recvData = data; cv.notify_one(); }; c.callAsync(1, sentData, dataBack); // Wait for the response - BOOST_CHECK(cv.wait_for(lck, std::chrono::milliseconds(100), [&recvData]() { + std::unique_lock lock(mutex); + BOOST_CHECK(cv.wait_for(lock, std::chrono::milliseconds(100), [&recvData]() { return static_cast(recvData); })); @@ -355,11 +355,11 @@ BOOST_AUTO_TEST_CASE(AsyncServiceToClientEcho) std::shared_ptr sentData(new SendData(56)); std::shared_ptr recvData; - std::mutex mtx; - std::unique_lock lck(mtx); + std::mutex mutex; std::condition_variable cv; - auto dataBack = [&cv, &recvData](ipc::Status status, std::shared_ptr& data) { + auto dataBack = [&cv, &recvData, &mutex](ipc::Status status, std::shared_ptr& data) { BOOST_CHECK(status == ipc::Status::OK); + std::unique_lock lock(mutex); recvData = data; cv.notify_one(); }; @@ -367,7 +367,8 @@ BOOST_AUTO_TEST_CASE(AsyncServiceToClientEcho) s.callAsync(1, peerID, sentData, dataBack); // Wait for the response - BOOST_CHECK(cv.wait_for(lck, std::chrono::milliseconds(1000), [&recvData]() { + std::unique_lock lock(mutex); + BOOST_CHECK(cv.wait_for(lock, std::chrono::milliseconds(1000), [&recvData]() { return recvData.get() != nullptr; })); @@ -386,7 +387,7 @@ BOOST_AUTO_TEST_CASE(SyncTimeout) std::shared_ptr sentData(new SendData(78)); - BOOST_CHECK_THROW((c.callSync(1, sentData, 10)), IPCException); + BOOST_CHECK_THROW((c.callSync(1, sentData, 10)), IPCException); //TODO it fails from time to time } BOOST_AUTO_TEST_CASE(SerializationError) @@ -432,12 +433,12 @@ BOOST_AUTO_TEST_CASE(DisconnectedPeerError) Client c(socketPath); c.start(); - std::mutex mtx; - std::unique_lock lck(mtx); + std::mutex mutex; std::condition_variable cv; ipc::Status retStatus = ipc::Status::UNDEFINED; - auto dataBack = [&cv, &retStatus](ipc::Status status, std::shared_ptr&) { + auto dataBack = [&cv, &retStatus, &mutex](ipc::Status status, std::shared_ptr&) { + std::unique_lock lock(mutex); retStatus = status; cv.notify_one(); }; @@ -446,10 +447,11 @@ BOOST_AUTO_TEST_CASE(DisconnectedPeerError) c.callAsync(1, sentData, dataBack); // Wait for the response - BOOST_CHECK(cv.wait_for(lck, std::chrono::seconds(10), [&retStatus]() { + std::unique_lock lock(mutex); + BOOST_CHECK(cv.wait_for(lock, std::chrono::seconds(10), [&retStatus]() { return retStatus != ipc::Status::UNDEFINED; })); - BOOST_CHECK(retStatus == ipc::Status::PEER_DISCONNECTED); + BOOST_CHECK(retStatus == ipc::Status::PEER_DISCONNECTED); //TODO it fails from time to time } @@ -515,7 +517,7 @@ BOOST_AUTO_TEST_CASE(AddSignalInRuntime) s.signal(1, data); // Wait for the signals to arrive - std::this_thread::sleep_for(std::chrono::milliseconds(100)); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); //TODO wait_for BOOST_CHECK(isHandlerACalled && isHandlerBCalled); } @@ -547,7 +549,7 @@ BOOST_AUTO_TEST_CASE(AddSignalOffline) s.signal(1, data); // Wait for the signals to arrive - std::this_thread::sleep_for(std::chrono::milliseconds(100)); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); //TODO wait_for BOOST_CHECK(isHandlerACalled && isHandlerBCalled); } -- 2.7.4 From b550c251c29c804983f019305b6e7574b2f7b585 Mon Sep 17 00:00:00 2001 From: Piotr Bartosiewicz Date: Mon, 8 Dec 2014 12:52:32 +0100 Subject: [PATCH 02/16] Fix some other threading issues [Bug/Feature] N/A [Cause] N/A [Solution] N/A [Verification] Build, install, run tests Change-Id: I89b35811644f424773c007bb7d13d622ba57ac48 --- common/lxc/zone.cpp | 4 +- common/utils/environment.cpp | 18 +++---- common/utils/execute.cpp | 17 ++++--- common/utils/execute.hpp | 3 ++ tests/unit_tests/server/ut-containers-manager.cpp | 60 +++++++++++------------ tests/unit_tests/utils/scoped-daemon.cpp | 37 ++++++++------ tests/unit_tests/utils/scoped-daemon.hpp | 2 +- 7 files changed, 78 insertions(+), 63 deletions(-) diff --git a/common/lxc/zone.cpp b/common/lxc/zone.cpp index c7736f5..f4ad3e4 100644 --- a/common/lxc/zone.cpp +++ b/common/lxc/zone.cpp @@ -34,8 +34,8 @@ #include "logger/logger.hpp" #include "lxc/zone.hpp" #include "lxc/exception.hpp" -#ifdef USE_EXEC #include "utils/execute.hpp" +#ifdef USE_EXEC #include "utils/c-array.hpp" #endif @@ -320,7 +320,7 @@ bool LxcZone::setRunLevel(int runLevel) return false; } int status; - if (waitpid(pid, &status, 0) < 0) { + if (!utils::waitPid(pid, status)) { return false; } return status == 0; diff --git a/common/utils/environment.cpp b/common/utils/environment.cpp index 73c7057..aec70c1 100644 --- a/common/utils/environment.cpp +++ b/common/utils/environment.cpp @@ -25,6 +25,7 @@ #include "config.hpp" #include "utils/environment.hpp" +#include "utils/execute.hpp" #include "logger/logger.hpp" #include @@ -96,29 +97,28 @@ bool launchAsRoot(const std::function& func) if (pid == 0) { if (::setuid(0) < 0) { LOGW("Failed to become root: " << strerror(errno)); - ::exit(EXIT_FAILURE); + _exit(EXIT_FAILURE); } try { if (!func()) { LOGE("Failed to successfully execute func"); - ::exit(EXIT_FAILURE); + _exit(EXIT_FAILURE); } } catch (const std::exception& e) { LOGE("Failed to successfully execute func: " << e.what()); - ::exit(EXIT_FAILURE); + _exit(EXIT_FAILURE); } - ::exit(EXIT_SUCCESS); + _exit(EXIT_SUCCESS); } - int result; - if (::waitpid(pid, &result, 0) < 0) { - LOGE("waitpid failed: " << strerror(errno)); + int status; + if (!waitPid(pid, status)) { return false; } - if (result != 0) { - LOGE("Function launched as root failed with result " << result); + if (status != 0) { + LOGE("Function launched as root exited with status " << status); return false; } diff --git a/common/utils/execute.cpp b/common/utils/execute.cpp index 2f2e927..6511456 100644 --- a/common/utils/execute.cpp +++ b/common/utils/execute.cpp @@ -61,12 +61,7 @@ bool executeAndWait(const char* fname, const char* const* argv, int& status) execv(fname, const_cast(argv)); _exit(EXIT_FAILURE); } - int ret = waitpid(pid, &status, 0); - if (ret != pid) { - LOGE("Waitpid failed"); - return false; - } - return true; + return waitPid(pid, status); } bool executeAndWait(const char* fname, const char* const* argv) @@ -88,5 +83,15 @@ bool executeAndWait(const char* fname, const char* const* argv) return true; } +bool waitPid(pid_t pid, int& status) +{ + while (waitpid(pid, &status, 0) == -1) { + if (errno != EINTR) { + return false; + } + } + return true; +} + } // namespace utils } // namespace security_containers diff --git a/common/utils/execute.hpp b/common/utils/execute.hpp index 1fc7b29..3256ee2 100644 --- a/common/utils/execute.hpp +++ b/common/utils/execute.hpp @@ -25,6 +25,7 @@ #ifndef COMMON_UTILS_EXECUTE_HPP #define COMMON_UTILS_EXECUTE_HPP +#include namespace security_containers { namespace utils { @@ -33,6 +34,8 @@ bool executeAndWait(const char* fname, const char* const* argv); bool executeAndWait(const char* fname, const char* const* argv, int& status); +bool waitPid(pid_t pid, int& status); + } // namespace utils } // namespace security_containers diff --git a/tests/unit_tests/server/ut-containers-manager.cpp b/tests/unit_tests/server/ut-containers-manager.cpp index 6d64c83..ac4a898 100644 --- a/tests/unit_tests/server/ut-containers-manager.cpp +++ b/tests/unit_tests/server/ut-containers-manager.cpp @@ -460,27 +460,6 @@ std::function expectedMessage(const std::string& me }; } -class FileCleanerRAII { -public: - FileCleanerRAII(const std::vector& filePathsToClean): - mFilePathsToClean(filePathsToClean) - { } - - ~FileCleanerRAII() - { - namespace fs = boost::filesystem; - for (const auto& file : mFilePathsToClean) { - fs::path f(file); - if (fs::exists(f)) { - fs::remove(f); - } - } - } - -private: - const std::vector mFilePathsToClean; -}; - struct Fixture { security_containers::utils::ScopedGlibLoop mLoop; @@ -1041,11 +1020,15 @@ BOOST_AUTO_TEST_CASE(SetActiveContainerTest) BOOST_AUTO_TEST_CASE(CreateDestroyContainerTest) { - const std::string newContainerId = "test1234"; + const std::string container1 = "test1"; + const std::string container2 = "test2"; + const std::string container3 = "test3"; ContainersManager cm(EMPTY_DBUS_CONFIG_PATH); cm.startAll(); + BOOST_CHECK_EQUAL(cm.getRunningForegroundContainerId(), ""); + Latch callDone; auto resultCallback = [&]() { callDone.set(); @@ -1053,19 +1036,36 @@ BOOST_AUTO_TEST_CASE(CreateDestroyContainerTest) DbusAccessory dbus(DbusAccessory::HOST_ID); - // create new container - dbus.callAsyncMethodCreateContainer(newContainerId, resultCallback); + // create container1 + dbus.callAsyncMethodCreateContainer(container1, resultCallback); BOOST_REQUIRE(callDone.wait(EVENT_TIMEOUT)); - // focus new container - cm.focus(newContainerId); - BOOST_CHECK(cm.getRunningForegroundContainerId() == newContainerId); + BOOST_CHECK_EQUAL(cm.getRunningForegroundContainerId(), container1); - // destroy container - dbus.callAsyncMethodDestroyContainer(newContainerId, resultCallback); + // create container2 + dbus.callAsyncMethodCreateContainer(container2, resultCallback); BOOST_REQUIRE(callDone.wait(EVENT_TIMEOUT)); + BOOST_CHECK_EQUAL(cm.getRunningForegroundContainerId(), container2); //TODO is this valid? - BOOST_CHECK(cm.getRunningForegroundContainerId() == ""); + // create container3 + dbus.callAsyncMethodCreateContainer(container3, resultCallback); + BOOST_REQUIRE(callDone.wait(EVENT_TIMEOUT)); + BOOST_CHECK_EQUAL(cm.getRunningForegroundContainerId(), container3); + + // destroy container2 + dbus.callAsyncMethodDestroyContainer(container2, resultCallback); + BOOST_REQUIRE(callDone.wait(EVENT_TIMEOUT)); + BOOST_CHECK_EQUAL(cm.getRunningForegroundContainerId(), container3); + + // destroy container3 + dbus.callAsyncMethodDestroyContainer(container3, resultCallback); + BOOST_REQUIRE(callDone.wait(EVENT_TIMEOUT)); + //BOOST_CHECK_EQUAL(cm.getRunningForegroundContainerId(), container1);//TODO fix it + + // destroy container1 + dbus.callAsyncMethodDestroyContainer(container1, resultCallback); + BOOST_REQUIRE(callDone.wait(EVENT_TIMEOUT)); + BOOST_CHECK_EQUAL(cm.getRunningForegroundContainerId(), ""); } BOOST_AUTO_TEST_CASE(DeclareFile) diff --git a/tests/unit_tests/utils/scoped-daemon.cpp b/tests/unit_tests/utils/scoped-daemon.cpp index 21fea83..db85375 100644 --- a/tests/unit_tests/utils/scoped-daemon.cpp +++ b/tests/unit_tests/utils/scoped-daemon.cpp @@ -25,6 +25,7 @@ #include "config.hpp" #include "utils/scoped-daemon.hpp" +#include "utils/execute.hpp" #include "logger/logger.hpp" @@ -69,17 +70,17 @@ namespace { volatile pid_t daemonPid = -1;// available in launcher process only; -void startDaemon(const char* path, const char* const argv[]) +bool startDaemon(const char* path, const char* const argv[]) { execv(path, const_cast(argv)); perror("exec failed"); + return false; } -void waitForDaemon() +bool waitForDaemon() { - if (waitpid(daemonPid, NULL, 0) == -1) { - perror("wait for daemon failed"); - } + int status; + return waitPid(daemonPid, status); } void launcherSignalHandler(int sig) @@ -108,21 +109,22 @@ void cleanupProcess() signal(SIGHUP, SIG_DFL); } -void startByLauncher(const char* path, const char* const argv[]) +bool startByLauncher(const char* path, const char* const argv[]) { cleanupProcess(); daemonPid = fork(); if (daemonPid == -1) { perror("fork failed"); - return; + return false; } if (daemonPid == 0) { - startDaemon(path, argv); - _exit(1); + if (!startDaemon(path, argv)) { + return false; + } } registerLauncherSignalHandler(); registerParentDiedNotification(); - waitForDaemon(); + return waitForDaemon(); } } // namespace @@ -147,12 +149,13 @@ void ScopedDaemon::start(const char* path, const char* const argv[], const bool throw std::runtime_error("fork failed"); } if (mPid == 0) { + bool ret; if (useLauncher) { - startByLauncher(path, argv); + ret = startByLauncher(path, argv); } else { - startDaemon(path, argv); + ret = startDaemon(path, argv); } - _exit(0); + _exit(ret ? EXIT_SUCCESS : EXIT_FAILURE); } } @@ -164,8 +167,12 @@ void ScopedDaemon::stop() if (kill(mPid, SIGTERM) == -1) { LOGE("kill failed"); } - if (waitpid(mPid, NULL, 0) == -1) { - LOGE("waitpid failed"); + int status; + if (!waitPid(mPid, status)) { + throw std::runtime_error("waitpid failed"); + } + if (status != EXIT_SUCCESS) { + LOGW("process exit with status " << status); } mPid = -1; } diff --git a/tests/unit_tests/utils/scoped-daemon.hpp b/tests/unit_tests/utils/scoped-daemon.hpp index 89e630c..b3eab29 100644 --- a/tests/unit_tests/utils/scoped-daemon.hpp +++ b/tests/unit_tests/utils/scoped-daemon.hpp @@ -50,7 +50,7 @@ public: * @param argv arguments passed to the daemon * @param useLauncher use additional launcher process */ - void start(const char* path, const char* const argv[], const bool useLauncher = true); + void start(const char* path, const char* const argv[], const bool useLauncher = false); /** * Stops a daemon by sending SIGTERM and waits for a process. -- 2.7.4 From 316605cca8c654878acfc67deb5a62103be2822b Mon Sep 17 00:00:00 2001 From: Jan Olszak Date: Mon, 8 Dec 2014 13:41:39 +0100 Subject: [PATCH 03/16] IPC: Replace PeerID witch peer's file descriptor [Bug/Feature] N/A [Cause] N/A [Solution] N/A [Verification] Build, install, run tests Change-Id: I30203990d9c9c3a58515d2fe09b074072122c156 --- common/ipc/client.cpp | 2 +- common/ipc/client.hpp | 6 +- common/ipc/internals/call-queue.hpp | 14 ++-- common/ipc/internals/processor.cpp | 134 ++++++++++++++++-------------------- common/ipc/internals/processor.hpp | 100 +++++++++++++-------------- common/ipc/service.hpp | 18 ++--- common/ipc/types.hpp | 14 ++-- tests/unit_tests/ipc/ut-ipc.cpp | 54 +++++++-------- 8 files changed, 165 insertions(+), 177 deletions(-) diff --git a/common/ipc/client.cpp b/common/ipc/client.cpp index c806e7b..8b0e458 100644 --- a/common/ipc/client.cpp +++ b/common/ipc/client.cpp @@ -55,7 +55,7 @@ void Client::start() // Initialize the connection with the server LOGD("Connecting to " + mSocketPath); auto socketPtr = std::make_shared(Socket::connectSocket(mSocketPath)); - mServiceID = mProcessor.addPeer(socketPtr); + mServiceFD = mProcessor.addPeer(socketPtr); // Start listening mProcessor.start(); diff --git a/common/ipc/client.hpp b/common/ipc/client.hpp index 3178474..6f8b049 100644 --- a/common/ipc/client.hpp +++ b/common/ipc/client.hpp @@ -156,7 +156,7 @@ public: const std::shared_ptr& data); private: - PeerID mServiceID; + FileDescriptor mServiceFD; Processor mProcessor; std::string mSocketPath; }; @@ -185,7 +185,7 @@ std::shared_ptr Client::callSync(const MethodID methodID, unsigned int timeoutMS) { LOGD("Sync calling method: " << methodID); - return mProcessor.callSync(methodID, mServiceID, data, timeoutMS); + return mProcessor.callSync(methodID, mServiceFD, data, timeoutMS); } template @@ -196,7 +196,7 @@ void Client::callAsync(const MethodID methodID, LOGD("Async calling method: " << methodID); mProcessor.callAsync(methodID, - mServiceID, + mServiceFD, data, resultCallback); LOGD("Async called method: " << methodID); diff --git a/common/ipc/internals/call-queue.hpp b/common/ipc/internals/call-queue.hpp index 4d1ecf6..7911d7a 100644 --- a/common/ipc/internals/call-queue.hpp +++ b/common/ipc/internals/call-queue.hpp @@ -48,7 +48,7 @@ public: Call() = default; Call(Call&&) = default; - PeerID peerID; + FileDescriptor peerFD; MethodID methodID; MessageID messageID; std::shared_ptr data; @@ -66,14 +66,14 @@ public: template MessageID push(const MethodID methodID, - const PeerID peerID, + const FileDescriptor peerFD, const std::shared_ptr& data, const typename ResultHandler::type& process); template MessageID push(const MethodID methodID, - const PeerID peerID, + const FileDescriptor peerFD, const std::shared_ptr& data); Call pop(); @@ -90,13 +90,13 @@ private: template MessageID CallQueue::push(const MethodID methodID, - const PeerID peerID, + const FileDescriptor peerFD, const std::shared_ptr& data, const typename ResultHandler::type& process) { Call call; call.methodID = methodID; - call.peerID = peerID; + call.peerFD = peerFD; call.data = data; MessageID messageID = getNextMessageID(); @@ -124,12 +124,12 @@ MessageID CallQueue::push(const MethodID methodID, template MessageID CallQueue::push(const MethodID methodID, - const PeerID peerID, + const FileDescriptor peerFD, const std::shared_ptr& data) { Call call; call.methodID = methodID; - call.peerID = peerID; + call.peerFD = peerFD; call.data = data; MessageID messageID = getNextMessageID(); diff --git a/common/ipc/internals/processor.cpp b/common/ipc/internals/processor.cpp index b134b08..7ac378e 100644 --- a/common/ipc/internals/processor.cpp +++ b/common/ipc/internals/processor.cpp @@ -55,8 +55,7 @@ Processor::Processor(const PeerCallback& newPeerCallback, const unsigned int maxNumberOfPeers) : mNewPeerCallback(newPeerCallback), mRemovedPeerCallback(removedPeerCallback), - mMaxNumberOfPeers(maxNumberOfPeers), - mPeerIDCounter(0) + mMaxNumberOfPeers(maxNumberOfPeers) { LOGT("Creating Processor"); using namespace std::placeholders; @@ -120,37 +119,37 @@ void Processor::removeMethod(const MethodID methodID) mMethodsCallbacks.erase(methodID); } -PeerID Processor::addPeer(const std::shared_ptr& socketPtr) +FileDescriptor Processor::addPeer(const std::shared_ptr& socketPtr) { LOGT("Adding socket"); - PeerID peerID; + FileDescriptor peerFD; { Lock lock(mSocketsMutex); - peerID = getNextPeerID(); - SocketInfo socketInfo(peerID, std::move(socketPtr)); + peerFD = socketPtr->getFD(); + SocketInfo socketInfo(peerFD, std::move(socketPtr)); mNewSockets.push(std::move(socketInfo)); } - LOGI("New peer added. Id: " << peerID); + LOGI("New peer added. Id: " << peerFD); mEventQueue.send(Event::ADD_PEER); - return peerID; + return peerFD; } -void Processor::removePeer(const PeerID peerID) +void Processor::removePeer(const FileDescriptor peerFD) { std::shared_ptr conditionPtr(new std::condition_variable()); { Lock lock(mSocketsMutex); - RemovePeerRequest request(peerID, conditionPtr); + RemovePeerRequest request(peerFD, conditionPtr); mPeersToDelete.push(std::move(request)); } mEventQueue.send(Event::REMOVE_PEER); - auto isPeerDeleted = [&peerID, this]()->bool { + auto isPeerDeleted = [&peerFD, this]()->bool { Lock lock(mSocketsMutex); - return mSockets.count(peerID) == 0; + return mSockets.count(peerFD) == 0; }; std::mutex mutex; @@ -158,16 +157,16 @@ void Processor::removePeer(const PeerID peerID) conditionPtr->wait(lock, isPeerDeleted); } -void Processor::removePeerInternal(const PeerID peerID, Status status) +void Processor::removePeerInternal(const FileDescriptor peerFD, Status status) { - LOGW("Removing peer. ID: " << peerID); + LOGW("Removing peer. ID: " << peerFD); { Lock lock(mSocketsMutex); - mSockets.erase(peerID); + mSockets.erase(peerFD); // Remove from signal addressees for (auto it = mSignalsPeers.begin(); it != mSignalsPeers.end();) { - it->second.remove(peerID); + it->second.remove(peerFD); if (it->second.empty()) { it = mSignalsPeers.erase(it); } else { @@ -182,7 +181,7 @@ void Processor::removePeerInternal(const PeerID peerID, Status status) std::shared_ptr data; for (auto it = mReturnCallbacks.begin(); it != mReturnCallbacks.end();) { - if (it->second.peerID == peerID) { + if (it->second.peerFD == peerFD) { IGNORE_EXCEPTIONS(it->second.process(status, data)); it = mReturnCallbacks.erase(it); } else { @@ -196,7 +195,7 @@ void Processor::removePeerInternal(const PeerID peerID, Status status) Lock lock(mCallbacksMutex); if (mRemovedPeerCallback) { // Notify about the deletion - mRemovedPeerCallback(peerID); + mRemovedPeerCallback(peerFD); } } @@ -264,22 +263,21 @@ void Processor::run() bool Processor::handleLostConnections() { - std::list peersToRemove; + std::vector peersToRemove; { Lock lock(mSocketsMutex); - auto socketIt = mSockets.begin(); - for (unsigned int i = 1; i < mFDs.size(); ++i, ++socketIt) { + for (unsigned int i = 1; i < mFDs.size(); ++i) { if (mFDs[i].revents & POLLHUP) { - LOGI("Lost connection to peer: " << socketIt->first); + LOGI("Lost connection to peer: " << mFDs[i].fd); mFDs[i].revents &= ~(POLLHUP); - peersToRemove.push_back(socketIt->first); + peersToRemove.push_back(mFDs[i].fd); } } } - for (const PeerID peerID : peersToRemove) { - removePeerInternal(peerID, Status::PEER_DISCONNECTED); + for (const FileDescriptor peerFD : peersToRemove) { + removePeerInternal(peerFD, Status::PEER_DISCONNECTED); } return !peersToRemove.empty(); @@ -287,27 +285,26 @@ bool Processor::handleLostConnections() bool Processor::handleInputs() { - std::list> > peersWithInput; + std::vector> socketsWithInput; { Lock lock(mSocketsMutex); - auto socketIt = mSockets.begin(); - for (unsigned int i = 1; i < mFDs.size(); ++i, ++socketIt) { + for (unsigned int i = 1; i < mFDs.size(); ++i) { if (mFDs[i].revents & POLLIN) { mFDs[i].revents &= ~(POLLIN); - peersWithInput.push_back(*socketIt); + socketsWithInput.push_back(mSockets[mFDs[i].fd]); } } } bool pollChanged = false; // Handle input outside the critical section - for (const auto& peer : peersWithInput) { - pollChanged = pollChanged || handleInput(peer.first, *peer.second); + for (const auto& socketPtr : socketsWithInput) { + pollChanged = pollChanged || handleInput(*socketPtr); } return pollChanged; } -bool Processor::handleInput(const PeerID peerID, const Socket& socket) +bool Processor::handleInput(const Socket& socket) { LOGT("Handle incoming data"); MethodID methodID; @@ -318,7 +315,7 @@ bool Processor::handleInput(const PeerID peerID, const Socket& socket) socket.read(&messageID, sizeof(messageID)); if (methodID == RETURN_METHOD_ID) { - return onReturnValue(peerID, socket, messageID); + return onReturnValue(socket, messageID); } else { Lock lock(mCallsMutex); @@ -326,19 +323,19 @@ bool Processor::handleInput(const PeerID peerID, const Socket& socket) // Method std::shared_ptr methodCallbacks = mMethodsCallbacks.at(methodID); lock.unlock(); - return onRemoteCall(peerID, socket, methodID, messageID, methodCallbacks); + return onRemoteCall(socket, methodID, messageID, methodCallbacks); } else if (mSignalsCallbacks.count(methodID)) { // Signal std::shared_ptr signalCallbacks = mSignalsCallbacks.at(methodID); lock.unlock(); - return onRemoteSignal(peerID, socket, methodID, messageID, signalCallbacks); + return onRemoteSignal(socket, methodID, messageID, signalCallbacks); } else { // Nothing lock.unlock(); LOGW("No method or signal callback for methodID: " << methodID); - removePeerInternal(peerID, Status::NAUGHTY_PEER); + removePeerInternal(socket.getFD(), Status::NAUGHTY_PEER); return true; } } @@ -347,20 +344,19 @@ bool Processor::handleInput(const PeerID peerID, const Socket& socket) return false; } -std::shared_ptr Processor::onNewSignals(const PeerID peerID, +std::shared_ptr Processor::onNewSignals(const FileDescriptor peerFD, std::shared_ptr& data) { - LOGD("New signals for peer: " << peerID); + LOGD("New signals for peer: " << peerFD); Lock lock(mSocketsMutex); for (MethodID methodID : data->ids) { - mSignalsPeers[methodID].push_back(peerID); + mSignalsPeers[methodID].push_back(peerFD); } return std::make_shared(); } -bool Processor::onReturnValue(const PeerID peerID, - const Socket& socket, +bool Processor::onReturnValue(const Socket& socket, const MessageID messageID) { LOGI("Return value for messageID: " << messageID); @@ -372,7 +368,7 @@ bool Processor::onReturnValue(const PeerID peerID, mReturnCallbacks.erase(messageID); } catch (const std::out_of_range&) { LOGW("No return callback for messageID: " << messageID); - removePeerInternal(peerID, Status::NAUGHTY_PEER); + removePeerInternal(socket.getFD(), Status::NAUGHTY_PEER); return true; } @@ -383,7 +379,7 @@ bool Processor::onReturnValue(const PeerID peerID, } catch (const std::exception& e) { LOGE("Exception during parsing: " << e.what()); IGNORE_EXCEPTIONS(returnCallbacks.process(Status::PARSING_ERROR, data)); - removePeerInternal(peerID, Status::PARSING_ERROR); + removePeerInternal(socket.getFD(), Status::PARSING_ERROR); return true; } @@ -393,8 +389,7 @@ bool Processor::onReturnValue(const PeerID peerID, return false; } -bool Processor::onRemoteSignal(const PeerID peerID, - const Socket& socket, +bool Processor::onRemoteSignal(const Socket& socket, const MethodID methodID, const MessageID messageID, std::shared_ptr signalCallbacks) @@ -407,24 +402,23 @@ bool Processor::onRemoteSignal(const PeerID peerID, data = signalCallbacks->parse(socket.getFD()); } catch (const std::exception& e) { LOGE("Exception during parsing: " << e.what()); - removePeerInternal(peerID, Status::PARSING_ERROR); + removePeerInternal(socket.getFD(), Status::PARSING_ERROR); return true; } LOGT("Signal callback for methodID: " << methodID << "; messageID: " << messageID); try { - signalCallbacks->signal(peerID, data); + signalCallbacks->signal(socket.getFD(), data); } catch (const std::exception& e) { LOGE("Exception in method handler: " << e.what()); - removePeerInternal(peerID, Status::NAUGHTY_PEER); + removePeerInternal(socket.getFD(), Status::NAUGHTY_PEER); return true; } return false; } -bool Processor::onRemoteCall(const PeerID peerID, - const Socket& socket, +bool Processor::onRemoteCall(const Socket& socket, const MethodID methodID, const MessageID messageID, std::shared_ptr methodCallbacks) @@ -437,17 +431,17 @@ bool Processor::onRemoteCall(const PeerID peerID, data = methodCallbacks->parse(socket.getFD()); } catch (const std::exception& e) { LOGE("Exception during parsing: " << e.what()); - removePeerInternal(peerID, Status::PARSING_ERROR); + removePeerInternal(socket.getFD(), Status::PARSING_ERROR); return true; } LOGT("Process callback for methodID: " << methodID << "; messageID: " << messageID); std::shared_ptr returnData; try { - returnData = methodCallbacks->method(peerID, data); + returnData = methodCallbacks->method(socket.getFD(), data); } catch (const std::exception& e) { LOGE("Exception in method handler: " << e.what()); - removePeerInternal(peerID, Status::NAUGHTY_PEER); + removePeerInternal(socket.getFD(), Status::NAUGHTY_PEER); return true; } @@ -460,7 +454,7 @@ bool Processor::onRemoteCall(const PeerID peerID, methodCallbacks->serialize(socket.getFD(), returnData); } catch (const std::exception& e) { LOGE("Exception during serialization: " << e.what()); - removePeerInternal(peerID, Status::SERIALIZATION_ERROR); + removePeerInternal(socket.getFD(), Status::SERIALIZATION_ERROR); return true; } @@ -512,21 +506,21 @@ bool Processor::onNewPeer() mNewSockets.pop(); if (mSockets.size() > mMaxNumberOfPeers) { - LOGE("There are too many peers. I don't accept the connection with " << socketInfo.peerID); + LOGE("There are too many peers. I don't accept the connection with " << socketInfo.peerFD); return false; } - if (mSockets.count(socketInfo.peerID) != 0) { - LOGE("There already was a socket for peerID: " << socketInfo.peerID); + if (mSockets.count(socketInfo.peerFD) != 0) { + LOGE("There already was a socket for peerFD: " << socketInfo.peerFD); return false; } - mSockets[socketInfo.peerID] = std::move(socketInfo.socketPtr); + mSockets[socketInfo.peerFD] = std::move(socketInfo.socketPtr); } // Broadcast the new signal to peers LOGW("Sending handled signals"); - std::list peersIDs; + std::list peersIDs; { Lock lock(mSocketsMutex); for (const auto kv : mSockets) { @@ -543,9 +537,9 @@ bool Processor::onNewPeer() } auto data = std::make_shared(ids); - for (const PeerID peerID : peersIDs) { + for (const FileDescriptor peerFD : peersIDs) { callInternal(REGISTER_SIGNAL_METHOD_ID, - peerID, + peerFD, data, discardResultHandler); } @@ -558,7 +552,7 @@ bool Processor::onNewPeer() Lock lock(mCallbacksMutex); if (mNewPeerCallback) { // Notify about the new user. - mNewPeerCallback(socketInfo.peerID); + mNewPeerCallback(socketInfo.peerFD); } } return true; @@ -573,17 +567,11 @@ bool Processor::onRemovePeer() mPeersToDelete.pop(); } - removePeerInternal(request.peerID, Status::REMOVED_PEER); + removePeerInternal(request.peerFD, Status::REMOVED_PEER); request.conditionPtr->notify_all(); return true; } -PeerID Processor::getNextPeerID() -{ - // TODO: This method of generating UIDs is buggy. To be changed. - return ++mPeerIDCounter; -} - CallQueue::Call Processor::getCall() { Lock lock(mCallsMutex); @@ -599,9 +587,9 @@ bool Processor::onCall() try { // Get the peer's socket Lock lock(mSocketsMutex); - socketPtr = mSockets.at(call.peerID); + socketPtr = mSockets.at(call.peerFD); } catch (const std::out_of_range&) { - LOGE("Peer disconnected. No socket with a peerID: " << call.peerID); + LOGE("Peer disconnected. No socket with a peerFD: " << call.peerFD); IGNORE_EXCEPTIONS(call.process(Status::PEER_DISCONNECTED, call.data)); return false; } @@ -612,7 +600,7 @@ bool Processor::onCall() if (mReturnCallbacks.count(call.messageID) != 0) { LOGE("There already was a return callback for messageID: " << call.messageID); } - mReturnCallbacks[call.messageID] = std::move(ReturnCallbacks(call.peerID, + mReturnCallbacks[call.messageID] = std::move(ReturnCallbacks(call.peerFD, std::move(call.parse), std::move(call.process))); } @@ -634,7 +622,7 @@ bool Processor::onCall() mReturnCallbacks.erase(call.messageID); } - removePeerInternal(call.peerID, Status::SERIALIZATION_ERROR); + removePeerInternal(call.peerFD, Status::SERIALIZATION_ERROR); return true; } diff --git a/common/ipc/internals/processor.hpp b/common/ipc/internals/processor.hpp index da2a5b9..476e662 100644 --- a/common/ipc/internals/processor.hpp +++ b/common/ipc/internals/processor.hpp @@ -35,8 +35,6 @@ #include "logger/logger.hpp" #include - -#include #include #include #include @@ -76,6 +74,9 @@ const unsigned int DEFAULT_METHOD_TIMEOUT = 1000; * - helper function for removing from unordered map * - new way to generate UIDs * - callbacks for serialization/parsing +* - store Sockets in a vector, maybe SocketStore? +* +* */ class Processor { public: @@ -141,16 +142,16 @@ public: * Calls the newPeerCallback. * * @param socketPtr pointer to the new socket - * @return peerID of the new socket + * @return peerFD of the new socket */ - PeerID addPeer(const std::shared_ptr& socketPtr); + FileDescriptor addPeer(const std::shared_ptr& socketPtr); /** * Request removing peer and wait * - * @param peerID id of the peer + * @param peerFD id of the peer */ - void removePeer(const PeerID peerID); + void removePeer(const FileDescriptor peerFD); /** * Saves the callbacks connected to the method id. @@ -197,7 +198,7 @@ public: * Synchronous method call. * * @param methodID API dependent id of the method - * @param peerID id of the peer + * @param peerFD id of the peer * @param data data to sent * @param timeoutMS how long to wait for the return value before throw * @tparam SentDataType data type to send @@ -205,7 +206,7 @@ public: */ template std::shared_ptr callSync(const MethodID methodID, - const PeerID peerID, + const FileDescriptor peerFD, const std::shared_ptr& data, unsigned int timeoutMS = 500); @@ -213,7 +214,7 @@ public: * Asynchronous method call * * @param methodID API dependent id of the method - * @param peerID id of the peer + * @param peerFD id of the peer * @param data data to sent * @param process callback processing the return data * @tparam SentDataType data type to send @@ -221,7 +222,7 @@ public: */ template MessageID callAsync(const MethodID methodID, - const PeerID peerID, + const FileDescriptor peerFD, const std::shared_ptr& data, const typename ResultHandler::type& process); @@ -292,10 +293,10 @@ private: ReturnCallbacks(ReturnCallbacks&&) = default; ReturnCallbacks& operator=(ReturnCallbacks &&) = default; - ReturnCallbacks(PeerID peerID, const ParseCallback& parse, const ResultHandler::type& process) - : peerID(peerID), parse(parse), process(process) {} + ReturnCallbacks(FileDescriptor peerFD, const ParseCallback& parse, const ResultHandler::type& process) + : peerFD(peerFD), parse(parse), process(process) {} - PeerID peerID; + FileDescriptor peerFD; ParseCallback parse; ResultHandler::type process; }; @@ -307,10 +308,10 @@ private: SocketInfo(SocketInfo&&) = default; SocketInfo& operator=(SocketInfo &&) = default; - SocketInfo(const PeerID peerID, const std::shared_ptr& socketPtr) - : peerID(peerID), socketPtr(socketPtr) {} + SocketInfo(const FileDescriptor peerFD, const std::shared_ptr& socketPtr) + : peerFD(peerFD), socketPtr(socketPtr) {} - PeerID peerID; + FileDescriptor peerFD; std::shared_ptr socketPtr; }; @@ -321,11 +322,11 @@ private: RemovePeerRequest(RemovePeerRequest&&) = default; RemovePeerRequest& operator=(RemovePeerRequest &&) = default; - RemovePeerRequest(const PeerID peerID, + RemovePeerRequest(const FileDescriptor peerFD, const std::shared_ptr& conditionPtr) - : peerID(peerID), conditionPtr(conditionPtr) {} + : peerFD(peerFD), conditionPtr(conditionPtr) {} - PeerID peerID; + FileDescriptor peerFD; std::shared_ptr conditionPtr; }; @@ -345,12 +346,13 @@ private: CallQueue mCalls; std::unordered_map> mMethodsCallbacks; std::unordered_map> mSignalsCallbacks; - std::unordered_map> mSignalsPeers; + std::unordered_map> mSignalsPeers; // Mutex for changing mSockets map. // Shouldn't be locked on any read/write, that could block. Just copy the ptr. std::mutex mSocketsMutex; - std::unordered_map > mSockets; + std::unordered_map > mSockets; + std::vector mFDs; std::queue mNewSockets; std::queue mPeersToDelete; @@ -366,9 +368,6 @@ private: unsigned int mMaxNumberOfPeers; std::thread mThread; - std::vector mFDs; - - std::atomic mPeerIDCounter; template void addMethodHandlerInternal(const MethodID methodID, @@ -376,7 +375,7 @@ private: template MessageID callInternal(const MethodID methodID, - const PeerID peerID, + const FileDescriptor peerFD, const std::shared_ptr& data, const typename ResultHandler::type& process); @@ -390,26 +389,23 @@ private: bool onRemovePeer(); bool handleLostConnections(); bool handleInputs(); - bool handleInput(const PeerID peerID, const Socket& socket); - bool onReturnValue(const PeerID peerID, - const Socket& socket, + bool handleInput(const Socket& socket); + bool onReturnValue(const Socket& socket, const MessageID messageID); - bool onRemoteCall(const PeerID peerID, - const Socket& socket, + bool onRemoteCall(const Socket& socket, const MethodID methodID, const MessageID messageID, std::shared_ptr methodCallbacks); - bool onRemoteSignal(const PeerID peerID, - const Socket& socket, + bool onRemoteSignal(const Socket& socket, const MethodID methodID, const MessageID messageID, std::shared_ptr signalCallbacks); void resetPolling(); - PeerID getNextPeerID(); + FileDescriptor getNextFileDescriptor(); CallQueue::Call getCall(); - void removePeerInternal(const PeerID peerID, Status status); + void removePeerInternal(const FileDescriptor peerFD, Status status); - std::shared_ptr onNewSignals(const PeerID peerID, + std::shared_ptr onNewSignals(const FileDescriptor peerFD, std::shared_ptr& data); @@ -432,9 +428,9 @@ void Processor::addMethodHandlerInternal(const MethodID methodID, config::saveToFD(fd, *std::static_pointer_cast(data)); }; - methodCall.method = [method](const PeerID peerID, std::shared_ptr& data)->std::shared_ptr { + methodCall.method = [method](const FileDescriptor peerFD, std::shared_ptr& data)->std::shared_ptr { std::shared_ptr tmpData = std::static_pointer_cast(data); - return method(peerID, tmpData); + return method(peerFD, tmpData); }; { @@ -488,9 +484,9 @@ void Processor::addSignalHandler(const MethodID methodID, return data; }; - signalCall.signal = [handler](const PeerID peerID, std::shared_ptr& data) { + signalCall.signal = [handler](const FileDescriptor peerFD, std::shared_ptr& data) { std::shared_ptr tmpData = std::static_pointer_cast(data); - handler(peerID, tmpData); + handler(peerFD, tmpData); }; { @@ -503,7 +499,7 @@ void Processor::addSignalHandler(const MethodID methodID, std::vector ids {methodID}; auto data = std::make_shared(ids); - std::list peersIDs; + std::list peersIDs; { Lock lock(mSocketsMutex); for (const auto kv : mSockets) { @@ -511,9 +507,9 @@ void Processor::addSignalHandler(const MethodID methodID, } } - for (const PeerID peerID : peersIDs) { + for (const FileDescriptor peerFD : peersIDs) { callSync(REGISTER_SIGNAL_METHOD_ID, - peerID, + peerFD, data, DEFAULT_METHOD_TIMEOUT); } @@ -522,12 +518,12 @@ void Processor::addSignalHandler(const MethodID methodID, template MessageID Processor::callInternal(const MethodID methodID, - const PeerID peerID, + const FileDescriptor peerFD, const std::shared_ptr& data, const typename ResultHandler::type& process) { Lock lock(mCallsMutex); - MessageID messageID = mCalls.push(methodID, peerID, data, process); + MessageID messageID = mCalls.push(methodID, peerFD, data, process); mEventQueue.send(Event::CALL); return messageID; @@ -535,7 +531,7 @@ MessageID Processor::callInternal(const MethodID methodID, template MessageID Processor::callAsync(const MethodID methodID, - const PeerID peerID, + const FileDescriptor peerFD, const std::shared_ptr& data, const typename ResultHandler::type& process) { @@ -544,13 +540,13 @@ MessageID Processor::callAsync(const MethodID methodID, throw IPCException("The Processor thread is not started. Can't send any data."); } - return callInternal(methodID, peerID, data, process); + return callInternal(methodID, peerFD, data, process); } template std::shared_ptr Processor::callSync(const MethodID methodID, - const PeerID peerID, + const FileDescriptor peerFD, const std::shared_ptr& data, unsigned int timeoutMS) { @@ -568,7 +564,7 @@ std::shared_ptr Processor::callSync(const MethodID methodID, }; MessageID messageID = callAsync(methodID, - peerID, + peerFD, data, process); @@ -586,7 +582,7 @@ std::shared_ptr Processor::callSync(const MethodID methodID, } } if (isTimeout) { - removePeer(peerID); + removePeer(peerFD); LOGE("Function call timeout; methodID: " << methodID); throw IPCTimeoutException("Function call timeout; methodID: " + std::to_string(methodID)); } else { @@ -609,15 +605,15 @@ void Processor::signal(const MethodID methodID, throw IPCException("The Processor thread is not started. Can't send any data."); } - std::list peersIDs; + std::list peersIDs; { Lock lock(mSocketsMutex); peersIDs = mSignalsPeers[methodID]; } - for (const PeerID peerID : peersIDs) { + for (const FileDescriptor peerFD : peersIDs) { Lock lock(mCallsMutex); - mCalls.push(methodID, peerID, data); + mCalls.push(methodID, peerFD, data); mEventQueue.send(Event::CALL); } } diff --git a/common/ipc/service.hpp b/common/ipc/service.hpp index ac22eb2..317311d 100644 --- a/common/ipc/service.hpp +++ b/common/ipc/service.hpp @@ -129,7 +129,7 @@ public: */ template std::shared_ptr callSync(const MethodID methodID, - const PeerID peerID, + const FileDescriptor peerFD, const std::shared_ptr& data, unsigned int timeoutMS = 500); @@ -144,7 +144,7 @@ public: */ template void callAsync(const MethodID methodID, - const PeerID peerID, + const FileDescriptor peerFD, const std::shared_ptr& data, const typename ResultHandler::type& resultCallback); @@ -187,27 +187,27 @@ void Service::addSignalHandler(const MethodID methodID, template std::shared_ptr Service::callSync(const MethodID methodID, - const PeerID peerID, + const FileDescriptor peerFD, const std::shared_ptr& data, unsigned int timeoutMS) { - LOGD("Sync calling method: " << methodID << " for user: " << peerID); - return mProcessor.callSync(methodID, peerID, data, timeoutMS); + LOGD("Sync calling method: " << methodID << " for user: " << peerFD); + return mProcessor.callSync(methodID, peerFD, data, timeoutMS); } template void Service::callAsync(const MethodID methodID, - const PeerID peerID, + const FileDescriptor peerFD, const std::shared_ptr& data, const typename ResultHandler::type& resultCallback) { - LOGD("Async calling method: " << methodID << " for user: " << peerID); + LOGD("Async calling method: " << methodID << " for user: " << peerFD); mProcessor.callAsync(methodID, - peerID, + peerFD, data, resultCallback); - LOGD("Async called method: " << methodID << "for user: " << peerID); + LOGD("Async called method: " << methodID << "for user: " << peerFD); } template diff --git a/common/ipc/types.hpp b/common/ipc/types.hpp index 6588fb0..5fe9188 100644 --- a/common/ipc/types.hpp +++ b/common/ipc/types.hpp @@ -34,11 +34,12 @@ namespace security_containers { namespace ipc { -typedef std::function PeerCallback; -typedef unsigned int PeerID; +typedef int FileDescriptor; typedef unsigned int MethodID; typedef unsigned int MessageID; +typedef std::function PeerCallback; + enum class Status : int { OK = 0, PARSING_ERROR, @@ -55,17 +56,20 @@ void throwOnError(const Status status); template struct MethodHandler { - typedef std::function(PeerID, std::shared_ptr&)> type; + typedef std::function(FileDescriptor peerFD, + std::shared_ptr& data)> type; }; template struct SignalHandler { - typedef std::function&)> type; + typedef std::function& data)> type; }; template struct ResultHandler { - typedef std::function&)> type; + typedef std::function& resultData)> type; }; } // namespace ipc diff --git a/tests/unit_tests/ipc/ut-ipc.cpp b/tests/unit_tests/ipc/ut-ipc.cpp index b8b9e95..679f3df 100644 --- a/tests/unit_tests/ipc/ut-ipc.cpp +++ b/tests/unit_tests/ipc/ut-ipc.cpp @@ -111,38 +111,38 @@ struct ThrowOnAcceptData { } }; -std::shared_ptr returnEmptyCallback(const PeerID, std::shared_ptr&) +std::shared_ptr returnEmptyCallback(const FileDescriptor, std::shared_ptr&) { return std::shared_ptr(new EmptyData()); } -std::shared_ptr returnDataCallback(const PeerID, std::shared_ptr&) +std::shared_ptr returnDataCallback(const FileDescriptor, std::shared_ptr&) { return std::shared_ptr(new SendData(1)); } -std::shared_ptr echoCallback(const PeerID, std::shared_ptr& data) +std::shared_ptr echoCallback(const FileDescriptor, std::shared_ptr& data) { return data; } -std::shared_ptr longEchoCallback(const PeerID, std::shared_ptr& data) +std::shared_ptr longEchoCallback(const FileDescriptor, std::shared_ptr& data) { std::this_thread::sleep_for(std::chrono::seconds(1)); return data; } -PeerID connect(Service& s, Client& c) +FileDescriptor connect(Service& s, Client& c) { - // Connects the Client to the Service and returns Clients PeerID + // Connects the Client to the Service and returns Clients FileDescriptor std::mutex mutex; std::condition_variable cv; - PeerID peerID = 0; - auto newPeerCallback = [&cv, &peerID, &mutex](const PeerID newPeerID) { + FileDescriptor peerFD = 0; + auto newPeerCallback = [&cv, &peerFD, &mutex](const FileDescriptor newFileDescriptor) { std::unique_lock lock(mutex); - peerID = newPeerID; + peerFD = newFileDescriptor; cv.notify_one(); }; @@ -155,11 +155,11 @@ PeerID connect(Service& s, Client& c) c.start(); std::unique_lock lock(mutex); - BOOST_CHECK(cv.wait_for(lock, std::chrono::milliseconds(1000), [&peerID]() { - return peerID != 0; + BOOST_CHECK(cv.wait_for(lock, std::chrono::milliseconds(1000), [&peerFD]() { + return peerFD != 0; })); - return peerID; + return peerFD; } void testEcho(Client& c, const MethodID methodID) @@ -169,10 +169,10 @@ void testEcho(Client& c, const MethodID methodID) BOOST_CHECK_EQUAL(recvData->intVal, sentData->intVal); } -void testEcho(Service& s, const MethodID methodID, const PeerID peerID) +void testEcho(Service& s, const MethodID methodID, const FileDescriptor peerFD) { std::shared_ptr sentData(new SendData(56)); - std::shared_ptr recvData = s.callSync(methodID, peerID, sentData); + std::shared_ptr recvData = s.callSync(methodID, peerFD, sentData); BOOST_CHECK_EQUAL(recvData->intVal, sentData->intVal); } @@ -216,17 +216,17 @@ BOOST_AUTO_TEST_CASE(ClientAddRemoveMethod) c.addMethodHandler(1, returnEmptyCallback); c.addMethodHandler(1, returnDataCallback); - PeerID peerID = connect(s, c); + FileDescriptor peerFD = connect(s, c); c.addMethodHandler(1, echoCallback); c.addMethodHandler(2, returnDataCallback); - testEcho(s, 1, peerID); + testEcho(s, 1, peerFD); c.removeMethod(1); c.removeMethod(2); - BOOST_CHECK_THROW(testEcho(s, 1, peerID), IPCException); + BOOST_CHECK_THROW(testEcho(s, 1, peerFD), IPCException); } BOOST_AUTO_TEST_CASE(ServiceStartStop) @@ -305,10 +305,10 @@ BOOST_AUTO_TEST_CASE(SyncServiceToClientEcho) Service s(socketPath); Client c(socketPath); c.addMethodHandler(1, echoCallback); - PeerID peerID = connect(s, c); + FileDescriptor peerFD = connect(s, c); std::shared_ptr sentData(new SendData(56)); - std::shared_ptr recvData = s.callSync(1, peerID, sentData); + std::shared_ptr recvData = s.callSync(1, peerFD, sentData); BOOST_CHECK_EQUAL(recvData->intVal, sentData->intVal); } @@ -349,7 +349,7 @@ BOOST_AUTO_TEST_CASE(AsyncServiceToClientEcho) Service s(socketPath); Client c(socketPath); c.addMethodHandler(1, echoCallback); - PeerID peerID = connect(s, c); + FileDescriptor peerFD = connect(s, c); // Async call std::shared_ptr sentData(new SendData(56)); @@ -364,7 +364,7 @@ BOOST_AUTO_TEST_CASE(AsyncServiceToClientEcho) cv.notify_one(); }; - s.callAsync(1, peerID, sentData, dataBack); + s.callAsync(1, peerFD, sentData, dataBack); // Wait for the response std::unique_lock lock(mutex); @@ -422,7 +422,7 @@ BOOST_AUTO_TEST_CASE(DisconnectedPeerError) { Service s(socketPath); - auto method = [](const PeerID, std::shared_ptr&) { + auto method = [](const FileDescriptor, std::shared_ptr&) { return std::shared_ptr(new SendData(1)); }; @@ -458,7 +458,7 @@ BOOST_AUTO_TEST_CASE(DisconnectedPeerError) BOOST_AUTO_TEST_CASE(ReadTimeout) { Service s(socketPath); - auto longEchoCallback = [](const PeerID, std::shared_ptr& data) { + auto longEchoCallback = [](const FileDescriptor, std::shared_ptr& data) { return std::shared_ptr(new LongSendData(data->intVal)); }; s.addMethodHandler(1, longEchoCallback); @@ -500,12 +500,12 @@ BOOST_AUTO_TEST_CASE(AddSignalInRuntime) connect(s, c); std::atomic_bool isHandlerACalled(false); - auto handlerA = [&isHandlerACalled](const PeerID, std::shared_ptr&) { + auto handlerA = [&isHandlerACalled](const FileDescriptor, std::shared_ptr&) { isHandlerACalled = true; }; std::atomic_bool isHandlerBCalled(false); - auto handlerB = [&isHandlerBCalled](const PeerID, std::shared_ptr&) { + auto handlerB = [&isHandlerBCalled](const FileDescriptor, std::shared_ptr&) { isHandlerBCalled = true; }; @@ -528,12 +528,12 @@ BOOST_AUTO_TEST_CASE(AddSignalOffline) Client c(socketPath); std::atomic_bool isHandlerACalled(false); - auto handlerA = [&isHandlerACalled](const PeerID, std::shared_ptr&) { + auto handlerA = [&isHandlerACalled](const FileDescriptor, std::shared_ptr&) { isHandlerACalled = true; }; std::atomic_bool isHandlerBCalled(false); - auto handlerB = [&isHandlerBCalled](const PeerID, std::shared_ptr&) { + auto handlerB = [&isHandlerBCalled](const FileDescriptor, std::shared_ptr&) { isHandlerBCalled = true; }; -- 2.7.4 From 59c2f3cfa7bd83eabf305cec961335153a815084 Mon Sep 17 00:00:00 2001 From: Mateusz Malicki Date: Tue, 2 Dec 2014 16:17:13 +0100 Subject: [PATCH 04/16] Test ability to copy union and to set union type [Bug/Feature] Test ability to copy union and to set union type [Cause] Need to copy and add new union elements [Solution] 1) Clear vector with unions; 2) set, copy and move elements [Verification] Build, install, tests Change-Id: Iea2d7eca36edcfd34f768d1e99a3da970300afd8 --- tests/unit_tests/config/ut-configuration.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/unit_tests/config/ut-configuration.cpp b/tests/unit_tests/config/ut-configuration.cpp index 7f9703b..8aab028 100644 --- a/tests/unit_tests/config/ut-configuration.cpp +++ b/tests/unit_tests/config/ut-configuration.cpp @@ -382,9 +382,18 @@ BOOST_AUTO_TEST_CASE(ConfigUnion) BOOST_CHECK_EQUAL(subConfig.intVal, 54321); BOOST_CHECK(testConfig.unions[0].is()); BOOST_CHECK(testConfig.unions[1].is()); - std::string out = saveToString(testConfig); BOOST_CHECK_EQUAL(out, jsonTestString); + + //Check move and copy + std::vector unions(2); + unions[0].set(2); + unions[1].set(std::move(testConfig.unions[1].as())); + BOOST_CHECK(testConfig.unions[1].as().intVector.empty()); + testConfig.unions.clear(); + testConfig.unions = unions; + out = saveToString(testConfig); + BOOST_CHECK_EQUAL(out, jsonTestString); } BOOST_AUTO_TEST_SUITE_END() -- 2.7.4 From b71b2a16ef7590741686c33bf8ca77f3c23d6817 Mon Sep 17 00:00:00 2001 From: Mateusz Malicki Date: Tue, 2 Dec 2014 14:52:47 +0100 Subject: [PATCH 05/16] Implementation of provisioning functions (store declarations) [Feature] Posibility to store provisioning declarations [Cause] N/A [Solution] Store declarations in config file (using libConfig) [Verification] Build, install, run tests Change-Id: Ie661f1b560adc96798acc7911a2d86eb12fa6616 --- server/container.cpp | 46 ++++++++++ server/container.hpp | 22 +++++ server/containers-manager.cpp | 64 +++++++++---- server/provisioning-config.hpp | 106 ++++++++++++++++++++++ tests/unit_tests/server/ut-containers-manager.cpp | 84 +++++++++++++---- 5 files changed, 284 insertions(+), 38 deletions(-) create mode 100644 server/provisioning-config.hpp diff --git a/server/container.cpp b/server/container.cpp index e1377d0..e411798 100644 --- a/server/container.cpp +++ b/server/container.cpp @@ -26,6 +26,7 @@ #include "container.hpp" #include "base-exception.hpp" +#include "provisioning-config.hpp" #include "logger/logger.hpp" #include "utils/paths.hpp" @@ -49,6 +50,18 @@ typedef std::lock_guard Lock; // TODO: move constants to the config file when default values are implemented there const int RECONNECT_RETRIES = 15; const int RECONNECT_DELAY = 1 * 1000; +const std::string CONTAINER_PROVISION_FILE = "provision.conf"; + +void declareUnit(const std::string& file, ContainerProvisioning::Unit&& unit) +{ + // TODO: Add to the dynamic configuration + ContainerProvisioning config; + if (fs::exists(file)) { + config::loadFromFile(file, config); + } + config.units.push_back(std::move(unit)); + config::saveToFile(file, config); +} } // namespace @@ -71,6 +84,8 @@ Container::Container(const std::string& containersPath, } mAdmin.reset(new ContainerAdmin(containersPath, lxcTemplatePrefix, mConfig)); + const fs::path baseProvision = fs::path(containersPath) / mAdmin->getId(); + mProvisionConfig = fs::absolute(CONTAINER_PROVISION_FILE, baseProvision).string(); } Container::~Container() @@ -398,5 +413,36 @@ void Container::proxyCallAsync(const std::string& busName, } } +void Container::declareFile(const int32_t& type, + const std::string& path, + const int32_t& flags, + const int32_t& mode) +{ + ContainerProvisioning::Unit unit; + unit.set(std::move(ContainerProvisioning::File({type, path, flags, mode}))); + + declareUnit(mProvisionConfig, std::move(unit)); +} + +void Container::declareMount(const std::string& source, + const std::string& target, + const std::string& type, + const int64_t& flags, + const std::string& data) +{ + ContainerProvisioning::Unit unit; + unit.set(std::move(ContainerProvisioning::Mount({source, target, type, flags, data}))); + + declareUnit(mProvisionConfig, std::move(unit)); +} + +void Container::declareLink(const std::string& source, + const std::string& target) +{ + ContainerProvisioning::Unit unit; + unit.set(std::move(ContainerProvisioning::Link({source, target}))); + + declareUnit(mProvisionConfig, std::move(unit)); +} } // namespace security_containers diff --git a/server/container.hpp b/server/container.hpp index b0264cb..fe9c317 100644 --- a/server/container.hpp +++ b/server/container.hpp @@ -231,6 +231,27 @@ public: */ int getVT() const; + /** + * Declare file, directory or pipe that will be created while container startup + */ + void declareFile(const int32_t& type, + const std::string& path, + const int32_t& flags, + const int32_t& mode); + /** + * Declare mount that will be created while container startup + */ + void declareMount(const std::string& source, + const std::string& target, + const std::string& type, + const int64_t& flags, + const std::string& data); + /** + * Declare link that will be created while container startup + */ + void declareLink(const std::string& source, + const std::string& target); + private: ContainerConfig mConfig; std::vector mPermittedToSend; @@ -248,6 +269,7 @@ private: DbusStateChangedCallback mDbusStateChangedCallback; std::string mDbusAddress; std::string mRunMountPoint; + std::string mProvisionConfig; void onNameLostCallback(); void reconnectHandler(); diff --git a/server/containers-manager.cpp b/server/containers-manager.cpp index c5fb04e..5250b98 100644 --- a/server/containers-manager.cpp +++ b/server/containers-manager.cpp @@ -582,39 +582,63 @@ void ContainersManager::handleGetContainerInfoCall(const std::string& id, rootfsPath.string().c_str())); } -void ContainersManager::handleDeclareFileCall(const std::string& /* container */, - const int32_t& /* type */, - const std::string& /* path */, - const int32_t& /* flags */, - const int32_t& /* mode */, +void ContainersManager::handleDeclareFileCall(const std::string& container, + const int32_t& type, + const std::string& path, + const int32_t& flags, + const int32_t& mode, dbus::MethodResultBuilder::Pointer result) { LOGI("DeclareFile call"); - LOGE("Not implemeted method"); - result->setError(api::ERROR_INTERNAL, "Not implemented"); + try { + mContainers.at(container)->declareFile(type, path, flags, mode); + result->setVoid(); + } catch (const std::out_of_range& ex) { + LOGE("No container with id=" << container); + result->setError(api::ERROR_INVALID_ID, "No such container id"); + } catch (const config::ConfigException& ex) { + LOGE("Can't declare file: " << ex.what()); + result->setError(api::ERROR_INTERNAL, "Internal error"); + } } -void ContainersManager::handleDeclareMountCall(const std::string& /* source */, - const std::string& /* container */, - const std::string& /* target */, - const std::string& /* type */, - const uint64_t& /* flags */, - const std::string& /* data */, +void ContainersManager::handleDeclareMountCall(const std::string& source, + const std::string& container, + const std::string& target, + const std::string& type, + const uint64_t& flags, + const std::string& data, dbus::MethodResultBuilder::Pointer result) { LOGI("DeclareMount call"); - LOGE("Not implemeted method"); - result->setError(api::ERROR_INTERNAL, "Not implemented"); + try { + mContainers.at(container)->declareMount(source, target, type, flags, data); + result->setVoid(); + } catch (const std::out_of_range& ex) { + LOGE("No container with id=" << container); + result->setError(api::ERROR_INVALID_ID, "No such container id"); + } catch (const config::ConfigException& ex) { + LOGE("Can't declare mount: " << ex.what()); + result->setError(api::ERROR_INTERNAL, "Internal error"); + } } -void ContainersManager::handleDeclareLinkCall(const std::string& /* source */, - const std::string& /* container */, - const std::string& /* target */, +void ContainersManager::handleDeclareLinkCall(const std::string& source, + const std::string& container, + const std::string& target, dbus::MethodResultBuilder::Pointer result) { LOGI("DeclareLink call"); - LOGE("Not implemeted method"); - result->setError(api::ERROR_INTERNAL, "Not implemented"); + try { + mContainers.at(container)->declareLink(source, target); + result->setVoid(); + } catch (const std::out_of_range& ex) { + LOGE("No container with id=" << container); + result->setError(api::ERROR_INVALID_ID, "No such container id"); + } catch (const config::ConfigException& ex) { + LOGE("Can't declare link: " << ex.what()); + result->setError(api::ERROR_INTERNAL, "Internal error"); + } } void ContainersManager::handleSetActiveContainerCall(const std::string& id, diff --git a/server/provisioning-config.hpp b/server/provisioning-config.hpp new file mode 100644 index 0000000..e5cf456 --- /dev/null +++ b/server/provisioning-config.hpp @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved + * + * Contact: Mateusz Malicki + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +/** + * @file + * @author Mateusz Malicki (m.malicki2@samsung.com) + * @brief Declaration of the class for storing container provisioning configuration + */ + + +#ifndef SERVER_PROVISIONING_CONFIG_HPP +#define SERVER_PROVISIONING_CONFIG_HPP + +#include "config/fields.hpp" +#include "config/fields-union.hpp" +#include +#include + + +namespace security_containers { + +struct ContainerProvisioning +{ + + struct File + { + std::int32_t type; + std::string path; + std::int32_t flags; + std::int32_t mode; + + CONFIG_REGISTER + ( + type, + path, + flags, + mode + ) + }; + + struct Mount + { + std::string source; + std::string target; + std::string type; + std::int64_t flags; + std::string data; + + CONFIG_REGISTER + ( + source, + target, + type, + flags, + data + ) + }; + + struct Link + { + std::string source; + std::string target; + + CONFIG_REGISTER + ( + source, + target + ) + }; + + struct Unit + { + CONFIG_DECLARE_UNION + ( + File, + Mount, + Link + ) + }; + + std::vector units; + + CONFIG_REGISTER + ( + units + ) +}; + +} + +#endif // SERVER_PROVISIONING_CONFIG_HPP diff --git a/tests/unit_tests/server/ut-containers-manager.cpp b/tests/unit_tests/server/ut-containers-manager.cpp index ac4a898..a55400a 100644 --- a/tests/unit_tests/server/ut-containers-manager.cpp +++ b/tests/unit_tests/server/ut-containers-manager.cpp @@ -27,6 +27,9 @@ #include "ut.hpp" #include "containers-manager.hpp" +#include "containers-manager-config.hpp" +#include "container-config.hpp" +#include "provisioning-config.hpp" #include "container-dbus-definitions.hpp" #include "host-dbus-definitions.hpp" #include "test-dbus-definitions.hpp" @@ -37,6 +40,7 @@ #include "dbus/connection.hpp" #include "dbus/exception.hpp" #include "utils/glib-loop.hpp" +#include "config/manager.hpp" #include "config/exception.hpp" #include "utils/latch.hpp" #include "utils/fs.hpp" @@ -78,6 +82,7 @@ const std::string FILE_CONTENT = "File content\n" "Line 2\n"; const std::string NON_EXISTANT_CONTAINER_ID = "NON_EXISTANT_CONTAINER_ID"; const std::string CONTAINERS_PATH = "/tmp/ut-containers"; // the same as in daemon.conf +const std::string PROVISON_CONFIG_FILE = "provision.conf"; class DbusAccessory { public: @@ -472,6 +477,26 @@ struct Fixture { {} }; +std::string getProvisionConfigPath(const std::string& container) +{ + namespace fs = boost::filesystem; + ContainersManagerConfig managerConfig; + loadFromFile(TEST_CONFIG_PATH, managerConfig); + for (const auto& containersPath : managerConfig.containerConfigs) { + ContainerConfig containerConfig; + const fs::path configConfigPath = fs::absolute(containersPath, + fs::path(TEST_CONFIG_PATH).parent_path()); + + loadFromFile(configConfigPath.string(), containerConfig); + if (containerConfig.name == container) { + const fs::path base = fs::path(managerConfig.containersPath) / fs::path(container); + return fs::absolute(PROVISON_CONFIG_FILE, base).string(); + } + } + BOOST_FAIL("There is no provision config file for " + container); + return std::string(); +} + } // namespace @@ -1070,44 +1095,67 @@ BOOST_AUTO_TEST_CASE(CreateDestroyContainerTest) BOOST_AUTO_TEST_CASE(DeclareFile) { - //TODO Fill after implementing const std::string container = EXPECTED_DBUSES_NO_DBUS.begin()->first; + const std::string provisionConfigPath = getProvisionConfigPath(container); ContainersManager cm(TEST_CONFIG_PATH); DbusAccessory dbus(DbusAccessory::HOST_ID); - BOOST_CHECK_EXCEPTION(dbus.callMethodDeclareFile(container, 1, "path", 747, 777), - DbusException, - expectedMessage("Not implemented")); + dbus.callMethodDeclareFile(container, 1, "path", 0747, 0777); + dbus.callMethodDeclareFile(container, 2, "path", 0747, 0777); + + ContainerProvisioning config; + BOOST_REQUIRE_NO_THROW(loadFromFile(provisionConfigPath, config)); + BOOST_REQUIRE_EQUAL(config.units.size(), 2); + BOOST_REQUIRE(config.units[0].is()); + BOOST_REQUIRE(config.units[1].is()); + const ContainerProvisioning::File& unit = config.units[0].as(); + BOOST_CHECK_EQUAL(unit.type, 1); + BOOST_CHECK_EQUAL(unit.path, "path"); + BOOST_CHECK_EQUAL(unit.flags, 0747); + BOOST_CHECK_EQUAL(unit.mode, 0777); } BOOST_AUTO_TEST_CASE(DeclareMount) { - //TODO Fill after implementing const std::string container = EXPECTED_DBUSES_NO_DBUS.begin()->first; + const std::string provisionConfigPath = getProvisionConfigPath(container); ContainersManager cm(TEST_CONFIG_PATH); DbusAccessory dbus(DbusAccessory::HOST_ID); - BOOST_CHECK_EXCEPTION(dbus.callMethodDeclareMount("/fake/path1", - container, - "/fake/path2", - "tmpfs", - 77, - "fake"), - DbusException, - expectedMessage("Not implemented")); - + dbus.callMethodDeclareMount("/fake/path1", container, "/fake/path2", "tmpfs", 077, "fake"); + dbus.callMethodDeclareMount("/fake/path2", container, "/fake/path2", "tmpfs", 077, "fake"); + + ContainerProvisioning config; + BOOST_REQUIRE_NO_THROW(loadFromFile(provisionConfigPath, config)); + BOOST_REQUIRE_EQUAL(config.units.size(), 2); + BOOST_REQUIRE(config.units[0].is()); + BOOST_REQUIRE(config.units[1].is()); + const ContainerProvisioning::Mount& unit = config.units[0].as(); + BOOST_CHECK_EQUAL(unit.source, "/fake/path1"); + BOOST_CHECK_EQUAL(unit.target, "/fake/path2"); + BOOST_CHECK_EQUAL(unit.type, "tmpfs"); + BOOST_CHECK_EQUAL(unit.flags, 077); + BOOST_CHECK_EQUAL(unit.data, "fake"); } BOOST_AUTO_TEST_CASE(DeclareLink) { - //TODO Fill after implementing const std::string container = EXPECTED_DBUSES_NO_DBUS.begin()->first; + const std::string provisionConfigPath = getProvisionConfigPath(container); ContainersManager cm(TEST_CONFIG_PATH); DbusAccessory dbus(DbusAccessory::HOST_ID); - BOOST_CHECK_EXCEPTION(dbus.callMethodDeclareLink("/fake/path1", container, "/fake/path2"), - DbusException, - expectedMessage("Not implemented")); + dbus.callMethodDeclareLink("/fake/path1", container, "/fake/path2"); + dbus.callMethodDeclareLink("/fake/path2", container, "/fake/path2"); + + ContainerProvisioning config; + BOOST_REQUIRE_NO_THROW(loadFromFile(provisionConfigPath, config)); + BOOST_REQUIRE_EQUAL(config.units.size(), 2); + BOOST_REQUIRE(config.units[0].is()); + BOOST_REQUIRE(config.units[1].is()); + const ContainerProvisioning::Link& unit = config.units[0].as(); + BOOST_CHECK_EQUAL(unit.source, "/fake/path1"); + BOOST_CHECK_EQUAL(unit.target, "/fake/path2"); } BOOST_AUTO_TEST_CASE(LockUnlockContainerTest) -- 2.7.4 From 551d10e8449af023a827efd453fa4cd9524ce350 Mon Sep 17 00:00:00 2001 From: Dariusz Michaluk Date: Fri, 5 Dec 2014 16:25:48 +0100 Subject: [PATCH 06/16] Rename security containers to vasum [Bug/Feature] N/A [Cause] N/A [Solution] N/A [Verification] Build, install, run tests Change-Id: I1df0eb506d03bde0f288322deaa0159741930199 Signed-off-by: Dariusz Michaluk --- .gitignore | 2 +- CMakeLists.txt | 14 +-- cli/CMakeLists.txt | 2 +- cli/command-line-interface.cpp | 6 +- cli/command-line-interface.hpp | 4 +- cli/main.cpp | 2 +- client/CMakeLists.txt | 2 +- client/utils.hpp | 6 +- ...iners-client-impl.cpp => vasum-client-impl.cpp} | 8 +- ...iners-client-impl.hpp => vasum-client-impl.hpp} | 12 +-- ...rity-containers-client.cpp => vasum-client.cpp} | 6 +- ...security-containers-client.h => vasum-client.h} | 98 +++++++++--------- client/{security-containers.pc.in => vasum.pc.in} | 8 +- common/base-exception.hpp | 12 +-- common/ipc/client.cpp | 4 +- common/ipc/client.hpp | 4 +- common/ipc/exception.hpp | 6 +- common/ipc/internals/acceptor.cpp | 4 +- common/ipc/internals/acceptor.hpp | 4 +- common/ipc/internals/call-queue.cpp | 4 +- common/ipc/internals/call-queue.hpp | 4 +- common/ipc/internals/event-queue.hpp | 4 +- common/ipc/internals/eventfd.cpp | 4 +- common/ipc/internals/eventfd.hpp | 4 +- common/ipc/internals/processor.cpp | 4 +- common/ipc/internals/processor.hpp | 4 +- common/ipc/internals/socket.cpp | 4 +- common/ipc/internals/socket.hpp | 4 +- common/ipc/internals/utils.cpp | 4 +- common/ipc/internals/utils.hpp | 4 +- common/ipc/service.cpp | 4 +- common/ipc/service.hpp | 4 +- common/ipc/types.cpp | 4 +- common/ipc/types.hpp | 4 +- common/lxc/exception.hpp | 9 +- common/lxc/zone.cpp | 4 +- common/lxc/zone.hpp | 4 +- common/utils/c-array.hpp | 4 +- common/utils/callback-guard.cpp | 4 +- common/utils/callback-guard.hpp | 4 +- common/utils/callback-wrapper.hpp | 4 +- common/utils/environment.cpp | 4 +- common/utils/environment.hpp | 4 +- common/utils/exception.hpp | 9 +- common/utils/execute.cpp | 4 +- common/utils/execute.hpp | 4 +- common/utils/file-wait.cpp | 4 +- common/utils/file-wait.hpp | 4 +- common/utils/fs.cpp | 4 +- common/utils/fs.hpp | 4 +- common/utils/glib-loop.cpp | 4 +- common/utils/glib-loop.hpp | 4 +- common/utils/img.cpp | 4 +- common/utils/img.hpp | 4 +- common/utils/initctl.cpp | 4 +- common/utils/initctl.hpp | 4 +- common/utils/latch.cpp | 4 +- common/utils/latch.hpp | 4 +- common/utils/paths.hpp | 4 +- common/utils/scoped-gerror.cpp | 4 +- common/utils/scoped-gerror.hpp | 4 +- common/utils/typeinfo.cpp | 4 +- common/utils/typeinfo.hpp | 4 +- common/utils/vt.cpp | 4 +- common/utils/vt.hpp | 4 +- .../org.tizen.containers.zone.daemon.conf.in | 2 +- container-daemon/daemon-connection.cpp | 4 +- container-daemon/daemon-connection.hpp | 4 +- container-daemon/daemon-dbus-definitions.hpp | 4 +- container-daemon/daemon.cpp | 4 +- container-daemon/daemon.hpp | 4 +- container-daemon/exception.hpp | 10 +- container-daemon/main.cpp | 6 +- container-daemon/runner.cpp | 4 +- container-daemon/runner.hpp | 4 +- .../configs/org.tizen.containers.zone.conf.in | 2 +- doc/doxygen.cfg | 2 +- ...ontainers.manifest => libvasum-client.manifest} | 0 ...ts.manifest => vasum-container-daemon.manifest} | 0 ...t.manifest => vasum-container-support.manifest} | 0 ...daemon.manifest => vasum-server-tests.manifest} | 0 ...y-containers-client.manifest => vasum.manifest} | 0 packaging/{security-containers.spec => vasum.spec} | 114 ++++++++++----------- server/common-dbus-definitions.hpp | 4 +- server/configs/CMakeLists.txt | 16 +-- server/configs/daemon.conf | 4 +- .../system.d/org.tizen.containers.host.conf.in | 2 +- ...rity-containers.service.in => vasum.service.in} | 4 +- server/container-admin.cpp | 46 ++++----- server/container-admin.hpp | 6 +- server/container-config.hpp | 5 +- server/container-connection-transport.cpp | 4 +- server/container-connection-transport.hpp | 4 +- server/container-connection.cpp | 4 +- server/container-connection.hpp | 4 +- server/container-dbus-definitions.hpp | 4 +- server/container.cpp | 6 +- server/container.hpp | 5 +- server/containers-manager-config.hpp | 6 +- server/containers-manager.cpp | 16 +-- server/containers-manager.hpp | 4 +- server/exception.hpp | 8 +- server/host-connection.cpp | 4 +- server/host-connection.hpp | 4 +- server/host-dbus-definitions.hpp | 4 +- server/input-monitor-config.hpp | 4 +- server/input-monitor.cpp | 6 +- server/input-monitor.hpp | 4 +- server/main.cpp | 8 +- server/proxy-call-config.hpp | 4 +- server/proxy-call-policy.cpp | 4 +- server/proxy-call-policy.hpp | 4 +- server/server.cpp | 14 +-- server/server.hpp | 4 +- tests/integration_tests/CMakeLists.txt | 4 +- tests/integration_tests/common/__init__.py | 2 +- .../common/{sc_test_utils.py => vsm_test_utils.py} | 0 .../image_tests/config_checker.py | 12 +-- tests/integration_tests/image_tests/image_tests.py | 28 ++--- .../network_tests/network_common.py | 4 +- .../network_tests/network_tests.py | 2 +- .../{sc_int_tests.py => vsm_int_tests.py} | 8 +- tests/scripts/sc_all_tests.py | 10 -- tests/scripts/vsm_all_tests.py | 10 ++ .../{sc_launch_test.py => vsm_launch_test.py} | 4 +- .../{sc_test_parser.py => vsm_test_parser.py} | 4 +- tests/unit_tests/CMakeLists.txt | 8 +- tests/unit_tests/client/configs/CMakeLists.txt | 6 +- .../ut-client/containers/console1-dbus.conf.in | 2 +- .../ut-client/containers/console2-dbus.conf.in | 2 +- .../ut-client/containers/console3-dbus.conf.in | 2 +- .../configs/ut-client/test-dbus-daemon.conf.in | 2 +- tests/unit_tests/client/ut-client.cpp | 8 +- tests/unit_tests/dbus/configs/CMakeLists.txt | 4 +- tests/unit_tests/dbus/test-client.cpp | 4 +- tests/unit_tests/dbus/test-client.hpp | 4 +- tests/unit_tests/dbus/test-common.hpp | 4 +- tests/unit_tests/dbus/test-server.cpp | 4 +- tests/unit_tests/dbus/test-server.hpp | 4 +- tests/unit_tests/dbus/ut-connection.cpp | 6 +- tests/unit_tests/ipc/ut-ipc.cpp | 4 +- tests/unit_tests/lxc/templates/CMakeLists.txt | 2 +- tests/unit_tests/lxc/ut-zone.cpp | 6 +- tests/unit_tests/server/configs/CMakeLists.txt | 28 ++--- .../ut-container/containers/test-dbus.conf.in | 2 +- .../ut-containers-manager/buggy-daemon.conf.in | 4 +- .../buggy-default-daemon.conf.in | 4 +- .../buggy-foreground-daemon.conf.in | 4 +- .../containers/console1-dbus.conf.in | 2 +- .../containers/console2-dbus.conf.in | 2 +- .../containers/console3-dbus.conf.in | 2 +- .../empty-dbus-daemon.conf.in | 4 +- .../templates/template.conf.in | 2 +- .../ut-containers-manager/test-daemon.conf.in | 4 +- .../ut-containers-manager/test-dbus-daemon.conf.in | 4 +- .../server/configs/ut-server/buggy-daemon.conf.in | 2 +- .../server/configs/ut-server/test-daemon.conf.in | 2 +- tests/unit_tests/server/test-dbus-definitions.hpp | 4 +- tests/unit_tests/server/ut-container-admin.cpp | 12 +-- .../unit_tests/server/ut-container-connection.cpp | 6 +- tests/unit_tests/server/ut-container.cpp | 10 +- tests/unit_tests/server/ut-containers-manager.cpp | 20 ++-- tests/unit_tests/server/ut-input-monitor.cpp | 4 +- tests/unit_tests/server/ut-server.cpp | 8 +- tests/unit_tests/ut.cpp | 2 +- tests/unit_tests/utils/configs/CMakeLists.txt | 4 +- tests/unit_tests/utils/scoped-daemon.cpp | 4 +- tests/unit_tests/utils/scoped-daemon.hpp | 4 +- tests/unit_tests/utils/scoped-dir.cpp | 4 +- tests/unit_tests/utils/scoped-dir.hpp | 4 +- tests/unit_tests/utils/ut-callback-guard.cpp | 2 +- tests/unit_tests/utils/ut-fs.cpp | 6 +- tests/unit_tests/utils/ut-glib-loop.cpp | 4 +- tests/unit_tests/utils/ut-paths.cpp | 2 +- 174 files changed, 550 insertions(+), 554 deletions(-) rename client/{security-containers-client-impl.cpp => vasum-client-impl.cpp} (98%) rename client/{security-containers-client-impl.hpp => vasum-client-impl.hpp} (96%) rename client/{security-containers-client.cpp => vasum-client.cpp} (98%) rename client/{security-containers-client.h => vasum-client.h} (86%) rename client/{security-containers.pc.in => vasum.pc.in} (51%) rename packaging/{security-containers.manifest => libvasum-client.manifest} (100%) rename packaging/{security-containers-server-tests.manifest => vasum-container-daemon.manifest} (100%) rename packaging/{security-containers-container-support.manifest => vasum-container-support.manifest} (100%) rename packaging/{security-containers-container-daemon.manifest => vasum-server-tests.manifest} (100%) rename packaging/{libsecurity-containers-client.manifest => vasum.manifest} (100%) rename packaging/{security-containers.spec => vasum.spec} (58%) rename server/configs/systemd/{security-containers.service.in => vasum.service.in} (58%) rename tests/integration_tests/common/{sc_test_utils.py => vsm_test_utils.py} (100%) rename tests/integration_tests/{sc_int_tests.py => vsm_int_tests.py} (69%) delete mode 100755 tests/scripts/sc_all_tests.py create mode 100755 tests/scripts/vsm_all_tests.py rename tests/scripts/{sc_launch_test.py => vsm_launch_test.py} (97%) rename tests/scripts/{sc_test_parser.py => vsm_test_parser.py} (96%) diff --git a/.gitignore b/.gitignore index b12879f..8d682ed 100644 --- a/.gitignore +++ b/.gitignore @@ -18,5 +18,5 @@ CMakeFiles Makefile # Others -security-containers.pc +vasum.pc doc/html diff --git a/CMakeLists.txt b/CMakeLists.txt index b998b20..b302d18 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,7 +18,7 @@ # CMAKE_MINIMUM_REQUIRED (VERSION 2.6.2) -PROJECT(security-containers) +PROJECT(vasum) ## pkgconfig ################################################################### @@ -60,9 +60,9 @@ ADD_DEFINITIONS("-pedantic-errors") # Make pedantic warnings into errors ADD_DEFINITIONS(-DPROGRAM_VERSION="${VERSION}") ADD_DEFINITIONS(-DPROJECT_SOURCE_DIR="${PROJECT_SOURCE_DIR}") -IF(NOT DEFINED SECURITY_CONTAINERS_USER) - SET(SECURITY_CONTAINERS_USER "security-containers") -ENDIF(NOT DEFINED SECURITY_CONTAINERS_USER) +IF(NOT DEFINED VASUM_USER) + SET(VASUM_USER "security-containers") +ENDIF(NOT DEFINED VASUM_USER) IF(NOT DEFINED INPUT_EVENT_GROUP) SET(INPUT_EVENT_GROUP "input") ENDIF(NOT DEFINED INPUT_EVENT_GROUP) @@ -73,7 +73,7 @@ IF(NOT DEFINED TTY_GROUP) SET(TTY_GROUP "tty") ENDIF(NOT DEFINED TTY_GROUP) -ADD_DEFINITIONS(-DSECURITY_CONTAINERS_USER="${SECURITY_CONTAINERS_USER}") +ADD_DEFINITIONS(-DVASUM_USER="${VASUM_USER}") ADD_DEFINITIONS(-DINPUT_EVENT_GROUP="${INPUT_EVENT_GROUP}") ADD_DEFINITIONS(-DDISK_GROUP="${DISK_GROUP}") ADD_DEFINITIONS(-DTTY_GROUP="${TTY_GROUP}") @@ -121,8 +121,8 @@ IF(NOT DEFINED SYSTEMD_UNIT_DIR) SET(SYSTEMD_UNIT_DIR "${LIB_INSTALL_DIR}/systemd/system") ENDIF(NOT DEFINED SYSTEMD_UNIT_DIR) -SET(SC_CONFIG_INSTALL_DIR ${SYSCONF_INSTALL_DIR}/security-containers) -SET(SC_DATA_INSTALL_DIR ${SHARE_INSTALL_PREFIX}/security-containers) +SET(VSM_CONFIG_INSTALL_DIR ${SYSCONF_INSTALL_DIR}/vasum) +SET(VSM_DATA_INSTALL_DIR ${SHARE_INSTALL_PREFIX}/vasum) ADD_SUBDIRECTORY(${CLIENT_FOLDER}) ADD_SUBDIRECTORY(${SERVER_FOLDER}) diff --git a/cli/CMakeLists.txt b/cli/CMakeLists.txt index ff1075b..f28e65b 100644 --- a/cli/CMakeLists.txt +++ b/cli/CMakeLists.txt @@ -27,7 +27,7 @@ ADD_EXECUTABLE(${CLI_CODENAME} ${cli_SRCS}) ## Link libraries ############################################################## -PKG_CHECK_MODULES(LIB_DEPS REQUIRED security-containers) +PKG_CHECK_MODULES(LIB_DEPS REQUIRED vasum) INCLUDE_DIRECTORIES(${CLIENT_FOLDER}) INCLUDE_DIRECTORIES(${COMMON_FOLDER}) diff --git a/cli/command-line-interface.cpp b/cli/command-line-interface.cpp index cf9c71a..ca75d25 100644 --- a/cli/command-line-interface.cpp +++ b/cli/command-line-interface.cpp @@ -24,7 +24,7 @@ #include "config.hpp" #include "command-line-interface.hpp" -#include +#include #include #include @@ -34,7 +34,7 @@ using namespace std; -namespace security_containers { +namespace vasum { namespace cli { namespace { @@ -201,4 +201,4 @@ void lookup_zone_by_id(int pos, int argc, const char** argv) } } // namespace cli -} // namespace security_containers +} // namespace vasum diff --git a/cli/command-line-interface.hpp b/cli/command-line-interface.hpp index 3239a00..6ff4fb0 100644 --- a/cli/command-line-interface.hpp +++ b/cli/command-line-interface.hpp @@ -29,7 +29,7 @@ #include #include -namespace security_containers { +namespace vasum { namespace cli { /** @@ -140,6 +140,6 @@ void lookup_zone_by_id(int pos, int argc, const char** argv); } // namespace cli -} // namespace security_containers +} // namespace vasum #endif /* CLI_COMMAND_LINE_INTERFACE_HPP */ diff --git a/cli/main.cpp b/cli/main.cpp index c7ad2e6..c2e8ad8 100644 --- a/cli/main.cpp +++ b/cli/main.cpp @@ -30,7 +30,7 @@ #include #include -using namespace security_containers::cli; +using namespace vasum::cli; std::map commands = { { diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 3d8eb5d..7060b7b 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -60,5 +60,5 @@ INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT RuntimeLibraries) -INSTALL(FILES security-containers-client.h +INSTALL(FILES vasum-client.h DESTINATION ${INCLUDE_INSTALL_DIR}/${PROJECT_NAME}) diff --git a/client/utils.hpp b/client/utils.hpp index 49b83c0..b86cc20 100644 --- a/client/utils.hpp +++ b/client/utils.hpp @@ -22,11 +22,11 @@ * @brief Utility functions declaration */ -#ifndef SECURITY_CONTAINERS_CLIENT_UTILS_HPP -#define SECURITY_CONTAINERS_CLIENT_UTILS_HPP +#ifndef VASUM_CLIENT_UTILS_HPP +#define VASUM_CLIENT_UTILS_HPP #include bool parseContainerIdFromCpuSet(const std::string& cpuset, std::string& id); -#endif // SECURITY_CONTAINERS_CLIENT_UTILS_HPP +#endif // VASUM_CLIENT_UTILS_HPP diff --git a/client/security-containers-client-impl.cpp b/client/vasum-client-impl.cpp similarity index 98% rename from client/security-containers-client-impl.cpp rename to client/vasum-client-impl.cpp index f96cbcc..e228409 100644 --- a/client/security-containers-client-impl.cpp +++ b/client/vasum-client-impl.cpp @@ -20,11 +20,11 @@ /** * @file * @author Mateusz Malicki (m.malicki2@samsung.com) - * @brief This file contains security-containers-server's client implementation + * @brief This file contains vasum-server's client implementation */ #include -#include "security-containers-client-impl.hpp" +#include "vasum-client-impl.hpp" #include "utils.hpp" #include #include @@ -38,8 +38,8 @@ using namespace std; using namespace dbus; -using namespace security_containers; -using namespace security_containers::utils; +using namespace vasum; +using namespace vasum::utils; namespace { diff --git a/client/security-containers-client-impl.hpp b/client/vasum-client-impl.hpp similarity index 96% rename from client/security-containers-client-impl.hpp rename to client/vasum-client-impl.hpp index d4c3506..f507c0a 100644 --- a/client/security-containers-client-impl.hpp +++ b/client/vasum-client-impl.hpp @@ -20,13 +20,13 @@ /** * @file * @author Mateusz Malicki (m.malicki2@samsung.com) - * @brief This file contains security-containers-server's client definition + * @brief This file contains vasum-server's client definition */ -#ifndef SECURITY_CONTAINERS_CLIENT_IMPL_HPP -#define SECURITY_CONTAINERS_CLIENT_IMPL_HPP +#ifndef VASUM_CLIENT_IMPL_HPP +#define VASUM_CLIENT_IMPL_HPP -#include "security-containers-client.h" +#include "vasum-client.h" #include #include @@ -46,7 +46,7 @@ struct DbusInterfaceInfo { }; /** - * security-containers's client definition. + * vasum's client definition. * * Client uses dbus API. */ @@ -305,4 +305,4 @@ public: static VsmStatus vsm_stop_glib_loop() noexcept; }; -#endif /* SECURITY_CONTAINERS_CLIENT_IMPL_HPP */ +#endif /* VASUM_CLIENT_IMPL_HPP */ diff --git a/client/security-containers-client.cpp b/client/vasum-client.cpp similarity index 98% rename from client/security-containers-client.cpp rename to client/vasum-client.cpp index 054113e..c366a8e 100644 --- a/client/security-containers-client.cpp +++ b/client/vasum-client.cpp @@ -20,12 +20,12 @@ /** * @file * @author Mateusz Malicki (m.malicki2@samsung.com) - * @brief This file contains the public API for Security Containers Client + * @brief This file contains the public API for Vasum Client */ #include -#include "security-containers-client.h" -#include "security-containers-client-impl.hpp" +#include "vasum-client.h" +#include "vasum-client-impl.hpp" #include diff --git a/client/security-containers-client.h b/client/vasum-client.h similarity index 86% rename from client/security-containers-client.h rename to client/vasum-client.h index bafa35c..b8137eb 100644 --- a/client/security-containers-client.h +++ b/client/vasum-client.h @@ -20,12 +20,12 @@ /** * @file * @author Mateusz Malicki (m.malicki2@samsung.com) - * @brief This file contains the public API for Security Containers Client + * @brief This file contains the public API for Vasum Client * * @par Example usage: * @code #include -#include "client/security-containers-client.h" +#include "client/vasum-client.h" int main(int argc, char** argv) { @@ -75,8 +75,8 @@ finish: @endcode */ -#ifndef SECURITY_CONTAINERS_CLIENT_H -#define SECURITY_CONTAINERS_CLIENT_H +#ifndef VASUM_CLIENT_H +#define VASUM_CLIENT_H #include #include @@ -87,7 +87,7 @@ extern "C" #endif /** - * security-containers-server's client pointer. + * vasum-server's client pointer. */ typedef void* VsmClient; @@ -205,7 +205,7 @@ VsmStatus vsm_start_glib_loop(); VsmStatus vsm_stop_glib_loop(); /** - * Create a new security-containers-server's client. + * Create a new vasum-server's client. * * @return Created client pointer or NULL on failure. */ @@ -214,38 +214,38 @@ VsmClient vsm_client_create(); /** * Release client resources. * - * @param[in] client security-containers-server's client + * @param[in] client vasum-server's client */ void vsm_client_free(VsmClient client); /** - * Get status code of last security-containers-server communication. + * Get status code of last vasum-server communication. * - * @param[in] client security-containers-server's client + * @param[in] client vasum-server's client * @return status of this function call */ VsmStatus vsm_get_status(VsmClient client); /** - * Get status message of the last security-containers-server communication. + * Get status message of the last vasum-server communication. * - * @param[in] client security-containers-server's client - * @return last status message from security-containers-server communication + * @param[in] client vasum-server's client + * @return last status message from vasum-server communication */ const char* vsm_get_status_message(VsmClient client); /** - * Connect client to the security-containers-server. + * Connect client to the vasum-server. * - * @param[in] client security-containers-server's client + * @param[in] client vasum-server's client * @return status of this function call */ VsmStatus vsm_connect(VsmClient client); /** - * Connect client to the security-containers-server via custom address. + * Connect client to the vasum-server via custom address. * - * @param[in] client security-containers-server's client + * @param[in] client vasum-server's client * @param[in] address dbus address * @return status of this function call */ @@ -301,7 +301,7 @@ typedef void (*VsmContainerDbusStateCallback)(const char* containerId, /** * Get dbus address of each container. * - * @param[in] client security-containers-server's client + * @param[in] client vasum-server's client * @param[out] keys array of containers name * @param[out] values array of containers dbus address * @return status of this function call @@ -313,7 +313,7 @@ VsmStatus vsm_get_container_dbuses(VsmClient client, VsmArrayString* keys, VsmAr /** * Get containers name. * - * @param[in] client security-containers-server's client + * @param[in] client vasum-server's client * @param[out] array array of containers name * @return status of this function call * @remark Use vsm_array_string_free() to free memory occupied by @p array. @@ -323,7 +323,7 @@ VsmStatus vsm_get_zone_ids(VsmClient client, VsmArrayString* array); /** * Get active (foreground) container name. * - * @param[in] client security-containers-server's client + * @param[in] client vasum-server's client * @param[out] id active container name * @return status of this function call * @remark Use @p vsm_string_free() to free memory occupied by @p id. @@ -333,7 +333,7 @@ VsmStatus vsm_get_active_container_id(VsmClient client, VsmString* id); /** * Get container name of process with given pid. * - * @param[in] client security-containers-server's client + * @param[in] client vasum-server's client * @param[in] pid process id * @param[out] id active container name * @return status of this function call @@ -344,7 +344,7 @@ VsmStatus vsm_lookup_zone_by_pid(VsmClient client, int pid, VsmString* id); /** * Get zone informations of zone with given id. * - * @param[in] client security-containers-server's client + * @param[in] client vasum-server's client * @param[in] id zone name * @param[out] zone zone informations * @return status of this function call @@ -355,7 +355,7 @@ VsmStatus vsm_lookup_zone_by_id(VsmClient client, const char* id, VsmZone* zone) /** * Get zone name with given terminal. * - * @param[in] client security-containers-server's client + * @param[in] client vasum-server's client * @param[in] terminal terminal id * @param[out] id zone name with given terminal * @return status of this function call @@ -366,7 +366,7 @@ VsmStatus vsm_lookup_zone_by_terminal_id(VsmClient client, int terminal, VsmStri /** * Set active (foreground) container. * - * @param[in] client security-containers-server's client + * @param[in] client vasum-server's client * @param[in] id container name * @return status of this function call */ @@ -375,7 +375,7 @@ VsmStatus vsm_set_active_container(VsmClient client, const char* id); /** * Create and add container * - * @param[in] client security-containers-server's client + * @param[in] client vasum-server's client * @param[in] id container id * @param[in] tname template name, NULL for default * @return status of this function call @@ -385,7 +385,7 @@ VsmStatus vsm_create_zone(VsmClient client, const char* id, const char* tname); /** * Remove zone * - * @param[in] client security-containers-server's client + * @param[in] client vasum-server's client * @param[in] id container id * @param[in] force if 0 data will be kept, otherwise data will be lost * @return status of this function call @@ -395,7 +395,7 @@ VsmStatus vsm_destroy_zone(VsmClient clent, const char* id, int force); /** * Shutdown zone * - * @param[in] client security-containers-server's client + * @param[in] client vasum-server's client * @param[in] id zone name * @return status of this function call */ @@ -404,7 +404,7 @@ VsmStatus vsm_shutdown_zone(VsmClient client, const char* id); /** * Start zone * - * @param[in] client security-containers-server's client + * @param[in] client vasum-server's client * @param[in] id zone name * @return status of this function call */ @@ -413,7 +413,7 @@ VsmStatus vsm_start_zone(VsmClient client, const char* id); /** * Lock zone * - * @param[in] client security-containers-server's client + * @param[in] client vasum-server's client * @param[in] id zone name * @return status of this function call */ @@ -422,7 +422,7 @@ VsmStatus vsm_lock_zone(VsmClient client, const char* id); /** * Unlock zone * - * @param[in] client security-containers-server's client + * @param[in] client vasum-server's client * @param[in] id zone name * @return status of this function call */ @@ -433,7 +433,7 @@ VsmStatus vsm_unlock_zone(VsmClient client, const char* id); * * @note The callback function will be invoked on a different thread. * - * @param[in] client security-containers-server's client + * @param[in] client vasum-server's client * @param[in] containerDbusStateCallback callback function * @param[in] data some extra data that will be passed to callback function * @param[out] subscriptionId subscription identifier that can be used to unsubscribe signal, @@ -448,7 +448,7 @@ VsmStatus vsm_add_state_callback(VsmClient client, /** * Unregister dbus state change callback function. * - * @param[in] client security-containers-server's client + * @param[in] client vasum-server's client * @param[in] subscriptionId subscription identifier returned by vsm_add_state_callback * @return status of this function call */ @@ -457,7 +457,7 @@ VsmStatus vsm_del_state_callback(VsmClient client, VsmSubscriptionId subscriptio /** * Grant access to device * - * @param[in] client security-containers-server's client + * @param[in] client vasum-server's client * @param[in] zone zone name * @param[in] device device path * @param[in] flags access flags @@ -471,7 +471,7 @@ VsmStatus vsm_zone_grant_device(VsmClient client, /** * Revoke access to device * - * @param[in] client security-containers-server's client + * @param[in] client vasum-server's client * @param[in] zone zone name * @param[in] device device path * @return status of this function call @@ -481,7 +481,7 @@ VsmStatus vsm_revoke_device(VsmClient client, const char* zone, const char* devi /** * Get array of netdev from given zone * - * @param[in] client security-containers-server's client + * @param[in] client vasum-server's client * @param[in] zone zone name * @param[out] netdevIds array of netdev id * @return status of this function call @@ -492,7 +492,7 @@ VsmStatus vsm_zone_get_netdevs(VsmClient client, const char* zone, VsmArrayStrin /** * Get ipv4 address for given netdevId * - * @param[in] client security-containers-server's client + * @param[in] client vasum-server's client * @param[in] zone zone name * @param[in] netdevId netdev id * @param[out] addr ipv4 address @@ -506,7 +506,7 @@ VsmStatus vsm_netdev_get_ipv4_addr(VsmClient client, /** * Get ipv6 address for given netdevId * - * @param[in] client security-containers-server's client + * @param[in] client vasum-server's client * @param[in] zone zone name * @param[in] netdevId netdev id * @param[out] addr ipv6 address @@ -520,7 +520,7 @@ VsmStatus vsm_netdev_get_ipv6_addr(VsmClient client, /** * Set ipv4 address for given netdevId * - * @param[in] client security-containers-server's client + * @param[in] client vasum-server's client * @param[in] zone zone name * @param[in] netdevId netdev id * @param[in] addr ipv4 address @@ -536,7 +536,7 @@ VsmStatus vsm_netdev_set_ipv4_addr(VsmClient client, /** * Set ipv6 address for given netdevId * - * @param[in] client security-containers-server's client + * @param[in] client vasum-server's client * @param[in] zone zone name * @param[in] netdevId netdev id * @param[in] addr ipv6 address @@ -552,7 +552,7 @@ VsmStatus vsm_netdev_set_ipv6_addr(VsmClient client, /** * Create netdev in zone * - * @param[in] client security-containers-server's client + * @param[in] client vasum-server's client * @param[in] zone zone name * @param[in] netdevType netdev type * @param[in] target TODO: this is taken form zone-control @@ -568,7 +568,7 @@ VsmStatus vsm_create_netdev(VsmClient client, /** * Remove netdev from zone * - * @param[in] client security-containers-server's client + * @param[in] client vasum-server's client * @param[in] zone zone name * @param[in] netdevId network device id * @return status of this function call @@ -578,7 +578,7 @@ VsmStatus vsm_destroy_netdev(VsmClient client, const char* zone, const char* net /** * Get netdev informations * - * @param[in] client security-containers-server's client + * @param[in] client vasum-server's client * @param[in] zone zone name * @param[in] netdevId network device id * @param[out] netdev netdev informations @@ -595,7 +595,7 @@ VsmStatus vsm_lookup_netdev_by_name(VsmClient client, * * Declare file, directory or pipe that will be created while container startup * - * @param[in] client security-containers-server's client + * @param[in] client vasum-server's client * @param[in] type file type * @param[in] container container id * @param[in] path path to file @@ -618,7 +618,7 @@ VsmStatus vsm_declare_file(VsmClient client, * Declare mount that will be created while container startup * Parameters are passed to mount system function * - * @param[in] client security-containers-server's client + * @param[in] client vasum-server's client * @param[in] source device path (path in host) * @param[in] container container id * @param[in] target mount point (path in container) @@ -641,7 +641,7 @@ VsmStatus vsm_declare_mount(VsmClient client, * Declare link that will be created while container startup * Parameters are passed to link system function * - * @param[in] client security-containers-server's client + * @param[in] client vasum-server's client * @param[in] source path to link source (in host) * @param[in] container container id * @param[in] target path to link name (in container) @@ -679,7 +679,7 @@ typedef void (*VsmNotificationCallback)(const char* container, /** * Send message to active container. * - * @param[in] client security-containers-server's client + * @param[in] client vasum-server's client * @param[in] application application name * @param[in] message message * @return status of this function call @@ -689,7 +689,7 @@ VsmStatus vsm_notify_active_container(VsmClient client, const char* application, /** * Move file between containers. * - * @param[in] client security-containers-server's client + * @param[in] client vasum-server's client * @param[in] destContainer destination container id * @param[in] path path to moved file * @return status of this function call @@ -701,7 +701,7 @@ VsmStatus vsm_file_move_request(VsmClient client, const char* destContainer, con * * @note The callback function will be invoked on a different thread. * - * @param[in] client security-containers-server's client + * @param[in] client vasum-server's client * @param[in] notificationCallback callback function * @param[in] data some extra data that will be passed to callback function * @param[out] subscriptionId subscription identifier that can be used to unsubscribe signal, @@ -716,7 +716,7 @@ VsmStatus vsm_add_notification_callback(VsmClient client, /** * Unregister notification callback function. * - * @param[in] client security-containers-server's client + * @param[in] client vasum-server's client * @param[in] subscriptionId subscription identifier returned by vsm_add_notification_callback * @return status of this function call */ @@ -728,4 +728,4 @@ VsmStatus vsm_del_notification_callback(VsmClient client, VsmSubscriptionId subs } #endif -#endif /* SECRITY_CONTAINERS_CLIENT_H */ +#endif /* VASUM_CLIENT_H */ diff --git a/client/security-containers.pc.in b/client/vasum.pc.in similarity index 51% rename from client/security-containers.pc.in rename to client/vasum.pc.in index 186218e..f12abc2 100644 --- a/client/security-containers.pc.in +++ b/client/vasum.pc.in @@ -5,8 +5,8 @@ exec_prefix=${prefix} libdir=@LIB_INSTALL_DIR@ includedir=${prefix}/include -Name: security-containers -Description: Security Containers library +Name: vasum +Description: Vasum library Version: @_LIB_VERSION_@ -Libs: -L${libdir} -lsecurity-containers-client -Cflags: -I${includedir}/security-containers +Libs: -L${libdir} -lvasum-client +Cflags: -I${includedir}/vasum diff --git a/common/base-exception.hpp b/common/base-exception.hpp index 15fd3e0..d501e3d 100644 --- a/common/base-exception.hpp +++ b/common/base-exception.hpp @@ -19,7 +19,7 @@ /** * @file * @author Piotr Bartosiewicz (p.bartosiewi@partner.samsung.com) - * @brief Security containers base exception + * @brief Vasum base exception */ @@ -30,19 +30,19 @@ #include -namespace security_containers { +namespace vasum { /** - * Base class security containers exceptions + * Base class vasum exceptions */ -struct SecurityContainersException: public std::runtime_error { +struct VasumException: public std::runtime_error { - SecurityContainersException(const std::string& error = "") : std::runtime_error(error) {} + VasumException(const std::string& error = "") : std::runtime_error(error) {} }; -} // namespace security_containers +} // namespace vasum #endif // COMMON_BASE_EXCEPTION_HPP diff --git a/common/ipc/client.cpp b/common/ipc/client.cpp index 8b0e458..835020d 100644 --- a/common/ipc/client.cpp +++ b/common/ipc/client.cpp @@ -28,7 +28,7 @@ #include "ipc/internals/socket.hpp" #include "ipc/exception.hpp" -namespace security_containers { +namespace vasum { namespace ipc { Client::Client(const std::string& socketPath) @@ -92,4 +92,4 @@ void Client::removeMethod(const MethodID methodID) } } // namespace ipc -} // namespace security_containers +} // namespace vasum diff --git a/common/ipc/client.hpp b/common/ipc/client.hpp index 6f8b049..5233e29 100644 --- a/common/ipc/client.hpp +++ b/common/ipc/client.hpp @@ -31,7 +31,7 @@ #include -namespace security_containers { +namespace vasum { namespace ipc { /** @@ -212,6 +212,6 @@ void Client::signal(const MethodID methodID, } } // namespace ipc -} // namespace security_containers +} // namespace vasum #endif // COMMON_IPC_CLIENT_HPP diff --git a/common/ipc/exception.hpp b/common/ipc/exception.hpp index f9e8322..794cf21 100644 --- a/common/ipc/exception.hpp +++ b/common/ipc/exception.hpp @@ -28,14 +28,14 @@ #include "base-exception.hpp" -namespace security_containers { +namespace vasum { /** * Base class for exceptions in IPC */ -struct IPCException: public SecurityContainersException { - IPCException(const std::string& error) : SecurityContainersException(error) {} +struct IPCException: public VasumException { + IPCException(const std::string& error) : VasumException(error) {} }; struct IPCParsingException: public IPCException { diff --git a/common/ipc/internals/acceptor.cpp b/common/ipc/internals/acceptor.cpp index 193da61..3a6c4cd 100644 --- a/common/ipc/internals/acceptor.cpp +++ b/common/ipc/internals/acceptor.cpp @@ -35,7 +35,7 @@ #include #include -namespace security_containers { +namespace vasum { namespace ipc { Acceptor::Acceptor(const std::string& socketPath, const NewConnectionCallback& newConnectionCallback) @@ -127,4 +127,4 @@ void Acceptor::run() } } // namespace ipc -} // namespace security_containers +} // namespace vasum diff --git a/common/ipc/internals/acceptor.hpp b/common/ipc/internals/acceptor.hpp index b863400..702a161 100644 --- a/common/ipc/internals/acceptor.hpp +++ b/common/ipc/internals/acceptor.hpp @@ -33,7 +33,7 @@ #include #include -namespace security_containers { +namespace vasum { namespace ipc { /** @@ -82,6 +82,6 @@ private: }; } // namespace ipc -} // namespace security_containers +} // namespace vasum #endif // COMMON_IPC_INTERNALS_ACCEPTOR_HPP diff --git a/common/ipc/internals/call-queue.cpp b/common/ipc/internals/call-queue.cpp index 9be7e53..df70f11 100644 --- a/common/ipc/internals/call-queue.cpp +++ b/common/ipc/internals/call-queue.cpp @@ -28,7 +28,7 @@ #include "ipc/exception.hpp" #include "logger/logger.hpp" -namespace security_containers { +namespace vasum { namespace ipc { CallQueue::CallQueue() @@ -63,4 +63,4 @@ CallQueue::Call CallQueue::pop() } } // namespace ipc -} // namespace security_containers +} // namespace vasum diff --git a/common/ipc/internals/call-queue.hpp b/common/ipc/internals/call-queue.hpp index 7911d7a..03adfc8 100644 --- a/common/ipc/internals/call-queue.hpp +++ b/common/ipc/internals/call-queue.hpp @@ -31,7 +31,7 @@ #include #include -namespace security_containers { +namespace vasum { namespace ipc { /** @@ -145,6 +145,6 @@ MessageID CallQueue::push(const MethodID methodID, } } // namespace ipc -} // namespace security_containers +} // namespace vasum #endif // COMMON_IPC_INTERNALS_CALL_QUEUE_HPP diff --git a/common/ipc/internals/event-queue.hpp b/common/ipc/internals/event-queue.hpp index b50f0c4..74a4923 100644 --- a/common/ipc/internals/event-queue.hpp +++ b/common/ipc/internals/event-queue.hpp @@ -33,7 +33,7 @@ #include #include -namespace security_containers { +namespace vasum { namespace ipc { @@ -119,6 +119,6 @@ bool EventQueue::isEmpty() } } // namespace ipc -} // namespace security_containers +} // namespace vasum #endif // COMMON_IPC_INTERNALS_EVENT_QUEUE_HPP diff --git a/common/ipc/internals/eventfd.cpp b/common/ipc/internals/eventfd.cpp index 37cf7dd..729243d 100644 --- a/common/ipc/internals/eventfd.cpp +++ b/common/ipc/internals/eventfd.cpp @@ -34,7 +34,7 @@ #include #include -namespace security_containers { +namespace vasum { namespace ipc { EventFD::EventFD() @@ -74,4 +74,4 @@ void EventFD::receive() } // namespace ipc -} // namespace security_containers +} // namespace vasum diff --git a/common/ipc/internals/eventfd.hpp b/common/ipc/internals/eventfd.hpp index 9de6f17..cf3094c 100644 --- a/common/ipc/internals/eventfd.hpp +++ b/common/ipc/internals/eventfd.hpp @@ -25,7 +25,7 @@ #ifndef COMMON_IPC_INTERNALS_EVENTFD_HPP #define COMMON_IPC_INTERNALS_EVENTFD_HPP -namespace security_containers { +namespace vasum { namespace ipc { class EventFD { @@ -57,6 +57,6 @@ private: }; } // namespace ipc -} // namespace security_containers +} // namespace vasum #endif // COMMON_IPC_INTERNALS_EVENTFD_HPP diff --git a/common/ipc/internals/processor.cpp b/common/ipc/internals/processor.cpp index 7ac378e..aa21675 100644 --- a/common/ipc/internals/processor.cpp +++ b/common/ipc/internals/processor.cpp @@ -35,7 +35,7 @@ #include #include -namespace security_containers { +namespace vasum { namespace ipc { #define IGNORE_EXCEPTIONS(expr) \ @@ -667,4 +667,4 @@ void Processor::cleanCommunication() } } // namespace ipc -} // namespace security_containers +} // namespace vasum diff --git a/common/ipc/internals/processor.hpp b/common/ipc/internals/processor.hpp index 476e662..6ce2688 100644 --- a/common/ipc/internals/processor.hpp +++ b/common/ipc/internals/processor.hpp @@ -46,7 +46,7 @@ #include #include -namespace security_containers { +namespace vasum { namespace ipc { const unsigned int DEFAULT_MAX_NUMBER_OF_PEERS = 500; @@ -620,6 +620,6 @@ void Processor::signal(const MethodID methodID, } // namespace ipc -} // namespace security_containers +} // namespace vasum #endif // COMMON_IPC_INTERNALS_PROCESSOR_HPP diff --git a/common/ipc/internals/socket.cpp b/common/ipc/internals/socket.cpp index 4db22fe..b12dfa0 100644 --- a/common/ipc/internals/socket.cpp +++ b/common/ipc/internals/socket.cpp @@ -39,7 +39,7 @@ #include -namespace security_containers { +namespace vasum { namespace ipc { namespace { @@ -205,4 +205,4 @@ Socket Socket::connectSocket(const std::string& path) } } // namespace ipc -} // namespace security_containers +} // namespace vasum diff --git a/common/ipc/internals/socket.hpp b/common/ipc/internals/socket.hpp index 717ba00..91f0dcd 100644 --- a/common/ipc/internals/socket.hpp +++ b/common/ipc/internals/socket.hpp @@ -29,7 +29,7 @@ #include #include -namespace security_containers { +namespace vasum { namespace ipc { /** @@ -111,6 +111,6 @@ private: }; } // namespace ipc -} // namespace security_containers +} // namespace vasum #endif // COMMON_IPC_INTERNALS_SOCKET_HPP diff --git a/common/ipc/internals/utils.cpp b/common/ipc/internals/utils.cpp index bb11c80..88f8fc0 100644 --- a/common/ipc/internals/utils.cpp +++ b/common/ipc/internals/utils.cpp @@ -39,7 +39,7 @@ namespace fs = boost::filesystem; namespace chr = std::chrono; -namespace security_containers { +namespace vasum { namespace ipc { namespace { @@ -193,5 +193,5 @@ unsigned int getFDNumber() } } // namespace ipc -} // namespace security_containers +} // namespace vasum diff --git a/common/ipc/internals/utils.hpp b/common/ipc/internals/utils.hpp index a9a79a0..c3bcaf1 100644 --- a/common/ipc/internals/utils.hpp +++ b/common/ipc/internals/utils.hpp @@ -27,7 +27,7 @@ #include -namespace security_containers { +namespace vasum { namespace ipc { /** @@ -74,6 +74,6 @@ void setMaxFDNumber(unsigned int limit); unsigned int getFDNumber(); } // namespace ipc -} // namespace security_containers +} // namespace vasum #endif // COMMON_IPC_INTERNALS_UTILS_HPP diff --git a/common/ipc/service.cpp b/common/ipc/service.cpp index e845fe6..5ee5fbd 100644 --- a/common/ipc/service.cpp +++ b/common/ipc/service.cpp @@ -30,7 +30,7 @@ using namespace std::placeholders; -namespace security_containers { +namespace vasum { namespace ipc { Service::Service(const std::string& socketPath, @@ -98,4 +98,4 @@ void Service::removeMethod(const MethodID methodID) } // namespace ipc -} // namespace security_containers +} // namespace vasum diff --git a/common/ipc/service.hpp b/common/ipc/service.hpp index 317311d..5038398 100644 --- a/common/ipc/service.hpp +++ b/common/ipc/service.hpp @@ -32,7 +32,7 @@ #include -namespace security_containers { +namespace vasum { namespace ipc { @@ -220,6 +220,6 @@ void Service::signal(const MethodID methodID, } } // namespace ipc -} // namespace security_containers +} // namespace vasum #endif // COMMON_IPC_SERVICE_HPP diff --git a/common/ipc/types.cpp b/common/ipc/types.cpp index bce862c..18c769d 100644 --- a/common/ipc/types.cpp +++ b/common/ipc/types.cpp @@ -26,7 +26,7 @@ #include "logger/logger.hpp" -namespace security_containers { +namespace vasum { namespace ipc { std::string toString(const Status status) @@ -65,4 +65,4 @@ void throwOnError(const Status status) } } } // namespace ipc -} // namespace security_containers +} // namespace vasum diff --git a/common/ipc/types.hpp b/common/ipc/types.hpp index 5fe9188..5132911 100644 --- a/common/ipc/types.hpp +++ b/common/ipc/types.hpp @@ -31,7 +31,7 @@ #include #include -namespace security_containers { +namespace vasum { namespace ipc { typedef int FileDescriptor; @@ -73,6 +73,6 @@ struct ResultHandler { }; } // namespace ipc -} // namespace security_containers +} // namespace vasum #endif // COMMON_IPC_HANDLERS_HPP diff --git a/common/lxc/exception.hpp b/common/lxc/exception.hpp index 31248b5..85272b5 100644 --- a/common/lxc/exception.hpp +++ b/common/lxc/exception.hpp @@ -29,19 +29,18 @@ #include "base-exception.hpp" -namespace security_containers { +namespace vasum { /** * Base class for exceptions in utils */ -struct LxcException: public SecurityContainersException { +struct LxcException: public VasumException { - LxcException(const std::string& error) : SecurityContainersException(error) {} + LxcException(const std::string& error) : VasumException(error) {} }; -} - +} // namespace vasum #endif // COMMON_UTILS_EXCEPTION_HPP diff --git a/common/lxc/zone.cpp b/common/lxc/zone.cpp index f4ad3e4..ceded4b 100644 --- a/common/lxc/zone.cpp +++ b/common/lxc/zone.cpp @@ -47,7 +47,7 @@ #include -namespace security_containers { +namespace vasum { namespace lxc { namespace { @@ -337,4 +337,4 @@ void LxcZone::refresh() } // namespace lxc -} // namespace security_containers +} // namespace vasum diff --git a/common/lxc/zone.hpp b/common/lxc/zone.hpp index 6ea5e3a..9b29f6f 100644 --- a/common/lxc/zone.hpp +++ b/common/lxc/zone.hpp @@ -30,7 +30,7 @@ // fwd declaration of lxc internals struct lxc_container; -namespace security_containers { +namespace vasum { namespace lxc { @@ -145,7 +145,7 @@ private: } // namespace lxc -} // namespace security_containers +} // namespace vasum #endif // COMMON_LXC_ZONE_HPP diff --git a/common/utils/c-array.hpp b/common/utils/c-array.hpp index 73b037b..68fa816 100644 --- a/common/utils/c-array.hpp +++ b/common/utils/c-array.hpp @@ -27,7 +27,7 @@ #include -namespace security_containers { +namespace vasum { namespace utils { template @@ -67,7 +67,7 @@ private: typedef CArrayBuilder CStringArrayBuilder; } // namespace utils -} // namespace security_containers +} // namespace vasum #endif // COMMON_UTILS_C_ARRAY_HPP diff --git a/common/utils/callback-guard.cpp b/common/utils/callback-guard.cpp index d8ee57c..b0ce7dd 100644 --- a/common/utils/callback-guard.cpp +++ b/common/utils/callback-guard.cpp @@ -31,7 +31,7 @@ #include -namespace security_containers { +namespace vasum { namespace utils { // Reference counting class like shared_ptr but with the ability to wait for it. @@ -127,4 +127,4 @@ bool CallbackGuard::waitForTrackers(const unsigned int timeoutMs) } } // namespace utils -} // namespace security_containers +} // namespace vasum diff --git a/common/utils/callback-guard.hpp b/common/utils/callback-guard.hpp index 3ebc2fb..d28e707 100644 --- a/common/utils/callback-guard.hpp +++ b/common/utils/callback-guard.hpp @@ -29,7 +29,7 @@ #include -namespace security_containers { +namespace vasum { namespace utils { /** @@ -73,7 +73,7 @@ private: }; } // namespace utils -} // namespace security_containers +} // namespace vasum #endif // COMMON_UTILS_CALLBACK_GUARD_HPP diff --git a/common/utils/callback-wrapper.hpp b/common/utils/callback-wrapper.hpp index fd40a07..fd5a4c0 100644 --- a/common/utils/callback-wrapper.hpp +++ b/common/utils/callback-wrapper.hpp @@ -28,7 +28,7 @@ #include "callback-guard.hpp" -namespace security_containers { +namespace vasum { namespace utils { @@ -86,7 +86,7 @@ const Callback& getCallbackFromPointer(const void* pointer) } // namespace utils -} // namespace security_containers +} // namespace vasum #endif // COMMON_UTILS_CALLBACK_WRAPPER_HPP diff --git a/common/utils/environment.cpp b/common/utils/environment.cpp index aec70c1..9d3f75a 100644 --- a/common/utils/environment.cpp +++ b/common/utils/environment.cpp @@ -36,7 +36,7 @@ #include -namespace security_containers { +namespace vasum { namespace utils { @@ -127,4 +127,4 @@ bool launchAsRoot(const std::function& func) } // namespace utils -} // namespace security_containers +} // namespace vasum diff --git a/common/utils/environment.hpp b/common/utils/environment.hpp index 07a767e..2060e19 100644 --- a/common/utils/environment.hpp +++ b/common/utils/environment.hpp @@ -31,7 +31,7 @@ #include -namespace security_containers { +namespace vasum { namespace utils { @@ -54,7 +54,7 @@ bool launchAsRoot(const std::function& func); } // namespace utils -} // namespace security_containers +} // namespace vasum #endif // COMMON_UTILS_ENVIRONMENT_HPP diff --git a/common/utils/exception.hpp b/common/utils/exception.hpp index e093f90..56fd0bd 100644 --- a/common/utils/exception.hpp +++ b/common/utils/exception.hpp @@ -29,19 +29,18 @@ #include "base-exception.hpp" -namespace security_containers { +namespace vasum { /** * Base class for exceptions in utils */ -struct UtilsException: public SecurityContainersException { +struct UtilsException: public VasumException { - UtilsException(const std::string& error = "") : SecurityContainersException(error) {} + UtilsException(const std::string& error = "") : VasumException(error) {} }; -} - +} // namespace vasum #endif // COMMON_UTILS_EXCEPTION_HPP diff --git a/common/utils/execute.cpp b/common/utils/execute.cpp index 6511456..5c9d1ce 100644 --- a/common/utils/execute.cpp +++ b/common/utils/execute.cpp @@ -30,7 +30,7 @@ #include #include -namespace security_containers { +namespace vasum { namespace utils { namespace { @@ -94,4 +94,4 @@ bool waitPid(pid_t pid, int& status) } } // namespace utils -} // namespace security_containers +} // namespace vasum diff --git a/common/utils/execute.hpp b/common/utils/execute.hpp index 3256ee2..47db58a 100644 --- a/common/utils/execute.hpp +++ b/common/utils/execute.hpp @@ -27,7 +27,7 @@ #include -namespace security_containers { +namespace vasum { namespace utils { bool executeAndWait(const char* fname, const char* const* argv); @@ -37,7 +37,7 @@ bool executeAndWait(const char* fname, const char* const* argv, int& status); bool waitPid(pid_t pid, int& status); } // namespace utils -} // namespace security_containers +} // namespace vasum #endif // COMMON_UTILS_EXECUTE_HPP diff --git a/common/utils/file-wait.cpp b/common/utils/file-wait.cpp index 9f210f1..f89ada6 100644 --- a/common/utils/file-wait.cpp +++ b/common/utils/file-wait.cpp @@ -31,7 +31,7 @@ #include -namespace security_containers { +namespace vasum { namespace utils { @@ -56,4 +56,4 @@ void waitForFile(const std::string& filename, const unsigned int timeoutMs) } // namespace utils -} // namespace security_containers +} // namespace vasum diff --git a/common/utils/file-wait.hpp b/common/utils/file-wait.hpp index d31dc71..9029c6e 100644 --- a/common/utils/file-wait.hpp +++ b/common/utils/file-wait.hpp @@ -28,7 +28,7 @@ #include -namespace security_containers { +namespace vasum { namespace utils { @@ -38,7 +38,7 @@ void waitForFile(const std::string& filename, const unsigned int timeoutMs); } // namespace utils -} // namespace security_containers +} // namespace vasum #endif // COMMON_UTILS_FILE_WAIT_HPP diff --git a/common/utils/fs.cpp b/common/utils/fs.cpp index 660db9f..9254f0a 100644 --- a/common/utils/fs.cpp +++ b/common/utils/fs.cpp @@ -42,7 +42,7 @@ #include -namespace security_containers { +namespace vasum { namespace utils { @@ -341,4 +341,4 @@ bool createEmptyDir(const std::string& path) } } // namespace utils -} // namespace security_containers +} // namespace vasum diff --git a/common/utils/fs.hpp b/common/utils/fs.hpp index 0e2f00e..91ea62a 100644 --- a/common/utils/fs.hpp +++ b/common/utils/fs.hpp @@ -31,7 +31,7 @@ #include -namespace security_containers { +namespace vasum { namespace utils { /** @@ -105,7 +105,7 @@ bool createEmptyDir(const std::string& path); } // namespace utils -} // namespace security_containers +} // namespace vasum #endif // COMMON_UTILS_FS_HPP diff --git a/common/utils/glib-loop.cpp b/common/utils/glib-loop.cpp index 3d76928..fb2d952 100644 --- a/common/utils/glib-loop.cpp +++ b/common/utils/glib-loop.cpp @@ -30,7 +30,7 @@ #include #include -namespace security_containers { +namespace vasum { namespace utils { namespace { @@ -87,4 +87,4 @@ gboolean Glib::onTimerEvent(gpointer data) } // namespace utils -} // namespace security_containers +} // namespace vasum diff --git a/common/utils/glib-loop.hpp b/common/utils/glib-loop.hpp index ca1bd88..8db43b6 100644 --- a/common/utils/glib-loop.hpp +++ b/common/utils/glib-loop.hpp @@ -32,7 +32,7 @@ #include -namespace security_containers { +namespace vasum { namespace utils { @@ -81,7 +81,7 @@ private: }; } // namespace utils -} // namespace security_containers +} // namespace vasum #endif // COMMON_UTILS_GLIB_LOOP_HPP diff --git a/common/utils/img.cpp b/common/utils/img.cpp index bc77491..a33b5fd 100644 --- a/common/utils/img.cpp +++ b/common/utils/img.cpp @@ -32,7 +32,7 @@ #include #include -namespace security_containers { +namespace vasum { namespace utils { namespace { @@ -237,4 +237,4 @@ bool copyImageContents(const std::string& img, const std::string& dst) } } // namespace utils -} // namespace security_containers +} // namespace vasum diff --git a/common/utils/img.hpp b/common/utils/img.hpp index db47cc6..8782ae2 100644 --- a/common/utils/img.hpp +++ b/common/utils/img.hpp @@ -25,7 +25,7 @@ #ifndef COMMON_UTILS_IMG_HPP #define COMMON_UTILS_IMG_HPP -namespace security_containers { +namespace vasum { namespace utils { /** @@ -50,6 +50,6 @@ bool umountImage(const std::string& path, const std::string& loopdev); bool copyImageContents(const std::string& img, const std::string& dst); } // namespace utils -} // namespace security_containers +} // namespace vasum #endif // COMMON_UTILS_IMG_HPP diff --git a/common/utils/initctl.cpp b/common/utils/initctl.cpp index cfdea77..f4a778b 100644 --- a/common/utils/initctl.cpp +++ b/common/utils/initctl.cpp @@ -30,7 +30,7 @@ #include #include -namespace security_containers { +namespace vasum { namespace utils { namespace { @@ -87,4 +87,4 @@ bool setRunLevel(RunLevel runLevel) } // namespace utils -} // namespace security_containers +} // namespace vasum diff --git a/common/utils/initctl.hpp b/common/utils/initctl.hpp index 2b97dd2..97f4ca4 100644 --- a/common/utils/initctl.hpp +++ b/common/utils/initctl.hpp @@ -26,7 +26,7 @@ #define COMMON_UTILS_INITCTL_HPP -namespace security_containers { +namespace vasum { namespace utils { enum RunLevel : int { @@ -38,7 +38,7 @@ bool setRunLevel(RunLevel runLevel); } // namespace utils -} // namespace security_containers +} // namespace vasum #endif // COMMON_UTILS_INITCTL_HPP diff --git a/common/utils/latch.cpp b/common/utils/latch.cpp index 2ae240d..e4b3649 100644 --- a/common/utils/latch.cpp +++ b/common/utils/latch.cpp @@ -28,7 +28,7 @@ #include -namespace security_containers { +namespace vasum { namespace utils { @@ -81,4 +81,4 @@ bool Latch::empty() } // namespace utils -} // namespace security_containers +} // namespace vasum diff --git a/common/utils/latch.hpp b/common/utils/latch.hpp index 2621d49..1fa773b 100644 --- a/common/utils/latch.hpp +++ b/common/utils/latch.hpp @@ -29,7 +29,7 @@ #include -namespace security_containers { +namespace vasum { namespace utils { @@ -89,7 +89,7 @@ private: } // namespace utils -} // namespace security_containers +} // namespace vasum #endif // COMMON_UTILS_LATCH_HPP diff --git a/common/utils/paths.hpp b/common/utils/paths.hpp index 14132b4..b86333f 100644 --- a/common/utils/paths.hpp +++ b/common/utils/paths.hpp @@ -30,7 +30,7 @@ #include -namespace security_containers { +namespace vasum { namespace utils { @@ -121,7 +121,7 @@ inline std::string getAbsolutePath(const std::string& path, const std::string& b } // namespace utils -} // namespace security_containers +} // namespace vasum #endif // COMMON_UTILS_PATHS_HPP diff --git a/common/utils/scoped-gerror.cpp b/common/utils/scoped-gerror.cpp index 7ce85d4..0e4de47 100644 --- a/common/utils/scoped-gerror.cpp +++ b/common/utils/scoped-gerror.cpp @@ -26,7 +26,7 @@ #include "scoped-gerror.hpp" -namespace security_containers { +namespace vasum { namespace utils { ScopedGError::ScopedGError() @@ -74,4 +74,4 @@ std::ostream& operator<<(std::ostream& os, const ScopedGError& e) } } // namespace utils -} // namespace security_containers +} // namespace vasum diff --git a/common/utils/scoped-gerror.hpp b/common/utils/scoped-gerror.hpp index 6df8085..0ee4c64 100644 --- a/common/utils/scoped-gerror.hpp +++ b/common/utils/scoped-gerror.hpp @@ -28,7 +28,7 @@ #include #include -namespace security_containers{ +namespace vasum{ namespace utils { class ScopedGError { @@ -73,6 +73,6 @@ private: }; } // namespace utils -} // namespace security_containers +} // namespace vasum #endif // COMMON_SCOPED_GERROR_HPP diff --git a/common/utils/typeinfo.cpp b/common/utils/typeinfo.cpp index 7fe08ad..0f7e574 100644 --- a/common/utils/typeinfo.cpp +++ b/common/utils/typeinfo.cpp @@ -29,7 +29,7 @@ #include #include -namespace security_containers { +namespace vasum { namespace utils { std::string getTypeName(const std::type_info& ti) @@ -47,4 +47,4 @@ std::string getTypeName(const std::type_info& ti) } } // namespace utils -} // namespace security_containers +} // namespace vasum diff --git a/common/utils/typeinfo.hpp b/common/utils/typeinfo.hpp index b08e75a..9faf0cb 100644 --- a/common/utils/typeinfo.hpp +++ b/common/utils/typeinfo.hpp @@ -28,7 +28,7 @@ #include #include -namespace security_containers { +namespace vasum { namespace utils { std::string getTypeName(const std::type_info& ti); @@ -39,7 +39,7 @@ template std::string getTypeName(const T& t) } } // namespace utils -} // namespace security_containers +} // namespace vasum #endif // COMMON_TYPE_INFO_HPP diff --git a/common/utils/vt.cpp b/common/utils/vt.cpp index 22a697e..df8a923 100644 --- a/common/utils/vt.cpp +++ b/common/utils/vt.cpp @@ -39,7 +39,7 @@ const std::string TTY_DEV = "/dev/tty0"; } // namespace -namespace security_containers { +namespace vasum { namespace utils { bool activateVT(const int& vt) @@ -83,4 +83,4 @@ bool activateVT(const int& vt) } } // namespace utils -} // namespace security_containers +} // namespace vasum diff --git a/common/utils/vt.hpp b/common/utils/vt.hpp index d285806..16f4030 100644 --- a/common/utils/vt.hpp +++ b/common/utils/vt.hpp @@ -25,12 +25,12 @@ #ifndef COMMON_UTILS_VT_HPP #define COMMON_UTILS_VT_HPP -namespace security_containers { +namespace vasum { namespace utils { bool activateVT(const int& vt); } // namespace utils -} // namespace security_containers +} // namespace vasum #endif // COMMON_UTILS_VT_HPP diff --git a/container-daemon/configs/org.tizen.containers.zone.daemon.conf.in b/container-daemon/configs/org.tizen.containers.zone.daemon.conf.in index efb60b2..f66921a 100644 --- a/container-daemon/configs/org.tizen.containers.zone.daemon.conf.in +++ b/container-daemon/configs/org.tizen.containers.zone.daemon.conf.in @@ -2,7 +2,7 @@ "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd"> - + diff --git a/container-daemon/daemon-connection.cpp b/container-daemon/daemon-connection.cpp index 7f4d6b7..be171e1 100644 --- a/container-daemon/daemon-connection.cpp +++ b/container-daemon/daemon-connection.cpp @@ -31,7 +31,7 @@ #include "logger/logger.hpp" -namespace security_containers { +namespace vasum { namespace container_daemon { namespace { @@ -139,4 +139,4 @@ void DaemonConnection::onMessageCall(const std::string& objectPath, } } // namespace container_daemon -} // namespace security_containers +} // namespace vasum diff --git a/container-daemon/daemon-connection.hpp b/container-daemon/daemon-connection.hpp index 34129df..8b39f02 100644 --- a/container-daemon/daemon-connection.hpp +++ b/container-daemon/daemon-connection.hpp @@ -32,7 +32,7 @@ #include -namespace security_containers { +namespace vasum { namespace container_daemon { @@ -73,7 +73,7 @@ private: } // namespace container_daemon -} // namespace security_containers +} // namespace vasum #endif // CONTAINER_DAEMON_DAEMON_CONNECTION_HPP diff --git a/container-daemon/daemon-dbus-definitions.hpp b/container-daemon/daemon-dbus-definitions.hpp index 4580d39..057abeb 100644 --- a/container-daemon/daemon-dbus-definitions.hpp +++ b/container-daemon/daemon-dbus-definitions.hpp @@ -28,7 +28,7 @@ #include -namespace security_containers { +namespace vasum { namespace container_daemon { namespace api { @@ -52,7 +52,7 @@ const std::string DEFINITION = } // namespace api } // namespace container_daemon -} // namespace security_containers +} // namespace vasum #endif // CONTAINER_DAEMON_DAEMON_DBUS_DEFINITIONS_HPP diff --git a/container-daemon/daemon.cpp b/container-daemon/daemon.cpp index 6848a09..3955140 100644 --- a/container-daemon/daemon.cpp +++ b/container-daemon/daemon.cpp @@ -29,7 +29,7 @@ #include "logger/logger.hpp" -namespace security_containers { +namespace vasum { namespace container_daemon { @@ -63,4 +63,4 @@ void Daemon::onLoseFocusCallback() } } // namespace container_daemon -} // namespace security_containers +} // namespace vasum diff --git a/container-daemon/daemon.hpp b/container-daemon/daemon.hpp index 1731f6a..0821e70 100644 --- a/container-daemon/daemon.hpp +++ b/container-daemon/daemon.hpp @@ -31,7 +31,7 @@ #include -namespace security_containers { +namespace vasum { namespace container_daemon { class Daemon { @@ -48,7 +48,7 @@ private: } // namespace container_daemon -} // namespace security_containers +} // namespace vasum #endif // CONTAINER_DAEMON_DAEMON_HPP diff --git a/container-daemon/exception.hpp b/container-daemon/exception.hpp index 898d202..011b189 100644 --- a/container-daemon/exception.hpp +++ b/container-daemon/exception.hpp @@ -29,20 +29,20 @@ #include "base-exception.hpp" -namespace security_containers { +namespace vasum { namespace container_daemon { /** - * Base class for exceptions in Security Containers Container Daemon + * Base class for exceptions in Vasum Container Daemon */ -struct ContainerDaemonException: public SecurityContainersException { +struct ContainerDaemonException: public VasumException { - ContainerDaemonException(const std::string& error = "") : SecurityContainersException(error) {} + ContainerDaemonException(const std::string& error = "") : VasumException(error) {} }; } // container_daemon -} // security_containers +} // vasum #endif // CONTAINER_DAEMON_EXCEPTION_HPP diff --git a/container-daemon/main.cpp b/container-daemon/main.cpp index fde059a..0a8a2b9 100644 --- a/container-daemon/main.cpp +++ b/container-daemon/main.cpp @@ -20,7 +20,7 @@ /** * @file * @author Jan Olszak (j.olszak@samsung.com) - * @brief Main file for the Security Containers Daemon + * @brief Main file for the Vasum Daemon */ // Always log to console in DEBUG mode @@ -42,7 +42,7 @@ #include using namespace logger; -using namespace security_containers; +using namespace vasum; namespace po = boost::program_options; @@ -50,7 +50,7 @@ namespace po = boost::program_options; namespace { const std::string PROGRAM_NAME_AND_VERSION = - "Security Containers Containers Daemon " PROGRAM_VERSION; + "Vasum Containers Daemon " PROGRAM_VERSION; } // namespace diff --git a/container-daemon/runner.cpp b/container-daemon/runner.cpp index 7b5c93f..dfa73c1 100644 --- a/container-daemon/runner.cpp +++ b/container-daemon/runner.cpp @@ -34,7 +34,7 @@ #include -namespace security_containers { +namespace vasum { namespace container_daemon { @@ -87,4 +87,4 @@ void Runner::terminate() } } // namespace container_daemon -} // namespace security_containers +} // namespace vasum diff --git a/container-daemon/runner.hpp b/container-daemon/runner.hpp index cdc0913..e68fa0f 100644 --- a/container-daemon/runner.hpp +++ b/container-daemon/runner.hpp @@ -27,7 +27,7 @@ #define CONTAINER_DAEMON_RUNNER_HPP -namespace security_containers { +namespace vasum { namespace container_daemon { @@ -50,7 +50,7 @@ public: } // namespace container_daemon -} // namespace security_containers +} // namespace vasum #endif // CONTAINER_DAEMON_RUNNER_HPP diff --git a/container-support/configs/org.tizen.containers.zone.conf.in b/container-support/configs/org.tizen.containers.zone.conf.in index 264e915..384c8c6 100644 --- a/container-support/configs/org.tizen.containers.zone.conf.in +++ b/container-support/configs/org.tizen.containers.zone.conf.in @@ -2,7 +2,7 @@ "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd"> - + diff --git a/doc/doxygen.cfg b/doc/doxygen.cfg index e997623..2b673a2 100644 --- a/doc/doxygen.cfg +++ b/doc/doxygen.cfg @@ -26,7 +26,7 @@ DOXYFILE_ENCODING = UTF-8 # identify the project. Note that if you do not use Doxywizard you need # to put quotes around the project name if it contains spaces. -PROJECT_NAME = security-containers +PROJECT_NAME = Vasum # The PROJECT_NUMBER tag can be used to enter a project or revision number. # This could be handy for archiving the generated documentation or diff --git a/packaging/security-containers.manifest b/packaging/libvasum-client.manifest similarity index 100% rename from packaging/security-containers.manifest rename to packaging/libvasum-client.manifest diff --git a/packaging/security-containers-server-tests.manifest b/packaging/vasum-container-daemon.manifest similarity index 100% rename from packaging/security-containers-server-tests.manifest rename to packaging/vasum-container-daemon.manifest diff --git a/packaging/security-containers-container-support.manifest b/packaging/vasum-container-support.manifest similarity index 100% rename from packaging/security-containers-container-support.manifest rename to packaging/vasum-container-support.manifest diff --git a/packaging/security-containers-container-daemon.manifest b/packaging/vasum-server-tests.manifest similarity index 100% rename from packaging/security-containers-container-daemon.manifest rename to packaging/vasum-server-tests.manifest diff --git a/packaging/libsecurity-containers-client.manifest b/packaging/vasum.manifest similarity index 100% rename from packaging/libsecurity-containers-client.manifest rename to packaging/vasum.manifest diff --git a/packaging/security-containers.spec b/packaging/vasum.spec similarity index 58% rename from packaging/security-containers.spec rename to packaging/vasum.spec index 47833e4..74114e3 100644 --- a/packaging/security-containers.spec +++ b/packaging/vasum.spec @@ -1,6 +1,6 @@ %define script_dir %{_sbindir} -# Security Containers Server's user info - it should already exist in the system -%define scs_user security-containers +# Vasum Server's user info - it should already exist in the system +%define vsm_user security-containers # The group that has read and write access to /dev/input/event* devices. # It may vary between platforms. %define input_event_group input @@ -9,7 +9,7 @@ # The group that has write access to /dev/tty* devices. %define tty_group tty -Name: security-containers +Name: vasum Version: 0.1.1 Release: 0 Source0: %{name}-%{version}.tar.gz @@ -37,19 +37,19 @@ between them. A process from inside a container can request a switch of context (display, input devices) to the other container. %files -%manifest packaging/security-containers.manifest +%manifest packaging/vasum.manifest %defattr(644,root,root,755) -%attr(755,root,root) %{_bindir}/security-containers-server -%dir /etc/security-containers -%dir /etc/security-containers/containers -%dir /etc/security-containers/lxc-templates -%dir /etc/security-containers/templates -%config /etc/security-containers/daemon.conf -%config /etc/security-containers/containers/*.conf -%attr(755,root,root) /etc/security-containers/lxc-templates/*.sh -%config /etc/security-containers/templates/*.conf -%{_unitdir}/security-containers.service -%{_unitdir}/multi-user.target.wants/security-containers.service +%attr(755,root,root) %{_bindir}/vasum-server +%dir /etc/vasum +%dir /etc/vasum/containers +%dir /etc/vasum/lxc-templates +%dir /etc/vasum/templates +%config /etc/vasum/daemon.conf +%config /etc/vasum/containers/*.conf +%attr(755,root,root) /etc/vasum/lxc-templates/*.sh +%config /etc/vasum/templates/*.conf +%{_unitdir}/vasum.service +%{_unitdir}/multi-user.target.wants/vasum.service /etc/dbus-1/system.d/org.tizen.containers.host.conf %prep @@ -68,7 +68,7 @@ between them. A process from inside a container can request a switch of context -DSCRIPT_INSTALL_DIR=%{script_dir} \ -DSYSTEMD_UNIT_DIR=%{_unitdir} \ -DPYTHON_SITELIB=%{python_sitelib} \ - -DSECURITY_CONTAINERS_USER=%{scs_user} \ + -DVASUM_USER=%{vsm_user} \ -DINPUT_EVENT_GROUP=%{input_event_group} \ -DDISK_GROUP=%{disk_group} \ -DTTY_GROUP=%{tty_group} @@ -77,7 +77,7 @@ make -k %{?jobs:-j%jobs} %install %make_install mkdir -p %{buildroot}/%{_unitdir}/multi-user.target.wants -ln -s ../security-containers.service %{buildroot}/%{_unitdir}/multi-user.target.wants/security-containers.service +ln -s ../vasum.service %{buildroot}/%{_unitdir}/multi-user.target.wants/vasum.service %clean rm -rf %{buildroot} @@ -88,12 +88,12 @@ if [ $1 == 1 ]; then systemctl daemon-reload || : fi # set needed caps on the binary to allow restart without loosing them -setcap CAP_SYS_ADMIN,CAP_MAC_OVERRIDE,CAP_SYS_TTY_CONFIG+ei %{_bindir}/security-containers-server +setcap CAP_SYS_ADMIN,CAP_MAC_OVERRIDE,CAP_SYS_TTY_CONFIG+ei %{_bindir}/vasum-server %preun # Stop the service before uninstall if [ $1 == 0 ]; then - systemctl stop security-containers.service || : + systemctl stop vasum.service || : fi %postun @@ -101,31 +101,31 @@ fi systemctl daemon-reload || : if [ $1 -ge 1 ]; then # TODO: at this point an appropriate notification should show up - eval `systemctl show security-containers --property=MainPID` + eval `systemctl show vasum --property=MainPID` if [ -n "$MainPID" -a "$MainPID" != "0" ]; then kill -USR1 $MainPID fi - echo "Security Containers updated. Reboot is required for the changes to take effect..." + echo "Vasum updated. Reboot is required for the changes to take effect..." else - echo "Security Containers removed. Reboot is required for the changes to take effect..." + echo "Vasum removed. Reboot is required for the changes to take effect..." fi ## Client Package ############################################################## %package client -Summary: Security Containers Client +Summary: Vasum Client Group: Development/Libraries -Requires: security-containers = %{version}-%{release} +Requires: vasum = %{version}-%{release} Requires(post): /sbin/ldconfig Requires(postun): /sbin/ldconfig %description client -Library interface to the security-containers daemon +Library interface to the vasum daemon %files client -%manifest packaging/libsecurity-containers-client.manifest +%manifest packaging/libvasum-client.manifest %defattr(644,root,root,755) -%attr(755,root,root) %{_libdir}/libsecurity-containers.so.0.0.1 -%{_libdir}/libsecurity-containers.so.0 +%attr(755,root,root) %{_libdir}/libvasum.so.0.0.1 +%{_libdir}/libvasum.so.0 %post client -p /sbin/ldconfig @@ -134,34 +134,34 @@ Library interface to the security-containers daemon ## Devel Package ############################################################### %package devel -Summary: Security Containers Client Devel +Summary: Vasum Client Devel Group: Development/Libraries -Requires: security-containers = %{version}-%{release} -Requires: security-containers-client = %{version}-%{release} +Requires: vasum = %{version}-%{release} +Requires: vasum-client = %{version}-%{release} %description devel Development package including the header files for the client library %files devel -%manifest packaging/security-containers.manifest +%manifest packaging/vasum.manifest %defattr(644,root,root,755) -%{_libdir}/libsecurity-containers.so -%{_includedir}/security-containers +%{_libdir}/libvasum.so +%{_includedir}/vasum %{_libdir}/pkgconfig/*.pc ## Container Support Package ################################################### # TODO move to a separate repository %package container-support -Summary: Security Containers Support +Summary: Vasum Support Group: Security/Other -Conflicts: security-containers +Conflicts: vasum %description container-support Containers support installed inside every container. %files container-support -%manifest packaging/security-containers-container-support.manifest +%manifest packaging/vasum-container-support.manifest %defattr(644,root,root,755) /etc/dbus-1/system.d/org.tizen.containers.zone.conf @@ -169,40 +169,40 @@ Containers support installed inside every container. ## Container Daemon Package #################################################### # TODO move to a separate repository %package container-daemon -Summary: Security Containers Containers Daemon +Summary: Vasum Containers Daemon Group: Security/Other -Requires: security-containers-container-support = %{version}-%{release} +Requires: vasum-container-support = %{version}-%{release} %description container-daemon Daemon running inside every container. %files container-daemon -%manifest packaging/security-containers-container-daemon.manifest +%manifest packaging/vasum-container-daemon.manifest %defattr(644,root,root,755) -%attr(755,root,root) %{_bindir}/security-containers-container-daemon +%attr(755,root,root) %{_bindir}/vasum-container-daemon /etc/dbus-1/system.d/org.tizen.containers.zone.daemon.conf ## Command Line Interface ###################################################### %package cli -Summary: Security Containers Command Line Interface +Summary: Vasum Command Line Interface Group: Security/Other -Requires: security-containers-client = %{version}-%{release} +Requires: vasum-client = %{version}-%{release} %description cli -Command Line Interface for security-containers. +Command Line Interface for vasum. %files cli %defattr(644,root,root,755) -%attr(755,root,root) %{_bindir}/security-containers-cli +%attr(755,root,root) %{_bindir}/vasum-cli ## Test Package ################################################################ %package tests -Summary: Security Containers Tests +Summary: Vasum Tests Group: Development/Libraries -Requires: security-containers = %{version}-%{release} -Requires: security-containers-client = %{version}-%{release} +Requires: vasum = %{version}-%{release} +Requires: vasum-client = %{version}-%{release} Requires: python Requires: python-xml Requires: boost-test @@ -211,14 +211,14 @@ Requires: boost-test Unit tests for both: server and client and integration tests. %files tests -%manifest packaging/security-containers-server-tests.manifest +%manifest packaging/vasum-server-tests.manifest %defattr(644,root,root,755) -%attr(755,root,root) %{_bindir}/security-containers-server-unit-tests -%attr(755,root,root) %{script_dir}/sc_all_tests.py -%attr(755,root,root) %{script_dir}/sc_int_tests.py -%attr(755,root,root) %{script_dir}/sc_launch_test.py -%{script_dir}/sc_test_parser.py -%{_datadir}/security-containers/tests -%attr(755,root,root) %{_datadir}/security-containers/lxc-templates -%{python_sitelib}/sc_integration_tests +%attr(755,root,root) %{_bindir}/vasum-server-unit-tests +%attr(755,root,root) %{script_dir}/vsm_all_tests.py +%attr(755,root,root) %{script_dir}/vsm_int_tests.py +%attr(755,root,root) %{script_dir}/vsm_launch_test.py +%{script_dir}/vsm_test_parser.py +%{_datadir}/vasum/tests +%attr(755,root,root) %{_datadir}/vasum/lxc-templates +%{python_sitelib}/vsm_integration_tests /etc/dbus-1/system.d/org.tizen.containers.tests.conf diff --git a/server/common-dbus-definitions.hpp b/server/common-dbus-definitions.hpp index 389f73f..de355b3 100644 --- a/server/common-dbus-definitions.hpp +++ b/server/common-dbus-definitions.hpp @@ -28,7 +28,7 @@ #include -namespace security_containers { +namespace vasum { namespace api { const std::string ERROR_FORBIDDEN = "org.tizen.containers.Error.Forbidden"; const std::string ERROR_FORWARDED = "org.tizen.containers.Error.Forwarded"; @@ -39,7 +39,7 @@ const std::string ERROR_INTERNAL = "org.tizen.containers.Error.Internal"; const std::string METHOD_PROXY_CALL = "ProxyCall"; } // namespace api -} // namespace security_containers +} // namespace vasum #endif // SERVER_COMMON_DBUS_DEFINITIONS_HPP diff --git a/server/configs/CMakeLists.txt b/server/configs/CMakeLists.txt index e4f9df9..cb4d003 100644 --- a/server/configs/CMakeLists.txt +++ b/server/configs/CMakeLists.txt @@ -17,20 +17,20 @@ # @author Lukasz Pawelczyk (l.pawelczyk@partner.samsung.com) # -MESSAGE(STATUS "Installing configs to " ${SC_CONFIG_INSTALL_DIR}) +MESSAGE(STATUS "Installing configs to " ${VSM_CONFIG_INSTALL_DIR}) FILE(GLOB container_CONF containers/*.conf) FILE(GLOB admin_CONF lxc-templates/*.sh) FILE(GLOB template_CONF templates/*.conf) ## Generate #################################################################### -CONFIGURE_FILE(systemd/security-containers.service.in - ${CMAKE_BINARY_DIR}/systemd/security-containers.service) +CONFIGURE_FILE(systemd/vasum.service.in + ${CMAKE_BINARY_DIR}/systemd/vasum.service) ## Install ##################################################################### INSTALL(FILES daemon.conf - DESTINATION ${SC_CONFIG_INSTALL_DIR}) + DESTINATION ${VSM_CONFIG_INSTALL_DIR}) # preprocess d-bus configs CONFIGURE_FILE(dbus-1/system.d/org.tizen.containers.host.conf.in @@ -40,13 +40,13 @@ INSTALL(FILES ${CMAKE_BINARY_DIR}/dbus-1/system.d/org.tizen.containers.hos DESTINATION ${SYSCONF_INSTALL_DIR}/dbus-1/system.d/) INSTALL(FILES ${container_CONF} - DESTINATION ${SC_CONFIG_INSTALL_DIR}/containers) + DESTINATION ${VSM_CONFIG_INSTALL_DIR}/containers) INSTALL(PROGRAMS ${admin_CONF} - DESTINATION ${SC_CONFIG_INSTALL_DIR}/lxc-templates) + DESTINATION ${VSM_CONFIG_INSTALL_DIR}/lxc-templates) INSTALL(PROGRAMS ${template_CONF} - DESTINATION ${SC_CONFIG_INSTALL_DIR}/templates) + DESTINATION ${VSM_CONFIG_INSTALL_DIR}/templates) -INSTALL(FILES ${CMAKE_BINARY_DIR}/systemd/security-containers.service +INSTALL(FILES ${CMAKE_BINARY_DIR}/systemd/vasum.service DESTINATION ${SYSTEMD_UNIT_DIR}) diff --git a/server/configs/daemon.conf b/server/configs/daemon.conf index 058a3cd..7a0f8c1 100644 --- a/server/configs/daemon.conf +++ b/server/configs/daemon.conf @@ -3,11 +3,11 @@ "containersPath" : "/opt/usr/containers", "containerImagePath" : "/opt/usr/containers/img/system-data.img", "containerTemplatePath" : "templates", - "containerNewConfigPrefix" : "/var/lib/security-containers", + "containerNewConfigPrefix" : "/var/lib/vasum", "runMountPointPrefix" : "/var/run/containers", "foregroundId" : "private", "defaultId" : "private", - "lxcTemplatePrefix" : "/etc/security-containers/lxc-templates", + "lxcTemplatePrefix" : "/etc/vasum/lxc-templates", "inputConfig" : {"enabled" : false, "device" : "gpio_keys.6", "code" : 139, diff --git a/server/configs/dbus-1/system.d/org.tizen.containers.host.conf.in b/server/configs/dbus-1/system.d/org.tizen.containers.host.conf.in index c29a684..948a731 100644 --- a/server/configs/dbus-1/system.d/org.tizen.containers.host.conf.in +++ b/server/configs/dbus-1/system.d/org.tizen.containers.host.conf.in @@ -2,7 +2,7 @@ "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd"> - + diff --git a/server/configs/systemd/security-containers.service.in b/server/configs/systemd/vasum.service.in similarity index 58% rename from server/configs/systemd/security-containers.service.in rename to server/configs/systemd/vasum.service.in index a1b8af0..f36622a 100644 --- a/server/configs/systemd/security-containers.service.in +++ b/server/configs/systemd/vasum.service.in @@ -1,10 +1,10 @@ [Unit] -Description=Security Containers Server +Description=Vasum Server ConditionVirtualization=no [Service] Type=simple -ExecStart=${CMAKE_INSTALL_PREFIX}/bin/security-containers-server +ExecStart=${CMAKE_INSTALL_PREFIX}/bin/vasum-server Restart=on-failure ExecReload=/bin/kill -HUP $MAINPID diff --git a/server/container-admin.cpp b/server/container-admin.cpp index bd9f8f1..e00fd71 100644 --- a/server/container-admin.cpp +++ b/server/container-admin.cpp @@ -34,7 +34,7 @@ #include -namespace security_containers { +namespace vasum { namespace { @@ -50,14 +50,14 @@ ContainerAdmin::ContainerAdmin(const std::string& containersPath, const std::string& lxcTemplatePrefix, const ContainerConfig& config) : mConfig(config), - mDom(containersPath, config.name), - mId(mDom.getName()), + mZone(containersPath, config.name), + mId(mZone.getName()), mDetachOnExit(false), mDestroyOnExit(false) { LOGD(mId << ": Instantiating ContainerAdmin object"); - if (!mDom.isDefined()) { + if (!mZone.isDefined()) { const std::string lxcTemplate = utils::getAbsolutePath(config.lxcTemplate, lxcTemplatePrefix); @@ -71,7 +71,7 @@ ContainerAdmin::ContainerAdmin(const std::string& containersPath, args.add("--ipv4"); args.add(config.ipv4.c_str()); } - if (!mDom.create(lxcTemplate, args.c_array())) { + if (!mZone.create(lxcTemplate, args.c_array())) { throw ContainerOperationException("Could not create zone"); } } @@ -83,17 +83,17 @@ ContainerAdmin::~ContainerAdmin() LOGD(mId << ": Destroying ContainerAdmin object..."); if (mDestroyOnExit) { - if (!mDom.stop()) { + if (!mZone.stop()) { LOGE(mId << ": Failed to stop the container"); } - if (!mDom.destroy()) { + if (!mZone.destroy()) { LOGE(mId << ": Failed to destroy the container"); } } if (!mDetachOnExit) { // Try to forcefully stop - if (!mDom.stop()) { + if (!mZone.stop()) { LOGE(mId << ": Failed to stop the container"); } } @@ -124,7 +124,7 @@ void ContainerAdmin::start() args.add("/sbin/init"); } - if (!mDom.start(args.c_array())) { + if (!mZone.start(args.c_array())) { throw ContainerOperationException("Could not start container"); } @@ -140,9 +140,9 @@ void ContainerAdmin::stop() return; } - if (!mDom.shutdown(SHUTDOWN_WAIT)) { + if (!mZone.shutdown(SHUTDOWN_WAIT)) { // force stop - if (!mDom.stop()) { + if (!mZone.stop()) { throw ContainerOperationException("Could not stop container"); } } @@ -155,7 +155,7 @@ void ContainerAdmin::destroy() { LOGD(mId << ": Destroying procedure started..."); - if (!mDom.destroy()) { + if (!mZone.destroy()) { throw ContainerOperationException("Could not destroy container"); } @@ -165,20 +165,20 @@ void ContainerAdmin::destroy() bool ContainerAdmin::isRunning() { - return mDom.getState() == lxc::LxcZone::State::RUNNING; + return mZone.getState() == lxc::LxcZone::State::RUNNING; } bool ContainerAdmin::isStopped() { - return mDom.getState() == lxc::LxcZone::State::STOPPED; + return mZone.getState() == lxc::LxcZone::State::STOPPED; } void ContainerAdmin::suspend() { LOGD(mId << ": Pausing..."); - if (!mDom.freeze()) { + if (!mZone.freeze()) { throw ContainerOperationException("Could not pause container"); } LOGD(mId << ": Paused"); @@ -188,7 +188,7 @@ void ContainerAdmin::suspend() void ContainerAdmin::resume() { LOGD(mId << ": Resuming..."); - if (!mDom.unfreeze()) { + if (!mZone.unfreeze()) { throw ContainerOperationException("Could not resume container"); } LOGD(mId << ": Resumed"); @@ -197,7 +197,7 @@ void ContainerAdmin::resume() bool ContainerAdmin::isPaused() { - return mDom.getState() == lxc::LxcZone::State::FROZEN; + return mZone.getState() == lxc::LxcZone::State::FROZEN; } @@ -225,7 +225,7 @@ void ContainerAdmin::setSchedulerLevel(SchedulerLevel sched) void ContainerAdmin::setSchedulerParams(std::uint64_t, std::uint64_t, std::int64_t) //void ContainerAdmin::setSchedulerParams(std::uint64_t cpuShares, std::uint64_t vcpuPeriod, std::int64_t vcpuQuota) { -// assert(mDom); +// assert(mZone); // // int maxParams = 3; // int numParamsBuff = 0; @@ -238,7 +238,7 @@ void ContainerAdmin::setSchedulerParams(std::uint64_t, std::uint64_t, std::int64 // virTypedParamsAddULLong(¶msTmp, &numParamsBuff, &maxParams, VIR_DOMAIN_SCHEDULER_VCPU_PERIOD, vcpuPeriod); // virTypedParamsAddLLong(¶msTmp, &numParamsBuff, &maxParams, VIR_DOMAIN_SCHEDULER_VCPU_QUOTA, vcpuQuota); // -// if (virDomainSetSchedulerParameters(mDom.get(), params.get(), numParamsBuff) < 0) { +// if (virDomainSetSchedulerParameters(mZone.get(), params.get(), numParamsBuff) < 0) { // LOGE(mId << ": Error while setting the container's scheduler params:\n" // << libvirt::libvirtFormatError()); // throw ContainerOperationException(); @@ -257,10 +257,10 @@ void ContainerAdmin::setDestroyOnExit() std::int64_t ContainerAdmin::getSchedulerQuota() { -// assert(mDom); +// assert(mZone); // // int numParamsBuff; -// std::unique_ptr type(virDomainGetSchedulerType(mDom.get(), &numParamsBuff), free); +// std::unique_ptr type(virDomainGetSchedulerType(mZone.get(), &numParamsBuff), free); // // if (type == NULL || numParamsBuff <= 0 || strcmp(type.get(), "posix") != 0) { // LOGE(mId << ": Error while getting the container's scheduler type:\n" @@ -270,7 +270,7 @@ std::int64_t ContainerAdmin::getSchedulerQuota() // // std::unique_ptr params(new virTypedParameter[numParamsBuff]); // -// if (virDomainGetSchedulerParameters(mDom.get(), params.get(), &numParamsBuff) < 0) { +// if (virDomainGetSchedulerParameters(mZone.get(), params.get(), &numParamsBuff) < 0) { // LOGE(mId << ": Error while getting the container's scheduler params:\n" // << libvirt::libvirtFormatError()); // throw ContainerOperationException(); @@ -291,4 +291,4 @@ std::int64_t ContainerAdmin::getSchedulerQuota() } -} // namespace security_containers +} // namespace vasum diff --git a/server/container-admin.hpp b/server/container-admin.hpp index c40f30c..050d9d9 100644 --- a/server/container-admin.hpp +++ b/server/container-admin.hpp @@ -30,7 +30,7 @@ #include "lxc/zone.hpp" -namespace security_containers { +namespace vasum { enum class SchedulerLevel { @@ -128,7 +128,7 @@ public: private: const ContainerConfig& mConfig; - lxc::LxcZone mDom; + lxc::LxcZone mZone; const std::string mId; bool mDetachOnExit; bool mDestroyOnExit; @@ -137,7 +137,7 @@ private: }; -} // namespace security_containers +} // namespace vasum #endif // SERVER_CONTAINER_ADMIN_HPP diff --git a/server/container-config.hpp b/server/container-config.hpp index c1ba2e9..d9331b3 100644 --- a/server/container-config.hpp +++ b/server/container-config.hpp @@ -32,7 +32,7 @@ #include -namespace security_containers { +namespace vasum { struct ContainerConfig { @@ -132,7 +132,6 @@ struct ContainerConfig { }; -} - +} // namespace vasum #endif // SERVER_CONTAINER_CONFIG_HPP diff --git a/server/container-connection-transport.cpp b/server/container-connection-transport.cpp index b5bcfb5..bbbfdcf 100644 --- a/server/container-connection-transport.cpp +++ b/server/container-connection-transport.cpp @@ -34,7 +34,7 @@ #include #include -namespace security_containers { +namespace vasum { namespace { @@ -120,4 +120,4 @@ void ContainerConnectionTransport::setDetachOnExit() mDetachOnExit = true; } -} // namespace security_containers +} // namespace vasum diff --git a/server/container-connection-transport.hpp b/server/container-connection-transport.hpp index 0be1035..5e7c9e8 100644 --- a/server/container-connection-transport.hpp +++ b/server/container-connection-transport.hpp @@ -29,7 +29,7 @@ #include "dbus/connection.hpp" -namespace security_containers { +namespace vasum { /** @@ -57,7 +57,7 @@ private: }; -} // namespace security_containers +} // namespace vasum #endif // SERVER_CONTAINER_CONNECTION_TRANSPORT_HPP diff --git a/server/container-connection.cpp b/server/container-connection.cpp index 7eb8447..8e18590 100644 --- a/server/container-connection.cpp +++ b/server/container-connection.cpp @@ -33,7 +33,7 @@ #include "logger/logger.hpp" -namespace security_containers { +namespace vasum { namespace { @@ -256,4 +256,4 @@ void ContainerConnection::proxyCallAsync(const std::string& busName, } -} // namespace security_containers +} // namespace vasum diff --git a/server/container-connection.hpp b/server/container-connection.hpp index a635bc8..cb41b7f 100644 --- a/server/container-connection.hpp +++ b/server/container-connection.hpp @@ -32,7 +32,7 @@ #include -namespace security_containers { +namespace vasum { class ContainerConnection { @@ -130,7 +130,7 @@ private: }; -} // namespace security_containers +} // namespace vasum #endif // SERVER_CONTAINER_CONNECTION_HPP diff --git a/server/container-dbus-definitions.hpp b/server/container-dbus-definitions.hpp index d22c633..8d9efe9 100644 --- a/server/container-dbus-definitions.hpp +++ b/server/container-dbus-definitions.hpp @@ -28,7 +28,7 @@ #include "common-dbus-definitions.hpp" -namespace security_containers { +namespace vasum { namespace api { namespace container { @@ -79,7 +79,7 @@ const std::string DEFINITION = } // namespace container } // namespace api -} // namespace security_containers +} // namespace vasum #endif // SERVER_CONTAINER_DBUS_DEFINITIONS_HPP diff --git a/server/container.cpp b/server/container.cpp index e411798..b3be5a5 100644 --- a/server/container.cpp +++ b/server/container.cpp @@ -39,7 +39,7 @@ #include -namespace security_containers { +namespace vasum { namespace fs = boost::filesystem; @@ -328,7 +328,7 @@ void Container::reconnectHandler() connect(); LOGI(getId() << ": Reconnected"); return; - } catch (SecurityContainersException&) { + } catch (VasumException&) { LOGT(getId() << ": Reconnect try " << i + 1 << " has been unsuccessful"); } } @@ -445,4 +445,4 @@ void Container::declareLink(const std::string& source, declareUnit(mProvisionConfig, std::move(unit)); } -} // namespace security_containers +} // namespace vasum diff --git a/server/container.hpp b/server/container.hpp index fe9c317..88f5171 100644 --- a/server/container.hpp +++ b/server/container.hpp @@ -37,7 +37,7 @@ #include -namespace security_containers { +namespace vasum { class Container { @@ -278,7 +278,6 @@ private: }; -} - +} // namespace vasum #endif // SERVER_CONTAINER_HPP diff --git a/server/containers-manager-config.hpp b/server/containers-manager-config.hpp index 83c8901..58509a8 100644 --- a/server/containers-manager-config.hpp +++ b/server/containers-manager-config.hpp @@ -34,10 +34,10 @@ #include -namespace security_containers { +namespace vasum { -const std::string CONTAINERS_MANAGER_CONFIG_PATH = "/etc/security-containers/config/daemon.conf"; +const std::string CONTAINERS_MANAGER_CONFIG_PATH = "/etc/vasum/config/daemon.conf"; struct ContainersManagerConfig { @@ -115,7 +115,7 @@ struct ContainersManagerConfig { }; -} // namespace security_containers +} // namespace vasum #endif // SERVER_CONTAINERS_MANAGER_CONFIG_HPP diff --git a/server/containers-manager.cpp b/server/containers-manager.cpp index 5250b98..fa3f157 100644 --- a/server/containers-manager.cpp +++ b/server/containers-manager.cpp @@ -47,7 +47,7 @@ #include -namespace security_containers { +namespace vasum { namespace { @@ -350,7 +350,7 @@ void ContainersManager::notifyActiveContainerHandler(const std::string& caller, if (!activeContainer.empty() && caller != activeContainer) { mContainers[activeContainer]->sendNotification(caller, application, message); } - } catch(const SecurityContainersException&) { + } catch(const VasumException&) { LOGE("Notification from " << caller << " hasn't been sent"); } } @@ -387,7 +387,7 @@ void ContainersManager::handleContainerMoveFileRequest(const std::string& srcCon // NOTE: other possible implementations include: // 1. Sending file descriptors opened directly in each container through DBUS // using something like g_dbus_message_set_unix_fd_list() - // 2. SCS forking and calling setns(MNT) in each container and opening files + // 2. VSM forking and calling setns(MNT) in each container and opening files // by itself, then passing FDs to the main process // Now when the main process has obtained FDs (by either of those methods) // it can do the copying by itself. @@ -703,7 +703,7 @@ void ContainersManager::generateNewConfig(const std::string& id, throw ContainerOperationException("Failed to save new config file."); } - // restrict new config file so that only owner (security-containers) can write it + // restrict new config file so that only owner (vasum) can write it fs::permissions(resultPath, fs::perms::owner_all | fs::perms::group_read | fs::perms::others_read); @@ -769,7 +769,7 @@ void ContainersManager::handleCreateContainerCall(const std::string& id, LOGI("Generating config from " << configPath << " to " << newConfigPath); generateNewConfig(id, configPath, newConfigPath); - } catch (SecurityContainersException& e) { + } catch (VasumException& e) { LOGE("Generate config failed: " << e.what()); utils::launchAsRoot(std::bind(removeAllWrapper, containerPathStr)); result->setError(api::ERROR_INTERNAL, "Failed to generate config"); @@ -779,7 +779,7 @@ void ContainersManager::handleCreateContainerCall(const std::string& id, LOGT("Creating new container"); try { createContainer(newConfigPath); - } catch (SecurityContainersException& e) { + } catch (VasumException& e) { LOGE("Creating new container failed: " << e.what()); utils::launchAsRoot(std::bind(removeAllWrapper, containerPathStr)); result->setError(api::ERROR_INTERNAL, "Failed to create container"); @@ -813,7 +813,7 @@ void ContainersManager::handleDestroyContainerCall(const std::string& id, auto destroyer = [id, result, this] { try { destroyContainer(id); - } catch (const SecurityContainersException& e) { + } catch (const VasumException& e) { LOGE("Error during container destruction: " << e.what()); result->setError(api::ERROR_INTERNAL, "Failed to destroy container"); return; @@ -885,4 +885,4 @@ void ContainersManager::handleUnlockContainerCall(const std::string& id, result->setVoid(); } -} // namespace security_containers +} // namespace vasum diff --git a/server/containers-manager.hpp b/server/containers-manager.hpp index 5f31b97..b9773e9 100644 --- a/server/containers-manager.hpp +++ b/server/containers-manager.hpp @@ -37,7 +37,7 @@ #include -namespace security_containers { +namespace vasum { class ContainersManager final { @@ -171,7 +171,7 @@ private: }; -} // namespace security_containers +} // namespace vasum #endif // SERVER_CONTAINERS_MANAGER_HPP diff --git a/server/exception.hpp b/server/exception.hpp index adfbdf7..55d7727 100644 --- a/server/exception.hpp +++ b/server/exception.hpp @@ -29,15 +29,15 @@ #include "base-exception.hpp" -namespace security_containers { +namespace vasum { /** - * Base class for exceptions in Security Containers Server + * Base class for exceptions in Vasum Server */ -struct ServerException: public SecurityContainersException { +struct ServerException: public VasumException { - ServerException(const std::string& error = "") : SecurityContainersException(error) {} + ServerException(const std::string& error = "") : VasumException(error) {} }; /** diff --git a/server/host-connection.cpp b/server/host-connection.cpp index f862b55..37eaeba 100644 --- a/server/host-connection.cpp +++ b/server/host-connection.cpp @@ -31,7 +31,7 @@ #include "logger/logger.hpp" -namespace security_containers { +namespace vasum { namespace { @@ -363,4 +363,4 @@ void HostConnection::signalContainerDbusState(const std::string& containerId, } -} // namespace security_containers +} // namespace vasum diff --git a/server/host-connection.hpp b/server/host-connection.hpp index bbec909..b5f581c 100644 --- a/server/host-connection.hpp +++ b/server/host-connection.hpp @@ -32,7 +32,7 @@ #include -namespace security_containers { +namespace vasum { class HostConnection { @@ -208,7 +208,7 @@ private: }; -} // namespace security_containers +} // namespace vasum #endif // SERVER_HOST_CONNECTION_HPP diff --git a/server/host-dbus-definitions.hpp b/server/host-dbus-definitions.hpp index 1b134ea..15ace0d 100644 --- a/server/host-dbus-definitions.hpp +++ b/server/host-dbus-definitions.hpp @@ -28,7 +28,7 @@ #include "common-dbus-definitions.hpp" -namespace security_containers { +namespace vasum { namespace api { namespace host { @@ -123,7 +123,7 @@ const std::string DEFINITION = } // namespace host } // namespace api -} // namespace security_containers +} // namespace vasum #endif // SERVER_HOST_DBUS_DEFINITIONS_HPP diff --git a/server/input-monitor-config.hpp b/server/input-monitor-config.hpp index 33e716f..52e0c50 100644 --- a/server/input-monitor-config.hpp +++ b/server/input-monitor-config.hpp @@ -32,7 +32,7 @@ #include -namespace security_containers { +namespace vasum { struct InputConfig { @@ -73,6 +73,6 @@ struct InputConfig { }; -} // namespace security_containers +} // namespace vasum #endif /* SERVER_INPUT_MONITOR_CONFIG_HPP */ diff --git a/server/input-monitor.cpp b/server/input-monitor.cpp index 76dff29..8d641b1 100644 --- a/server/input-monitor.cpp +++ b/server/input-monitor.cpp @@ -49,10 +49,10 @@ #include #include -using namespace security_containers::utils; +using namespace vasum::utils; namespace fs = boost::filesystem; -namespace security_containers { +namespace vasum { namespace { const int MAX_TIME_WINDOW_SEC = 10; @@ -292,4 +292,4 @@ bool InputMonitor::isExpectedEventSequence(const struct input_event& ie) LOGT("Event sequence not detected"); return false; } -} // namespace security_containers +} // namespace vasum diff --git a/server/input-monitor.hpp b/server/input-monitor.hpp index 15262bc..93c2d75 100644 --- a/server/input-monitor.hpp +++ b/server/input-monitor.hpp @@ -37,7 +37,7 @@ #include -namespace security_containers { +namespace vasum { class InputMonitor { public: @@ -67,7 +67,7 @@ private: guint mSourceId; }; -} // namespace security_containers +} // namespace vasum #endif // SERVER_INPUT_MONITOR_HPP diff --git a/server/main.cpp b/server/main.cpp index bf3da84..d641148 100644 --- a/server/main.cpp +++ b/server/main.cpp @@ -20,7 +20,7 @@ /** * @file * @author Jan Olszak (j.olszak@samsung.com) - * @brief Main file for the Security Containers Daemon + * @brief Main file for the Vasum Daemon */ // Always log to console in DEBUG mode @@ -42,7 +42,7 @@ #include using namespace logger; -using namespace security_containers; +using namespace vasum; namespace po = boost::program_options; @@ -50,7 +50,7 @@ namespace po = boost::program_options; namespace { const std::string PROGRAM_NAME_AND_VERSION = - "Security Containers Server " PROGRAM_VERSION; + "Vasum Server " PROGRAM_VERSION; } // namespace @@ -67,7 +67,7 @@ int main(int argc, char* argv[]) ("root,r", "Don't drop root privileges at startup") ("version,v", "show application version") ("log-level,l", po::value()->default_value("DEBUG"), "set log level") - ("config,c", po::value()->default_value("/etc/security-containers/daemon.conf"), "server configuration file") + ("config,c", po::value()->default_value("/etc/vasum/daemon.conf"), "server configuration file") ; po::variables_map vm; diff --git a/server/proxy-call-config.hpp b/server/proxy-call-config.hpp index f20d119..3bb734c 100644 --- a/server/proxy-call-config.hpp +++ b/server/proxy-call-config.hpp @@ -32,7 +32,7 @@ #include -namespace security_containers { +namespace vasum { /** * A single allow rule for proxy call dispatching. @@ -58,6 +58,6 @@ struct ProxyCallRule { }; -} // namespace security_containers +} // namespace vasum #endif /* SERVER_PROXY_CALL_CONFIG_HPP */ diff --git a/server/proxy-call-policy.cpp b/server/proxy-call-policy.cpp index c452d53..281cb3a 100644 --- a/server/proxy-call-policy.cpp +++ b/server/proxy-call-policy.cpp @@ -28,7 +28,7 @@ #include "proxy-call-policy.hpp" -namespace security_containers { +namespace vasum { namespace { const std::string ANY = "*"; @@ -68,4 +68,4 @@ bool ProxyCallPolicy::isProxyCallAllowed(const std::string& caller, } -} // namespace security_containers +} // namespace vasum diff --git a/server/proxy-call-policy.hpp b/server/proxy-call-policy.hpp index cbab0e0..4176979 100644 --- a/server/proxy-call-policy.hpp +++ b/server/proxy-call-policy.hpp @@ -31,7 +31,7 @@ #include -namespace security_containers { +namespace vasum { class ProxyCallPolicy { @@ -51,7 +51,7 @@ private: }; -} // namespace security_containers +} // namespace vasum #endif // SERVER_PROXY_CALL_POLICY_HPP diff --git a/server/server.cpp b/server/server.cpp index 5f2bb6e..f2d70c1 100644 --- a/server/server.cpp +++ b/server/server.cpp @@ -46,8 +46,8 @@ #include -#ifndef SECURITY_CONTAINERS_USER -#error "SECURITY_CONTAINERS_USER must be defined!" +#ifndef VASUM_USER +#error "VASUM_USER must be defined!" #endif #ifndef INPUT_EVENT_GROUP @@ -64,7 +64,7 @@ extern char** environ; -namespace security_containers { +namespace vasum { Server::Server(const std::string& configPath, bool runAsRoot) @@ -150,14 +150,14 @@ bool Server::prepareEnvironment(const std::string& configPath, bool runAsRoot) ContainersManagerConfig config; config::loadFromFile(configPath, config); - struct passwd* pwd = ::getpwnam(SECURITY_CONTAINERS_USER); + struct passwd* pwd = ::getpwnam(VASUM_USER); if (pwd == NULL) { - LOGE("getpwnam failed to find user '" << SECURITY_CONTAINERS_USER << "'"); + LOGE("getpwnam failed to find user '" << VASUM_USER << "'"); return false; } uid_t uid = pwd->pw_uid; gid_t gid = pwd->pw_gid; - LOGD("security-containers UID = " << uid << ", GID = " << gid); + LOGD("vasum UID = " << uid << ", GID = " << gid); // create directory for dbus socket (if needed) if (!config.runMountPointPrefix.empty()) { @@ -208,4 +208,4 @@ bool Server::prepareEnvironment(const std::string& configPath, bool runAsRoot) } -} // namespace security_containers +} // namespace vasum diff --git a/server/server.hpp b/server/server.hpp index ba2334e..525eb23 100644 --- a/server/server.hpp +++ b/server/server.hpp @@ -31,7 +31,7 @@ #include -namespace security_containers { +namespace vasum { class Server { @@ -64,7 +64,7 @@ private: }; -} // namespace security_containers +} // namespace vasum #endif // SERVER_SERVER_HPP diff --git a/tests/integration_tests/CMakeLists.txt b/tests/integration_tests/CMakeLists.txt index 7330049..12a641d 100644 --- a/tests/integration_tests/CMakeLists.txt +++ b/tests/integration_tests/CMakeLists.txt @@ -22,12 +22,12 @@ MESSAGE(STATUS "Generating makefile for Integration Tests...") ## Defines for further package installation #################################### -SET(TEST_DEST_DIR "${PYTHON_SITELIB}/sc_integration_tests") +SET(TEST_DEST_DIR "${PYTHON_SITELIB}/vsm_integration_tests") ## Search for .py files available ############################################## FILE(GLOB py_SCRIPTS *.py) -FILE(GLOB main_SCRIPT sc_int_tests.py) +FILE(GLOB main_SCRIPT vsm_int_tests.py) LIST(REMOVE_ITEM py_SCRIPTS ${main_SCRIPT}) diff --git a/tests/integration_tests/common/__init__.py b/tests/integration_tests/common/__init__.py index 1be1917..6915d3b 100644 --- a/tests/integration_tests/common/__init__.py +++ b/tests/integration_tests/common/__init__.py @@ -1,2 +1,2 @@ -__all__ = ["sc_test_utils", +__all__ = ["vsm_test_utils", ] diff --git a/tests/integration_tests/common/sc_test_utils.py b/tests/integration_tests/common/vsm_test_utils.py similarity index 100% rename from tests/integration_tests/common/sc_test_utils.py rename to tests/integration_tests/common/vsm_test_utils.py diff --git a/tests/integration_tests/image_tests/config_checker.py b/tests/integration_tests/image_tests/config_checker.py index 4cc2d18..035c460 100644 --- a/tests/integration_tests/image_tests/config_checker.py +++ b/tests/integration_tests/image_tests/config_checker.py @@ -1,16 +1,16 @@ -'''! Module used to collect list of containers based on the security-containers configuration files. +'''! Module used to collect list of containers based on the vasum configuration files. @author: Michal Witanowski (m.witanowski@samsung.com) ''' import os import json import xml.etree.ElementTree as ET -from sc_integration_tests.common import sc_test_utils +from vsm_integration_tests.common import vsm_test_utils from pprint import pprint class ConfigChecker: - '''! This class verifies security-containers configuration files and collects dictionary with + '''! This class verifies vasum configuration files and collects dictionary with containers existing in the system (name and rootfs path). ''' @@ -61,7 +61,7 @@ class ConfigChecker: # load main daemon JSON config file if not os.path.isfile(mainConfigPath): raise Exception(mainConfigPath + " not found. " + - "Please verify that security containers is properly installed.") + "Please verify that vasum is properly installed.") with open(mainConfigPath) as daemonConfigStr: daemonConfigData = json.load(daemonConfigStr) daemonConfigDir = os.path.dirname(os.path.abspath(mainConfigPath)) @@ -74,7 +74,7 @@ class ConfigChecker: containerConfigPath = os.path.join(daemonConfigDir, configPath) if not os.path.isfile(containerConfigPath): raise Exception(containerConfigPath + " not found. " + - "Please verify that security containers is properly installed.") + "Please verify that vasum is properly installed.") with open(containerConfigPath) as containerConfigStr: containerConfigData = json.load(containerConfigStr) @@ -82,7 +82,7 @@ class ConfigChecker: libvirtConfigPath = os.path.join(daemonConfigDir, "containers", containerConfigData["config"]) - output, ret = sc_test_utils.launchProc("virt-xml-validate " + libvirtConfigPath) + output, ret = vsm_test_utils.launchProc("virt-xml-validate " + libvirtConfigPath) if ret == 0: self.__parseLibvirtXML(libvirtConfigPath) else: diff --git a/tests/integration_tests/image_tests/image_tests.py b/tests/integration_tests/image_tests/image_tests.py index a74c5ac..79f72e8 100644 --- a/tests/integration_tests/image_tests/image_tests.py +++ b/tests/integration_tests/image_tests/image_tests.py @@ -3,14 +3,14 @@ @author: Michal Witanowski (m.witanowski@samsung.com) ''' import unittest -from sc_integration_tests.common import sc_test_utils +from vsm_integration_tests.common import vsm_test_utils from config_checker import * import xml.etree.ElementTree as ET -# security-containers daemon user name and user ID -SCS_USER_NAME = "security-containers" -SCS_UID = 377 +# vasum daemon user name and user ID +VSM_USER_NAME = "security-containers" +VSM_UID = 377 DAEMON_DBUS_SOCKET_NAME = "org.tizen.containers.zone" @@ -18,7 +18,7 @@ DAEMON_DBUS_SOCKET_NAME = "org.tizen.containers.zone" DBUS_CONFIG_PATH = "etc/dbus-1/system.d/" + DAEMON_DBUS_SOCKET_NAME + ".conf" # main daemon config -DAEMON_CONFIG_PATH = "/etc/security-containers/daemon.conf" +DAEMON_CONFIG_PATH = "/etc/vasum/daemon.conf" class ContainerImageTestCase(unittest.TestCase): @@ -31,23 +31,23 @@ class ContainerImageTestCase(unittest.TestCase): ''' self.configChecker = ConfigChecker(DAEMON_CONFIG_PATH) - def test01_scsUserExistence(self): - '''! Verifies if "security-containers" user with an appropriate UID exists within the + def test01_vsmUserExistence(self): + '''! Verifies if "vasum" user with an appropriate UID exists within the containers. ''' for containerName, containerPath in self.configChecker.containers.iteritems(): # chroot into a container and get UID of the user - output, ret = sc_test_utils.launchProc("chroot " + containerPath + - " /usr/bin/id -u " + SCS_USER_NAME) + output, ret = vsm_test_utils.launchProc("chroot " + containerPath + + " /usr/bin/id -u " + VSM_USER_NAME) - self.assertEqual(ret, 0, "User '" + SCS_USER_NAME + "' does not exist in '" + + self.assertEqual(ret, 0, "User '" + VSM_USER_NAME + "' does not exist in '" + containerName + "' container.") # cast to integer to remove white spaces, etc. uid = int(output) - self.assertEqual(uid, SCS_UID, "Invalid UID of '" + SCS_USER_NAME + "' in '" + + self.assertEqual(uid, VSM_UID, "Invalid UID of '" + VSM_USER_NAME + "' in '" + containerName + "' container: got " + str(uid) + - ", should be " + str(SCS_UID)) + ", should be " + str(VSM_UID)) def test02_dbusConfig(self): '''! Verifies if dbus configuration file exists within containers. @@ -61,7 +61,7 @@ class ContainerImageTestCase(unittest.TestCase): root = tree.getroot() self.assertEqual(root.tag, "busconfig", "Invalid root node name") - # validate "security-containers" access to the dbus + # validate "vasum" access to the dbus ownCheck = False sendDestinationCheck = False receiveSenderCheck = False @@ -71,7 +71,7 @@ class ContainerImageTestCase(unittest.TestCase): if "user" not in elem.attrib: continue - self.assertEqual(elem.attrib["user"], SCS_USER_NAME, "dbus configuration allows '" + + self.assertEqual(elem.attrib["user"], VSM_USER_NAME, "dbus configuration allows '" + elem.attrib["user"] + "' user to access the dbus socket.") for allowNode in elem.iterfind("allow"): diff --git a/tests/integration_tests/network_tests/network_common.py b/tests/integration_tests/network_tests/network_common.py index 63289a6..3432c88 100755 --- a/tests/integration_tests/network_tests/network_common.py +++ b/tests/integration_tests/network_tests/network_common.py @@ -16,7 +16,7 @@ # @author Jacek Pielaszkiewicz (j.pielaszkie@samsung.com) # -from sc_integration_tests.common import sc_test_utils +from vsm_integration_tests.common import vsm_test_utils import subprocess import string import sys @@ -94,7 +94,7 @@ def runCommand(cmd, blockDebug=False): rc=0 try: - out=sc_test_utils.launchProc(run_cmd) + out=vsm_test_utils.launchProc(run_cmd) except Exception: rc=1 diff --git a/tests/integration_tests/network_tests/network_tests.py b/tests/integration_tests/network_tests/network_tests.py index bd118a2..fb10195 100644 --- a/tests/integration_tests/network_tests/network_tests.py +++ b/tests/integration_tests/network_tests/network_tests.py @@ -21,7 +21,7 @@ @author: Jacek Pielaszkiewicz (j.pielaszkie@samsung.com) ''' import unittest -from sc_integration_tests.common import sc_test_utils +from vsm_integration_tests.common import vsm_test_utils from network_common import * class NetworkTestCase(unittest.TestCase): diff --git a/tests/integration_tests/sc_int_tests.py b/tests/integration_tests/vsm_int_tests.py similarity index 69% rename from tests/integration_tests/sc_int_tests.py rename to tests/integration_tests/vsm_int_tests.py index 60d1ed3..a2bdc1d 100644 --- a/tests/integration_tests/sc_int_tests.py +++ b/tests/integration_tests/vsm_int_tests.py @@ -1,13 +1,13 @@ #!/usr/bin/env python -'''@package: sc_integration_tests +'''@package: vsm_integration_tests @author: Lukasz Kostyra (l.kostyra@samsung.com) -Security-containers integration tests launcher. Launches all integration tests. +Vasum integration tests launcher. Launches all integration tests. ''' import unittest -from sc_integration_tests.network_tests import * +from vsm_integration_tests.network_tests import * -from sc_integration_tests.image_tests import * +from vsm_integration_tests.image_tests import * # add tests here... test_groups = [ diff --git a/tests/scripts/sc_all_tests.py b/tests/scripts/sc_all_tests.py deleted file mode 100755 index 99c67c9..0000000 --- a/tests/scripts/sc_all_tests.py +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env python - -import sc_launch_test -import sys - -# insert other test binaries to this array -_testCmdTable = ["security-containers-server-unit-tests"] - -for test in _testCmdTable: - sc_launch_test.launchTest([test] + sys.argv[1:]) diff --git a/tests/scripts/vsm_all_tests.py b/tests/scripts/vsm_all_tests.py new file mode 100755 index 0000000..67ef23b --- /dev/null +++ b/tests/scripts/vsm_all_tests.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python + +import vsm_launch_test +import sys + +# insert other test binaries to this array +_testCmdTable = ["vasum-server-unit-tests"] + +for test in _testCmdTable: + vsm_launch_test.launchTest([test] + sys.argv[1:]) diff --git a/tests/scripts/sc_launch_test.py b/tests/scripts/vsm_launch_test.py similarity index 97% rename from tests/scripts/sc_launch_test.py rename to tests/scripts/vsm_launch_test.py index 6bdbcfe..038ba30 100755 --- a/tests/scripts/sc_launch_test.py +++ b/tests/scripts/vsm_launch_test.py @@ -1,7 +1,7 @@ #!/usr/bin/env python from xml.dom import minidom -from sc_test_parser import Logger, Parser +from vsm_test_parser import Logger, Parser import subprocess import argparse import os @@ -72,7 +72,7 @@ _valgrindCmd = ["valgrind"] _gdbCmd = ["gdb", "--args"] def main(): - argparser = argparse.ArgumentParser(description="Test binary launcher for security-containers.") + argparser = argparse.ArgumentParser(description="Test binary launcher for vasum.") group = argparser.add_mutually_exclusive_group() group.add_argument('--valgrind', action='store_true', help='Launch test binary inside Valgrind (assuming it is installed).') diff --git a/tests/scripts/sc_test_parser.py b/tests/scripts/vsm_test_parser.py similarity index 96% rename from tests/scripts/sc_test_parser.py rename to tests/scripts/vsm_test_parser.py index b8ec404..41dd495 100644 --- a/tests/scripts/sc_test_parser.py +++ b/tests/scripts/vsm_test_parser.py @@ -77,7 +77,7 @@ class Logger(object): if not self.__failedTests: return - commandPrefix = "sc_launch_test.py " + bin + " -t " + commandPrefix = "vsm_launch_test.py " + bin + " -t " self.infoTitle("Some tests failed. Use following command(s) to launch them explicitly:") for test in self.__failedTests: self.error(self.__indentChar + commandPrefix + test) @@ -96,7 +96,7 @@ class Logger(object): self.error('Terminated by ' + siginfo) if signum in [5, 6, 8, 11]: self.error("\nUse following command to launch debugger:") - self.error(self.__indentChar + "sc_launch_test.py --gdb " + bin) + self.error(self.__indentChar + "vsm_launch_test.py --gdb " + bin) class Parser(object): diff --git a/tests/unit_tests/CMakeLists.txt b/tests/unit_tests/CMakeLists.txt index 7ab9e00..c0cc2a8 100644 --- a/tests/unit_tests/CMakeLists.txt +++ b/tests/unit_tests/CMakeLists.txt @@ -44,10 +44,10 @@ TARGET_LINK_LIBRARIES(${UT_SERVER_CODENAME} ${UT_SERVER_DEPS_LIBRARIES} ${Boost_ ## Subdirectories ############################################################## -SET(SC_TEST_CONFIG_INSTALL_DIR ${SC_DATA_INSTALL_DIR}/tests) -SET(SC_TEST_LXC_TEMPLATES_INSTALL_DIR ${SC_DATA_INSTALL_DIR}/lxc-templates/tests) -ADD_DEFINITIONS(-DSC_TEST_CONFIG_INSTALL_DIR="${SC_TEST_CONFIG_INSTALL_DIR}") -ADD_DEFINITIONS(-DSC_TEST_LXC_TEMPLATES_INSTALL_DIR="${SC_TEST_LXC_TEMPLATES_INSTALL_DIR}") +SET(VSM_TEST_CONFIG_INSTALL_DIR ${VSM_DATA_INSTALL_DIR}/tests) +SET(VSM_TEST_LXC_TEMPLATES_INSTALL_DIR ${VSM_DATA_INSTALL_DIR}/lxc-templates/tests) +ADD_DEFINITIONS(-DVSM_TEST_CONFIG_INSTALL_DIR="${VSM_TEST_CONFIG_INSTALL_DIR}") +ADD_DEFINITIONS(-DVSM_TEST_LXC_TEMPLATES_INSTALL_DIR="${VSM_TEST_LXC_TEMPLATES_INSTALL_DIR}") ADD_SUBDIRECTORY(dbus/configs) ADD_SUBDIRECTORY(server/configs) diff --git a/tests/unit_tests/client/configs/CMakeLists.txt b/tests/unit_tests/client/configs/CMakeLists.txt index 72ec622..c4bbda2 100644 --- a/tests/unit_tests/client/configs/CMakeLists.txt +++ b/tests/unit_tests/client/configs/CMakeLists.txt @@ -17,7 +17,7 @@ # @author Mateusz Malicki (m.malicki2@samsung.com) # -MESSAGE(STATUS "Installing configs for the Client Unit Tests to " ${SC_TEST_CONFIG_INSTALL_DIR}) +MESSAGE(STATUS "Installing configs for the Client Unit Tests to " ${VSM_TEST_CONFIG_INSTALL_DIR}) ## Generate #################################################################### CONFIGURE_FILE(ut-client/test-dbus-daemon.conf.in @@ -34,6 +34,6 @@ FILE(GLOB client_container_CONF_GEN ${CMAKE_BINARY_DIR}/ut-client/containers/*.c ## Install ##################################################################### INSTALL(FILES ${client_manager_CONF_GEN} - DESTINATION ${SC_TEST_CONFIG_INSTALL_DIR}/client/ut-client) + DESTINATION ${VSM_TEST_CONFIG_INSTALL_DIR}/client/ut-client) INSTALL(FILES ${client_container_CONF_GEN} - DESTINATION ${SC_TEST_CONFIG_INSTALL_DIR}/client/ut-client/containers) + DESTINATION ${VSM_TEST_CONFIG_INSTALL_DIR}/client/ut-client/containers) diff --git a/tests/unit_tests/client/configs/ut-client/containers/console1-dbus.conf.in b/tests/unit_tests/client/configs/ut-client/containers/console1-dbus.conf.in index 267a812..4bf616c 100644 --- a/tests/unit_tests/client/configs/ut-client/containers/console1-dbus.conf.in +++ b/tests/unit_tests/client/configs/ut-client/containers/console1-dbus.conf.in @@ -1,7 +1,7 @@ { "name" : "ut-containers-manager-console1-dbus", "lxcTemplate" : "minimal-dbus.sh", - "initWithArgs" : ["/bin/sh", "-c", "trap exit SIGTERM; /usr/bin/dbus-daemon --config-file=@SC_TEST_CONFIG_INSTALL_DIR@/server/ut-containers-manager/ut-dbus.conf --fork; read"], + "initWithArgs" : ["/bin/sh", "-c", "trap exit SIGTERM; /usr/bin/dbus-daemon --config-file=@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-containers-manager/ut-dbus.conf --fork; read"], "ipv4Gateway" : "", "ipv4" : "", "privilege" : 20, diff --git a/tests/unit_tests/client/configs/ut-client/containers/console2-dbus.conf.in b/tests/unit_tests/client/configs/ut-client/containers/console2-dbus.conf.in index f050525..4ca2215 100644 --- a/tests/unit_tests/client/configs/ut-client/containers/console2-dbus.conf.in +++ b/tests/unit_tests/client/configs/ut-client/containers/console2-dbus.conf.in @@ -1,7 +1,7 @@ { "name" : "ut-containers-manager-console2-dbus", "lxcTemplate" : "minimal-dbus.sh", - "initWithArgs" : ["/bin/sh", "-c", "trap exit SIGTERM; /usr/bin/dbus-daemon --config-file=@SC_TEST_CONFIG_INSTALL_DIR@/server/ut-containers-manager/ut-dbus.conf --fork; read"], + "initWithArgs" : ["/bin/sh", "-c", "trap exit SIGTERM; /usr/bin/dbus-daemon --config-file=@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-containers-manager/ut-dbus.conf --fork; read"], "ipv4Gateway" : "", "ipv4" : "", "privilege" : 20, diff --git a/tests/unit_tests/client/configs/ut-client/containers/console3-dbus.conf.in b/tests/unit_tests/client/configs/ut-client/containers/console3-dbus.conf.in index b78ac71..f3d8385 100644 --- a/tests/unit_tests/client/configs/ut-client/containers/console3-dbus.conf.in +++ b/tests/unit_tests/client/configs/ut-client/containers/console3-dbus.conf.in @@ -1,7 +1,7 @@ { "name" : "ut-containers-manager-console3-dbus", "lxcTemplate" : "minimal-dbus.sh", - "initWithArgs" : ["/bin/sh", "-c", "trap exit SIGTERM; /usr/bin/dbus-daemon --config-file=@SC_TEST_CONFIG_INSTALL_DIR@/server/ut-containers-manager/ut-dbus.conf --fork; read"], + "initWithArgs" : ["/bin/sh", "-c", "trap exit SIGTERM; /usr/bin/dbus-daemon --config-file=@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-containers-manager/ut-dbus.conf --fork; read"], "ipv4Gateway" : "", "ipv4" : "", "privilege" : 20, 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 f65c013..33a8a0d 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 @@ -9,7 +9,7 @@ "containerTemplatePath" : "", "containerNewConfigPrefix" : "", "runMountPointPrefix" : "", - "lxcTemplatePrefix" : "@SC_TEST_LXC_TEMPLATES_INSTALL_DIR@", + "lxcTemplatePrefix" : "@VSM_TEST_LXC_TEMPLATES_INSTALL_DIR@", "inputConfig" : {"enabled" : false, "device" : "/dev/doesnotexist", "code" : 139, diff --git a/tests/unit_tests/client/ut-client.cpp b/tests/unit_tests/client/ut-client.cpp index 1240e51..ec38228 100644 --- a/tests/unit_tests/client/ut-client.cpp +++ b/tests/unit_tests/client/ut-client.cpp @@ -25,7 +25,7 @@ #include #include "ut.hpp" -#include +#include #include "utils/latch.hpp" #include "utils/scoped-dir.hpp" @@ -40,13 +40,13 @@ #include #include -using namespace security_containers; -using namespace security_containers::utils; +using namespace vasum; +using namespace vasum::utils; namespace { const std::string TEST_DBUS_CONFIG_PATH = - SC_TEST_CONFIG_INSTALL_DIR "/client/ut-client/test-dbus-daemon.conf"; + VSM_TEST_CONFIG_INSTALL_DIR "/client/ut-client/test-dbus-daemon.conf"; const std::string CONTAINERS_PATH = "/tmp/ut-containers"; // the same as in daemon.conf struct Loop { diff --git a/tests/unit_tests/dbus/configs/CMakeLists.txt b/tests/unit_tests/dbus/configs/CMakeLists.txt index 99daa2f..69c2910 100644 --- a/tests/unit_tests/dbus/configs/CMakeLists.txt +++ b/tests/unit_tests/dbus/configs/CMakeLists.txt @@ -17,10 +17,10 @@ # @author Lukasz Pawelczyk (l.pawelczyk@partner.samsung.com) # -MESSAGE(STATUS "Installing configs for the DBus Unit Tests to " ${SC_TEST_CONFIG_INSTALL_DIR}) +MESSAGE(STATUS "Installing configs for the DBus Unit Tests to " ${VSM_TEST_CONFIG_INSTALL_DIR}) FILE(GLOB dbus_CONF ut-connection/*.conf) ## Install ##################################################################### INSTALL(FILES ${dbus_CONF} - DESTINATION ${SC_TEST_CONFIG_INSTALL_DIR}/dbus/ut-connection) + DESTINATION ${VSM_TEST_CONFIG_INSTALL_DIR}/dbus/ut-connection) diff --git a/tests/unit_tests/dbus/test-client.cpp b/tests/unit_tests/dbus/test-client.cpp index 59b6adb..f1a9c25 100644 --- a/tests/unit_tests/dbus/test-client.cpp +++ b/tests/unit_tests/dbus/test-client.cpp @@ -30,7 +30,7 @@ #include "dbus/connection.hpp" -namespace security_containers { +namespace vasum { DbusTestClient::DbusTestClient() @@ -100,4 +100,4 @@ void DbusTestClient::throwException(int arg) } -} // namespace security_containers +} // namespace vasum diff --git a/tests/unit_tests/dbus/test-client.hpp b/tests/unit_tests/dbus/test-client.hpp index 5612283..ff7dcee 100644 --- a/tests/unit_tests/dbus/test-client.hpp +++ b/tests/unit_tests/dbus/test-client.hpp @@ -31,7 +31,7 @@ #include -namespace security_containers { +namespace vasum { /** @@ -61,7 +61,7 @@ private: }; -} // namespace security_containers +} // namespace vasum #endif // UNIT_TESTS_DBUS_TEST_CLIENT_HPP diff --git a/tests/unit_tests/dbus/test-common.hpp b/tests/unit_tests/dbus/test-common.hpp index 85dad51..5e93699 100644 --- a/tests/unit_tests/dbus/test-common.hpp +++ b/tests/unit_tests/dbus/test-common.hpp @@ -28,7 +28,7 @@ #include -namespace security_containers { +namespace vasum { const std::string DBUS_SOCKET_FILE = "/tmp/container_socket"; @@ -60,7 +60,7 @@ const std::string TESTAPI_DEFINITION = ""; -} // namespace security_containers +} // namespace vasum #endif // UNIT_TESTS_DBUS_TEST_COMMON_HPP diff --git a/tests/unit_tests/dbus/test-server.cpp b/tests/unit_tests/dbus/test-server.cpp index bdbda8b..c5f6ab8 100644 --- a/tests/unit_tests/dbus/test-server.cpp +++ b/tests/unit_tests/dbus/test-server.cpp @@ -32,7 +32,7 @@ #include "logger/logger.hpp" -namespace security_containers { +namespace vasum { DbusTestServer::DbusTestServer() @@ -147,4 +147,4 @@ void DbusTestServer::onMessageCall(const std::string& objectPath, } -} // namespace security_containers +} // namespace vasum diff --git a/tests/unit_tests/dbus/test-server.hpp b/tests/unit_tests/dbus/test-server.hpp index 8e2aa7f..cf1ae85 100644 --- a/tests/unit_tests/dbus/test-server.hpp +++ b/tests/unit_tests/dbus/test-server.hpp @@ -33,7 +33,7 @@ #include -namespace security_containers { +namespace vasum { /** @@ -77,7 +77,7 @@ private: }; -} // namespace security_containers +} // namespace vasum #endif // UNIT_TESTS_DBUS_TEST_SERVER_HPP diff --git a/tests/unit_tests/dbus/ut-connection.cpp b/tests/unit_tests/dbus/ut-connection.cpp index 1352f85..fa8a620 100644 --- a/tests/unit_tests/dbus/ut-connection.cpp +++ b/tests/unit_tests/dbus/ut-connection.cpp @@ -45,8 +45,8 @@ BOOST_AUTO_TEST_SUITE(DbusSuite) -using namespace security_containers; -using namespace security_containers::utils; +using namespace vasum; +using namespace vasum::utils; using namespace dbus; namespace { @@ -54,7 +54,7 @@ namespace { const char* DBUS_DAEMON_PROC = "/usr/bin/dbus-daemon"; const char* const DBUS_DAEMON_ARGS[] = { DBUS_DAEMON_PROC, - "--config-file=" SC_TEST_CONFIG_INSTALL_DIR "/dbus/ut-connection/ut-dbus.conf", + "--config-file=" VSM_TEST_CONFIG_INSTALL_DIR "/dbus/ut-connection/ut-dbus.conf", "--nofork", NULL }; diff --git a/tests/unit_tests/ipc/ut-ipc.cpp b/tests/unit_tests/ipc/ut-ipc.cpp index 679f3df..c671db6 100644 --- a/tests/unit_tests/ipc/ut-ipc.cpp +++ b/tests/unit_tests/ipc/ut-ipc.cpp @@ -45,8 +45,8 @@ #include #include -using namespace security_containers; -using namespace security_containers::ipc; +using namespace vasum; +using namespace vasum::ipc; namespace fs = boost::filesystem; namespace { diff --git a/tests/unit_tests/lxc/templates/CMakeLists.txt b/tests/unit_tests/lxc/templates/CMakeLists.txt index 139cf49..43db4d9 100644 --- a/tests/unit_tests/lxc/templates/CMakeLists.txt +++ b/tests/unit_tests/lxc/templates/CMakeLists.txt @@ -20,4 +20,4 @@ FILE(GLOB LXC_TEMPLATES *.sh) INSTALL(PROGRAMS ${LXC_TEMPLATES} - DESTINATION ${SC_TEST_LXC_TEMPLATES_INSTALL_DIR}) + DESTINATION ${VSM_TEST_LXC_TEMPLATES_INSTALL_DIR}) diff --git a/tests/unit_tests/lxc/ut-zone.cpp b/tests/unit_tests/lxc/ut-zone.cpp index bf8779d..b80e261 100644 --- a/tests/unit_tests/lxc/ut-zone.cpp +++ b/tests/unit_tests/lxc/ut-zone.cpp @@ -36,12 +36,12 @@ namespace { -using namespace security_containers; -using namespace security_containers::lxc; +using namespace vasum; +using namespace vasum::lxc; const std::string LXC_PATH = "/tmp/ut-lxc/"; const std::string ZONE_NAME = "ut-zone"; -const std::string TEMPLATE = SC_TEST_LXC_TEMPLATES_INSTALL_DIR "/minimal.sh"; +const std::string TEMPLATE = VSM_TEST_LXC_TEMPLATES_INSTALL_DIR "/minimal.sh"; const char* TEMPLATE_ARGS[] = {NULL}; struct Fixture { diff --git a/tests/unit_tests/server/configs/CMakeLists.txt b/tests/unit_tests/server/configs/CMakeLists.txt index fc73fd4..9979c1b 100644 --- a/tests/unit_tests/server/configs/CMakeLists.txt +++ b/tests/unit_tests/server/configs/CMakeLists.txt @@ -17,7 +17,7 @@ # @author Jan Olszak (j.olszak@samsung.com) # -MESSAGE(STATUS "Installing configs for the Server Unit Tests to " ${SC_TEST_CONFIG_INSTALL_DIR}) +MESSAGE(STATUS "Installing configs for the Server Unit Tests to " ${VSM_TEST_CONFIG_INSTALL_DIR}) FILE(GLOB server_manager_CONF ut-server/*.conf) FILE(GLOB server_container_CONF ut-server/containers/*.conf) @@ -73,35 +73,35 @@ FILE(GLOB manager_container_TEMPLATE_GEN ${CMAKE_BINARY_DIR}/ut-containers-manag ## Install ##################################################################### INSTALL(FILES ${server_manager_CONF} - DESTINATION ${SC_TEST_CONFIG_INSTALL_DIR}/server/ut-server) + DESTINATION ${VSM_TEST_CONFIG_INSTALL_DIR}/server/ut-server) INSTALL(FILES ${server_manager_CONF_GEN} - DESTINATION ${SC_TEST_CONFIG_INSTALL_DIR}/server/ut-server) + DESTINATION ${VSM_TEST_CONFIG_INSTALL_DIR}/server/ut-server) INSTALL(FILES ${server_container_CONF} - DESTINATION ${SC_TEST_CONFIG_INSTALL_DIR}/server/ut-server/containers) + DESTINATION ${VSM_TEST_CONFIG_INSTALL_DIR}/server/ut-server/containers) INSTALL(FILES ${manager_manager_CONF} - DESTINATION ${SC_TEST_CONFIG_INSTALL_DIR}/server/ut-containers-manager) + DESTINATION ${VSM_TEST_CONFIG_INSTALL_DIR}/server/ut-containers-manager) INSTALL(FILES ${manager_manager_CONF_GEN} - DESTINATION ${SC_TEST_CONFIG_INSTALL_DIR}/server/ut-containers-manager) + DESTINATION ${VSM_TEST_CONFIG_INSTALL_DIR}/server/ut-containers-manager) INSTALL(FILES ${manager_container_CONF} - DESTINATION ${SC_TEST_CONFIG_INSTALL_DIR}/server/ut-containers-manager/containers) + DESTINATION ${VSM_TEST_CONFIG_INSTALL_DIR}/server/ut-containers-manager/containers) INSTALL(FILES ${manager_container_CONF_GEN} - DESTINATION ${SC_TEST_CONFIG_INSTALL_DIR}/server/ut-containers-manager/containers) + DESTINATION ${VSM_TEST_CONFIG_INSTALL_DIR}/server/ut-containers-manager/containers) INSTALL(FILES ${manager_container_TEMPLATE_GEN} - DESTINATION ${SC_TEST_CONFIG_INSTALL_DIR}/server/ut-containers-manager/templates) + DESTINATION ${VSM_TEST_CONFIG_INSTALL_DIR}/server/ut-containers-manager/templates) INSTALL(FILES ${container_CONF} - DESTINATION ${SC_TEST_CONFIG_INSTALL_DIR}/server/ut-container) + DESTINATION ${VSM_TEST_CONFIG_INSTALL_DIR}/server/ut-container) INSTALL(FILES ${container_container_CONF} - DESTINATION ${SC_TEST_CONFIG_INSTALL_DIR}/server/ut-container/containers) + DESTINATION ${VSM_TEST_CONFIG_INSTALL_DIR}/server/ut-container/containers) INSTALL(FILES ${container_container_CONF_GEN} - DESTINATION ${SC_TEST_CONFIG_INSTALL_DIR}/server/ut-container/containers) + DESTINATION ${VSM_TEST_CONFIG_INSTALL_DIR}/server/ut-container/containers) INSTALL(FILES ${admin_container_CONF} - DESTINATION ${SC_TEST_CONFIG_INSTALL_DIR}/server/ut-container-admin/containers) + DESTINATION ${VSM_TEST_CONFIG_INSTALL_DIR}/server/ut-container-admin/containers) INSTALL(FILES ${connection_CONF} - DESTINATION ${SC_TEST_CONFIG_INSTALL_DIR}/server/ut-container-connection) + DESTINATION ${VSM_TEST_CONFIG_INSTALL_DIR}/server/ut-container-connection) INSTALL(FILES dbus-1/system.d/org.tizen.containers.tests.conf DESTINATION ${SYSCONF_INSTALL_DIR}/dbus-1/system.d/) diff --git a/tests/unit_tests/server/configs/ut-container/containers/test-dbus.conf.in b/tests/unit_tests/server/configs/ut-container/containers/test-dbus.conf.in index ed9a976..1992140 100644 --- a/tests/unit_tests/server/configs/ut-container/containers/test-dbus.conf.in +++ b/tests/unit_tests/server/configs/ut-container/containers/test-dbus.conf.in @@ -1,7 +1,7 @@ { "name" : "ut-container-test-dbus", "lxcTemplate" : "minimal-dbus.sh", - "initWithArgs" : ["/bin/sh", "-c", "trap exit SIGTERM; /usr/bin/dbus-daemon --config-file=@SC_TEST_CONFIG_INSTALL_DIR@/server/ut-container/ut-dbus.conf --fork; read"], + "initWithArgs" : ["/bin/sh", "-c", "trap exit SIGTERM; /usr/bin/dbus-daemon --config-file=@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-container/ut-dbus.conf --fork; read"], "ipv4Gateway" : "", "ipv4" : "", "privilege" : 10, diff --git a/tests/unit_tests/server/configs/ut-containers-manager/buggy-daemon.conf.in b/tests/unit_tests/server/configs/ut-containers-manager/buggy-daemon.conf.in index c848165..c3ec37b 100644 --- a/tests/unit_tests/server/configs/ut-containers-manager/buggy-daemon.conf.in +++ b/tests/unit_tests/server/configs/ut-containers-manager/buggy-daemon.conf.in @@ -6,8 +6,8 @@ "containersPath" : "/tmp/ut-containers", "containerImagePath" : "", "containerTemplatePath" : "templates", - "containerNewConfigPrefix" : "@SC_TEST_CONFIG_INSTALL_DIR@/server/ut-containers-manager/", - "lxcTemplatePrefix" : "@SC_TEST_LXC_TEMPLATES_INSTALL_DIR@", + "containerNewConfigPrefix" : "@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-containers-manager/", + "lxcTemplatePrefix" : "@VSM_TEST_LXC_TEMPLATES_INSTALL_DIR@", "inputConfig" : {"enabled" : false, "device" : "/dev/doesnotexist", "code" : 139, diff --git a/tests/unit_tests/server/configs/ut-containers-manager/buggy-default-daemon.conf.in b/tests/unit_tests/server/configs/ut-containers-manager/buggy-default-daemon.conf.in index 590ea73..6390378 100644 --- a/tests/unit_tests/server/configs/ut-containers-manager/buggy-default-daemon.conf.in +++ b/tests/unit_tests/server/configs/ut-containers-manager/buggy-default-daemon.conf.in @@ -6,8 +6,8 @@ "containersPath" : "/tmp/ut-containers", "containerImagePath" : "", "containerTemplatePath" : "templates", - "containerNewConfigPrefix" : "@SC_TEST_CONFIG_INSTALL_DIR@/server/ut-containers-manager/", - "lxcTemplatePrefix" : "@SC_TEST_LXC_TEMPLATES_INSTALL_DIR@", + "containerNewConfigPrefix" : "@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-containers-manager/", + "lxcTemplatePrefix" : "@VSM_TEST_LXC_TEMPLATES_INSTALL_DIR@", "inputConfig" : {"enabled" : false, "device" : "/dev/doesnotexist", "code" : 139, diff --git a/tests/unit_tests/server/configs/ut-containers-manager/buggy-foreground-daemon.conf.in b/tests/unit_tests/server/configs/ut-containers-manager/buggy-foreground-daemon.conf.in index cb3eb30..fb1490c 100644 --- a/tests/unit_tests/server/configs/ut-containers-manager/buggy-foreground-daemon.conf.in +++ b/tests/unit_tests/server/configs/ut-containers-manager/buggy-foreground-daemon.conf.in @@ -6,8 +6,8 @@ "containersPath" : "/tmp/ut-containers", "containerImagePath" : "", "containerTemplatePath" : "templates", - "containerNewConfigPrefix" : "@SC_TEST_CONFIG_INSTALL_DIR@/server/ut-containers-manager/", - "lxcTemplatePrefix" : "@SC_TEST_LXC_TEMPLATES_INSTALL_DIR@", + "containerNewConfigPrefix" : "@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-containers-manager/", + "lxcTemplatePrefix" : "@VSM_TEST_LXC_TEMPLATES_INSTALL_DIR@", "inputConfig" : {"enabled" : false, "device" : "/dev/doesnotexist", "code" : 139, diff --git a/tests/unit_tests/server/configs/ut-containers-manager/containers/console1-dbus.conf.in b/tests/unit_tests/server/configs/ut-containers-manager/containers/console1-dbus.conf.in index 267a812..4bf616c 100644 --- a/tests/unit_tests/server/configs/ut-containers-manager/containers/console1-dbus.conf.in +++ b/tests/unit_tests/server/configs/ut-containers-manager/containers/console1-dbus.conf.in @@ -1,7 +1,7 @@ { "name" : "ut-containers-manager-console1-dbus", "lxcTemplate" : "minimal-dbus.sh", - "initWithArgs" : ["/bin/sh", "-c", "trap exit SIGTERM; /usr/bin/dbus-daemon --config-file=@SC_TEST_CONFIG_INSTALL_DIR@/server/ut-containers-manager/ut-dbus.conf --fork; read"], + "initWithArgs" : ["/bin/sh", "-c", "trap exit SIGTERM; /usr/bin/dbus-daemon --config-file=@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-containers-manager/ut-dbus.conf --fork; read"], "ipv4Gateway" : "", "ipv4" : "", "privilege" : 20, diff --git a/tests/unit_tests/server/configs/ut-containers-manager/containers/console2-dbus.conf.in b/tests/unit_tests/server/configs/ut-containers-manager/containers/console2-dbus.conf.in index f050525..4ca2215 100644 --- a/tests/unit_tests/server/configs/ut-containers-manager/containers/console2-dbus.conf.in +++ b/tests/unit_tests/server/configs/ut-containers-manager/containers/console2-dbus.conf.in @@ -1,7 +1,7 @@ { "name" : "ut-containers-manager-console2-dbus", "lxcTemplate" : "minimal-dbus.sh", - "initWithArgs" : ["/bin/sh", "-c", "trap exit SIGTERM; /usr/bin/dbus-daemon --config-file=@SC_TEST_CONFIG_INSTALL_DIR@/server/ut-containers-manager/ut-dbus.conf --fork; read"], + "initWithArgs" : ["/bin/sh", "-c", "trap exit SIGTERM; /usr/bin/dbus-daemon --config-file=@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-containers-manager/ut-dbus.conf --fork; read"], "ipv4Gateway" : "", "ipv4" : "", "privilege" : 20, diff --git a/tests/unit_tests/server/configs/ut-containers-manager/containers/console3-dbus.conf.in b/tests/unit_tests/server/configs/ut-containers-manager/containers/console3-dbus.conf.in index b78ac71..f3d8385 100644 --- a/tests/unit_tests/server/configs/ut-containers-manager/containers/console3-dbus.conf.in +++ b/tests/unit_tests/server/configs/ut-containers-manager/containers/console3-dbus.conf.in @@ -1,7 +1,7 @@ { "name" : "ut-containers-manager-console3-dbus", "lxcTemplate" : "minimal-dbus.sh", - "initWithArgs" : ["/bin/sh", "-c", "trap exit SIGTERM; /usr/bin/dbus-daemon --config-file=@SC_TEST_CONFIG_INSTALL_DIR@/server/ut-containers-manager/ut-dbus.conf --fork; read"], + "initWithArgs" : ["/bin/sh", "-c", "trap exit SIGTERM; /usr/bin/dbus-daemon --config-file=@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-containers-manager/ut-dbus.conf --fork; read"], "ipv4Gateway" : "", "ipv4" : "", "privilege" : 20, diff --git a/tests/unit_tests/server/configs/ut-containers-manager/empty-dbus-daemon.conf.in b/tests/unit_tests/server/configs/ut-containers-manager/empty-dbus-daemon.conf.in index 82f6c0e..97e70d8 100644 --- a/tests/unit_tests/server/configs/ut-containers-manager/empty-dbus-daemon.conf.in +++ b/tests/unit_tests/server/configs/ut-containers-manager/empty-dbus-daemon.conf.in @@ -5,9 +5,9 @@ "containersPath" : "/tmp/ut-containers", "containerImagePath" : "", "containerTemplatePath" : "templates", - "containerNewConfigPrefix" : "@SC_TEST_CONFIG_INSTALL_DIR@/server/ut-containers-manager/", + "containerNewConfigPrefix" : "@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-containers-manager/", "runMountPointPrefix" : "", - "lxcTemplatePrefix" : "@SC_TEST_LXC_TEMPLATES_INSTALL_DIR@", + "lxcTemplatePrefix" : "@VSM_TEST_LXC_TEMPLATES_INSTALL_DIR@", "inputConfig" : {"enabled" : false, "device" : "/dev/doesnotexist", "code" : 139, diff --git a/tests/unit_tests/server/configs/ut-containers-manager/templates/template.conf.in b/tests/unit_tests/server/configs/ut-containers-manager/templates/template.conf.in index 7c35446..8e2292a 100644 --- a/tests/unit_tests/server/configs/ut-containers-manager/templates/template.conf.in +++ b/tests/unit_tests/server/configs/ut-containers-manager/templates/template.conf.in @@ -1,7 +1,7 @@ { "name" : "~NAME~", "lxcTemplate" : "minimal-dbus.sh", - "initWithArgs" : ["/bin/sh", "-c", "trap exit SIGTERM; /usr/bin/dbus-daemon --config-file=@SC_TEST_CONFIG_INSTALL_DIR@/server/ut-containers-manager/ut-dbus.conf --fork; read"], + "initWithArgs" : ["/bin/sh", "-c", "trap exit SIGTERM; /usr/bin/dbus-daemon --config-file=@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-containers-manager/ut-dbus.conf --fork; read"], "ipv4Gateway" : "", "ipv4" : "", "privilege" : 20, diff --git a/tests/unit_tests/server/configs/ut-containers-manager/test-daemon.conf.in b/tests/unit_tests/server/configs/ut-containers-manager/test-daemon.conf.in index 359066d..25890e6 100644 --- a/tests/unit_tests/server/configs/ut-containers-manager/test-daemon.conf.in +++ b/tests/unit_tests/server/configs/ut-containers-manager/test-daemon.conf.in @@ -6,8 +6,8 @@ "containersPath" : "/tmp/ut-containers", "containerImagePath" : "", "containerTemplatePath" : "templates", - "containerNewConfigPrefix" : "@SC_TEST_CONFIG_INSTALL_DIR@/server/ut-containers-manager/", - "lxcTemplatePrefix" : "@SC_TEST_LXC_TEMPLATES_INSTALL_DIR@", + "containerNewConfigPrefix" : "@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-containers-manager/", + "lxcTemplatePrefix" : "@VSM_TEST_LXC_TEMPLATES_INSTALL_DIR@", "inputConfig" : {"enabled" : false, "device" : "/dev/doesnotexist", "code" : 139, diff --git a/tests/unit_tests/server/configs/ut-containers-manager/test-dbus-daemon.conf.in b/tests/unit_tests/server/configs/ut-containers-manager/test-dbus-daemon.conf.in index 4421d62..19a9f60 100644 --- a/tests/unit_tests/server/configs/ut-containers-manager/test-dbus-daemon.conf.in +++ b/tests/unit_tests/server/configs/ut-containers-manager/test-dbus-daemon.conf.in @@ -7,9 +7,9 @@ "containersPath" : "/tmp/ut-containers", "containerImagePath" : "", "containerTemplatePath" : "templates", - "containerNewConfigPrefix" : "@SC_TEST_CONFIG_INSTALL_DIR@/server/ut-containers-manager/", + "containerNewConfigPrefix" : "@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-containers-manager/", "runMountPointPrefix" : "", - "lxcTemplatePrefix" : "@SC_TEST_LXC_TEMPLATES_INSTALL_DIR@", + "lxcTemplatePrefix" : "@VSM_TEST_LXC_TEMPLATES_INSTALL_DIR@", "inputConfig" : {"enabled" : false, "device" : "/dev/doesnotexist", "code" : 139, 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 3b7702f..55479b7 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 @@ -7,7 +7,7 @@ "runMountPointPrefix" : "", "foregroundId" : "ut-server-container1", "defaultId" : "ut-server-container1", - "lxcTemplatePrefix" : "@SC_TEST_LXC_TEMPLATES_INSTALL_DIR@", + "lxcTemplatePrefix" : "@VSM_TEST_LXC_TEMPLATES_INSTALL_DIR@", "inputConfig" : {"enabled" : false, "device" : "/dev/doesnotexist", "code" : 139, 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 d6d7e2a..57fb7a1 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 @@ -7,7 +7,7 @@ "runMountPointPrefix" : "", "foregroundId" : "ut-server-container1", "defaultId" : "ut-server-container1", - "lxcTemplatePrefix" : "@SC_TEST_LXC_TEMPLATES_INSTALL_DIR@", + "lxcTemplatePrefix" : "@VSM_TEST_LXC_TEMPLATES_INSTALL_DIR@", "inputConfig" : {"enabled" : false, "device" : "gpio-keys.4", "code" : 139, diff --git a/tests/unit_tests/server/test-dbus-definitions.hpp b/tests/unit_tests/server/test-dbus-definitions.hpp index ddad4ac..9099c11 100644 --- a/tests/unit_tests/server/test-dbus-definitions.hpp +++ b/tests/unit_tests/server/test-dbus-definitions.hpp @@ -28,7 +28,7 @@ #include -namespace security_containers { +namespace vasum { namespace testapi { @@ -49,7 +49,7 @@ const std::string DEFINITION = } // namespace testapi -} // namespace security_containers +} // namespace vasum #endif // UNIT_TESTS_SERVER_TEST_DBUS_DEFINITIONS_HPP diff --git a/tests/unit_tests/server/ut-container-admin.cpp b/tests/unit_tests/server/ut-container-admin.cpp index ae00abf..fb97d6e 100644 --- a/tests/unit_tests/server/ut-container-admin.cpp +++ b/tests/unit_tests/server/ut-container-admin.cpp @@ -33,16 +33,16 @@ #include "utils/scoped-dir.hpp" #include "config/manager.hpp" -using namespace security_containers; +using namespace vasum; namespace { -const std::string TEST_CONFIG_PATH = SC_TEST_CONFIG_INSTALL_DIR "/server/ut-container-admin/containers/test.conf"; -const std::string TEST_NO_SHUTDOWN_CONFIG_PATH = SC_TEST_CONFIG_INSTALL_DIR "/server/ut-container-admin/containers/test-no-shutdown.conf"; -const std::string BUGGY_CONFIG_PATH = SC_TEST_CONFIG_INSTALL_DIR "/server/ut-container-admin/containers/buggy.conf"; -const std::string MISSING_CONFIG_PATH = SC_TEST_CONFIG_INSTALL_DIR "/server/ut-container-admin/containers/missing.conf"; +const std::string TEST_CONFIG_PATH = VSM_TEST_CONFIG_INSTALL_DIR "/server/ut-container-admin/containers/test.conf"; +const std::string TEST_NO_SHUTDOWN_CONFIG_PATH = VSM_TEST_CONFIG_INSTALL_DIR "/server/ut-container-admin/containers/test-no-shutdown.conf"; +const std::string BUGGY_CONFIG_PATH = VSM_TEST_CONFIG_INSTALL_DIR "/server/ut-container-admin/containers/buggy.conf"; +const std::string MISSING_CONFIG_PATH = VSM_TEST_CONFIG_INSTALL_DIR "/server/ut-container-admin/containers/missing.conf"; const std::string CONTAINERS_PATH = "/tmp/ut-containers"; -const std::string LXC_TEMPLATES_PATH = SC_TEST_LXC_TEMPLATES_INSTALL_DIR; +const std::string LXC_TEMPLATES_PATH = VSM_TEST_LXC_TEMPLATES_INSTALL_DIR; struct Fixture { utils::ScopedGlibLoop mLoop; diff --git a/tests/unit_tests/server/ut-container-connection.cpp b/tests/unit_tests/server/ut-container-connection.cpp index 1a2d153..9a65aab 100644 --- a/tests/unit_tests/server/ut-container-connection.cpp +++ b/tests/unit_tests/server/ut-container-connection.cpp @@ -43,8 +43,8 @@ BOOST_AUTO_TEST_SUITE(ContainerConnectionSuite) -using namespace security_containers; -using namespace security_containers::utils; +using namespace vasum; +using namespace vasum::utils; using namespace dbus; namespace { @@ -52,7 +52,7 @@ namespace { const char* DBUS_DAEMON_PROC = "/usr/bin/dbus-daemon"; const char* const DBUS_DAEMON_ARGS[] = { DBUS_DAEMON_PROC, - "--config-file=" SC_TEST_CONFIG_INSTALL_DIR "/server/ut-container-connection/ut-dbus.conf", + "--config-file=" VSM_TEST_CONFIG_INSTALL_DIR "/server/ut-container-connection/ut-dbus.conf", "--nofork", NULL }; diff --git a/tests/unit_tests/server/ut-container.cpp b/tests/unit_tests/server/ut-container.cpp index 3cb676e..4c4c305 100644 --- a/tests/unit_tests/server/ut-container.cpp +++ b/tests/unit_tests/server/ut-container.cpp @@ -40,17 +40,17 @@ #include -using namespace security_containers; +using namespace vasum; using namespace config; namespace { -const std::string TEST_CONFIG_PATH = SC_TEST_CONFIG_INSTALL_DIR "/server/ut-container/containers/test.conf"; -const std::string TEST_DBUS_CONFIG_PATH = SC_TEST_CONFIG_INSTALL_DIR "/server/ut-container/containers/test-dbus.conf"; -const std::string BUGGY_CONFIG_PATH = SC_TEST_CONFIG_INSTALL_DIR "/server/ut-container/containers/buggy.conf"; +const std::string TEST_CONFIG_PATH = VSM_TEST_CONFIG_INSTALL_DIR "/server/ut-container/containers/test.conf"; +const std::string TEST_DBUS_CONFIG_PATH = VSM_TEST_CONFIG_INSTALL_DIR "/server/ut-container/containers/test-dbus.conf"; +const std::string BUGGY_CONFIG_PATH = VSM_TEST_CONFIG_INSTALL_DIR "/server/ut-container/containers/buggy.conf"; const std::string MISSING_CONFIG_PATH = "/this/is/a/missing/file/path/config.conf"; const std::string CONTAINERS_PATH = "/tmp/ut-containers"; -const std::string LXC_TEMPLATES_PATH = SC_TEST_LXC_TEMPLATES_INSTALL_DIR; +const std::string LXC_TEMPLATES_PATH = VSM_TEST_LXC_TEMPLATES_INSTALL_DIR; struct Fixture { utils::ScopedGlibLoop mLoop; diff --git a/tests/unit_tests/server/ut-containers-manager.cpp b/tests/unit_tests/server/ut-containers-manager.cpp index a55400a..4b45186 100644 --- a/tests/unit_tests/server/ut-containers-manager.cpp +++ b/tests/unit_tests/server/ut-containers-manager.cpp @@ -57,20 +57,20 @@ #include #include -using namespace security_containers; +using namespace vasum; using namespace config; -using namespace security_containers::utils; +using namespace vasum::utils; using namespace dbus; namespace { -const std::string TEST_CONFIG_PATH = SC_TEST_CONFIG_INSTALL_DIR "/server/ut-containers-manager/test-daemon.conf"; -const std::string TEST_DBUS_CONFIG_PATH = SC_TEST_CONFIG_INSTALL_DIR "/server/ut-containers-manager/test-dbus-daemon.conf"; -const std::string EMPTY_DBUS_CONFIG_PATH = SC_TEST_CONFIG_INSTALL_DIR "/server/ut-containers-manager/empty-dbus-daemon.conf"; -const std::string BUGGY_CONFIG_PATH = SC_TEST_CONFIG_INSTALL_DIR "/server/ut-containers-manager/buggy-daemon.conf"; -const std::string BUGGY_FOREGROUND_CONFIG_PATH = SC_TEST_CONFIG_INSTALL_DIR "/server/ut-containers-manager/buggy-foreground-daemon.conf"; -const std::string BUGGY_DEFAULTID_CONFIG_PATH = SC_TEST_CONFIG_INSTALL_DIR "/server/ut-containers-manager/buggy-default-daemon.conf"; -const std::string TEST_CONTAINER_CONF_PATH = SC_TEST_CONFIG_INSTALL_DIR "/server/ut-containers-manager/containers/"; +const std::string TEST_CONFIG_PATH = VSM_TEST_CONFIG_INSTALL_DIR "/server/ut-containers-manager/test-daemon.conf"; +const std::string TEST_DBUS_CONFIG_PATH = VSM_TEST_CONFIG_INSTALL_DIR "/server/ut-containers-manager/test-dbus-daemon.conf"; +const std::string EMPTY_DBUS_CONFIG_PATH = VSM_TEST_CONFIG_INSTALL_DIR "/server/ut-containers-manager/empty-dbus-daemon.conf"; +const std::string BUGGY_CONFIG_PATH = VSM_TEST_CONFIG_INSTALL_DIR "/server/ut-containers-manager/buggy-daemon.conf"; +const std::string BUGGY_FOREGROUND_CONFIG_PATH = VSM_TEST_CONFIG_INSTALL_DIR "/server/ut-containers-manager/buggy-foreground-daemon.conf"; +const std::string BUGGY_DEFAULTID_CONFIG_PATH = VSM_TEST_CONFIG_INSTALL_DIR "/server/ut-containers-manager/buggy-default-daemon.conf"; +const std::string TEST_CONTAINER_CONF_PATH = VSM_TEST_CONFIG_INSTALL_DIR "/server/ut-containers-manager/containers/"; const std::string MISSING_CONFIG_PATH = "/this/is/a/missing/file/path/missing-daemon.conf"; const int EVENT_TIMEOUT = 5000; const int TEST_DBUS_CONNECTION_CONTAINERS_COUNT = 3; @@ -466,7 +466,7 @@ std::function expectedMessage(const std::string& me } struct Fixture { - security_containers::utils::ScopedGlibLoop mLoop; + vasum::utils::ScopedGlibLoop mLoop; utils::ScopedDir mContainersPathGuard; utils::ScopedDir mRunGuard; diff --git a/tests/unit_tests/server/ut-input-monitor.cpp b/tests/unit_tests/server/ut-input-monitor.cpp index 99b0bd2..241da6c 100644 --- a/tests/unit_tests/server/ut-input-monitor.cpp +++ b/tests/unit_tests/server/ut-input-monitor.cpp @@ -45,8 +45,8 @@ #include -using namespace security_containers; -using namespace security_containers::utils; +using namespace vasum; +using namespace vasum::utils; namespace { diff --git a/tests/unit_tests/server/ut-server.cpp b/tests/unit_tests/server/ut-server.cpp index 1c3c46b..cc178db 100644 --- a/tests/unit_tests/server/ut-server.cpp +++ b/tests/unit_tests/server/ut-server.cpp @@ -38,7 +38,7 @@ namespace { const std::string CONTAINERS_PATH = "/tmp/ut-containers"; // the same as in daemon.conf struct Fixture { - security_containers::utils::ScopedDir mContainersPathGuard; + vasum::utils::ScopedDir mContainersPathGuard; Fixture() : mContainersPathGuard(CONTAINERS_PATH) @@ -48,11 +48,11 @@ struct Fixture { BOOST_FIXTURE_TEST_SUITE(ServerSuite, Fixture) -using namespace security_containers; +using namespace vasum; using namespace config; -const std::string TEST_CONFIG_PATH = SC_TEST_CONFIG_INSTALL_DIR "/server/ut-server/test-daemon.conf"; -const std::string BUGGY_CONFIG_PATH = SC_TEST_CONFIG_INSTALL_DIR "/server/ut-server/buggy-daemon.conf"; +const std::string TEST_CONFIG_PATH = VSM_TEST_CONFIG_INSTALL_DIR "/server/ut-server/test-daemon.conf"; +const std::string BUGGY_CONFIG_PATH = VSM_TEST_CONFIG_INSTALL_DIR "/server/ut-server/buggy-daemon.conf"; const std::string MISSING_CONFIG_PATH = "/this/is/a/missing/file/path/missing-daemon.conf"; diff --git a/tests/unit_tests/ut.cpp b/tests/unit_tests/ut.cpp index 194dc9e..bb45e84 100644 --- a/tests/unit_tests/ut.cpp +++ b/tests/unit_tests/ut.cpp @@ -20,7 +20,7 @@ /** * @file * @author Jan Olszak (j.olszak@samsung.com) - * @brief Main file for the Security Containers Daemon unit tests + * @brief Main file for the Vasum Daemon unit tests */ #include "config.hpp" diff --git a/tests/unit_tests/utils/configs/CMakeLists.txt b/tests/unit_tests/utils/configs/CMakeLists.txt index a752d77..d408df0 100644 --- a/tests/unit_tests/utils/configs/CMakeLists.txt +++ b/tests/unit_tests/utils/configs/CMakeLists.txt @@ -17,10 +17,10 @@ # @author Lukasz Pawelczyk (l.pawelczyk@partner.samsung.com) # -MESSAGE(STATUS "Installing configs for the Utils Unit Tests to " ${SC_TEST_CONFIG_INSTALL_DIR}) +MESSAGE(STATUS "Installing configs for the Utils Unit Tests to " ${VSM_TEST_CONFIG_INSTALL_DIR}) FILE(GLOB fs_CONF ut-fs/*.txt) ## Install ##################################################################### INSTALL(FILES ${fs_CONF} - DESTINATION ${SC_TEST_CONFIG_INSTALL_DIR}/utils/ut-fs) + DESTINATION ${VSM_TEST_CONFIG_INSTALL_DIR}/utils/ut-fs) diff --git a/tests/unit_tests/utils/scoped-daemon.cpp b/tests/unit_tests/utils/scoped-daemon.cpp index db85375..19f252c 100644 --- a/tests/unit_tests/utils/scoped-daemon.cpp +++ b/tests/unit_tests/utils/scoped-daemon.cpp @@ -35,7 +35,7 @@ #include -namespace security_containers { +namespace vasum { namespace utils { @@ -179,4 +179,4 @@ void ScopedDaemon::stop() } // namespace utils -} // namespace security_containers +} // namespace vasum diff --git a/tests/unit_tests/utils/scoped-daemon.hpp b/tests/unit_tests/utils/scoped-daemon.hpp index b3eab29..7d67c00 100644 --- a/tests/unit_tests/utils/scoped-daemon.hpp +++ b/tests/unit_tests/utils/scoped-daemon.hpp @@ -28,7 +28,7 @@ #include -namespace security_containers { +namespace vasum { namespace utils { @@ -62,7 +62,7 @@ private: } // namespace utils -} // namespace security_containers +} // namespace vasum #endif // UNIT_TESTS_UTILS_SCOPED_DAEMON_HPP diff --git a/tests/unit_tests/utils/scoped-dir.cpp b/tests/unit_tests/utils/scoped-dir.cpp index c1b184c..48b354b 100644 --- a/tests/unit_tests/utils/scoped-dir.cpp +++ b/tests/unit_tests/utils/scoped-dir.cpp @@ -29,7 +29,7 @@ #include -namespace security_containers { +namespace vasum { namespace utils { namespace fs = boost::filesystem; @@ -67,4 +67,4 @@ void ScopedDir::remove() } } // namespace utils -} // namespace security_containers +} // namespace vasum diff --git a/tests/unit_tests/utils/scoped-dir.hpp b/tests/unit_tests/utils/scoped-dir.hpp index 93e18a2..c42dbe7 100644 --- a/tests/unit_tests/utils/scoped-dir.hpp +++ b/tests/unit_tests/utils/scoped-dir.hpp @@ -28,7 +28,7 @@ #include -namespace security_containers { +namespace vasum { namespace utils { @@ -58,7 +58,7 @@ private: } // namespace utils -} // namespace security_containers +} // namespace vasum #endif // UNIT_TESTS_UTILS_SCOPED_DIR_HPP diff --git a/tests/unit_tests/utils/ut-callback-guard.cpp b/tests/unit_tests/utils/ut-callback-guard.cpp index 9e1e6b2..89787d5 100644 --- a/tests/unit_tests/utils/ut-callback-guard.cpp +++ b/tests/unit_tests/utils/ut-callback-guard.cpp @@ -35,7 +35,7 @@ BOOST_AUTO_TEST_SUITE(CallbackGuardSuite) -using namespace security_containers::utils; +using namespace vasum::utils; const int unsigned TIMEOUT = 1000; diff --git a/tests/unit_tests/utils/ut-fs.cpp b/tests/unit_tests/utils/ut-fs.cpp index a1eea40..5557e46 100644 --- a/tests/unit_tests/utils/ut-fs.cpp +++ b/tests/unit_tests/utils/ut-fs.cpp @@ -35,12 +35,12 @@ BOOST_AUTO_TEST_SUITE(UtilsFSSuite) -using namespace security_containers; -using namespace security_containers::utils; +using namespace vasum; +using namespace vasum::utils; namespace { -const std::string FILE_PATH = SC_TEST_CONFIG_INSTALL_DIR "/utils/ut-fs/file.txt"; +const std::string FILE_PATH = VSM_TEST_CONFIG_INSTALL_DIR "/utils/ut-fs/file.txt"; const std::string FILE_CONTENT = "File content\n" "Line 1\n" "Line 2\n"; diff --git a/tests/unit_tests/utils/ut-glib-loop.cpp b/tests/unit_tests/utils/ut-glib-loop.cpp index af07eef..30d5342 100644 --- a/tests/unit_tests/utils/ut-glib-loop.cpp +++ b/tests/unit_tests/utils/ut-glib-loop.cpp @@ -33,8 +33,8 @@ BOOST_AUTO_TEST_SUITE(UtilsGlibLoopSuite) -using namespace security_containers; -using namespace security_containers::utils; +using namespace vasum; +using namespace vasum::utils; namespace { diff --git a/tests/unit_tests/utils/ut-paths.cpp b/tests/unit_tests/utils/ut-paths.cpp index e32424b..bb2b11f 100644 --- a/tests/unit_tests/utils/ut-paths.cpp +++ b/tests/unit_tests/utils/ut-paths.cpp @@ -32,7 +32,7 @@ BOOST_AUTO_TEST_SUITE(UtilsPathsSuite) -using namespace security_containers::utils; +using namespace vasum::utils; BOOST_AUTO_TEST_CASE(CreateFilePathTest) { -- 2.7.4 From b4ca234cdffa223952b54037d62e0387878d5fde Mon Sep 17 00:00:00 2001 From: Dariusz Michaluk Date: Mon, 8 Dec 2014 14:04:46 +0100 Subject: [PATCH 07/16] Rename containers to zones [Bug/Feature] N/A [Cause] N/A [Solution] N/A [Verification] Build, install, run tests Change-Id: I3d9eb8894c1d236061a0abe35691be6c57839702 Signed-off-by: Dariusz Michaluk --- CMakeLists.txt | 8 +- cli/command-line-interface.cpp | 4 +- cli/command-line-interface.hpp | 6 +- cli/main.cpp | 38 +- client/utils.cpp | 2 +- client/utils.hpp | 2 +- client/vasum-client-impl.cpp | 96 +-- client/vasum-client-impl.hpp | 26 +- client/vasum-client.cpp | 36 +- client/vasum-client.h | 92 +-- common/lxc/zone.cpp | 70 +- common/lxc/zone.hpp | 6 +- .../org.tizen.containers.zone.daemon.conf.in | 14 - .../configs/org.tizen.containers.zone.conf.in | 14 - ...support.manifest => vasum-zone-daemon.manifest} | 0 ...daemon.manifest => vasum-zone-support.manifest} | 0 packaging/vasum.spec | 50 +- server/common-dbus-definitions.hpp | 10 +- server/configs/CMakeLists.txt | 12 +- server/configs/daemon.conf | 12 +- .../system.d/org.tizen.containers.host.conf.in | 20 - .../dbus-1/system.d/org.tizen.vasum.host.conf.in | 20 + server/configs/lxc-templates/template.sh | 6 +- .../configs/lxc-templates/tizen-common-wayland.sh | 28 +- server/configs/{containers => zones}/business.conf | 0 server/configs/{containers => zones}/private.conf | 0 server/containers-manager.cpp | 888 --------------------- server/exception.hpp | 14 +- server/fake-power-manager-dbus-definitions.hpp | 4 +- server/host-connection.cpp | 114 +-- server/host-connection.hpp | 78 +- server/host-dbus-definitions.hpp | 56 +- server/provisioning-config.hpp | 8 +- server/proxy-call-config.hpp | 4 +- server/server.cpp | 26 +- server/server.hpp | 2 +- server/{container-admin.cpp => zone-admin.cpp} | 84 +- server/{container-admin.hpp => zone-admin.hpp} | 56 +- server/{container-config.hpp => zone-config.hpp} | 36 +- ...transport.cpp => zone-connection-transport.cpp} | 26 +- ...transport.hpp => zone-connection-transport.hpp} | 18 +- ...ontainer-connection.cpp => zone-connection.cpp} | 78 +- ...ontainer-connection.hpp => zone-connection.hpp} | 24 +- ...s-definitions.hpp => zone-dbus-definitions.hpp} | 24 +- server/{container.cpp => zone.cpp} | 122 +-- server/{container.hpp => zone.hpp} | 120 +-- ...manager-config.hpp => zones-manager-config.hpp} | 54 +- server/zones-manager.cpp | 888 +++++++++++++++++++++ .../{containers-manager.hpp => zones-manager.hpp} | 102 +-- .../image_tests/config_checker.py | 38 +- tests/integration_tests/image_tests/image_tests.py | 34 +- .../network_tests/network_common.py | 66 +- .../network_tests/network_tests.py | 6 +- tests/unit_tests/client/configs/CMakeLists.txt | 18 +- .../configs/ut-client/test-dbus-daemon.conf.in | 20 +- .../{containers => zones}/console1-dbus.conf.in | 6 +- .../configs/ut-client/zones}/console2-dbus.conf.in | 6 +- .../{containers => zones}/console3-dbus.conf.in | 6 +- tests/unit_tests/client/ut-client-utils.cpp | 6 +- tests/unit_tests/client/ut-client.cpp | 110 +-- .../dbus/configs/ut-connection/ut-dbus.conf | 4 +- tests/unit_tests/dbus/test-common.hpp | 2 +- tests/unit_tests/dbus/test-server.cpp | 2 +- tests/unit_tests/dbus/ut-connection.cpp | 6 +- tests/unit_tests/lxc/templates/minimal-dbus.sh | 4 +- tests/unit_tests/lxc/templates/minimal.sh | 4 +- tests/unit_tests/server/configs/CMakeLists.txt | 116 +-- .../system.d/org.tizen.containers.tests.conf | 14 - .../dbus-1/system.d/org.tizen.vasum.tests.conf | 14 + .../ut-containers-manager/buggy-daemon.conf.in | 17 - .../ut-containers-manager/test-daemon.conf.in | 17 - .../ut-containers-manager/test-dbus-daemon.conf.in | 24 - .../server/configs/ut-server/buggy-daemon.conf.in | 14 +- .../server/configs/ut-server/test-daemon.conf.in | 14 +- .../container1.conf => zones/zone1.conf} | 2 +- .../container2.conf => zones/zone2.conf} | 2 +- .../container3.conf => zones/zone3.conf} | 2 +- .../containers => ut-zone-admin/zones}/buggy.conf | 2 +- .../zones}/missing.conf | 2 +- .../zones}/test-no-shutdown.conf | 2 +- .../containers => ut-zone-admin/zones}/test.conf | 2 +- .../ut-dbus.conf | 4 +- .../ut-dbus.conf | 2 +- .../containers => ut-zone/zones}/buggy.conf | 2 +- .../containers => ut-zone/zones}/test-dbus.conf.in | 6 +- .../containers => ut-zone/zones}/test.conf | 2 +- .../configs/ut-zones-manager/buggy-daemon.conf.in | 17 + .../buggy-default-daemon.conf.in | 12 +- .../buggy-foreground-daemon.conf.in | 12 +- .../empty-dbus-daemon.conf.in | 12 +- .../templates/template.conf.in | 2 +- .../configs/ut-zones-manager/test-daemon.conf.in | 17 + .../ut-zones-manager/test-dbus-daemon.conf.in | 24 + .../ut-dbus.conf | 2 +- .../zones}/console1-dbus.conf.in | 6 +- .../zones}/console1.conf | 2 +- .../ut-zones-manager/zones}/console2-dbus.conf.in | 6 +- .../zones}/console2.conf | 2 +- .../zones}/console3-dbus.conf.in | 6 +- .../zones}/console3.conf | 2 +- tests/unit_tests/server/test-dbus-definitions.hpp | 4 +- tests/unit_tests/server/ut-server.cpp | 6 +- .../{ut-container-admin.cpp => ut-zone-admin.cpp} | 32 +- ...ainer-connection.cpp => ut-zone-connection.cpp} | 58 +- .../server/{ut-container.cpp => ut-zone.cpp} | 26 +- ...containers-manager.cpp => ut-zones-manager.cpp} | 580 +++++++------- {container-daemon => zone-daemon}/CMakeLists.txt | 20 +- .../configs/org.tizen.vasum.zone.daemon.conf.in | 14 + .../daemon-connection.cpp | 16 +- .../daemon-connection.hpp | 12 +- .../daemon-dbus-definitions.hpp | 18 +- {container-daemon => zone-daemon}/daemon.cpp | 4 +- {container-daemon => zone-daemon}/daemon.hpp | 10 +- {container-daemon => zone-daemon}/exception.hpp | 18 +- {container-daemon => zone-daemon}/main.cpp | 4 +- {container-daemon => zone-daemon}/runner.cpp | 14 +- {container-daemon => zone-daemon}/runner.hpp | 10 +- {container-support => zone-support}/CMakeLists.txt | 8 +- zone-support/configs/org.tizen.vasum.zone.conf.in | 14 + 119 files changed, 2493 insertions(+), 2493 deletions(-) delete mode 100644 container-daemon/configs/org.tizen.containers.zone.daemon.conf.in delete mode 100644 container-support/configs/org.tizen.containers.zone.conf.in rename packaging/{vasum-container-support.manifest => vasum-zone-daemon.manifest} (100%) rename packaging/{vasum-container-daemon.manifest => vasum-zone-support.manifest} (100%) delete mode 100644 server/configs/dbus-1/system.d/org.tizen.containers.host.conf.in create mode 100644 server/configs/dbus-1/system.d/org.tizen.vasum.host.conf.in rename server/configs/{containers => zones}/business.conf (100%) rename server/configs/{containers => zones}/private.conf (100%) delete mode 100644 server/containers-manager.cpp rename server/{container-admin.cpp => zone-admin.cpp} (71%) rename server/{container-admin.hpp => zone-admin.hpp} (60%) rename server/{container-config.hpp => zone-config.hpp} (70%) rename server/{container-connection-transport.cpp => zone-connection-transport.cpp} (77%) rename server/{container-connection-transport.hpp => zone-connection-transport.hpp} (73%) rename server/{container-connection.cpp => zone-connection.cpp} (72%) rename server/{container-connection.hpp => zone-connection.hpp} (85%) rename server/{container-dbus-definitions.hpp => zone-dbus-definitions.hpp} (85%) rename server/{container.cpp => zone.cpp} (72%) rename server/{container.hpp => zone.hpp} (61%) rename server/{containers-manager-config.hpp => zones-manager-config.hpp} (57%) create mode 100644 server/zones-manager.cpp rename server/{containers-manager.hpp => zones-manager.hpp} (56%) rename tests/unit_tests/client/configs/ut-client/{containers => zones}/console1-dbus.conf.in (73%) rename tests/unit_tests/{server/configs/ut-containers-manager/containers => client/configs/ut-client/zones}/console2-dbus.conf.in (73%) rename tests/unit_tests/client/configs/ut-client/{containers => zones}/console3-dbus.conf.in (72%) delete mode 100644 tests/unit_tests/server/configs/dbus-1/system.d/org.tizen.containers.tests.conf create mode 100644 tests/unit_tests/server/configs/dbus-1/system.d/org.tizen.vasum.tests.conf delete mode 100644 tests/unit_tests/server/configs/ut-containers-manager/buggy-daemon.conf.in delete mode 100644 tests/unit_tests/server/configs/ut-containers-manager/test-daemon.conf.in delete mode 100644 tests/unit_tests/server/configs/ut-containers-manager/test-dbus-daemon.conf.in rename tests/unit_tests/server/configs/ut-server/{containers/container1.conf => zones/zone1.conf} (91%) rename tests/unit_tests/server/configs/ut-server/{containers/container2.conf => zones/zone2.conf} (91%) rename tests/unit_tests/server/configs/ut-server/{containers/container3.conf => zones/zone3.conf} (91%) rename tests/unit_tests/server/configs/{ut-container-admin/containers => ut-zone-admin/zones}/buggy.conf (90%) rename tests/unit_tests/server/configs/{ut-container-admin/containers => ut-zone-admin/zones}/missing.conf (91%) rename tests/unit_tests/server/configs/{ut-container-admin/containers => ut-zone-admin/zones}/test-no-shutdown.conf (90%) rename tests/unit_tests/server/configs/{ut-container-admin/containers => ut-zone-admin/zones}/test.conf (91%) rename tests/unit_tests/server/configs/{ut-container-connection => ut-zone-connection}/ut-dbus.conf (76%) rename tests/unit_tests/server/configs/{ut-containers-manager => ut-zone}/ut-dbus.conf (89%) rename tests/unit_tests/server/configs/{ut-container/containers => ut-zone/zones}/buggy.conf (92%) rename tests/unit_tests/server/configs/{ut-container/containers => ut-zone/zones}/test-dbus.conf.in (75%) rename tests/unit_tests/server/configs/{ut-container/containers => ut-zone/zones}/test.conf (92%) create mode 100644 tests/unit_tests/server/configs/ut-zones-manager/buggy-daemon.conf.in rename tests/unit_tests/server/configs/{ut-containers-manager => ut-zones-manager}/buggy-default-daemon.conf.in (51%) rename tests/unit_tests/server/configs/{ut-containers-manager => ut-zones-manager}/buggy-foreground-daemon.conf.in (50%) rename tests/unit_tests/server/configs/{ut-containers-manager => ut-zones-manager}/empty-dbus-daemon.conf.in (65%) rename tests/unit_tests/server/configs/{ut-containers-manager => ut-zones-manager}/templates/template.conf.in (90%) create mode 100644 tests/unit_tests/server/configs/ut-zones-manager/test-daemon.conf.in create mode 100644 tests/unit_tests/server/configs/ut-zones-manager/test-dbus-daemon.conf.in rename tests/unit_tests/server/configs/{ut-container => ut-zones-manager}/ut-dbus.conf (89%) rename tests/unit_tests/server/configs/{ut-containers-manager/containers => ut-zones-manager/zones}/console1-dbus.conf.in (73%) rename tests/unit_tests/server/configs/{ut-containers-manager/containers => ut-zones-manager/zones}/console1.conf (90%) rename tests/unit_tests/{client/configs/ut-client/containers => server/configs/ut-zones-manager/zones}/console2-dbus.conf.in (73%) rename tests/unit_tests/server/configs/{ut-containers-manager/containers => ut-zones-manager/zones}/console2.conf (90%) rename tests/unit_tests/server/configs/{ut-containers-manager/containers => ut-zones-manager/zones}/console3-dbus.conf.in (72%) rename tests/unit_tests/server/configs/{ut-containers-manager/containers => ut-zones-manager/zones}/console3.conf (90%) rename tests/unit_tests/server/{ut-container-admin.cpp => ut-zone-admin.cpp} (80%) rename tests/unit_tests/server/{ut-container-connection.cpp => ut-zone-connection.cpp} (75%) rename tests/unit_tests/server/{ut-container.cpp => ut-zone.cpp} (78%) rename tests/unit_tests/server/{ut-containers-manager.cpp => ut-zones-manager.cpp} (62%) rename {container-daemon => zone-daemon}/CMakeLists.txt (65%) create mode 100644 zone-daemon/configs/org.tizen.vasum.zone.daemon.conf.in rename {container-daemon => zone-daemon}/daemon-connection.cpp (88%) rename {container-daemon => zone-daemon}/daemon-connection.hpp (87%) rename {container-daemon => zone-daemon}/daemon-dbus-definitions.hpp (71%) rename {container-daemon => zone-daemon}/daemon.cpp (96%) rename {container-daemon => zone-daemon}/daemon.hpp (87%) rename {container-daemon => zone-daemon}/exception.hpp (66%) rename {container-daemon => zone-daemon}/main.cpp (97%) rename {container-daemon => zone-daemon}/runner.cpp (85%) rename {container-daemon => zone-daemon}/runner.hpp (87%) rename {container-support => zone-support}/CMakeLists.txt (80%) create mode 100644 zone-support/configs/org.tizen.vasum.zone.conf.in diff --git a/CMakeLists.txt b/CMakeLists.txt index b302d18..588f066 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -91,8 +91,8 @@ ENDIF(NOT DEFINED PYTHON_SITELIB) SET(COMMON_FOLDER ${PROJECT_SOURCE_DIR}/common) SET(CLIENT_FOLDER ${PROJECT_SOURCE_DIR}/client) SET(SERVER_FOLDER ${PROJECT_SOURCE_DIR}/server) -SET(CONTAINER_SUPPORT_FOLDER ${PROJECT_SOURCE_DIR}/container-support) -SET(CONTAINER_DAEMON_FOLDER ${PROJECT_SOURCE_DIR}/container-daemon) +SET(ZONE_SUPPORT_FOLDER ${PROJECT_SOURCE_DIR}/zone-support) +SET(ZONE_DAEMON_FOLDER ${PROJECT_SOURCE_DIR}/zone-daemon) SET(TESTS_FOLDER ${PROJECT_SOURCE_DIR}/tests) SET(UNIT_TESTS_FOLDER ${TESTS_FOLDER}/unit_tests) SET(CLI_FOLDER ${PROJECT_SOURCE_DIR}/cli) @@ -126,8 +126,8 @@ SET(VSM_DATA_INSTALL_DIR ${SHARE_INSTALL_PREFIX}/vasum) ADD_SUBDIRECTORY(${CLIENT_FOLDER}) ADD_SUBDIRECTORY(${SERVER_FOLDER}) -ADD_SUBDIRECTORY(${CONTAINER_SUPPORT_FOLDER}) -ADD_SUBDIRECTORY(${CONTAINER_DAEMON_FOLDER}) +ADD_SUBDIRECTORY(${ZONE_SUPPORT_FOLDER}) +ADD_SUBDIRECTORY(${ZONE_DAEMON_FOLDER}) ADD_SUBDIRECTORY(${TESTS_FOLDER}) ADD_SUBDIRECTORY(${CLI_FOLDER}) diff --git a/cli/command-line-interface.cpp b/cli/command-line-interface.cpp index ca75d25..d7d8439 100644 --- a/cli/command-line-interface.cpp +++ b/cli/command-line-interface.cpp @@ -132,7 +132,7 @@ void CommandLineInterface::execute(int pos, int argc, const char** argv) } -void set_active_container(int pos, int argc, const char** argv) +void set_active_zone(int pos, int argc, const char** argv) { using namespace std::placeholders; @@ -140,7 +140,7 @@ void set_active_container(int pos, int argc, const char** argv) throw runtime_error("Not enough parameters"); } - one_shot(bind(vsm_set_active_container, _1, argv[pos + 1])); + one_shot(bind(vsm_set_active_zone, _1, argv[pos + 1])); } void create_zone(int pos, int argc, const char** argv) diff --git a/cli/command-line-interface.hpp b/cli/command-line-interface.hpp index 6ff4fb0..d2fe6be 100644 --- a/cli/command-line-interface.hpp +++ b/cli/command-line-interface.hpp @@ -97,11 +97,11 @@ private: }; /** - * Parses command line arguments and call vsm_set_active_container + * Parses command line arguments and call vsm_set_active_zone * - * @see vsm_set_active_container + * @see vsm_set_active_zone */ -void set_active_container(int pos, int argc, const char** argv); +void set_active_zone(int pos, int argc, const char** argv); /** * Parses command line arguments and call vsm_create_zone diff --git a/cli/main.cpp b/cli/main.cpp index c2e8ad8..e837d86 100644 --- a/cli/main.cpp +++ b/cli/main.cpp @@ -34,51 +34,51 @@ using namespace vasum::cli; std::map commands = { { - "set_active_container", { - set_active_container, - "set_active_container container_id", - "Set active (foreground) container", - {{"container_id", "id container name"}} + "set_active_zone", { + set_active_zone, + "set_active_zone zone_id", + "Set active (foreground) zone", + {{"zone_id", "id zone name"}} } }, { "create_zone", { create_zone, - "create_zone container_id", - "Create and add container", - {{"container_id", "id container name"}} + "create_zone zone_id", + "Create and add zone", + {{"zone_id", "id zone name"}} } }, { "destroy_zone", { destroy_zone, - "destroy_zone container_id", - "Destroy container", - {{"container_id", "id container name"}} + "destroy_zone zone_id", + "Destroy zone", + {{"zone_id", "id zone name"}} } }, { "lock_zone", { lock_zone, - "lock_zone container_id", - "Lock container", - {{"container_id", "id container name"}} + "lock_zone zone_id", + "Lock zone", + {{"zone_id", "id zone name"}} } }, { "unlock_zone", { unlock_zone, - "unlock_zone container_id", - "Unlock container", - {{"container_id", "id container name"}} + "unlock_zone zone_id", + "Unlock zone", + {{"zone_id", "id zone name"}} } }, { "lookup_zone_by_id", { lookup_zone_by_id, - "lookup_zone_by_id container_id", + "lookup_zone_by_id zone_id", "Prints informations about zone", - {{"container_id", "id container name"}} + {{"zone_id", "id zone name"}} } } }; diff --git a/client/utils.cpp b/client/utils.cpp index d6157c4..a5ff48e 100644 --- a/client/utils.cpp +++ b/client/utils.cpp @@ -117,7 +117,7 @@ bool parseNewLibvirtFormat(const std::string& cpuset, std::string& id) } // namespace -bool parseContainerIdFromCpuSet(const std::string& cpuset, std::string& id) +bool parseZoneIdFromCpuSet(const std::string& cpuset, std::string& id) { if (cpuset == CPUSET_HOST) { id = "host"; diff --git a/client/utils.hpp b/client/utils.hpp index b86cc20..d6b4057 100644 --- a/client/utils.hpp +++ b/client/utils.hpp @@ -27,6 +27,6 @@ #include -bool parseContainerIdFromCpuSet(const std::string& cpuset, std::string& id); +bool parseZoneIdFromCpuSet(const std::string& cpuset, std::string& id); #endif // VASUM_CLIENT_UTILS_HPP diff --git a/client/vasum-client-impl.cpp b/client/vasum-client-impl.cpp index e228409..c16c9d2 100644 --- a/client/vasum-client-impl.cpp +++ b/client/vasum-client-impl.cpp @@ -30,7 +30,7 @@ #include #include #include -#include +#include #include #include @@ -46,9 +46,9 @@ namespace { const DbusInterfaceInfo HOST_INTERFACE(api::host::BUS_NAME, api::host::OBJECT_PATH, api::host::INTERFACE); -const DbusInterfaceInfo CONTAINER_INTERFACE(api::container::BUS_NAME, - api::container::OBJECT_PATH, - api::container::INTERFACE); +const DbusInterfaceInfo ZONE_INTERFACE(api::zone::BUS_NAME, + api::zone::OBJECT_PATH, + api::zone::INTERFACE); unique_ptr gGlibLoop; @@ -317,14 +317,14 @@ VsmStatus Client::vsm_get_status() noexcept return mStatus.mVsmStatus; } -VsmStatus Client::vsm_get_container_dbuses(VsmArrayString* keys, VsmArrayString* values) noexcept +VsmStatus Client::vsm_get_zone_dbuses(VsmArrayString* keys, VsmArrayString* values) noexcept { assert(keys); assert(values); GVariant* out; VsmStatus ret = callMethod(HOST_INTERFACE, - api::host::METHOD_GET_CONTAINER_DBUSES, + api::host::METHOD_GET_ZONE_DBUSES, NULL, "(a{ss})", &out); @@ -345,7 +345,7 @@ VsmStatus Client::vsm_get_zone_ids(VsmArrayString* array) noexcept GVariant* out; VsmStatus ret = callMethod(HOST_INTERFACE, - api::host::METHOD_GET_CONTAINER_ID_LIST, + api::host::METHOD_GET_ZONE_ID_LIST, NULL, "(as)", &out); @@ -360,13 +360,13 @@ VsmStatus Client::vsm_get_zone_ids(VsmArrayString* array) noexcept return ret; } -VsmStatus Client::vsm_get_active_container_id(VsmString* id) noexcept +VsmStatus Client::vsm_get_active_zone_id(VsmString* id) noexcept { assert(id); GVariant* out; VsmStatus ret = callMethod(HOST_INTERFACE, - api::host::METHOD_GET_ACTIVE_CONTAINER_ID, + api::host::METHOD_GET_ACTIVE_ZONE_ID, NULL, "(s)", &out); @@ -393,13 +393,13 @@ VsmStatus Client::vsm_lookup_zone_by_pid(int pid, VsmString* id) noexcept return vsm_get_status(); } - std::string containerId; - if (!parseContainerIdFromCpuSet(cpuset, containerId)) { + std::string zoneId; + if (!parseZoneIdFromCpuSet(cpuset, zoneId)) { mStatus = Status(VSMCLIENT_OTHER_ERROR, "unknown format of cpuset"); return vsm_get_status(); } - *id = strdup(containerId.c_str()); + *id = strdup(zoneId.c_str()); mStatus = Status(); return vsm_get_status(); } @@ -412,7 +412,7 @@ VsmStatus Client::vsm_lookup_zone_by_id(const char* id, VsmZone* zone) noexcept GVariant* out; GVariant* args_in = g_variant_new("(s)", id); VsmStatus ret = callMethod(HOST_INTERFACE, - api::host::METHOD_GET_CONTAINER_INFO, + api::host::METHOD_GET_ZONE_INFO, args_in, "((siss))", &out); @@ -433,12 +433,12 @@ VsmStatus Client::vsm_lookup_zone_by_terminal_id(int, VsmString*) noexcept return vsm_get_status(); } -VsmStatus Client::vsm_set_active_container(const char* id) noexcept +VsmStatus Client::vsm_set_active_zone(const char* id) noexcept { assert(id); GVariant* args_in = g_variant_new("(s)", id); - return callMethod(HOST_INTERFACE, api::host::METHOD_SET_ACTIVE_CONTAINER, args_in); + return callMethod(HOST_INTERFACE, api::host::METHOD_SET_ACTIVE_ZONE, args_in); } VsmStatus Client::vsm_create_zone(const char* id, const char* tname) noexcept @@ -450,14 +450,14 @@ VsmStatus Client::vsm_create_zone(const char* id, const char* tname) noexcept } GVariant* args_in = g_variant_new("(s)", id); - return callMethod(HOST_INTERFACE, api::host::METHOD_CREATE_CONTAINER, args_in); + return callMethod(HOST_INTERFACE, api::host::METHOD_CREATE_ZONE, args_in); } VsmStatus Client::vsm_destroy_zone(const char* id) noexcept { assert(id); GVariant* args_in = g_variant_new("(s)", id); - return callMethod(HOST_INTERFACE, api::host::METHOD_DESTROY_CONTAINER, args_in); + return callMethod(HOST_INTERFACE, api::host::METHOD_DESTROY_ZONE, args_in); } VsmStatus Client::vsm_shutdown_zone(const char*) noexcept @@ -477,7 +477,7 @@ VsmStatus Client::vsm_lock_zone(const char* id) noexcept assert(id); GVariant* args_in = g_variant_new("(s)", id); - return callMethod(HOST_INTERFACE, api::host::METHOD_LOCK_CONTAINER, args_in); + return callMethod(HOST_INTERFACE, api::host::METHOD_LOCK_ZONE, args_in); } VsmStatus Client::vsm_unlock_zone(const char* id) noexcept @@ -485,25 +485,25 @@ VsmStatus Client::vsm_unlock_zone(const char* id) noexcept assert(id); GVariant* args_in = g_variant_new("(s)", id); - return callMethod(HOST_INTERFACE, api::host::METHOD_UNLOCK_CONTAINER, args_in); + return callMethod(HOST_INTERFACE, api::host::METHOD_UNLOCK_ZONE, args_in); } -VsmStatus Client::vsm_add_state_callback(VsmContainerDbusStateCallback containerDbusStateCallback, +VsmStatus Client::vsm_add_state_callback(VsmZoneDbusStateCallback zoneDbusStateCallback, void* data, VsmSubscriptionId* subscriptionId) noexcept { - assert(containerDbusStateCallback); + assert(zoneDbusStateCallback); auto onSigal = [=](GVariant * parameters) { - const char* container; + const char* zone; const char* dbusAddress; - g_variant_get(parameters, "(&s&s)", &container, &dbusAddress); - containerDbusStateCallback(container, dbusAddress, data); + g_variant_get(parameters, "(&s&s)", &zone, &dbusAddress); + zoneDbusStateCallback(zone, dbusAddress, data); }; return signalSubscribe(HOST_INTERFACE, - api::host::SIGNAL_CONTAINER_DBUS_STATE, + api::host::SIGNAL_ZONE_DBUS_STATE, onSigal, subscriptionId); } @@ -573,7 +573,7 @@ VsmStatus Client::vsm_lookup_netdev_by_name(const char*, const char*, VsmNetdev* return vsm_get_status(); } -VsmStatus Client::vsm_declare_file(const char* container, +VsmStatus Client::vsm_declare_file(const char* zone, VsmFileType type, const char *path, int32_t flags, @@ -581,14 +581,14 @@ VsmStatus Client::vsm_declare_file(const char* container, { assert(path); - GVariant* args_in = g_variant_new("(sisii)", container, type, path, flags, mode); - return callMethod(CONTAINER_INTERFACE, + GVariant* args_in = g_variant_new("(sisii)", zone, type, path, flags, mode); + return callMethod(ZONE_INTERFACE, api::host::METHOD_DECLARE_FILE, args_in); } VsmStatus Client::vsm_declare_mount(const char *source, - const char* container, + const char* zone, const char *target, const char *type, uint64_t flags, @@ -601,45 +601,45 @@ VsmStatus Client::vsm_declare_mount(const char *source, data = ""; } - GVariant* args_in = g_variant_new("(ssssts)", source, container, target, type, flags, data); - return callMethod(CONTAINER_INTERFACE, + GVariant* args_in = g_variant_new("(ssssts)", source, zone, target, type, flags, data); + return callMethod(ZONE_INTERFACE, api::host::METHOD_DECLARE_MOUNT, args_in); } VsmStatus Client::vsm_declare_link(const char *source, - const char* container, + const char* zone, const char *target) noexcept { assert(source); assert(target); - GVariant* args_in = g_variant_new("(sss)", source, container, target); - return callMethod(CONTAINER_INTERFACE, + GVariant* args_in = g_variant_new("(sss)", source, zone, target); + return callMethod(ZONE_INTERFACE, api::host::METHOD_DECLARE_LINK, args_in); } -VsmStatus Client::vsm_notify_active_container(const char* application, const char* message) noexcept +VsmStatus Client::vsm_notify_active_zone(const char* application, const char* message) noexcept { assert(application); assert(message); GVariant* args_in = g_variant_new("(ss)", application, message); - return callMethod(CONTAINER_INTERFACE, - api::container::METHOD_NOTIFY_ACTIVE_CONTAINER, + return callMethod(ZONE_INTERFACE, + api::zone::METHOD_NOTIFY_ACTIVE_ZONE, args_in); } -VsmStatus Client::vsm_file_move_request(const char* destContainer, const char* path) noexcept +VsmStatus Client::vsm_file_move_request(const char* destZone, const char* path) noexcept { - assert(destContainer); + assert(destZone); assert(path); GVariant* out; - GVariant* args_in = g_variant_new("(ss)", destContainer, path); - VsmStatus ret = callMethod(CONTAINER_INTERFACE, - api::container::METHOD_FILE_MOVE_REQUEST, + GVariant* args_in = g_variant_new("(ss)", destZone, path); + VsmStatus ret = callMethod(ZONE_INTERFACE, + api::zone::METHOD_FILE_MOVE_REQUEST, args_in, "(s)", &out); @@ -649,7 +649,7 @@ VsmStatus Client::vsm_file_move_request(const char* destContainer, const char* p } const gchar* retcode = NULL;; g_variant_get(out, "(&s)", &retcode); - if (strcmp(retcode, api::container::FILE_MOVE_SUCCEEDED.c_str()) != 0) { + if (strcmp(retcode, api::zone::FILE_MOVE_SUCCEEDED.c_str()) != 0) { mStatus = Status(VSMCLIENT_CUSTOM_ERROR, retcode); g_variant_unref(out); return vsm_get_status(); @@ -665,15 +665,15 @@ VsmStatus Client::vsm_add_notification_callback(VsmNotificationCallback notifica assert(notificationCallback); auto onSigal = [=](GVariant * parameters) { - const char* container; + const char* zone; const char* application; const char* message; - g_variant_get(parameters, "(&s&s&s)", &container, &application, &message); - notificationCallback(container, application, message, data); + g_variant_get(parameters, "(&s&s&s)", &zone, &application, &message); + notificationCallback(zone, application, message, data); }; - return signalSubscribe(CONTAINER_INTERFACE, - api::container::SIGNAL_NOTIFICATION, + return signalSubscribe(ZONE_INTERFACE, + api::zone::SIGNAL_NOTIFICATION, onSigal, subscriptionId); } diff --git a/client/vasum-client-impl.hpp b/client/vasum-client-impl.hpp index f507c0a..18eb726 100644 --- a/client/vasum-client-impl.hpp +++ b/client/vasum-client-impl.hpp @@ -104,9 +104,9 @@ public: VsmStatus vsm_get_status() noexcept; /** - * @see ::vsm_get_container_dbuses + * @see ::vsm_get_zone_dbuses */ - VsmStatus vsm_get_container_dbuses(VsmArrayString* keys, VsmArrayString* values) noexcept; + VsmStatus vsm_get_zone_dbuses(VsmArrayString* keys, VsmArrayString* values) noexcept; /** * @see ::vsm_get_zone_ids @@ -114,9 +114,9 @@ public: VsmStatus vsm_get_zone_ids(VsmArrayString* array) noexcept; /** - * @see ::vsm_get_active_container_id + * @see ::vsm_get_active_zone_id */ - VsmStatus vsm_get_active_container_id(VsmString* id) noexcept; + VsmStatus vsm_get_active_zone_id(VsmString* id) noexcept; /** * @see ::vsm_lookup_zone_by_pid @@ -134,9 +134,9 @@ public: VsmStatus vsm_lookup_zone_by_terminal_id(int terminal, VsmString* id) noexcept; /** - * @see ::vsm_set_active_container + * @see ::vsm_set_active_zone */ - VsmStatus vsm_set_active_container(const char* id) noexcept; + VsmStatus vsm_set_active_zone(const char* id) noexcept; /** * @see ::vsm_create_zone @@ -171,7 +171,7 @@ public: /** * @see ::vsm_add_state_callback */ - VsmStatus vsm_add_state_callback(VsmContainerDbusStateCallback containerDbusStateCallback, + VsmStatus vsm_add_state_callback(VsmZoneDbusStateCallback zoneDbusStateCallback, void* data, VsmSubscriptionId* subscriptionId) noexcept; @@ -250,7 +250,7 @@ public: /** * @see ::vsm_declare_file */ - VsmStatus vsm_declare_file(const char* container, + VsmStatus vsm_declare_file(const char* zone, VsmFileType type, const char* path, int32_t flags, @@ -260,7 +260,7 @@ public: * @see ::vsm_declare_mount */ VsmStatus vsm_declare_mount(const char* source, - const char* container, + const char* zone, const char* target, const char* type, uint64_t flags, @@ -269,18 +269,18 @@ public: * @see ::vsm_declare_link */ VsmStatus vsm_declare_link(const char* source, - const char* container, + const char* zone, const char* target) noexcept; /** - * @see ::vsm_notify_active_container + * @see ::vsm_notify_active_zone */ - VsmStatus vsm_notify_active_container(const char* application, const char* message) noexcept; + VsmStatus vsm_notify_active_zone(const char* application, const char* message) noexcept; /** * @see ::vsm_file_move_request */ - VsmStatus vsm_file_move_request(const char* destContainer, const char* path) noexcept; + VsmStatus vsm_file_move_request(const char* destZone, const char* path) noexcept; /** * @see ::vsm_add_notification_callback diff --git a/client/vasum-client.cpp b/client/vasum-client.cpp index c366a8e..2102432 100644 --- a/client/vasum-client.cpp +++ b/client/vasum-client.cpp @@ -118,9 +118,9 @@ API VsmStatus vsm_get_status(VsmClient client) return getClient(client).vsm_get_status(); } -API VsmStatus vsm_get_container_dbuses(VsmClient client, VsmArrayString* keys, VsmArrayString* values) +API VsmStatus vsm_get_zone_dbuses(VsmClient client, VsmArrayString* keys, VsmArrayString* values) { - return getClient(client).vsm_get_container_dbuses(keys, values); + return getClient(client).vsm_get_zone_dbuses(keys, values); } API VsmStatus vsm_get_zone_ids(VsmClient client, VsmArrayString* array) @@ -128,9 +128,9 @@ API VsmStatus vsm_get_zone_ids(VsmClient client, VsmArrayString* array) return getClient(client).vsm_get_zone_ids(array); } -API VsmStatus vsm_get_active_container_id(VsmClient client, VsmString* id) +API VsmStatus vsm_get_active_zone_id(VsmClient client, VsmString* id) { - return getClient(client).vsm_get_active_container_id(id); + return getClient(client).vsm_get_active_zone_id(id); } API VsmStatus vsm_lookup_zone_by_pid(VsmClient client, int pid, VsmString* id) @@ -148,9 +148,9 @@ API VsmStatus vsm_lookup_zone_by_terminal_id(VsmClient client, int terminal, Vsm return getClient(client).vsm_lookup_zone_by_terminal_id(terminal, id); } -API VsmStatus vsm_set_active_container(VsmClient client, const char* id) +API VsmStatus vsm_set_active_zone(VsmClient client, const char* id) { - return getClient(client).vsm_set_active_container(id); + return getClient(client).vsm_set_active_zone(id); } API VsmStatus vsm_create_zone(VsmClient client, const char* id, const char* tname) @@ -184,11 +184,11 @@ API VsmStatus vsm_unlock_zone(VsmClient client, const char* id) } API VsmStatus vsm_add_state_callback(VsmClient client, - VsmContainerDbusStateCallback containerDbusStateCallback, + VsmZoneDbusStateCallback zoneDbusStateCallback, void* data, VsmSubscriptionId* subscriptionId) { - return getClient(client).vsm_add_state_callback(containerDbusStateCallback, data, subscriptionId); + return getClient(client).vsm_add_state_callback(zoneDbusStateCallback, data, subscriptionId); } API VsmStatus vsm_del_state_callback(VsmClient client, VsmSubscriptionId subscriptionId) @@ -273,46 +273,46 @@ API VsmStatus vsm_lookup_netdev_by_name(VsmClient client, } API VsmStatus vsm_declare_file(VsmClient client, - const char* container, + const char* zone, VsmFileType type, const char* path, int32_t flags, mode_t mode) { - return getClient(client).vsm_declare_file(container, type, path, flags, mode); + return getClient(client).vsm_declare_file(zone, type, path, flags, mode); } API VsmStatus vsm_declare_mount(VsmClient client, const char* source, - const char* container, + const char* zone, const char* target, const char* type, uint64_t flags, const char* data) { - return getClient(client).vsm_declare_mount(source, container, target, type, flags, data); + return getClient(client).vsm_declare_mount(source, zone, target, type, flags, data); } API VsmStatus vsm_declare_link(VsmClient client, const char* source, - const char* container, + const char* zone, const char* target) { - return getClient(client).vsm_declare_link(source, container, target); + return getClient(client).vsm_declare_link(source, zone, target); } -API VsmStatus vsm_notify_active_container(VsmClient client, +API VsmStatus vsm_notify_active_zone(VsmClient client, const char* application, const char* message) { - return getClient(client).vsm_notify_active_container(application, message); + return getClient(client).vsm_notify_active_zone(application, message); } -API VsmStatus vsm_file_move_request(VsmClient client, const char* destContainer, const char* path) +API VsmStatus vsm_file_move_request(VsmClient client, const char* destZone, const char* path) { - return getClient(client).vsm_file_move_request(destContainer, path); + return getClient(client).vsm_file_move_request(destZone, path); } API VsmStatus vsm_add_notification_callback(VsmClient client, diff --git a/client/vasum-client.h b/client/vasum-client.h index b8137eb..3e1f66d 100644 --- a/client/vasum-client.h +++ b/client/vasum-client.h @@ -282,60 +282,60 @@ void vsm_netdev_free(VsmNetdev netdev); /** * @name Host API * - * Functions using org.tizen.containers.host.manager D-Bus interface. + * Functions using org.tizen.vasum.host.manager D-Bus interface. * * @{ */ /** - * Container's D-Bus state change callback function signature. + * Zone's D-Bus state change callback function signature. * - * @param[in] containerId affected container id + * @param[in] zoneId affected zone id * @param[in] dbusAddress new D-Bus address * @param data custom user's data pointer passed to vsm_add_state_callback() function */ -typedef void (*VsmContainerDbusStateCallback)(const char* containerId, +typedef void (*VsmZoneDbusStateCallback)(const char* zoneId, const char* dbusAddress, void* data); /** - * Get dbus address of each container. + * Get dbus address of each zone. * * @param[in] client vasum-server's client - * @param[out] keys array of containers name - * @param[out] values array of containers dbus address + * @param[out] keys array of zones name + * @param[out] values array of zones dbus address * @return status of this function call * @post keys[i] corresponds to values[i] * @remark Use vsm_array_string_free() to free memory occupied by @p keys and @p values. */ -VsmStatus vsm_get_container_dbuses(VsmClient client, VsmArrayString* keys, VsmArrayString* values); +VsmStatus vsm_get_zone_dbuses(VsmClient client, VsmArrayString* keys, VsmArrayString* values); /** - * Get containers name. + * Get zones name. * * @param[in] client vasum-server's client - * @param[out] array array of containers name + * @param[out] array array of zones name * @return status of this function call * @remark Use vsm_array_string_free() to free memory occupied by @p array. */ VsmStatus vsm_get_zone_ids(VsmClient client, VsmArrayString* array); /** - * Get active (foreground) container name. + * Get active (foreground) zone name. * * @param[in] client vasum-server's client - * @param[out] id active container name + * @param[out] id active zone name * @return status of this function call * @remark Use @p vsm_string_free() to free memory occupied by @p id. */ -VsmStatus vsm_get_active_container_id(VsmClient client, VsmString* id); +VsmStatus vsm_get_active_zone_id(VsmClient client, VsmString* id); /** - * Get container name of process with given pid. + * Get zone name of process with given pid. * * @param[in] client vasum-server's client * @param[in] pid process id - * @param[out] id active container name + * @param[out] id active zone name * @return status of this function call * @remark Use @p vsm_string_free() to free memory occupied by @p id. */ @@ -364,19 +364,19 @@ VsmStatus vsm_lookup_zone_by_id(VsmClient client, const char* id, VsmZone* zone) VsmStatus vsm_lookup_zone_by_terminal_id(VsmClient client, int terminal, VsmString* id); /** - * Set active (foreground) container. + * Set active (foreground) zone. * * @param[in] client vasum-server's client - * @param[in] id container name + * @param[in] id zone name * @return status of this function call */ -VsmStatus vsm_set_active_container(VsmClient client, const char* id); +VsmStatus vsm_set_active_zone(VsmClient client, const char* id); /** - * Create and add container + * Create and add zone * * @param[in] client vasum-server's client - * @param[in] id container id + * @param[in] id zone id * @param[in] tname template name, NULL for default * @return status of this function call */ @@ -386,7 +386,7 @@ VsmStatus vsm_create_zone(VsmClient client, const char* id, const char* tname); * Remove zone * * @param[in] client vasum-server's client - * @param[in] id container id + * @param[in] id zone id * @param[in] force if 0 data will be kept, otherwise data will be lost * @return status of this function call */ @@ -434,14 +434,14 @@ VsmStatus vsm_unlock_zone(VsmClient client, const char* id); * @note The callback function will be invoked on a different thread. * * @param[in] client vasum-server's client - * @param[in] containerDbusStateCallback callback function + * @param[in] zoneDbusStateCallback callback function * @param[in] data some extra data that will be passed to callback function * @param[out] subscriptionId subscription identifier that can be used to unsubscribe signal, * pointer can be NULL. * @return status of this function call */ VsmStatus vsm_add_state_callback(VsmClient client, - VsmContainerDbusStateCallback containerDbusStateCallback, + VsmZoneDbusStateCallback zoneDbusStateCallback, void* data, VsmSubscriptionId* subscriptionId); @@ -591,37 +591,37 @@ VsmStatus vsm_lookup_netdev_by_name(VsmClient client, VsmNetdev* netdev); /** - * Create file, directory or pipe in container + * Create file, directory or pipe in zone * - * Declare file, directory or pipe that will be created while container startup + * Declare file, directory or pipe that will be created while zone startup * * @param[in] client vasum-server's client * @param[in] type file type - * @param[in] container container id + * @param[in] zone zone id * @param[in] path path to file - * @param[in] flags if O_CREAT bit is set then file will be created in container, + * @param[in] flags if O_CREAT bit is set then file will be created in zone, * otherwise file will by copied from host; * it is meaningful only when O_CREAT is set * @param[in] mode mode of file * @return status of this function call */ VsmStatus vsm_declare_file(VsmClient client, - const char* container, + const char* zone, VsmFileType type, const char* path, int32_t flags, mode_t mode); /** - * Create mount point in container + * Create mount point in zone * - * Declare mount that will be created while container startup + * Declare mount that will be created while zone startup * Parameters are passed to mount system function * * @param[in] client vasum-server's client * @param[in] source device path (path in host) - * @param[in] container container id - * @param[in] target mount point (path in container) + * @param[in] zone zone id + * @param[in] target mount point (path in zone) * @param[in] type filesystem type * @param[in] flags mount flags as in mount function * @patam[in] data additional data as in mount function @@ -629,27 +629,27 @@ VsmStatus vsm_declare_file(VsmClient client, */ VsmStatus vsm_declare_mount(VsmClient client, const char* source, - const char* container, + const char* zone, const char* target, const char* type, uint64_t flags, const char* data); /** - * Create link in container + * Create link in zone * - * Declare link that will be created while container startup + * Declare link that will be created while zone startup * Parameters are passed to link system function * * @param[in] client vasum-server's client * @param[in] source path to link source (in host) - * @param[in] container container id - * @param[in] target path to link name (in container) + * @param[in] zone zone id + * @param[in] target path to link name (in zone) * @return status of this function call */ VsmStatus vsm_declare_link(VsmClient client, const char *source, - const char* container, + const char* zone, const char *target); @@ -659,7 +659,7 @@ VsmStatus vsm_declare_link(VsmClient client, /** * @name Zone API * - * Functions using org.tizen.containers.zone.manager D-Bus interface. + * Functions using org.tizen.vasum.zone.manager D-Bus interface. * * @{ */ @@ -667,34 +667,34 @@ VsmStatus vsm_declare_link(VsmClient client, /** * Notification callback function signature. * - * @param[in] container source container + * @param[in] zone source zone * @param[in] application sending application name * @param[in] message notification message * @param data custom user's data pointer passed to vsm_add_notification_callback() */ -typedef void (*VsmNotificationCallback)(const char* container, +typedef void (*VsmNotificationCallback)(const char* zone, const char* application, const char* message, void* data); /** - * Send message to active container. + * Send message to active zone. * * @param[in] client vasum-server's client * @param[in] application application name * @param[in] message message * @return status of this function call */ -VsmStatus vsm_notify_active_container(VsmClient client, const char* application, const char* message); +VsmStatus vsm_notify_active_zone(VsmClient client, const char* application, const char* message); /** - * Move file between containers. + * Move file between zones. * * @param[in] client vasum-server's client - * @param[in] destContainer destination container id + * @param[in] destZone destination zone id * @param[in] path path to moved file * @return status of this function call */ -VsmStatus vsm_file_move_request(VsmClient client, const char* destContainer, const char* path); +VsmStatus vsm_file_move_request(VsmClient client, const char* destZone, const char* path); /** * Register notification callback function. diff --git a/common/lxc/zone.cpp b/common/lxc/zone.cpp index ceded4b..b142de4 100644 --- a/common/lxc/zone.cpp +++ b/common/lxc/zone.cpp @@ -83,10 +83,10 @@ std::string LxcZone::toString(State state) } LxcZone::LxcZone(const std::string& lxcPath, const std::string& zoneName) - : mContainer(nullptr) + : mLxcContainer(nullptr) { - mContainer = lxc_container_new(zoneName.c_str(), lxcPath.c_str()); - if (!mContainer) { + mLxcContainer = lxc_container_new(zoneName.c_str(), lxcPath.c_str()); + if (!mLxcContainer) { LOGE("Could not initialize lxc zone " << zoneName << " in path " << lxcPath); throw LxcException("Could not initialize lxc zone"); } @@ -94,18 +94,18 @@ LxcZone::LxcZone(const std::string& lxcPath, const std::string& zoneName) LxcZone::~LxcZone() { - lxc_container_put(mContainer); + lxc_container_put(mLxcContainer); } std::string LxcZone::getName() const { - return mContainer->name; + return mLxcContainer->name; } std::string LxcZone::getConfigItem(const std::string& key) { char buffer[1024]; - int len = mContainer->get_config_item(mContainer, key.c_str(), buffer, sizeof(buffer)); + int len = mLxcContainer->get_config_item(mLxcContainer, key.c_str(), buffer, sizeof(buffer)); if (len < 0) { LOGE("Key '" << key << "' not found in zone " << getName()); throw LxcException("Key not found"); @@ -115,12 +115,12 @@ std::string LxcZone::getConfigItem(const std::string& key) bool LxcZone::isDefined() { - return mContainer->is_defined(mContainer); + return mLxcContainer->is_defined(mLxcContainer); } LxcZone::State LxcZone::getState() { - const std::string str = mContainer->state(mContainer); + const std::string str = mLxcContainer->state(mLxcContainer); return STATE_MAP.at(str); } @@ -129,9 +129,9 @@ bool LxcZone::create(const std::string& templatePath, const char* const* argv) #ifdef USE_EXEC utils::CStringArrayBuilder args; args.add("lxc-create") - .add("-n").add(mContainer->name) + .add("-n").add(mLxcContainer->name) .add("-t").add(templatePath.c_str()) - .add("-P").add(mContainer->config_path); + .add("-P").add(mLxcContainer->config_path); while (*argv) { args.add(*argv++); @@ -145,10 +145,10 @@ bool LxcZone::create(const std::string& templatePath, const char* const* argv) refresh(); return true; #else - if (!mContainer->create(mContainer, - templatePath.c_str(), - NULL, NULL, 0, - const_cast(argv))) { + if (!mLxcContainer->create(mLxcContainer, + templatePath.c_str(), + NULL, NULL, 0, + const_cast(argv))) { LOGE("Could not create zone " << getName()); return false; } @@ -158,7 +158,7 @@ bool LxcZone::create(const std::string& templatePath, const char* const* argv) bool LxcZone::destroy() { - if (!mContainer->destroy(mContainer)) { + if (!mLxcContainer->destroy(mLxcContainer)) { LOGE("Could not destroy zone " << getName()); return false; } @@ -168,7 +168,7 @@ bool LxcZone::destroy() bool LxcZone::start(const char* const* argv) { #ifdef USE_EXEC - if (mContainer->is_running(mContainer)) { + if (mLxcContainer->is_running(mLxcContainer)) { LOGE("Already started " << getName()); return false; } @@ -176,8 +176,8 @@ bool LxcZone::start(const char* const* argv) utils::CStringArrayBuilder args; args.add("lxc-start") .add("-d") - .add("-n").add(mContainer->name) - .add("-P").add(mContainer->config_path) + .add("-n").add(mLxcContainer->name) + .add("-P").add(mLxcContainer->config_path) .add("--"); while (*argv) { @@ -192,21 +192,21 @@ bool LxcZone::start(const char* const* argv) refresh(); // we have to check status because lxc-start runs in daemonized mode - if (!mContainer->is_running(mContainer)) { + if (!mLxcContainer->is_running(mLxcContainer)) { LOGE("Could not start init in zone " << getName()); return false; } return true; #else - if (mContainer->is_running(mContainer)) { + if (mLxcContainer->is_running(mLxcContainer)) { LOGE("Already started " << getName()); return false; } - if (!mContainer->want_daemonize(mContainer, true)) { + if (!mLxcContainer->want_daemonize(mLxcContainer, true)) { LOGE("Could not configure zone " << getName()); return false; } - if (!mContainer->start(mContainer, false, const_cast(argv))) { + if (!mLxcContainer->start(mLxcContainer, false, const_cast(argv))) { LOGE("Could not start zone " << getName()); return false; } @@ -216,7 +216,7 @@ bool LxcZone::start(const char* const* argv) bool LxcZone::stop() { - if (!mContainer->stop(mContainer)) { + if (!mLxcContainer->stop(mLxcContainer)) { LOGE("Could not stop zone " << getName()); return false; } @@ -225,7 +225,7 @@ bool LxcZone::stop() bool LxcZone::reboot() { - if (!mContainer->reboot(mContainer)) { + if (!mLxcContainer->reboot(mLxcContainer)) { LOGE("Could not reboot zone " << getName()); return false; } @@ -247,8 +247,8 @@ bool LxcZone::shutdown(int timeout) utils::CStringArrayBuilder args; std::string timeoutStr = std::to_string(timeout); args.add("lxc-stop") - .add("-n").add(mContainer->name) - .add("-P").add(mContainer->config_path) + .add("-n").add(mLxcContainer->name) + .add("-P").add(mLxcContainer->config_path) .add("-t").add(timeoutStr.c_str()) .add("--nokill"); @@ -271,7 +271,7 @@ bool LxcZone::shutdown(int timeout) LOGW("SetRunLevel failed for zone " + getName()); // fallback for other inits like bash: lxc sends 'lxc.haltsignal' signal to init - if (!mContainer->shutdown(mContainer, timeout)) { + if (!mLxcContainer->shutdown(mLxcContainer, timeout)) { LOGE("Could not gracefully shutdown zone " << getName() << " in " << timeout << "s"); return false; } @@ -281,7 +281,7 @@ bool LxcZone::shutdown(int timeout) bool LxcZone::freeze() { - if (!mContainer->freeze(mContainer)) { + if (!mLxcContainer->freeze(mLxcContainer)) { LOGE("Could not freeze zone " << getName()); return false; } @@ -290,7 +290,7 @@ bool LxcZone::freeze() bool LxcZone::unfreeze() { - if (!mContainer->unfreeze(mContainer)) { + if (!mLxcContainer->unfreeze(mLxcContainer)) { LOGE("Could not unfreeze zone " << getName()); return false; } @@ -299,7 +299,7 @@ bool LxcZone::unfreeze() bool LxcZone::waitForState(State state, int timeout) { - if (!mContainer->wait(mContainer, toString(state).c_str(), timeout)) { + if (!mLxcContainer->wait(mLxcContainer, toString(state).c_str(), timeout)) { LOGD("Timeout while waiting for state " << toString(state) << " of zone " << getName()); return false; } @@ -315,7 +315,7 @@ bool LxcZone::setRunLevel(int runLevel) lxc_attach_options_t options = LXC_ATTACH_OPTIONS_DEFAULT; pid_t pid; - int ret = mContainer->attach(mContainer, callback, &runLevel, &options, &pid); + int ret = mLxcContainer->attach(mLxcContainer, callback, &runLevel, &options, &pid); if (ret != 0) { return false; } @@ -329,10 +329,10 @@ bool LxcZone::setRunLevel(int runLevel) void LxcZone::refresh() { //TODO Consider make LxcZone state-less - std::string zoneName = mContainer->name; - std::string lxcPath = mContainer->config_path; - lxc_container_put(mContainer); - mContainer = lxc_container_new(zoneName.c_str(), lxcPath.c_str()); + std::string zoneName = mLxcContainer->name; + std::string lxcPath = mLxcContainer->config_path; + lxc_container_put(mLxcContainer); + mLxcContainer = lxc_container_new(zoneName.c_str(), lxcPath.c_str()); } diff --git a/common/lxc/zone.hpp b/common/lxc/zone.hpp index 9b29f6f..1573c7d 100644 --- a/common/lxc/zone.hpp +++ b/common/lxc/zone.hpp @@ -35,7 +35,7 @@ namespace lxc { /** - * A class wwapping lxc container + * A class wrapping lxc container */ class LxcZone { public: @@ -52,7 +52,7 @@ public: /** * LxcZone constructor - * @param lxcPath path where containers lives + * @param lxcPath path where zones lives * @param zoneName name of zone */ LxcZone(const std::string& lxcPath, const std::string& zoneName); @@ -137,7 +137,7 @@ public: */ bool unfreeze(); private: - lxc_container* mContainer; + lxc_container* mLxcContainer; bool setRunLevel(int runLevel); void refresh(); diff --git a/container-daemon/configs/org.tizen.containers.zone.daemon.conf.in b/container-daemon/configs/org.tizen.containers.zone.daemon.conf.in deleted file mode 100644 index f66921a..0000000 --- a/container-daemon/configs/org.tizen.containers.zone.daemon.conf.in +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - diff --git a/container-support/configs/org.tizen.containers.zone.conf.in b/container-support/configs/org.tizen.containers.zone.conf.in deleted file mode 100644 index 384c8c6..0000000 --- a/container-support/configs/org.tizen.containers.zone.conf.in +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - diff --git a/packaging/vasum-container-support.manifest b/packaging/vasum-zone-daemon.manifest similarity index 100% rename from packaging/vasum-container-support.manifest rename to packaging/vasum-zone-daemon.manifest diff --git a/packaging/vasum-container-daemon.manifest b/packaging/vasum-zone-support.manifest similarity index 100% rename from packaging/vasum-container-daemon.manifest rename to packaging/vasum-zone-support.manifest diff --git a/packaging/vasum.spec b/packaging/vasum.spec index 74114e3..78db5de 100644 --- a/packaging/vasum.spec +++ b/packaging/vasum.spec @@ -15,7 +15,7 @@ Release: 0 Source0: %{name}-%{version}.tar.gz License: Apache-2.0 Group: Security/Other -Summary: Daemon for managing containers +Summary: Daemon for managing zones BuildRequires: cmake BuildRequires: boost-devel BuildRequires: libjson-devel >= 0.10 @@ -32,25 +32,25 @@ Requires(post): libcap-tools Requires: bridge-utils %description -This package provides a daemon used to manage containers - start, stop and switch -between them. A process from inside a container can request a switch of context -(display, input devices) to the other container. +This package provides a daemon used to manage zones - start, stop and switch +between them. A process from inside a zone can request a switch of context +(display, input devices) to the other zone. %files %manifest packaging/vasum.manifest %defattr(644,root,root,755) %attr(755,root,root) %{_bindir}/vasum-server %dir /etc/vasum -%dir /etc/vasum/containers +%dir /etc/vasum/zones %dir /etc/vasum/lxc-templates %dir /etc/vasum/templates %config /etc/vasum/daemon.conf -%config /etc/vasum/containers/*.conf +%config /etc/vasum/zones/*.conf %attr(755,root,root) /etc/vasum/lxc-templates/*.sh %config /etc/vasum/templates/*.conf %{_unitdir}/vasum.service %{_unitdir}/multi-user.target.wants/vasum.service -/etc/dbus-1/system.d/org.tizen.containers.host.conf +/etc/dbus-1/system.d/org.tizen.vasum.host.conf %prep %setup -q @@ -150,37 +150,37 @@ Development package including the header files for the client library %{_libdir}/pkgconfig/*.pc -## Container Support Package ################################################### +## Zone Support Package ################################################### # TODO move to a separate repository -%package container-support +%package zone-support Summary: Vasum Support Group: Security/Other Conflicts: vasum -%description container-support -Containers support installed inside every container. +%description zone-support +Zones support installed inside every zone. -%files container-support -%manifest packaging/vasum-container-support.manifest +%files zone-support +%manifest packaging/vasum-zone-support.manifest %defattr(644,root,root,755) -/etc/dbus-1/system.d/org.tizen.containers.zone.conf +/etc/dbus-1/system.d/org.tizen.vasum.zone.conf -## Container Daemon Package #################################################### +## Zone Daemon Package #################################################### # TODO move to a separate repository -%package container-daemon -Summary: Vasum Containers Daemon +%package zone-daemon +Summary: Vasum Zones Daemon Group: Security/Other -Requires: vasum-container-support = %{version}-%{release} +Requires: vasum-zone-support = %{version}-%{release} -%description container-daemon -Daemon running inside every container. +%description zone-daemon +Daemon running inside every zone. -%files container-daemon -%manifest packaging/vasum-container-daemon.manifest +%files zone-daemon +%manifest packaging/vasum-zone-daemon.manifest %defattr(644,root,root,755) -%attr(755,root,root) %{_bindir}/vasum-container-daemon -/etc/dbus-1/system.d/org.tizen.containers.zone.daemon.conf +%attr(755,root,root) %{_bindir}/vasum-zone-daemon +/etc/dbus-1/system.d/org.tizen.vasum.zone.daemon.conf ## Command Line Interface ###################################################### @@ -221,4 +221,4 @@ Unit tests for both: server and client and integration tests. %{_datadir}/vasum/tests %attr(755,root,root) %{_datadir}/vasum/lxc-templates %{python_sitelib}/vsm_integration_tests -/etc/dbus-1/system.d/org.tizen.containers.tests.conf +/etc/dbus-1/system.d/org.tizen.vasum.tests.conf diff --git a/server/common-dbus-definitions.hpp b/server/common-dbus-definitions.hpp index de355b3..178f363 100644 --- a/server/common-dbus-definitions.hpp +++ b/server/common-dbus-definitions.hpp @@ -30,11 +30,11 @@ namespace vasum { namespace api { -const std::string ERROR_FORBIDDEN = "org.tizen.containers.Error.Forbidden"; -const std::string ERROR_FORWARDED = "org.tizen.containers.Error.Forwarded"; -const std::string ERROR_INVALID_ID = "org.tizen.containers.Error.InvalidId"; -const std::string ERROR_INVALID_STATE = "org.tizen.containers.Error.InvalidState"; -const std::string ERROR_INTERNAL = "org.tizen.containers.Error.Internal"; +const std::string ERROR_FORBIDDEN = "org.tizen.vasum.Error.Forbidden"; +const std::string ERROR_FORWARDED = "org.tizen.vasum.Error.Forwarded"; +const std::string ERROR_INVALID_ID = "org.tizen.vasum.Error.InvalidId"; +const std::string ERROR_INVALID_STATE = "org.tizen.vasum.Error.InvalidState"; +const std::string ERROR_INTERNAL = "org.tizen.vasum.Error.Internal"; const std::string METHOD_PROXY_CALL = "ProxyCall"; diff --git a/server/configs/CMakeLists.txt b/server/configs/CMakeLists.txt index cb4d003..b5c9286 100644 --- a/server/configs/CMakeLists.txt +++ b/server/configs/CMakeLists.txt @@ -19,7 +19,7 @@ MESSAGE(STATUS "Installing configs to " ${VSM_CONFIG_INSTALL_DIR}) -FILE(GLOB container_CONF containers/*.conf) +FILE(GLOB zone_CONF zones/*.conf) FILE(GLOB admin_CONF lxc-templates/*.sh) FILE(GLOB template_CONF templates/*.conf) @@ -33,14 +33,14 @@ INSTALL(FILES daemon.conf DESTINATION ${VSM_CONFIG_INSTALL_DIR}) # preprocess d-bus configs -CONFIGURE_FILE(dbus-1/system.d/org.tizen.containers.host.conf.in - ${CMAKE_BINARY_DIR}/dbus-1/system.d/org.tizen.containers.host.conf) +CONFIGURE_FILE(dbus-1/system.d/org.tizen.vasum.host.conf.in + ${CMAKE_BINARY_DIR}/dbus-1/system.d/org.tizen.vasum.host.conf) -INSTALL(FILES ${CMAKE_BINARY_DIR}/dbus-1/system.d/org.tizen.containers.host.conf +INSTALL(FILES ${CMAKE_BINARY_DIR}/dbus-1/system.d/org.tizen.vasum.host.conf DESTINATION ${SYSCONF_INSTALL_DIR}/dbus-1/system.d/) -INSTALL(FILES ${container_CONF} - DESTINATION ${VSM_CONFIG_INSTALL_DIR}/containers) +INSTALL(FILES ${zone_CONF} + DESTINATION ${VSM_CONFIG_INSTALL_DIR}/zones) INSTALL(PROGRAMS ${admin_CONF} DESTINATION ${VSM_CONFIG_INSTALL_DIR}/lxc-templates) diff --git a/server/configs/daemon.conf b/server/configs/daemon.conf index 7a0f8c1..714640e 100644 --- a/server/configs/daemon.conf +++ b/server/configs/daemon.conf @@ -1,10 +1,10 @@ { - "containerConfigs" : ["containers/private.conf", "containers/business.conf"], - "containersPath" : "/opt/usr/containers", - "containerImagePath" : "/opt/usr/containers/img/system-data.img", - "containerTemplatePath" : "templates", - "containerNewConfigPrefix" : "/var/lib/vasum", - "runMountPointPrefix" : "/var/run/containers", + "zoneConfigs" : ["zones/private.conf", "zones/business.conf"], + "zonesPath" : "/opt/usr/zones", + "zoneImagePath" : "/opt/usr/zones/img/system-data.img", + "zoneTemplatePath" : "templates", + "zoneNewConfigPrefix" : "/var/lib/vasum", + "runMountPointPrefix" : "/var/run/zones", "foregroundId" : "private", "defaultId" : "private", "lxcTemplatePrefix" : "/etc/vasum/lxc-templates", diff --git a/server/configs/dbus-1/system.d/org.tizen.containers.host.conf.in b/server/configs/dbus-1/system.d/org.tizen.containers.host.conf.in deleted file mode 100644 index 948a731..0000000 --- a/server/configs/dbus-1/system.d/org.tizen.containers.host.conf.in +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - - - - - - - - - diff --git a/server/configs/dbus-1/system.d/org.tizen.vasum.host.conf.in b/server/configs/dbus-1/system.d/org.tizen.vasum.host.conf.in new file mode 100644 index 0000000..81f9540 --- /dev/null +++ b/server/configs/dbus-1/system.d/org.tizen.vasum.host.conf.in @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + diff --git a/server/configs/lxc-templates/template.sh b/server/configs/lxc-templates/template.sh index 531ec30..c73bd01 100755 --- a/server/configs/lxc-templates/template.sh +++ b/server/configs/lxc-templates/template.sh @@ -25,7 +25,7 @@ br_name="virbr-${name}" # XXX assume rootfs if mounted from iso -# Prepare container configuration file +# Prepare zone configuration file > ${path}/config cat <> ${path}/config lxc.utsname = ${name} @@ -39,9 +39,9 @@ lxc.pts = 256 lxc.tty = 0 lxc.mount.auto = proc sys cgroup -lxc.mount.entry = /var/run/containers/${name}/run var/run none rw,bind 0 0 +lxc.mount.entry = /var/run/zones/${name}/run var/run none rw,bind 0 0 -# create a separate network per container +# create a separate network per zone # - it forbids traffic sniffing (like macvlan in bridge mode) # - it enables traffic controlling from host using iptables lxc.network.type = veth diff --git a/server/configs/lxc-templates/tizen-common-wayland.sh b/server/configs/lxc-templates/tizen-common-wayland.sh index 002e1f7..ed2df9b 100755 --- a/server/configs/lxc-templates/tizen-common-wayland.sh +++ b/server/configs/lxc-templates/tizen-common-wayland.sh @@ -22,17 +22,17 @@ usage() { cat < + $1 -n|--name= [-p|--path=] [-r|--rootfs=] [-v|--vt=] [--ipv4=] [--ipv4-gateway=] [-h|--help] Mandatory args: - -n,--name container name + -n,--name zone name Optional args: - -p,--path path to container config files, defaults to /var/lib/lxc - --rootfs path to container rootfs, defaults to /var/lib/lxc/[NAME]/rootfs - -v,--vt container virtual terminal - --ipv4 container IP address - --ipv4-gateway container gateway + -p,--path path to zone config files, defaults to /var/lib/lxc + --rootfs path to zone rootfs, defaults to /var/lib/lxc/[NAME]/rootfs + -v,--vt zone virtual terminal + --ipv4 zone IP address + --ipv4-gateway zone gateway -h,--help print help EOF return 0 @@ -66,7 +66,7 @@ if [ "$(id -u)" != "0" ]; then fi if [ -z $name ]; then - echo "Container name must be given" + echo "Zone name must be given" exit 1 fi @@ -77,7 +77,7 @@ fi br_name="virbr-${name}" -# Prepare container rootfs +# Prepare zone rootfs ROOTFS_DIRS="\ ${rootfs}/bin \ ${rootfs}/dev \ @@ -181,7 +181,7 @@ XDG_CONFIG_HOME=/etc/systemd/system EOF cat <>${path}/systemd/system/weston.ini -# Weston config for container. +# Weston config for zone. [core] modules=desktop-shell.so @@ -290,7 +290,7 @@ RestartSec=10 WantedBy=graphical.target EOF -# Prepare container configuration file +# Prepare zone configuration file cat <>${path}/config lxc.utsname = ${name} lxc.rootfs = ${rootfs} @@ -343,7 +343,7 @@ lxc.kmsg = 0 lxc.mount.auto = proc sys:rw cgroup lxc.mount = ${path}/fstab -# create a separate network per container +# create a separate network per zone # - it forbids traffic sniffing (like macvlan in bridge mode) # - it enables traffic controlling from host using iptables lxc.network.type = veth @@ -358,7 +358,7 @@ lxc.hook.pre-start = ${path}/hooks/pre-start.sh #lxc.hook.post-stop = ${path}/hooks/post-stop.sh EOF -# Prepare container hook files +# Prepare zone hook files cat <>${path}/hooks/pre-start.sh if [ -z "\$(/usr/sbin/brctl show | /bin/grep -P "${br_name}\t")" ] then @@ -375,7 +375,7 @@ EOF chmod 770 ${path}/hooks/pre-start.sh -# Prepare container fstab file +# Prepare zone fstab file cat <>${path}/fstab /bin bin none ro,bind 0 0 /etc etc none ro,bind 0 0 diff --git a/server/configs/containers/business.conf b/server/configs/zones/business.conf similarity index 100% rename from server/configs/containers/business.conf rename to server/configs/zones/business.conf diff --git a/server/configs/containers/private.conf b/server/configs/zones/private.conf similarity index 100% rename from server/configs/containers/private.conf rename to server/configs/zones/private.conf diff --git a/server/containers-manager.cpp b/server/containers-manager.cpp deleted file mode 100644 index fa3f157..0000000 --- a/server/containers-manager.cpp +++ /dev/null @@ -1,888 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved - * - * Contact: Jan Olszak - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ - -/** - * @file - * @author Jan Olszak (j.olszak@samsung.com) - * @brief Definition of the class for managing containers - */ - -#include "config.hpp" - -#include "host-dbus-definitions.hpp" -#include "common-dbus-definitions.hpp" -#include "container-dbus-definitions.hpp" -#include "containers-manager.hpp" -#include "container-admin.hpp" -#include "exception.hpp" - -#include "utils/paths.hpp" -#include "logger/logger.hpp" -#include "config/manager.hpp" -#include "dbus/exception.hpp" -#include "utils/fs.hpp" -#include "utils/img.hpp" -#include "utils/environment.hpp" - -#include -#include -#include -#include -#include -#include - - -namespace vasum { - - -namespace { - -bool regexMatchVector(const std::string& str, const std::vector& v) -{ - for (const boost::regex& toMatch: v) { - if (boost::regex_match(str, toMatch)) { - return true; - } - } - - return false; -} - -const std::string HOST_ID = "host"; -const std::string CONTAINER_TEMPLATE_CONFIG_PATH = "template.conf"; - -const boost::regex CONTAINER_NAME_REGEX("~NAME~"); -const boost::regex CONTAINER_IP_THIRD_OCTET_REGEX("~IP~"); - -const unsigned int CONTAINER_IP_BASE_THIRD_OCTET = 100; - -} // namespace - -ContainersManager::ContainersManager(const std::string& managerConfigPath): mDetachOnExit(false) -{ - LOGD("Instantiating ContainersManager object..."); - - mConfigPath = managerConfigPath; - config::loadFromFile(mConfigPath, mConfig); - - mProxyCallPolicy.reset(new ProxyCallPolicy(mConfig.proxyCallRules)); - - using namespace std::placeholders; - mHostConnection.setProxyCallCallback(bind(&ContainersManager::handleProxyCall, - this, HOST_ID, _1, _2, _3, _4, _5, _6, _7)); - - mHostConnection.setGetContainerDbusesCallback(bind( - &ContainersManager::handleGetContainerDbuses, this, _1)); - - mHostConnection.setGetContainerIdsCallback(bind(&ContainersManager::handleGetContainerIdsCall, - this, _1)); - - mHostConnection.setGetActiveContainerIdCallback(bind(&ContainersManager::handleGetActiveContainerIdCall, - this, _1)); - - mHostConnection.setGetContainerInfoCallback(bind(&ContainersManager::handleGetContainerInfoCall, - this, _1, _2)); - - mHostConnection.setDeclareFileCallback(bind(&ContainersManager::handleDeclareFileCall, - this, _1, _2, _3, _4, _5, _6)); - - mHostConnection.setDeclareMountCallback(bind(&ContainersManager::handleDeclareMountCall, - this, _1, _2, _3, _4, _5, _6, _7)); - - mHostConnection.setDeclareLinkCallback(bind(&ContainersManager::handleDeclareLinkCall, - this, _1, _2, _3, _4)); - - mHostConnection.setSetActiveContainerCallback(bind(&ContainersManager::handleSetActiveContainerCall, - this, _1, _2)); - - mHostConnection.setCreateContainerCallback(bind(&ContainersManager::handleCreateContainerCall, - this, _1, _2)); - - mHostConnection.setDestroyContainerCallback(bind(&ContainersManager::handleDestroyContainerCall, - this, _1, _2)); - - mHostConnection.setLockContainerCallback(bind(&ContainersManager::handleLockContainerCall, - this, _1, _2)); - - mHostConnection.setUnlockContainerCallback(bind(&ContainersManager::handleUnlockContainerCall, - this, _1, _2)); - - for (auto& containerConfig : mConfig.containerConfigs) { - createContainer(containerConfig); - } - - // check if default container exists, throw ContainerOperationException if not found - if (!mConfig.defaultId.empty() && mContainers.find(mConfig.defaultId) == mContainers.end()) { - LOGE("Provided default container ID " << mConfig.defaultId << " is invalid."); - throw ContainerOperationException("Provided default container ID " + mConfig.defaultId + - " is invalid."); - } - - LOGD("ContainersManager object instantiated"); - - if (mConfig.inputConfig.enabled) { - LOGI("Registering input monitor [" << mConfig.inputConfig.device.c_str() << "]"); - mSwitchingSequenceMonitor.reset( - new InputMonitor(mConfig.inputConfig, - std::bind(&ContainersManager::switchingSequenceMonitorNotify, - this))); - } - - -} - -ContainersManager::~ContainersManager() -{ - LOGD("Destroying ContainersManager object..."); - - if (!mDetachOnExit) { - try { - stopAll(); - } catch (ServerException&) { - LOGE("Failed to stop all of the containers"); - } - } - - LOGD("ContainersManager object destroyed"); -} - -void ContainersManager::createContainer(const std::string& containerConfig) -{ - std::string baseConfigPath = utils::dirName(mConfigPath); - std::string containerConfigPath = utils::getAbsolutePath(containerConfig, baseConfigPath); - - LOGT("Creating Container " << containerConfigPath); - std::unique_ptr c(new Container(mConfig.containersPath, - containerConfigPath, - mConfig.lxcTemplatePrefix, - mConfig.runMountPointPrefix)); - const std::string id = c->getId(); - if (id == HOST_ID) { - throw ContainerOperationException("Cannot use reserved container ID"); - } - - using namespace std::placeholders; - c->setNotifyActiveContainerCallback(bind(&ContainersManager::notifyActiveContainerHandler, - this, id, _1, _2)); - - c->setDisplayOffCallback(bind(&ContainersManager::displayOffHandler, - this, id)); - - c->setFileMoveRequestCallback(bind(&ContainersManager::handleContainerMoveFileRequest, - this, id, _1, _2, _3)); - - c->setProxyCallCallback(bind(&ContainersManager::handleProxyCall, - this, id, _1, _2, _3, _4, _5, _6, _7)); - - c->setDbusStateChangedCallback(bind(&ContainersManager::handleDbusStateChanged, - this, id, _1)); - - mContainers.insert(ContainerMap::value_type(id, std::move(c))); -} - -void ContainersManager::destroyContainer(const std::string& containerId) -{ - // TODO mutex for mContainers access - auto it = mContainers.find(containerId); - if (it == mContainers.end()) { - LOGE("Failed to destroy container " << containerId << ": no such container"); - throw ContainerOperationException("No such container"); - } - - // TODO give back the focus - it->second->setDestroyOnExit(); - mContainers.erase(it); -} - -void ContainersManager::focus(const std::string& containerId) -{ - /* try to access the object first to throw immediately if it doesn't exist */ - ContainerMap::mapped_type& foregroundContainer = mContainers.at(containerId); - - if (!foregroundContainer->activateVT()) { - LOGE("Failed to activate containers VT. Aborting focus."); - return; - } - - for (auto& container : mContainers) { - LOGD(container.second->getId() << ": being sent to background"); - container.second->goBackground(); - } - mConfig.foregroundId = foregroundContainer->getId(); - LOGD(mConfig.foregroundId << ": being sent to foreground"); - foregroundContainer->goForeground(); -} - -void ContainersManager::startAll() -{ - LOGI("Starting all containers"); - - bool isForegroundFound = false; - - for (auto& container : mContainers) { - container.second->start(); - - if (container.first == mConfig.foregroundId) { - isForegroundFound = true; - LOGI(container.second->getId() << ": set as the foreground container"); - container.second->goForeground(); - } - } - - if (!isForegroundFound) { - auto foregroundIterator = std::min_element(mContainers.begin(), mContainers.end(), - [](ContainerMap::value_type &c1, ContainerMap::value_type &c2) { - return c1.second->getPrivilege() < c2.second->getPrivilege(); - }); - - if (foregroundIterator != mContainers.end()) { - mConfig.foregroundId = foregroundIterator->second->getId(); - LOGI(mConfig.foregroundId << ": no foreground container configured, setting one with highest priority"); - foregroundIterator->second->goForeground(); - } - } -} - -void ContainersManager::stopAll() -{ - LOGI("Stopping all containers"); - - for (auto& container : mContainers) { - container.second->stop(); - } -} - -bool ContainersManager::isPaused(const std::string& containerId) -{ - auto iter = mContainers.find(containerId); - if (iter == mContainers.end()) { - LOGE("No such container id: " << containerId); - throw ContainerOperationException("No such container"); - } - - return iter->second->isPaused(); -} - -bool ContainersManager::isRunning(const std::string& containerId) -{ - auto iter = mContainers.find(containerId); - if (iter == mContainers.end()) { - LOGE("No such container id: " << containerId); - throw ContainerOperationException("No such container"); - } - return iter->second->isRunning(); -} - -std::string ContainersManager::getRunningForegroundContainerId() -{ - for (auto& container : mContainers) { - if (container.first == mConfig.foregroundId && - container.second->isRunning()) { - return container.first; - } - } - return std::string(); -} - -std::string ContainersManager::getNextToForegroundContainerId() -{ - // handles case where there is no next container - if (mContainers.size() < 2) { - return std::string(); - } - - for (auto it = mContainers.begin(); it != mContainers.end(); ++it) { - if (it->first == mConfig.foregroundId && - it->second->isRunning()) { - auto nextIt = std::next(it); - if (nextIt != mContainers.end()) { - return nextIt->first; - } - } - } - return mContainers.begin()->first; -} - -void ContainersManager::switchingSequenceMonitorNotify() -{ - LOGI("switchingSequenceMonitorNotify() called"); - - auto nextContainerId = getNextToForegroundContainerId(); - - if (!nextContainerId.empty()) { - focus(nextContainerId); - } -} - - -void ContainersManager::setContainersDetachOnExit() -{ - mDetachOnExit = true; - - for (auto& container : mContainers) { - container.second->setDetachOnExit(); - } -} - -void ContainersManager::notifyActiveContainerHandler(const std::string& caller, - const std::string& application, - const std::string& message) -{ - LOGI("notifyActiveContainerHandler(" << caller << ", " << application << ", " << message - << ") called"); - try { - const std::string activeContainer = getRunningForegroundContainerId(); - if (!activeContainer.empty() && caller != activeContainer) { - mContainers[activeContainer]->sendNotification(caller, application, message); - } - } catch(const VasumException&) { - LOGE("Notification from " << caller << " hasn't been sent"); - } -} - -void ContainersManager::displayOffHandler(const std::string& /*caller*/) -{ - // 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, - const std::string& dstContainerId, - const std::string& path, - dbus::MethodResultBuilder::Pointer result) -{ - // TODO: this implementation is only a placeholder. - // There are too many unanswered questions and security concerns: - // 1. What about mount namespace, host might not see the source/destination - // file. The file might be a different file from a host perspective. - // 2. Copy vs move (speed and security concerns over already opened FDs) - // 3. Access to source and destination files - DAC, uid/gig - // 4. Access to source and destintation files - MAC, smack - // 5. Destination file uid/gid assignment - // 6. Destination file smack label assignment - // 7. Verifiability of the source path - - // NOTE: other possible implementations include: - // 1. Sending file descriptors opened directly in each container through DBUS - // using something like g_dbus_message_set_unix_fd_list() - // 2. VSM forking and calling setns(MNT) in each container and opening files - // by itself, then passing FDs to the main process - // Now when the main process has obtained FDs (by either of those methods) - // it can do the copying by itself. - - LOGI("File move requested\n" - << "src: " << srcContainerId << "\n" - << "dst: " << dstContainerId << "\n" - << "path: " << path); - - ContainerMap::const_iterator srcIter = mContainers.find(srcContainerId); - if (srcIter == mContainers.end()) { - LOGE("Source container '" << srcContainerId << "' not found"); - return; - } - Container& srcContainer = *srcIter->second; - - ContainerMap::const_iterator dstIter = mContainers.find(dstContainerId); - if (dstIter == mContainers.end()) { - LOGE("Destination container '" << dstContainerId << "' not found"); - result->set(g_variant_new("(s)", api::container::FILE_MOVE_DESTINATION_NOT_FOUND.c_str())); - return; - } - Container& dstContanier = *dstIter->second; - - if (srcContainerId == dstContainerId) { - LOGE("Cannot send a file to yourself"); - result->set(g_variant_new("(s)", api::container::FILE_MOVE_WRONG_DESTINATION.c_str())); - return; - } - - if (!regexMatchVector(path, srcContainer.getPermittedToSend())) { - LOGE("Source container has no permissions to send the file: " << path); - result->set(g_variant_new("(s)", api::container::FILE_MOVE_NO_PERMISSIONS_SEND.c_str())); - return; - } - - if (!regexMatchVector(path, dstContanier.getPermittedToRecv())) { - LOGE("Destination container has no permissions to receive the file: " << path); - result->set(g_variant_new("(s)", api::container::FILE_MOVE_NO_PERMISSIONS_RECEIVE.c_str())); - return; - } - - namespace fs = boost::filesystem; - std::string srcPath = fs::absolute(srcContainerId, mConfig.containersPath).string() + path; - std::string dstPath = fs::absolute(dstContainerId, mConfig.containersPath).string() + path; - - if (!utils::moveFile(srcPath, dstPath)) { - LOGE("Failed to move the file: " << path); - result->set(g_variant_new("(s)", api::container::FILE_MOVE_FAILED.c_str())); - } else { - result->set(g_variant_new("(s)", api::container::FILE_MOVE_SUCCEEDED.c_str())); - try { - dstContanier.sendNotification(srcContainerId, path, api::container::FILE_MOVE_SUCCEEDED); - } catch (ServerException&) { - LOGE("Notification to '" << dstContainerId << "' has not been sent"); - } - } -} - -void ContainersManager::handleProxyCall(const std::string& caller, - const std::string& target, - const std::string& targetBusName, - const std::string& targetObjectPath, - const std::string& targetInterface, - const std::string& targetMethod, - GVariant* parameters, - dbus::MethodResultBuilder::Pointer result) -{ - if (!mProxyCallPolicy->isProxyCallAllowed(caller, - target, - targetBusName, - targetObjectPath, - targetInterface, - targetMethod)) { - LOGW("Forbidden proxy call; " << caller << " -> " << target << "; " << targetBusName - << "; " << targetObjectPath << "; " << targetInterface << "; " << targetMethod); - result->setError(api::ERROR_FORBIDDEN, "Proxy call forbidden"); - return; - } - - LOGI("Proxy call; " << caller << " -> " << target << "; " << targetBusName - << "; " << targetObjectPath << "; " << targetInterface << "; " << targetMethod); - - auto asyncResultCallback = [result](dbus::AsyncMethodCallResult& asyncMethodCallResult) { - try { - GVariant* targetResult = asyncMethodCallResult.get(); - result->set(g_variant_new("(v)", targetResult)); - } catch (dbus::DbusException& e) { - result->setError(api::ERROR_FORWARDED, e.what()); - } - }; - - if (target == HOST_ID) { - mHostConnection.proxyCallAsync(targetBusName, - targetObjectPath, - targetInterface, - targetMethod, - parameters, - asyncResultCallback); - return; - } - - ContainerMap::const_iterator targetIter = mContainers.find(target); - if (targetIter == mContainers.end()) { - LOGE("Target container '" << target << "' not found"); - result->setError(api::ERROR_INVALID_ID, "Unknown proxy call target"); - return; - } - - Container& targetContainer = *targetIter->second; - targetContainer.proxyCallAsync(targetBusName, - targetObjectPath, - targetInterface, - targetMethod, - parameters, - asyncResultCallback); -} - -void ContainersManager::handleGetContainerDbuses(dbus::MethodResultBuilder::Pointer result) -{ - std::vector entries; - for (auto& container : mContainers) { - GVariant* containerId = g_variant_new_string(container.first.c_str()); - GVariant* dbusAddress = g_variant_new_string(container.second->getDbusAddress().c_str()); - GVariant* entry = g_variant_new_dict_entry(containerId, dbusAddress); - entries.push_back(entry); - } - GVariant* dict = g_variant_new_array(G_VARIANT_TYPE("{ss}"), entries.data(), entries.size()); - result->set(g_variant_new("(*)", dict)); -} - -void ContainersManager::handleDbusStateChanged(const std::string& containerId, - const std::string& dbusAddress) -{ - mHostConnection.signalContainerDbusState(containerId, dbusAddress); -} - -void ContainersManager::handleGetContainerIdsCall(dbus::MethodResultBuilder::Pointer result) -{ - std::vector containerIds; - for(auto& container: mContainers){ - containerIds.push_back(g_variant_new_string(container.first.c_str())); - } - - GVariant* array = g_variant_new_array(G_VARIANT_TYPE("s"), - containerIds.data(), - containerIds.size()); - result->set(g_variant_new("(*)", array)); -} - -void ContainersManager::handleGetActiveContainerIdCall(dbus::MethodResultBuilder::Pointer result) -{ - LOGI("GetActiveContainerId call"); - if (!mConfig.foregroundId.empty() && mContainers[mConfig.foregroundId]->isRunning()){ - result->set(g_variant_new("(s)", mConfig.foregroundId.c_str())); - } else { - result->set(g_variant_new("(s)", "")); - } -} - -void ContainersManager::handleGetContainerInfoCall(const std::string& id, - dbus::MethodResultBuilder::Pointer result) -{ - LOGI("GetContainerInfo call"); - if (mContainers.count(id) == 0) { - LOGE("No container with id=" << id); - result->setError(api::ERROR_INVALID_ID, "No such container id"); - return; - } - const auto& container = mContainers[id]; - const char* state; - //TODO: Use the lookup map. - if (container->isRunning()) { - state = "RUNNING"; - } else if (container->isStopped()) { - state = "STOPPED"; - } else if (container->isPaused()) { - state = "FROZEN"; - } else { - LOGE("Unrecognized state of container id=" << id); - result->setError(api::ERROR_INTERNAL, "Unrecognized state of container"); - return; - } - const auto containerPath = boost::filesystem::absolute(id, mConfig.containersPath); - const auto rootfsDir = boost::filesystem::path("rootfs"); - const auto rootfsPath = containerPath / rootfsDir; - - result->set(g_variant_new("((siss))", - id.c_str(), - container->getVT(), - state, - rootfsPath.string().c_str())); -} - -void ContainersManager::handleDeclareFileCall(const std::string& container, - const int32_t& type, - const std::string& path, - const int32_t& flags, - const int32_t& mode, - dbus::MethodResultBuilder::Pointer result) -{ - LOGI("DeclareFile call"); - try { - mContainers.at(container)->declareFile(type, path, flags, mode); - result->setVoid(); - } catch (const std::out_of_range& ex) { - LOGE("No container with id=" << container); - result->setError(api::ERROR_INVALID_ID, "No such container id"); - } catch (const config::ConfigException& ex) { - LOGE("Can't declare file: " << ex.what()); - result->setError(api::ERROR_INTERNAL, "Internal error"); - } -} - -void ContainersManager::handleDeclareMountCall(const std::string& source, - const std::string& container, - const std::string& target, - const std::string& type, - const uint64_t& flags, - const std::string& data, - dbus::MethodResultBuilder::Pointer result) -{ - LOGI("DeclareMount call"); - try { - mContainers.at(container)->declareMount(source, target, type, flags, data); - result->setVoid(); - } catch (const std::out_of_range& ex) { - LOGE("No container with id=" << container); - result->setError(api::ERROR_INVALID_ID, "No such container id"); - } catch (const config::ConfigException& ex) { - LOGE("Can't declare mount: " << ex.what()); - result->setError(api::ERROR_INTERNAL, "Internal error"); - } -} - -void ContainersManager::handleDeclareLinkCall(const std::string& source, - const std::string& container, - const std::string& target, - dbus::MethodResultBuilder::Pointer result) -{ - LOGI("DeclareLink call"); - try { - mContainers.at(container)->declareLink(source, target); - result->setVoid(); - } catch (const std::out_of_range& ex) { - LOGE("No container with id=" << container); - result->setError(api::ERROR_INVALID_ID, "No such container id"); - } catch (const config::ConfigException& ex) { - LOGE("Can't declare link: " << ex.what()); - result->setError(api::ERROR_INTERNAL, "Internal error"); - } -} - -void ContainersManager::handleSetActiveContainerCall(const std::string& id, - dbus::MethodResultBuilder::Pointer result) -{ - LOGI("SetActiveContainer call; Id=" << id ); - auto container = mContainers.find(id); - if (container == mContainers.end()){ - LOGE("No container with id=" << id ); - result->setError(api::ERROR_INVALID_ID, "No such container id"); - return; - } - - if (container->second->isStopped()){ - LOGE("Could not activate a stopped container"); - result->setError(api::host::ERROR_CONTAINER_STOPPED, - "Could not activate a stopped container"); - return; - } - - focus(id); - result->setVoid(); -} - - -void ContainersManager::generateNewConfig(const std::string& id, - const std::string& templatePath, - const std::string& resultPath) -{ - namespace fs = boost::filesystem; - - std::string resultFileDir = utils::dirName(resultPath); - if (!fs::exists(resultFileDir)) { - if (!utils::createEmptyDir(resultFileDir)) { - LOGE("Unable to create directory for new config."); - throw ContainerOperationException("Unable to create directory for new config."); - } - } - - fs::path resultFile(resultPath); - if (fs::exists(resultFile)) { - LOGT(resultPath << " already exists, removing"); - fs::remove(resultFile); - } - - std::string config; - if (!utils::readFileContent(templatePath, config)) { - LOGE("Failed to read template config file."); - throw ContainerOperationException("Failed to read template config file."); - } - - std::string resultConfig = boost::regex_replace(config, CONTAINER_NAME_REGEX, id); - - // generate third IP octet for network config - // TODO change algorithm after implementing removeContainer - std::string thirdOctetStr = std::to_string(CONTAINER_IP_BASE_THIRD_OCTET + mContainers.size() + 1); - LOGD("IP third octet: " << thirdOctetStr); - resultConfig = boost::regex_replace(resultConfig, CONTAINER_IP_THIRD_OCTET_REGEX, thirdOctetStr); - - if (!utils::saveFileContent(resultPath, resultConfig)) { - LOGE("Faield to save new config file."); - throw ContainerOperationException("Failed to save new config file."); - } - - // restrict new config file so that only owner (vasum) can write it - fs::permissions(resultPath, fs::perms::owner_all | - fs::perms::group_read | - fs::perms::others_read); -} - -void ContainersManager::handleCreateContainerCall(const std::string& id, - dbus::MethodResultBuilder::Pointer result) -{ - if (id.empty()) { - LOGE("Failed to add container - invalid name."); - result->setError(api::ERROR_INVALID_ID, "Invalid name"); - return; - } - - LOGI("Creating container " << id); - - // TODO: This solution is temporary. It utilizes direct access to config files when creating new - // containers. Update this handler when config database will appear. - namespace fs = boost::filesystem; - - // check if container does not exist - if (mContainers.find(id) != mContainers.end()) { - LOGE("Cannot create " << id << " container - already exists!"); - result->setError(api::ERROR_INVALID_ID, "Already exists"); - return; - } - - const std::string containerPathStr = utils::createFilePath(mConfig.containersPath, "/", id, "/"); - - // copy container image if config contains path to image - LOGT("Image path: " << mConfig.containerImagePath); - if (!mConfig.containerImagePath.empty()) { - auto copyImageContentsWrapper = std::bind(&utils::copyImageContents, - mConfig.containerImagePath, - containerPathStr); - - if (!utils::launchAsRoot(copyImageContentsWrapper)) { - LOGE("Failed to copy container image."); - result->setError(api::ERROR_INTERNAL, "Failed to copy container image."); - return; - } - } - - // generate paths to new configuration files - std::string baseDir = utils::dirName(mConfigPath); - std::string configDir = utils::getAbsolutePath(mConfig.containerNewConfigPrefix, baseDir); - std::string templateDir = utils::getAbsolutePath(mConfig.containerTemplatePath, baseDir); - - std::string configPath = utils::createFilePath(templateDir, "/", CONTAINER_TEMPLATE_CONFIG_PATH); - std::string newConfigPath = utils::createFilePath(configDir, "/containers/", id + ".conf"); - - auto removeAllWrapper = [](const std::string& path) -> bool { - try { - LOGD("Removing copied data"); - fs::remove_all(fs::path(path)); - } catch(const std::exception& e) { - LOGW("Failed to remove data: " << boost::diagnostic_information(e)); - } - return true; - }; - - try { - LOGI("Generating config from " << configPath << " to " << newConfigPath); - generateNewConfig(id, configPath, newConfigPath); - - } catch (VasumException& e) { - LOGE("Generate config failed: " << e.what()); - utils::launchAsRoot(std::bind(removeAllWrapper, containerPathStr)); - result->setError(api::ERROR_INTERNAL, "Failed to generate config"); - return; - } - - LOGT("Creating new container"); - try { - createContainer(newConfigPath); - } catch (VasumException& e) { - LOGE("Creating new container failed: " << e.what()); - utils::launchAsRoot(std::bind(removeAllWrapper, containerPathStr)); - result->setError(api::ERROR_INTERNAL, "Failed to create container"); - return; - } - - auto resultCallback = [this, id, result](bool succeeded) { - if (succeeded) { - focus(id); - result->setVoid(); - } else { - LOGE("Failed to start container."); - // TODO removeContainer - result->setError(api::ERROR_INTERNAL, "Failed to start container"); - } - }; - mContainers[id]->startAsync(resultCallback); -} - -void ContainersManager::handleDestroyContainerCall(const std::string& id, - dbus::MethodResultBuilder::Pointer result) -{ - if (mContainers.find(id) == mContainers.end()) { - LOGE("Failed to destroy container - no such container id: " << id); - result->setError(api::ERROR_INVALID_ID, "No such container id"); - return; - } - - LOGI("Destroying container " << id); - - auto destroyer = [id, result, this] { - try { - destroyContainer(id); - } catch (const VasumException& e) { - LOGE("Error during container destruction: " << e.what()); - result->setError(api::ERROR_INTERNAL, "Failed to destroy container"); - return; - } - result->setVoid(); - }; - - std::thread thread(destroyer); - thread.detach(); //TODO fix it -} - -void ContainersManager::handleLockContainerCall(const std::string& id, - dbus::MethodResultBuilder::Pointer result) -{ - LOGI("LockContainer call; Id=" << id ); - auto iter = mContainers.find(id); - if (iter == mContainers.end()) { - LOGE("Failed to lock container - no such container id: " << id); - result->setError(api::ERROR_INVALID_ID, "No such container id"); - return; - } - - auto& container = *iter->second; - if (!container.isRunning()) { - LOGE("Container id=" << id << " is not running."); - result->setError(api::ERROR_INVALID_STATE, "Container is not running"); - return; - } - - LOGT("Lock container"); - try { - container.suspend(); - } catch (ContainerOperationException& e) { - LOGE(e.what()); - result->setError(api::ERROR_INTERNAL, e.what()); - return; - } - - result->setVoid(); -} - -void ContainersManager::handleUnlockContainerCall(const std::string& id, - dbus::MethodResultBuilder::Pointer result) -{ - LOGI("UnlockContainer call; Id=" << id ); - auto iter = mContainers.find(id); - if (iter == mContainers.end()) { - LOGE("Failed to unlock container - no such container id: " << id); - result->setError(api::ERROR_INVALID_ID, "No such container id"); - return; - } - - auto& container = *iter->second; - if (!container.isPaused()) { - LOGE("Container id=" << id << " is not paused."); - result->setError(api::ERROR_INVALID_STATE, "Container is not paused"); - return; - } - - LOGT("Unlock container"); - try { - container.resume(); - } catch (ContainerOperationException& e) { - LOGE(e.what()); - result->setError(api::ERROR_INTERNAL, e.what()); - return; - } - - result->setVoid(); -} - -} // namespace vasum diff --git a/server/exception.hpp b/server/exception.hpp index 55d7727..09eaaef 100644 --- a/server/exception.hpp +++ b/server/exception.hpp @@ -41,20 +41,20 @@ struct ServerException: public VasumException { }; /** - * Error occurred during an attempt to perform an operation on a container, - * e.g. start, stop a container + * Error occurred during an attempt to perform an operation on a zone, + * e.g. start, stop a zone */ -struct ContainerOperationException: public ServerException { +struct ZoneOperationException: public ServerException { - ContainerOperationException(const std::string& error = "") : ServerException(error) {} + ZoneOperationException(const std::string& error = "") : ServerException(error) {} }; /** - * Exception during performing an operation on a container connection + * Exception during performing an operation on a zone connection */ -struct ContainerConnectionException: public ServerException { +struct ZoneConnectionException: public ServerException { - ContainerConnectionException(const std::string& error = "") : ServerException(error) {} + ZoneConnectionException(const std::string& error = "") : ServerException(error) {} }; /** diff --git a/server/fake-power-manager-dbus-definitions.hpp b/server/fake-power-manager-dbus-definitions.hpp index f24bc81..0abeb73 100644 --- a/server/fake-power-manager-dbus-definitions.hpp +++ b/server/fake-power-manager-dbus-definitions.hpp @@ -20,7 +20,7 @@ * @file fake-power-manager-dbus-definitions.h * @author Lukasz Kostyra (l.kostyra@samsung.com) * @brief Declaration of fake dbus definitions from power-manager. Made only to test API in - * ContainerConnection. + * ZoneConnection. */ #ifndef FAKE_POWER_MANAGER_DBUS_DEFINITIONS_H @@ -29,7 +29,7 @@ /** * !!WARNING!! * - * This header file is created only to test if API in ContainerConnection works correctly. It should + * This header file is created only to test if API in ZoneConnection works correctly. It should * be removed when power-managers API will be created. */ diff --git a/server/host-connection.cpp b/server/host-connection.cpp index 37eaeba..1eed929 100644 --- a/server/host-connection.cpp +++ b/server/host-connection.cpp @@ -110,24 +110,24 @@ void HostConnection::setProxyCallCallback(const ProxyCallCallback& callback) mProxyCallCallback = callback; } -void HostConnection::setGetContainerDbusesCallback(const GetContainerDbusesCallback& callback) +void HostConnection::setGetZoneDbusesCallback(const GetZoneDbusesCallback& callback) { - mGetContainerDbusesCallback = callback; + mGetZoneDbusesCallback = callback; } -void HostConnection::setGetContainerIdsCallback(const GetContainerIdsCallback& callback) +void HostConnection::setGetZoneIdsCallback(const GetZoneIdsCallback& callback) { - mGetContainerIdsCallback = callback; + mGetZoneIdsCallback = callback; } -void HostConnection::setGetActiveContainerIdCallback(const GetActiveContainerIdCallback& callback) +void HostConnection::setGetActiveZoneIdCallback(const GetActiveZoneIdCallback& callback) { - mGetActiveContainerIdCallback = callback; + mGetActiveZoneIdCallback = callback; } -void HostConnection::setGetContainerInfoCallback(const GetContainerInfoCallback& callback) +void HostConnection::setGetZoneInfoCallback(const GetZoneInfoCallback& callback) { - mGetContainerInfoCallback = callback; + mGetZoneInfoCallback = callback; } void HostConnection::setDeclareFileCallback(const DeclareFileCallback& callback) @@ -145,29 +145,29 @@ void HostConnection::setDeclareLinkCallback(const DeclareLinkCallback& callback) mDeclareLinkCallback = callback; } -void HostConnection::setSetActiveContainerCallback(const SetActiveContainerCallback& callback) +void HostConnection::setSetActiveZoneCallback(const SetActiveZoneCallback& callback) { - mSetActiveContainerCallback = callback; + mSetActiveZoneCallback = callback; } -void HostConnection::setCreateContainerCallback(const CreateContainerCallback& callback) +void HostConnection::setCreateZoneCallback(const CreateZoneCallback& callback) { - mCreateContainerCallback = callback; + mCreateZoneCallback = callback; } -void HostConnection::setDestroyContainerCallback(const DestroyContainerCallback& callback) +void HostConnection::setDestroyZoneCallback(const DestroyZoneCallback& callback) { - mDestroyContainerCallback = callback; + mDestroyZoneCallback = callback; } -void HostConnection::setLockContainerCallback(const LockContainerCallback& callback) +void HostConnection::setLockZoneCallback(const LockZoneCallback& callback) { - mLockContainerCallback = callback; + mLockZoneCallback = callback; } -void HostConnection::setUnlockContainerCallback(const UnlockContainerCallback& callback) +void HostConnection::setUnlockZoneCallback(const UnlockZoneCallback& callback) { - mUnlockContainerCallback = callback; + mUnlockZoneCallback = callback; } @@ -181,19 +181,19 @@ void HostConnection::onMessageCall(const std::string& objectPath, return; } - if (methodName == api::host::METHOD_SET_ACTIVE_CONTAINER) { + if (methodName == api::host::METHOD_SET_ACTIVE_ZONE) { const gchar* id = NULL; g_variant_get(parameters, "(&s)", &id); - if (mSetActiveContainerCallback) { - mSetActiveContainerCallback(id, result); + if (mSetActiveZoneCallback) { + mSetActiveZoneCallback(id, result); } return; } - if (methodName == api::host::METHOD_GET_CONTAINER_DBUSES) { - if (mGetContainerDbusesCallback) { - mGetContainerDbusesCallback(result); + if (methodName == api::host::METHOD_GET_ZONE_DBUSES) { + if (mGetZoneDbusesCallback) { + mGetZoneDbusesCallback(result); } return; } @@ -227,47 +227,47 @@ void HostConnection::onMessageCall(const std::string& objectPath, return; } - if (methodName == api::host::METHOD_GET_CONTAINER_ID_LIST){ - if (mGetContainerIdsCallback){ - mGetContainerIdsCallback(result); + if (methodName == api::host::METHOD_GET_ZONE_ID_LIST){ + if (mGetZoneIdsCallback){ + mGetZoneIdsCallback(result); } return; } - if (methodName == api::host::METHOD_GET_ACTIVE_CONTAINER_ID){ - if (mGetActiveContainerIdCallback){ - mGetActiveContainerIdCallback(result); + if (methodName == api::host::METHOD_GET_ACTIVE_ZONE_ID){ + if (mGetActiveZoneIdCallback){ + mGetActiveZoneIdCallback(result); } return; } - if (methodName == api::host::METHOD_GET_CONTAINER_INFO){ + if (methodName == api::host::METHOD_GET_ZONE_INFO){ const gchar* id = NULL; g_variant_get(parameters, "(&s)", &id); - if (mGetContainerInfoCallback) { - mGetContainerInfoCallback(id, result); + if (mGetZoneInfoCallback) { + mGetZoneInfoCallback(id, result); } return; } if (methodName == api::host::METHOD_DECLARE_FILE) { - const gchar* container; + const gchar* zone; int32_t type; const gchar* path; int32_t flags; int32_t mode; - g_variant_get(parameters, "(&si&sii)", &container, &type, &path, &flags, &mode); + g_variant_get(parameters, "(&si&sii)", &zone, &type, &path, &flags, &mode); if (mDeclareFileCallback) { - mDeclareFileCallback(container, type, path, flags, mode, result); + mDeclareFileCallback(zone, type, path, flags, mode, result); } return; } if (methodName == api::host::METHOD_DECLARE_MOUNT) { const gchar* source; - const gchar* container; + const gchar* zone; const gchar* target; const gchar* type; uint64_t flags; @@ -275,63 +275,63 @@ void HostConnection::onMessageCall(const std::string& objectPath, g_variant_get(parameters, "(&s&s&s&st&s)", &source, - &container, + &zone, &target, &type, &flags, &data); if (mDeclareMountCallback) { - mDeclareMountCallback(source, container, target, type, flags, data, result); + mDeclareMountCallback(source, zone, target, type, flags, data, result); } return; } if (methodName == api::host::METHOD_DECLARE_LINK) { const gchar* source; - const gchar* container; + const gchar* zone; const gchar* target; - g_variant_get(parameters, "(&s&s&s)", &source, &container, &target); + g_variant_get(parameters, "(&s&s&s)", &source, &zone, &target); if (mDeclareLinkCallback) { - mDeclareLinkCallback(source, container, target, result); + mDeclareLinkCallback(source, zone, target, result); } return; } - if (methodName == api::host::METHOD_CREATE_CONTAINER) { + if (methodName == api::host::METHOD_CREATE_ZONE) { const gchar* id = NULL; g_variant_get(parameters, "(&s)", &id); - if (mCreateContainerCallback){ - mCreateContainerCallback(id, result); + if (mCreateZoneCallback){ + mCreateZoneCallback(id, result); } } - if (methodName == api::host::METHOD_DESTROY_CONTAINER) { + if (methodName == api::host::METHOD_DESTROY_ZONE) { const gchar* id = NULL; g_variant_get(parameters, "(&s)", &id); - if (mDestroyContainerCallback){ - mDestroyContainerCallback(id, result); + if (mDestroyZoneCallback){ + mDestroyZoneCallback(id, result); } } - if (methodName == api::host::METHOD_LOCK_CONTAINER) { + if (methodName == api::host::METHOD_LOCK_ZONE) { const gchar* id = NULL; g_variant_get(parameters, "(&s)", &id); - if (mLockContainerCallback){ - mLockContainerCallback(id, result); + if (mLockZoneCallback){ + mLockZoneCallback(id, result); } } - if (methodName == api::host::METHOD_UNLOCK_CONTAINER) { + if (methodName == api::host::METHOD_UNLOCK_ZONE) { const gchar* id = NULL; g_variant_get(parameters, "(&s)", &id); - if (mUnlockContainerCallback){ - mUnlockContainerCallback(id, result); + if (mUnlockZoneCallback){ + mUnlockZoneCallback(id, result); } } } @@ -352,13 +352,13 @@ void HostConnection::proxyCallAsync(const std::string& busName, callback); } -void HostConnection::signalContainerDbusState(const std::string& containerId, +void HostConnection::signalZoneDbusState(const std::string& zoneId, const std::string& dbusAddress) { - GVariant* parameters = g_variant_new("(ss)", containerId.c_str(), dbusAddress.c_str()); + GVariant* parameters = g_variant_new("(ss)", zoneId.c_str(), dbusAddress.c_str()); mDbusConnection->emitSignal(api::host::OBJECT_PATH, api::host::INTERFACE, - api::host::SIGNAL_CONTAINER_DBUS_STATE, + api::host::SIGNAL_ZONE_DBUS_STATE, parameters); } diff --git a/server/host-connection.hpp b/server/host-connection.hpp index b5f581c..68e3a73 100644 --- a/server/host-connection.hpp +++ b/server/host-connection.hpp @@ -52,15 +52,15 @@ public: dbus::MethodResultBuilder::Pointer result )> ProxyCallCallback; typedef std::function GetContainerDbusesCallback; + )> GetZoneDbusesCallback; typedef std::function GetContainerIdsCallback; + )> GetZoneIdsCallback; typedef std::function GetActiveContainerIdCallback; + )> GetActiveZoneIdCallback; typedef std::function GetContainerInfoCallback; - typedef std::function GetZoneInfoCallback; + typedef std::function DeclareFileCallback; typedef std::function DeclareMountCallback; typedef std::function DeclareLinkCallback; typedef std::function SetActiveContainerCallback; + )> SetActiveZoneCallback; typedef std::function CreateContainerCallback; + )> CreateZoneCallback; typedef std::function DestroyContainerCallback; + )> DestroyZoneCallback; typedef std::function LockContainerCallback; + )> LockZoneCallback; typedef std::function UnlockContainerCallback; + )> UnlockZoneCallback; /** * Register proxy call callback @@ -102,29 +102,29 @@ public: void setProxyCallCallback(const ProxyCallCallback& callback); /** - * Register get container dbuses callback + * Register get zone dbuses callback */ - void setGetContainerDbusesCallback(const GetContainerDbusesCallback& callback); + void setGetZoneDbusesCallback(const GetZoneDbusesCallback& callback); /** * Send signal describing dbus address state change */ - void signalContainerDbusState(const std::string& containerId, const std::string& dbusAddress); + void signalZoneDbusState(const std::string& zoneId, const std::string& dbusAddress); /** * Register a callback called to get a list of zone ids */ - void setGetContainerIdsCallback(const GetContainerIdsCallback& callback); + void setGetZoneIdsCallback(const GetZoneIdsCallback& callback); /** - * Register a callback called to get the active container id + * Register a callback called to get the active zone id */ - void setGetActiveContainerIdCallback(const GetContainerIdsCallback& callback); + void setGetActiveZoneIdCallback(const GetZoneIdsCallback& callback); /** - * Register a callback called to get the container informations + * Register a callback called to get the zone informations */ - void setGetContainerInfoCallback(const GetContainerInfoCallback& callback); + void setGetZoneInfoCallback(const GetZoneInfoCallback& callback); /** * Register a callback called to declare file @@ -142,29 +142,29 @@ public: void setDeclareLinkCallback(const DeclareLinkCallback& callback); /** - * Register a callback called to set the active container + * Register a callback called to set the active zone */ - void setSetActiveContainerCallback(const SetActiveContainerCallback& callback); + void setSetActiveZoneCallback(const SetActiveZoneCallback& callback); /** - * Register a callback called to create new container + * Register a callback called to create new zone */ - void setCreateContainerCallback(const CreateContainerCallback& callback); + void setCreateZoneCallback(const CreateZoneCallback& callback); /** - * Register a callback called to destroy container + * Register a callback called to destroy zone */ - void setDestroyContainerCallback(const DestroyContainerCallback& callback); + void setDestroyZoneCallback(const DestroyZoneCallback& callback); /** - * Register a callback called to lock container + * Register a callback called to lock zone */ - void setLockContainerCallback(const LockContainerCallback& callback); + void setLockZoneCallback(const LockZoneCallback& callback); /** - * Register a callback called to unlock container + * Register a callback called to unlock zone */ - void setUnlockContainerCallback(const UnlockContainerCallback& callback); + void setUnlockZoneCallback(const UnlockZoneCallback& callback); /** * Make a proxy call @@ -183,18 +183,18 @@ private: bool mNameAcquired; bool mNameLost; ProxyCallCallback mProxyCallCallback; - GetContainerDbusesCallback mGetContainerDbusesCallback; - GetContainerIdsCallback mGetContainerIdsCallback; - GetActiveContainerIdCallback mGetActiveContainerIdCallback; - GetContainerInfoCallback mGetContainerInfoCallback; + GetZoneDbusesCallback mGetZoneDbusesCallback; + GetZoneIdsCallback mGetZoneIdsCallback; + GetActiveZoneIdCallback mGetActiveZoneIdCallback; + GetZoneInfoCallback mGetZoneInfoCallback; DeclareFileCallback mDeclareFileCallback; DeclareMountCallback mDeclareMountCallback; DeclareLinkCallback mDeclareLinkCallback; - SetActiveContainerCallback mSetActiveContainerCallback; - CreateContainerCallback mCreateContainerCallback; - DestroyContainerCallback mDestroyContainerCallback; - LockContainerCallback mLockContainerCallback; - UnlockContainerCallback mUnlockContainerCallback; + SetActiveZoneCallback mSetActiveZoneCallback; + CreateZoneCallback mCreateZoneCallback; + DestroyZoneCallback mDestroyZoneCallback; + LockZoneCallback mLockZoneCallback; + UnlockZoneCallback mUnlockZoneCallback; void onNameAcquired(); void onNameLost(); diff --git a/server/host-dbus-definitions.hpp b/server/host-dbus-definitions.hpp index 15ace0d..998c720 100644 --- a/server/host-dbus-definitions.hpp +++ b/server/host-dbus-definitions.hpp @@ -32,26 +32,26 @@ namespace vasum { namespace api { namespace host { -const std::string BUS_NAME = "org.tizen.containers.host"; -const std::string OBJECT_PATH = "/org/tizen/containers/host"; -const std::string INTERFACE = "org.tizen.containers.host.manager"; +const std::string BUS_NAME = "org.tizen.vasum.host"; +const std::string OBJECT_PATH = "/org/tizen/vasum/host"; +const std::string INTERFACE = "org.tizen.vasum.host.manager"; -const std::string ERROR_CONTAINER_STOPPED = "org.tizen.containers.host.Error.ContainersStopped"; +const std::string ERROR_ZONE_STOPPED = "org.tizen.vasum.host.Error.ZonesStopped"; -const std::string METHOD_GET_CONTAINER_DBUSES = "GetContainerDbuses"; -const std::string METHOD_GET_CONTAINER_ID_LIST = "GetContainerIds"; -const std::string METHOD_GET_ACTIVE_CONTAINER_ID = "GetActiveContainerId"; -const std::string METHOD_GET_CONTAINER_INFO = "GetContainerInfo"; +const std::string METHOD_GET_ZONE_DBUSES = "GetZoneDbuses"; +const std::string METHOD_GET_ZONE_ID_LIST = "GetZoneIds"; +const std::string METHOD_GET_ACTIVE_ZONE_ID = "GetActiveZoneId"; +const std::string METHOD_GET_ZONE_INFO = "GetZoneInfo"; const std::string METHOD_DECLARE_FILE = "DeclareFile"; const std::string METHOD_DECLARE_MOUNT = "DeclareMount"; const std::string METHOD_DECLARE_LINK = "DeclareLink"; -const std::string METHOD_SET_ACTIVE_CONTAINER = "SetActiveContainer"; -const std::string METHOD_CREATE_CONTAINER = "CreateContainer"; -const std::string METHOD_DESTROY_CONTAINER = "DestroyContainer"; -const std::string METHOD_LOCK_CONTAINER = "LockContainer"; -const std::string METHOD_UNLOCK_CONTAINER = "UnlockContainer"; +const std::string METHOD_SET_ACTIVE_ZONE = "SetActiveZone"; +const std::string METHOD_CREATE_ZONE = "CreateZone"; +const std::string METHOD_DESTROY_ZONE = "DestroyZone"; +const std::string METHOD_LOCK_ZONE = "LockZone"; +const std::string METHOD_UNLOCK_ZONE = "UnlockZone"; -const std::string SIGNAL_CONTAINER_DBUS_STATE = "ContainerDbusState"; +const std::string SIGNAL_ZONE_DBUS_STATE = "ZoneDbusState"; const std::string DEFINITION = @@ -66,21 +66,21 @@ const std::string DEFINITION = " " " " " " - " " + " " " " " " - " " + " " " " " " - " " + " " " " " " - " " + " " " " " " " " " " - " " + " " " " " " " " @@ -88,7 +88,7 @@ const std::string DEFINITION = " " " " " " - " " + " " " " " " " " @@ -96,26 +96,26 @@ const std::string DEFINITION = " " " " " " - " " + " " " " " " - " " + " " " " " " - " " + " " " " " " - " " + " " " " " " - " " + " " " " " " - " " + " " " " " " - " " - " " + " " + " " " " " " " " diff --git a/server/provisioning-config.hpp b/server/provisioning-config.hpp index e5cf456..5a9f5ff 100644 --- a/server/provisioning-config.hpp +++ b/server/provisioning-config.hpp @@ -19,7 +19,7 @@ /** * @file * @author Mateusz Malicki (m.malicki2@samsung.com) - * @brief Declaration of the class for storing container provisioning configuration + * @brief Declaration of the class for storing zone provisioning configuration */ @@ -32,9 +32,9 @@ #include -namespace security_containers { +namespace vasum { -struct ContainerProvisioning +struct ZoneProvisioning { struct File @@ -101,6 +101,6 @@ struct ContainerProvisioning ) }; -} +} // namespace vasum #endif // SERVER_PROVISIONING_CONFIG_HPP diff --git a/server/proxy-call-config.hpp b/server/proxy-call-config.hpp index 3bb734c..e062eaf 100644 --- a/server/proxy-call-config.hpp +++ b/server/proxy-call-config.hpp @@ -39,8 +39,8 @@ namespace vasum { */ struct ProxyCallRule { - std::string caller; ///< caller id (container id or host) - std::string target; ///< target id (container id or host) + std::string caller; ///< caller id (zone id or host) + std::string target; ///< target id (zone id or host) std::string targetBusName; ///< target dbus bus name std::string targetObjectPath; ///< target dbus object path std::string targetInterface; ///< target dbus interface diff --git a/server/server.cpp b/server/server.cpp index f2d70c1..d9a1628 100644 --- a/server/server.cpp +++ b/server/server.cpp @@ -25,7 +25,7 @@ #include "config.hpp" #include "server.hpp" -#include "containers-manager.hpp" +#include "zones-manager.hpp" #include "exception.hpp" #include "config/manager.hpp" @@ -109,16 +109,16 @@ void Server::run() LOGI("Starting daemon..."); { utils::ScopedGlibLoop loop; - ContainersManager manager(mConfigPath); + ZonesManager manager(mConfigPath); manager.startAll(); LOGI("Daemon started"); gSignalLatch.wait(); - // Detach containers if we triggered an update + // Detach zones if we triggered an update if (gUpdateTriggered) { - manager.setContainersDetachOnExit(); + manager.setZonesDetachOnExit(); } LOGI("Stopping daemon..."); @@ -146,8 +146,8 @@ bool Server::prepareEnvironment(const std::string& configPath, bool runAsRoot) { namespace fs = boost::filesystem; - // TODO: currently this config is loaded twice: here and in ContainerManager - ContainersManagerConfig config; + // TODO: currently this config is loaded twice: here and in ZonesManager + ZonesManagerConfig config; config::loadFromFile(configPath, config); struct passwd* pwd = ::getpwnam(VASUM_USER); @@ -169,9 +169,9 @@ bool Server::prepareEnvironment(const std::string& configPath, bool runAsRoot) } } - // create directory for additional container data (if needed) - if (!config.containerNewConfigPrefix.empty()) { - if (!utils::createDir(config.containerNewConfigPrefix, uid, gid, + // create directory for additional zone data (if needed) + if (!config.zoneNewConfigPrefix.empty()) { + if (!utils::createDir(config.zoneNewConfigPrefix, uid, gid, fs::perms::owner_all | fs::perms::group_read | fs::perms::group_exe | fs::perms::others_read | fs::perms::others_exe)) { @@ -186,8 +186,8 @@ bool Server::prepareEnvironment(const std::string& configPath, bool runAsRoot) } // INPUT_EVENT_GROUP provides access to /dev/input/event* devices used by InputMonitor. - // DISK_GROUP provides access to /dev/loop* devices, needed when adding new container to copy - // containers image + // DISK_GROUP provides access to /dev/loop* devices, needed when adding new zone to copy + // zones image if (!utils::setSuppGroups({INPUT_EVENT_GROUP, DISK_GROUP, TTY_GROUP})) { return false; } @@ -195,9 +195,9 @@ bool Server::prepareEnvironment(const std::string& configPath, bool runAsRoot) // CAP_SYS_ADMIN allows to mount tmpfs' for dbus communication at the runtime. // NOTE: CAP_MAC_OVERRIDE is temporary and must be removed when "smack namespace" // is introduced. The capability is needed to allow modify SMACK labels of - // "/var/run/containers//run" mount point. + // "/var/run/zones//run" mount point. // CAP_SYS_TTY_CONFIG is needed to activate virtual terminals through ioctl calls - // CAP_CHOWN is needed when creating new container from image to set owner/group for each file, + // CAP_CHOWN is needed when creating new zone from image to set owner/group for each file, // directory or symlink // CAP_SETUID is needed to launch specific funtions as root (see environment.cpp) return (runAsRoot || utils::dropRoot(uid, gid, {CAP_SYS_ADMIN, diff --git a/server/server.hpp b/server/server.hpp index 525eb23..009a468 100644 --- a/server/server.hpp +++ b/server/server.hpp @@ -45,7 +45,7 @@ public: static bool prepareEnvironment(const std::string& configPath, bool runAsRoot); /** - * Starts all the containers and blocks until SIGINT, SIGTERM or SIGUSR1 + * Starts all the zones and blocks until SIGINT, SIGTERM or SIGUSR1 */ void run(); diff --git a/server/container-admin.cpp b/server/zone-admin.cpp similarity index 71% rename from server/container-admin.cpp rename to server/zone-admin.cpp index e00fd71..42c71ea 100644 --- a/server/container-admin.cpp +++ b/server/zone-admin.cpp @@ -19,12 +19,12 @@ /** * @file * @author Jan Olszak (j.olszak@samsung.com) - * @brief Implementation of class for administrating one container + * @brief Implementation of class for administrating one zone */ #include "config.hpp" -#include "container-admin.hpp" +#include "zone-admin.hpp" #include "exception.hpp" #include "logger/logger.hpp" @@ -38,7 +38,7 @@ namespace vasum { namespace { -// TODO: this should be in container's configuration file +// TODO: this should be in zone's configuration file const int SHUTDOWN_WAIT = 10; } // namespace @@ -46,16 +46,16 @@ const int SHUTDOWN_WAIT = 10; const std::uint64_t DEFAULT_CPU_SHARES = 1024; const std::uint64_t DEFAULT_VCPU_PERIOD_MS = 100000; -ContainerAdmin::ContainerAdmin(const std::string& containersPath, +ZoneAdmin::ZoneAdmin(const std::string& zonesPath, const std::string& lxcTemplatePrefix, - const ContainerConfig& config) + const ZoneConfig& config) : mConfig(config), - mZone(containersPath, config.name), + mZone(zonesPath, config.name), mId(mZone.getName()), mDetachOnExit(false), mDestroyOnExit(false) { - LOGD(mId << ": Instantiating ContainerAdmin object"); + LOGD(mId << ": Instantiating ZoneAdmin object"); if (!mZone.isDefined()) { @@ -72,43 +72,43 @@ ContainerAdmin::ContainerAdmin(const std::string& containersPath, args.add(config.ipv4.c_str()); } if (!mZone.create(lxcTemplate, args.c_array())) { - throw ContainerOperationException("Could not create zone"); + throw ZoneOperationException("Could not create zone"); } } } -ContainerAdmin::~ContainerAdmin() +ZoneAdmin::~ZoneAdmin() { - LOGD(mId << ": Destroying ContainerAdmin object..."); + LOGD(mId << ": Destroying ZoneAdmin object..."); if (mDestroyOnExit) { if (!mZone.stop()) { - LOGE(mId << ": Failed to stop the container"); + LOGE(mId << ": Failed to stop the zone"); } if (!mZone.destroy()) { - LOGE(mId << ": Failed to destroy the container"); + LOGE(mId << ": Failed to destroy the zone"); } } if (!mDetachOnExit) { // Try to forcefully stop if (!mZone.stop()) { - LOGE(mId << ": Failed to stop the container"); + LOGE(mId << ": Failed to stop the zone"); } } - LOGD(mId << ": ContainerAdmin object destroyed"); + LOGD(mId << ": ZoneAdmin object destroyed"); } -const std::string& ContainerAdmin::getId() const +const std::string& ZoneAdmin::getId() const { return mId; } -void ContainerAdmin::start() +void ZoneAdmin::start() { LOGD(mId << ": Starting..."); if (isRunning()) { @@ -125,14 +125,14 @@ void ContainerAdmin::start() } if (!mZone.start(args.c_array())) { - throw ContainerOperationException("Could not start container"); + throw ZoneOperationException("Could not start zone"); } LOGD(mId << ": Started"); } -void ContainerAdmin::stop() +void ZoneAdmin::stop() { LOGD(mId << ": Stopping procedure started..."); if (isStopped()) { @@ -143,7 +143,7 @@ void ContainerAdmin::stop() if (!mZone.shutdown(SHUTDOWN_WAIT)) { // force stop if (!mZone.stop()) { - throw ContainerOperationException("Could not stop container"); + throw ZoneOperationException("Could not stop zone"); } } @@ -151,57 +151,57 @@ void ContainerAdmin::stop() } -void ContainerAdmin::destroy() +void ZoneAdmin::destroy() { LOGD(mId << ": Destroying procedure started..."); if (!mZone.destroy()) { - throw ContainerOperationException("Could not destroy container"); + throw ZoneOperationException("Could not destroy zone"); } LOGD(mId << ": Destroying procedure ended"); } -bool ContainerAdmin::isRunning() +bool ZoneAdmin::isRunning() { return mZone.getState() == lxc::LxcZone::State::RUNNING; } -bool ContainerAdmin::isStopped() +bool ZoneAdmin::isStopped() { return mZone.getState() == lxc::LxcZone::State::STOPPED; } -void ContainerAdmin::suspend() +void ZoneAdmin::suspend() { LOGD(mId << ": Pausing..."); if (!mZone.freeze()) { - throw ContainerOperationException("Could not pause container"); + throw ZoneOperationException("Could not pause zone"); } LOGD(mId << ": Paused"); } -void ContainerAdmin::resume() +void ZoneAdmin::resume() { LOGD(mId << ": Resuming..."); if (!mZone.unfreeze()) { - throw ContainerOperationException("Could not resume container"); + throw ZoneOperationException("Could not resume zone"); } LOGD(mId << ": Resumed"); } -bool ContainerAdmin::isPaused() +bool ZoneAdmin::isPaused() { return mZone.getState() == lxc::LxcZone::State::FROZEN; } -void ContainerAdmin::setSchedulerLevel(SchedulerLevel sched) +void ZoneAdmin::setSchedulerLevel(SchedulerLevel sched) { switch (sched) { case SchedulerLevel::FOREGROUND: @@ -222,8 +222,8 @@ void ContainerAdmin::setSchedulerLevel(SchedulerLevel sched) } -void ContainerAdmin::setSchedulerParams(std::uint64_t, std::uint64_t, std::int64_t) -//void ContainerAdmin::setSchedulerParams(std::uint64_t cpuShares, std::uint64_t vcpuPeriod, std::int64_t vcpuQuota) +void ZoneAdmin::setSchedulerParams(std::uint64_t, std::uint64_t, std::int64_t) +//void ZoneAdmin::setSchedulerParams(std::uint64_t cpuShares, std::uint64_t vcpuPeriod, std::int64_t vcpuQuota) { // assert(mZone); // @@ -239,23 +239,23 @@ void ContainerAdmin::setSchedulerParams(std::uint64_t, std::uint64_t, std::int64 // virTypedParamsAddLLong(¶msTmp, &numParamsBuff, &maxParams, VIR_DOMAIN_SCHEDULER_VCPU_QUOTA, vcpuQuota); // // if (virDomainSetSchedulerParameters(mZone.get(), params.get(), numParamsBuff) < 0) { -// LOGE(mId << ": Error while setting the container's scheduler params:\n" +// LOGE(mId << ": Error while setting the zone's scheduler params:\n" // << libvirt::libvirtFormatError()); -// throw ContainerOperationException(); +// throw ZoneOperationException(); // } } -void ContainerAdmin::setDetachOnExit() +void ZoneAdmin::setDetachOnExit() { mDetachOnExit = true; } -void ContainerAdmin::setDestroyOnExit() +void ZoneAdmin::setDestroyOnExit() { mDestroyOnExit = true; } -std::int64_t ContainerAdmin::getSchedulerQuota() +std::int64_t ZoneAdmin::getSchedulerQuota() { // assert(mZone); // @@ -263,17 +263,17 @@ std::int64_t ContainerAdmin::getSchedulerQuota() // std::unique_ptr type(virDomainGetSchedulerType(mZone.get(), &numParamsBuff), free); // // if (type == NULL || numParamsBuff <= 0 || strcmp(type.get(), "posix") != 0) { -// LOGE(mId << ": Error while getting the container's scheduler type:\n" +// LOGE(mId << ": Error while getting the zone's scheduler type:\n" // << libvirt::libvirtFormatError()); -// throw ContainerOperationException(); +// throw ZoneOperationException(); // } // // std::unique_ptr params(new virTypedParameter[numParamsBuff]); // // if (virDomainGetSchedulerParameters(mZone.get(), params.get(), &numParamsBuff) < 0) { -// LOGE(mId << ": Error while getting the container's scheduler params:\n" +// LOGE(mId << ": Error while getting the zone's scheduler params:\n" // << libvirt::libvirtFormatError()); -// throw ContainerOperationException(); +// throw ZoneOperationException(); // } // // long long quota; @@ -281,9 +281,9 @@ std::int64_t ContainerAdmin::getSchedulerQuota() // numParamsBuff, // VIR_DOMAIN_SCHEDULER_VCPU_QUOTA, // "a) <= 0) { -// LOGE(mId << ": Error while getting the container's scheduler quota param:\n" +// LOGE(mId << ": Error while getting the zone's scheduler quota param:\n" // << libvirt::libvirtFormatError()); -// throw ContainerOperationException(); +// throw ZoneOperationException(); // } // // return quota; diff --git a/server/container-admin.hpp b/server/zone-admin.hpp similarity index 60% rename from server/container-admin.hpp rename to server/zone-admin.hpp index 050d9d9..1d31ab4 100644 --- a/server/container-admin.hpp +++ b/server/zone-admin.hpp @@ -19,14 +19,14 @@ /** * @file * @author Jan Olszak (j.olszak@samsung.com) - * @brief Declaration of the class for administrating one container + * @brief Declaration of the class for administrating one zone */ -#ifndef SERVER_CONTAINER_ADMIN_HPP -#define SERVER_CONTAINER_ADMIN_HPP +#ifndef SERVER_ZONE_ADMIN_HPP +#define SERVER_ZONE_ADMIN_HPP -#include "container-config.hpp" +#include "zone-config.hpp" #include "lxc/zone.hpp" @@ -38,85 +38,85 @@ enum class SchedulerLevel { BACKGROUND }; -class ContainerAdmin { +class ZoneAdmin { public: /** - * ContainerAdmin constructor - * @param containersPath directory where containers are defined (lxc configs, rootfs etc) + * ZoneAdmin constructor + * @param zonesPath directory where zones are defined (lxc configs, rootfs etc) * @param lxcTemplatePrefix directory where templates are stored - * @param config containers config + * @param config zones config */ - ContainerAdmin(const std::string& containersPath, + ZoneAdmin(const std::string& zonesPath, const std::string& lxcTemplatePrefix, - const ContainerConfig& config); - virtual ~ContainerAdmin(); + const ZoneConfig& config); + virtual ~ZoneAdmin(); /** - * Get the container id + * Get the zone id */ const std::string& getId() const; /** - * Boot the container to the background. + * Boot the zone to the background. */ void start(); /** - * Try to shutdown the container, if failed, kill it. + * Try to shutdown the zone, if failed, kill it. */ void stop(); /** - * Destroy stopped container. In particular it removes whole containers rootfs. + * Destroy stopped zone. In particular it removes whole zones rootfs. */ void destroy(); /** - * @return Is the container running? + * @return Is the zone running? */ bool isRunning(); /** - * Check if the container is stopped. It's NOT equivalent to !isRunning, + * Check if the zone is stopped. It's NOT equivalent to !isRunning, * because it checks different internal lxc states. There are other states, - * (e.g. paused) when the container isn't running nor stopped. + * (e.g. paused) when the zone isn't running nor stopped. * - * @return Is the container stopped? + * @return Is the zone stopped? */ bool isStopped(); /** - * Suspends an active container, the process is frozen + * Suspends an active zone, the process is frozen * without further access to CPU resources and I/O, - * but the memory used by the container + * but the memory used by the zone * at the hypervisor level will stay allocated */ void suspend(); /** - * Resume the container after suspension. + * Resume the zone after suspension. */ void resume(); /** - * @return Is the container in a paused state? + * @return Is the zone in a paused state? */ bool isPaused(); /** - * Sets the containers scheduler CFS quota. + * Sets the zones scheduler CFS quota. */ void setSchedulerLevel(SchedulerLevel sched); /** - * Set whether container should be detached on exit. + * Set whether zone should be detached on exit. */ void setDetachOnExit(); /** - * Set if container should be destroyed on exit. + * Set if zone should be destroyed on exit. */ void setDestroyOnExit(); @@ -127,7 +127,7 @@ public: std::int64_t getSchedulerQuota(); private: - const ContainerConfig& mConfig; + const ZoneConfig& mConfig; lxc::LxcZone mZone; const std::string mId; bool mDetachOnExit; @@ -140,4 +140,4 @@ private: } // namespace vasum -#endif // SERVER_CONTAINER_ADMIN_HPP +#endif // SERVER_ZONE_ADMIN_HPP diff --git a/server/container-config.hpp b/server/zone-config.hpp similarity index 70% rename from server/container-config.hpp rename to server/zone-config.hpp index d9331b3..b801af8 100644 --- a/server/container-config.hpp +++ b/server/zone-config.hpp @@ -19,12 +19,12 @@ /** * @file * @author Michal Witanowski (m.witanowski@samsung.com) - * @brief Declaration of the class for storing container configuration + * @brief Declaration of the class for storing zone configuration */ -#ifndef SERVER_CONTAINER_CONFIG_HPP -#define SERVER_CONTAINER_CONFIG_HPP +#ifndef SERVER_ZONE_CONFIG_HPP +#define SERVER_ZONE_CONFIG_HPP #include "config/fields.hpp" @@ -35,10 +35,10 @@ namespace vasum { -struct ContainerConfig { +struct ZoneConfig { /** - * Container name + * Zone name */ std::string name; @@ -63,51 +63,51 @@ struct ContainerConfig { std::string ipv4; /** - * Privilege of the container. - * The smaller the value the more important the container + * Privilege of the zone. + * The smaller the value the more important the zone */ int privilege; /** - * Number of virtual terminal used by xserver inside container + * Number of virtual terminal used by xserver inside zone */ int vt; /** - * Allow switching to default container after timeout. - * Setting this to false will disable switching to default container after timeout. + * Allow switching to default zone after timeout. + * Setting this to false will disable switching to default zone after timeout. */ bool switchToDefaultAfterTimeout; /** - * Specify, if D-Bus communication with the container will be enabled. - * Setting this value to "false" will make the zone API not work inside the container. + * Specify, if D-Bus communication with the zone will be enabled. + * Setting this value to "false" will make the zone API not work inside the zone. */ bool enableDbusIntegration; /** - * Container's CFS quota in us when it's in the foreground + * Zone's CFS quota in us when it's in the foreground */ std::int64_t cpuQuotaForeground; /** - * Container's CFS quota in us when it's in the background + * Zone's CFS quota in us when it's in the background */ std::int64_t cpuQuotaBackground; /** - * Path to containers dbus unix socket + * Path to zones dbus unix socket */ std::string runMountPoint; /** - * When you move a file out of the container (by move request) + * When you move a file out of the zone (by move request) * its path must match at least one of the regexps in this vector. */ std::vector permittedToSend; /** - * When you move a file to the container (by move request) + * When you move a file to the zone (by move request) * its path must match at least one of the regexps in this vector. */ std::vector permittedToRecv; @@ -134,4 +134,4 @@ struct ContainerConfig { } // namespace vasum -#endif // SERVER_CONTAINER_CONFIG_HPP +#endif // SERVER_ZONE_CONFIG_HPP diff --git a/server/container-connection-transport.cpp b/server/zone-connection-transport.cpp similarity index 77% rename from server/container-connection-transport.cpp rename to server/zone-connection-transport.cpp index bbbfdcf..d209705 100644 --- a/server/container-connection-transport.cpp +++ b/server/zone-connection-transport.cpp @@ -19,12 +19,12 @@ /** * @file * @author Piotr Bartosiewicz (p.bartosiewi@partner.samsung.com) - * @brief Implementation of a class for communication transport between container and server + * @brief Implementation of a class for communication transport between zone and server */ #include "config.hpp" -#include "container-connection-transport.hpp" +#include "zone-connection-transport.hpp" #include "exception.hpp" #include "utils/file-wait.hpp" @@ -39,14 +39,14 @@ namespace vasum { namespace { // Timeout in ms for waiting for dbus transport. -// Should be very long to ensure dbus in container is ready. -// TODO: this should be in container's configuration file +// Should be very long to ensure dbus in zone is ready. +// TODO: this should be in zone's configuration file const unsigned int TRANSPORT_READY_TIMEOUT = 2 * 60 * 1000; } // namespace -ContainerConnectionTransport::ContainerConnectionTransport(const std::string& runMountPoint) +ZoneConnectionTransport::ZoneConnectionTransport(const std::string& runMountPoint) : mRunMountPoint(runMountPoint), mDetachOnExit(false) { if (runMountPoint.empty()) { @@ -56,14 +56,14 @@ ContainerConnectionTransport::ContainerConnectionTransport(const std::string& ru boost::filesystem::create_directories(runMountPoint, errorCode); if (errorCode) { LOGE("Initialization failed: could not create '" << runMountPoint << "' :" << errorCode); - throw ContainerConnectionException("Could not create: " + runMountPoint + + throw ZoneConnectionException("Could not create: " + runMountPoint + " :" + errorCode.message()); } bool isMount = false; if (!utils::isMountPoint(runMountPoint, isMount)) { LOGE("Failed to check if " << runMountPoint << " is a mount point."); - throw ContainerConnectionException("Could not check if " + runMountPoint + + throw ZoneConnectionException("Could not check if " + runMountPoint + " is a mount point."); } @@ -72,23 +72,23 @@ ContainerConnectionTransport::ContainerConnectionTransport(const std::string& ru if (!utils::mountRun(runMountPoint)) { LOGE("Initialization failed: could not mount " << runMountPoint); - throw ContainerConnectionException("Could not mount: " + runMountPoint); + throw ZoneConnectionException("Could not mount: " + runMountPoint); } } - // if there is no systemd in the container this dir won't be created automatically + // if there is no systemd in the zone this dir won't be created automatically // TODO: will require chown with USER namespace enabled std::string dbusDirectory = runMountPoint + "/dbus"; boost::filesystem::create_directories(dbusDirectory, errorCode); if (errorCode) { LOGE("Initialization failed: could not create '" << dbusDirectory << "' :" << errorCode); - throw ContainerConnectionException("Could not create: " + dbusDirectory + + throw ZoneConnectionException("Could not create: " + dbusDirectory + " :" + errorCode.message()); } } -ContainerConnectionTransport::~ContainerConnectionTransport() +ZoneConnectionTransport::~ZoneConnectionTransport() { if (!mDetachOnExit) { if (!mRunMountPoint.empty()) { @@ -100,7 +100,7 @@ ContainerConnectionTransport::~ContainerConnectionTransport() } -std::string ContainerConnectionTransport::acquireAddress() +std::string ZoneConnectionTransport::acquireAddress() { if (mRunMountPoint.empty()) { return std::string(); @@ -115,7 +115,7 @@ std::string ContainerConnectionTransport::acquireAddress() return "unix:path=" + dbusPath; } -void ContainerConnectionTransport::setDetachOnExit() +void ZoneConnectionTransport::setDetachOnExit() { mDetachOnExit = true; } diff --git a/server/container-connection-transport.hpp b/server/zone-connection-transport.hpp similarity index 73% rename from server/container-connection-transport.hpp rename to server/zone-connection-transport.hpp index 5e7c9e8..5729389 100644 --- a/server/container-connection-transport.hpp +++ b/server/zone-connection-transport.hpp @@ -19,12 +19,12 @@ /** * @file * @author Piotr Bartosiewicz (p.bartosiewi@partner.samsung.com) - * @brief Declaration of a class for communication transport between container and server + * @brief Declaration of a class for communication transport between zone and server */ -#ifndef SERVER_CONTAINER_CONNECTION_TRANSPORT_HPP -#define SERVER_CONTAINER_CONNECTION_TRANSPORT_HPP +#ifndef SERVER_ZONE_CONNECTION_TRANSPORT_HPP +#define SERVER_ZONE_CONNECTION_TRANSPORT_HPP #include "dbus/connection.hpp" @@ -33,13 +33,13 @@ namespace vasum { /** - * This class provides a communication transport between container and server. - * The object lifecycle should cover lifecycle of a container. + * This class provides a communication transport between zone and server. + * The object lifecycle should cover lifecycle of a zone. */ -class ContainerConnectionTransport { +class ZoneConnectionTransport { public: - ContainerConnectionTransport(const std::string& runMountPoint); - ~ContainerConnectionTransport(); + ZoneConnectionTransport(const std::string& runMountPoint); + ~ZoneConnectionTransport(); /** * Gets dbus addres. Will block until address is available. @@ -60,4 +60,4 @@ private: } // namespace vasum -#endif // SERVER_CONTAINER_CONNECTION_TRANSPORT_HPP +#endif // SERVER_ZONE_CONNECTION_TRANSPORT_HPP diff --git a/server/container-connection.cpp b/server/zone-connection.cpp similarity index 72% rename from server/container-connection.cpp rename to server/zone-connection.cpp index 8e18590..35341b3 100644 --- a/server/container-connection.cpp +++ b/server/zone-connection.cpp @@ -19,13 +19,13 @@ /** * @file * @author Piotr Bartosiewicz (p.bartosiewi@partner.samsung.com) - * @brief Implementation of a class for communication between container and server + * @brief Implementation of a class for communication between zone and server */ #include "config.hpp" -#include "container-connection.hpp" -#include "container-dbus-definitions.hpp" +#include "zone-connection.hpp" +#include "zone-dbus-definitions.hpp" #include "exception.hpp" // TODO: Switch to real power-manager dbus defs when they will be implemented in power-manager #include "fake-power-manager-dbus-definitions.hpp" @@ -39,39 +39,39 @@ namespace { // Timeout in ms for waiting for dbus name. // Can happen if glib loop is busy or not present. -// TODO: this should be in container's configuration file +// TODO: this should be in zone's configuration file const unsigned int NAME_ACQUIRED_TIMEOUT = 5 * 1000; } // namespace -ContainerConnection::ContainerConnection(const std::string& address, const OnNameLostCallback& callback) +ZoneConnection::ZoneConnection(const std::string& address, const OnNameLostCallback& callback) : mNameAcquired(false) , mNameLost(false) { if (address.empty()) { - LOGE("Invalid container connection address"); - throw ContainerConnectionException("Invalid container connection address"); + LOGE("Invalid zone connection address"); + throw ZoneConnectionException("Invalid zone connection address"); } LOGT("Connecting to DBUS on " << address); mDbusConnection = dbus::DbusConnection::create(address); LOGT("Setting DBUS name"); - mDbusConnection->setName(api::container::BUS_NAME, - std::bind(&ContainerConnection::onNameAcquired, this), - std::bind(&ContainerConnection::onNameLost, this)); + mDbusConnection->setName(api::zone::BUS_NAME, + std::bind(&ZoneConnection::onNameAcquired, this), + std::bind(&ZoneConnection::onNameLost, this)); if (!waitForNameAndSetCallback(NAME_ACQUIRED_TIMEOUT, callback)) { - LOGE("Could not acquire dbus name: " << api::container::BUS_NAME); - throw ContainerConnectionException("Could not acquire dbus name: " + api::container::BUS_NAME); + LOGE("Could not acquire dbus name: " << api::zone::BUS_NAME); + throw ZoneConnectionException("Could not acquire dbus name: " + api::zone::BUS_NAME); } LOGT("Registering DBUS interface"); using namespace std::placeholders; - mDbusConnection->registerObject(api::container::OBJECT_PATH, - api::container::DEFINITION, - std::bind(&ContainerConnection::onMessageCall, + mDbusConnection->registerObject(api::zone::OBJECT_PATH, + api::zone::DEFINITION, + std::bind(&ZoneConnection::onMessageCall, this, _1, _2, @@ -79,7 +79,7 @@ ContainerConnection::ContainerConnection(const std::string& address, const OnNam _4, _5)); - mDbusConnection->signalSubscribe(std::bind(&ContainerConnection::onSignalReceived, + mDbusConnection->signalSubscribe(std::bind(&ZoneConnection::onSignalReceived, this, _1, _2, @@ -91,11 +91,11 @@ ContainerConnection::ContainerConnection(const std::string& address, const OnNam LOGD("Connected"); } -ContainerConnection::~ContainerConnection() +ZoneConnection::~ZoneConnection() { } -bool ContainerConnection::waitForNameAndSetCallback(const unsigned int timeoutMs, const OnNameLostCallback& callback) +bool ZoneConnection::waitForNameAndSetCallback(const unsigned int timeoutMs, const OnNameLostCallback& callback) { std::unique_lock lock(mNameMutex); mNameCondition.wait_for(lock, @@ -110,14 +110,14 @@ bool ContainerConnection::waitForNameAndSetCallback(const unsigned int timeoutMs return mNameAcquired; } -void ContainerConnection::onNameAcquired() +void ZoneConnection::onNameAcquired() { std::unique_lock lock(mNameMutex); mNameAcquired = true; mNameCondition.notify_one(); } -void ContainerConnection::onNameLost() +void ZoneConnection::onNameLost() { std::unique_lock lock(mNameMutex); mNameLost = true; @@ -128,49 +128,49 @@ void ContainerConnection::onNameLost() } } -void ContainerConnection::setNotifyActiveContainerCallback( - const NotifyActiveContainerCallback& callback) +void ZoneConnection::setNotifyActiveZoneCallback( + const NotifyActiveZoneCallback& callback) { - mNotifyActiveContainerCallback = callback; + mNotifyActiveZoneCallback = callback; } -void ContainerConnection::setDisplayOffCallback(const DisplayOffCallback& callback) +void ZoneConnection::setDisplayOffCallback(const DisplayOffCallback& callback) { mDisplayOffCallback = callback; } -void ContainerConnection::setFileMoveRequestCallback( +void ZoneConnection::setFileMoveRequestCallback( const FileMoveRequestCallback& callback) { mFileMoveRequestCallback = callback; } -void ContainerConnection::setProxyCallCallback(const ProxyCallCallback& callback) +void ZoneConnection::setProxyCallCallback(const ProxyCallCallback& callback) { mProxyCallCallback = callback; } -void ContainerConnection::onMessageCall(const std::string& objectPath, +void ZoneConnection::onMessageCall(const std::string& objectPath, const std::string& interface, const std::string& methodName, GVariant* parameters, dbus::MethodResultBuilder::Pointer result) { - if (objectPath != api::container::OBJECT_PATH || interface != api::container::INTERFACE) { + if (objectPath != api::zone::OBJECT_PATH || interface != api::zone::INTERFACE) { return; } - if (methodName == api::container::METHOD_NOTIFY_ACTIVE_CONTAINER) { + if (methodName == api::zone::METHOD_NOTIFY_ACTIVE_ZONE) { const gchar* application = NULL; const gchar* message = NULL; g_variant_get(parameters, "(&s&s)", &application, &message); - if (mNotifyActiveContainerCallback) { - mNotifyActiveContainerCallback(application, message); + if (mNotifyActiveZoneCallback) { + mNotifyActiveZoneCallback(application, message); result->setVoid(); } } - if (methodName == api::container::METHOD_FILE_MOVE_REQUEST) { + if (methodName == api::zone::METHOD_FILE_MOVE_REQUEST) { const gchar* destination = NULL; const gchar* path = NULL; g_variant_get(parameters, "(&s&s)", &destination, &path); @@ -208,7 +208,7 @@ void ContainerConnection::onMessageCall(const std::string& objectPath, } } -void ContainerConnection::onSignalReceived(const std::string& senderBusName, +void ZoneConnection::onSignalReceived(const std::string& senderBusName, const std::string& objectPath, const std::string& interface, const std::string& signalName, @@ -225,21 +225,21 @@ void ContainerConnection::onSignalReceived(const std::string& senderBusName, } } -void ContainerConnection::sendNotification(const std::string& container, +void ZoneConnection::sendNotification(const std::string& zone, const std::string& application, const std::string& message) { GVariant* parameters = g_variant_new("(sss)", - container.c_str(), + zone.c_str(), application.c_str(), message.c_str()); - mDbusConnection->emitSignal(api::container::OBJECT_PATH, - api::container::INTERFACE, - api::container::SIGNAL_NOTIFICATION, + mDbusConnection->emitSignal(api::zone::OBJECT_PATH, + api::zone::INTERFACE, + api::zone::SIGNAL_NOTIFICATION, parameters); } -void ContainerConnection::proxyCallAsync(const std::string& busName, +void ZoneConnection::proxyCallAsync(const std::string& busName, const std::string& objectPath, const std::string& interface, const std::string& method, diff --git a/server/container-connection.hpp b/server/zone-connection.hpp similarity index 85% rename from server/container-connection.hpp rename to server/zone-connection.hpp index cb41b7f..78b6e56 100644 --- a/server/container-connection.hpp +++ b/server/zone-connection.hpp @@ -19,12 +19,12 @@ /** * @file * @author Piotr Bartosiewicz (p.bartosiewi@partner.samsung.com) - * @brief Declaration of a class for communication between container and server + * @brief Declaration of a class for communication between zone and server */ -#ifndef SERVER_CONTAINER_CONNECTION_HPP -#define SERVER_CONTAINER_CONNECTION_HPP +#ifndef SERVER_ZONE_CONNECTION_HPP +#define SERVER_ZONE_CONNECTION_HPP #include "dbus/connection.hpp" @@ -35,20 +35,20 @@ namespace vasum { -class ContainerConnection { +class ZoneConnection { public: typedef std::function OnNameLostCallback; typedef std::function DisplayOffCallback; - ContainerConnection(const std::string& address, const OnNameLostCallback& callback); - ~ContainerConnection(); + ZoneConnection(const std::string& address, const OnNameLostCallback& callback); + ~ZoneConnection(); // ------------- API -------------- typedef std::function NotifyActiveContainerCallback; + )> NotifyActiveZoneCallback; typedef std::function" - " " + " " " " " " " " @@ -70,16 +70,16 @@ const std::string DEFINITION = " " " " " " - " " + " " " " " " " " " " ""; -} // namespace container +} // namespace zone } // namespace api } // namespace vasum -#endif // SERVER_CONTAINER_DBUS_DEFINITIONS_HPP +#endif // SERVER_ZONE_DBUS_DEFINITIONS_HPP diff --git a/server/container.cpp b/server/zone.cpp similarity index 72% rename from server/container.cpp rename to server/zone.cpp index b3be5a5..2e4573c 100644 --- a/server/container.cpp +++ b/server/zone.cpp @@ -19,12 +19,12 @@ /** * @file * @author Lukasz Pawelczyk (l.pawelczyk@partner.samsung.com) - * @brief Implementation of class for managing one container + * @brief Implementation of class for managing one zone */ #include "config.hpp" -#include "container.hpp" +#include "zone.hpp" #include "base-exception.hpp" #include "provisioning-config.hpp" @@ -50,12 +50,12 @@ typedef std::lock_guard Lock; // TODO: move constants to the config file when default values are implemented there const int RECONNECT_RETRIES = 15; const int RECONNECT_DELAY = 1 * 1000; -const std::string CONTAINER_PROVISION_FILE = "provision.conf"; +const std::string ZONE_PROVISION_FILE = "provision.conf"; -void declareUnit(const std::string& file, ContainerProvisioning::Unit&& unit) +void declareUnit(const std::string& file, ZoneProvisioning::Unit&& unit) { // TODO: Add to the dynamic configuration - ContainerProvisioning config; + ZoneProvisioning config; if (fs::exists(file)) { config::loadFromFile(file, config); } @@ -65,12 +65,12 @@ void declareUnit(const std::string& file, ContainerProvisioning::Unit&& unit) } // namespace -Container::Container(const std::string& containersPath, - const std::string& containerConfigPath, +Zone::Zone(const std::string& zonesPath, + const std::string& zoneConfigPath, const std::string& lxcTemplatePrefix, const std::string& baseRunMountPointPath) { - config::loadFromFile(containerConfigPath, mConfig); + config::loadFromFile(zoneConfigPath, mConfig); for (std::string r: mConfig.permittedToSend) { mPermittedToSend.push_back(boost::regex(r)); @@ -83,12 +83,12 @@ Container::Container(const std::string& containersPath, mRunMountPoint = fs::absolute(mConfig.runMountPoint, baseRunMountPointPath).string(); } - mAdmin.reset(new ContainerAdmin(containersPath, lxcTemplatePrefix, mConfig)); - const fs::path baseProvision = fs::path(containersPath) / mAdmin->getId(); - mProvisionConfig = fs::absolute(CONTAINER_PROVISION_FILE, baseProvision).string(); + mAdmin.reset(new ZoneAdmin(zonesPath, lxcTemplatePrefix, mConfig)); + const fs::path baseProvision = fs::path(zonesPath) / mAdmin->getId(); + mProvisionConfig = fs::absolute(ZONE_PROVISION_FILE, baseProvision).string(); } -Container::~Container() +Zone::~Zone() { // Make sure all OnNameLostCallbacks get finished and no new will // get called before proceeding further. This guarantees no race @@ -107,32 +107,32 @@ Container::~Container() } } -const std::vector& Container::getPermittedToSend() const +const std::vector& Zone::getPermittedToSend() const { return mPermittedToSend; } -const std::vector& Container::getPermittedToRecv() const +const std::vector& Zone::getPermittedToRecv() const { return mPermittedToRecv; } -const std::string& Container::getId() const +const std::string& Zone::getId() const { Lock lock(mReconnectMutex); return mAdmin->getId(); } -int Container::getPrivilege() const +int Zone::getPrivilege() const { return mConfig.privilege; } -void Container::start() +void Zone::start() { Lock lock(mReconnectMutex); if (mConfig.enableDbusIntegration) { - mConnectionTransport.reset(new ContainerConnectionTransport(mRunMountPoint)); + mConnectionTransport.reset(new ZoneConnectionTransport(mRunMountPoint)); } mAdmin->start(); if (mConfig.enableDbusIntegration) { @@ -144,7 +144,7 @@ void Container::start() goBackground(); } -void Container::startAsync(const StartAsyncResultCallback& callback) +void Zone::startAsync(const StartAsyncResultCallback& callback) { if (mStartThread.joinable()) { mStartThread.join(); @@ -168,7 +168,7 @@ void Container::startAsync(const StartAsyncResultCallback& callback) mStartThread = std::thread(startWrapper); } -void Container::stop() +void Zone::stop() { Lock lock(mReconnectMutex); disconnect(); @@ -176,14 +176,14 @@ void Container::stop() mConnectionTransport.reset(); } -void Container::connect() +void Zone::connect() { // assume called under reconnect lock mDbusAddress = mConnectionTransport->acquireAddress(); - mConnection.reset(new ContainerConnection(mDbusAddress, - std::bind(&Container::onNameLostCallback, this))); + mConnection.reset(new ZoneConnection(mDbusAddress, + std::bind(&Zone::onNameLostCallback, this))); if (mNotifyCallback) { - mConnection->setNotifyActiveContainerCallback(mNotifyCallback); + mConnection->setNotifyActiveZoneCallback(mNotifyCallback); } if (mDisplayOffCallback) { mConnection->setDisplayOffCallback(mDisplayOffCallback); @@ -199,31 +199,31 @@ void Container::connect() } } -void Container::disconnect() +void Zone::disconnect() { // assume called under reconnect lock if (mConnection) { mConnection.reset(); mDbusAddress.clear(); if (mDbusStateChangedCallback) { - // notify about invalid dbusAddress for this container + // notify about invalid dbusAddress for this zone mDbusStateChangedCallback(std::string()); } } } -std::string Container::getDbusAddress() +std::string Zone::getDbusAddress() { Lock lock(mReconnectMutex); return mDbusAddress; } -int Container::getVT() const +int Zone::getVT() const { return mConfig.vt; } -bool Container::activateVT() +bool Zone::activateVT() { Lock lock(mReconnectMutex); @@ -234,19 +234,19 @@ bool Container::activateVT() return true; } -void Container::goForeground() +void Zone::goForeground() { Lock lock(mReconnectMutex); mAdmin->setSchedulerLevel(SchedulerLevel::FOREGROUND); } -void Container::goBackground() +void Zone::goBackground() { Lock lock(mReconnectMutex); mAdmin->setSchedulerLevel(SchedulerLevel::BACKGROUND); } -void Container::setDetachOnExit() +void Zone::setDetachOnExit() { Lock lock(mReconnectMutex); mAdmin->setDetachOnExit(); @@ -255,58 +255,58 @@ void Container::setDetachOnExit() } } -void Container::setDestroyOnExit() +void Zone::setDestroyOnExit() { Lock lock(mReconnectMutex); mAdmin->setDestroyOnExit(); } -bool Container::isRunning() +bool Zone::isRunning() { Lock lock(mReconnectMutex); return mAdmin->isRunning(); } -bool Container::isStopped() +bool Zone::isStopped() { Lock lock(mReconnectMutex); return mAdmin->isStopped(); } -void Container::suspend() +void Zone::suspend() { Lock lock(mReconnectMutex); mAdmin->suspend(); } -void Container::resume() +void Zone::resume() { Lock lock(mReconnectMutex); mAdmin->resume(); } -bool Container::isPaused() +bool Zone::isPaused() { Lock lock(mReconnectMutex); return mAdmin->isPaused(); } -bool Container::isSwitchToDefaultAfterTimeoutAllowed() const +bool Zone::isSwitchToDefaultAfterTimeoutAllowed() const { return mConfig.switchToDefaultAfterTimeout; } -void Container::onNameLostCallback() +void Zone::onNameLostCallback() { LOGI(getId() << ": A connection to the DBUS server has been lost, reconnecting..."); if (mReconnectThread.joinable()) { mReconnectThread.join(); } - mReconnectThread = std::thread(std::bind(&Container::reconnectHandler, this)); + mReconnectThread = std::thread(std::bind(&Zone::reconnectHandler, this)); } -void Container::reconnectHandler() +void Zone::reconnectHandler() { { Lock lock(mReconnectMutex); @@ -333,32 +333,32 @@ void Container::reconnectHandler() } } - LOGE(getId() << ": Reconnecting to the DBUS has failed, stopping the container"); + LOGE(getId() << ": Reconnecting to the DBUS has failed, stopping the zone"); stop(); } -void Container::setNotifyActiveContainerCallback(const NotifyActiveContainerCallback& callback) +void Zone::setNotifyActiveZoneCallback(const NotifyActiveZoneCallback& callback) { Lock lock(mReconnectMutex); mNotifyCallback = callback; if (mConnection) { - mConnection->setNotifyActiveContainerCallback(mNotifyCallback); + mConnection->setNotifyActiveZoneCallback(mNotifyCallback); } } -void Container::sendNotification(const std::string& container, +void Zone::sendNotification(const std::string& zone, const std::string& application, const std::string& message) { Lock lock(mReconnectMutex); if (mConnection) { - mConnection->sendNotification(container, application, message); + mConnection->sendNotification(zone, application, message); } else { LOGE(getId() << ": Can't send notification, no connection to DBUS"); } } -void Container::setDisplayOffCallback(const DisplayOffCallback& callback) +void Zone::setDisplayOffCallback(const DisplayOffCallback& callback) { Lock lock(mReconnectMutex); @@ -368,7 +368,7 @@ void Container::setDisplayOffCallback(const DisplayOffCallback& callback) } } -void Container::setFileMoveRequestCallback(const FileMoveRequestCallback& callback) +void Zone::setFileMoveRequestCallback(const FileMoveRequestCallback& callback) { Lock lock(mReconnectMutex); @@ -378,7 +378,7 @@ void Container::setFileMoveRequestCallback(const FileMoveRequestCallback& callba } } -void Container::setProxyCallCallback(const ProxyCallCallback& callback) +void Zone::setProxyCallCallback(const ProxyCallCallback& callback) { Lock lock(mReconnectMutex); @@ -388,12 +388,12 @@ void Container::setProxyCallCallback(const ProxyCallCallback& callback) } } -void Container::setDbusStateChangedCallback(const DbusStateChangedCallback& callback) +void Zone::setDbusStateChangedCallback(const DbusStateChangedCallback& callback) { mDbusStateChangedCallback = callback; } -void Container::proxyCallAsync(const std::string& busName, +void Zone::proxyCallAsync(const std::string& busName, const std::string& objectPath, const std::string& interface, const std::string& method, @@ -413,34 +413,34 @@ void Container::proxyCallAsync(const std::string& busName, } } -void Container::declareFile(const int32_t& type, +void Zone::declareFile(const int32_t& type, const std::string& path, const int32_t& flags, const int32_t& mode) { - ContainerProvisioning::Unit unit; - unit.set(std::move(ContainerProvisioning::File({type, path, flags, mode}))); + ZoneProvisioning::Unit unit; + unit.set(std::move(ZoneProvisioning::File({type, path, flags, mode}))); declareUnit(mProvisionConfig, std::move(unit)); } -void Container::declareMount(const std::string& source, +void Zone::declareMount(const std::string& source, const std::string& target, const std::string& type, const int64_t& flags, const std::string& data) { - ContainerProvisioning::Unit unit; - unit.set(std::move(ContainerProvisioning::Mount({source, target, type, flags, data}))); + ZoneProvisioning::Unit unit; + unit.set(std::move(ZoneProvisioning::Mount({source, target, type, flags, data}))); declareUnit(mProvisionConfig, std::move(unit)); } -void Container::declareLink(const std::string& source, +void Zone::declareLink(const std::string& source, const std::string& target) { - ContainerProvisioning::Unit unit; - unit.set(std::move(ContainerProvisioning::Link({source, target}))); + ZoneProvisioning::Unit unit; + unit.set(std::move(ZoneProvisioning::Link({source, target}))); declareUnit(mProvisionConfig, std::move(unit)); } diff --git a/server/container.hpp b/server/zone.hpp similarity index 61% rename from server/container.hpp rename to server/zone.hpp index 88f5171..5ee95af 100644 --- a/server/container.hpp +++ b/server/zone.hpp @@ -19,17 +19,17 @@ /** * @file * @author Lukasz Pawelczyk (l.pawelczyk@partner.samsung.com) - * @brief Declaration of the class for managing one container + * @brief Declaration of the class for managing one zone */ -#ifndef SERVER_CONTAINER_HPP -#define SERVER_CONTAINER_HPP +#ifndef SERVER_ZONE_HPP +#define SERVER_ZONE_HPP -#include "container-config.hpp" -#include "container-admin.hpp" -#include "container-connection.hpp" -#include "container-connection-transport.hpp" +#include "zone-config.hpp" +#include "zone-admin.hpp" +#include "zone-connection.hpp" +#include "zone-connection-transport.hpp" #include #include @@ -40,148 +40,148 @@ namespace vasum { -class Container { +class Zone { public: /** - * Container constructor - * @param containersPath directory where containers are defined (lxc configs, rootfs etc) - * @param containerConfigPath path for containers config + * Zone constructor + * @param zonesPath directory where zones are defined (lxc configs, rootfs etc) + * @param zoneConfigPath path for zones config * @param lxcTemplatePrefix directory where templates are stored * @param baseRunMountPointPath base directory for run mount point */ - Container(const std::string& containersPath, - const std::string& containerConfigPath, + Zone(const std::string& zonesPath, + const std::string& zoneConfigPath, const std::string& lxcTemplatePrefix, const std::string& baseRunMountPointPath); - Container(Container&&) = default; - virtual ~Container(); + Zone(Zone&&) = default; + virtual ~Zone(); - typedef ContainerConnection::NotifyActiveContainerCallback NotifyActiveContainerCallback; - typedef ContainerConnection::DisplayOffCallback DisplayOffCallback; - typedef ContainerConnection::FileMoveRequestCallback FileMoveRequestCallback; - typedef ContainerConnection::ProxyCallCallback ProxyCallCallback; + typedef ZoneConnection::NotifyActiveZoneCallback NotifyActiveZoneCallback; + typedef ZoneConnection::DisplayOffCallback DisplayOffCallback; + typedef ZoneConnection::FileMoveRequestCallback FileMoveRequestCallback; + typedef ZoneConnection::ProxyCallCallback ProxyCallCallback; typedef std::function DbusStateChangedCallback; typedef std::function StartAsyncResultCallback; /** * Returns a vector of regexps defining files permitted to be - * send to other containers using file move functionality + * send to other zones using file move functionality */ const std::vector& getPermittedToSend() const; /** * Returns a vector of regexps defining files permitted to be - * send to other containers using file move functionality + * send to other zones using file move functionality */ const std::vector& getPermittedToRecv() const; - // ContainerAdmin API + // ZoneAdmin API /** - * Get the container id + * Get the zone id */ const std::string& getId() const; /** - * Get the container privilege + * Get the zone privilege */ int getPrivilege() const; /** - * Boot the container to the background. + * Boot the zone to the background. */ void start(); /** - * Boot the container to the background in separate thread. This function immediately exits - * after container booting is started in another thread. + * Boot the zone to the background in separate thread. This function immediately exits + * after zone booting is started in another thread. * - * @param callback Called after starting the container. Passes bool with result of starting. + * @param callback Called after starting the zone. Passes bool with result of starting. */ void startAsync(const StartAsyncResultCallback& callback); /** - * Try to shutdown the container, if failed, destroy it. + * Try to shutdown the zone, if failed, destroy it. */ void stop(); /** - * Activate this container's VT + * Activate this zone's VT * * @return Was activation successful? */ bool activateVT(); /** - * Setup this container to be put in the foreground. + * Setup this zone to be put in the foreground. * I.e. set appropriate scheduler level. */ void goForeground(); /** - * Setup this container to be put in the background. + * Setup this zone to be put in the background. * I.e. set appropriate scheduler level. */ void goBackground(); /** - * Set if container should be detached on exit. + * Set if zone should be detached on exit. * - * This sends detach flag to ContainerAdmin object and disables unmounting tmpfs - * in ContainerConnectionTransport. + * This sends detach flag to ZoneAdmin object and disables unmounting tmpfs + * in ZoneConnectionTransport. */ void setDetachOnExit(); /** - * Set if container should be destroyed on exit. + * Set if zone should be destroyed on exit. */ void setDestroyOnExit(); /** - * @return Is the container running? + * @return Is the zone running? */ bool isRunning(); /** - * Check if the container is stopped. It's NOT equivalent to !isRunning, + * Check if the zone is stopped. It's NOT equivalent to !isRunning, * because it checks different internal libvirt's states. There are other states, - * (e.g. paused) when the container isn't running nor stopped. + * (e.g. paused) when the zone isn't running nor stopped. * - * @return Is the container stopped? + * @return Is the zone stopped? */ bool isStopped(); /** - * Suspend container. + * Suspend zone. */ void suspend(); /** - * Resume container. + * Resume zone. */ void resume(); /** - * @return Is the container in a paused state? + * @return Is the zone in a paused state? */ bool isPaused(); - // ContainerConnection API + // ZoneConnection API /** - * @return Is switching to default container after timeout allowed? + * @return Is switching to default zone after timeout allowed? */ bool isSwitchToDefaultAfterTimeoutAllowed() const; /** * Register notification request callback */ - void setNotifyActiveContainerCallback(const NotifyActiveContainerCallback& callback); + void setNotifyActiveZoneCallback(const NotifyActiveZoneCallback& callback); /** - * Register callback used when switching to default container. + * Register callback used when switching to default zone. */ void setDisplayOffCallback(const DisplayOffCallback& callback); @@ -191,13 +191,13 @@ public: void setProxyCallCallback(const ProxyCallCallback& callback); /** - * Send notification signal to this container + * Send notification signal to this zone * - * @param container name of container in which the notification occurred + * @param zone name of zone in which the notification occurred * @param application name of application that cause notification - * @param message message to be send to container + * @param message message to be send to zone */ - void sendNotification(const std::string& container, + void sendNotification(const std::string& zone, const std::string& application, const std::string& message); @@ -232,14 +232,14 @@ public: int getVT() const; /** - * Declare file, directory or pipe that will be created while container startup + * Declare file, directory or pipe that will be created while zone startup */ void declareFile(const int32_t& type, const std::string& path, const int32_t& flags, const int32_t& mode); /** - * Declare mount that will be created while container startup + * Declare mount that will be created while zone startup */ void declareMount(const std::string& source, const std::string& target, @@ -247,22 +247,22 @@ public: const int64_t& flags, const std::string& data); /** - * Declare link that will be created while container startup + * Declare link that will be created while zone startup */ void declareLink(const std::string& source, const std::string& target); private: - ContainerConfig mConfig; + ZoneConfig mConfig; std::vector mPermittedToSend; std::vector mPermittedToRecv; - std::unique_ptr mConnectionTransport; - std::unique_ptr mAdmin; - std::unique_ptr mConnection; + std::unique_ptr mConnectionTransport; + std::unique_ptr mAdmin; + std::unique_ptr mConnection; std::thread mReconnectThread; std::thread mStartThread; mutable std::recursive_mutex mReconnectMutex; - NotifyActiveContainerCallback mNotifyCallback; + NotifyActiveZoneCallback mNotifyCallback; DisplayOffCallback mDisplayOffCallback; FileMoveRequestCallback mFileMoveCallback; ProxyCallCallback mProxyCallCallback; @@ -280,4 +280,4 @@ private: } // namespace vasum -#endif // SERVER_CONTAINER_HPP +#endif // SERVER_ZONE_HPP diff --git a/server/containers-manager-config.hpp b/server/zones-manager-config.hpp similarity index 57% rename from server/containers-manager-config.hpp rename to server/zones-manager-config.hpp index 58509a8..1838d25 100644 --- a/server/containers-manager-config.hpp +++ b/server/zones-manager-config.hpp @@ -19,12 +19,12 @@ /** * @file * @author Jan Olszak (j.olszak@samsung.com) - * @brief Declaration of the class for storing container manager configuration + * @brief Declaration of the class for storing zone manager configuration */ -#ifndef SERVER_CONTAINERS_MANAGER_CONFIG_HPP -#define SERVER_CONTAINERS_MANAGER_CONFIG_HPP +#ifndef SERVER_ZONES_MANAGER_CONFIG_HPP +#define SERVER_ZONES_MANAGER_CONFIG_HPP #include "config/fields.hpp" #include "input-monitor-config.hpp" @@ -37,46 +37,46 @@ namespace vasum { -const std::string CONTAINERS_MANAGER_CONFIG_PATH = "/etc/vasum/config/daemon.conf"; +const std::string ZONES_MANAGER_CONFIG_PATH = "/etc/vasum/config/daemon.conf"; -struct ContainersManagerConfig { +struct ZonesManagerConfig { /** - * List of containers' configs that we manage. - * File paths can be relative to the ContainerManager config file. + * List of zones' configs that we manage. + * File paths can be relative to the ZoneManager config file. */ - std::vector containerConfigs; + std::vector zoneConfigs; /** - * An ID of a currently focused/foreground container. + * An ID of a currently focused/foreground zone. */ std::string foregroundId; /** - * An ID of default container. + * An ID of default zone. */ std::string defaultId; /** - * A path where the containers mount points reside. + * A path where the zones mount points reside. */ - std::string containersPath; + std::string zonesPath; /** - * A path where the containers image reside. Empty path means that containers image won't be - * copied to containersPath when creating new container. + * A path where the zones image reside. Empty path means that zones image won't be + * copied to zonesPath when creating new zone. */ - std::string containerImagePath; + std::string zoneImagePath; /** - * A path where template configuration files for new containers reside + * A path where template configuration files for new zones reside */ - std::string containerTemplatePath; + std::string zoneTemplatePath; /** - * Prefix added to a path for new container configuration files + * Prefix added to a path for new zone configuration files */ - std::string containerNewConfigPrefix; + std::string zoneNewConfigPrefix; /** * Path prefix for lxc templates @@ -84,12 +84,12 @@ struct ContainersManagerConfig { std::string lxcTemplatePrefix; /* - * Parameters describing input device used to switch between containers + * Parameters describing input device used to switch between zones */ InputConfig inputConfig; /** - * Prefix added to a path of "run" tmpfs mount point for each container. + * Prefix added to a path of "run" tmpfs mount point for each zone. */ std::string runMountPointPrefix; @@ -100,13 +100,13 @@ struct ContainersManagerConfig { CONFIG_REGISTER ( - containerConfigs, + zoneConfigs, foregroundId, defaultId, - containersPath, - containerImagePath, - containerTemplatePath, - containerNewConfigPrefix, + zonesPath, + zoneImagePath, + zoneTemplatePath, + zoneNewConfigPrefix, lxcTemplatePrefix, inputConfig, runMountPointPrefix, @@ -118,4 +118,4 @@ struct ContainersManagerConfig { } // namespace vasum -#endif // SERVER_CONTAINERS_MANAGER_CONFIG_HPP +#endif // SERVER_ZONES_MANAGER_CONFIG_HPP diff --git a/server/zones-manager.cpp b/server/zones-manager.cpp new file mode 100644 index 0000000..6744c30 --- /dev/null +++ b/server/zones-manager.cpp @@ -0,0 +1,888 @@ +/* + * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved + * + * Contact: Jan Olszak + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +/** + * @file + * @author Jan Olszak (j.olszak@samsung.com) + * @brief Definition of the class for managing zones + */ + +#include "config.hpp" + +#include "host-dbus-definitions.hpp" +#include "common-dbus-definitions.hpp" +#include "zone-dbus-definitions.hpp" +#include "zones-manager.hpp" +#include "zone-admin.hpp" +#include "exception.hpp" + +#include "utils/paths.hpp" +#include "logger/logger.hpp" +#include "config/manager.hpp" +#include "dbus/exception.hpp" +#include "utils/fs.hpp" +#include "utils/img.hpp" +#include "utils/environment.hpp" + +#include +#include +#include +#include +#include +#include + + +namespace vasum { + + +namespace { + +bool regexMatchVector(const std::string& str, const std::vector& v) +{ + for (const boost::regex& toMatch: v) { + if (boost::regex_match(str, toMatch)) { + return true; + } + } + + return false; +} + +const std::string HOST_ID = "host"; +const std::string ZONE_TEMPLATE_CONFIG_PATH = "template.conf"; + +const boost::regex ZONE_NAME_REGEX("~NAME~"); +const boost::regex ZONE_IP_THIRD_OCTET_REGEX("~IP~"); + +const unsigned int ZONE_IP_BASE_THIRD_OCTET = 100; + +} // namespace + +ZonesManager::ZonesManager(const std::string& managerConfigPath): mDetachOnExit(false) +{ + LOGD("Instantiating ZonesManager object..."); + + mConfigPath = managerConfigPath; + config::loadFromFile(mConfigPath, mConfig); + + mProxyCallPolicy.reset(new ProxyCallPolicy(mConfig.proxyCallRules)); + + using namespace std::placeholders; + mHostConnection.setProxyCallCallback(bind(&ZonesManager::handleProxyCall, + this, HOST_ID, _1, _2, _3, _4, _5, _6, _7)); + + mHostConnection.setGetZoneDbusesCallback(bind( + &ZonesManager::handleGetZoneDbuses, this, _1)); + + mHostConnection.setGetZoneIdsCallback(bind(&ZonesManager::handleGetZoneIdsCall, + this, _1)); + + mHostConnection.setGetActiveZoneIdCallback(bind(&ZonesManager::handleGetActiveZoneIdCall, + this, _1)); + + mHostConnection.setGetZoneInfoCallback(bind(&ZonesManager::handleGetZoneInfoCall, + this, _1, _2)); + + mHostConnection.setDeclareFileCallback(bind(&ZonesManager::handleDeclareFileCall, + this, _1, _2, _3, _4, _5, _6)); + + mHostConnection.setDeclareMountCallback(bind(&ZonesManager::handleDeclareMountCall, + this, _1, _2, _3, _4, _5, _6, _7)); + + mHostConnection.setDeclareLinkCallback(bind(&ZonesManager::handleDeclareLinkCall, + this, _1, _2, _3, _4)); + + mHostConnection.setSetActiveZoneCallback(bind(&ZonesManager::handleSetActiveZoneCall, + this, _1, _2)); + + mHostConnection.setCreateZoneCallback(bind(&ZonesManager::handleCreateZoneCall, + this, _1, _2)); + + mHostConnection.setDestroyZoneCallback(bind(&ZonesManager::handleDestroyZoneCall, + this, _1, _2)); + + mHostConnection.setLockZoneCallback(bind(&ZonesManager::handleLockZoneCall, + this, _1, _2)); + + mHostConnection.setUnlockZoneCallback(bind(&ZonesManager::handleUnlockZoneCall, + this, _1, _2)); + + for (auto& zoneConfig : mConfig.zoneConfigs) { + createZone(zoneConfig); + } + + // check if default zone exists, throw ZoneOperationException if not found + if (!mConfig.defaultId.empty() && mZones.find(mConfig.defaultId) == mZones.end()) { + LOGE("Provided default zone ID " << mConfig.defaultId << " is invalid."); + throw ZoneOperationException("Provided default zone ID " + mConfig.defaultId + + " is invalid."); + } + + LOGD("ZonesManager object instantiated"); + + if (mConfig.inputConfig.enabled) { + LOGI("Registering input monitor [" << mConfig.inputConfig.device.c_str() << "]"); + mSwitchingSequenceMonitor.reset( + new InputMonitor(mConfig.inputConfig, + std::bind(&ZonesManager::switchingSequenceMonitorNotify, + this))); + } + + +} + +ZonesManager::~ZonesManager() +{ + LOGD("Destroying ZonesManager object..."); + + if (!mDetachOnExit) { + try { + stopAll(); + } catch (ServerException&) { + LOGE("Failed to stop all of the zones"); + } + } + + LOGD("ZonesManager object destroyed"); +} + +void ZonesManager::createZone(const std::string& zoneConfig) +{ + std::string baseConfigPath = utils::dirName(mConfigPath); + std::string zoneConfigPath = utils::getAbsolutePath(zoneConfig, baseConfigPath); + + LOGT("Creating Zone " << zoneConfigPath); + std::unique_ptr c(new Zone(mConfig.zonesPath, + zoneConfigPath, + mConfig.lxcTemplatePrefix, + mConfig.runMountPointPrefix)); + const std::string id = c->getId(); + if (id == HOST_ID) { + throw ZoneOperationException("Cannot use reserved zone ID"); + } + + using namespace std::placeholders; + c->setNotifyActiveZoneCallback(bind(&ZonesManager::notifyActiveZoneHandler, + this, id, _1, _2)); + + c->setDisplayOffCallback(bind(&ZonesManager::displayOffHandler, + this, id)); + + c->setFileMoveRequestCallback(bind(&ZonesManager::handleZoneMoveFileRequest, + this, id, _1, _2, _3)); + + c->setProxyCallCallback(bind(&ZonesManager::handleProxyCall, + this, id, _1, _2, _3, _4, _5, _6, _7)); + + c->setDbusStateChangedCallback(bind(&ZonesManager::handleDbusStateChanged, + this, id, _1)); + + mZones.insert(ZoneMap::value_type(id, std::move(c))); +} + +void ZonesManager::destroyZone(const std::string& zoneId) +{ + // TODO mutex for mZones access + auto it = mZones.find(zoneId); + if (it == mZones.end()) { + LOGE("Failed to destroy zone " << zoneId << ": no such zone"); + throw ZoneOperationException("No such zone"); + } + + // TODO give back the focus + it->second->setDestroyOnExit(); + mZones.erase(it); +} + +void ZonesManager::focus(const std::string& zoneId) +{ + /* try to access the object first to throw immediately if it doesn't exist */ + ZoneMap::mapped_type& foregroundZone = mZones.at(zoneId); + + if (!foregroundZone->activateVT()) { + LOGE("Failed to activate zones VT. Aborting focus."); + return; + } + + for (auto& zone : mZones) { + LOGD(zone.second->getId() << ": being sent to background"); + zone.second->goBackground(); + } + mConfig.foregroundId = foregroundZone->getId(); + LOGD(mConfig.foregroundId << ": being sent to foreground"); + foregroundZone->goForeground(); +} + +void ZonesManager::startAll() +{ + LOGI("Starting all zones"); + + bool isForegroundFound = false; + + for (auto& zone : mZones) { + zone.second->start(); + + if (zone.first == mConfig.foregroundId) { + isForegroundFound = true; + LOGI(zone.second->getId() << ": set as the foreground zone"); + zone.second->goForeground(); + } + } + + if (!isForegroundFound) { + auto foregroundIterator = std::min_element(mZones.begin(), mZones.end(), + [](ZoneMap::value_type &c1, ZoneMap::value_type &c2) { + return c1.second->getPrivilege() < c2.second->getPrivilege(); + }); + + if (foregroundIterator != mZones.end()) { + mConfig.foregroundId = foregroundIterator->second->getId(); + LOGI(mConfig.foregroundId << ": no foreground zone configured, setting one with highest priority"); + foregroundIterator->second->goForeground(); + } + } +} + +void ZonesManager::stopAll() +{ + LOGI("Stopping all zones"); + + for (auto& zone : mZones) { + zone.second->stop(); + } +} + +bool ZonesManager::isPaused(const std::string& zoneId) +{ + auto iter = mZones.find(zoneId); + if (iter == mZones.end()) { + LOGE("No such zone id: " << zoneId); + throw ZoneOperationException("No such zone"); + } + + return iter->second->isPaused(); +} + +bool ZonesManager::isRunning(const std::string& zoneId) +{ + auto iter = mZones.find(zoneId); + if (iter == mZones.end()) { + LOGE("No such zone id: " << zoneId); + throw ZoneOperationException("No such zone"); + } + return iter->second->isRunning(); +} + +std::string ZonesManager::getRunningForegroundZoneId() +{ + for (auto& zone : mZones) { + if (zone.first == mConfig.foregroundId && + zone.second->isRunning()) { + return zone.first; + } + } + return std::string(); +} + +std::string ZonesManager::getNextToForegroundZoneId() +{ + // handles case where there is no next zone + if (mZones.size() < 2) { + return std::string(); + } + + for (auto it = mZones.begin(); it != mZones.end(); ++it) { + if (it->first == mConfig.foregroundId && + it->second->isRunning()) { + auto nextIt = std::next(it); + if (nextIt != mZones.end()) { + return nextIt->first; + } + } + } + return mZones.begin()->first; +} + +void ZonesManager::switchingSequenceMonitorNotify() +{ + LOGI("switchingSequenceMonitorNotify() called"); + + auto nextZoneId = getNextToForegroundZoneId(); + + if (!nextZoneId.empty()) { + focus(nextZoneId); + } +} + + +void ZonesManager::setZonesDetachOnExit() +{ + mDetachOnExit = true; + + for (auto& zone : mZones) { + zone.second->setDetachOnExit(); + } +} + +void ZonesManager::notifyActiveZoneHandler(const std::string& caller, + const std::string& application, + const std::string& message) +{ + LOGI("notifyActiveZoneHandler(" << caller << ", " << application << ", " << message + << ") called"); + try { + const std::string activeZone = getRunningForegroundZoneId(); + if (!activeZone.empty() && caller != activeZone) { + mZones[activeZone]->sendNotification(caller, application, message); + } + } catch(const VasumException&) { + LOGE("Notification from " << caller << " hasn't been sent"); + } +} + +void ZonesManager::displayOffHandler(const std::string& /*caller*/) +{ + // get config of currently set zone and switch if switchToDefaultAfterTimeout is true + const std::string activeZoneName = getRunningForegroundZoneId(); + const auto& activeZone = mZones.find(activeZoneName); + + if (activeZone != mZones.end() && + activeZone->second->isSwitchToDefaultAfterTimeoutAllowed()) { + LOGI("Switching to default zone " << mConfig.defaultId); + focus(mConfig.defaultId); + } +} + +void ZonesManager::handleZoneMoveFileRequest(const std::string& srcZoneId, + const std::string& dstZoneId, + const std::string& path, + dbus::MethodResultBuilder::Pointer result) +{ + // TODO: this implementation is only a placeholder. + // There are too many unanswered questions and security concerns: + // 1. What about mount namespace, host might not see the source/destination + // file. The file might be a different file from a host perspective. + // 2. Copy vs move (speed and security concerns over already opened FDs) + // 3. Access to source and destination files - DAC, uid/gig + // 4. Access to source and destintation files - MAC, smack + // 5. Destination file uid/gid assignment + // 6. Destination file smack label assignment + // 7. Verifiability of the source path + + // NOTE: other possible implementations include: + // 1. Sending file descriptors opened directly in each zone through DBUS + // using something like g_dbus_message_set_unix_fd_list() + // 2. VSM forking and calling setns(MNT) in each zone and opening files + // by itself, then passing FDs to the main process + // Now when the main process has obtained FDs (by either of those methods) + // it can do the copying by itself. + + LOGI("File move requested\n" + << "src: " << srcZoneId << "\n" + << "dst: " << dstZoneId << "\n" + << "path: " << path); + + ZoneMap::const_iterator srcIter = mZones.find(srcZoneId); + if (srcIter == mZones.end()) { + LOGE("Source zone '" << srcZoneId << "' not found"); + return; + } + Zone& srcZone = *srcIter->second; + + ZoneMap::const_iterator dstIter = mZones.find(dstZoneId); + if (dstIter == mZones.end()) { + LOGE("Destination zone '" << dstZoneId << "' not found"); + result->set(g_variant_new("(s)", api::zone::FILE_MOVE_DESTINATION_NOT_FOUND.c_str())); + return; + } + Zone& dstContanier = *dstIter->second; + + if (srcZoneId == dstZoneId) { + LOGE("Cannot send a file to yourself"); + result->set(g_variant_new("(s)", api::zone::FILE_MOVE_WRONG_DESTINATION.c_str())); + return; + } + + if (!regexMatchVector(path, srcZone.getPermittedToSend())) { + LOGE("Source zone has no permissions to send the file: " << path); + result->set(g_variant_new("(s)", api::zone::FILE_MOVE_NO_PERMISSIONS_SEND.c_str())); + return; + } + + if (!regexMatchVector(path, dstContanier.getPermittedToRecv())) { + LOGE("Destination zone has no permissions to receive the file: " << path); + result->set(g_variant_new("(s)", api::zone::FILE_MOVE_NO_PERMISSIONS_RECEIVE.c_str())); + return; + } + + namespace fs = boost::filesystem; + std::string srcPath = fs::absolute(srcZoneId, mConfig.zonesPath).string() + path; + std::string dstPath = fs::absolute(dstZoneId, mConfig.zonesPath).string() + path; + + if (!utils::moveFile(srcPath, dstPath)) { + LOGE("Failed to move the file: " << path); + result->set(g_variant_new("(s)", api::zone::FILE_MOVE_FAILED.c_str())); + } else { + result->set(g_variant_new("(s)", api::zone::FILE_MOVE_SUCCEEDED.c_str())); + try { + dstContanier.sendNotification(srcZoneId, path, api::zone::FILE_MOVE_SUCCEEDED); + } catch (ServerException&) { + LOGE("Notification to '" << dstZoneId << "' has not been sent"); + } + } +} + +void ZonesManager::handleProxyCall(const std::string& caller, + const std::string& target, + const std::string& targetBusName, + const std::string& targetObjectPath, + const std::string& targetInterface, + const std::string& targetMethod, + GVariant* parameters, + dbus::MethodResultBuilder::Pointer result) +{ + if (!mProxyCallPolicy->isProxyCallAllowed(caller, + target, + targetBusName, + targetObjectPath, + targetInterface, + targetMethod)) { + LOGW("Forbidden proxy call; " << caller << " -> " << target << "; " << targetBusName + << "; " << targetObjectPath << "; " << targetInterface << "; " << targetMethod); + result->setError(api::ERROR_FORBIDDEN, "Proxy call forbidden"); + return; + } + + LOGI("Proxy call; " << caller << " -> " << target << "; " << targetBusName + << "; " << targetObjectPath << "; " << targetInterface << "; " << targetMethod); + + auto asyncResultCallback = [result](dbus::AsyncMethodCallResult& asyncMethodCallResult) { + try { + GVariant* targetResult = asyncMethodCallResult.get(); + result->set(g_variant_new("(v)", targetResult)); + } catch (dbus::DbusException& e) { + result->setError(api::ERROR_FORWARDED, e.what()); + } + }; + + if (target == HOST_ID) { + mHostConnection.proxyCallAsync(targetBusName, + targetObjectPath, + targetInterface, + targetMethod, + parameters, + asyncResultCallback); + return; + } + + ZoneMap::const_iterator targetIter = mZones.find(target); + if (targetIter == mZones.end()) { + LOGE("Target zone '" << target << "' not found"); + result->setError(api::ERROR_INVALID_ID, "Unknown proxy call target"); + return; + } + + Zone& targetZone = *targetIter->second; + targetZone.proxyCallAsync(targetBusName, + targetObjectPath, + targetInterface, + targetMethod, + parameters, + asyncResultCallback); +} + +void ZonesManager::handleGetZoneDbuses(dbus::MethodResultBuilder::Pointer result) +{ + std::vector entries; + for (auto& zone : mZones) { + GVariant* zoneId = g_variant_new_string(zone.first.c_str()); + GVariant* dbusAddress = g_variant_new_string(zone.second->getDbusAddress().c_str()); + GVariant* entry = g_variant_new_dict_entry(zoneId, dbusAddress); + entries.push_back(entry); + } + GVariant* dict = g_variant_new_array(G_VARIANT_TYPE("{ss}"), entries.data(), entries.size()); + result->set(g_variant_new("(*)", dict)); +} + +void ZonesManager::handleDbusStateChanged(const std::string& zoneId, + const std::string& dbusAddress) +{ + mHostConnection.signalZoneDbusState(zoneId, dbusAddress); +} + +void ZonesManager::handleGetZoneIdsCall(dbus::MethodResultBuilder::Pointer result) +{ + std::vector zoneIds; + for(auto& zone: mZones){ + zoneIds.push_back(g_variant_new_string(zone.first.c_str())); + } + + GVariant* array = g_variant_new_array(G_VARIANT_TYPE("s"), + zoneIds.data(), + zoneIds.size()); + result->set(g_variant_new("(*)", array)); +} + +void ZonesManager::handleGetActiveZoneIdCall(dbus::MethodResultBuilder::Pointer result) +{ + LOGI("GetActiveZoneId call"); + if (!mConfig.foregroundId.empty() && mZones[mConfig.foregroundId]->isRunning()){ + result->set(g_variant_new("(s)", mConfig.foregroundId.c_str())); + } else { + result->set(g_variant_new("(s)", "")); + } +} + +void ZonesManager::handleGetZoneInfoCall(const std::string& id, + dbus::MethodResultBuilder::Pointer result) +{ + LOGI("GetZoneInfo call"); + if (mZones.count(id) == 0) { + LOGE("No zone with id=" << id); + result->setError(api::ERROR_INVALID_ID, "No such zone id"); + return; + } + const auto& zone = mZones[id]; + const char* state; + //TODO: Use the lookup map. + if (zone->isRunning()) { + state = "RUNNING"; + } else if (zone->isStopped()) { + state = "STOPPED"; + } else if (zone->isPaused()) { + state = "FROZEN"; + } else { + LOGE("Unrecognized state of zone id=" << id); + result->setError(api::ERROR_INTERNAL, "Unrecognized state of zone"); + return; + } + const auto zonePath = boost::filesystem::absolute(id, mConfig.zonesPath); + const auto rootfsDir = boost::filesystem::path("rootfs"); + const auto rootfsPath = zonePath / rootfsDir; + + result->set(g_variant_new("((siss))", + id.c_str(), + zone->getVT(), + state, + rootfsPath.string().c_str())); +} + +void ZonesManager::handleDeclareFileCall(const std::string& zone, + const int32_t& type, + const std::string& path, + const int32_t& flags, + const int32_t& mode, + dbus::MethodResultBuilder::Pointer result) +{ + LOGI("DeclareFile call"); + try { + mZones.at(zone)->declareFile(type, path, flags, mode); + result->setVoid(); + } catch (const std::out_of_range& ex) { + LOGE("No zone with id=" << zone); + result->setError(api::ERROR_INVALID_ID, "No such zone id"); + } catch (const config::ConfigException& ex) { + LOGE("Can't declare file: " << ex.what()); + result->setError(api::ERROR_INTERNAL, "Internal error"); + } +} + +void ZonesManager::handleDeclareMountCall(const std::string& source, + const std::string& zone, + const std::string& target, + const std::string& type, + const uint64_t& flags, + const std::string& data, + dbus::MethodResultBuilder::Pointer result) +{ + LOGI("DeclareMount call"); + try { + mZones.at(zone)->declareMount(source, target, type, flags, data); + result->setVoid(); + } catch (const std::out_of_range& ex) { + LOGE("No zone with id=" << zone); + result->setError(api::ERROR_INVALID_ID, "No such zone id"); + } catch (const config::ConfigException& ex) { + LOGE("Can't declare mount: " << ex.what()); + result->setError(api::ERROR_INTERNAL, "Internal error"); + } +} + +void ZonesManager::handleDeclareLinkCall(const std::string& source, + const std::string& zone, + const std::string& target, + dbus::MethodResultBuilder::Pointer result) +{ + LOGI("DeclareLink call"); + try { + mZones.at(zone)->declareLink(source, target); + result->setVoid(); + } catch (const std::out_of_range& ex) { + LOGE("No zone with id=" << zone); + result->setError(api::ERROR_INVALID_ID, "No such zone id"); + } catch (const config::ConfigException& ex) { + LOGE("Can't declare link: " << ex.what()); + result->setError(api::ERROR_INTERNAL, "Internal error"); + } +} + +void ZonesManager::handleSetActiveZoneCall(const std::string& id, + dbus::MethodResultBuilder::Pointer result) +{ + LOGI("SetActiveZone call; Id=" << id ); + auto zone = mZones.find(id); + if (zone == mZones.end()){ + LOGE("No zone with id=" << id ); + result->setError(api::ERROR_INVALID_ID, "No such zone id"); + return; + } + + if (zone->second->isStopped()){ + LOGE("Could not activate a stopped zone"); + result->setError(api::host::ERROR_ZONE_STOPPED, + "Could not activate a stopped zone"); + return; + } + + focus(id); + result->setVoid(); +} + + +void ZonesManager::generateNewConfig(const std::string& id, + const std::string& templatePath, + const std::string& resultPath) +{ + namespace fs = boost::filesystem; + + std::string resultFileDir = utils::dirName(resultPath); + if (!fs::exists(resultFileDir)) { + if (!utils::createEmptyDir(resultFileDir)) { + LOGE("Unable to create directory for new config."); + throw ZoneOperationException("Unable to create directory for new config."); + } + } + + fs::path resultFile(resultPath); + if (fs::exists(resultFile)) { + LOGT(resultPath << " already exists, removing"); + fs::remove(resultFile); + } + + std::string config; + if (!utils::readFileContent(templatePath, config)) { + LOGE("Failed to read template config file."); + throw ZoneOperationException("Failed to read template config file."); + } + + std::string resultConfig = boost::regex_replace(config, ZONE_NAME_REGEX, id); + + // generate third IP octet for network config + // TODO change algorithm after implementing removeZone + std::string thirdOctetStr = std::to_string(ZONE_IP_BASE_THIRD_OCTET + mZones.size() + 1); + LOGD("IP third octet: " << thirdOctetStr); + resultConfig = boost::regex_replace(resultConfig, ZONE_IP_THIRD_OCTET_REGEX, thirdOctetStr); + + if (!utils::saveFileContent(resultPath, resultConfig)) { + LOGE("Faield to save new config file."); + throw ZoneOperationException("Failed to save new config file."); + } + + // restrict new config file so that only owner (vasum) can write it + fs::permissions(resultPath, fs::perms::owner_all | + fs::perms::group_read | + fs::perms::others_read); +} + +void ZonesManager::handleCreateZoneCall(const std::string& id, + dbus::MethodResultBuilder::Pointer result) +{ + if (id.empty()) { + LOGE("Failed to add zone - invalid name."); + result->setError(api::ERROR_INVALID_ID, "Invalid name"); + return; + } + + LOGI("Creating zone " << id); + + // TODO: This solution is temporary. It utilizes direct access to config files when creating new + // zones. Update this handler when config database will appear. + namespace fs = boost::filesystem; + + // check if zone does not exist + if (mZones.find(id) != mZones.end()) { + LOGE("Cannot create " << id << " zone - already exists!"); + result->setError(api::ERROR_INVALID_ID, "Already exists"); + return; + } + + const std::string zonePathStr = utils::createFilePath(mConfig.zonesPath, "/", id, "/"); + + // copy zone image if config contains path to image + LOGT("Image path: " << mConfig.zoneImagePath); + if (!mConfig.zoneImagePath.empty()) { + auto copyImageContentsWrapper = std::bind(&utils::copyImageContents, + mConfig.zoneImagePath, + zonePathStr); + + if (!utils::launchAsRoot(copyImageContentsWrapper)) { + LOGE("Failed to copy zone image."); + result->setError(api::ERROR_INTERNAL, "Failed to copy zone image."); + return; + } + } + + // generate paths to new configuration files + std::string baseDir = utils::dirName(mConfigPath); + std::string configDir = utils::getAbsolutePath(mConfig.zoneNewConfigPrefix, baseDir); + std::string templateDir = utils::getAbsolutePath(mConfig.zoneTemplatePath, baseDir); + + std::string configPath = utils::createFilePath(templateDir, "/", ZONE_TEMPLATE_CONFIG_PATH); + std::string newConfigPath = utils::createFilePath(configDir, "/zones/", id + ".conf"); + + auto removeAllWrapper = [](const std::string& path) -> bool { + try { + LOGD("Removing copied data"); + fs::remove_all(fs::path(path)); + } catch(const std::exception& e) { + LOGW("Failed to remove data: " << boost::diagnostic_information(e)); + } + return true; + }; + + try { + LOGI("Generating config from " << configPath << " to " << newConfigPath); + generateNewConfig(id, configPath, newConfigPath); + + } catch (VasumException& e) { + LOGE("Generate config failed: " << e.what()); + utils::launchAsRoot(std::bind(removeAllWrapper, zonePathStr)); + result->setError(api::ERROR_INTERNAL, "Failed to generate config"); + return; + } + + LOGT("Creating new zone"); + try { + createZone(newConfigPath); + } catch (VasumException& e) { + LOGE("Creating new zone failed: " << e.what()); + utils::launchAsRoot(std::bind(removeAllWrapper, zonePathStr)); + result->setError(api::ERROR_INTERNAL, "Failed to create zone"); + return; + } + + auto resultCallback = [this, id, result](bool succeeded) { + if (succeeded) { + focus(id); + result->setVoid(); + } else { + LOGE("Failed to start zone."); + // TODO removeZone + result->setError(api::ERROR_INTERNAL, "Failed to start zone"); + } + }; + mZones[id]->startAsync(resultCallback); +} + +void ZonesManager::handleDestroyZoneCall(const std::string& id, + dbus::MethodResultBuilder::Pointer result) +{ + if (mZones.find(id) == mZones.end()) { + LOGE("Failed to destroy zone - no such zone id: " << id); + result->setError(api::ERROR_INVALID_ID, "No such zone id"); + return; + } + + LOGI("Destroying zone " << id); + + auto destroyer = [id, result, this] { + try { + destroyZone(id); + } catch (const VasumException& e) { + LOGE("Error during zone destruction: " << e.what()); + result->setError(api::ERROR_INTERNAL, "Failed to destroy zone"); + return; + } + result->setVoid(); + }; + + std::thread thread(destroyer); + thread.detach(); //TODO fix it +} + +void ZonesManager::handleLockZoneCall(const std::string& id, + dbus::MethodResultBuilder::Pointer result) +{ + LOGI("LockZone call; Id=" << id ); + auto iter = mZones.find(id); + if (iter == mZones.end()) { + LOGE("Failed to lock zone - no such zone id: " << id); + result->setError(api::ERROR_INVALID_ID, "No such zone id"); + return; + } + + auto& zone = *iter->second; + if (!zone.isRunning()) { + LOGE("Zone id=" << id << " is not running."); + result->setError(api::ERROR_INVALID_STATE, "Zone is not running"); + return; + } + + LOGT("Lock zone"); + try { + zone.suspend(); + } catch (ZoneOperationException& e) { + LOGE(e.what()); + result->setError(api::ERROR_INTERNAL, e.what()); + return; + } + + result->setVoid(); +} + +void ZonesManager::handleUnlockZoneCall(const std::string& id, + dbus::MethodResultBuilder::Pointer result) +{ + LOGI("UnlockZone call; Id=" << id ); + auto iter = mZones.find(id); + if (iter == mZones.end()) { + LOGE("Failed to unlock zone - no such zone id: " << id); + result->setError(api::ERROR_INVALID_ID, "No such zone id"); + return; + } + + auto& zone = *iter->second; + if (!zone.isPaused()) { + LOGE("Zone id=" << id << " is not paused."); + result->setError(api::ERROR_INVALID_STATE, "Zone is not paused"); + return; + } + + LOGT("Unlock zone"); + try { + zone.resume(); + } catch (ZoneOperationException& e) { + LOGE(e.what()); + result->setError(api::ERROR_INTERNAL, e.what()); + return; + } + + result->setVoid(); +} + +} // namespace vasum diff --git a/server/containers-manager.hpp b/server/zones-manager.hpp similarity index 56% rename from server/containers-manager.hpp rename to server/zones-manager.hpp index b9773e9..2fc0305 100644 --- a/server/containers-manager.hpp +++ b/server/zones-manager.hpp @@ -19,15 +19,15 @@ /** * @file * @author Jan Olszak (j.olszak@samsung.com) - * @brief Declaration of the class for managing many containers + * @brief Declaration of the class for managing many zones */ -#ifndef SERVER_CONTAINERS_MANAGER_HPP -#define SERVER_CONTAINERS_MANAGER_HPP +#ifndef SERVER_ZONES_MANAGER_HPP +#define SERVER_ZONES_MANAGER_HPP -#include "container.hpp" -#include "containers-manager-config.hpp" +#include "zone.hpp" +#include "zones-manager-config.hpp" #include "host-connection.hpp" #include "input-monitor.hpp" #include "proxy-call-policy.hpp" @@ -40,79 +40,79 @@ namespace vasum { -class ContainersManager final { +class ZonesManager final { public: - ContainersManager(const std::string& managerConfigPath); - ~ContainersManager(); + ZonesManager(const std::string& managerConfigPath); + ~ZonesManager(); /** - * Create new container. + * Create new zone. * - * @param containerConfig config of new container + * @param zoneConfig config of new zone */ - void createContainer(const std::string& containerConfig); + void createZone(const std::string& zoneConfig); /** - * Destroy container. + * Destroy zone. * - * @param containerId id of the container + * @param zoneId id of the zone */ - void destroyContainer(const std::string& containerId); + void destroyZone(const std::string& zoneId); /** - * Focus this container, put it to the foreground. + * Focus this zone, put it to the foreground. * Method blocks until the focus is switched. * - * @param containerId id of the container + * @param zoneId id of the zone */ - void focus(const std::string& containerId); + void focus(const std::string& zoneId); /** - * Start up all the configured containers + * Start up all the configured zones */ void startAll(); /** - * Stop all managed containers + * Stop all managed zones */ void stopAll(); /** - * @return Is the container in a paused state? + * @return Is the zone in a paused state? */ - bool isPaused(const std::string& containerId); + bool isPaused(const std::string& zoneId); /** - * @return Is the container running? + * @return Is the zone running? */ - bool isRunning(const std::string& containerId); + bool isRunning(const std::string& zoneId); /** - * @return id of the currently focused/foreground container + * @return id of the currently focused/foreground zone */ - std::string getRunningForegroundContainerId(); + std::string getRunningForegroundZoneId(); /** - * @return id of next to currently focused/foreground container. If currently focused container - * is last in container map, id of fisrt container from map is returned. + * @return id of next to currently focused/foreground zone. If currently focused zone + * is last in zone map, id of fisrt zone from map is returned. */ - std::string getNextToForegroundContainerId(); + std::string getNextToForegroundZoneId(); /** - * Set whether ContainersManager should detach containers on exit + * Set whether ZonesManager should detach zones on exit */ - void setContainersDetachOnExit(); + void setZonesDetachOnExit(); private: - ContainersManagerConfig mConfig; + ZonesManagerConfig mConfig; std::string mConfigPath; HostConnection mHostConnection; - // to hold InputMonitor pointer to monitor if container switching sequence is recognized + // to hold InputMonitor pointer to monitor if zone switching sequence is recognized std::unique_ptr mSwitchingSequenceMonitor; std::unique_ptr mProxyCallPolicy; - typedef std::unordered_map> ContainerMap; - ContainerMap mContainers; // map of containers, id is the key + typedef std::unordered_map> ZoneMap; + ZoneMap mZones; // map of zones, id is the key bool mDetachOnExit; void switchingSequenceMonitorNotify(); @@ -120,12 +120,12 @@ private: const std::string& templatePath, const std::string& resultPath); - void notifyActiveContainerHandler(const std::string& caller, + void notifyActiveZoneHandler(const std::string& caller, const std::string& appliaction, const std::string& message); void displayOffHandler(const std::string& caller); - void handleContainerMoveFileRequest(const std::string& srcContainerId, - const std::string& dstContainerId, + void handleZoneMoveFileRequest(const std::string& srcZoneId, + const std::string& dstZoneId, const std::string& path, dbus::MethodResultBuilder::Pointer result); void handleProxyCall(const std::string& caller, @@ -136,37 +136,37 @@ private: const std::string& targetMethod, GVariant* parameters, dbus::MethodResultBuilder::Pointer result); - void handleGetContainerDbuses(dbus::MethodResultBuilder::Pointer result); - void handleDbusStateChanged(const std::string& containerId, const std::string& dbusAddress); - void handleGetContainerIdsCall(dbus::MethodResultBuilder::Pointer result); - void handleGetActiveContainerIdCall(dbus::MethodResultBuilder::Pointer result); - void handleGetContainerInfoCall(const std::string& id, dbus::MethodResultBuilder::Pointer result); - void handleDeclareFileCall(const std::string& container, + void handleGetZoneDbuses(dbus::MethodResultBuilder::Pointer result); + void handleDbusStateChanged(const std::string& zoneId, const std::string& dbusAddress); + void handleGetZoneIdsCall(dbus::MethodResultBuilder::Pointer result); + void handleGetActiveZoneIdCall(dbus::MethodResultBuilder::Pointer result); + void handleGetZoneInfoCall(const std::string& id, dbus::MethodResultBuilder::Pointer result); + void handleDeclareFileCall(const std::string& zone, const int32_t& type, const std::string& path, const int32_t& flags, const int32_t& mode, dbus::MethodResultBuilder::Pointer result); void handleDeclareMountCall(const std::string& source, - const std::string& container, + const std::string& zone, const std::string& target, const std::string& type, const uint64_t& flags, const std::string& data, dbus::MethodResultBuilder::Pointer result); void handleDeclareLinkCall(const std::string& source, - const std::string& container, + const std::string& zone, const std::string& target, dbus::MethodResultBuilder::Pointer result); - void handleSetActiveContainerCall(const std::string& id, + void handleSetActiveZoneCall(const std::string& id, dbus::MethodResultBuilder::Pointer result); - void handleCreateContainerCall(const std::string& id, + void handleCreateZoneCall(const std::string& id, dbus::MethodResultBuilder::Pointer result); - void handleDestroyContainerCall(const std::string& id, + void handleDestroyZoneCall(const std::string& id, dbus::MethodResultBuilder::Pointer result); - void handleLockContainerCall(const std::string& id, + void handleLockZoneCall(const std::string& id, dbus::MethodResultBuilder::Pointer result); - void handleUnlockContainerCall(const std::string& id, + void handleUnlockZoneCall(const std::string& id, dbus::MethodResultBuilder::Pointer result); }; @@ -174,4 +174,4 @@ private: } // namespace vasum -#endif // SERVER_CONTAINERS_MANAGER_HPP +#endif // SERVER_ZONES_MANAGER_HPP diff --git a/tests/integration_tests/image_tests/config_checker.py b/tests/integration_tests/image_tests/config_checker.py index 035c460..0d47b8e 100644 --- a/tests/integration_tests/image_tests/config_checker.py +++ b/tests/integration_tests/image_tests/config_checker.py @@ -1,4 +1,4 @@ -'''! Module used to collect list of containers based on the vasum configuration files. +'''! Module used to collect list of zones based on the vasum configuration files. @author: Michal Witanowski (m.witanowski@samsung.com) ''' @@ -11,11 +11,11 @@ from pprint import pprint class ConfigChecker: '''! This class verifies vasum configuration files and collects dictionary with - containers existing in the system (name and rootfs path). + zones existing in the system (name and rootfs path). ''' def __parseLibvirtXML(self, path): - '''! Parses libvirt's configuration in order to extract container name and path. + '''! Parses libvirt's configuration in order to extract zone name and path. @param path Libvirt's zone configuration path ''' @@ -43,20 +43,20 @@ class ConfigChecker: if rootFound: raise Exception("Multiple root fs mounts found in file: " + path) else: - self.containers[name] = source - print " Container '" + name + "' found at: " + source + self.zones[name] = source + print " Zone '" + name + "' found at: " + source rootFound = True if not rootFound: - raise Exception("Root directory of '" + name + "' container not specified in XML") + raise Exception("Root directory of '" + name + "' zone not specified in XML") def __init__(self, mainConfigPath): '''! Parses daemon's JSON configuration files. @param mainConfigPath Path to the main config "daemon.conf" ''' - self.containers = {} - print "Looking for container IDs..." + self.zones = {} + print "Looking for zone IDs..." # load main daemon JSON config file if not os.path.isfile(mainConfigPath): @@ -66,21 +66,21 @@ class ConfigChecker: daemonConfigData = json.load(daemonConfigStr) daemonConfigDir = os.path.dirname(os.path.abspath(mainConfigPath)) - # get dictionary with containers - containerConfigPaths = daemonConfigData["containerConfigs"] - for configPath in containerConfigPaths: + # get dictionary with zones + zoneConfigPaths = daemonConfigData["zoneConfigs"] + for configPath in zoneConfigPaths: - # open container config file - containerConfigPath = os.path.join(daemonConfigDir, configPath) - if not os.path.isfile(containerConfigPath): - raise Exception(containerConfigPath + " not found. " + + # open zone config file + zoneConfigPath = os.path.join(daemonConfigDir, configPath) + if not os.path.isfile(zoneConfigPath): + raise Exception(zoneConfigPath + " not found. " + "Please verify that vasum is properly installed.") - with open(containerConfigPath) as containerConfigStr: - containerConfigData = json.load(containerConfigStr) + with open(zoneConfigPath) as zoneConfigStr: + zoneConfigData = json.load(zoneConfigStr) # extract XML config path for libvirt - libvirtConfigPath = os.path.join(daemonConfigDir, "containers", - containerConfigData["config"]) + libvirtConfigPath = os.path.join(daemonConfigDir, "zones", + zoneConfigData["config"]) output, ret = vsm_test_utils.launchProc("virt-xml-validate " + libvirtConfigPath) if ret == 0: diff --git a/tests/integration_tests/image_tests/image_tests.py b/tests/integration_tests/image_tests/image_tests.py index 79f72e8..6898bdc 100644 --- a/tests/integration_tests/image_tests/image_tests.py +++ b/tests/integration_tests/image_tests/image_tests.py @@ -1,4 +1,4 @@ -'''! Module used to test containers' images completeness +'''! Module used to test zones' images completeness @author: Michal Witanowski (m.witanowski@samsung.com) ''' @@ -12,50 +12,50 @@ import xml.etree.ElementTree as ET VSM_USER_NAME = "security-containers" VSM_UID = 377 -DAEMON_DBUS_SOCKET_NAME = "org.tizen.containers.zone" +DAEMON_DBUS_SOCKET_NAME = "org.tizen.vasum.zone" -# dbus config file path relative to container's root +# dbus config file path relative to zone's root DBUS_CONFIG_PATH = "etc/dbus-1/system.d/" + DAEMON_DBUS_SOCKET_NAME + ".conf" # main daemon config DAEMON_CONFIG_PATH = "/etc/vasum/daemon.conf" -class ContainerImageTestCase(unittest.TestCase): - '''! Test case class verifying containers' images +class ZoneImageTestCase(unittest.TestCase): + '''! Test case class verifying zones' images ''' @classmethod def setUpClass(self): - '''! Sets up testing environment - collects container names and paths. + '''! Sets up testing environment - collects zone names and paths. ''' self.configChecker = ConfigChecker(DAEMON_CONFIG_PATH) def test01_vsmUserExistence(self): '''! Verifies if "vasum" user with an appropriate UID exists within the - containers. + zones. ''' - for containerName, containerPath in self.configChecker.containers.iteritems(): - # chroot into a container and get UID of the user - output, ret = vsm_test_utils.launchProc("chroot " + containerPath + + for zoneName, zonePath in self.configChecker.zones.iteritems(): + # chroot into a zone and get UID of the user + output, ret = vsm_test_utils.launchProc("chroot " + zonePath + " /usr/bin/id -u " + VSM_USER_NAME) self.assertEqual(ret, 0, "User '" + VSM_USER_NAME + "' does not exist in '" + - containerName + "' container.") + zoneName + "' zone.") # cast to integer to remove white spaces, etc. uid = int(output) self.assertEqual(uid, VSM_UID, "Invalid UID of '" + VSM_USER_NAME + "' in '" + - containerName + "' container: got " + str(uid) + + zoneName + "' zone: got " + str(uid) + ", should be " + str(VSM_UID)) def test02_dbusConfig(self): - '''! Verifies if dbus configuration file exists within containers. + '''! Verifies if dbus configuration file exists within zones. ''' - for containerName, containerPath in self.configChecker.containers.iteritems(): - configPath = os.path.join(containerPath, DBUS_CONFIG_PATH) + for zoneName, zonePath in self.configChecker.zones.iteritems(): + configPath = os.path.join(zonePath, DBUS_CONFIG_PATH) self.assertTrue(os.path.isfile(configPath), "Dbus configuration not found in '" + - containerName + "' container") + zoneName + "' zone") tree = ET.parse(configPath) root = tree.getroot() @@ -85,4 +85,4 @@ class ContainerImageTestCase(unittest.TestCase): DAEMON_DBUS_SOCKET_NAME) if not (ownCheck and sendDestinationCheck and sendDestinationCheck): - raise Exception("Invalid dbus configuration in '" + containerName + "' container") + raise Exception("Invalid dbus configuration in '" + zoneName + "' zone") diff --git a/tests/integration_tests/network_tests/network_common.py b/tests/integration_tests/network_tests/network_common.py index 3432c88..945b255 100755 --- a/tests/integration_tests/network_tests/network_common.py +++ b/tests/integration_tests/network_tests/network_common.py @@ -28,18 +28,18 @@ DEBUG_COMMAND=False # Test urls TEST_URL_INTERNET=["www.samsung.com", "www.google.com", "www.oracle.com"] -# Path to test container -TEST_CONTAINER_PATH="/opt/usr/containers/private" +# Path to test zone +TEST_ZONE_PATH="/opt/usr/zones/private" # Device Ethernet device ETHERNET_DEVICE="usb0" ETHERNET_DEVICE_DETECT=False -# Test containers -CONTAINER_T1="business" -CONTAINER_T2="private" +# Test zones +ZONE_T1="business" +ZONE_T2="private" -containers=[CONTAINER_T1, CONTAINER_T2] +zones=[ZONE_T1, ZONE_T2] # Null device OUTPUT_TO_NULL_DEVICE=" >/dev/null 2>&1 " @@ -125,10 +125,10 @@ def runCommandAndReadOutput(cmd): break # ---------------------------------------------------------- -# The function checks whether test container image is present in system +# The function checks whether test zone image is present in system # def test_guest_image(): - rc = runCommand("/usr/bin/chroot " + TEST_CONTAINER_PATH + " /bin/true") + rc = runCommand("/usr/bin/chroot " + TEST_ZONE_PATH + " /bin/true") if( rc != 0 ): return 1 return 0 @@ -154,7 +154,7 @@ def getActiveEthernetDevice(): def test_mandatory_toos(): tools =["/usr/bin/ping"] - root_tools=[TEST_CONTAINER_PATH] + root_tools=[TEST_ZONE_PATH] for i in range(len(tools)): rc = runCommand("/usr/bin/ls " + root_tools[i] + tools[i]) @@ -180,11 +180,11 @@ def test_result(expected_result, result): # ---------------------------------------------------------- # The function performs single internet access test # -def internetAccessTest(container): +def internetAccessTest(zone): count=0 for item in TEST_URL_INTERNET: LOG_INFO(" Test for URL : " + item); - rc = virshCmd("lxc-enter-namespace " + container + \ + rc = virshCmd("lxc-enter-namespace " + zone + \ " --noseclabel -- /usr/bin/ping -c 3 -W " + \ str(PING_TIME_OUT) + " " + item) if(rc != 0): @@ -198,14 +198,14 @@ def internetAccessTest(container): # ---------------------------------------------------------- # The function performs single internet access test # -def networkVisibiltyTest(container, dest_ip): - return virshCmd("lxc-enter-namespace " + container + \ +def networkVisibiltyTest(zone, dest_ip): + return virshCmd("lxc-enter-namespace " + zone + \ " --noseclabel -- /usr/bin/ping -c 3 -W " + \ str(PING_TIME_OUT) + " " + dest_ip) -def printInternetAccessTestStatus(container, testInfo1): +def printInternetAccessTestStatus(zone, testInfo1): - text = " Internet access for container: " + container + \ + text = " Internet access for zone: " + zone + \ "; TCS = " + testInfo1.testItemResult[len(testInfo1.testItemResult)-1] if(testInfo1.testItemResult[len(testInfo1.testItemResult)-1] == "Success"): @@ -215,7 +215,7 @@ def printInternetAccessTestStatus(container, testInfo1): def networkVisibiltyTestStatus(src, dest, ip, testInfo2): - text = " Container access: " + src + \ + text = " Zone access: " + src + \ " -> " + dest + \ " [" + ip + "]" + \ "; TCS = " + testInfo2.testItemResult[len(testInfo2.testItemResult)-1] @@ -226,15 +226,15 @@ def networkVisibiltyTestStatus(src, dest, ip, testInfo2): LOG_ERROR(text) # ---------------------------------------------------------- -# The function performs test case for two containers - Business and Private. -# Both containers are mutually isolated and have access to the Internet. +# The function performs test case for two zones - Business and Private. +# Both zones are mutually isolated and have access to the Internet. # def twoNetworks(): ltestInfo = TestNetworkInfo("Two networks tests") # 0. Test data - containers_list = [CONTAINER_T1, CONTAINER_T2] - dest_containers_list = [CONTAINER_T2, CONTAINER_T1] + zones_list = [ZONE_T1, ZONE_T2] + dest_zones_list = [ZONE_T2, ZONE_T1] test_ip_list = [["10.0.101.2"], ["10.0.102.2"]] test_1_expected_res = [ 0, 0] test_2_expected_res = [-1, -1] @@ -243,17 +243,17 @@ def twoNetworks(): LOG_INFO(" - Setup device") # 2. Internet access - LOG_INFO(" - Two containers environment network test case execution") + LOG_INFO(" - Two zones environment network test case execution") LOG_INFO(" - Internet access test") - for i in range(len(containers_list)): + for i in range(len(zones_list)): # - Test case info ltestInfo.testItemType.append("[Two nets] Internet access") - ltestInfo.testItemName.append(containers_list[i]) - ltestInfo.testItemDescription.append("Internet access test for : " + containers_list[i]) + ltestInfo.testItemName.append(zones_list[i]) + ltestInfo.testItemDescription.append("Internet access test for : " + zones_list[i]) # - Perform test - rc = internetAccessTest(containers_list[i]) + rc = internetAccessTest(zones_list[i]) # - Test status store if(test_result(test_1_expected_res[i], rc) == 0): @@ -264,22 +264,22 @@ def twoNetworks(): ltestInfo.testItemResult.append("Error") # - Print status - printInternetAccessTestStatus(containers_list[i], ltestInfo) + printInternetAccessTestStatus(zones_list[i], ltestInfo) - # 3. Mutual containers visibility - LOG_INFO(" - Containers isolation") - for i in range(len(containers_list)): + # 3. Mutual zones visibility + LOG_INFO(" - Zones isolation") + for i in range(len(zones_list)): # Interate over destynation ips dest_ips = test_ip_list[i] for j in range(len(dest_ips)): # - Test case info ltestInfo.testItemType.append("[Two nets] Visibility") - ltestInfo.testItemName.append(containers_list[i] + "->" + dest_containers_list[i]) - ltestInfo.testItemDescription.append("Container access for : " + containers_list[i]) + ltestInfo.testItemName.append(zones_list[i] + "->" + dest_zones_list[i]) + ltestInfo.testItemDescription.append("Zone access for : " + zones_list[i]) # Perform test - rc = networkVisibiltyTest(containers_list[i], dest_ips[j]) + rc = networkVisibiltyTest(zones_list[i], dest_ips[j]) # - Test status store if(test_result(test_2_expected_res[i], rc) == 0): @@ -290,7 +290,7 @@ def twoNetworks(): ltestInfo.testItemResult.append("Error") # - Print status - networkVisibiltyTestStatus(containers_list[i], dest_containers_list[i], dest_ips[j], ltestInfo) + networkVisibiltyTestStatus(zones_list[i], dest_zones_list[i], dest_ips[j], ltestInfo) LOG_INFO(" - Clean environment") diff --git a/tests/integration_tests/network_tests/network_tests.py b/tests/integration_tests/network_tests/network_tests.py index fb10195..980830e 100644 --- a/tests/integration_tests/network_tests/network_tests.py +++ b/tests/integration_tests/network_tests/network_tests.py @@ -16,7 +16,7 @@ # @author Jacek Pielaszkiewicz (j.pielaszkie@samsung.com) # -'''! Module used to test network in containers +'''! Module used to test network in zones @author: Jacek Pielaszkiewicz (j.pielaszkie@samsung.com) ''' @@ -35,9 +35,9 @@ class NetworkTestCase(unittest.TestCase): self.assertTrue(False, "ROOT user is required to run the test") return - # 2. Test container images + # 2. Test zone images if(test_guest_image() == 1): - self.assertTrue(False, "No test container in path :" + TEST_CONTAINER_PATH) + self.assertTrue(False, "No test zone in path :" + TEST_ZONE_PATH) return # 3. Test mandatory tools diff --git a/tests/unit_tests/client/configs/CMakeLists.txt b/tests/unit_tests/client/configs/CMakeLists.txt index c4bbda2..8742612 100644 --- a/tests/unit_tests/client/configs/CMakeLists.txt +++ b/tests/unit_tests/client/configs/CMakeLists.txt @@ -24,16 +24,16 @@ CONFIGURE_FILE(ut-client/test-dbus-daemon.conf.in ${CMAKE_BINARY_DIR}/ut-client/test-dbus-daemon.conf @ONLY) FILE(GLOB client_manager_CONF_GEN ${CMAKE_BINARY_DIR}/ut-client/*.conf) -CONFIGURE_FILE(ut-client/containers/console1-dbus.conf.in - ${CMAKE_BINARY_DIR}/ut-client/containers/console1-dbus.conf @ONLY) -CONFIGURE_FILE(ut-client/containers/console2-dbus.conf.in - ${CMAKE_BINARY_DIR}/ut-client/containers/console2-dbus.conf @ONLY) -CONFIGURE_FILE(ut-client/containers/console3-dbus.conf.in - ${CMAKE_BINARY_DIR}/ut-client/containers/console3-dbus.conf @ONLY) -FILE(GLOB client_container_CONF_GEN ${CMAKE_BINARY_DIR}/ut-client/containers/*.conf) +CONFIGURE_FILE(ut-client/zones/console1-dbus.conf.in + ${CMAKE_BINARY_DIR}/ut-client/zones/console1-dbus.conf @ONLY) +CONFIGURE_FILE(ut-client/zones/console2-dbus.conf.in + ${CMAKE_BINARY_DIR}/ut-client/zones/console2-dbus.conf @ONLY) +CONFIGURE_FILE(ut-client/zones/console3-dbus.conf.in + ${CMAKE_BINARY_DIR}/ut-client/zones/console3-dbus.conf @ONLY) +FILE(GLOB client_zone_CONF_GEN ${CMAKE_BINARY_DIR}/ut-client/zones/*.conf) ## Install ##################################################################### INSTALL(FILES ${client_manager_CONF_GEN} DESTINATION ${VSM_TEST_CONFIG_INSTALL_DIR}/client/ut-client) -INSTALL(FILES ${client_container_CONF_GEN} - DESTINATION ${VSM_TEST_CONFIG_INSTALL_DIR}/client/ut-client/containers) +INSTALL(FILES ${client_zone_CONF_GEN} + DESTINATION ${VSM_TEST_CONFIG_INSTALL_DIR}/client/ut-client/zones) 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 33a8a0d..1b90e67 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 @@ -1,13 +1,13 @@ { - "containerConfigs" : ["containers/console1-dbus.conf", - "containers/console2-dbus.conf", - "containers/console3-dbus.conf"], - "foregroundId" : "ut-containers-manager-console1-dbus", - "defaultId" : "ut-containers-manager-console1-dbus", - "containersPath" : "/tmp/ut-containers", - "containerImagePath" : "", - "containerTemplatePath" : "", - "containerNewConfigPrefix" : "", + "zoneConfigs" : ["zones/console1-dbus.conf", + "zones/console2-dbus.conf", + "zones/console3-dbus.conf"], + "foregroundId" : "ut-zones-manager-console1-dbus", + "defaultId" : "ut-zones-manager-console1-dbus", + "zonesPath" : "/tmp/ut-zones", + "zoneImagePath" : "", + "zoneTemplatePath" : "", + "zoneNewConfigPrefix" : "", "runMountPointPrefix" : "", "lxcTemplatePrefix" : "@VSM_TEST_LXC_TEMPLATES_INSTALL_DIR@", "inputConfig" : {"enabled" : false, @@ -17,7 +17,7 @@ "timeWindowMs" : 500}, "proxyCallRules" : [{"caller" : "*", "target" : "*", - "targetBusName" : "org.tizen.containers.tests", + "targetBusName" : "org.tizen.vasum.tests", "targetObjectPath" : "*", "targetInterface" : "*", "targetMethod" : "*"}] diff --git a/tests/unit_tests/client/configs/ut-client/containers/console1-dbus.conf.in b/tests/unit_tests/client/configs/ut-client/zones/console1-dbus.conf.in similarity index 73% rename from tests/unit_tests/client/configs/ut-client/containers/console1-dbus.conf.in rename to tests/unit_tests/client/configs/ut-client/zones/console1-dbus.conf.in index 4bf616c..72fbdbf 100644 --- a/tests/unit_tests/client/configs/ut-client/containers/console1-dbus.conf.in +++ b/tests/unit_tests/client/configs/ut-client/zones/console1-dbus.conf.in @@ -1,7 +1,7 @@ { - "name" : "ut-containers-manager-console1-dbus", + "name" : "ut-zones-manager-console1-dbus", "lxcTemplate" : "minimal-dbus.sh", - "initWithArgs" : ["/bin/sh", "-c", "trap exit SIGTERM; /usr/bin/dbus-daemon --config-file=@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-containers-manager/ut-dbus.conf --fork; read"], + "initWithArgs" : ["/bin/sh", "-c", "trap exit SIGTERM; /usr/bin/dbus-daemon --config-file=@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-zones-manager/ut-dbus.conf --fork; read"], "ipv4Gateway" : "", "ipv4" : "", "privilege" : 20, @@ -10,7 +10,7 @@ "enableDbusIntegration" : true, "cpuQuotaForeground" : -1, "cpuQuotaBackground" : 1000, - "runMountPoint" : "/tmp/ut-run/ut-containers-manager-console1-dbus", + "runMountPoint" : "/tmp/ut-run/ut-zones-manager-console1-dbus", "permittedToSend" : [ "/tmp/.*", "/etc/secret2" ], "permittedToRecv" : [ "/tmp/.*" ] } diff --git a/tests/unit_tests/server/configs/ut-containers-manager/containers/console2-dbus.conf.in b/tests/unit_tests/client/configs/ut-client/zones/console2-dbus.conf.in similarity index 73% rename from tests/unit_tests/server/configs/ut-containers-manager/containers/console2-dbus.conf.in rename to tests/unit_tests/client/configs/ut-client/zones/console2-dbus.conf.in index 4ca2215..1386878 100644 --- a/tests/unit_tests/server/configs/ut-containers-manager/containers/console2-dbus.conf.in +++ b/tests/unit_tests/client/configs/ut-client/zones/console2-dbus.conf.in @@ -1,7 +1,7 @@ { - "name" : "ut-containers-manager-console2-dbus", + "name" : "ut-zones-manager-console2-dbus", "lxcTemplate" : "minimal-dbus.sh", - "initWithArgs" : ["/bin/sh", "-c", "trap exit SIGTERM; /usr/bin/dbus-daemon --config-file=@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-containers-manager/ut-dbus.conf --fork; read"], + "initWithArgs" : ["/bin/sh", "-c", "trap exit SIGTERM; /usr/bin/dbus-daemon --config-file=@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-zones-manager/ut-dbus.conf --fork; read"], "ipv4Gateway" : "", "ipv4" : "", "privilege" : 20, @@ -10,7 +10,7 @@ "enableDbusIntegration" : true, "cpuQuotaForeground" : -1, "cpuQuotaBackground" : 1000, - "runMountPoint" : "/tmp/ut-run/ut-containers-manager-console2-dbus", + "runMountPoint" : "/tmp/ut-run/ut-zones-manager-console2-dbus", "permittedToSend" : [ "/tmp/.*" ], "permittedToRecv" : [ "/tmp/.*", "/etc/secret1" ] } diff --git a/tests/unit_tests/client/configs/ut-client/containers/console3-dbus.conf.in b/tests/unit_tests/client/configs/ut-client/zones/console3-dbus.conf.in similarity index 72% rename from tests/unit_tests/client/configs/ut-client/containers/console3-dbus.conf.in rename to tests/unit_tests/client/configs/ut-client/zones/console3-dbus.conf.in index f3d8385..f91754f 100644 --- a/tests/unit_tests/client/configs/ut-client/containers/console3-dbus.conf.in +++ b/tests/unit_tests/client/configs/ut-client/zones/console3-dbus.conf.in @@ -1,7 +1,7 @@ { - "name" : "ut-containers-manager-console3-dbus", + "name" : "ut-zones-manager-console3-dbus", "lxcTemplate" : "minimal-dbus.sh", - "initWithArgs" : ["/bin/sh", "-c", "trap exit SIGTERM; /usr/bin/dbus-daemon --config-file=@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-containers-manager/ut-dbus.conf --fork; read"], + "initWithArgs" : ["/bin/sh", "-c", "trap exit SIGTERM; /usr/bin/dbus-daemon --config-file=@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-zones-manager/ut-dbus.conf --fork; read"], "ipv4Gateway" : "", "ipv4" : "", "privilege" : 20, @@ -10,7 +10,7 @@ "enableDbusIntegration" : true, "cpuQuotaForeground" : -1, "cpuQuotaBackground" : 1000, - "runMountPoint" : "/tmp/ut-run/ut-containers-manager-console3-dbus", + "runMountPoint" : "/tmp/ut-run/ut-zones-manager-console3-dbus", "permittedToSend" : [ "/tmp/.*" ], "permittedToRecv" : [ "/tmp/.*" ] } diff --git a/tests/unit_tests/client/ut-client-utils.cpp b/tests/unit_tests/client/ut-client-utils.cpp index 334d7bf..140238a 100644 --- a/tests/unit_tests/client/ut-client-utils.cpp +++ b/tests/unit_tests/client/ut-client-utils.cpp @@ -30,16 +30,16 @@ BOOST_AUTO_TEST_SUITE(ClientUtils) -BOOST_AUTO_TEST_CASE(ParseContainerIdFromCpuSetTest) +BOOST_AUTO_TEST_CASE(ParseZoneIdFromCpuSetTest) { auto testBad = [](const std::string& input) { std::string ret; - BOOST_CHECK(!parseContainerIdFromCpuSet(input, ret)); + BOOST_CHECK(!parseZoneIdFromCpuSet(input, ret)); }; auto testOK = [](const std::string& input, const std::string& expected) { std::string ret; - BOOST_CHECK(parseContainerIdFromCpuSet(input, ret)); + BOOST_CHECK(parseZoneIdFromCpuSet(input, ret)); BOOST_CHECK_EQUAL(expected, ret); }; diff --git a/tests/unit_tests/client/ut-client.cpp b/tests/unit_tests/client/ut-client.cpp index ec38228..e8060be 100644 --- a/tests/unit_tests/client/ut-client.cpp +++ b/tests/unit_tests/client/ut-client.cpp @@ -29,8 +29,8 @@ #include "utils/latch.hpp" #include "utils/scoped-dir.hpp" -#include "containers-manager.hpp" -#include "container-dbus-definitions.hpp" +#include "zones-manager.hpp" +#include "zone-dbus-definitions.hpp" #include #include @@ -47,7 +47,7 @@ namespace { const std::string TEST_DBUS_CONFIG_PATH = VSM_TEST_CONFIG_INSTALL_DIR "/client/ut-client/test-dbus-daemon.conf"; -const std::string CONTAINERS_PATH = "/tmp/ut-containers"; // the same as in daemon.conf +const std::string ZONES_PATH = "/tmp/ut-zones"; // the same as in daemon.conf struct Loop { Loop() @@ -62,13 +62,13 @@ struct Loop { struct Fixture { Loop loop; - utils::ScopedDir mContainersPathGuard; + utils::ScopedDir mZonesPathGuard; utils::ScopedDir mRunGuard; - ContainersManager cm; + ZonesManager cm; Fixture() - : mContainersPathGuard(CONTAINERS_PATH) + : mZonesPathGuard(ZONES_PATH) , mRunGuard("/tmp/ut-run") , cm(TEST_DBUS_CONFIG_PATH) { @@ -79,16 +79,16 @@ struct Fixture { const int EVENT_TIMEOUT = 5000; ///< ms const std::map EXPECTED_DBUSES_STARTED = { { - "ut-containers-manager-console1-dbus", - "unix:path=/tmp/ut-run/ut-containers-manager-console1-dbus/dbus/system_bus_socket" + "ut-zones-manager-console1-dbus", + "unix:path=/tmp/ut-run/ut-zones-manager-console1-dbus/dbus/system_bus_socket" }, { - "ut-containers-manager-console2-dbus", - "unix:path=/tmp/ut-run/ut-containers-manager-console2-dbus/dbus/system_bus_socket" + "ut-zones-manager-console2-dbus", + "unix:path=/tmp/ut-run/ut-zones-manager-console2-dbus/dbus/system_bus_socket" }, { - "ut-containers-manager-console3-dbus", - "unix:path=/tmp/ut-run/ut-containers-manager-console3-dbus/dbus/system_bus_socket" + "ut-zones-manager-console3-dbus", + "unix:path=/tmp/ut-run/ut-zones-manager-console3-dbus/dbus/system_bus_socket" } }; @@ -136,13 +136,13 @@ BOOST_AUTO_TEST_CASE(NotRunningServerTest) vsm_client_free(client); } -BOOST_AUTO_TEST_CASE(GetContainerDbusesTest) +BOOST_AUTO_TEST_CASE(GetZoneDbusesTest) { VsmClient client = vsm_client_create(); VsmStatus status = vsm_connect(client); BOOST_REQUIRE_EQUAL(VSMCLIENT_SUCCESS, status); VsmArrayString keys, values; - status = vsm_get_container_dbuses(client, &keys, &values); + status = vsm_get_zone_dbuses(client, &keys, &values); BOOST_REQUIRE_EQUAL(VSMCLIENT_SUCCESS, status); BOOST_CHECK_EQUAL(getArrayStringLength(keys, EXPECTED_DBUSES_STARTED.size() + 1), @@ -150,15 +150,15 @@ BOOST_AUTO_TEST_CASE(GetContainerDbusesTest) BOOST_CHECK_EQUAL(getArrayStringLength(values, EXPECTED_DBUSES_STARTED.size() + 1), EXPECTED_DBUSES_STARTED.size()); - std::map containers; - convertDictToMap(keys, values, containers); - BOOST_CHECK(containers == EXPECTED_DBUSES_STARTED); + std::map zones; + convertDictToMap(keys, values, zones); + BOOST_CHECK(zones == EXPECTED_DBUSES_STARTED); vsm_array_string_free(keys); vsm_array_string_free(values); vsm_client_free(client); } -BOOST_AUTO_TEST_CASE(GetContainerIdsTest) +BOOST_AUTO_TEST_CASE(GetZoneIdsTest) { VsmClient client = vsm_client_create(); VsmStatus status = vsm_connect(client); @@ -169,68 +169,68 @@ BOOST_AUTO_TEST_CASE(GetContainerIdsTest) BOOST_CHECK_EQUAL(getArrayStringLength(values, EXPECTED_DBUSES_STARTED.size() + 1), EXPECTED_DBUSES_STARTED.size()); - std::set containers; - convertArrayToSet(values, containers); + std::set zones; + convertArrayToSet(values, zones); - for (const auto& container : containers) { - BOOST_CHECK(EXPECTED_DBUSES_STARTED.find(container) != EXPECTED_DBUSES_STARTED.cend()); + for (const auto& zone : zones) { + BOOST_CHECK(EXPECTED_DBUSES_STARTED.find(zone) != EXPECTED_DBUSES_STARTED.cend()); } vsm_array_string_free(values); vsm_client_free(client); } -BOOST_AUTO_TEST_CASE(GetActiveContainerIdTest) +BOOST_AUTO_TEST_CASE(GetActiveZoneIdTest) { VsmClient client = vsm_client_create(); VsmStatus status = vsm_connect(client); BOOST_REQUIRE_EQUAL(VSMCLIENT_SUCCESS, status); - VsmString container; - status = vsm_get_active_container_id(client, &container); + VsmString zone; + status = vsm_get_active_zone_id(client, &zone); BOOST_REQUIRE_EQUAL(VSMCLIENT_SUCCESS, status); - BOOST_CHECK_EQUAL(container, cm.getRunningForegroundContainerId()); + BOOST_CHECK_EQUAL(zone, cm.getRunningForegroundZoneId()); - vsm_string_free(container); + vsm_string_free(zone); vsm_client_free(client); } -BOOST_AUTO_TEST_CASE(SetActiveContainerTest) +BOOST_AUTO_TEST_CASE(SetActiveZoneTest) { - const std::string newActiveContainerId = "ut-containers-manager-console2-dbus"; + const std::string newActiveZoneId = "ut-zones-manager-console2-dbus"; - BOOST_REQUIRE_NE(newActiveContainerId, cm.getRunningForegroundContainerId()); + BOOST_REQUIRE_NE(newActiveZoneId, cm.getRunningForegroundZoneId()); VsmClient client = vsm_client_create(); VsmStatus status = vsm_connect(client); BOOST_REQUIRE_EQUAL(VSMCLIENT_SUCCESS, status); - status = vsm_set_active_container(client, newActiveContainerId.c_str()); + status = vsm_set_active_zone(client, newActiveZoneId.c_str()); BOOST_REQUIRE_EQUAL(VSMCLIENT_SUCCESS, status); - BOOST_CHECK_EQUAL(newActiveContainerId, cm.getRunningForegroundContainerId()); + BOOST_CHECK_EQUAL(newActiveZoneId, cm.getRunningForegroundZoneId()); vsm_client_free(client); } -BOOST_AUTO_TEST_CASE(CreateContainerTest) +BOOST_AUTO_TEST_CASE(CreateZoneTest) { - const std::string newActiveContainerId = ""; + const std::string newActiveZoneId = ""; VsmClient client = vsm_client_create(); VsmStatus status = vsm_connect(client); BOOST_REQUIRE_EQUAL(VSMCLIENT_SUCCESS, status); - status = vsm_create_zone(client, newActiveContainerId.c_str(), NULL); + status = vsm_create_zone(client, newActiveZoneId.c_str(), NULL); BOOST_REQUIRE_EQUAL(VSMCLIENT_CUSTOM_ERROR, status); vsm_client_free(client); } -BOOST_AUTO_TEST_CASE(LockUnlockContainerTest) +BOOST_AUTO_TEST_CASE(LockUnlockZoneTest) { - const std::string newActiveContainerId = "ut-containers-manager-console2-dbus"; + const std::string newActiveZoneId = "ut-zones-manager-console2-dbus"; VsmClient client = vsm_client_create(); VsmStatus status = vsm_connect(client); BOOST_REQUIRE_EQUAL(VSMCLIENT_SUCCESS, status); - status = vsm_lock_zone(client, newActiveContainerId.c_str()); + status = vsm_lock_zone(client, newActiveZoneId.c_str()); BOOST_REQUIRE_EQUAL(VSMCLIENT_SUCCESS, status); - status = vsm_unlock_zone(client, newActiveContainerId.c_str()); + status = vsm_unlock_zone(client, newActiveZoneId.c_str()); BOOST_REQUIRE_EQUAL(VSMCLIENT_SUCCESS, status); vsm_client_free(client); } @@ -238,14 +238,14 @@ BOOST_AUTO_TEST_CASE(LockUnlockContainerTest) BOOST_AUTO_TEST_CASE(FileMoveRequestTest) { const std::string path = "/tmp/fake_path"; - const std::string secondContainer = "fake_container"; + const std::string secondZone = "fake_zone"; VsmClient client = vsm_client_create(); VsmStatus status = vsm_connect_custom(client, EXPECTED_DBUSES_STARTED.begin()->second.c_str()); BOOST_REQUIRE_EQUAL(VSMCLIENT_SUCCESS, status); - status = vsm_file_move_request(client, secondContainer.c_str(), path.c_str()); + status = vsm_file_move_request(client, secondZone.c_str(), path.c_str()); BOOST_REQUIRE_EQUAL(VSMCLIENT_CUSTOM_ERROR, status); - BOOST_REQUIRE_EQUAL(api::container::FILE_MOVE_DESTINATION_NOT_FOUND, + BOOST_REQUIRE_EQUAL(api::zone::FILE_MOVE_DESTINATION_NOT_FOUND, vsm_get_status_message(client)); vsm_client_free(client); } @@ -260,12 +260,12 @@ BOOST_AUTO_TEST_CASE(NotificationTest) std::vector< std::tuple > receivedSignalMsg; }; - auto callback = [](const char* container, + auto callback = [](const char* zone, const char* application, const char* message, void* data) { CallbackData& callbackData = *reinterpret_cast(data); - callbackData.receivedSignalMsg.push_back(std::make_tuple(container, application, message)); + callbackData.receivedSignalMsg.push_back(std::make_tuple(zone, application, message)); callbackData.signalReceivedLatch.set(); }; @@ -285,7 +285,7 @@ BOOST_AUTO_TEST_CASE(NotificationTest) BOOST_REQUIRE_EQUAL(VSMCLIENT_SUCCESS, status); } for (auto& client : clients) { - VsmStatus status = vsm_notify_active_container(client.second, + VsmStatus status = vsm_notify_active_zone(client.second, MSG_APP.c_str(), MSG_CONTENT.c_str()); BOOST_REQUIRE_EQUAL(VSMCLIENT_SUCCESS, status); @@ -305,30 +305,30 @@ BOOST_AUTO_TEST_CASE(NotificationTest) } } -BOOST_AUTO_TEST_CASE(GetContainerIdByPidTest1) +BOOST_AUTO_TEST_CASE(GetZoneIdByPidTest1) { VsmClient client = vsm_client_create(); - VsmString container; - VsmStatus status = vsm_lookup_zone_by_pid(client, 1, &container); + VsmString zone; + VsmStatus status = vsm_lookup_zone_by_pid(client, 1, &zone); BOOST_REQUIRE_EQUAL(VSMCLIENT_SUCCESS, status); - BOOST_CHECK_EQUAL(container, std::string("host")); + BOOST_CHECK_EQUAL(zone, std::string("host")); - vsm_string_free(container); + vsm_string_free(zone); vsm_client_free(client); } -BOOST_AUTO_TEST_CASE(GetContainerIdByPidTest2) +BOOST_AUTO_TEST_CASE(GetZoneIdByPidTest2) { std::set ids; VsmClient client = vsm_client_create(); for (int n = 0; n < 100000; ++n) { - VsmString container; - VsmStatus status = vsm_lookup_zone_by_pid(client, n, &container); + VsmString zone; + VsmStatus status = vsm_lookup_zone_by_pid(client, n, &zone); if (status == VSMCLIENT_SUCCESS) { - ids.insert(container); - vsm_string_free(container); + ids.insert(zone); + vsm_string_free(zone); } else { BOOST_WARN_MESSAGE(status == VSMCLIENT_INVALID_ARGUMENT, vsm_get_status_message(client)); } diff --git a/tests/unit_tests/dbus/configs/ut-connection/ut-dbus.conf b/tests/unit_tests/dbus/configs/ut-connection/ut-dbus.conf index 7b56fa4..f3bf58c 100644 --- a/tests/unit_tests/dbus/configs/ut-connection/ut-dbus.conf +++ b/tests/unit_tests/dbus/configs/ut-connection/ut-dbus.conf @@ -1,11 +1,11 @@ - + custom - unix:path=/tmp/container_socket + unix:path=/tmp/zone_socket diff --git a/tests/unit_tests/dbus/test-common.hpp b/tests/unit_tests/dbus/test-common.hpp index 5e93699..ae76d82 100644 --- a/tests/unit_tests/dbus/test-common.hpp +++ b/tests/unit_tests/dbus/test-common.hpp @@ -31,7 +31,7 @@ namespace vasum { -const std::string DBUS_SOCKET_FILE = "/tmp/container_socket"; +const std::string DBUS_SOCKET_FILE = "/tmp/zone_socket"; const std::string DBUS_ADDRESS = "unix:path=" + DBUS_SOCKET_FILE; const std::string TESTAPI_BUS_NAME = "org.tizen.tests"; diff --git a/tests/unit_tests/dbus/test-server.cpp b/tests/unit_tests/dbus/test-server.cpp index c5f6ab8..a0fee4c 100644 --- a/tests/unit_tests/dbus/test-server.cpp +++ b/tests/unit_tests/dbus/test-server.cpp @@ -142,7 +142,7 @@ void DbusTestServer::onMessageCall(const std::string& objectPath, LOGE("unknown method; should never happen"); } } catch (const std::exception& e) { - result->setError("org.tizen.containers.Error.Test", e.what()); + result->setError("org.tizen.vasum.Error.Test", e.what()); } } diff --git a/tests/unit_tests/dbus/ut-connection.cpp b/tests/unit_tests/dbus/ut-connection.cpp index fa8a620..3e335ed 100644 --- a/tests/unit_tests/dbus/ut-connection.cpp +++ b/tests/unit_tests/dbus/ut-connection.cpp @@ -65,7 +65,7 @@ class ScopedDbusDaemon { public: ScopedDbusDaemon() { - boost::filesystem::remove("/tmp/container_socket"); + boost::filesystem::remove("/tmp/zone_socket"); mDaemon.start(DBUS_DAEMON_PROC, DBUS_DAEMON_ARGS); waitForFile(DBUS_SOCKET_FILE, DBUS_DAEMON_TIMEOUT); } @@ -338,7 +338,7 @@ BOOST_AUTO_TEST_CASE(MethodCallTest) } else if (methodName == TESTAPI_METHOD_THROW) { int arg = 0; g_variant_get(parameters, "(i)", &arg); - result->setError("org.tizen.containers.Error.Test", "msg: " + std::to_string(arg)); + result->setError("org.tizen.vasum.Error.Test", "msg: " + std::to_string(arg)); } }; conn1->registerObject(TESTAPI_OBJECT_PATH, TESTAPI_DEFINITION, handler); @@ -402,7 +402,7 @@ BOOST_AUTO_TEST_CASE(MethodAsyncCallTest) } else if (methodName == TESTAPI_METHOD_THROW) { int arg = 0; g_variant_get(parameters, "(i)", &arg); - result->setError("org.tizen.containers.Error.Test", "msg: " + std::to_string(arg)); + result->setError("org.tizen.vasum.Error.Test", "msg: " + std::to_string(arg)); } }; conn1->registerObject(TESTAPI_OBJECT_PATH, TESTAPI_DEFINITION, handler); diff --git a/tests/unit_tests/lxc/templates/minimal-dbus.sh b/tests/unit_tests/lxc/templates/minimal-dbus.sh index 82c76e8..fb61eb3 100755 --- a/tests/unit_tests/lxc/templates/minimal-dbus.sh +++ b/tests/unit_tests/lxc/templates/minimal-dbus.sh @@ -19,7 +19,7 @@ do esac done -# Prepare container rootfs +# Prepare zone rootfs ROOTFS_DIRS="\ ${rootfs}/bin \ ${rootfs}/dev \ @@ -41,7 +41,7 @@ ${rootfs}/var/run " /bin/mkdir ${ROOTFS_DIRS} -# Prepare container configuration file +# Prepare zone configuration file > ${path}/config cat <> ${path}/config lxc.utsname = ${name} diff --git a/tests/unit_tests/lxc/templates/minimal.sh b/tests/unit_tests/lxc/templates/minimal.sh index 873277e..0450d1a 100755 --- a/tests/unit_tests/lxc/templates/minimal.sh +++ b/tests/unit_tests/lxc/templates/minimal.sh @@ -19,7 +19,7 @@ do esac done -# Prepare container rootfs +# Prepare zone rootfs ROOTFS_DIRS="\ ${rootfs}/bin \ ${rootfs}/dev \ @@ -39,7 +39,7 @@ ${rootfs}/opt " /bin/mkdir ${ROOTFS_DIRS} -# Prepare container configuration file +# Prepare zone configuration file > ${path}/config cat <> ${path}/config lxc.utsname = ${name} diff --git a/tests/unit_tests/server/configs/CMakeLists.txt b/tests/unit_tests/server/configs/CMakeLists.txt index 9979c1b..4a9edbe 100644 --- a/tests/unit_tests/server/configs/CMakeLists.txt +++ b/tests/unit_tests/server/configs/CMakeLists.txt @@ -20,17 +20,17 @@ MESSAGE(STATUS "Installing configs for the Server Unit Tests to " ${VSM_TEST_CONFIG_INSTALL_DIR}) FILE(GLOB server_manager_CONF ut-server/*.conf) -FILE(GLOB server_container_CONF ut-server/containers/*.conf) +FILE(GLOB server_zone_CONF ut-server/zones/*.conf) -FILE(GLOB manager_manager_CONF ut-containers-manager/*.conf) -FILE(GLOB manager_container_CONF ut-containers-manager/containers/*.conf) +FILE(GLOB manager_manager_CONF ut-zones-manager/*.conf) +FILE(GLOB manager_zone_CONF ut-zones-manager/zones/*.conf) -FILE(GLOB container_CONF ut-container/*.conf) -FILE(GLOB container_container_CONF ut-container/containers/*.conf) +FILE(GLOB zone_CONF ut-zone/*.conf) +FILE(GLOB zone_zone_CONF ut-zone/zones/*.conf) -FILE(GLOB admin_container_CONF ut-container-admin/containers/*.conf) +FILE(GLOB admin_zone_CONF ut-zone-admin/zones/*.conf) -FILE(GLOB connection_CONF ut-container-connection/*.conf) +FILE(GLOB connection_CONF ut-zone-connection/*.conf) ## Generate #################################################################### @@ -40,35 +40,35 @@ CONFIGURE_FILE(ut-server/buggy-daemon.conf.in ${CMAKE_BINARY_DIR}/ut-server/buggy-daemon.conf @ONLY) FILE(GLOB server_manager_CONF_GEN ${CMAKE_BINARY_DIR}/ut-server/*.conf) -CONFIGURE_FILE(ut-container/containers/test-dbus.conf.in - ${CMAKE_BINARY_DIR}/ut-container/containers/test-dbus.conf @ONLY) -FILE(GLOB container_container_CONF_GEN ${CMAKE_BINARY_DIR}/ut-container/containers/*.conf) - -CONFIGURE_FILE(ut-containers-manager/test-daemon.conf.in - ${CMAKE_BINARY_DIR}/ut-containers-manager/test-daemon.conf @ONLY) -CONFIGURE_FILE(ut-containers-manager/buggy-daemon.conf.in - ${CMAKE_BINARY_DIR}/ut-containers-manager/buggy-daemon.conf @ONLY) -CONFIGURE_FILE(ut-containers-manager/buggy-default-daemon.conf.in - ${CMAKE_BINARY_DIR}/ut-containers-manager/buggy-default-daemon.conf @ONLY) -CONFIGURE_FILE(ut-containers-manager/buggy-foreground-daemon.conf.in - ${CMAKE_BINARY_DIR}/ut-containers-manager/buggy-foreground-daemon.conf @ONLY) -CONFIGURE_FILE(ut-containers-manager/test-dbus-daemon.conf.in - ${CMAKE_BINARY_DIR}/ut-containers-manager/test-dbus-daemon.conf @ONLY) -CONFIGURE_FILE(ut-containers-manager/empty-dbus-daemon.conf.in - ${CMAKE_BINARY_DIR}/ut-containers-manager/empty-dbus-daemon.conf @ONLY) -FILE(GLOB manager_manager_CONF_GEN ${CMAKE_BINARY_DIR}/ut-containers-manager/*.conf) - -CONFIGURE_FILE(ut-containers-manager/containers/console1-dbus.conf.in - ${CMAKE_BINARY_DIR}/ut-containers-manager/containers/console1-dbus.conf @ONLY) -CONFIGURE_FILE(ut-containers-manager/containers/console2-dbus.conf.in - ${CMAKE_BINARY_DIR}/ut-containers-manager/containers/console2-dbus.conf @ONLY) -CONFIGURE_FILE(ut-containers-manager/containers/console3-dbus.conf.in - ${CMAKE_BINARY_DIR}/ut-containers-manager/containers/console3-dbus.conf @ONLY) -FILE(GLOB manager_container_CONF_GEN ${CMAKE_BINARY_DIR}/ut-containers-manager/containers/*.conf) - -CONFIGURE_FILE(ut-containers-manager/templates/template.conf.in - ${CMAKE_BINARY_DIR}/ut-containers-manager/templates/template.conf @ONLY) -FILE(GLOB manager_container_TEMPLATE_GEN ${CMAKE_BINARY_DIR}/ut-containers-manager/templates/*.conf) +CONFIGURE_FILE(ut-zone/zones/test-dbus.conf.in + ${CMAKE_BINARY_DIR}/ut-zone/zones/test-dbus.conf @ONLY) +FILE(GLOB zone_zone_CONF_GEN ${CMAKE_BINARY_DIR}/ut-zone/zones/*.conf) + +CONFIGURE_FILE(ut-zones-manager/test-daemon.conf.in + ${CMAKE_BINARY_DIR}/ut-zones-manager/test-daemon.conf @ONLY) +CONFIGURE_FILE(ut-zones-manager/buggy-daemon.conf.in + ${CMAKE_BINARY_DIR}/ut-zones-manager/buggy-daemon.conf @ONLY) +CONFIGURE_FILE(ut-zones-manager/buggy-default-daemon.conf.in + ${CMAKE_BINARY_DIR}/ut-zones-manager/buggy-default-daemon.conf @ONLY) +CONFIGURE_FILE(ut-zones-manager/buggy-foreground-daemon.conf.in + ${CMAKE_BINARY_DIR}/ut-zones-manager/buggy-foreground-daemon.conf @ONLY) +CONFIGURE_FILE(ut-zones-manager/test-dbus-daemon.conf.in + ${CMAKE_BINARY_DIR}/ut-zones-manager/test-dbus-daemon.conf @ONLY) +CONFIGURE_FILE(ut-zones-manager/empty-dbus-daemon.conf.in + ${CMAKE_BINARY_DIR}/ut-zones-manager/empty-dbus-daemon.conf @ONLY) +FILE(GLOB manager_manager_CONF_GEN ${CMAKE_BINARY_DIR}/ut-zones-manager/*.conf) + +CONFIGURE_FILE(ut-zones-manager/zones/console1-dbus.conf.in + ${CMAKE_BINARY_DIR}/ut-zones-manager/zones/console1-dbus.conf @ONLY) +CONFIGURE_FILE(ut-zones-manager/zones/console2-dbus.conf.in + ${CMAKE_BINARY_DIR}/ut-zones-manager/zones/console2-dbus.conf @ONLY) +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) +FILE(GLOB manager_zone_TEMPLATE_GEN ${CMAKE_BINARY_DIR}/ut-zones-manager/templates/*.conf) ## Install ##################################################################### @@ -76,32 +76,32 @@ INSTALL(FILES ${server_manager_CONF} DESTINATION ${VSM_TEST_CONFIG_INSTALL_DIR}/server/ut-server) INSTALL(FILES ${server_manager_CONF_GEN} DESTINATION ${VSM_TEST_CONFIG_INSTALL_DIR}/server/ut-server) -INSTALL(FILES ${server_container_CONF} - DESTINATION ${VSM_TEST_CONFIG_INSTALL_DIR}/server/ut-server/containers) +INSTALL(FILES ${server_zone_CONF} + DESTINATION ${VSM_TEST_CONFIG_INSTALL_DIR}/server/ut-server/zones) INSTALL(FILES ${manager_manager_CONF} - DESTINATION ${VSM_TEST_CONFIG_INSTALL_DIR}/server/ut-containers-manager) + DESTINATION ${VSM_TEST_CONFIG_INSTALL_DIR}/server/ut-zones-manager) INSTALL(FILES ${manager_manager_CONF_GEN} - DESTINATION ${VSM_TEST_CONFIG_INSTALL_DIR}/server/ut-containers-manager) -INSTALL(FILES ${manager_container_CONF} - DESTINATION ${VSM_TEST_CONFIG_INSTALL_DIR}/server/ut-containers-manager/containers) -INSTALL(FILES ${manager_container_CONF_GEN} - DESTINATION ${VSM_TEST_CONFIG_INSTALL_DIR}/server/ut-containers-manager/containers) -INSTALL(FILES ${manager_container_TEMPLATE_GEN} - DESTINATION ${VSM_TEST_CONFIG_INSTALL_DIR}/server/ut-containers-manager/templates) - -INSTALL(FILES ${container_CONF} - DESTINATION ${VSM_TEST_CONFIG_INSTALL_DIR}/server/ut-container) -INSTALL(FILES ${container_container_CONF} - DESTINATION ${VSM_TEST_CONFIG_INSTALL_DIR}/server/ut-container/containers) -INSTALL(FILES ${container_container_CONF_GEN} - DESTINATION ${VSM_TEST_CONFIG_INSTALL_DIR}/server/ut-container/containers) - -INSTALL(FILES ${admin_container_CONF} - DESTINATION ${VSM_TEST_CONFIG_INSTALL_DIR}/server/ut-container-admin/containers) + DESTINATION ${VSM_TEST_CONFIG_INSTALL_DIR}/server/ut-zones-manager) +INSTALL(FILES ${manager_zone_CONF} + DESTINATION ${VSM_TEST_CONFIG_INSTALL_DIR}/server/ut-zones-manager/zones) +INSTALL(FILES ${manager_zone_CONF_GEN} + DESTINATION ${VSM_TEST_CONFIG_INSTALL_DIR}/server/ut-zones-manager/zones) +INSTALL(FILES ${manager_zone_TEMPLATE_GEN} + DESTINATION ${VSM_TEST_CONFIG_INSTALL_DIR}/server/ut-zones-manager/templates) + +INSTALL(FILES ${zone_CONF} + DESTINATION ${VSM_TEST_CONFIG_INSTALL_DIR}/server/ut-zone) +INSTALL(FILES ${zone_zone_CONF} + DESTINATION ${VSM_TEST_CONFIG_INSTALL_DIR}/server/ut-zone/zones) +INSTALL(FILES ${zone_zone_CONF_GEN} + DESTINATION ${VSM_TEST_CONFIG_INSTALL_DIR}/server/ut-zone/zones) + +INSTALL(FILES ${admin_zone_CONF} + DESTINATION ${VSM_TEST_CONFIG_INSTALL_DIR}/server/ut-zone-admin/zones) INSTALL(FILES ${connection_CONF} - DESTINATION ${VSM_TEST_CONFIG_INSTALL_DIR}/server/ut-container-connection) + DESTINATION ${VSM_TEST_CONFIG_INSTALL_DIR}/server/ut-zone-connection) -INSTALL(FILES dbus-1/system.d/org.tizen.containers.tests.conf +INSTALL(FILES dbus-1/system.d/org.tizen.vasum.tests.conf DESTINATION ${SYSCONF_INSTALL_DIR}/dbus-1/system.d/) diff --git a/tests/unit_tests/server/configs/dbus-1/system.d/org.tizen.containers.tests.conf b/tests/unit_tests/server/configs/dbus-1/system.d/org.tizen.containers.tests.conf deleted file mode 100644 index be6c6d6..0000000 --- a/tests/unit_tests/server/configs/dbus-1/system.d/org.tizen.containers.tests.conf +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - diff --git a/tests/unit_tests/server/configs/dbus-1/system.d/org.tizen.vasum.tests.conf b/tests/unit_tests/server/configs/dbus-1/system.d/org.tizen.vasum.tests.conf new file mode 100644 index 0000000..b818da9 --- /dev/null +++ b/tests/unit_tests/server/configs/dbus-1/system.d/org.tizen.vasum.tests.conf @@ -0,0 +1,14 @@ + + + + + + + + + + + + + diff --git a/tests/unit_tests/server/configs/ut-containers-manager/buggy-daemon.conf.in b/tests/unit_tests/server/configs/ut-containers-manager/buggy-daemon.conf.in deleted file mode 100644 index c3ec37b..0000000 --- a/tests/unit_tests/server/configs/ut-containers-manager/buggy-daemon.conf.in +++ /dev/null @@ -1,17 +0,0 @@ -{ - "containerConfigs" : ["containers/console1.conf", "missing/file/path/missing.conf", "containers/console3.conf"], - "runMountPointPrefix" : "", - "foregroundId" : "ut-containers-manager-console1", - "defaultId" : "ut-containers-manager-console1", - "containersPath" : "/tmp/ut-containers", - "containerImagePath" : "", - "containerTemplatePath" : "templates", - "containerNewConfigPrefix" : "@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-containers-manager/", - "lxcTemplatePrefix" : "@VSM_TEST_LXC_TEMPLATES_INSTALL_DIR@", - "inputConfig" : {"enabled" : false, - "device" : "/dev/doesnotexist", - "code" : 139, - "numberOfEvents" : 2, - "timeWindowMs" : 500}, - "proxyCallRules" : [] -} diff --git a/tests/unit_tests/server/configs/ut-containers-manager/test-daemon.conf.in b/tests/unit_tests/server/configs/ut-containers-manager/test-daemon.conf.in deleted file mode 100644 index 25890e6..0000000 --- a/tests/unit_tests/server/configs/ut-containers-manager/test-daemon.conf.in +++ /dev/null @@ -1,17 +0,0 @@ -{ - "containerConfigs" : ["containers/console1.conf", "containers/console2.conf", "containers/console3.conf"], - "runMountPointPrefix" : "", - "foregroundId" : "ut-containers-manager-console1", - "defaultId" : "ut-containers-manager-console1", - "containersPath" : "/tmp/ut-containers", - "containerImagePath" : "", - "containerTemplatePath" : "templates", - "containerNewConfigPrefix" : "@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-containers-manager/", - "lxcTemplatePrefix" : "@VSM_TEST_LXC_TEMPLATES_INSTALL_DIR@", - "inputConfig" : {"enabled" : false, - "device" : "/dev/doesnotexist", - "code" : 139, - "numberOfEvents" : 2, - "timeWindowMs" : 500}, - "proxyCallRules" : [] -} diff --git a/tests/unit_tests/server/configs/ut-containers-manager/test-dbus-daemon.conf.in b/tests/unit_tests/server/configs/ut-containers-manager/test-dbus-daemon.conf.in deleted file mode 100644 index 19a9f60..0000000 --- a/tests/unit_tests/server/configs/ut-containers-manager/test-dbus-daemon.conf.in +++ /dev/null @@ -1,24 +0,0 @@ -{ - "containerConfigs" : ["containers/console1-dbus.conf", - "containers/console2-dbus.conf", - "containers/console3-dbus.conf"], - "foregroundId" : "ut-containers-manager-console1-dbus", - "defaultId" : "ut-containers-manager-console1-dbus", - "containersPath" : "/tmp/ut-containers", - "containerImagePath" : "", - "containerTemplatePath" : "templates", - "containerNewConfigPrefix" : "@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-containers-manager/", - "runMountPointPrefix" : "", - "lxcTemplatePrefix" : "@VSM_TEST_LXC_TEMPLATES_INSTALL_DIR@", - "inputConfig" : {"enabled" : false, - "device" : "/dev/doesnotexist", - "code" : 139, - "numberOfEvents" : 2, - "timeWindowMs" : 500}, - "proxyCallRules" : [{"caller" : "*", - "target" : "*", - "targetBusName" : "org.tizen.containers.tests", - "targetObjectPath" : "*", - "targetInterface" : "*", - "targetMethod" : "*"}] -} 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 55479b7..8ea6cb8 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 @@ -1,12 +1,12 @@ { - "containerConfigs" : ["containers/container1.conf", "missing/file/path/missing.conf", "containers/container3.conf"], - "containersPath" : "/tmp/ut-containers", - "containerImagePath" : "", - "containerTemplatePath" : "no_need_for_templates_in_this_test", - "containerNewConfigPrefix" : "", + "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", + "zoneNewConfigPrefix" : "", "runMountPointPrefix" : "", - "foregroundId" : "ut-server-container1", - "defaultId" : "ut-server-container1", + "foregroundId" : "ut-server-zone1", + "defaultId" : "ut-server-zone1", "lxcTemplatePrefix" : "@VSM_TEST_LXC_TEMPLATES_INSTALL_DIR@", "inputConfig" : {"enabled" : false, "device" : "/dev/doesnotexist", 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 57fb7a1..24e1c4e 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 @@ -1,12 +1,12 @@ { - "containerConfigs" : ["containers/container1.conf", "containers/container2.conf", "containers/container3.conf"], - "containersPath" : "/tmp/ut-containers", - "containerImagePath" : "", - "containerTemplatePath" : "no_need_for_templates_in_this_test", - "containerNewConfigPrefix" : "", + "zoneConfigs" : ["zones/zone1.conf", "zones/zone2.conf", "zones/zone3.conf"], + "zonesPath" : "/tmp/ut-zones", + "zoneImagePath" : "", + "zoneTemplatePath" : "no_need_for_templates_in_this_test", + "zoneNewConfigPrefix" : "", "runMountPointPrefix" : "", - "foregroundId" : "ut-server-container1", - "defaultId" : "ut-server-container1", + "foregroundId" : "ut-server-zone1", + "defaultId" : "ut-server-zone1", "lxcTemplatePrefix" : "@VSM_TEST_LXC_TEMPLATES_INSTALL_DIR@", "inputConfig" : {"enabled" : false, "device" : "gpio-keys.4", diff --git a/tests/unit_tests/server/configs/ut-server/containers/container1.conf b/tests/unit_tests/server/configs/ut-server/zones/zone1.conf similarity index 91% rename from tests/unit_tests/server/configs/ut-server/containers/container1.conf rename to tests/unit_tests/server/configs/ut-server/zones/zone1.conf index 995efb4..898eef2 100644 --- a/tests/unit_tests/server/configs/ut-server/containers/container1.conf +++ b/tests/unit_tests/server/configs/ut-server/zones/zone1.conf @@ -1,5 +1,5 @@ { - "name" : "ut-server-container1", + "name" : "ut-server-zone1", "lxcTemplate" : "minimal.sh", "initWithArgs" : ["/bin/sh", "-c", "trap exit SIGTERM; read"], "ipv4Gateway" : "", diff --git a/tests/unit_tests/server/configs/ut-server/containers/container2.conf b/tests/unit_tests/server/configs/ut-server/zones/zone2.conf similarity index 91% rename from tests/unit_tests/server/configs/ut-server/containers/container2.conf rename to tests/unit_tests/server/configs/ut-server/zones/zone2.conf index 1e9b3b7..8f4687a 100644 --- a/tests/unit_tests/server/configs/ut-server/containers/container2.conf +++ b/tests/unit_tests/server/configs/ut-server/zones/zone2.conf @@ -1,5 +1,5 @@ { - "name" : "ut-server-container2", + "name" : "ut-server-zone2", "lxcTemplate" : "minimal.sh", "initWithArgs" : ["/bin/sh", "-c", "trap exit SIGTERM; read"], "ipv4Gateway" : "", diff --git a/tests/unit_tests/server/configs/ut-server/containers/container3.conf b/tests/unit_tests/server/configs/ut-server/zones/zone3.conf similarity index 91% rename from tests/unit_tests/server/configs/ut-server/containers/container3.conf rename to tests/unit_tests/server/configs/ut-server/zones/zone3.conf index 47396f5..fdb958f 100644 --- a/tests/unit_tests/server/configs/ut-server/containers/container3.conf +++ b/tests/unit_tests/server/configs/ut-server/zones/zone3.conf @@ -1,5 +1,5 @@ { - "name" : "ut-server-container3", + "name" : "ut-server-zone3", "lxcTemplate" : "minimal.sh", "initWithArgs" : ["/bin/sh", "-c", "trap exit SIGTERM; read"], "ipv4Gateway" : "", diff --git a/tests/unit_tests/server/configs/ut-container-admin/containers/buggy.conf b/tests/unit_tests/server/configs/ut-zone-admin/zones/buggy.conf similarity index 90% rename from tests/unit_tests/server/configs/ut-container-admin/containers/buggy.conf rename to tests/unit_tests/server/configs/ut-zone-admin/zones/buggy.conf index ffa8652..320dc00 100644 --- a/tests/unit_tests/server/configs/ut-container-admin/containers/buggy.conf +++ b/tests/unit_tests/server/configs/ut-zone-admin/zones/buggy.conf @@ -1,5 +1,5 @@ { - "name" : "ut-container-admin-test", + "name" : "ut-zone-admin-test", "lxcTemplate" : "minimal.sh", "initWithArgs" : ["/foo"], "ipv4Gateway" : "", diff --git a/tests/unit_tests/server/configs/ut-container-admin/containers/missing.conf b/tests/unit_tests/server/configs/ut-zone-admin/zones/missing.conf similarity index 91% rename from tests/unit_tests/server/configs/ut-container-admin/containers/missing.conf rename to tests/unit_tests/server/configs/ut-zone-admin/zones/missing.conf index 686dde2..9aaf464 100644 --- a/tests/unit_tests/server/configs/ut-container-admin/containers/missing.conf +++ b/tests/unit_tests/server/configs/ut-zone-admin/zones/missing.conf @@ -1,5 +1,5 @@ { - "name" : "ut-container-admin-test", + "name" : "ut-zone-admin-test", "lxcTemplate" : "missing.sh", "initWithArgs" : ["/bin/sh", "-c", "trap exit SIGTERM; read"], "ipv4Gateway" : "", diff --git a/tests/unit_tests/server/configs/ut-container-admin/containers/test-no-shutdown.conf b/tests/unit_tests/server/configs/ut-zone-admin/zones/test-no-shutdown.conf similarity index 90% rename from tests/unit_tests/server/configs/ut-container-admin/containers/test-no-shutdown.conf rename to tests/unit_tests/server/configs/ut-zone-admin/zones/test-no-shutdown.conf index 307afd5..b3b0141 100644 --- a/tests/unit_tests/server/configs/ut-container-admin/containers/test-no-shutdown.conf +++ b/tests/unit_tests/server/configs/ut-zone-admin/zones/test-no-shutdown.conf @@ -1,5 +1,5 @@ { - "name" : "ut-container-admin-test", + "name" : "ut-zone-admin-test", "lxcTemplate" : "minimal.sh", "initWithArgs" : ["/bin/sh"], "ipv4Gateway" : "", diff --git a/tests/unit_tests/server/configs/ut-container-admin/containers/test.conf b/tests/unit_tests/server/configs/ut-zone-admin/zones/test.conf similarity index 91% rename from tests/unit_tests/server/configs/ut-container-admin/containers/test.conf rename to tests/unit_tests/server/configs/ut-zone-admin/zones/test.conf index 76f4a70..ae046e5 100644 --- a/tests/unit_tests/server/configs/ut-container-admin/containers/test.conf +++ b/tests/unit_tests/server/configs/ut-zone-admin/zones/test.conf @@ -1,5 +1,5 @@ { - "name" : "ut-container-admin-test", + "name" : "ut-zone-admin-test", "lxcTemplate" : "minimal.sh", "initWithArgs" : ["/bin/sh", "-c", "trap exit SIGTERM; read"], "ipv4Gateway" : "", diff --git a/tests/unit_tests/server/configs/ut-container-connection/ut-dbus.conf b/tests/unit_tests/server/configs/ut-zone-connection/ut-dbus.conf similarity index 76% rename from tests/unit_tests/server/configs/ut-container-connection/ut-dbus.conf rename to tests/unit_tests/server/configs/ut-zone-connection/ut-dbus.conf index b0a2d18..d60e774 100644 --- a/tests/unit_tests/server/configs/ut-container-connection/ut-dbus.conf +++ b/tests/unit_tests/server/configs/ut-zone-connection/ut-dbus.conf @@ -1,11 +1,11 @@ - + custom - unix:path=/tmp/ut-container-connection/dbus/system_bus_socket + unix:path=/tmp/ut-zone-connection/dbus/system_bus_socket diff --git a/tests/unit_tests/server/configs/ut-containers-manager/ut-dbus.conf b/tests/unit_tests/server/configs/ut-zone/ut-dbus.conf similarity index 89% rename from tests/unit_tests/server/configs/ut-containers-manager/ut-dbus.conf rename to tests/unit_tests/server/configs/ut-zone/ut-dbus.conf index 520a14f..2e0488d 100644 --- a/tests/unit_tests/server/configs/ut-containers-manager/ut-dbus.conf +++ b/tests/unit_tests/server/configs/ut-zone/ut-dbus.conf @@ -1,4 +1,4 @@ - + diff --git a/tests/unit_tests/server/configs/ut-container/containers/buggy.conf b/tests/unit_tests/server/configs/ut-zone/zones/buggy.conf similarity index 92% rename from tests/unit_tests/server/configs/ut-container/containers/buggy.conf rename to tests/unit_tests/server/configs/ut-zone/zones/buggy.conf index 2af10da..55586b4 100644 --- a/tests/unit_tests/server/configs/ut-container/containers/buggy.conf +++ b/tests/unit_tests/server/configs/ut-zone/zones/buggy.conf @@ -1,5 +1,5 @@ { - "name" : "ut-container-test", + "name" : "ut-zone-test", "lxcTemplate" : "/buggy/path", "initWithArgs" : ["/bin/sh", "-c", "trap exit SIGTERM; read"], "ipv4Gateway" : "", diff --git a/tests/unit_tests/server/configs/ut-container/containers/test-dbus.conf.in b/tests/unit_tests/server/configs/ut-zone/zones/test-dbus.conf.in similarity index 75% rename from tests/unit_tests/server/configs/ut-container/containers/test-dbus.conf.in rename to tests/unit_tests/server/configs/ut-zone/zones/test-dbus.conf.in index 1992140..4f8e6db 100644 --- a/tests/unit_tests/server/configs/ut-container/containers/test-dbus.conf.in +++ b/tests/unit_tests/server/configs/ut-zone/zones/test-dbus.conf.in @@ -1,7 +1,7 @@ { - "name" : "ut-container-test-dbus", + "name" : "ut-zone-test-dbus", "lxcTemplate" : "minimal-dbus.sh", - "initWithArgs" : ["/bin/sh", "-c", "trap exit SIGTERM; /usr/bin/dbus-daemon --config-file=@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-container/ut-dbus.conf --fork; read"], + "initWithArgs" : ["/bin/sh", "-c", "trap exit SIGTERM; /usr/bin/dbus-daemon --config-file=@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-zone/ut-dbus.conf --fork; read"], "ipv4Gateway" : "", "ipv4" : "", "privilege" : 10, @@ -10,7 +10,7 @@ "enableDbusIntegration" : true, "cpuQuotaForeground" : -1, "cpuQuotaBackground" : 1000, - "runMountPoint" : "/tmp/ut-run/ut-container-test-dbus", + "runMountPoint" : "/tmp/ut-run/ut-zone-test-dbus", "permittedToSend" : [], "permittedToRecv" : [] } diff --git a/tests/unit_tests/server/configs/ut-container/containers/test.conf b/tests/unit_tests/server/configs/ut-zone/zones/test.conf similarity index 92% rename from tests/unit_tests/server/configs/ut-container/containers/test.conf rename to tests/unit_tests/server/configs/ut-zone/zones/test.conf index 1264669..a8f9692 100644 --- a/tests/unit_tests/server/configs/ut-container/containers/test.conf +++ b/tests/unit_tests/server/configs/ut-zone/zones/test.conf @@ -1,5 +1,5 @@ { - "name" : "ut-container-test", + "name" : "ut-zone-test", "lxcTemplate" : "minimal.sh", "initWithArgs" : ["/bin/sh", "-c", "trap exit SIGTERM; read"], "ipv4Gateway" : "", 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 new file mode 100644 index 0000000..f2bcbb9 --- /dev/null +++ b/tests/unit_tests/server/configs/ut-zones-manager/buggy-daemon.conf.in @@ -0,0 +1,17 @@ +{ + "zoneConfigs" : ["zones/console1.conf", "missing/file/path/missing.conf", "zones/console3.conf"], + "runMountPointPrefix" : "", + "foregroundId" : "ut-zones-manager-console1", + "defaultId" : "ut-zones-manager-console1", + "zonesPath" : "/tmp/ut-zones", + "zoneImagePath" : "", + "zoneTemplatePath" : "templates", + "zoneNewConfigPrefix" : "@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-zones-manager/", + "lxcTemplatePrefix" : "@VSM_TEST_LXC_TEMPLATES_INSTALL_DIR@", + "inputConfig" : {"enabled" : false, + "device" : "/dev/doesnotexist", + "code" : 139, + "numberOfEvents" : 2, + "timeWindowMs" : 500}, + "proxyCallRules" : [] +} diff --git a/tests/unit_tests/server/configs/ut-containers-manager/buggy-default-daemon.conf.in b/tests/unit_tests/server/configs/ut-zones-manager/buggy-default-daemon.conf.in similarity index 51% rename from tests/unit_tests/server/configs/ut-containers-manager/buggy-default-daemon.conf.in rename to tests/unit_tests/server/configs/ut-zones-manager/buggy-default-daemon.conf.in index 6390378..90b9107 100644 --- a/tests/unit_tests/server/configs/ut-containers-manager/buggy-default-daemon.conf.in +++ b/tests/unit_tests/server/configs/ut-zones-manager/buggy-default-daemon.conf.in @@ -1,12 +1,12 @@ { - "containerConfigs" : ["containers/console1.conf", "containers/console2.conf", "containers/console3.conf"], + "zoneConfigs" : ["zones/console1.conf", "zones/console2.conf", "zones/console3.conf"], "runMountPointPrefix" : "", - "foregroundId" : "ut-containers-manager-console1", + "foregroundId" : "ut-zones-manager-console1", "defaultId" : "in_no_way_there_is_a_valid_id_here", - "containersPath" : "/tmp/ut-containers", - "containerImagePath" : "", - "containerTemplatePath" : "templates", - "containerNewConfigPrefix" : "@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-containers-manager/", + "zonesPath" : "/tmp/ut-zones", + "zoneImagePath" : "", + "zoneTemplatePath" : "templates", + "zoneNewConfigPrefix" : "@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-zones-manager/", "lxcTemplatePrefix" : "@VSM_TEST_LXC_TEMPLATES_INSTALL_DIR@", "inputConfig" : {"enabled" : false, "device" : "/dev/doesnotexist", diff --git a/tests/unit_tests/server/configs/ut-containers-manager/buggy-foreground-daemon.conf.in b/tests/unit_tests/server/configs/ut-zones-manager/buggy-foreground-daemon.conf.in similarity index 50% rename from tests/unit_tests/server/configs/ut-containers-manager/buggy-foreground-daemon.conf.in rename to tests/unit_tests/server/configs/ut-zones-manager/buggy-foreground-daemon.conf.in index fb1490c..49c4c2d 100644 --- a/tests/unit_tests/server/configs/ut-containers-manager/buggy-foreground-daemon.conf.in +++ b/tests/unit_tests/server/configs/ut-zones-manager/buggy-foreground-daemon.conf.in @@ -1,12 +1,12 @@ { - "containerConfigs" : ["containers/console1.conf", "containers/console2.conf", "containers/console3.conf"], + "zoneConfigs" : ["zones/console1.conf", "zones/console2.conf", "zones/console3.conf"], "runMountPointPrefix" : "", "foregroundId" : "this_id_does_not_exist", - "defaultId" : "ut-containers-manager-console1", - "containersPath" : "/tmp/ut-containers", - "containerImagePath" : "", - "containerTemplatePath" : "templates", - "containerNewConfigPrefix" : "@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-containers-manager/", + "defaultId" : "ut-zones-manager-console1", + "zonesPath" : "/tmp/ut-zones", + "zoneImagePath" : "", + "zoneTemplatePath" : "templates", + "zoneNewConfigPrefix" : "@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-zones-manager/", "lxcTemplatePrefix" : "@VSM_TEST_LXC_TEMPLATES_INSTALL_DIR@", "inputConfig" : {"enabled" : false, "device" : "/dev/doesnotexist", diff --git a/tests/unit_tests/server/configs/ut-containers-manager/empty-dbus-daemon.conf.in b/tests/unit_tests/server/configs/ut-zones-manager/empty-dbus-daemon.conf.in similarity index 65% rename from tests/unit_tests/server/configs/ut-containers-manager/empty-dbus-daemon.conf.in rename to tests/unit_tests/server/configs/ut-zones-manager/empty-dbus-daemon.conf.in index 97e70d8..4e20535 100644 --- a/tests/unit_tests/server/configs/ut-containers-manager/empty-dbus-daemon.conf.in +++ b/tests/unit_tests/server/configs/ut-zones-manager/empty-dbus-daemon.conf.in @@ -1,11 +1,11 @@ { - "containerConfigs" : [], + "zoneConfigs" : [], "foregroundId" : "", "defaultId" : "", - "containersPath" : "/tmp/ut-containers", - "containerImagePath" : "", - "containerTemplatePath" : "templates", - "containerNewConfigPrefix" : "@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-containers-manager/", + "zonesPath" : "/tmp/ut-zones", + "zoneImagePath" : "", + "zoneTemplatePath" : "templates", + "zoneNewConfigPrefix" : "@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-zones-manager/", "runMountPointPrefix" : "", "lxcTemplatePrefix" : "@VSM_TEST_LXC_TEMPLATES_INSTALL_DIR@", "inputConfig" : {"enabled" : false, @@ -15,7 +15,7 @@ "timeWindowMs" : 500}, "proxyCallRules" : [{"caller" : "*", "target" : "*", - "targetBusName" : "org.tizen.containers.tests", + "targetBusName" : "org.tizen.vasum.tests", "targetObjectPath" : "*", "targetInterface" : "*", "targetMethod" : "*"}] diff --git a/tests/unit_tests/server/configs/ut-containers-manager/templates/template.conf.in b/tests/unit_tests/server/configs/ut-zones-manager/templates/template.conf.in similarity index 90% rename from tests/unit_tests/server/configs/ut-containers-manager/templates/template.conf.in rename to tests/unit_tests/server/configs/ut-zones-manager/templates/template.conf.in index 8e2292a..15185d6 100644 --- a/tests/unit_tests/server/configs/ut-containers-manager/templates/template.conf.in +++ b/tests/unit_tests/server/configs/ut-zones-manager/templates/template.conf.in @@ -1,7 +1,7 @@ { "name" : "~NAME~", "lxcTemplate" : "minimal-dbus.sh", - "initWithArgs" : ["/bin/sh", "-c", "trap exit SIGTERM; /usr/bin/dbus-daemon --config-file=@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-containers-manager/ut-dbus.conf --fork; read"], + "initWithArgs" : ["/bin/sh", "-c", "trap exit SIGTERM; /usr/bin/dbus-daemon --config-file=@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-zones-manager/ut-dbus.conf --fork; read"], "ipv4Gateway" : "", "ipv4" : "", "privilege" : 20, 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 new file mode 100644 index 0000000..d72c440 --- /dev/null +++ b/tests/unit_tests/server/configs/ut-zones-manager/test-daemon.conf.in @@ -0,0 +1,17 @@ +{ + "zoneConfigs" : ["zones/console1.conf", "zones/console2.conf", "zones/console3.conf"], + "runMountPointPrefix" : "", + "foregroundId" : "ut-zones-manager-console1", + "defaultId" : "ut-zones-manager-console1", + "zonesPath" : "/tmp/ut-zones", + "zoneImagePath" : "", + "zoneTemplatePath" : "templates", + "zoneNewConfigPrefix" : "@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-zones-manager/", + "lxcTemplatePrefix" : "@VSM_TEST_LXC_TEMPLATES_INSTALL_DIR@", + "inputConfig" : {"enabled" : false, + "device" : "/dev/doesnotexist", + "code" : 139, + "numberOfEvents" : 2, + "timeWindowMs" : 500}, + "proxyCallRules" : [] +} 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 new file mode 100644 index 0000000..72b3523 --- /dev/null +++ b/tests/unit_tests/server/configs/ut-zones-manager/test-dbus-daemon.conf.in @@ -0,0 +1,24 @@ +{ + "zoneConfigs" : ["zones/console1-dbus.conf", + "zones/console2-dbus.conf", + "zones/console3-dbus.conf"], + "foregroundId" : "ut-zones-manager-console1-dbus", + "defaultId" : "ut-zones-manager-console1-dbus", + "zonesPath" : "/tmp/ut-zones", + "zoneImagePath" : "", + "zoneTemplatePath" : "templates", + "zoneNewConfigPrefix" : "@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-zones-manager/", + "runMountPointPrefix" : "", + "lxcTemplatePrefix" : "@VSM_TEST_LXC_TEMPLATES_INSTALL_DIR@", + "inputConfig" : {"enabled" : false, + "device" : "/dev/doesnotexist", + "code" : 139, + "numberOfEvents" : 2, + "timeWindowMs" : 500}, + "proxyCallRules" : [{"caller" : "*", + "target" : "*", + "targetBusName" : "org.tizen.vasum.tests", + "targetObjectPath" : "*", + "targetInterface" : "*", + "targetMethod" : "*"}] +} diff --git a/tests/unit_tests/server/configs/ut-container/ut-dbus.conf b/tests/unit_tests/server/configs/ut-zones-manager/ut-dbus.conf similarity index 89% rename from tests/unit_tests/server/configs/ut-container/ut-dbus.conf rename to tests/unit_tests/server/configs/ut-zones-manager/ut-dbus.conf index 520a14f..2e0488d 100644 --- a/tests/unit_tests/server/configs/ut-container/ut-dbus.conf +++ b/tests/unit_tests/server/configs/ut-zones-manager/ut-dbus.conf @@ -1,4 +1,4 @@ - + diff --git a/tests/unit_tests/server/configs/ut-containers-manager/containers/console1-dbus.conf.in b/tests/unit_tests/server/configs/ut-zones-manager/zones/console1-dbus.conf.in similarity index 73% rename from tests/unit_tests/server/configs/ut-containers-manager/containers/console1-dbus.conf.in rename to tests/unit_tests/server/configs/ut-zones-manager/zones/console1-dbus.conf.in index 4bf616c..72fbdbf 100644 --- a/tests/unit_tests/server/configs/ut-containers-manager/containers/console1-dbus.conf.in +++ b/tests/unit_tests/server/configs/ut-zones-manager/zones/console1-dbus.conf.in @@ -1,7 +1,7 @@ { - "name" : "ut-containers-manager-console1-dbus", + "name" : "ut-zones-manager-console1-dbus", "lxcTemplate" : "minimal-dbus.sh", - "initWithArgs" : ["/bin/sh", "-c", "trap exit SIGTERM; /usr/bin/dbus-daemon --config-file=@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-containers-manager/ut-dbus.conf --fork; read"], + "initWithArgs" : ["/bin/sh", "-c", "trap exit SIGTERM; /usr/bin/dbus-daemon --config-file=@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-zones-manager/ut-dbus.conf --fork; read"], "ipv4Gateway" : "", "ipv4" : "", "privilege" : 20, @@ -10,7 +10,7 @@ "enableDbusIntegration" : true, "cpuQuotaForeground" : -1, "cpuQuotaBackground" : 1000, - "runMountPoint" : "/tmp/ut-run/ut-containers-manager-console1-dbus", + "runMountPoint" : "/tmp/ut-run/ut-zones-manager-console1-dbus", "permittedToSend" : [ "/tmp/.*", "/etc/secret2" ], "permittedToRecv" : [ "/tmp/.*" ] } diff --git a/tests/unit_tests/server/configs/ut-containers-manager/containers/console1.conf b/tests/unit_tests/server/configs/ut-zones-manager/zones/console1.conf similarity index 90% rename from tests/unit_tests/server/configs/ut-containers-manager/containers/console1.conf rename to tests/unit_tests/server/configs/ut-zones-manager/zones/console1.conf index 1ca1e5f..3e88c3d 100644 --- a/tests/unit_tests/server/configs/ut-containers-manager/containers/console1.conf +++ b/tests/unit_tests/server/configs/ut-zones-manager/zones/console1.conf @@ -1,5 +1,5 @@ { - "name" : "ut-containers-manager-console1", + "name" : "ut-zones-manager-console1", "lxcTemplate" : "minimal.sh", "initWithArgs" : ["/bin/sh", "-c", "trap exit SIGTERM; read"], "ipv4Gateway" : "", diff --git a/tests/unit_tests/client/configs/ut-client/containers/console2-dbus.conf.in b/tests/unit_tests/server/configs/ut-zones-manager/zones/console2-dbus.conf.in similarity index 73% rename from tests/unit_tests/client/configs/ut-client/containers/console2-dbus.conf.in rename to tests/unit_tests/server/configs/ut-zones-manager/zones/console2-dbus.conf.in index 4ca2215..1386878 100644 --- a/tests/unit_tests/client/configs/ut-client/containers/console2-dbus.conf.in +++ b/tests/unit_tests/server/configs/ut-zones-manager/zones/console2-dbus.conf.in @@ -1,7 +1,7 @@ { - "name" : "ut-containers-manager-console2-dbus", + "name" : "ut-zones-manager-console2-dbus", "lxcTemplate" : "minimal-dbus.sh", - "initWithArgs" : ["/bin/sh", "-c", "trap exit SIGTERM; /usr/bin/dbus-daemon --config-file=@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-containers-manager/ut-dbus.conf --fork; read"], + "initWithArgs" : ["/bin/sh", "-c", "trap exit SIGTERM; /usr/bin/dbus-daemon --config-file=@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-zones-manager/ut-dbus.conf --fork; read"], "ipv4Gateway" : "", "ipv4" : "", "privilege" : 20, @@ -10,7 +10,7 @@ "enableDbusIntegration" : true, "cpuQuotaForeground" : -1, "cpuQuotaBackground" : 1000, - "runMountPoint" : "/tmp/ut-run/ut-containers-manager-console2-dbus", + "runMountPoint" : "/tmp/ut-run/ut-zones-manager-console2-dbus", "permittedToSend" : [ "/tmp/.*" ], "permittedToRecv" : [ "/tmp/.*", "/etc/secret1" ] } diff --git a/tests/unit_tests/server/configs/ut-containers-manager/containers/console2.conf b/tests/unit_tests/server/configs/ut-zones-manager/zones/console2.conf similarity index 90% rename from tests/unit_tests/server/configs/ut-containers-manager/containers/console2.conf rename to tests/unit_tests/server/configs/ut-zones-manager/zones/console2.conf index 155910b..22f7a39 100644 --- a/tests/unit_tests/server/configs/ut-containers-manager/containers/console2.conf +++ b/tests/unit_tests/server/configs/ut-zones-manager/zones/console2.conf @@ -1,5 +1,5 @@ { - "name" : "ut-containers-manager-console2", + "name" : "ut-zones-manager-console2", "lxcTemplate" : "minimal.sh", "initWithArgs" : ["/bin/sh", "-c", "trap exit SIGTERM; read"], "ipv4Gateway" : "", diff --git a/tests/unit_tests/server/configs/ut-containers-manager/containers/console3-dbus.conf.in b/tests/unit_tests/server/configs/ut-zones-manager/zones/console3-dbus.conf.in similarity index 72% rename from tests/unit_tests/server/configs/ut-containers-manager/containers/console3-dbus.conf.in rename to tests/unit_tests/server/configs/ut-zones-manager/zones/console3-dbus.conf.in index f3d8385..f91754f 100644 --- a/tests/unit_tests/server/configs/ut-containers-manager/containers/console3-dbus.conf.in +++ b/tests/unit_tests/server/configs/ut-zones-manager/zones/console3-dbus.conf.in @@ -1,7 +1,7 @@ { - "name" : "ut-containers-manager-console3-dbus", + "name" : "ut-zones-manager-console3-dbus", "lxcTemplate" : "minimal-dbus.sh", - "initWithArgs" : ["/bin/sh", "-c", "trap exit SIGTERM; /usr/bin/dbus-daemon --config-file=@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-containers-manager/ut-dbus.conf --fork; read"], + "initWithArgs" : ["/bin/sh", "-c", "trap exit SIGTERM; /usr/bin/dbus-daemon --config-file=@VSM_TEST_CONFIG_INSTALL_DIR@/server/ut-zones-manager/ut-dbus.conf --fork; read"], "ipv4Gateway" : "", "ipv4" : "", "privilege" : 20, @@ -10,7 +10,7 @@ "enableDbusIntegration" : true, "cpuQuotaForeground" : -1, "cpuQuotaBackground" : 1000, - "runMountPoint" : "/tmp/ut-run/ut-containers-manager-console3-dbus", + "runMountPoint" : "/tmp/ut-run/ut-zones-manager-console3-dbus", "permittedToSend" : [ "/tmp/.*" ], "permittedToRecv" : [ "/tmp/.*" ] } diff --git a/tests/unit_tests/server/configs/ut-containers-manager/containers/console3.conf b/tests/unit_tests/server/configs/ut-zones-manager/zones/console3.conf similarity index 90% rename from tests/unit_tests/server/configs/ut-containers-manager/containers/console3.conf rename to tests/unit_tests/server/configs/ut-zones-manager/zones/console3.conf index a144c79..2f99f23 100644 --- a/tests/unit_tests/server/configs/ut-containers-manager/containers/console3.conf +++ b/tests/unit_tests/server/configs/ut-zones-manager/zones/console3.conf @@ -1,5 +1,5 @@ { - "name" : "ut-containers-manager-console3", + "name" : "ut-zones-manager-console3", "lxcTemplate" : "minimal.sh", "initWithArgs" : ["/bin/sh", "-c", "trap exit SIGTERM; read"], "ipv4Gateway" : "", diff --git a/tests/unit_tests/server/test-dbus-definitions.hpp b/tests/unit_tests/server/test-dbus-definitions.hpp index 9099c11..01fbb93 100644 --- a/tests/unit_tests/server/test-dbus-definitions.hpp +++ b/tests/unit_tests/server/test-dbus-definitions.hpp @@ -32,8 +32,8 @@ namespace vasum { namespace testapi { -const std::string BUS_NAME = "org.tizen.containers.tests"; -const std::string OBJECT_PATH = "/org/tizen/containers/tests"; +const std::string BUS_NAME = "org.tizen.vasum.tests"; +const std::string OBJECT_PATH = "/org/tizen/vasum/tests"; const std::string INTERFACE = "tests.api"; const std::string METHOD = "Method"; diff --git a/tests/unit_tests/server/ut-server.cpp b/tests/unit_tests/server/ut-server.cpp index cc178db..75b894a 100644 --- a/tests/unit_tests/server/ut-server.cpp +++ b/tests/unit_tests/server/ut-server.cpp @@ -35,13 +35,13 @@ #include namespace { -const std::string CONTAINERS_PATH = "/tmp/ut-containers"; // the same as in daemon.conf +const std::string ZONES_PATH = "/tmp/ut-zones"; // the same as in daemon.conf struct Fixture { - vasum::utils::ScopedDir mContainersPathGuard; + vasum::utils::ScopedDir mZonesPathGuard; Fixture() - : mContainersPathGuard(CONTAINERS_PATH) + : mZonesPathGuard(ZONES_PATH) {} }; } // namespace diff --git a/tests/unit_tests/server/ut-container-admin.cpp b/tests/unit_tests/server/ut-zone-admin.cpp similarity index 80% rename from tests/unit_tests/server/ut-container-admin.cpp rename to tests/unit_tests/server/ut-zone-admin.cpp index fb97d6e..0cd2ddf 100644 --- a/tests/unit_tests/server/ut-container-admin.cpp +++ b/tests/unit_tests/server/ut-zone-admin.cpp @@ -20,13 +20,13 @@ /** * @file * @author Jan Olszak (j.olszak@samsung.com) - * @brief Unit tests of the ContainerAdmin class + * @brief Unit tests of the ZoneAdmin class */ #include "config.hpp" #include "ut.hpp" -#include "container-admin.hpp" +#include "zone-admin.hpp" #include "exception.hpp" #include "utils/glib-loop.hpp" @@ -37,34 +37,34 @@ using namespace vasum; namespace { -const std::string TEST_CONFIG_PATH = VSM_TEST_CONFIG_INSTALL_DIR "/server/ut-container-admin/containers/test.conf"; -const std::string TEST_NO_SHUTDOWN_CONFIG_PATH = VSM_TEST_CONFIG_INSTALL_DIR "/server/ut-container-admin/containers/test-no-shutdown.conf"; -const std::string BUGGY_CONFIG_PATH = VSM_TEST_CONFIG_INSTALL_DIR "/server/ut-container-admin/containers/buggy.conf"; -const std::string MISSING_CONFIG_PATH = VSM_TEST_CONFIG_INSTALL_DIR "/server/ut-container-admin/containers/missing.conf"; -const std::string CONTAINERS_PATH = "/tmp/ut-containers"; +const std::string TEST_CONFIG_PATH = VSM_TEST_CONFIG_INSTALL_DIR "/server/ut-zone-admin/zones/test.conf"; +const std::string TEST_NO_SHUTDOWN_CONFIG_PATH = VSM_TEST_CONFIG_INSTALL_DIR "/server/ut-zone-admin/zones/test-no-shutdown.conf"; +const std::string BUGGY_CONFIG_PATH = VSM_TEST_CONFIG_INSTALL_DIR "/server/ut-zone-admin/zones/buggy.conf"; +const std::string MISSING_CONFIG_PATH = VSM_TEST_CONFIG_INSTALL_DIR "/server/ut-zone-admin/zones/missing.conf"; +const std::string ZONES_PATH = "/tmp/ut-zones"; const std::string LXC_TEMPLATES_PATH = VSM_TEST_LXC_TEMPLATES_INSTALL_DIR; struct Fixture { utils::ScopedGlibLoop mLoop; - utils::ScopedDir mContainersPathGuard; + utils::ScopedDir mZonesPathGuard; - ContainerConfig mConfig; + ZoneConfig mConfig; Fixture() - : mContainersPathGuard(CONTAINERS_PATH) + : mZonesPathGuard(ZONES_PATH) {} - std::unique_ptr create(const std::string& configPath) + std::unique_ptr create(const std::string& configPath) { config::loadFromFile(configPath, mConfig); - return std::unique_ptr(new ContainerAdmin(CONTAINERS_PATH, + return std::unique_ptr(new ZoneAdmin(ZONES_PATH, LXC_TEMPLATES_PATH, mConfig)); } void ensureStarted() { - // wait for containers init to fully start + // wait for zones init to fully start std::this_thread::sleep_for(std::chrono::milliseconds(200)); } }; @@ -72,7 +72,7 @@ struct Fixture { } // namespace -BOOST_FIXTURE_TEST_SUITE(ContainerAdminSuite, Fixture) +BOOST_FIXTURE_TEST_SUITE(ZoneAdminSuite, Fixture) BOOST_AUTO_TEST_CASE(ConstructorDestructorTest) { @@ -82,7 +82,7 @@ BOOST_AUTO_TEST_CASE(ConstructorDestructorTest) BOOST_AUTO_TEST_CASE(MissingConfigTest) { - BOOST_REQUIRE_THROW(create(MISSING_CONFIG_PATH), ContainerOperationException); + BOOST_REQUIRE_THROW(create(MISSING_CONFIG_PATH), ZoneOperationException); } BOOST_AUTO_TEST_CASE(StartTest) @@ -98,7 +98,7 @@ BOOST_AUTO_TEST_CASE(StartTest) BOOST_AUTO_TEST_CASE(StartBuggyTest) { auto admin = create(BUGGY_CONFIG_PATH); - BOOST_REQUIRE_THROW(admin->start(), ContainerOperationException); + BOOST_REQUIRE_THROW(admin->start(), ZoneOperationException); } BOOST_AUTO_TEST_CASE(StopShutdownTest) diff --git a/tests/unit_tests/server/ut-container-connection.cpp b/tests/unit_tests/server/ut-zone-connection.cpp similarity index 75% rename from tests/unit_tests/server/ut-container-connection.cpp rename to tests/unit_tests/server/ut-zone-connection.cpp index 9a65aab..a93b469 100644 --- a/tests/unit_tests/server/ut-container-connection.cpp +++ b/tests/unit_tests/server/ut-zone-connection.cpp @@ -20,16 +20,16 @@ /** * @file * @author Piotr Bartosiewicz (p.bartosiewi@partner.samsung.com) - * @brief Unit tests of the ContainerConnection class + * @brief Unit tests of the ZoneConnection class */ #include "config.hpp" #include "ut.hpp" -#include "container-connection.hpp" -#include "container-connection-transport.hpp" +#include "zone-connection.hpp" +#include "zone-connection-transport.hpp" #include "host-dbus-definitions.hpp" -#include "container-dbus-definitions.hpp" +#include "zone-dbus-definitions.hpp" // TODO: Switch to real power-manager dbus defs when they will be implemented in power-manager #include "fake-power-manager-dbus-definitions.hpp" @@ -41,7 +41,7 @@ #include "utils/fs.hpp" -BOOST_AUTO_TEST_SUITE(ContainerConnectionSuite) +BOOST_AUTO_TEST_SUITE(ZoneConnectionSuite) using namespace vasum; using namespace vasum::utils; @@ -52,12 +52,12 @@ namespace { const char* DBUS_DAEMON_PROC = "/usr/bin/dbus-daemon"; const char* const DBUS_DAEMON_ARGS[] = { DBUS_DAEMON_PROC, - "--config-file=" VSM_TEST_CONFIG_INSTALL_DIR "/server/ut-container-connection/ut-dbus.conf", + "--config-file=" VSM_TEST_CONFIG_INSTALL_DIR "/server/ut-zone-connection/ut-dbus.conf", "--nofork", NULL }; -const std::string TRANSPORT_MOUNT_POINT = "/tmp/ut-container-connection"; +const std::string TRANSPORT_MOUNT_POINT = "/tmp/ut-zone-connection"; const int EVENT_TIMEOUT = 1000; class ScopedDbusDaemon { @@ -73,7 +73,7 @@ public: return mTransport.acquireAddress(); } private: - ContainerConnectionTransport mTransport; + ZoneConnectionTransport mTransport; ScopedDaemon mDaemon; }; @@ -132,31 +132,31 @@ BOOST_AUTO_TEST_CASE(ConstructorDestructorConnectTest) ScopedGlibLoop loop; ScopedDbusDaemon dbus; - BOOST_REQUIRE_NO_THROW(ContainerConnection(dbus.acquireAddress(), nullptr)); + BOOST_REQUIRE_NO_THROW(ZoneConnection(dbus.acquireAddress(), nullptr)); } -BOOST_AUTO_TEST_CASE(NotifyActiveContainerApiTest) +BOOST_AUTO_TEST_CASE(NotifyActiveZoneApiTest) { ScopedGlibLoop loop; ScopedDbusDaemon dbus; Latch notifyCalled; - std::unique_ptr connection; + std::unique_ptr connection; - BOOST_REQUIRE_NO_THROW(connection.reset(new ContainerConnection(dbus.acquireAddress(), nullptr))); + BOOST_REQUIRE_NO_THROW(connection.reset(new ZoneConnection(dbus.acquireAddress(), nullptr))); auto callback = [&](const std::string& application, const std::string& message) { if (application == "testapp" && message == "testmessage") { notifyCalled.set(); } }; - connection->setNotifyActiveContainerCallback(callback); + connection->setNotifyActiveZoneCallback(callback); DbusConnection::Pointer client = DbusConnection::create(dbus.acquireAddress()); - client->callMethod(api::container::BUS_NAME, - api::container::OBJECT_PATH, - api::container::INTERFACE, - api::container::METHOD_NOTIFY_ACTIVE_CONTAINER, + client->callMethod(api::zone::BUS_NAME, + api::zone::OBJECT_PATH, + api::zone::INTERFACE, + api::zone::METHOD_NOTIFY_ACTIVE_ZONE, g_variant_new("(ss)", "testapp", "testmessage"), "()"); BOOST_CHECK(notifyCalled.wait(EVENT_TIMEOUT)); @@ -168,9 +168,9 @@ BOOST_AUTO_TEST_CASE(SignalNotificationApiTest) ScopedDbusDaemon dbus; Latch signalEmitted; - std::unique_ptr connection; + std::unique_ptr connection; - BOOST_REQUIRE_NO_THROW(connection.reset(new ContainerConnection(dbus.acquireAddress(), nullptr))); + BOOST_REQUIRE_NO_THROW(connection.reset(new ZoneConnection(dbus.acquireAddress(), nullptr))); DbusConnection::Pointer client = DbusConnection::create(dbus.acquireAddress()); @@ -179,25 +179,25 @@ BOOST_AUTO_TEST_CASE(SignalNotificationApiTest) const std::string& interface, const std::string& signalName, GVariant* parameters) { - if (objectPath == api::container::OBJECT_PATH && - interface == api::container::INTERFACE && - signalName == api::container::SIGNAL_NOTIFICATION && + if (objectPath == api::zone::OBJECT_PATH && + interface == api::zone::INTERFACE && + signalName == api::zone::SIGNAL_NOTIFICATION && g_variant_is_of_type(parameters, G_VARIANT_TYPE("(sss)"))) { - const gchar* container = NULL; + const gchar* zone = NULL; const gchar* application = NULL; const gchar* message = NULL; - g_variant_get(parameters, "(&s&s&s)", &container, &application, &message); - if (container == std::string("testcontainer") && + g_variant_get(parameters, "(&s&s&s)", &zone, &application, &message); + if (zone == std::string("testzone") && application == std::string("testapp") && message == std::string("testmessage")) { signalEmitted.set(); } } }; - client->signalSubscribe(handler, api::container::BUS_NAME); + client->signalSubscribe(handler, api::zone::BUS_NAME); - connection->sendNotification("testcontainer", "testapp", "testmessage"); + connection->sendNotification("testzone", "testapp", "testmessage"); BOOST_CHECK(signalEmitted.wait(EVENT_TIMEOUT)); } @@ -208,9 +208,9 @@ BOOST_AUTO_TEST_CASE(SignalDisplayOffApiTest) ScopedDbusDaemon dbus; Latch displayOffCalled; - std::unique_ptr connection; + std::unique_ptr connection; - BOOST_REQUIRE_NO_THROW(connection.reset(new ContainerConnection(dbus.acquireAddress(), + BOOST_REQUIRE_NO_THROW(connection.reset(new ZoneConnection(dbus.acquireAddress(), nullptr))); DbusConnection::Pointer client = DbusConnection::create(dbus.acquireAddress()); diff --git a/tests/unit_tests/server/ut-container.cpp b/tests/unit_tests/server/ut-zone.cpp similarity index 78% rename from tests/unit_tests/server/ut-container.cpp rename to tests/unit_tests/server/ut-zone.cpp index 4c4c305..7d80d66 100644 --- a/tests/unit_tests/server/ut-container.cpp +++ b/tests/unit_tests/server/ut-zone.cpp @@ -20,13 +20,13 @@ /** * @file * @author Lukasz Pawelczyk (l.pawelczyk@partner.samsung.com) - * @brief Unit tests of the Container class + * @brief Unit tests of the Zone class */ #include "config.hpp" #include "ut.hpp" -#include "container.hpp" +#include "zone.hpp" #include "exception.hpp" #include "utils/exception.hpp" @@ -45,25 +45,25 @@ using namespace config; namespace { -const std::string TEST_CONFIG_PATH = VSM_TEST_CONFIG_INSTALL_DIR "/server/ut-container/containers/test.conf"; -const std::string TEST_DBUS_CONFIG_PATH = VSM_TEST_CONFIG_INSTALL_DIR "/server/ut-container/containers/test-dbus.conf"; -const std::string BUGGY_CONFIG_PATH = VSM_TEST_CONFIG_INSTALL_DIR "/server/ut-container/containers/buggy.conf"; +const std::string TEST_CONFIG_PATH = VSM_TEST_CONFIG_INSTALL_DIR "/server/ut-zone/zones/test.conf"; +const std::string TEST_DBUS_CONFIG_PATH = VSM_TEST_CONFIG_INSTALL_DIR "/server/ut-zone/zones/test-dbus.conf"; +const std::string BUGGY_CONFIG_PATH = VSM_TEST_CONFIG_INSTALL_DIR "/server/ut-zone/zones/buggy.conf"; const std::string MISSING_CONFIG_PATH = "/this/is/a/missing/file/path/config.conf"; -const std::string CONTAINERS_PATH = "/tmp/ut-containers"; +const std::string ZONES_PATH = "/tmp/ut-zones"; const std::string LXC_TEMPLATES_PATH = VSM_TEST_LXC_TEMPLATES_INSTALL_DIR; struct Fixture { utils::ScopedGlibLoop mLoop; - utils::ScopedDir mContainersPathGuard; + utils::ScopedDir mZonesPathGuard; utils::ScopedDir mRunGuard; Fixture() - : mContainersPathGuard(CONTAINERS_PATH) + : mZonesPathGuard(ZONES_PATH) {} - std::unique_ptr create(const std::string& configPath) + std::unique_ptr create(const std::string& configPath) { - return std::unique_ptr(new Container(CONTAINERS_PATH, + return std::unique_ptr(new Zone(ZONES_PATH, configPath, LXC_TEMPLATES_PATH, "")); @@ -71,7 +71,7 @@ struct Fixture { void ensureStarted() { - // wait for containers init to fully start + // wait for zones init to fully start std::this_thread::sleep_for(std::chrono::milliseconds(200)); } }; @@ -79,7 +79,7 @@ struct Fixture { } // namespace -BOOST_FIXTURE_TEST_SUITE(ContainerSuite, Fixture) +BOOST_FIXTURE_TEST_SUITE(ZoneSuite, Fixture) BOOST_AUTO_TEST_CASE(ConstructorDestructorTest) { @@ -89,7 +89,7 @@ BOOST_AUTO_TEST_CASE(ConstructorDestructorTest) BOOST_AUTO_TEST_CASE(BuggyConfigTest) { - BOOST_REQUIRE_THROW(create(BUGGY_CONFIG_PATH), ContainerOperationException); + BOOST_REQUIRE_THROW(create(BUGGY_CONFIG_PATH), ZoneOperationException); } BOOST_AUTO_TEST_CASE(MissingConfigTest) diff --git a/tests/unit_tests/server/ut-containers-manager.cpp b/tests/unit_tests/server/ut-zones-manager.cpp similarity index 62% rename from tests/unit_tests/server/ut-containers-manager.cpp rename to tests/unit_tests/server/ut-zones-manager.cpp index 4b45186..33d7c50 100644 --- a/tests/unit_tests/server/ut-containers-manager.cpp +++ b/tests/unit_tests/server/ut-zones-manager.cpp @@ -20,17 +20,17 @@ /** * @file * @author Jan Olszak (j.olszak@samsung.com) - * @brief Unit tests of the ContainersManager class + * @brief Unit tests of the ZonesManager class */ #include "config.hpp" #include "ut.hpp" -#include "containers-manager.hpp" -#include "containers-manager-config.hpp" -#include "container-config.hpp" +#include "zones-manager.hpp" +#include "zones-manager-config.hpp" +#include "zone-config.hpp" #include "provisioning-config.hpp" -#include "container-dbus-definitions.hpp" +#include "zone-dbus-definitions.hpp" #include "host-dbus-definitions.hpp" #include "test-dbus-definitions.hpp" // TODO: Switch to real power-manager dbus defs when they will be implemented in power-manager @@ -64,24 +64,24 @@ using namespace dbus; namespace { -const std::string TEST_CONFIG_PATH = VSM_TEST_CONFIG_INSTALL_DIR "/server/ut-containers-manager/test-daemon.conf"; -const std::string TEST_DBUS_CONFIG_PATH = VSM_TEST_CONFIG_INSTALL_DIR "/server/ut-containers-manager/test-dbus-daemon.conf"; -const std::string EMPTY_DBUS_CONFIG_PATH = VSM_TEST_CONFIG_INSTALL_DIR "/server/ut-containers-manager/empty-dbus-daemon.conf"; -const std::string BUGGY_CONFIG_PATH = VSM_TEST_CONFIG_INSTALL_DIR "/server/ut-containers-manager/buggy-daemon.conf"; -const std::string BUGGY_FOREGROUND_CONFIG_PATH = VSM_TEST_CONFIG_INSTALL_DIR "/server/ut-containers-manager/buggy-foreground-daemon.conf"; -const std::string BUGGY_DEFAULTID_CONFIG_PATH = VSM_TEST_CONFIG_INSTALL_DIR "/server/ut-containers-manager/buggy-default-daemon.conf"; -const std::string TEST_CONTAINER_CONF_PATH = VSM_TEST_CONFIG_INSTALL_DIR "/server/ut-containers-manager/containers/"; +const std::string TEST_CONFIG_PATH = VSM_TEST_CONFIG_INSTALL_DIR "/server/ut-zones-manager/test-daemon.conf"; +const std::string TEST_DBUS_CONFIG_PATH = VSM_TEST_CONFIG_INSTALL_DIR "/server/ut-zones-manager/test-dbus-daemon.conf"; +const std::string EMPTY_DBUS_CONFIG_PATH = VSM_TEST_CONFIG_INSTALL_DIR "/server/ut-zones-manager/empty-dbus-daemon.conf"; +const std::string BUGGY_CONFIG_PATH = VSM_TEST_CONFIG_INSTALL_DIR "/server/ut-zones-manager/buggy-daemon.conf"; +const std::string BUGGY_FOREGROUND_CONFIG_PATH = VSM_TEST_CONFIG_INSTALL_DIR "/server/ut-zones-manager/buggy-foreground-daemon.conf"; +const std::string BUGGY_DEFAULTID_CONFIG_PATH = VSM_TEST_CONFIG_INSTALL_DIR "/server/ut-zones-manager/buggy-default-daemon.conf"; +const std::string TEST_ZONE_CONF_PATH = VSM_TEST_CONFIG_INSTALL_DIR "/server/ut-zones-manager/zones/"; const std::string MISSING_CONFIG_PATH = "/this/is/a/missing/file/path/missing-daemon.conf"; const int EVENT_TIMEOUT = 5000; -const int TEST_DBUS_CONNECTION_CONTAINERS_COUNT = 3; -const std::string PREFIX_CONSOLE_NAME = "ut-containers-manager-console"; +const int TEST_DBUS_CONNECTION_ZONES_COUNT = 3; +const std::string PREFIX_CONSOLE_NAME = "ut-zones-manager-console"; const std::string TEST_APP_NAME = "testapp"; const std::string TEST_MESSAGE = "testmessage"; const std::string FILE_CONTENT = "File content\n" "Line 1\n" "Line 2\n"; -const std::string NON_EXISTANT_CONTAINER_ID = "NON_EXISTANT_CONTAINER_ID"; -const std::string CONTAINERS_PATH = "/tmp/ut-containers"; // the same as in daemon.conf +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 PROVISON_CONFIG_FILE = "provision.conf"; class DbusAccessory { @@ -138,7 +138,7 @@ public: void signalSubscribe(const DbusConnection::SignalCallback& callback) { - mClient->signalSubscribe(callback, isHost() ? api::host::BUS_NAME : api::container::BUS_NAME); + mClient->signalSubscribe(callback, isHost() ? api::host::BUS_NAME : api::zone::BUS_NAME); } void emitSignal(const std::string& objectPath, @@ -152,10 +152,10 @@ public: void callMethodNotify() { GVariant* parameters = g_variant_new("(ss)", TEST_APP_NAME.c_str(), TEST_MESSAGE.c_str()); - mClient->callMethod(api::container::BUS_NAME, - api::container::OBJECT_PATH, - api::container::INTERFACE, - api::container::METHOD_NOTIFY_ACTIVE_CONTAINER, + mClient->callMethod(api::zone::BUS_NAME, + api::zone::OBJECT_PATH, + api::zone::INTERFACE, + api::zone::METHOD_NOTIFY_ACTIVE_ZONE, parameters, "()"); } @@ -163,10 +163,10 @@ public: std::string callMethodMove(const std::string& dest, const std::string& path) { GVariant* parameters = g_variant_new("(ss)", dest.c_str(), path.c_str()); - GVariantPtr result = mClient->callMethod(api::container::BUS_NAME, - api::container::OBJECT_PATH, - api::container::INTERFACE, - api::container::METHOD_FILE_MOVE_REQUEST, + GVariantPtr result = mClient->callMethod(api::zone::BUS_NAME, + api::zone::OBJECT_PATH, + api::zone::INTERFACE, + api::zone::METHOD_FILE_MOVE_REQUEST, parameters, "(s)"); @@ -225,11 +225,11 @@ public: method.c_str(), parameters); GVariantPtr result = mClient->callMethod(isHost() ? api::host::BUS_NAME : - api::container::BUS_NAME, + api::zone::BUS_NAME, isHost() ? api::host::OBJECT_PATH : - api::container::OBJECT_PATH, + api::zone::OBJECT_PATH, isHost() ? api::host::INTERFACE : - api::container::INTERFACE, + api::zone::INTERFACE, api::METHOD_PROXY_CALL, packedParameters, "(v)"); @@ -238,14 +238,14 @@ public: return GVariantPtr(unpackedResult, g_variant_unref); } - Dbuses callMethodGetContainerDbuses() + Dbuses callMethodGetZoneDbuses() { assert(isHost()); Dbuses dbuses; GVariantPtr result = mClient->callMethod(api::host::BUS_NAME, api::host::OBJECT_PATH, api::host::INTERFACE, - api::host::METHOD_GET_CONTAINER_DBUSES, + api::host::METHOD_GET_ZONE_DBUSES, NULL, "(a{ss})"); GVariant* array = NULL; @@ -253,21 +253,21 @@ public: dbus::GVariantPtr autounref(array, g_variant_unref); size_t count = g_variant_n_children(array); for (size_t n = 0; n < count; ++n) { - const char* containerId = NULL; + const char* zoneId = NULL; const char* dbusAddress = NULL; - g_variant_get_child(array, n, "{&s&s}", &containerId, &dbusAddress); - dbuses.insert(Dbuses::value_type(containerId, dbusAddress)); + g_variant_get_child(array, n, "{&s&s}", &zoneId, &dbusAddress); + dbuses.insert(Dbuses::value_type(zoneId, dbusAddress)); } return dbuses; } - std::vector callMethodGetContainerIds() + std::vector callMethodGetZoneIds() { assert(isHost()); GVariantPtr result = mClient->callMethod(api::host::BUS_NAME, api::host::OBJECT_PATH, api::host::INTERFACE, - api::host::METHOD_GET_CONTAINER_ID_LIST, + api::host::METHOD_GET_ZONE_ID_LIST, NULL, "(as)"); @@ -275,46 +275,46 @@ public: g_variant_get(result.get(), "(*)", &array); size_t arraySize = g_variant_n_children(array); - std::vector containerIds; + std::vector zoneIds; for (size_t i = 0; i < arraySize; ++i) { const char* id = NULL; g_variant_get_child(array, i, "&s", &id); - containerIds.push_back(id); + zoneIds.push_back(id); } g_variant_unref(array); - return containerIds; + return zoneIds; } - std::string callMethodGetActiveContainerId() + std::string callMethodGetActiveZoneId() { assert(isHost()); GVariantPtr result = mClient->callMethod(api::host::BUS_NAME, api::host::OBJECT_PATH, api::host::INTERFACE, - api::host::METHOD_GET_ACTIVE_CONTAINER_ID, + api::host::METHOD_GET_ACTIVE_ZONE_ID, NULL, "(s)"); - const char* containerId = NULL; - g_variant_get(result.get(), "(&s)", &containerId); - return containerId; + const char* zoneId = NULL; + g_variant_get(result.get(), "(&s)", &zoneId); + return zoneId; } - void callMethodSetActiveContainer(const std::string& id) + void callMethodSetActiveZone(const std::string& id) { assert(isHost()); GVariant* parameters = g_variant_new("(s)", id.c_str()); GVariantPtr result = mClient->callMethod(api::host::BUS_NAME, api::host::OBJECT_PATH, api::host::INTERFACE, - api::host::METHOD_SET_ACTIVE_CONTAINER, + api::host::METHOD_SET_ACTIVE_ZONE, parameters, "()"); } - void callMethodDeclareFile(const std::string& container, + void callMethodDeclareFile(const std::string& zone, const int32_t& type, const std::string& path, const int32_t& flags, @@ -322,7 +322,7 @@ public: { assert(isHost()); GVariant* parameters = g_variant_new("(sisii)", - container.c_str(), + zone.c_str(), type, path.c_str(), flags, @@ -336,7 +336,7 @@ public: } void callMethodDeclareMount(const std::string& source, - const std::string& container, + const std::string& zone, const std::string& target, const std::string& type, const uint64_t& flags, @@ -345,7 +345,7 @@ public: assert(isHost()); GVariant* parameters = g_variant_new("(ssssts)", source.c_str(), - container.c_str(), + zone.c_str(), target.c_str(), type.c_str(), flags, @@ -359,13 +359,13 @@ public: } void callMethodDeclareLink(const std::string& source, - const std::string& container, + const std::string& zone, const std::string& target) { assert(isHost()); GVariant* parameters = g_variant_new("(sss)", source.c_str(), - container.c_str(), + zone.c_str(), target.c_str()); GVariantPtr result = mClient->callMethod(api::host::BUS_NAME, api::host::OBJECT_PATH, @@ -375,7 +375,7 @@ public: "()"); } - void callAsyncMethodCreateContainer(const std::string& id, + void callAsyncMethodCreateZone(const std::string& id, const VoidResultCallback& result) { auto asyncResult = [result](dbus::AsyncMethodCallResult& asyncMethodCallResult) { @@ -388,13 +388,13 @@ public: mClient->callMethodAsync(api::host::BUS_NAME, api::host::OBJECT_PATH, api::host::INTERFACE, - api::host::METHOD_CREATE_CONTAINER, + api::host::METHOD_CREATE_ZONE, parameters, "()", asyncResult); } - void callAsyncMethodDestroyContainer(const std::string& id, + void callAsyncMethodDestroyZone(const std::string& id, const VoidResultCallback& result) { auto asyncResult = [result](dbus::AsyncMethodCallResult& asyncMethodCallResult) { @@ -407,32 +407,32 @@ public: mClient->callMethodAsync(api::host::BUS_NAME, api::host::OBJECT_PATH, api::host::INTERFACE, - api::host::METHOD_DESTROY_CONTAINER, + api::host::METHOD_DESTROY_ZONE, parameters, "()", asyncResult); } - void callMethodLockContainer(const std::string& id) + void callMethodLockZone(const std::string& id) { assert(isHost()); GVariant* parameters = g_variant_new("(s)", id.c_str()); GVariantPtr result = mClient->callMethod(api::host::BUS_NAME, api::host::OBJECT_PATH, api::host::INTERFACE, - api::host::METHOD_LOCK_CONTAINER, + api::host::METHOD_LOCK_ZONE, parameters, "()"); } - void callMethodUnlockContainer(const std::string& id) + void callMethodUnlockZone(const std::string& id) { assert(isHost()); GVariant* parameters = g_variant_new("(s)", id.c_str()); GVariantPtr result = mClient->callMethod(api::host::BUS_NAME, api::host::OBJECT_PATH, api::host::INTERFACE, - api::host::METHOD_UNLOCK_CONTAINER, + api::host::METHOD_UNLOCK_ZONE, parameters, "()"); } @@ -454,7 +454,7 @@ private: if (isHost()) { return "unix:path=/var/run/dbus/system_bus_socket"; } - return "unix:path=/tmp/ut-run/ut-containers-manager-console" + std::to_string(mId) + + return "unix:path=/tmp/ut-run/ut-zones-manager-console" + std::to_string(mId) + "-dbus/dbus/system_bus_socket"; } }; @@ -468,120 +468,120 @@ std::function expectedMessage(const std::string& me struct Fixture { vasum::utils::ScopedGlibLoop mLoop; - utils::ScopedDir mContainersPathGuard; + utils::ScopedDir mZonesPathGuard; utils::ScopedDir mRunGuard; Fixture() - : mContainersPathGuard(CONTAINERS_PATH) + : mZonesPathGuard(ZONES_PATH) , mRunGuard("/tmp/ut-run") {} }; -std::string getProvisionConfigPath(const std::string& container) +std::string getProvisionConfigPath(const std::string& zone) { namespace fs = boost::filesystem; - ContainersManagerConfig managerConfig; + ZonesManagerConfig managerConfig; loadFromFile(TEST_CONFIG_PATH, managerConfig); - for (const auto& containersPath : managerConfig.containerConfigs) { - ContainerConfig containerConfig; - const fs::path configConfigPath = fs::absolute(containersPath, + for (const auto& zonesPath : managerConfig.zoneConfigs) { + ZoneConfig zoneConfig; + const fs::path configConfigPath = fs::absolute(zonesPath, fs::path(TEST_CONFIG_PATH).parent_path()); - loadFromFile(configConfigPath.string(), containerConfig); - if (containerConfig.name == container) { - const fs::path base = fs::path(managerConfig.containersPath) / fs::path(container); + loadFromFile(configConfigPath.string(), zoneConfig); + if (zoneConfig.name == zone) { + const fs::path base = fs::path(managerConfig.zonesPath) / fs::path(zone); return fs::absolute(PROVISON_CONFIG_FILE, base).string(); } } - BOOST_FAIL("There is no provision config file for " + container); + BOOST_FAIL("There is no provision config file for " + zone); return std::string(); } } // namespace -BOOST_FIXTURE_TEST_SUITE(ContainersManagerSuite, Fixture) +BOOST_FIXTURE_TEST_SUITE(ZonesManagerSuite, Fixture) BOOST_AUTO_TEST_CASE(ConstructorDestructorTest) { - std::unique_ptr cm; - cm.reset(new ContainersManager(TEST_CONFIG_PATH)); + std::unique_ptr cm; + cm.reset(new ZonesManager(TEST_CONFIG_PATH)); cm.reset(); } BOOST_AUTO_TEST_CASE(BuggyConfigTest) { - BOOST_REQUIRE_THROW(ContainersManager cm(BUGGY_CONFIG_PATH), ConfigException); + BOOST_REQUIRE_THROW(ZonesManager cm(BUGGY_CONFIG_PATH), ConfigException); } BOOST_AUTO_TEST_CASE(MissingConfigTest) { - BOOST_REQUIRE_THROW(ContainersManager cm(MISSING_CONFIG_PATH), ConfigException); + BOOST_REQUIRE_THROW(ZonesManager cm(MISSING_CONFIG_PATH), ConfigException); } BOOST_AUTO_TEST_CASE(StartAllTest) { - ContainersManager cm(TEST_CONFIG_PATH); + ZonesManager cm(TEST_CONFIG_PATH); cm.startAll(); - BOOST_CHECK(cm.getRunningForegroundContainerId() == "ut-containers-manager-console1"); + BOOST_CHECK(cm.getRunningForegroundZoneId() == "ut-zones-manager-console1"); } BOOST_AUTO_TEST_CASE(BuggyForegroundTest) { - ContainersManager cm(BUGGY_FOREGROUND_CONFIG_PATH); + ZonesManager cm(BUGGY_FOREGROUND_CONFIG_PATH); cm.startAll(); - BOOST_CHECK(cm.getRunningForegroundContainerId() == "ut-containers-manager-console2"); + BOOST_CHECK(cm.getRunningForegroundZoneId() == "ut-zones-manager-console2"); } BOOST_AUTO_TEST_CASE(BuggyDefaultTest) { - BOOST_REQUIRE_THROW(ContainersManager cm(BUGGY_DEFAULTID_CONFIG_PATH), - ContainerOperationException); + BOOST_REQUIRE_THROW(ZonesManager cm(BUGGY_DEFAULTID_CONFIG_PATH), + ZoneOperationException); } BOOST_AUTO_TEST_CASE(StopAllTest) { - ContainersManager cm(TEST_CONFIG_PATH); + ZonesManager cm(TEST_CONFIG_PATH); cm.startAll(); cm.stopAll(); - BOOST_CHECK(cm.getRunningForegroundContainerId().empty()); + BOOST_CHECK(cm.getRunningForegroundZoneId().empty()); } BOOST_AUTO_TEST_CASE(DetachOnExitTest) { { - ContainersManager cm(TEST_CONFIG_PATH); + ZonesManager cm(TEST_CONFIG_PATH); cm.startAll(); - cm.setContainersDetachOnExit(); + cm.setZonesDetachOnExit(); } { - ContainersManager cm(TEST_CONFIG_PATH); + ZonesManager cm(TEST_CONFIG_PATH); cm.startAll(); } } BOOST_AUTO_TEST_CASE(FocusTest) { - ContainersManager cm(TEST_CONFIG_PATH); + ZonesManager cm(TEST_CONFIG_PATH); cm.startAll(); - cm.focus("ut-containers-manager-console2"); - BOOST_CHECK(cm.getRunningForegroundContainerId() == "ut-containers-manager-console2"); - cm.focus("ut-containers-manager-console1"); - BOOST_CHECK(cm.getRunningForegroundContainerId() == "ut-containers-manager-console1"); - cm.focus("ut-containers-manager-console3"); - BOOST_CHECK(cm.getRunningForegroundContainerId() == "ut-containers-manager-console3"); + cm.focus("ut-zones-manager-console2"); + BOOST_CHECK(cm.getRunningForegroundZoneId() == "ut-zones-manager-console2"); + cm.focus("ut-zones-manager-console1"); + BOOST_CHECK(cm.getRunningForegroundZoneId() == "ut-zones-manager-console1"); + cm.focus("ut-zones-manager-console3"); + BOOST_CHECK(cm.getRunningForegroundZoneId() == "ut-zones-manager-console3"); } -BOOST_AUTO_TEST_CASE(NotifyActiveContainerTest) +BOOST_AUTO_TEST_CASE(NotifyActiveZoneTest) { - ContainersManager cm(TEST_DBUS_CONFIG_PATH); + ZonesManager cm(TEST_DBUS_CONFIG_PATH); cm.startAll(); Latch signalReceivedLatch; std::map> signalReceivedSourcesMap; std::map> dbuses; - for (int i = 1; i <= TEST_DBUS_CONNECTION_CONTAINERS_COUNT; ++i) { + for (int i = 1; i <= TEST_DBUS_CONNECTION_ZONES_COUNT; ++i) { dbuses[i] = std::unique_ptr(new DbusAccessory(i)); } @@ -593,16 +593,16 @@ BOOST_AUTO_TEST_CASE(NotifyActiveContainerTest) const std::string& signalName, GVariant* parameters) { - if (objectPath == api::container::OBJECT_PATH && - interface == api::container::INTERFACE && - signalName == api::container::SIGNAL_NOTIFICATION && + if (objectPath == api::zone::OBJECT_PATH && + interface == api::zone::INTERFACE && + signalName == api::zone::SIGNAL_NOTIFICATION && g_variant_is_of_type(parameters, G_VARIANT_TYPE("(sss)"))) { - const gchar* container = NULL; + const gchar* zone = NULL; const gchar* application = NULL; const gchar* message = NULL; - g_variant_get(parameters, "(&s&s&s)", &container, &application, &message); - receivedSignalSources.push_back(container); + g_variant_get(parameters, "(&s&s&s)", &zone, &application, &message); + receivedSignalSources.push_back(zone); if (application == TEST_APP_NAME && message == TEST_MESSAGE) { latch.set(); } @@ -610,7 +610,7 @@ BOOST_AUTO_TEST_CASE(NotifyActiveContainerTest) }; using namespace std::placeholders; - for (int i = 1; i <= TEST_DBUS_CONNECTION_CONTAINERS_COUNT; ++i) { + for (int i = 1; i <= TEST_DBUS_CONNECTION_ZONES_COUNT; ++i) { dbuses[i]->signalSubscribe(std::bind(handler, std::ref(signalReceivedLatch), std::ref(signalReceivedSourcesMap[i]), @@ -629,9 +629,9 @@ BOOST_AUTO_TEST_CASE(NotifyActiveContainerTest) signalReceivedSourcesMap[1].end(), source), 1); } - //check if all signals was received by active container + //check if all signals was received by active zone BOOST_CHECK_EQUAL(signalReceivedSourcesMap[1].size(), dbuses.size() - 1); - //check if no signals was received by inactive container + //check if no signals was received by inactive zone for (size_t i = 2; i <= dbuses.size(); ++i) { BOOST_CHECK(signalReceivedSourcesMap[i].empty()); } @@ -641,11 +641,11 @@ BOOST_AUTO_TEST_CASE(NotifyActiveContainerTest) BOOST_AUTO_TEST_CASE(DisplayOffTest) { - ContainersManager cm(TEST_DBUS_CONFIG_PATH); + ZonesManager cm(TEST_DBUS_CONFIG_PATH); cm.startAll(); std::vector> clients; - for (int i = 1; i <= TEST_DBUS_CONNECTION_CONTAINERS_COUNT; ++i) { + for (int i = 1; i <= TEST_DBUS_CONNECTION_ZONES_COUNT; ++i) { clients.push_back(std::unique_ptr(new DbusAccessory(i))); } @@ -657,13 +657,13 @@ BOOST_AUTO_TEST_CASE(DisplayOffTest) std::unique_lock Lock(Mutex); std::condition_variable Condition; auto cond = [&cm]() -> bool { - return cm.getRunningForegroundContainerId() == "ut-containers-manager-console1-dbus"; + return cm.getRunningForegroundZoneId() == "ut-zones-manager-console1-dbus"; }; for (auto& client : clients) { - // TEST SWITCHING TO DEFAULT CONTAINER - // focus non-default container - cm.focus("ut-containers-manager-console3-dbus"); + // TEST SWITCHING TO DEFAULT ZONE + // focus non-default zone + cm.focus("ut-zones-manager-console3-dbus"); // emit signal from dbus connection client->emitSignal(fake_power_manager_api::OBJECT_PATH, @@ -671,14 +671,14 @@ BOOST_AUTO_TEST_CASE(DisplayOffTest) fake_power_manager_api::SIGNAL_DISPLAY_OFF, nullptr); - // check if default container has focus + // check if default zone has focus BOOST_CHECK(Condition.wait_for(Lock, std::chrono::milliseconds(EVENT_TIMEOUT), cond)); } } BOOST_AUTO_TEST_CASE(MoveFileTest) { - ContainersManager cm(TEST_DBUS_CONFIG_PATH); + ZonesManager cm(TEST_DBUS_CONFIG_PATH); cm.startAll(); Latch notificationLatch; @@ -697,9 +697,9 @@ BOOST_AUTO_TEST_CASE(MoveFileTest) const std::string& signalName, GVariant* parameters) { - if (objectPath == api::container::OBJECT_PATH && - interface == api::container::INTERFACE && - signalName == api::container::SIGNAL_NOTIFICATION && + if (objectPath == api::zone::OBJECT_PATH && + interface == api::zone::INTERFACE && + signalName == api::zone::SIGNAL_NOTIFICATION && g_variant_is_of_type(parameters, G_VARIANT_TYPE("(sss)"))) { const gchar* source = NULL; @@ -714,73 +714,73 @@ BOOST_AUTO_TEST_CASE(MoveFileTest) } }; - // subscribe the second (destination) container for notifications + // subscribe the second (destination) zone for notifications dbuses.at(2)->signalSubscribe(handler); - const std::string TMP = "/tmp/ut-containers"; + const std::string TMP = "/tmp/ut-zones"; const std::string NO_PATH = "path_doesnt_matter_here"; const std::string BUGGY_PATH = TMP + "/this_file_does_not_exist"; - const std::string BUGGY_CONTAINER = "this-container-does-not-exist"; - const std::string CONTAINER1 = "ut-containers-manager-console1-dbus"; - const std::string CONTAINER2 = "ut-containers-manager-console2-dbus"; - const std::string CONTAINER1PATH = TMP + "/" + CONTAINER1 + TMP; - const std::string CONTAINER2PATH = TMP + "/" + CONTAINER2 + TMP; - - // sending to a non existing container - BOOST_CHECK_EQUAL(dbuses.at(1)->callMethodMove(BUGGY_CONTAINER, NO_PATH), - api::container::FILE_MOVE_DESTINATION_NOT_FOUND); + const std::string BUGGY_ZONE = "this-zone-does-not-exist"; + const std::string ZONE1 = "ut-zones-manager-console1-dbus"; + const std::string ZONE2 = "ut-zones-manager-console2-dbus"; + const std::string ZONE1PATH = TMP + "/" + ZONE1 + TMP; + const std::string ZONE2PATH = TMP + "/" + ZONE2 + TMP; + + // sending to a non existing zone + BOOST_CHECK_EQUAL(dbuses.at(1)->callMethodMove(BUGGY_ZONE, NO_PATH), + api::zone::FILE_MOVE_DESTINATION_NOT_FOUND); BOOST_CHECK(notificationLatch.empty()); // sending to self - BOOST_CHECK_EQUAL(dbuses.at(1)->callMethodMove(CONTAINER1, NO_PATH), - api::container::FILE_MOVE_WRONG_DESTINATION); + BOOST_CHECK_EQUAL(dbuses.at(1)->callMethodMove(ZONE1, NO_PATH), + api::zone::FILE_MOVE_WRONG_DESTINATION); BOOST_CHECK(notificationLatch.empty()); // no permission to send - BOOST_CHECK_EQUAL(dbuses.at(1)->callMethodMove(CONTAINER2, "/etc/secret1"), - api::container::FILE_MOVE_NO_PERMISSIONS_SEND); + BOOST_CHECK_EQUAL(dbuses.at(1)->callMethodMove(ZONE2, "/etc/secret1"), + api::zone::FILE_MOVE_NO_PERMISSIONS_SEND); BOOST_CHECK(notificationLatch.empty()); // no permission to receive - BOOST_CHECK_EQUAL(dbuses.at(1)->callMethodMove(CONTAINER2, "/etc/secret2"), - api::container::FILE_MOVE_NO_PERMISSIONS_RECEIVE); + BOOST_CHECK_EQUAL(dbuses.at(1)->callMethodMove(ZONE2, "/etc/secret2"), + api::zone::FILE_MOVE_NO_PERMISSIONS_RECEIVE); BOOST_CHECK(notificationLatch.empty()); // non existing file - BOOST_CHECK_EQUAL(dbuses.at(1)->callMethodMove(CONTAINER2, BUGGY_PATH), - api::container::FILE_MOVE_FAILED); + BOOST_CHECK_EQUAL(dbuses.at(1)->callMethodMove(ZONE2, BUGGY_PATH), + api::zone::FILE_MOVE_FAILED); BOOST_CHECK(notificationLatch.empty()); // a working scenario namespace fs = boost::filesystem; boost::system::error_code ec; - fs::remove_all(CONTAINER1PATH, ec); - fs::remove_all(CONTAINER2PATH, ec); - BOOST_REQUIRE(fs::create_directories(CONTAINER1PATH, ec)); - BOOST_REQUIRE(fs::create_directories(CONTAINER2PATH, ec)); - BOOST_REQUIRE(utils::saveFileContent(CONTAINER1PATH + "/file", FILE_CONTENT)); - - BOOST_CHECK_EQUAL(dbuses.at(1)->callMethodMove(CONTAINER2, TMP + "/file"), - api::container::FILE_MOVE_SUCCEEDED); + fs::remove_all(ZONE1PATH, ec); + fs::remove_all(ZONE2PATH, ec); + BOOST_REQUIRE(fs::create_directories(ZONE1PATH, ec)); + BOOST_REQUIRE(fs::create_directories(ZONE2PATH, ec)); + BOOST_REQUIRE(utils::saveFileContent(ZONE1PATH + "/file", FILE_CONTENT)); + + BOOST_CHECK_EQUAL(dbuses.at(1)->callMethodMove(ZONE2, TMP + "/file"), + api::zone::FILE_MOVE_SUCCEEDED); BOOST_CHECK(notificationLatch.wait(EVENT_TIMEOUT)); BOOST_CHECK(notificationLatch.empty()); - BOOST_CHECK_EQUAL(notificationSource, CONTAINER1); + BOOST_CHECK_EQUAL(notificationSource, ZONE1); BOOST_CHECK_EQUAL(notificationPath, TMP + "/file"); - BOOST_CHECK_EQUAL(notificationRetcode, api::container::FILE_MOVE_SUCCEEDED); - BOOST_CHECK(!fs::exists(CONTAINER1PATH + "/file")); - BOOST_CHECK_EQUAL(utils::readFileContent(CONTAINER2PATH + "/file"), FILE_CONTENT); + BOOST_CHECK_EQUAL(notificationRetcode, api::zone::FILE_MOVE_SUCCEEDED); + BOOST_CHECK(!fs::exists(ZONE1PATH + "/file")); + BOOST_CHECK_EQUAL(utils::readFileContent(ZONE2PATH + "/file"), FILE_CONTENT); - fs::remove_all(CONTAINER1PATH, ec); - fs::remove_all(CONTAINER2PATH, ec); + fs::remove_all(ZONE1PATH, ec); + fs::remove_all(ZONE2PATH, ec); } BOOST_AUTO_TEST_CASE(AllowSwitchToDefaultTest) { - ContainersManager cm(TEST_DBUS_CONFIG_PATH); + ZonesManager cm(TEST_DBUS_CONFIG_PATH); cm.startAll(); std::vector> clients; - for (int i = 1; i <= TEST_DBUS_CONNECTION_CONTAINERS_COUNT; ++i) { + for (int i = 1; i <= TEST_DBUS_CONNECTION_ZONES_COUNT; ++i) { clients.push_back(std::unique_ptr(new DbusAccessory(i))); } @@ -792,12 +792,12 @@ BOOST_AUTO_TEST_CASE(AllowSwitchToDefaultTest) std::unique_lock condLock(condMutex); std::condition_variable condition; auto cond = [&cm]() -> bool { - return cm.getRunningForegroundContainerId() == "ut-containers-manager-console1-dbus"; + return cm.getRunningForegroundZoneId() == "ut-zones-manager-console1-dbus"; }; for (auto& client : clients) { - // focus non-default container with allowed switching - cm.focus("ut-containers-manager-console3-dbus"); + // focus non-default zone with allowed switching + cm.focus("ut-zones-manager-console3-dbus"); // emit signal from dbus connection client->emitSignal(fake_power_manager_api::OBJECT_PATH, @@ -805,11 +805,11 @@ BOOST_AUTO_TEST_CASE(AllowSwitchToDefaultTest) fake_power_manager_api::SIGNAL_DISPLAY_OFF, nullptr); - // check if default container has focus + // check if default zone has focus BOOST_CHECK(condition.wait_for(condLock, std::chrono::milliseconds(EVENT_TIMEOUT), cond)); - // focus non-default container with disabled switching - cm.focus("ut-containers-manager-console2-dbus"); + // focus non-default zone with disabled switching + cm.focus("ut-zones-manager-console2-dbus"); // emit signal from dbus connection client->emitSignal(fake_power_manager_api::OBJECT_PATH, @@ -817,18 +817,18 @@ BOOST_AUTO_TEST_CASE(AllowSwitchToDefaultTest) fake_power_manager_api::SIGNAL_DISPLAY_OFF, nullptr); - // now default container should not be focused + // now default zone should not be focused BOOST_CHECK(!condition.wait_for(condLock, std::chrono::milliseconds(EVENT_TIMEOUT), cond)); } } BOOST_AUTO_TEST_CASE(ProxyCallTest) { - ContainersManager cm(TEST_DBUS_CONFIG_PATH); + ZonesManager cm(TEST_DBUS_CONFIG_PATH); cm.startAll(); std::map> dbuses; - for (int i = 0; i <= TEST_DBUS_CONNECTION_CONTAINERS_COUNT; ++i) { + for (int i = 0; i <= TEST_DBUS_CONNECTION_ZONES_COUNT; ++i) { dbuses[i] = std::unique_ptr(new DbusAccessory(i)); } @@ -838,7 +838,7 @@ BOOST_AUTO_TEST_CASE(ProxyCallTest) const int id = dbus.first; auto handler = [id](const std::string& argument, MethodResultBuilder::Pointer result) { if (argument.empty()) { - result->setError("org.tizen.containers.Error.Test", "Test error"); + result->setError("org.tizen.vasum.Error.Test", "Test error"); } else { std::string ret = "reply from " + std::to_string(id) + ": " + argument; result->set(g_variant_new("(s)", ret.c_str())); @@ -847,9 +847,9 @@ BOOST_AUTO_TEST_CASE(ProxyCallTest) dbus.second->registerTestApiObject(handler); } - // host -> container2 + // host -> zone2 BOOST_CHECK_EQUAL("reply from 2: param1", - dbuses.at(0)->testApiProxyCall("ut-containers-manager-console2-dbus", + dbuses.at(0)->testApiProxyCall("ut-zones-manager-console2-dbus", "param1")); // host -> host @@ -857,19 +857,19 @@ BOOST_AUTO_TEST_CASE(ProxyCallTest) dbuses.at(0)->testApiProxyCall("host", "param2")); - // container1 -> host + // zone1 -> host BOOST_CHECK_EQUAL("reply from 0: param3", dbuses.at(1)->testApiProxyCall("host", "param3")); - // container1 -> container2 + // zone1 -> zone2 BOOST_CHECK_EQUAL("reply from 2: param4", - dbuses.at(1)->testApiProxyCall("ut-containers-manager-console2-dbus", + dbuses.at(1)->testApiProxyCall("ut-zones-manager-console2-dbus", "param4")); - // container2 -> container2 + // zone2 -> zone2 BOOST_CHECK_EQUAL("reply from 2: param5", - dbuses.at(2)->testApiProxyCall("ut-containers-manager-console2-dbus", + dbuses.at(2)->testApiProxyCall("ut-zones-manager-console2-dbus", "param5")); // host -> unknown @@ -895,48 +895,48 @@ BOOST_AUTO_TEST_CASE(ProxyCallTest) namespace { const DbusAccessory::Dbuses EXPECTED_DBUSES_NO_DBUS = { - {"ut-containers-manager-console1", ""}, - {"ut-containers-manager-console2", ""}, - {"ut-containers-manager-console3", ""}}; + {"ut-zones-manager-console1", ""}, + {"ut-zones-manager-console2", ""}, + {"ut-zones-manager-console3", ""}}; const DbusAccessory::Dbuses EXPECTED_DBUSES_STOPPED = { - {"ut-containers-manager-console1-dbus", ""}, - {"ut-containers-manager-console2-dbus", ""}, - {"ut-containers-manager-console3-dbus", ""}}; + {"ut-zones-manager-console1-dbus", ""}, + {"ut-zones-manager-console2-dbus", ""}, + {"ut-zones-manager-console3-dbus", ""}}; const DbusAccessory::Dbuses EXPECTED_DBUSES_STARTED = { - {"ut-containers-manager-console1-dbus", - "unix:path=/tmp/ut-run/ut-containers-manager-console1-dbus/dbus/system_bus_socket"}, - {"ut-containers-manager-console2-dbus", - "unix:path=/tmp/ut-run/ut-containers-manager-console2-dbus/dbus/system_bus_socket"}, - {"ut-containers-manager-console3-dbus", - "unix:path=/tmp/ut-run/ut-containers-manager-console3-dbus/dbus/system_bus_socket"}}; + {"ut-zones-manager-console1-dbus", + "unix:path=/tmp/ut-run/ut-zones-manager-console1-dbus/dbus/system_bus_socket"}, + {"ut-zones-manager-console2-dbus", + "unix:path=/tmp/ut-run/ut-zones-manager-console2-dbus/dbus/system_bus_socket"}, + {"ut-zones-manager-console3-dbus", + "unix:path=/tmp/ut-run/ut-zones-manager-console3-dbus/dbus/system_bus_socket"}}; } // namespace -BOOST_AUTO_TEST_CASE(GetContainerDbusesTest) +BOOST_AUTO_TEST_CASE(GetZoneDbusesTest) { DbusAccessory host(DbusAccessory::HOST_ID); - ContainersManager cm(TEST_DBUS_CONFIG_PATH); + ZonesManager cm(TEST_DBUS_CONFIG_PATH); - BOOST_CHECK(EXPECTED_DBUSES_STOPPED == host.callMethodGetContainerDbuses()); + BOOST_CHECK(EXPECTED_DBUSES_STOPPED == host.callMethodGetZoneDbuses()); cm.startAll(); - BOOST_CHECK(EXPECTED_DBUSES_STARTED == host.callMethodGetContainerDbuses()); + BOOST_CHECK(EXPECTED_DBUSES_STARTED == host.callMethodGetZoneDbuses()); cm.stopAll(); - BOOST_CHECK(EXPECTED_DBUSES_STOPPED == host.callMethodGetContainerDbuses()); + BOOST_CHECK(EXPECTED_DBUSES_STOPPED == host.callMethodGetZoneDbuses()); } -BOOST_AUTO_TEST_CASE(GetContainerDbusesNoDbusTest) +BOOST_AUTO_TEST_CASE(GetZoneDbusesNoDbusTest) { DbusAccessory host(DbusAccessory::HOST_ID); - ContainersManager cm(TEST_CONFIG_PATH); - BOOST_CHECK(EXPECTED_DBUSES_NO_DBUS == host.callMethodGetContainerDbuses()); + ZonesManager cm(TEST_CONFIG_PATH); + BOOST_CHECK(EXPECTED_DBUSES_NO_DBUS == host.callMethodGetZoneDbuses()); cm.startAll(); - BOOST_CHECK(EXPECTED_DBUSES_NO_DBUS == host.callMethodGetContainerDbuses()); + BOOST_CHECK(EXPECTED_DBUSES_NO_DBUS == host.callMethodGetZoneDbuses()); cm.stopAll(); - BOOST_CHECK(EXPECTED_DBUSES_NO_DBUS == host.callMethodGetContainerDbuses()); + BOOST_CHECK(EXPECTED_DBUSES_NO_DBUS == host.callMethodGetZoneDbuses()); } -BOOST_AUTO_TEST_CASE(ContainerDbusesSignalsTest) +BOOST_AUTO_TEST_CASE(ZoneDbusesSignalsTest) { Latch signalLatch; DbusAccessory::Dbuses collectedDbuses; @@ -950,13 +950,13 @@ BOOST_AUTO_TEST_CASE(ContainerDbusesSignalsTest) GVariant* parameters) { if (objectPath == api::host::OBJECT_PATH && interface == api::host::INTERFACE && - signalName == api::host::SIGNAL_CONTAINER_DBUS_STATE) { + signalName == api::host::SIGNAL_ZONE_DBUS_STATE) { - const gchar* containerId = NULL; + const gchar* zoneId = NULL; const gchar* dbusAddress = NULL; - g_variant_get(parameters, "(&s&s)", &containerId, &dbusAddress); + g_variant_get(parameters, "(&s&s)", &zoneId, &dbusAddress); - collectedDbuses.insert(DbusAccessory::Dbuses::value_type(containerId, dbusAddress)); + collectedDbuses.insert(DbusAccessory::Dbuses::value_type(zoneId, dbusAddress)); signalLatch.set(); } }; @@ -964,95 +964,95 @@ BOOST_AUTO_TEST_CASE(ContainerDbusesSignalsTest) host.signalSubscribe(onSignal); { - ContainersManager cm(TEST_DBUS_CONFIG_PATH); + ZonesManager cm(TEST_DBUS_CONFIG_PATH); BOOST_CHECK(signalLatch.empty()); BOOST_CHECK(collectedDbuses.empty()); cm.startAll(); - BOOST_CHECK(signalLatch.waitForN(TEST_DBUS_CONNECTION_CONTAINERS_COUNT, EVENT_TIMEOUT)); + BOOST_CHECK(signalLatch.waitForN(TEST_DBUS_CONNECTION_ZONES_COUNT, EVENT_TIMEOUT)); BOOST_CHECK(signalLatch.empty()); BOOST_CHECK(EXPECTED_DBUSES_STARTED == collectedDbuses); collectedDbuses.clear(); } - BOOST_CHECK(signalLatch.waitForN(TEST_DBUS_CONNECTION_CONTAINERS_COUNT, EVENT_TIMEOUT)); + BOOST_CHECK(signalLatch.waitForN(TEST_DBUS_CONNECTION_ZONES_COUNT, EVENT_TIMEOUT)); BOOST_CHECK(signalLatch.empty()); BOOST_CHECK(EXPECTED_DBUSES_STOPPED == collectedDbuses); } -BOOST_AUTO_TEST_CASE(GetContainerIdsTest) +BOOST_AUTO_TEST_CASE(GetZoneIdsTest) { - ContainersManager cm(TEST_DBUS_CONFIG_PATH); + ZonesManager cm(TEST_DBUS_CONFIG_PATH); DbusAccessory dbus(DbusAccessory::HOST_ID); - std::vector containerIds = {"ut-containers-manager-console1-dbus", - "ut-containers-manager-console2-dbus", - "ut-containers-manager-console3-dbus"}; - std::vector returnedIds = dbus.callMethodGetContainerIds(); + std::vector zoneIds = {"ut-zones-manager-console1-dbus", + "ut-zones-manager-console2-dbus", + "ut-zones-manager-console3-dbus"}; + std::vector returnedIds = dbus.callMethodGetZoneIds(); BOOST_CHECK(std::is_permutation(returnedIds.begin(), returnedIds.end(), - containerIds.begin())); + zoneIds.begin())); } -BOOST_AUTO_TEST_CASE(GetActiveContainerIdTest) +BOOST_AUTO_TEST_CASE(GetActiveZoneIdTest) { - ContainersManager cm(TEST_DBUS_CONFIG_PATH); + ZonesManager cm(TEST_DBUS_CONFIG_PATH); cm.startAll(); DbusAccessory dbus(DbusAccessory::HOST_ID); - std::vector containerIds = {"ut-containers-manager-console1-dbus", - "ut-containers-manager-console2-dbus", - "ut-containers-manager-console3-dbus"}; + std::vector zoneIds = {"ut-zones-manager-console1-dbus", + "ut-zones-manager-console2-dbus", + "ut-zones-manager-console3-dbus"}; - for (std::string& containerId: containerIds){ - cm.focus(containerId); - BOOST_CHECK(dbus.callMethodGetActiveContainerId() == containerId); + for (std::string& zoneId: zoneIds){ + cm.focus(zoneId); + BOOST_CHECK(dbus.callMethodGetActiveZoneId() == zoneId); } cm.stopAll(); - BOOST_CHECK(dbus.callMethodGetActiveContainerId() == ""); + BOOST_CHECK(dbus.callMethodGetActiveZoneId() == ""); } -BOOST_AUTO_TEST_CASE(SetActiveContainerTest) +BOOST_AUTO_TEST_CASE(SetActiveZoneTest) { - ContainersManager cm(TEST_DBUS_CONFIG_PATH); + ZonesManager cm(TEST_DBUS_CONFIG_PATH); cm.startAll(); DbusAccessory dbus(DbusAccessory::HOST_ID); - std::vector containerIds = {"ut-containers-manager-console1-dbus", - "ut-containers-manager-console2-dbus", - "ut-containers-manager-console3-dbus"}; + std::vector zoneIds = {"ut-zones-manager-console1-dbus", + "ut-zones-manager-console2-dbus", + "ut-zones-manager-console3-dbus"}; - for (std::string& containerId: containerIds){ - dbus.callMethodSetActiveContainer(containerId); - BOOST_CHECK(dbus.callMethodGetActiveContainerId() == containerId); + for (std::string& zoneId: zoneIds){ + dbus.callMethodSetActiveZone(zoneId); + BOOST_CHECK(dbus.callMethodGetActiveZoneId() == zoneId); } - BOOST_REQUIRE_THROW(dbus.callMethodSetActiveContainer(NON_EXISTANT_CONTAINER_ID), + BOOST_REQUIRE_THROW(dbus.callMethodSetActiveZone(NON_EXISTANT_ZONE_ID), DbusException); cm.stopAll(); - BOOST_REQUIRE_THROW(dbus.callMethodSetActiveContainer("ut-containers-manager-console1-dbus"), + BOOST_REQUIRE_THROW(dbus.callMethodSetActiveZone("ut-zones-manager-console1-dbus"), DbusException); } -BOOST_AUTO_TEST_CASE(CreateDestroyContainerTest) +BOOST_AUTO_TEST_CASE(CreateDestroyZoneTest) { - const std::string container1 = "test1"; - const std::string container2 = "test2"; - const std::string container3 = "test3"; + const std::string zone1 = "test1"; + const std::string zone2 = "test2"; + const std::string zone3 = "test3"; - ContainersManager cm(EMPTY_DBUS_CONFIG_PATH); + ZonesManager cm(EMPTY_DBUS_CONFIG_PATH); cm.startAll(); - BOOST_CHECK_EQUAL(cm.getRunningForegroundContainerId(), ""); + BOOST_CHECK_EQUAL(cm.getRunningForegroundZoneId(), ""); Latch callDone; auto resultCallback = [&]() { @@ -1061,54 +1061,54 @@ BOOST_AUTO_TEST_CASE(CreateDestroyContainerTest) DbusAccessory dbus(DbusAccessory::HOST_ID); - // create container1 - dbus.callAsyncMethodCreateContainer(container1, resultCallback); + // create zone1 + dbus.callAsyncMethodCreateZone(zone1, resultCallback); BOOST_REQUIRE(callDone.wait(EVENT_TIMEOUT)); - BOOST_CHECK_EQUAL(cm.getRunningForegroundContainerId(), container1); + BOOST_CHECK_EQUAL(cm.getRunningForegroundZoneId(), zone1); - // create container2 - dbus.callAsyncMethodCreateContainer(container2, resultCallback); + // create zone2 + dbus.callAsyncMethodCreateZone(zone2, resultCallback); BOOST_REQUIRE(callDone.wait(EVENT_TIMEOUT)); - BOOST_CHECK_EQUAL(cm.getRunningForegroundContainerId(), container2); //TODO is this valid? + BOOST_CHECK_EQUAL(cm.getRunningForegroundZoneId(), zone2); //TODO is this valid? - // create container3 - dbus.callAsyncMethodCreateContainer(container3, resultCallback); + // create zone3 + dbus.callAsyncMethodCreateZone(zone3, resultCallback); BOOST_REQUIRE(callDone.wait(EVENT_TIMEOUT)); - BOOST_CHECK_EQUAL(cm.getRunningForegroundContainerId(), container3); + BOOST_CHECK_EQUAL(cm.getRunningForegroundZoneId(), zone3); - // destroy container2 - dbus.callAsyncMethodDestroyContainer(container2, resultCallback); + // destroy zone2 + dbus.callAsyncMethodDestroyZone(zone2, resultCallback); BOOST_REQUIRE(callDone.wait(EVENT_TIMEOUT)); - BOOST_CHECK_EQUAL(cm.getRunningForegroundContainerId(), container3); + BOOST_CHECK_EQUAL(cm.getRunningForegroundZoneId(), zone3); - // destroy container3 - dbus.callAsyncMethodDestroyContainer(container3, resultCallback); + // destroy zone3 + dbus.callAsyncMethodDestroyZone(zone3, resultCallback); BOOST_REQUIRE(callDone.wait(EVENT_TIMEOUT)); - //BOOST_CHECK_EQUAL(cm.getRunningForegroundContainerId(), container1);//TODO fix it + //BOOST_CHECK_EQUAL(cm.getRunningForegroundZoneId(), zone1);//TODO fix it - // destroy container1 - dbus.callAsyncMethodDestroyContainer(container1, resultCallback); + // destroy zone1 + dbus.callAsyncMethodDestroyZone(zone1, resultCallback); BOOST_REQUIRE(callDone.wait(EVENT_TIMEOUT)); - BOOST_CHECK_EQUAL(cm.getRunningForegroundContainerId(), ""); + BOOST_CHECK_EQUAL(cm.getRunningForegroundZoneId(), ""); } BOOST_AUTO_TEST_CASE(DeclareFile) { - const std::string container = EXPECTED_DBUSES_NO_DBUS.begin()->first; - const std::string provisionConfigPath = getProvisionConfigPath(container); + const std::string zone = EXPECTED_DBUSES_NO_DBUS.begin()->first; + const std::string provisionConfigPath = getProvisionConfigPath(zone); - ContainersManager cm(TEST_CONFIG_PATH); + ZonesManager cm(TEST_CONFIG_PATH); DbusAccessory dbus(DbusAccessory::HOST_ID); - dbus.callMethodDeclareFile(container, 1, "path", 0747, 0777); - dbus.callMethodDeclareFile(container, 2, "path", 0747, 0777); + dbus.callMethodDeclareFile(zone, 1, "path", 0747, 0777); + dbus.callMethodDeclareFile(zone, 2, "path", 0747, 0777); - ContainerProvisioning config; + ZoneProvisioning config; BOOST_REQUIRE_NO_THROW(loadFromFile(provisionConfigPath, config)); BOOST_REQUIRE_EQUAL(config.units.size(), 2); - BOOST_REQUIRE(config.units[0].is()); - BOOST_REQUIRE(config.units[1].is()); - const ContainerProvisioning::File& unit = config.units[0].as(); + BOOST_REQUIRE(config.units[0].is()); + BOOST_REQUIRE(config.units[1].is()); + const ZoneProvisioning::File& unit = config.units[0].as(); BOOST_CHECK_EQUAL(unit.type, 1); BOOST_CHECK_EQUAL(unit.path, "path"); BOOST_CHECK_EQUAL(unit.flags, 0747); @@ -1117,20 +1117,20 @@ BOOST_AUTO_TEST_CASE(DeclareFile) BOOST_AUTO_TEST_CASE(DeclareMount) { - const std::string container = EXPECTED_DBUSES_NO_DBUS.begin()->first; - const std::string provisionConfigPath = getProvisionConfigPath(container); + const std::string zone = EXPECTED_DBUSES_NO_DBUS.begin()->first; + const std::string provisionConfigPath = getProvisionConfigPath(zone); - ContainersManager cm(TEST_CONFIG_PATH); + ZonesManager cm(TEST_CONFIG_PATH); DbusAccessory dbus(DbusAccessory::HOST_ID); - dbus.callMethodDeclareMount("/fake/path1", container, "/fake/path2", "tmpfs", 077, "fake"); - dbus.callMethodDeclareMount("/fake/path2", container, "/fake/path2", "tmpfs", 077, "fake"); + dbus.callMethodDeclareMount("/fake/path1", zone, "/fake/path2", "tmpfs", 077, "fake"); + dbus.callMethodDeclareMount("/fake/path2", zone, "/fake/path2", "tmpfs", 077, "fake"); - ContainerProvisioning config; + ZoneProvisioning config; BOOST_REQUIRE_NO_THROW(loadFromFile(provisionConfigPath, config)); BOOST_REQUIRE_EQUAL(config.units.size(), 2); - BOOST_REQUIRE(config.units[0].is()); - BOOST_REQUIRE(config.units[1].is()); - const ContainerProvisioning::Mount& unit = config.units[0].as(); + BOOST_REQUIRE(config.units[0].is()); + BOOST_REQUIRE(config.units[1].is()); + const ZoneProvisioning::Mount& unit = config.units[0].as(); BOOST_CHECK_EQUAL(unit.source, "/fake/path1"); BOOST_CHECK_EQUAL(unit.target, "/fake/path2"); BOOST_CHECK_EQUAL(unit.type, "tmpfs"); @@ -1140,51 +1140,51 @@ BOOST_AUTO_TEST_CASE(DeclareMount) BOOST_AUTO_TEST_CASE(DeclareLink) { - const std::string container = EXPECTED_DBUSES_NO_DBUS.begin()->first; - const std::string provisionConfigPath = getProvisionConfigPath(container); + const std::string zone = EXPECTED_DBUSES_NO_DBUS.begin()->first; + const std::string provisionConfigPath = getProvisionConfigPath(zone); - ContainersManager cm(TEST_CONFIG_PATH); + ZonesManager cm(TEST_CONFIG_PATH); DbusAccessory dbus(DbusAccessory::HOST_ID); - dbus.callMethodDeclareLink("/fake/path1", container, "/fake/path2"); - dbus.callMethodDeclareLink("/fake/path2", container, "/fake/path2"); + dbus.callMethodDeclareLink("/fake/path1", zone, "/fake/path2"); + dbus.callMethodDeclareLink("/fake/path2", zone, "/fake/path2"); - ContainerProvisioning config; + ZoneProvisioning config; BOOST_REQUIRE_NO_THROW(loadFromFile(provisionConfigPath, config)); BOOST_REQUIRE_EQUAL(config.units.size(), 2); - BOOST_REQUIRE(config.units[0].is()); - BOOST_REQUIRE(config.units[1].is()); - const ContainerProvisioning::Link& unit = config.units[0].as(); + BOOST_REQUIRE(config.units[0].is()); + BOOST_REQUIRE(config.units[1].is()); + const ZoneProvisioning::Link& unit = config.units[0].as(); BOOST_CHECK_EQUAL(unit.source, "/fake/path1"); BOOST_CHECK_EQUAL(unit.target, "/fake/path2"); } -BOOST_AUTO_TEST_CASE(LockUnlockContainerTest) +BOOST_AUTO_TEST_CASE(LockUnlockZoneTest) { - ContainersManager cm(TEST_DBUS_CONFIG_PATH); + ZonesManager cm(TEST_DBUS_CONFIG_PATH); cm.startAll(); DbusAccessory dbus(DbusAccessory::HOST_ID); - std::vector containerIds = {"ut-containers-manager-console1-dbus", - "ut-containers-manager-console2-dbus", - "ut-containers-manager-console3-dbus"}; + std::vector zoneIds = {"ut-zones-manager-console1-dbus", + "ut-zones-manager-console2-dbus", + "ut-zones-manager-console3-dbus"}; - for (std::string& containerId: containerIds){ - dbus.callMethodLockContainer(containerId); - BOOST_CHECK(cm.isPaused(containerId)); - dbus.callMethodUnlockContainer(containerId); - BOOST_CHECK(cm.isRunning(containerId)); + for (std::string& zoneId: zoneIds){ + dbus.callMethodLockZone(zoneId); + BOOST_CHECK(cm.isPaused(zoneId)); + dbus.callMethodUnlockZone(zoneId); + BOOST_CHECK(cm.isRunning(zoneId)); } - BOOST_REQUIRE_THROW(dbus.callMethodLockContainer(NON_EXISTANT_CONTAINER_ID), + BOOST_REQUIRE_THROW(dbus.callMethodLockZone(NON_EXISTANT_ZONE_ID), DbusException); - BOOST_REQUIRE_THROW(dbus.callMethodUnlockContainer(NON_EXISTANT_CONTAINER_ID), + BOOST_REQUIRE_THROW(dbus.callMethodUnlockZone(NON_EXISTANT_ZONE_ID), DbusException); cm.stopAll(); - BOOST_REQUIRE_THROW(dbus.callMethodLockContainer("ut-containers-manager-console1-dbus"), + BOOST_REQUIRE_THROW(dbus.callMethodLockZone("ut-zones-manager-console1-dbus"), DbusException); - BOOST_REQUIRE_THROW(dbus.callMethodUnlockContainer("ut-containers-manager-console1-dbus"), + BOOST_REQUIRE_THROW(dbus.callMethodUnlockZone("ut-zones-manager-console1-dbus"), DbusException); } diff --git a/container-daemon/CMakeLists.txt b/zone-daemon/CMakeLists.txt similarity index 65% rename from container-daemon/CMakeLists.txt rename to zone-daemon/CMakeLists.txt index d702c8e..3fd611f 100644 --- a/container-daemon/CMakeLists.txt +++ b/zone-daemon/CMakeLists.txt @@ -18,32 +18,32 @@ # MESSAGE(STATUS "") -MESSAGE(STATUS "Generating makefile for the Container Daemon...") +MESSAGE(STATUS "Generating makefile for the Zone Daemon...") FILE(GLOB project_SRCS *.cpp *.hpp) FILE(GLOB common_SRCS ${COMMON_FOLDER}/dbus/*.cpp ${COMMON_FOLDER}/dbus/*.hpp ${COMMON_FOLDER}/log/*.cpp ${COMMON_FOLDER}/log/*.hpp ${COMMON_FOLDER}/utils/*.cpp ${COMMON_FOLDER}/utils/*.hpp) ## Setup target ################################################################ -SET(CONTAINER_DAEMON_CODENAME "${PROJECT_NAME}-container-daemon") -ADD_EXECUTABLE(${CONTAINER_DAEMON_CODENAME} ${project_SRCS} ${common_SRCS}) +SET(ZONE_DAEMON_CODENAME "${PROJECT_NAME}-zone-daemon") +ADD_EXECUTABLE(${ZONE_DAEMON_CODENAME} ${project_SRCS} ${common_SRCS}) ## Link libraries ############################################################## FIND_PACKAGE (Boost COMPONENTS program_options system filesystem) -PKG_CHECK_MODULES(CONTAINER_DAEMON_DEPS REQUIRED gio-2.0 libsystemd-journal libcap-ng +PKG_CHECK_MODULES(ZONE_DAEMON_DEPS REQUIRED gio-2.0 libsystemd-journal libcap-ng libLogger libSimpleDbus libConfig) INCLUDE_DIRECTORIES(${COMMON_FOLDER}) -INCLUDE_DIRECTORIES(SYSTEM ${CONTAINER_DAEMON_DEPS_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS}) -TARGET_LINK_LIBRARIES(${CONTAINER_DAEMON_CODENAME} ${CONTAINER_DAEMON_DEPS_LIBRARIES} ${Boost_LIBRARIES}) +INCLUDE_DIRECTORIES(SYSTEM ${ZONE_DAEMON_DEPS_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS}) +TARGET_LINK_LIBRARIES(${ZONE_DAEMON_CODENAME} ${ZONE_DAEMON_DEPS_LIBRARIES} ${Boost_LIBRARIES}) ## Install ##################################################################### -INSTALL(TARGETS ${CONTAINER_DAEMON_CODENAME} DESTINATION bin) +INSTALL(TARGETS ${ZONE_DAEMON_CODENAME} DESTINATION bin) -CONFIGURE_FILE(configs/org.tizen.containers.zone.daemon.conf.in - ${CMAKE_BINARY_DIR}/configs/org.tizen.containers.zone.daemon.conf) +CONFIGURE_FILE(configs/org.tizen.vasum.zone.daemon.conf.in + ${CMAKE_BINARY_DIR}/configs/org.tizen.vasum.zone.daemon.conf) -INSTALL(FILES ${CMAKE_BINARY_DIR}/configs/org.tizen.containers.zone.daemon.conf +INSTALL(FILES ${CMAKE_BINARY_DIR}/configs/org.tizen.vasum.zone.daemon.conf DESTINATION /etc/dbus-1/system.d/) diff --git a/zone-daemon/configs/org.tizen.vasum.zone.daemon.conf.in b/zone-daemon/configs/org.tizen.vasum.zone.daemon.conf.in new file mode 100644 index 0000000..7b24276 --- /dev/null +++ b/zone-daemon/configs/org.tizen.vasum.zone.daemon.conf.in @@ -0,0 +1,14 @@ + + + + + + + + + + + + + diff --git a/container-daemon/daemon-connection.cpp b/zone-daemon/daemon-connection.cpp similarity index 88% rename from container-daemon/daemon-connection.cpp rename to zone-daemon/daemon-connection.cpp index be171e1..94a84a8 100644 --- a/container-daemon/daemon-connection.cpp +++ b/zone-daemon/daemon-connection.cpp @@ -19,7 +19,7 @@ /** * @file * @author Jan Olszak (j.olszak@samsung.com) - * @brief Dbus API for the Container Daemon + * @brief Dbus API for the Zone Daemon */ #include "config.hpp" @@ -32,7 +32,7 @@ namespace vasum { -namespace container_daemon { +namespace zone_daemon { namespace { @@ -53,13 +53,13 @@ DaemonConnection::DaemonConnection(const NameLostCallback& nameLostCallback, mDbusConnection = dbus::DbusConnection::createSystem(); LOGD("Setting DBUS name"); - mDbusConnection->setName(container_daemon::api::BUS_NAME, + mDbusConnection->setName(zone_daemon::api::BUS_NAME, std::bind(&DaemonConnection::onNameAcquired, this), std::bind(&DaemonConnection::onNameLost, this)); if (!waitForNameAndSetCallback(NAME_ACQUIRED_TIMEOUT, nameLostCallback)) { - LOGE("Could not acquire dbus name: " << container_daemon::api::BUS_NAME); - throw ContainerDaemonException("Could not acquire dbus name: " + container_daemon::api::BUS_NAME); + LOGE("Could not acquire dbus name: " << zone_daemon::api::BUS_NAME); + throw ZoneDaemonException("Could not acquire dbus name: " + zone_daemon::api::BUS_NAME); } LOGD("Setting callbacks"); @@ -69,8 +69,8 @@ DaemonConnection::DaemonConnection(const NameLostCallback& nameLostCallback, LOGD("Registering DBUS interface"); using namespace std::placeholders; - mDbusConnection->registerObject(container_daemon::api::OBJECT_PATH, - container_daemon::api::DEFINITION, + mDbusConnection->registerObject(zone_daemon::api::OBJECT_PATH, + zone_daemon::api::DEFINITION, std::bind(&DaemonConnection::onMessageCall, this, _1, _2, _3, _4, _5)); LOGD("Connected"); @@ -138,5 +138,5 @@ void DaemonConnection::onMessageCall(const std::string& objectPath, } } -} // namespace container_daemon +} // namespace zone_daemon } // namespace vasum diff --git a/container-daemon/daemon-connection.hpp b/zone-daemon/daemon-connection.hpp similarity index 87% rename from container-daemon/daemon-connection.hpp rename to zone-daemon/daemon-connection.hpp index 8b39f02..7ac7012 100644 --- a/container-daemon/daemon-connection.hpp +++ b/zone-daemon/daemon-connection.hpp @@ -19,12 +19,12 @@ /** * @file * @author Jan Olszak (j.olszak@samsung.com) - * @brief Declaration of a class for communication between container and server + * @brief Declaration of a class for communication between zone and server */ -#ifndef CONTAINER_DAEMON_DAEMON_CONNECTION_HPP -#define CONTAINER_DAEMON_DAEMON_CONNECTION_HPP +#ifndef ZONE_DAEMON_DAEMON_CONNECTION_HPP +#define ZONE_DAEMON_DAEMON_CONNECTION_HPP #include "dbus/connection.hpp" @@ -33,7 +33,7 @@ namespace vasum { -namespace container_daemon { +namespace zone_daemon { class DaemonConnection { @@ -72,8 +72,8 @@ private: }; -} // namespace container_daemon +} // namespace zone_daemon } // namespace vasum -#endif // CONTAINER_DAEMON_DAEMON_CONNECTION_HPP +#endif // ZONE_DAEMON_DAEMON_CONNECTION_HPP diff --git a/container-daemon/daemon-dbus-definitions.hpp b/zone-daemon/daemon-dbus-definitions.hpp similarity index 71% rename from container-daemon/daemon-dbus-definitions.hpp rename to zone-daemon/daemon-dbus-definitions.hpp index 057abeb..96c88b4 100644 --- a/container-daemon/daemon-dbus-definitions.hpp +++ b/zone-daemon/daemon-dbus-definitions.hpp @@ -19,22 +19,22 @@ /** * @file * @author Jan Olszak (j.olszak@samsung.com) - * @brief container-daemon dbus api definitions + * @brief zone-daemon dbus api definitions */ -#ifndef CONTAINER_DAEMON_DAEMON_DBUS_DEFINITIONS_HPP -#define CONTAINER_DAEMON_DAEMON_DBUS_DEFINITIONS_HPP +#ifndef ZONE_DAEMON_DAEMON_DBUS_DEFINITIONS_HPP +#define ZONE_DAEMON_DAEMON_DBUS_DEFINITIONS_HPP #include namespace vasum { -namespace container_daemon { +namespace zone_daemon { namespace api { -const std::string BUS_NAME = "org.tizen.containers.zone.daemon"; -const std::string OBJECT_PATH = "/org/tizen/containers/zone/daemon"; -const std::string INTERFACE = "org.tizen.containers.zone.daemon"; +const std::string BUS_NAME = "org.tizen.vasum.zone.daemon"; +const std::string OBJECT_PATH = "/org/tizen/vasum/zone/daemon"; +const std::string INTERFACE = "org.tizen.vasum.zone.daemon"; const std::string METHOD_GAIN_FOCUS = "GainFocus"; const std::string METHOD_LOSE_FOCUS = "LoseFocus"; @@ -51,8 +51,8 @@ const std::string DEFINITION = } // namespace api -} // namespace container_daemon +} // namespace zone_daemon } // namespace vasum -#endif // CONTAINER_DAEMON_DAEMON_DBUS_DEFINITIONS_HPP +#endif // ZONE_DAEMON_DAEMON_DBUS_DEFINITIONS_HPP diff --git a/container-daemon/daemon.cpp b/zone-daemon/daemon.cpp similarity index 96% rename from container-daemon/daemon.cpp rename to zone-daemon/daemon.cpp index 3955140..0ded40a 100644 --- a/container-daemon/daemon.cpp +++ b/zone-daemon/daemon.cpp @@ -30,7 +30,7 @@ namespace vasum { -namespace container_daemon { +namespace zone_daemon { Daemon::Daemon() @@ -62,5 +62,5 @@ void Daemon::onLoseFocusCallback() } -} // namespace container_daemon +} // namespace zone_daemon } // namespace vasum diff --git a/container-daemon/daemon.hpp b/zone-daemon/daemon.hpp similarity index 87% rename from container-daemon/daemon.hpp rename to zone-daemon/daemon.hpp index 0821e70..92dcccf 100644 --- a/container-daemon/daemon.hpp +++ b/zone-daemon/daemon.hpp @@ -23,8 +23,8 @@ */ -#ifndef CONTAINER_DAEMON_DAEMON_HPP -#define CONTAINER_DAEMON_DAEMON_HPP +#ifndef ZONE_DAEMON_DAEMON_HPP +#define ZONE_DAEMON_DAEMON_HPP #include "daemon-connection.hpp" @@ -32,7 +32,7 @@ namespace vasum { -namespace container_daemon { +namespace zone_daemon { class Daemon { public: @@ -47,8 +47,8 @@ private: }; -} // namespace container_daemon +} // namespace zone_daemon } // namespace vasum -#endif // CONTAINER_DAEMON_DAEMON_HPP +#endif // ZONE_DAEMON_DAEMON_HPP diff --git a/container-daemon/exception.hpp b/zone-daemon/exception.hpp similarity index 66% rename from container-daemon/exception.hpp rename to zone-daemon/exception.hpp index 011b189..a281910 100644 --- a/container-daemon/exception.hpp +++ b/zone-daemon/exception.hpp @@ -19,30 +19,30 @@ /** * @file * @author Jan Olszak (j.olszak@samsung.com) - * @brief Exceptions for the container-daemon + * @brief Exceptions for the zone-daemon */ -#ifndef CONTAINER_DAEMON_EXCEPTION_HPP -#define CONTAINER_DAEMON_EXCEPTION_HPP +#ifndef ZONE_DAEMON_EXCEPTION_HPP +#define ZONE_DAEMON_EXCEPTION_HPP #include "base-exception.hpp" namespace vasum { -namespace container_daemon { +namespace zone_daemon { /** - * Base class for exceptions in Vasum Container Daemon + * Base class for exceptions in Vasum Zone Daemon */ -struct ContainerDaemonException: public VasumException { +struct ZoneDaemonException: public VasumException { - ContainerDaemonException(const std::string& error = "") : VasumException(error) {} + ZoneDaemonException(const std::string& error = "") : VasumException(error) {} }; -} // container_daemon +} // zone_daemon } // vasum -#endif // CONTAINER_DAEMON_EXCEPTION_HPP +#endif // ZONE_DAEMON_EXCEPTION_HPP diff --git a/container-daemon/main.cpp b/zone-daemon/main.cpp similarity index 97% rename from container-daemon/main.cpp rename to zone-daemon/main.cpp index 0a8a2b9..846f431 100644 --- a/container-daemon/main.cpp +++ b/zone-daemon/main.cpp @@ -50,7 +50,7 @@ namespace po = boost::program_options; namespace { const std::string PROGRAM_NAME_AND_VERSION = - "Vasum Containers Daemon " PROGRAM_VERSION; + "Vasum Zones Daemon " PROGRAM_VERSION; } // namespace @@ -113,7 +113,7 @@ int main(int argc, char* argv[]) } try { - container_daemon::Runner daemon; + zone_daemon::Runner daemon; daemon.run(); } catch (std::exception& e) { diff --git a/container-daemon/runner.cpp b/zone-daemon/runner.cpp similarity index 85% rename from container-daemon/runner.cpp rename to zone-daemon/runner.cpp index dfa73c1..8d00361 100644 --- a/container-daemon/runner.cpp +++ b/zone-daemon/runner.cpp @@ -35,7 +35,7 @@ namespace vasum { -namespace container_daemon { +namespace zone_daemon { Runner::Runner() @@ -64,17 +64,17 @@ void Runner::run() signal(SIGINT, signalHandler); signal(SIGTERM, signalHandler); - LOGI("Starting Container Daemon..."); + LOGI("Starting Zone Daemon..."); { utils::ScopedGlibLoop loop; - LOGI("Container Daemon started"); + LOGI("Zone Daemon started"); // Connects to dbus and registers API - container_daemon::Daemon daemon; + zone_daemon::Daemon daemon; gSignalLatch.wait(); - LOGI("Stopping Container Daemon..."); + LOGI("Stopping Zone Daemon..."); } LOGI("Daemon stopped"); @@ -82,9 +82,9 @@ void Runner::run() void Runner::terminate() { - LOGI("Terminating Container Daemon"); + LOGI("Terminating Zone Daemon"); gSignalLatch.set(); } -} // namespace container_daemon +} // namespace zone_daemon } // namespace vasum diff --git a/container-daemon/runner.hpp b/zone-daemon/runner.hpp similarity index 87% rename from container-daemon/runner.hpp rename to zone-daemon/runner.hpp index e68fa0f..1a88530 100644 --- a/container-daemon/runner.hpp +++ b/zone-daemon/runner.hpp @@ -23,12 +23,12 @@ */ -#ifndef CONTAINER_DAEMON_RUNNER_HPP -#define CONTAINER_DAEMON_RUNNER_HPP +#ifndef ZONE_DAEMON_RUNNER_HPP +#define ZONE_DAEMON_RUNNER_HPP namespace vasum { -namespace container_daemon { +namespace zone_daemon { class Runner { @@ -49,8 +49,8 @@ public: }; -} // namespace container_daemon +} // namespace zone_daemon } // namespace vasum -#endif // CONTAINER_DAEMON_RUNNER_HPP +#endif // ZONE_DAEMON_RUNNER_HPP diff --git a/container-support/CMakeLists.txt b/zone-support/CMakeLists.txt similarity index 80% rename from container-support/CMakeLists.txt rename to zone-support/CMakeLists.txt index 79bdb9c..bee0fbd 100644 --- a/container-support/CMakeLists.txt +++ b/zone-support/CMakeLists.txt @@ -18,13 +18,13 @@ # MESSAGE(STATUS "") -MESSAGE(STATUS "Generating makefile for the Container Support...") +MESSAGE(STATUS "Generating makefile for the Zone Support...") ## Install ##################################################################### -CONFIGURE_FILE(configs/org.tizen.containers.zone.conf.in - ${CMAKE_BINARY_DIR}/dbus-1/system.d/org.tizen.containers.zone.conf) +CONFIGURE_FILE(configs/org.tizen.vasum.zone.conf.in + ${CMAKE_BINARY_DIR}/dbus-1/system.d/org.tizen.vasum.zone.conf) -INSTALL(FILES ${CMAKE_BINARY_DIR}/dbus-1/system.d/org.tizen.containers.zone.conf +INSTALL(FILES ${CMAKE_BINARY_DIR}/dbus-1/system.d/org.tizen.vasum.zone.conf DESTINATION /etc/dbus-1/system.d/) diff --git a/zone-support/configs/org.tizen.vasum.zone.conf.in b/zone-support/configs/org.tizen.vasum.zone.conf.in new file mode 100644 index 0000000..fdf0305 --- /dev/null +++ b/zone-support/configs/org.tizen.vasum.zone.conf.in @@ -0,0 +1,14 @@ + + + + + + + + + + + + + -- 2.7.4 From 3f45df61e5ce5424cf75db24d0f8798594dfc4b0 Mon Sep 17 00:00:00 2001 From: Piotr Bartosiewicz Date: Tue, 9 Dec 2014 15:23:54 +0100 Subject: [PATCH 08/16] CMake options for fsanitize and additional warnings [Bug/Feature] N/A [Cause] N/A [Solution] N/A [Verification] Build, install, run tests Change-Id: I7d54cec67d9d15c750a7108bd9d24a508be0d103 --- CMakeLists.txt | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 588f066..34573cc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,6 +51,20 @@ SET(CMAKE_CXX_FLAGS_RELEASE "-g -std=${CXX_11_STD} -O2 -DNDEBUG") SET(CMAKE_C_FLAGS_CCOV "-g -O2 --coverage") SET(CMAKE_CXX_FLAGS_CCOV "-g -std=${CXX_11_STD} -O2 --coverage") +IF(DEFINED SANITIZE) + # Enable sanitize build. + # It works with clang and gcc>=4.8 + # Possible arguments: address, thread and others (see doc.) + # Note on thread sanitizer bugs left in out code: + # - we use non thread save boost test library + # - there are some mysterious problems with glib + SET(SANITIZE_FLAGS "-fsanitize=${SANITIZE}") + MESSAGE(STATUS "Sanitize flags: ${SANITIZE_FLAGS}") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SANITIZE_FLAGS} -fPIE -fno-omit-frame-pointer") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SANITIZE_FLAGS} -fPIE -fno-omit-frame-pointer") + SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie ${SANITIZE_FLAGS}") +ENDIF(DEFINED SANITIZE) + ADD_DEFINITIONS("-fPIC") # Position Independent Code ADD_DEFINITIONS("-Werror") # Make all warnings into errors ADD_DEFINITIONS("-Wall") # Generate all warnings @@ -60,6 +74,24 @@ ADD_DEFINITIONS("-pedantic-errors") # Make pedantic warnings into errors ADD_DEFINITIONS(-DPROGRAM_VERSION="${VERSION}") ADD_DEFINITIONS(-DPROJECT_SOURCE_DIR="${PROJECT_SOURCE_DIR}") +IF("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + # Warn about documentation problems + ADD_DEFINITIONS("-Wdocumentation") + ADD_DEFINITIONS("-Wno-error=documentation") + + IF(ALL_WARNINGS) + # turn on every -W flags except a few explicitly mentioned + ADD_DEFINITIONS("-Wno-error") + ADD_DEFINITIONS("-Weverything") + ADD_DEFINITIONS("-Wno-c++98-compat") + ADD_DEFINITIONS("-Wno-c++98-compat-pedantic") + ADD_DEFINITIONS("-Wno-padded") + ADD_DEFINITIONS("-Wno-global-constructors") + ADD_DEFINITIONS("-Wno-exit-time-destructors") + ADD_DEFINITIONS("-Wno-weak-vtables") + ENDIF(ALL_WARNINGS) +ENDIF() + IF(NOT DEFINED VASUM_USER) SET(VASUM_USER "security-containers") ENDIF(NOT DEFINED VASUM_USER) -- 2.7.4 From d8fedce7b248e5d57038882889354c617a08ab85 Mon Sep 17 00:00:00 2001 From: Piotr Bartosiewicz Date: Tue, 9 Dec 2014 17:08:00 +0100 Subject: [PATCH 09/16] Fix doxy comments and some other warnings [Bug/Feature] N/A [Cause] N/A [Solution] N/A [Verification] Build Change-Id: I5cff5b198d533ec256d551d9e8280a5c117e06d4 --- CMakeLists.txt | 1 - cli/main.cpp | 4 ++++ client/utils.cpp | 4 ++-- client/vasum-client-impl.cpp | 2 +- client/vasum-client.h | 4 ++-- common/ipc/client.hpp | 6 +++--- common/ipc/internals/event-queue.hpp | 8 ++++---- common/ipc/internals/processor.cpp | 2 -- common/ipc/service.hpp | 4 ++-- common/utils/initctl.cpp | 2 +- server/zones-manager.cpp | 6 +++--- tests/unit_tests/client/ut-client.cpp | 8 ++++---- tests/unit_tests/server/ut-zones-manager.cpp | 2 +- 13 files changed, 27 insertions(+), 26 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 34573cc..cd999d7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -77,7 +77,6 @@ ADD_DEFINITIONS(-DPROJECT_SOURCE_DIR="${PROJECT_SOURCE_DIR}") IF("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") # Warn about documentation problems ADD_DEFINITIONS("-Wdocumentation") - ADD_DEFINITIONS("-Wno-error=documentation") IF(ALL_WARNINGS) # turn on every -W flags except a few explicitly mentioned diff --git a/cli/main.cpp b/cli/main.cpp index e837d86..448d32d 100644 --- a/cli/main.cpp +++ b/cli/main.cpp @@ -32,6 +32,8 @@ using namespace vasum::cli; +namespace { + std::map commands = { { "set_active_zone", { @@ -93,6 +95,8 @@ void printUsage(std::ostream& out, const std::string& name) } } +} // namespace + int main(const int argc, const char** argv) { if (argc < 2) { diff --git a/client/utils.cpp b/client/utils.cpp index a5ff48e..305b848 100644 --- a/client/utils.cpp +++ b/client/utils.cpp @@ -87,8 +87,8 @@ void unescape(std::string& value) if (c == '-') { value[outPos++] = '/'; } else if (c == '\\' && value[inPos] == 'x') { - const char a = unhex(value[inPos+1]); - const char b = unhex(value[inPos+2]); + const int a = unhex(value[inPos+1]); + const int b = unhex(value[inPos+2]); value[outPos++] = (char) ((a << 4) | b); inPos += 3; } else { diff --git a/client/vasum-client-impl.cpp b/client/vasum-client-impl.cpp index c16c9d2..41898c7 100644 --- a/client/vasum-client-impl.cpp +++ b/client/vasum-client-impl.cpp @@ -113,7 +113,7 @@ VsmZoneState getZoneState(const char* state) } else if (strcmp(state, "ACTIVATING") == 0) { return ACTIVATING; } - assert(!"UNKNOWN STATE"); + assert(0 && "UNKNOWN STATE"); return (VsmZoneState)-1; } diff --git a/client/vasum-client.h b/client/vasum-client.h index 3e1f66d..eb4cbba 100644 --- a/client/vasum-client.h +++ b/client/vasum-client.h @@ -390,7 +390,7 @@ VsmStatus vsm_create_zone(VsmClient client, const char* id, const char* tname); * @param[in] force if 0 data will be kept, otherwise data will be lost * @return status of this function call */ -VsmStatus vsm_destroy_zone(VsmClient clent, const char* id, int force); +VsmStatus vsm_destroy_zone(VsmClient client, const char* id, int force); /** * Shutdown zone @@ -624,7 +624,7 @@ VsmStatus vsm_declare_file(VsmClient client, * @param[in] target mount point (path in zone) * @param[in] type filesystem type * @param[in] flags mount flags as in mount function - * @patam[in] data additional data as in mount function + * @param[in] data additional data as in mount function * @return status of this function call */ VsmStatus vsm_declare_mount(VsmClient client, diff --git a/common/ipc/client.hpp b/common/ipc/client.hpp index 5233e29..5751812 100644 --- a/common/ipc/client.hpp +++ b/common/ipc/client.hpp @@ -89,7 +89,7 @@ public: * the data will be parsed and passed to this callback. * * @param methodID API dependent id of the method - * @param methodCallback method handling implementation + * @param method method handling implementation */ template void addMethodHandler(const MethodID methodID, @@ -101,7 +101,7 @@ public: * the data will be parsed and passed to this callback. * * @param methodID API dependent id of the method - * @param SignalHandler signal handling implementation + * @param signal signal handling implementation * @tparam ReceivedDataType data type to serialize */ template @@ -134,7 +134,7 @@ public: * * * @param methodID API dependent id of the method - * @param sendCallback callback for data serialization + * @param data data to send * @param resultCallback callback for result serialization and handling */ template diff --git a/common/ipc/internals/event-queue.hpp b/common/ipc/internals/event-queue.hpp index 74a4923..2c591f7 100644 --- a/common/ipc/internals/event-queue.hpp +++ b/common/ipc/internals/event-queue.hpp @@ -57,14 +57,14 @@ public: int getFD() const; /** - * Send an event of a given value + * Send an event * - * @param value size of the buffer + * @param message mesage to send */ - void send(const MessageType& mess); + void send(const MessageType& message); /** - * Receives the signal. + * Receives the event. * Blocks if there is no event. * * @return event's value diff --git a/common/ipc/internals/processor.cpp b/common/ipc/internals/processor.cpp index aa21675..be1060d 100644 --- a/common/ipc/internals/processor.cpp +++ b/common/ipc/internals/processor.cpp @@ -340,8 +340,6 @@ bool Processor::handleInput(const Socket& socket) } } } - - return false; } std::shared_ptr Processor::onNewSignals(const FileDescriptor peerFD, diff --git a/common/ipc/service.hpp b/common/ipc/service.hpp index 5038398..1f9aee3 100644 --- a/common/ipc/service.hpp +++ b/common/ipc/service.hpp @@ -94,7 +94,7 @@ public: * the data will be parsed and passed to this callback. * * @param methodID API dependent id of the method - * @param methodCallback method handling implementation + * @param method method handling implementation */ template void addMethodHandler(const MethodID methodID, @@ -139,7 +139,7 @@ public: * * * @param methodID API dependent id of the method - * @param sendCallback callback for data serialization + * @param data data to send * @param resultCallback callback for result serialization and handling */ template diff --git a/common/utils/initctl.cpp b/common/utils/initctl.cpp index f4a778b..5986799 100644 --- a/common/utils/initctl.cpp +++ b/common/utils/initctl.cpp @@ -54,7 +54,7 @@ namespace { } return false; } - size -= r; + size -= static_cast(r); data = reinterpret_cast(data) + r; } return true; diff --git a/server/zones-manager.cpp b/server/zones-manager.cpp index 6744c30..981556b 100644 --- a/server/zones-manager.cpp +++ b/server/zones-manager.cpp @@ -593,7 +593,7 @@ void ZonesManager::handleDeclareFileCall(const std::string& zone, try { mZones.at(zone)->declareFile(type, path, flags, mode); result->setVoid(); - } catch (const std::out_of_range& ex) { + } catch (const std::out_of_range&) { LOGE("No zone with id=" << zone); result->setError(api::ERROR_INVALID_ID, "No such zone id"); } catch (const config::ConfigException& ex) { @@ -614,7 +614,7 @@ void ZonesManager::handleDeclareMountCall(const std::string& source, try { mZones.at(zone)->declareMount(source, target, type, flags, data); result->setVoid(); - } catch (const std::out_of_range& ex) { + } catch (const std::out_of_range&) { LOGE("No zone with id=" << zone); result->setError(api::ERROR_INVALID_ID, "No such zone id"); } catch (const config::ConfigException& ex) { @@ -632,7 +632,7 @@ void ZonesManager::handleDeclareLinkCall(const std::string& source, try { mZones.at(zone)->declareLink(source, target); result->setVoid(); - } catch (const std::out_of_range& ex) { + } catch (const std::out_of_range&) { LOGE("No zone with id=" << zone); result->setError(api::ERROR_INVALID_ID, "No such zone id"); } catch (const config::ConfigException& ex) { diff --git a/tests/unit_tests/client/ut-client.cpp b/tests/unit_tests/client/ut-client.cpp index e8060be..1e23e81 100644 --- a/tests/unit_tests/client/ut-client.cpp +++ b/tests/unit_tests/client/ut-client.cpp @@ -145,9 +145,9 @@ BOOST_AUTO_TEST_CASE(GetZoneDbusesTest) status = vsm_get_zone_dbuses(client, &keys, &values); BOOST_REQUIRE_EQUAL(VSMCLIENT_SUCCESS, status); - BOOST_CHECK_EQUAL(getArrayStringLength(keys, EXPECTED_DBUSES_STARTED.size() + 1), + BOOST_CHECK_EQUAL(getArrayStringLength(keys, EXPECTED_DBUSES_STARTED.size() + 1u), EXPECTED_DBUSES_STARTED.size()); - BOOST_CHECK_EQUAL(getArrayStringLength(values, EXPECTED_DBUSES_STARTED.size() + 1), + BOOST_CHECK_EQUAL(getArrayStringLength(values, EXPECTED_DBUSES_STARTED.size() + 1u), EXPECTED_DBUSES_STARTED.size()); std::map zones; @@ -166,7 +166,7 @@ BOOST_AUTO_TEST_CASE(GetZoneIdsTest) VsmArrayString values; status = vsm_get_zone_ids(client, &values); BOOST_REQUIRE_EQUAL(VSMCLIENT_SUCCESS, status); - BOOST_CHECK_EQUAL(getArrayStringLength(values, EXPECTED_DBUSES_STARTED.size() + 1), + BOOST_CHECK_EQUAL(getArrayStringLength(values, EXPECTED_DBUSES_STARTED.size() + 1u), EXPECTED_DBUSES_STARTED.size()); std::set zones; @@ -291,7 +291,7 @@ BOOST_AUTO_TEST_CASE(NotificationTest) BOOST_REQUIRE_EQUAL(VSMCLIENT_SUCCESS, status); } - BOOST_CHECK(callbackData.signalReceivedLatch.waitForN(clients.size() - 1, EVENT_TIMEOUT)); + BOOST_CHECK(callbackData.signalReceivedLatch.waitForN(clients.size() - 1u, EVENT_TIMEOUT)); BOOST_CHECK(callbackData.signalReceivedLatch.empty()); for (const auto& msg : callbackData.receivedSignalMsg) { diff --git a/tests/unit_tests/server/ut-zones-manager.cpp b/tests/unit_tests/server/ut-zones-manager.cpp index 33d7c50..07c03dd 100644 --- a/tests/unit_tests/server/ut-zones-manager.cpp +++ b/tests/unit_tests/server/ut-zones-manager.cpp @@ -620,7 +620,7 @@ BOOST_AUTO_TEST_CASE(NotifyActiveZoneTest) dbus.second->callMethodNotify(); } - BOOST_CHECK(signalReceivedLatch.waitForN(dbuses.size() - 1, EVENT_TIMEOUT)); + BOOST_CHECK(signalReceivedLatch.waitForN(dbuses.size() - 1u, EVENT_TIMEOUT)); BOOST_CHECK(signalReceivedLatch.empty()); //check if there are no signals that was received more than once -- 2.7.4 From 683b44bd6dc9cce82d8bba32e2988225ce52ddbe Mon Sep 17 00:00:00 2001 From: Mateusz Malicki Date: Wed, 10 Dec 2014 18:24:32 +0100 Subject: [PATCH 10/16] Support for boost version less then 1.54 -- disbale move in config union [Bug/Feature] Boost < 1.54 doesn't support rvalues in boost::any, better rvalues tests [Cause] ConfigUnionTest doesn't pass if compiled with boost 1.51 [Solution] Changes in libConfig; Disable moving in union [Verification] Build, install, run tests Change-Id: I3bb6af655fa9393bfab66d535705fa252ecf6174 --- tests/unit_tests/config/ut-configuration.cpp | 44 ++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/tests/unit_tests/config/ut-configuration.cpp b/tests/unit_tests/config/ut-configuration.cpp index 8aab028..e46bfd8 100644 --- a/tests/unit_tests/config/ut-configuration.cpp +++ b/tests/unit_tests/config/ut-configuration.cpp @@ -44,11 +44,31 @@ struct TestConfig { struct SubSubConfig { int intVal; + bool moved; CONFIG_REGISTER ( intVal ) + SubSubConfig() : moved(false) {} + SubSubConfig(const SubSubConfig& config) : intVal(config.intVal), moved(false) {} + SubSubConfig(SubSubConfig&& config) : intVal(std::move(config.intVal)), moved(false) { + config.moved = true; + } + SubSubConfig& operator=(const SubSubConfig& config) { + intVal = config.intVal; + moved = false; + return *this; + } + SubSubConfig& operator=(SubSubConfig&& config) { + intVal = std::move(config.intVal); + moved = false; + config.moved = true; + return *this; + } + bool isMoved() const { + return moved; + } }; int intVal; @@ -368,7 +388,7 @@ BOOST_AUTO_TEST_CASE(FromToFDTest) fs::remove(fifoPath); } -BOOST_AUTO_TEST_CASE(ConfigUnion) +BOOST_AUTO_TEST_CASE(ConfigUnionTest) { TestConfig testConfig; BOOST_REQUIRE_NO_THROW(loadFromString(jsonTestString, testConfig)); @@ -385,11 +405,29 @@ BOOST_AUTO_TEST_CASE(ConfigUnion) std::string out = saveToString(testConfig); BOOST_CHECK_EQUAL(out, jsonTestString); - //Check move and copy + //Check copy + std::vector unions(2); unions[0].set(2); + //set from const lvalue reference (copy) + unions[1].set(testConfig.unions[1].as()); + BOOST_CHECK(!testConfig.unions[1].as().subSubObj.isMoved()); + //set from lvalue reference (copy) + unions[1].set(testConfig.unions[1].as()); + BOOST_CHECK(!testConfig.unions[1].as().subSubObj.isMoved()); + //set from const rvalue reference (copy) + unions[1].set(std::move(testConfig.unions[1].as())); + BOOST_CHECK(!testConfig.unions[1].as().subSubObj.isMoved()); + //set rvalue reference (copy -- move is disabled) unions[1].set(std::move(testConfig.unions[1].as())); - BOOST_CHECK(testConfig.unions[1].as().intVector.empty()); + BOOST_CHECK(!testConfig.unions[1].as().subSubObj.isMoved()); + //assign lvalue reference (copy) + testConfig.unions[1] = unions[1]; + BOOST_CHECK(!unions[1].as().subSubObj.isMoved()); + //assign rvalue reference (copy -- move is disabled) + testConfig.unions[1] = std::move(unions[1]); + BOOST_CHECK(!unions[1].as().subSubObj.isMoved()); + testConfig.unions.clear(); testConfig.unions = unions; out = saveToString(testConfig); -- 2.7.4 From 7a5a6303f9d660195ef58f730b303eab23617f24 Mon Sep 17 00:00:00 2001 From: Dariusz Michaluk Date: Mon, 15 Dec 2014 15:20:26 +0100 Subject: [PATCH 11/16] Fix build error ('out' may be used uninitialized) [Bug/Feature] build error [Cause] uninitialized variable [Solution] initialize variable [Verification] build Change-Id: I15fa8909d96a5f61998fb774efbc698cb21744f8 Signed-off-by: Dariusz Michaluk --- client/vasum-client-impl.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/vasum-client-impl.cpp b/client/vasum-client-impl.cpp index 41898c7..3c9448b 100644 --- a/client/vasum-client-impl.cpp +++ b/client/vasum-client-impl.cpp @@ -364,7 +364,7 @@ VsmStatus Client::vsm_get_active_zone_id(VsmString* id) noexcept { assert(id); - GVariant* out; + GVariant* out = NULL; VsmStatus ret = callMethod(HOST_INTERFACE, api::host::METHOD_GET_ACTIVE_ZONE_ID, NULL, @@ -409,7 +409,7 @@ VsmStatus Client::vsm_lookup_zone_by_id(const char* id, VsmZone* zone) noexcept assert(id); assert(zone); - GVariant* out; + GVariant* out = NULL; GVariant* args_in = g_variant_new("(s)", id); VsmStatus ret = callMethod(HOST_INTERFACE, api::host::METHOD_GET_ZONE_INFO, @@ -636,7 +636,7 @@ VsmStatus Client::vsm_file_move_request(const char* destZone, const char* path) assert(destZone); assert(path); - GVariant* out; + GVariant* out = NULL; GVariant* args_in = g_variant_new("(ss)", destZone, path); VsmStatus ret = callMethod(ZONE_INTERFACE, api::zone::METHOD_FILE_MOVE_REQUEST, -- 2.7.4 From 1ea2e87dd7c56e65f918466cdb20ef5fd2baa434 Mon Sep 17 00:00:00 2001 From: Jan Olszak Date: Mon, 8 Dec 2014 16:48:21 +0100 Subject: [PATCH 12/16] IPC: Support for the external polling loop in Service [Bug/Feature] Using GMainLoop is possible [Cause] N/A [Solution] For glib > v.2.36 [Verification] Build, install, run tests Change-Id: Ic6d74688c322dd79b29195d94658a4f2ffe0aa83 --- common/ipc/internals/acceptor.cpp | 44 +++++++--- common/ipc/internals/acceptor.hpp | 25 ++++++ common/ipc/internals/processor.cpp | 84 +++++++++++------- common/ipc/internals/processor.hpp | 79 ++++++++++------- common/ipc/internals/utils.cpp | 4 +- common/ipc/ipc-gsource.cpp | 174 +++++++++++++++++++++++++++++++++++++ common/ipc/ipc-gsource.hpp | 150 ++++++++++++++++++++++++++++++++ common/ipc/service.cpp | 35 ++++++++ common/ipc/service.hpp | 17 ++++ common/ipc/types.cpp | 2 + tests/unit_tests/ipc/ut-ipc.cpp | 71 ++++++++++++--- 11 files changed, 599 insertions(+), 86 deletions(-) create mode 100644 common/ipc/ipc-gsource.cpp create mode 100644 common/ipc/ipc-gsource.hpp diff --git a/common/ipc/internals/acceptor.cpp b/common/ipc/internals/acceptor.cpp index 3a6c4cd..1eab1c2 100644 --- a/common/ipc/internals/acceptor.cpp +++ b/common/ipc/internals/acceptor.cpp @@ -25,21 +25,20 @@ #include "config.hpp" #include "ipc/exception.hpp" -#include "ipc/internals/utils.hpp" #include "ipc/internals/acceptor.hpp" #include "logger/logger.hpp" #include #include #include -#include #include namespace vasum { namespace ipc { Acceptor::Acceptor(const std::string& socketPath, const NewConnectionCallback& newConnectionCallback) - : mNewConnectionCallback(newConnectionCallback), + : mIsRunning(false), + mNewConnectionCallback(newConnectionCallback), mSocket(Socket::createSocket(socketPath)) { LOGT("Creating Acceptor for socket " << socketPath); @@ -88,9 +87,8 @@ void Acceptor::run() fds[1].fd = mSocket.getFD(); fds[1].events = POLLIN; - // Main loop - bool isRunning = true; - while (isRunning) { + mIsRunning = true; + while (mIsRunning) { LOGT("Waiting for new connections..."); int ret = ::poll(fds.data(), fds.size(), -1 /*blocking call*/); @@ -108,23 +106,41 @@ void Acceptor::run() // Check for incoming connections if (fds[1].revents & POLLIN) { fds[1].revents = 0; - std::shared_ptr tmpSocket = mSocket.accept(); - mNewConnectionCallback(tmpSocket); + handleConnection(); } // Check for incoming events if (fds[0].revents & POLLIN) { fds[0].revents = 0; - - if (mEventQueue.receive() == Event::FINISH) { - LOGD("Event FINISH"); - isRunning = false; - break; - } + handleEvent(); } } LOGT("Exiting run"); } +void Acceptor::handleConnection() +{ + std::shared_ptr tmpSocket = mSocket.accept(); + mNewConnectionCallback(tmpSocket); +} + +void Acceptor::handleEvent() +{ + if (mEventQueue.receive() == Event::FINISH) { + LOGD("Event FINISH"); + mIsRunning = false; + } +} + +FileDescriptor Acceptor::getEventFD() +{ + return mEventQueue.getFD(); +} + +FileDescriptor Acceptor::getConnectionFD() +{ + return mSocket.getFD(); +} + } // namespace ipc } // namespace vasum diff --git a/common/ipc/internals/acceptor.hpp b/common/ipc/internals/acceptor.hpp index 702a161..f87a0bb 100644 --- a/common/ipc/internals/acceptor.hpp +++ b/common/ipc/internals/acceptor.hpp @@ -29,6 +29,7 @@ #include "ipc/internals/socket.hpp" #include "ipc/internals/event-queue.hpp" +#include "ipc/types.hpp" #include #include @@ -67,11 +68,35 @@ public: */ void stop(); + /** + * Handle one incoming connection. + * Used with external polling + */ + void handleConnection(); + + /** + * Handle one event from the internal event's queue + * Used with external polling + */ + void handleEvent(); + + /** + * @return file descriptor of internal event's queue + */ + FileDescriptor getEventFD(); + + /** + * @return file descriptor for the connection socket + */ + FileDescriptor getConnectionFD(); + private: enum class Event : int { FINISH // Shutdown request }; + bool mIsRunning; + NewConnectionCallback mNewConnectionCallback; Socket mSocket; diff --git a/common/ipc/internals/processor.cpp b/common/ipc/internals/processor.cpp index be1060d..72a1788 100644 --- a/common/ipc/internals/processor.cpp +++ b/common/ipc/internals/processor.cpp @@ -112,6 +112,11 @@ void Processor::setRemovedPeerCallback(const PeerCallback& removedPeerCallback) mRemovedPeerCallback = removedPeerCallback; } +FileDescriptor Processor::getEventFD() +{ + return mEventQueue.getFD(); +} + void Processor::removeMethod(const MethodID methodID) { LOGT("Removing method " << methodID); @@ -128,9 +133,9 @@ FileDescriptor Processor::addPeer(const std::shared_ptr& socketPtr) peerFD = socketPtr->getFD(); SocketInfo socketInfo(peerFD, std::move(socketPtr)); mNewSockets.push(std::move(socketInfo)); + mEventQueue.send(Event::ADD_PEER); } LOGI("New peer added. Id: " << peerFD); - mEventQueue.send(Event::ADD_PEER); return peerFD; } @@ -143,9 +148,9 @@ void Processor::removePeer(const FileDescriptor peerFD) Lock lock(mSocketsMutex); RemovePeerRequest request(peerFD, conditionPtr); mPeersToDelete.push(std::move(request)); + mEventQueue.send(Event::REMOVE_PEER); } - mEventQueue.send(Event::REMOVE_PEER); auto isPeerDeleted = [&peerFD, this]()->bool { Lock lock(mSocketsMutex); @@ -204,6 +209,10 @@ void Processor::removePeerInternal(const FileDescriptor peerFD, Status status) void Processor::resetPolling() { + if (!isStarted()) { + return; + } + LOGI("Resetting polling"); // Setup polling on eventfd and sockets Lock lock(mSocketsMutex); @@ -251,20 +260,22 @@ void Processor::run() } // Check for incoming events - if (handleEvent()) { - // mFDs changed - continue; + if (mFDs[0].revents & POLLIN) { + mFDs[0].revents &= ~(POLLIN); + if (handleEvent()) { + // mFDs changed + continue; + } } + } cleanCommunication(); } - bool Processor::handleLostConnections() { std::vector peersToRemove; - { Lock lock(mSocketsMutex); for (unsigned int i = 1; i < mFDs.size(); ++i) { @@ -283,39 +294,61 @@ bool Processor::handleLostConnections() return !peersToRemove.empty(); } +bool Processor::handleLostConnection(const FileDescriptor peerFD) +{ + removePeerInternal(peerFD, Status::PEER_DISCONNECTED); + return true; +} + bool Processor::handleInputs() { - std::vector> socketsWithInput; + std::vector peersWithInput; { Lock lock(mSocketsMutex); for (unsigned int i = 1; i < mFDs.size(); ++i) { if (mFDs[i].revents & POLLIN) { mFDs[i].revents &= ~(POLLIN); - socketsWithInput.push_back(mSockets[mFDs[i].fd]); + peersWithInput.push_back(mFDs[i].fd); } } } bool pollChanged = false; // Handle input outside the critical section - for (const auto& socketPtr : socketsWithInput) { - pollChanged = pollChanged || handleInput(*socketPtr); + for (const FileDescriptor peerFD : peersWithInput) { + pollChanged = pollChanged || handleInput(peerFD); } return pollChanged; } -bool Processor::handleInput(const Socket& socket) +bool Processor::handleInput(const FileDescriptor peerFD) { LOGT("Handle incoming data"); + + std::shared_ptr socketPtr; + try { + socketPtr = mSockets.at(peerFD); + } catch (const std::out_of_range&) { + LOGE("No such peer: " << peerFD); + return false; + } + MethodID methodID; MessageID messageID; { - Socket::Guard guard = socket.getGuard(); - socket.read(&methodID, sizeof(methodID)); - socket.read(&messageID, sizeof(messageID)); + Socket::Guard guard = socketPtr->getGuard(); + try { + socketPtr->read(&methodID, sizeof(methodID)); + socketPtr->read(&messageID, sizeof(messageID)); + + } catch (const IPCException& e) { + LOGE("Error during reading the socket"); + removePeerInternal(socketPtr->getFD(), Status::NAUGHTY_PEER); + return true; + } if (methodID == RETURN_METHOD_ID) { - return onReturnValue(socket, messageID); + return onReturnValue(*socketPtr, messageID); } else { Lock lock(mCallsMutex); @@ -323,19 +356,19 @@ bool Processor::handleInput(const Socket& socket) // Method std::shared_ptr methodCallbacks = mMethodsCallbacks.at(methodID); lock.unlock(); - return onRemoteCall(socket, methodID, messageID, methodCallbacks); + return onRemoteCall(*socketPtr, methodID, messageID, methodCallbacks); } else if (mSignalsCallbacks.count(methodID)) { // Signal std::shared_ptr signalCallbacks = mSignalsCallbacks.at(methodID); lock.unlock(); - return onRemoteSignal(socket, methodID, messageID, signalCallbacks); + return onRemoteSignal(*socketPtr, methodID, messageID, signalCallbacks); } else { // Nothing lock.unlock(); LOGW("No method or signal callback for methodID: " << methodID); - removePeerInternal(socket.getFD(), Status::NAUGHTY_PEER); + removePeerInternal(socketPtr->getFD(), Status::NAUGHTY_PEER); return true; } } @@ -461,13 +494,6 @@ bool Processor::onRemoteCall(const Socket& socket, bool Processor::handleEvent() { - if (!(mFDs[0].revents & POLLIN)) { - // No event to serve - return false; - } - - mFDs[0].revents &= ~(POLLIN); - switch (mEventQueue.receive()) { case Event::FINISH: { LOGD("Event FINISH"); @@ -518,11 +544,11 @@ bool Processor::onNewPeer() // Broadcast the new signal to peers LOGW("Sending handled signals"); - std::list peersIDs; + std::list peersFDs; { Lock lock(mSocketsMutex); for (const auto kv : mSockets) { - peersIDs.push_back(kv.first); + peersFDs.push_back(kv.first); } } @@ -535,7 +561,7 @@ bool Processor::onNewPeer() } auto data = std::make_shared(ids); - for (const FileDescriptor peerFD : peersIDs) { + for (const FileDescriptor peerFD : peersFDs) { callInternal(REGISTER_SIGNAL_METHOD_ID, peerFD, data, diff --git a/common/ipc/internals/processor.hpp b/common/ipc/internals/processor.hpp index 6ce2688..d33d12b 100644 --- a/common/ipc/internals/processor.hpp +++ b/common/ipc/internals/processor.hpp @@ -75,6 +75,7 @@ const unsigned int DEFAULT_METHOD_TIMEOUT = 1000; * - new way to generate UIDs * - callbacks for serialization/parsing * - store Sockets in a vector, maybe SocketStore? +* - fix valgrind tests * * */ @@ -240,6 +241,35 @@ public: void signal(const MethodID methodID, const std::shared_ptr& data); + /** + * Removes one peer. + * Handler used in external polling. + * + * @param peerFD file description identifying the peer + * @return should the polling structure be rebuild + */ + bool handleLostConnection(const FileDescriptor peerFD); + + /** + * Handles input from one peer. + * Handler used in external polling. + * + * @param peerFD file description identifying the peer + * @return should the polling structure be rebuild + */ + bool handleInput(const FileDescriptor peerFD); + + /** + * Handle one event from the internal event's queue + * + * @return should the polling structure be rebuild + */ + bool handleEvent(); + + /** + * @return file descriptor for the internal event's queue + */ + FileDescriptor getEventFD(); private: typedef std::function& data)> SerializeCallback; @@ -383,13 +413,12 @@ private: static void discardResultHandler(Status, std::shared_ptr&) {} void run(); - bool handleEvent(); bool onCall(); bool onNewPeer(); bool onRemovePeer(); bool handleLostConnections(); bool handleInputs(); - bool handleInput(const Socket& socket); + bool onReturnValue(const Socket& socket, const MessageID messageID); bool onRemoteCall(const Socket& socket, @@ -494,26 +523,24 @@ void Processor::addSignalHandler(const MethodID methodID, mSignalsCallbacks[methodID] = std::make_shared(std::move(signalCall)); } - if (isStarted()) { - // Broadcast the new signal to peers - std::vector ids {methodID}; - auto data = std::make_shared(ids); + std::vector ids {methodID}; + auto data = std::make_shared(ids); - std::list peersIDs; - { - Lock lock(mSocketsMutex); - for (const auto kv : mSockets) { - peersIDs.push_back(kv.first); - } + std::list peersFDs; + { + Lock lock(mSocketsMutex); + for (const auto kv : mSockets) { + peersFDs.push_back(kv.first); } + } - for (const FileDescriptor peerFD : peersIDs) { - callSync(REGISTER_SIGNAL_METHOD_ID, - peerFD, - data, - DEFAULT_METHOD_TIMEOUT); - } + for (const FileDescriptor peerFD : peersFDs) { + callSync(REGISTER_SIGNAL_METHOD_ID, + peerFD, + data, + DEFAULT_METHOD_TIMEOUT); } + } template @@ -535,11 +562,6 @@ MessageID Processor::callAsync(const MethodID methodID, const std::shared_ptr& data, const typename ResultHandler::type& process) { - if (!isStarted()) { - LOGE("The Processor thread is not started. Can't send any data."); - throw IPCException("The Processor thread is not started. Can't send any data."); - } - return callInternal(methodID, peerFD, data, process); } @@ -600,18 +622,13 @@ template void Processor::signal(const MethodID methodID, const std::shared_ptr& data) { - if (!isStarted()) { - LOGE("The Processor thread is not started. Can't send any data."); - throw IPCException("The Processor thread is not started. Can't send any data."); - } - - std::list peersIDs; + std::list peersFDs; { Lock lock(mSocketsMutex); - peersIDs = mSignalsPeers[methodID]; + peersFDs = mSignalsPeers[methodID]; } - for (const FileDescriptor peerFD : peersIDs) { + for (const FileDescriptor peerFD : peersFDs) { Lock lock(mCallsMutex); mCalls.push(methodID, peerFD, data); mEventQueue.send(Event::CALL); diff --git a/common/ipc/internals/utils.cpp b/common/ipc/internals/utils.cpp index 88f8fc0..bd98c1b 100644 --- a/common/ipc/internals/utils.cpp +++ b/common/ipc/internals/utils.cpp @@ -122,8 +122,8 @@ void write(int fd, const void* bufferPtr, const size_t size, int timeoutMS) // Neglected errors LOGD("Retrying write"); } else { - LOGE("Error during reading: " + std::string(strerror(errno))); - throw IPCException("Error during reading: " + std::string(strerror(errno))); + LOGE("Error during writing: " + std::string(strerror(errno))); + throw IPCException("Error during writing: " + std::string(strerror(errno))); } if (nTotal >= size) { diff --git a/common/ipc/ipc-gsource.cpp b/common/ipc/ipc-gsource.cpp new file mode 100644 index 0000000..f5cdbb5 --- /dev/null +++ b/common/ipc/ipc-gsource.cpp @@ -0,0 +1,174 @@ +/* +* Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved +* +* Contact: Jan Olszak +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License +*/ + +/** + * @file + * @author Jan Olszak (j.olszak@samsung.com) + * @brief Class for creating a dedicated GSource + */ + + +#include "config.hpp" + +#include "ipc/ipc-gsource.hpp" + +#if GLIB_CHECK_VERSION(2,36,0) + +#include "logger/logger.hpp" +#include + +namespace vasum { +namespace ipc { + +namespace { + + +GIOCondition conditions = static_cast(G_IO_IN | + G_IO_ERR | + G_IO_HUP); +} + + +IPCGSource::IPCGSource(const std::vector fds, + const HandlerCallback& handlerCallback) + : mHandlerCallback(handlerCallback) +{ + LOGD("Constructing IPCGSource"); + for (const FileDescriptor fd : fds) { + addFD(fd); + } +} + +IPCGSource::~IPCGSource() +{ + LOGD("Destroying IPCGSource"); + g_source_destroy(&mGSource); + +} + +IPCGSource* IPCGSource::create(const std::vector& fds, + const HandlerCallback& handlerCallback) +{ + LOGD("Creating IPCGSource"); + + static GSourceFuncs funcs = { &IPCGSource::prepare, + &IPCGSource::check, + &IPCGSource::dispatch, + &IPCGSource::finalize, + nullptr, + nullptr + }; + + // New GSource + GSource* gSource = g_source_new(&funcs, sizeof(IPCGSource)); + g_source_set_priority(gSource, G_PRIORITY_HIGH); + + // Fill additional data + IPCGSource* source = reinterpret_cast(gSource); + return new(source) IPCGSource(fds, handlerCallback); +} + + +void IPCGSource::addFD(const FileDescriptor fd) +{ + if (!&mGSource) { + // In case it's called as a callback but the IPCGSource is destroyed + return; + } + + LOGD("Adding fd to glib"); + gpointer tag = g_source_add_unix_fd(&mGSource, + fd, + conditions); + FDInfo fdInfo(tag, fd); + mFDInfos.push_back(std::move(fdInfo)); +} + +void IPCGSource::removeFD(const FileDescriptor fd) +{ + if (!&mGSource) { + // In case it's called as a callback but the IPCGSource is destroyed + return; + } + + LOGD("Removing fd from glib"); + auto it = std::find(mFDInfos.begin(), mFDInfos.end(), fd); + if (it == mFDInfos.end()) { + LOGE("No such fd"); + return; + } + g_source_remove_unix_fd(&mGSource, it->tag); + mFDInfos.erase(it); +} + +guint IPCGSource::attach(GMainContext* context) +{ + LOGD("Attaching to GMainContext"); + return g_source_attach(&mGSource, context); +} + +gboolean IPCGSource::prepare(GSource* gSource, gint* timeout) +{ + if (!gSource) { + return FALSE; + } + + *timeout = -1; + + // TODO: Implement hasEvents() method in Client and Service and use it here as a callback: + // return source->hasEvents(); + return FALSE; +} + +gboolean IPCGSource::check(GSource* gSource) +{ + if (!gSource) { + return FALSE; + } + + return TRUE; +} + +gboolean IPCGSource::dispatch(GSource* gSource, + GSourceFunc /*callback*/, + gpointer /*userData*/) +{ + IPCGSource* source = reinterpret_cast(gSource); + + for (const FDInfo fdInfo : source->mFDInfos) { + GIOCondition cond = g_source_query_unix_fd(gSource, fdInfo.tag); + if (conditions & cond) { + source->mHandlerCallback(fdInfo.fd, cond); + } + } + + return TRUE; // Don't remove the GSource from the GMainContext +} + +void IPCGSource::finalize(GSource* gSource) +{ + if (gSource) { + IPCGSource* source = reinterpret_cast(gSource); + source->~IPCGSource(); + } +} + +} // namespace ipc +} // namespace vasum + +#endif // GLIB_CHECK_VERSION diff --git a/common/ipc/ipc-gsource.hpp b/common/ipc/ipc-gsource.hpp new file mode 100644 index 0000000..96e0a1a --- /dev/null +++ b/common/ipc/ipc-gsource.hpp @@ -0,0 +1,150 @@ +/* +* Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved +* +* Contact: Jan Olszak +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License +*/ + +/** + * @file + * @author Jan Olszak (j.olszak@samsung.com) + * @brief Class for creating a dedicated GSource + */ + +#ifndef COMMON_IPC_IPC_GSOURCE_HPP +#define COMMON_IPC_IPC_GSOURCE_HPP + +#include +#if GLIB_CHECK_VERSION(2,36,0) + +#include "ipc/service.hpp" +#include "ipc/types.hpp" +#include "utils/callback-wrapper.hpp" +#include + + +namespace vasum { +namespace ipc { + +/** + * Class for connecting to the glib's loop. + * Creates a dedicated GSource. + * + * It's supposed to be constructed ONLY with the static create method + * and destructed in a glib callback. + */ +struct IPCGSource { +public: + typedef std::function HandlerCallback; + + IPCGSource() = delete; + IPCGSource(const IPCGSource&) = delete; + IPCGSource& operator=(const IPCGSource&) = delete; + + /** + * New file descriptor to listen on. + * + * @param peerFD file descriptor + */ + void addFD(const FileDescriptor peerFD); + + /** + * Removes the file descriptor from the GSource + * + * @param peerFD file descriptor + */ + void removeFD(const FileDescriptor peerFD); + + /** + * Attach to the glib's GMainContext + * + * @param context where to connect + * @return result of the g_source_attach call + */ + guint attach(GMainContext* context = nullptr); + + /** + * Creates the IPCGSource class in the memory allocated by glib. + * Calls IPCGSource's constructor + * + * @param fds initial set of file descriptors + * @param handlerCallback event handling callback + * + * @return pointer to the IPCGSource + */ + static IPCGSource* create(const std::vector& fds, + const HandlerCallback& handlerCallback); + +private: + + /** + * GSourceFuncs' callback + */ + static gboolean prepare(GSource* source, gint* timeout); + + /** + * GSourceFuncs' callback + */ + static gboolean check(GSource* source); + + /** + * GSourceFuncs' callback + */ + static gboolean dispatch(GSource* source, + GSourceFunc callbacks, + gpointer userData); + + /** + * GSourceFuncs' callback + */ + static void finalize(GSource* source); + + + + // Called only from IPCGSource::create + IPCGSource(const std::vector fds, + const HandlerCallback& handlerCallback); + + // Called only from IPCGSource::finalize + ~IPCGSource(); + + struct FDInfo { + FDInfo(gpointer tag, FileDescriptor fd) + : tag(tag), fd(fd) {} + + bool operator==(const gpointer t) + { + return t == tag; + } + + bool operator==(const FileDescriptor f) + { + return f == fd; + } + + gpointer tag; + FileDescriptor fd; + }; + + GSource mGSource; + HandlerCallback mHandlerCallback; + std::vector mFDInfos; +}; + +} // namespace ipc +} // namespace vasum + +#endif // GLIB_CHECK_VERSION + +#endif // COMMON_IPC_IPC_GSOURCE_HPP diff --git a/common/ipc/service.cpp b/common/ipc/service.cpp index 5ee5fbd..be95cee 100644 --- a/common/ipc/service.cpp +++ b/common/ipc/service.cpp @@ -79,6 +79,41 @@ void Service::stop() LOGD("Stopped"); } +std::vector Service::getFDs() +{ + std::vector fds; + fds.push_back(mAcceptor.getEventFD()); + fds.push_back(mAcceptor.getConnectionFD()); + fds.push_back(mProcessor.getEventFD()); + + return fds; +} + +void Service::handle(const FileDescriptor fd, const short pollEvent) +{ + if (fd == mProcessor.getEventFD() && pollEvent & POLLIN) { + mProcessor.handleEvent(); + return; + + } else if (fd == mAcceptor.getConnectionFD() && pollEvent & POLLIN) { + mAcceptor.handleConnection(); + return; + + } else if (fd == mAcceptor.getEventFD() && pollEvent & POLLIN) { + mAcceptor.handleEvent(); + return; + + } else if (pollEvent & POLLIN) { + mProcessor.handleInput(fd); + return; + + } else if (pollEvent & POLLHUP) { + mProcessor.handleLostConnection(fd); + return; + } +} + + void Service::setNewPeerCallback(const PeerCallback& newPeerCallback) { mProcessor.setNewPeerCallback(newPeerCallback); diff --git a/common/ipc/service.hpp b/common/ipc/service.hpp index 1f9aee3..ed83606 100644 --- a/common/ipc/service.hpp +++ b/common/ipc/service.hpp @@ -75,6 +75,23 @@ public: void stop(); /** + * Used with an external polling loop + * + * @return vector of internal file descriptors + */ + std::vector getFDs(); + + /** + * Used with an external polling loop. + * Handles one event from the file descriptor. + * + * @param fd file descriptor + * @param pollEvent event on the fd. Defined in poll.h + * + */ + void handle(const FileDescriptor fd, const short pollEvent); + + /** * Set the callback called for each new connection to a peer * * @param newPeerCallback the callback diff --git a/common/ipc/types.cpp b/common/ipc/types.cpp index 18c769d..fa57648 100644 --- a/common/ipc/types.cpp +++ b/common/ipc/types.cpp @@ -22,6 +22,8 @@ * @brief Types definitions and helper functions */ +#include "config.hpp" + #include "ipc/types.hpp" #include "logger/logger.hpp" diff --git a/tests/unit_tests/ipc/ut-ipc.cpp b/tests/unit_tests/ipc/ut-ipc.cpp index c671db6..9ce131d 100644 --- a/tests/unit_tests/ipc/ut-ipc.cpp +++ b/tests/unit_tests/ipc/ut-ipc.cpp @@ -33,7 +33,9 @@ #include "ipc/service.hpp" #include "ipc/client.hpp" +#include "ipc/ipc-gsource.hpp" #include "ipc/types.hpp" +#include "utils/glib-loop.hpp" #include "config/fields.hpp" #include "logger/logger.hpp" @@ -47,6 +49,8 @@ using namespace vasum; using namespace vasum::ipc; +using namespace vasum::utils; +using namespace std::placeholders; namespace fs = boost::filesystem; namespace { @@ -132,30 +136,48 @@ std::shared_ptr longEchoCallback(const FileDescriptor, std::shared_ptr return data; } -FileDescriptor connect(Service& s, Client& c) +FileDescriptor connect(Service& s, Client& c, bool serviceUsesGlib = false) { // Connects the Client to the Service and returns Clients FileDescriptor - std::mutex mutex; std::condition_variable cv; FileDescriptor peerFD = 0; - auto newPeerCallback = [&cv, &peerFD, &mutex](const FileDescriptor newFileDescriptor) { + auto newPeerCallback = [&cv, &peerFD, &mutex](const FileDescriptor newFD) { std::unique_lock lock(mutex); - peerFD = newFileDescriptor; - cv.notify_one(); + peerFD = newFD; + cv.notify_all(); }; - s.setNewPeerCallback(newPeerCallback); - if (!s.isStarted()) { - s.start(); + if (!serviceUsesGlib) { + s.setNewPeerCallback(newPeerCallback); + + if (!s.isStarted()) { + s.start(); + } + } else { +#if GLIB_CHECK_VERSION(2,36,0) + + IPCGSource* serviceGSourcePtr = IPCGSource::create(s.getFDs(), std::bind(&Service::handle, &s, _1, _2)); + + auto agregateCallback = [&newPeerCallback, &serviceGSourcePtr](const FileDescriptor newFD) { + serviceGSourcePtr->addFD(newFD); + newPeerCallback(newFD); + }; + + s.setNewPeerCallback(agregateCallback); + s.setRemovedPeerCallback(std::bind(&IPCGSource::removeFD, serviceGSourcePtr, _1)); + + serviceGSourcePtr->attach(); +#endif // GLIB_CHECK_VERSION + } c.start(); std::unique_lock lock(mutex); - BOOST_CHECK(cv.wait_for(lock, std::chrono::milliseconds(1000), [&peerFD]() { + BOOST_CHECK(cv.wait_for(lock, std::chrono::milliseconds(2000), [&peerFD]() { return peerFD != 0; })); @@ -165,7 +187,7 @@ FileDescriptor connect(Service& s, Client& c) void testEcho(Client& c, const MethodID methodID) { std::shared_ptr sentData(new SendData(34)); - std::shared_ptr recvData = c.callSync(methodID, sentData); + std::shared_ptr recvData = c.callSync(methodID, sentData, 1000); BOOST_CHECK_EQUAL(recvData->intVal, sentData->intVal); } @@ -554,6 +576,35 @@ BOOST_AUTO_TEST_CASE(AddSignalOffline) } +#if GLIB_CHECK_VERSION(2,36,0) + +BOOST_AUTO_TEST_CASE(ServiceGSource) +{ + ScopedGlibLoop loop; + + std::atomic_bool isSignalCalled(false); + auto signalHandler = [&isSignalCalled](const FileDescriptor, std::shared_ptr&) { + isSignalCalled = true; + }; + + Service s(socketPath); + s.addMethodHandler(1, echoCallback); + + Client c(socketPath); + s.addSignalHandler(2, signalHandler); + connect(s, c, true); + + testEcho(c, 1); + + auto data = std::make_shared(1); + c.signal(2, data); + + std::this_thread::sleep_for(std::chrono::milliseconds(100)); //TODO wait_for + BOOST_CHECK(isSignalCalled); +} + +#endif // GLIB_CHECK_VERSION + // BOOST_AUTO_TEST_CASE(ConnectionLimitTest) // { // unsigned oldLimit = ipc::getMaxFDNumber(); -- 2.7.4 From 637f643f63b8c7de143a2eec4891d7b78f396264 Mon Sep 17 00:00:00 2001 From: Lukasz Kostyra Date: Mon, 15 Dec 2014 13:25:23 +0100 Subject: [PATCH 13/16] Add "enabled" file [Feature] File indicating that zones are running in the system. [Cause] Other external services (eg. security-manager) must know when zones are active in the system. [Solution] Provide "enabled" file, which will appear when zones are launched. The file will appear when first zone will be created, and file will disappear when last zone will be destroyed. [Verification] Build, install, run tests. Change-Id: I634e424e28c7d449276bbe1c2c80f3cb0e35bcb7 --- common/utils/fs.cpp | 13 +++++++++++++ common/utils/fs.hpp | 5 +++++ server/zones-manager.cpp | 15 +++++++++++++++ tests/unit_tests/utils/ut-fs.cpp | 7 +++++++ 4 files changed, 40 insertions(+) diff --git a/common/utils/fs.cpp b/common/utils/fs.cpp index 9254f0a..3330cbf 100644 --- a/common/utils/fs.cpp +++ b/common/utils/fs.cpp @@ -98,6 +98,19 @@ bool saveFileContent(const std::string& path, const std::string& content) return true; } +bool removeFile(const std::string& path) +{ + LOGD(path << ": exists, removing."); + if (::remove(path.c_str())) { + if (errno != ENOENT) { + LOGE(path << ": failed to delete: " << ::strerror(errno)); + return false; + } + } + + return true; +} + bool isCharDevice(const std::string& path) { struct stat s; diff --git a/common/utils/fs.hpp b/common/utils/fs.hpp index 91ea62a..35000c6 100644 --- a/common/utils/fs.hpp +++ b/common/utils/fs.hpp @@ -50,6 +50,11 @@ bool readFileContent(const std::string& path, std::string& content); bool saveFileContent(const std::string& path, const std::string& content); /** + * Remove file + */ +bool removeFile(const std::string& path); + +/** * Checks if a char device exists */ bool isCharDevice(const std::string& path); diff --git a/server/zones-manager.cpp b/server/zones-manager.cpp index 981556b..402fc7f 100644 --- a/server/zones-manager.cpp +++ b/server/zones-manager.cpp @@ -65,6 +65,7 @@ bool regexMatchVector(const std::string& str, const std::vector& v const std::string HOST_ID = "host"; const std::string ZONE_TEMPLATE_CONFIG_PATH = "template.conf"; +const std::string ENABLED_FILE_NAME = "enabled"; const boost::regex ZONE_NAME_REGEX("~NAME~"); const boost::regex ZONE_IP_THIRD_OCTET_REGEX("~IP~"); @@ -193,6 +194,14 @@ void ZonesManager::createZone(const std::string& zoneConfig) this, id, _1)); mZones.insert(ZoneMap::value_type(id, std::move(c))); + + // after zone is created successfully, put a file informing that zones are enabled + if (mZones.size() == 1) { + if (!utils::saveFileContent( + utils::createFilePath(mConfig.zonesPath, "/", ENABLED_FILE_NAME), "")) { + throw ZoneOperationException(ENABLED_FILE_NAME + ": cannot create."); + } + } } void ZonesManager::destroyZone(const std::string& zoneId) @@ -207,6 +216,12 @@ void ZonesManager::destroyZone(const std::string& zoneId) // TODO give back the focus it->second->setDestroyOnExit(); mZones.erase(it); + + if (mZones.size() == 0) { + if (!utils::removeFile(utils::createFilePath(mConfig.zonesPath, "/", ENABLED_FILE_NAME))) { + LOGE("Failed to remove enabled file."); + } + } } void ZonesManager::focus(const std::string& zoneId) diff --git a/tests/unit_tests/utils/ut-fs.cpp b/tests/unit_tests/utils/ut-fs.cpp index 5557e46..63b4f63 100644 --- a/tests/unit_tests/utils/ut-fs.cpp +++ b/tests/unit_tests/utils/ut-fs.cpp @@ -88,6 +88,13 @@ BOOST_AUTO_TEST_CASE(SaveFileContentTest) boost::filesystem::remove(FILE_PATH_RANDOM, ec); } +BOOST_AUTO_TEST_CASE(RemoveFileTest) +{ + BOOST_REQUIRE(saveFileContent(FILE_PATH_RANDOM, FILE_CONTENT)); + BOOST_REQUIRE(removeFile(FILE_PATH_RANDOM)); + BOOST_REQUIRE(!boost::filesystem::exists(FILE_PATH_RANDOM)); +} + BOOST_AUTO_TEST_CASE(MountPointTest) { bool result; -- 2.7.4 From 8f92cd9ec0ab3c34ac8add4c9b6e8f2a31227cb5 Mon Sep 17 00:00:00 2001 From: Piotr Bartosiewicz Date: Thu, 11 Dec 2014 17:54:13 +0100 Subject: [PATCH 14/16] Worker thread utility class [Bug/Feature] A utility class that wraps a queue of tasks executed in a dedicated thread. [Cause] N/A [Solution] N/A [Verification] Build, install, run tests Change-Id: I32788fd6321c2877cf4dafe7213c1a140c1d3fd2 --- common/utils/counting-map.hpp | 88 ++++++++++++++ common/utils/worker.cpp | 186 +++++++++++++++++++++++++++++ common/utils/worker.hpp | 74 ++++++++++++ server/zone.cpp | 37 ++---- server/zone.hpp | 13 +- server/zones-manager.cpp | 39 +++--- server/zones-manager.hpp | 2 + tests/unit_tests/server/ut-zone.cpp | 9 +- tests/unit_tests/utils/ut-counting-map.cpp | 81 +++++++++++++ tests/unit_tests/utils/ut-worker.cpp | 182 ++++++++++++++++++++++++++++ 10 files changed, 656 insertions(+), 55 deletions(-) create mode 100644 common/utils/counting-map.hpp create mode 100644 common/utils/worker.cpp create mode 100644 common/utils/worker.hpp create mode 100644 tests/unit_tests/utils/ut-counting-map.cpp create mode 100644 tests/unit_tests/utils/ut-worker.cpp diff --git a/common/utils/counting-map.hpp b/common/utils/counting-map.hpp new file mode 100644 index 0000000..da5f4c7 --- /dev/null +++ b/common/utils/counting-map.hpp @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved + * + * Contact: Piotr Bartosiewicz + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +/** + * @file + * @author Piotr Bartosiewicz (p.bartosiewi@partner.samsung.com) + * @brief Counting map + */ + +#ifndef COMMON_UTILS_COUNTING_MAP_HPP +#define COMMON_UTILS_COUNTING_MAP_HPP + +#include + +namespace vasum { +namespace utils { + + +/** + * Structure used to count elements. + * It's like multiset + count but is more efficient. + */ +template +class CountingMap { +public: + size_t increment(const Key& key) + { + auto res = mMap.insert(typename Map::value_type(key, 1)); + if (!res.second) { + ++res.first->second; + } + return res.first->second; + } + + size_t decrement(const Key& key) + { + auto it = mMap.find(key); + if (it == mMap.end()) { + return 0; + } + if (--it->second == 0) { + mMap.erase(it); + return 0; + } + return it->second; + } + + void clear() + { + mMap.clear(); + } + + size_t get(const Key& key) const + { + auto it = mMap.find(key); + return it == mMap.end() ? 0 : it->second; + } + + bool empty() const + { + return mMap.empty(); + } +private: + typedef std::unordered_map Map; + Map mMap; +}; + + +} // namespace utils +} // namespace vasum + + +#endif // COMMON_UTILS_COUNTING_MAP_HPP diff --git a/common/utils/worker.cpp b/common/utils/worker.cpp new file mode 100644 index 0000000..2cb3284 --- /dev/null +++ b/common/utils/worker.cpp @@ -0,0 +1,186 @@ +/* + * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved + * + * Contact: Piotr Bartosiewicz + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +/** + * @file + * @author Piotr Bartosiewicz (p.bartosiewi@partner.samsung.com) + * @brief A worker thread that executes tasks + */ + +#include "config.hpp" +#include "utils/worker.hpp" +#include "utils/counting-map.hpp" +#include "logger/logger.hpp" + +#include +#include +#include +#include +#include +#include + + +namespace vasum { +namespace utils { + + +class Worker::WorkerQueue { +public: + WorkerQueue() + : mLastGroupID(0), mEnding(false) + { + LOGT("Worker queue created"); + } + + ~WorkerQueue() + { + { + Lock lock(mMutex); + assert(mTaskQueue.empty()); + assert(mGroupCounter.empty()); + mEnding = true; + } + if (mThread.joinable()) { + mAddedCondition.notify_all(); + mThread.join(); + } + LOGT("Worker queue destroyed"); + } + + GroupID getNextGroupID() + { + return ++mLastGroupID; + } + + void addTask(const Worker::Task& task, GroupID groupID) + { + assert(task); + + Lock lock(mMutex); + LOGT("Adding task to subgroup " << groupID); + mTaskQueue.push_back(TaskInfo{task, groupID}); + mGroupCounter.increment(groupID); + mAddedCondition.notify_one(); + if (!mThread.joinable()) { + mThread = std::thread(&WorkerQueue::workerProc, this); + } + } + + void waitForGroupEmpty(GroupID groupID) + { + Lock lock(mMutex); + size_t count = mGroupCounter.get(groupID); + if (count > 0) { + LOGD("Waiting for " << count << " task in group " << groupID); + } + mEmptyGroupCondition.wait(lock, [this, groupID] { + return mGroupCounter.get(groupID) == 0; + }); + } +private: + typedef std::unique_lock Lock; + + struct TaskInfo { + Worker::Task task; + GroupID groupID; + }; + + std::atomic mLastGroupID; + std::condition_variable mAddedCondition; + std::condition_variable mEmptyGroupCondition; + std::thread mThread; + + std::mutex mMutex; // protects below member variables: + bool mEnding; + std::deque mTaskQueue; + CountingMap mGroupCounter; + + void workerProc() + { + LOGT("Worker thread started"); + for (;;) { + // wait for a task + GroupID groupID; + { + Lock lock(mMutex); + mAddedCondition.wait(lock, [this] { + return !mTaskQueue.empty() || mEnding; + }); + if (mTaskQueue.empty()) { + break; + } + TaskInfo taskInfo = std::move(mTaskQueue.front()); + mTaskQueue.pop_front(); + + lock.unlock(); + + // execute + execute(taskInfo); + groupID = taskInfo.groupID; + } + // remove from queue + { + Lock lock(mMutex); + if (mGroupCounter.decrement(groupID) == 0) { + mEmptyGroupCondition.notify_all(); + } + } + } + LOGT("Worker thread exited"); + } + + void execute(const TaskInfo& taskInfo) + { + try { + LOGT("Executing task from subgroup " << taskInfo.groupID); + taskInfo.task(); + } catch (const std::exception& e) { + LOGE("Unexpected exception while executing task: " << e.what()); + } + } +}; + + +Worker::Pointer Worker::create() +{ + return Pointer(new Worker(std::make_shared())); +} + +Worker::Worker(const std::shared_ptr& workerQueue) + : mWorkerQueue(workerQueue), mGroupID(workerQueue->getNextGroupID()) +{ +} + +Worker::~Worker() +{ + mWorkerQueue->waitForGroupEmpty(mGroupID); +} + +Worker::Pointer Worker::createSubWorker() +{ + return Pointer(new Worker(mWorkerQueue)); +} + +void Worker::addTask(const Task& task) +{ + mWorkerQueue->addTask(task, mGroupID); +} + + +} // namespace utils +} // namespace vasum diff --git a/common/utils/worker.hpp b/common/utils/worker.hpp new file mode 100644 index 0000000..0d951fb --- /dev/null +++ b/common/utils/worker.hpp @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved + * + * Contact: Piotr Bartosiewicz + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +/** + * @file + * @author Piotr Bartosiewicz (p.bartosiewi@partner.samsung.com) + * @brief A worker thread that executes tasks + */ + +#ifndef COMMON_UTILS_WORKER_HPP +#define COMMON_UTILS_WORKER_HPP + +#include +#include + +namespace vasum { +namespace utils { + +/** + * A queue with tasks executed in a dedicated thread. + * Current implementation creates a thread on the first use. + */ +class Worker { +public: + typedef std::shared_ptr Pointer; + typedef std::function Task; + + ~Worker(); + + /** + * Creates a worker with its own thread + */ + static Pointer create(); + + /** + * Creates a worker that share a thread with its parent + */ + Pointer createSubWorker(); + + /** + * Adds a task to the queue. + */ + void addTask(const Task& task); + +private: + typedef unsigned int GroupID; + class WorkerQueue; + + const std::shared_ptr mWorkerQueue; + const GroupID mGroupID; + + Worker(const std::shared_ptr& workerQueue); +}; + +} // namespace utils +} // namespace vasum + + +#endif // COMMON_UTILS_WORKER_HPP diff --git a/server/zone.cpp b/server/zone.cpp index 2e4573c..5f6dce0 100644 --- a/server/zone.cpp +++ b/server/zone.cpp @@ -65,10 +65,12 @@ void declareUnit(const std::string& file, ZoneProvisioning::Unit&& unit) } // namespace -Zone::Zone(const std::string& zonesPath, - const std::string& zoneConfigPath, - const std::string& lxcTemplatePrefix, - const std::string& baseRunMountPointPath) +Zone::Zone(const utils::Worker::Pointer& worker, + const std::string& zonesPath, + const std::string& zoneConfigPath, + const std::string& lxcTemplatePrefix, + const std::string& baseRunMountPointPath) + : mWorker(worker) { config::loadFromFile(zoneConfigPath, mConfig); @@ -92,19 +94,9 @@ Zone::~Zone() { // Make sure all OnNameLostCallbacks get finished and no new will // get called before proceeding further. This guarantees no race - // condition on the mReconnectThread. - { - Lock lock(mReconnectMutex); - disconnect(); - } - - if (mReconnectThread.joinable()) { - mReconnectThread.join(); - } - - if (mStartThread.joinable()) { - mStartThread.join(); - } + // condition on the reconnect thread. + Lock lock(mReconnectMutex); + disconnect(); } const std::vector& Zone::getPermittedToSend() const @@ -146,10 +138,6 @@ void Zone::start() void Zone::startAsync(const StartAsyncResultCallback& callback) { - if (mStartThread.joinable()) { - mStartThread.join(); - } - auto startWrapper = [this, callback]() { bool succeeded = false; @@ -165,7 +153,7 @@ void Zone::startAsync(const StartAsyncResultCallback& callback) } }; - mStartThread = std::thread(startWrapper); + mWorker->addTask(startWrapper); } void Zone::stop() @@ -300,10 +288,7 @@ void Zone::onNameLostCallback() { LOGI(getId() << ": A connection to the DBUS server has been lost, reconnecting..."); - if (mReconnectThread.joinable()) { - mReconnectThread.join(); - } - mReconnectThread = std::thread(std::bind(&Zone::reconnectHandler, this)); + mWorker->addTask(std::bind(&Zone::reconnectHandler, this)); } void Zone::reconnectHandler() diff --git a/server/zone.hpp b/server/zone.hpp index 5ee95af..1fdc588 100644 --- a/server/zone.hpp +++ b/server/zone.hpp @@ -30,6 +30,7 @@ #include "zone-admin.hpp" #include "zone-connection.hpp" #include "zone-connection-transport.hpp" +#include "utils/worker.hpp" #include #include @@ -50,10 +51,11 @@ public: * @param lxcTemplatePrefix directory where templates are stored * @param baseRunMountPointPath base directory for run mount point */ - Zone(const std::string& zonesPath, - const std::string& zoneConfigPath, - const std::string& lxcTemplatePrefix, - const std::string& baseRunMountPointPath); + Zone(const utils::Worker::Pointer& worker, + const std::string& zonesPath, + const std::string& zoneConfigPath, + const std::string& lxcTemplatePrefix, + const std::string& baseRunMountPointPath); Zone(Zone&&) = default; virtual ~Zone(); @@ -253,14 +255,13 @@ public: const std::string& target); private: + utils::Worker::Pointer mWorker; ZoneConfig mConfig; std::vector mPermittedToSend; std::vector mPermittedToRecv; std::unique_ptr mConnectionTransport; std::unique_ptr mAdmin; std::unique_ptr mConnection; - std::thread mReconnectThread; - std::thread mStartThread; mutable std::recursive_mutex mReconnectMutex; NotifyActiveZoneCallback mNotifyCallback; DisplayOffCallback mDisplayOffCallback; diff --git a/server/zones-manager.cpp b/server/zones-manager.cpp index 402fc7f..2ce03d7 100644 --- a/server/zones-manager.cpp +++ b/server/zones-manager.cpp @@ -74,7 +74,8 @@ const unsigned int ZONE_IP_BASE_THIRD_OCTET = 100; } // namespace -ZonesManager::ZonesManager(const std::string& managerConfigPath): mDetachOnExit(false) +ZonesManager::ZonesManager(const std::string& managerConfigPath) + : mWorker(utils::Worker::create()), mDetachOnExit(false) { LOGD("Instantiating ZonesManager object..."); @@ -168,32 +169,33 @@ void ZonesManager::createZone(const std::string& zoneConfig) std::string zoneConfigPath = utils::getAbsolutePath(zoneConfig, baseConfigPath); LOGT("Creating Zone " << zoneConfigPath); - std::unique_ptr c(new Zone(mConfig.zonesPath, - zoneConfigPath, - mConfig.lxcTemplatePrefix, - mConfig.runMountPointPrefix)); - const std::string id = c->getId(); + std::unique_ptr zone(new Zone(mWorker->createSubWorker(), + mConfig.zonesPath, + zoneConfigPath, + mConfig.lxcTemplatePrefix, + mConfig.runMountPointPrefix)); + const std::string id = zone->getId(); if (id == HOST_ID) { throw ZoneOperationException("Cannot use reserved zone ID"); } using namespace std::placeholders; - c->setNotifyActiveZoneCallback(bind(&ZonesManager::notifyActiveZoneHandler, - this, id, _1, _2)); + zone->setNotifyActiveZoneCallback(bind(&ZonesManager::notifyActiveZoneHandler, + this, id, _1, _2)); - c->setDisplayOffCallback(bind(&ZonesManager::displayOffHandler, - this, id)); + zone->setDisplayOffCallback(bind(&ZonesManager::displayOffHandler, + this, id)); - c->setFileMoveRequestCallback(bind(&ZonesManager::handleZoneMoveFileRequest, - this, id, _1, _2, _3)); + zone->setFileMoveRequestCallback(bind(&ZonesManager::handleZoneMoveFileRequest, + this, id, _1, _2, _3)); - c->setProxyCallCallback(bind(&ZonesManager::handleProxyCall, - this, id, _1, _2, _3, _4, _5, _6, _7)); + zone->setProxyCallCallback(bind(&ZonesManager::handleProxyCall, + this, id, _1, _2, _3, _4, _5, _6, _7)); - c->setDbusStateChangedCallback(bind(&ZonesManager::handleDbusStateChanged, - this, id, _1)); + zone->setDbusStateChangedCallback(bind(&ZonesManager::handleDbusStateChanged, + this, id, _1)); - mZones.insert(ZoneMap::value_type(id, std::move(c))); + mZones.insert(ZoneMap::value_type(id, std::move(zone))); // after zone is created successfully, put a file informing that zones are enabled if (mZones.size() == 1) { @@ -836,8 +838,7 @@ void ZonesManager::handleDestroyZoneCall(const std::string& id, result->setVoid(); }; - std::thread thread(destroyer); - thread.detach(); //TODO fix it + mWorker->addTask(destroyer); } void ZonesManager::handleLockZoneCall(const std::string& id, diff --git a/server/zones-manager.hpp b/server/zones-manager.hpp index 2fc0305..b58da86 100644 --- a/server/zones-manager.hpp +++ b/server/zones-manager.hpp @@ -31,6 +31,7 @@ #include "host-connection.hpp" #include "input-monitor.hpp" #include "proxy-call-policy.hpp" +#include "utils/worker.hpp" #include #include @@ -105,6 +106,7 @@ public: void setZonesDetachOnExit(); private: + utils::Worker::Pointer mWorker; ZonesManagerConfig mConfig; std::string mConfigPath; HostConnection mHostConnection; diff --git a/tests/unit_tests/server/ut-zone.cpp b/tests/unit_tests/server/ut-zone.cpp index 7d80d66..80e73da 100644 --- a/tests/unit_tests/server/ut-zone.cpp +++ b/tests/unit_tests/server/ut-zone.cpp @@ -63,10 +63,11 @@ struct Fixture { std::unique_ptr create(const std::string& configPath) { - return std::unique_ptr(new Zone(ZONES_PATH, - configPath, - LXC_TEMPLATES_PATH, - "")); + return std::unique_ptr(new Zone(utils::Worker::create(), + ZONES_PATH, + configPath, + LXC_TEMPLATES_PATH, + "")); } void ensureStarted() diff --git a/tests/unit_tests/utils/ut-counting-map.cpp b/tests/unit_tests/utils/ut-counting-map.cpp new file mode 100644 index 0000000..702470f --- /dev/null +++ b/tests/unit_tests/utils/ut-counting-map.cpp @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved + * + * Contact: Piotr Bartosiewicz + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + + +/** + * @file + * @author Piotr Bartosiewicz (p.bartosiewi@partner.samsung.com) + * @brief Unit tests of counting map + */ + +#include "config.hpp" +#include "ut.hpp" + +#include "utils/counting-map.hpp" + +BOOST_AUTO_TEST_SUITE(CountingMapSuite) + +using namespace vasum::utils; + +BOOST_AUTO_TEST_CASE(CountingTest) +{ + CountingMap map; + + BOOST_CHECK(map.empty()); + BOOST_CHECK_EQUAL(0, map.get("ala")); + + BOOST_CHECK_EQUAL(1, map.increment("ala")); + BOOST_CHECK_EQUAL(1, map.increment("ma")); + + BOOST_CHECK(!map.empty()); + BOOST_CHECK_EQUAL(1, map.get("ala")); + BOOST_CHECK_EQUAL(1, map.get("ma")); + BOOST_CHECK_EQUAL(0, map.get("kota")); + + BOOST_CHECK_EQUAL(2, map.increment("ala")); + BOOST_CHECK_EQUAL(2, map.increment("ma")); + BOOST_CHECK_EQUAL(3, map.increment("ma")); + + BOOST_CHECK(!map.empty()); + BOOST_CHECK_EQUAL(2, map.get("ala")); + BOOST_CHECK_EQUAL(3, map.get("ma")); + BOOST_CHECK_EQUAL(0, map.get("kota")); + + BOOST_CHECK_EQUAL(1, map.decrement("ala")); + BOOST_CHECK_EQUAL(0, map.decrement("kota")); + + BOOST_CHECK(!map.empty()); + BOOST_CHECK_EQUAL(1, map.get("ala")); + BOOST_CHECK_EQUAL(3, map.get("ma")); + BOOST_CHECK_EQUAL(0, map.get("kota")); + + BOOST_CHECK_EQUAL(0, map.decrement("ala")); + + BOOST_CHECK(!map.empty()); + BOOST_CHECK_EQUAL(0, map.get("ala")); + BOOST_CHECK_EQUAL(3, map.get("ma")); + BOOST_CHECK_EQUAL(0, map.get("kota")); + + BOOST_CHECK_EQUAL(2, map.decrement("ma")); + BOOST_CHECK_EQUAL(1, map.decrement("ma")); + BOOST_CHECK_EQUAL(0, map.decrement("ma")); + + BOOST_CHECK(map.empty()); +} + +BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/unit_tests/utils/ut-worker.cpp b/tests/unit_tests/utils/ut-worker.cpp new file mode 100644 index 0000000..280889b --- /dev/null +++ b/tests/unit_tests/utils/ut-worker.cpp @@ -0,0 +1,182 @@ +/* + * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved + * + * Contact: Piotr Bartosiewicz + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + + +/** + * @file + * @author Piotr Bartosiewicz (p.bartosiewi@partner.samsung.com) + * @brief Unit tests of worker thread + */ + +#include "config.hpp" +#include "ut.hpp" + +#include "utils/worker.hpp" +#include "utils/latch.hpp" + +#include +#include +#include + +BOOST_AUTO_TEST_SUITE(WorkerSuite) + +using namespace vasum::utils; + +const int unsigned TIMEOUT = 1000; + +BOOST_AUTO_TEST_CASE(NoTasksTest) +{ + Worker::Pointer worker = Worker::create(); +} + +BOOST_AUTO_TEST_CASE(NoTasks2Test) +{ + Worker::Pointer worker = Worker::create(); + Worker::Pointer sub1 = worker->createSubWorker(); + Worker::Pointer sub2 = worker->createSubWorker(); + Worker::Pointer sub3 = sub1->createSubWorker(); + + sub1.reset(); + worker.reset(); +} + +BOOST_AUTO_TEST_CASE(SimpleTest) +{ + Latch done; + + Worker::Pointer worker = Worker::create(); + worker->addTask([&] { + done.set(); + }); + + BOOST_CHECK(done.wait(TIMEOUT)); +} + +BOOST_AUTO_TEST_CASE(QueueTest) +{ + std::mutex mutex; + std::string result; + + Worker::Pointer worker = Worker::create(); + + for (int n=0; n<10; ++n) { + worker->addTask([&, n]{ + std::lock_guard lock(mutex); + result += std::to_string(n); + std::this_thread::sleep_for(std::chrono::milliseconds(10)); + }); + } + + worker.reset(); + + std::lock_guard lock(mutex); + BOOST_CHECK_EQUAL("0123456789", result); +} + +BOOST_AUTO_TEST_CASE(ThreadResumeTest) +{ + Latch done; + + const auto task = [&] { + done.set(); + }; + + Worker::Pointer worker = Worker::create(); + + worker->addTask(task); + + BOOST_CHECK(done.wait(TIMEOUT)); + + // make sure worker thread is in waiting state + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + + worker->addTask(task); + + worker.reset(); + + BOOST_CHECK(done.wait(TIMEOUT)); +} + +BOOST_AUTO_TEST_CASE(SubWorkerTest) +{ + std::mutex mutex; + std::string result; + + Worker::Pointer worker = Worker::create(); + Worker::Pointer sub1 = worker->createSubWorker(); + Worker::Pointer sub2 = worker->createSubWorker(); + + auto addTask = [&](Worker::Pointer w, const std::string& id) { + w->addTask([&, id]{ + std::lock_guard lock(mutex); + result += id; + std::this_thread::sleep_for(std::chrono::milliseconds(10)); + }); + }; + + for (int n=0; n<4; ++n) { + addTask(worker, "_w" + std::to_string(n)); + addTask(sub1, "_a" + std::to_string(n)); + } + + worker.reset(); + sub1.reset(); + + { + std::lock_guard lock(mutex); + BOOST_CHECK_EQUAL("_w0_a0_w1_a1_w2_a2_w3_a3", result); + result.clear(); + } + + addTask(sub2, "_b0"); + addTask(sub2, "_b1"); + + sub2.reset(); + + { + std::lock_guard lock(mutex); + BOOST_CHECK_EQUAL("_b0_b1", result); + } +} + +BOOST_AUTO_TEST_CASE(NoCopyTest) +{ + typedef std::atomic_int Counter; + + struct Task { + Counter& count; + + Task(Counter& c) : count(c) {}; + Task(const Task& t) : count(t.count) {++count;} + Task(Task&& r) : count(r.count) {} + Task& operator=(const Task&) = delete; + Task& operator=(Task&&) = delete; + void operator() () {} + + }; + + Counter copyCount(0); + + Worker::Pointer worker = Worker::create(); + worker->addTask(Task(copyCount)); + worker.reset(); + + BOOST_CHECK_EQUAL(1, copyCount); // one copy for creating std::function +} + +BOOST_AUTO_TEST_SUITE_END() -- 2.7.4 From 6de4eeceb5f669eb2fe71cf0a3d5d755e2663f8d Mon Sep 17 00:00:00 2001 From: Dariusz Michaluk Date: Mon, 15 Dec 2014 12:36:25 +0100 Subject: [PATCH 15/16] Adding support for --vt option in lxc-templates [Bug/Feature] N/A [Cause] N/A [Solution] N/A [Verification] Build, install, run tests Change-Id: I11049b06922f763e168449d43cf6dd9527ea9324 Signed-off-by: Dariusz Michaluk --- server/configs/lxc-templates/template.sh | 3 ++- server/zone-admin.cpp | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/server/configs/lxc-templates/template.sh b/server/configs/lxc-templates/template.sh index c73bd01..e7d5533 100755 --- a/server/configs/lxc-templates/template.sh +++ b/server/configs/lxc-templates/template.sh @@ -2,7 +2,7 @@ echo LXC template, args: $@ -options=$(getopt -o p:n: -l rootfs:,path:,name:,ipv4:,ipv4-gateway: -- "$@") +options=$(getopt -o p:n: -l path:,rootfs:,name:,vt:,ipv4:,ipv4-gateway: -- "$@") if [ $? -ne 0 ]; then exit 1 fi @@ -14,6 +14,7 @@ do -p|--path) path=$2; shift 2;; --rootfs) rootfs=$2; shift 2;; -n|--name) name=$2; shift 2;; + --vt) vt=$2; shift 2;; --ipv4) ipv4=$2; shift 2;; --ipv4-gateway) ipv4_gateway=$2; shift 2;; --) shift 1; break ;; diff --git a/server/zone-admin.cpp b/server/zone-admin.cpp index 42c71ea..46c4974 100644 --- a/server/zone-admin.cpp +++ b/server/zone-admin.cpp @@ -71,6 +71,11 @@ ZoneAdmin::ZoneAdmin(const std::string& zonesPath, args.add("--ipv4"); args.add(config.ipv4.c_str()); } + const std::string vt = std::to_string(config.vt); + if (config.vt > 0) { + args.add("--vt"); + args.add(vt.c_str()); + } if (!mZone.create(lxcTemplate, args.c_array())) { throw ZoneOperationException("Could not create zone"); } -- 2.7.4 From 3bf358a390639906a64f6d9c1487c86be2962ba2 Mon Sep 17 00:00:00 2001 From: Dariusz Michaluk Date: Mon, 15 Dec 2014 13:13:52 +0100 Subject: [PATCH 16/16] Change zonesPath and ExecStart command in service [Bug/Feature] N/A [Cause] N/A [Solution] N/A [Verification] Build, install, run tests Change-Id: Ie51e3bd436f039f926c93b92ea5343e27e7314c0 Signed-off-by: Dariusz Michaluk --- CMakeLists.txt | 4 ++++ packaging/vasum.spec | 3 +++ server/configs/CMakeLists.txt | 5 ++++- server/configs/{daemon.conf => daemon.conf.in} | 4 ++-- server/configs/systemd/vasum.service.in | 2 +- 5 files changed, 14 insertions(+), 4 deletions(-) rename server/configs/{daemon.conf => daemon.conf.in} (84%) diff --git a/CMakeLists.txt b/CMakeLists.txt index cd999d7..a12367f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -152,6 +152,10 @@ IF(NOT DEFINED SYSTEMD_UNIT_DIR) SET(SYSTEMD_UNIT_DIR "${LIB_INSTALL_DIR}/systemd/system") ENDIF(NOT DEFINED SYSTEMD_UNIT_DIR) +IF(NOT DEFINED DATA_DIR) + SET(DATA_DIR "${CMAKE_INSTALL_FULL_DATAROOTDIR}") +ENDIF(NOT DEFINED DATA_DIR) + SET(VSM_CONFIG_INSTALL_DIR ${SYSCONF_INSTALL_DIR}/vasum) SET(VSM_DATA_INSTALL_DIR ${SHARE_INSTALL_PREFIX}/vasum) diff --git a/packaging/vasum.spec b/packaging/vasum.spec index 78db5de..887409e 100644 --- a/packaging/vasum.spec +++ b/packaging/vasum.spec @@ -51,6 +51,7 @@ between them. A process from inside a zone can request a switch of context %{_unitdir}/vasum.service %{_unitdir}/multi-user.target.wants/vasum.service /etc/dbus-1/system.d/org.tizen.vasum.host.conf +%dir %{_datadir}/.zones %prep %setup -q @@ -67,6 +68,7 @@ between them. A process from inside a zone can request a switch of context -DCMAKE_BUILD_TYPE=%{build_type} \ -DSCRIPT_INSTALL_DIR=%{script_dir} \ -DSYSTEMD_UNIT_DIR=%{_unitdir} \ + -DDATA_DIR=%{_datadir} \ -DPYTHON_SITELIB=%{python_sitelib} \ -DVASUM_USER=%{vsm_user} \ -DINPUT_EVENT_GROUP=%{input_event_group} \ @@ -78,6 +80,7 @@ make -k %{?jobs:-j%jobs} %make_install mkdir -p %{buildroot}/%{_unitdir}/multi-user.target.wants ln -s ../vasum.service %{buildroot}/%{_unitdir}/multi-user.target.wants/vasum.service +mkdir -p %{buildroot}/%{_datadir}/.zones %clean rm -rf %{buildroot} diff --git a/server/configs/CMakeLists.txt b/server/configs/CMakeLists.txt index b5c9286..9c0fa4b 100644 --- a/server/configs/CMakeLists.txt +++ b/server/configs/CMakeLists.txt @@ -29,7 +29,10 @@ CONFIGURE_FILE(systemd/vasum.service.in ## Install ##################################################################### -INSTALL(FILES daemon.conf +CONFIGURE_FILE(daemon.conf.in + ${CMAKE_BINARY_DIR}/daemon.conf) + +INSTALL(FILES ${CMAKE_BINARY_DIR}/daemon.conf DESTINATION ${VSM_CONFIG_INSTALL_DIR}) # preprocess d-bus configs diff --git a/server/configs/daemon.conf b/server/configs/daemon.conf.in similarity index 84% rename from server/configs/daemon.conf rename to server/configs/daemon.conf.in index 714640e..296c1c7 100644 --- a/server/configs/daemon.conf +++ b/server/configs/daemon.conf.in @@ -1,7 +1,7 @@ { "zoneConfigs" : ["zones/private.conf", "zones/business.conf"], - "zonesPath" : "/opt/usr/zones", - "zoneImagePath" : "/opt/usr/zones/img/system-data.img", + "zonesPath" : "${DATA_DIR}/.zones", + "zoneImagePath" : "${DATA_DIR}/.zones/img/system-data.img", "zoneTemplatePath" : "templates", "zoneNewConfigPrefix" : "/var/lib/vasum", "runMountPointPrefix" : "/var/run/zones", diff --git a/server/configs/systemd/vasum.service.in b/server/configs/systemd/vasum.service.in index f36622a..8131ed5 100644 --- a/server/configs/systemd/vasum.service.in +++ b/server/configs/systemd/vasum.service.in @@ -4,7 +4,7 @@ ConditionVirtualization=no [Service] Type=simple -ExecStart=${CMAKE_INSTALL_PREFIX}/bin/vasum-server +ExecStart=${CMAKE_INSTALL_PREFIX}/bin/vasum-server -r Restart=on-failure ExecReload=/bin/kill -HUP $MAINPID -- 2.7.4