"switchToDefaultAfterTimeout" : true,
"enableDbusIntegration" : true,
"runMountPoint" : "~NAME~/run",
+ "provisions" : [],
"permittedToSend" : [ "/tmp/.*" ],
"permittedToRecv" : [ "/tmp/.*" ],
"validLinkPrefixes" : [ "/tmp/",
namespace vasum {
-struct ZoneProvisioning
+struct ZoneProvisioningConfig
{
struct File
)
};
- struct Unit
+ struct Provision
{
CONFIG_DECLARE_UNION
(
)
};
- std::vector<Unit> units;
+ std::vector<Provision> provisions;
CONFIG_REGISTER
(
- units
+ provisions
)
};
namespace vasum {
-namespace {
-
-const std::string ZONE_PROVISION_FILE = "provision.conf";
-
-void declareUnit(const std::string& file, ZoneProvisioning::Unit&& unit)
-{
- // TODO: Add to the dynamic configuration
- ZoneProvisioning config;
- if (fs::exists(file)) {
- config::loadFromJsonFile(file, config);
- }
- config.units.push_back(std::move(unit));
- config::saveToJsonFile(file, config);
-}
-
-} // namespace
-
-ZoneProvision::ZoneProvision(const std::string& zonePath,
+ZoneProvision::ZoneProvision(const std::string& rootPath,
+ const std::string& configPath,
+ const std::string& dbPath,
+ const std::string& dbPrefix,
const std::vector<std::string>& validLinkPrefixes)
+ : mRootPath(rootPath)
+ , mDbPath(dbPath)
+ , mDbPrefix(dbPrefix)
+ , mValidLinkPrefixes(validLinkPrefixes)
{
- mProvisionFile = (fs::path(zonePath) / fs::path(ZONE_PROVISION_FILE)).string();
- mRootPath = (zonePath / fs::path("rootfs")).string();
- mValidLinkPrefixes = validLinkPrefixes;
+ config::loadFromKVStoreWithJsonFile(dbPath, configPath, mProvisioningConfig, dbPrefix);
}
ZoneProvision::~ZoneProvision()
stop();
}
-std::string ZoneProvision::getRootPath() const
+void ZoneProvision::saveProvisioningConfig()
{
- return mRootPath;
+ config::saveToKVStore(mDbPath, mProvisioningConfig, mDbPrefix);
}
+void ZoneProvision::declareProvision(ZoneProvisioningConfig::Provision&& provision)
+{
+ mProvisioningConfig.provisions.push_back(std::move(provision));
+ saveProvisioningConfig();
+}
void ZoneProvision::declareFile(const int32_t& type,
const std::string& path,
const int32_t& flags,
const int32_t& mode)
{
- ZoneProvisioning::Unit unit;
- unit.set(ZoneProvisioning::File({type, path, flags, mode}));
+ ZoneProvisioningConfig::Provision provision;
+ provision.set(ZoneProvisioningConfig::File({type, path, flags, mode}));
- declareUnit(mProvisionFile, std::move(unit));
+ declareProvision(std::move(provision));
}
void ZoneProvision::declareMount(const std::string& source,
const int64_t& flags,
const std::string& data)
{
- ZoneProvisioning::Unit unit;
- unit.set(ZoneProvisioning::Mount({source, target, type, flags, data}));
+ ZoneProvisioningConfig::Provision provision;
+ provision.set(ZoneProvisioningConfig::Mount({source, target, type, flags, data}));
- declareUnit(mProvisionFile, std::move(unit));
+ declareProvision(std::move(provision));
}
void ZoneProvision::declareLink(const std::string& source,
const std::string& target)
{
- ZoneProvisioning::Unit unit;
- unit.set(ZoneProvisioning::Link({source, target}));
+ ZoneProvisioningConfig::Provision provision;
+ provision.set(ZoneProvisioningConfig::Link({source, target}));
- declareUnit(mProvisionFile, std::move(unit));
+ declareProvision(std::move(provision));
}
void ZoneProvision::start() noexcept
{
- if (fs::exists(mProvisionFile)) {
- config::loadFromJsonFile(mProvisionFile, mProvisioningConfig);
- for (const auto& unit : mProvisioningConfig.units) {
- try {
- if (unit.is<ZoneProvisioning::File>()) {
- file(unit.as<ZoneProvisioning::File>());
- } else if (unit.is<ZoneProvisioning::Mount>()) {
- mount(unit.as<ZoneProvisioning::Mount>());
- } else if (unit.is<ZoneProvisioning::Link>()) {
- link(unit.as<ZoneProvisioning::Link>());
- }
- // mProvisioned must be FILO
- mProvisioned.push_front(unit);
- } catch (const std::exception& ex) {
- LOGE("Provsion error: " << ex.what());
+ for (const auto& provision : mProvisioningConfig.provisions) {
+ try {
+ if (provision.is<ZoneProvisioningConfig::File>()) {
+ file(provision.as<ZoneProvisioningConfig::File>());
+ } else if (provision.is<ZoneProvisioningConfig::Mount>()) {
+ mount(provision.as<ZoneProvisioningConfig::Mount>());
+ } else if (provision.is<ZoneProvisioningConfig::Link>()) {
+ link(provision.as<ZoneProvisioningConfig::Link>());
}
+ // mProvisioned must be FILO
+ mProvisioned.push_front(provision);
+ } catch (const std::exception& ex) {
+ LOGE("Provsion error: " << ex.what());
}
}
}
void ZoneProvision::stop() noexcept
{
- mProvisioned.remove_if([this](const ZoneProvisioning::Unit& unit) -> bool {
+ mProvisioned.remove_if([this](const ZoneProvisioningConfig::Provision& provision) -> bool {
try {
- if (unit.is<ZoneProvisioning::Mount>()) {
- umount(unit.as<ZoneProvisioning::Mount>());
+ if (provision.is<ZoneProvisioningConfig::Mount>()) {
+ umount(provision.as<ZoneProvisioningConfig::Mount>());
}
// leaves files, links, fifo, untouched
return true;
});
}
-void ZoneProvision::file(const ZoneProvisioning::File& config)
+void ZoneProvision::file(const ZoneProvisioningConfig::File& config)
{
bool ret = false;
const fs::path hostPath = fs::path(mRootPath) / fs::path(config.path);
}
}
-void ZoneProvision::mount(const ZoneProvisioning::Mount& config)
+void ZoneProvision::mount(const ZoneProvisioningConfig::Mount& config)
{
const fs::path hostPath = fs::path(mRootPath) / fs::path(config.target);
bool ret = utils::mount(config.source,
}
}
-void ZoneProvision::umount(const ZoneProvisioning::Mount& config)
+void ZoneProvision::umount(const ZoneProvisioningConfig::Mount& config)
{
const fs::path hostPath = fs::path(mRootPath) / fs::path(config.target);
bool ret = utils::umount(hostPath.string());
}
}
-void ZoneProvision::link(const ZoneProvisioning::Link& config)
+void ZoneProvision::link(const ZoneProvisioningConfig::Link& config)
{
const std::string srcHostPath = fs::path(config.source).normalize().string();
for (const std::string& prefix : mValidLinkPrefixes) {
public:
/**
* ZoneProvision constructor
- * @param zonePath directory where zones are defined (lxc configs, rootfs etc)
+ * @param rootPath zone root path
+ * @param configPath path to config with defaults
+ * @param dbPath path to database
+ * @param dbPrefix database prefix
+ * @param validLinkPrefixes valid link prefixes
*/
- ZoneProvision(const std::string& zonePath,
+ ZoneProvision(const std::string& rootPath,
+ const std::string& configPath,
+ const std::string& dbPath,
+ const std::string& dbPrefix,
const std::vector<std::string>& validLinkPrefixes);
~ZoneProvision();
+ ZoneProvision(const ZoneProvision&) = delete;
+ ZoneProvision& operator=(const ZoneProvision&) = delete;
+ ZoneProvision(ZoneProvision&&) = default;
+
/**
* Declare file, directory or pipe that will be created while zone startup
*/
void declareLink(const std::string& source,
const std::string& target);
- /**
- * Get zone root path
- */
- std::string getRootPath() const;
-
void start() noexcept;
void stop() noexcept;
private:
- ZoneProvisioning mProvisioningConfig;
+ ZoneProvisioningConfig mProvisioningConfig;
std::string mRootPath;
- std::string mProvisionFile;
+ std::string mDbPath;
+ std::string mDbPrefix;
std::vector<std::string> mValidLinkPrefixes;
- std::list<ZoneProvisioning::Unit> mProvisioned;
+ std::list<ZoneProvisioningConfig::Provision> mProvisioned;
+
+ void saveProvisioningConfig();
+ void declareProvision(ZoneProvisioningConfig::Provision&& provision);
- void mount(const ZoneProvisioning::Mount& config);
- void umount(const ZoneProvisioning::Mount& config);
- void file(const ZoneProvisioning::File& config);
- void link(const ZoneProvisioning::Link& config);
+ void mount(const ZoneProvisioningConfig::Mount& config);
+ void umount(const ZoneProvisioningConfig::Mount& config);
+ void file(const ZoneProvisioningConfig::File& config);
+ void link(const ZoneProvisioningConfig::Link& config);
};
// 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 DB_PREFIX = "zone.";
} // namespace
Zone::Zone(const utils::Worker::Pointer& worker,
const std::string& zonesPath,
const std::string& zoneConfigPath,
+ const std::string& dbPath,
const std::string& lxcTemplatePrefix,
const std::string& baseRunMountPointPath)
: mWorker(worker)
}
mAdmin.reset(new ZoneAdmin(zonesPath, lxcTemplatePrefix, mConfig));
+
const fs::path zonePath = fs::path(zonesPath) / mAdmin->getId();
- mProvision.reset(new ZoneProvision(zonePath.string(), mConfig.validLinkPrefixes));
+ mRootPath = (zonePath / fs::path("rootfs")).string();
+ const std::string dbPrefix = DB_PREFIX + mAdmin->getId();
+
+ mProvision.reset(new ZoneProvision(mRootPath, zoneConfigPath, dbPath, dbPrefix, mConfig.validLinkPrefixes));
}
Zone::~Zone()
std::string Zone::getRootPath() const
{
- return mProvision->getRootPath();
+ return mRootPath;
}
-
bool Zone::activateVT()
{
Lock lock(mReconnectMutex);
Zone(const utils::Worker::Pointer& worker,
const std::string& zonesPath,
const std::string& zoneConfigPath,
+ const std::string& dbPath,
const std::string& lxcTemplatePrefix,
const std::string& baseRunMountPointPath);
Zone(Zone&&) = default;
DbusStateChangedCallback mDbusStateChangedCallback;
std::string mDbusAddress;
std::string mRunMountPoint;
+ std::string mRootPath;
void onNameLostCallback();
void reconnectHandler();
std::unique_ptr<Zone> zone(new Zone(mWorker->createSubWorker(),
mConfig.zonesPath,
zoneConfigPath,
+ mConfig.dbPath,
mConfig.lxcTemplatePrefix,
mConfig.runMountPointPrefix));
const std::string id = zone->getId();
it->second->setDestroyOnExit();
mZones.erase(it);
- if (mZones.size() == 0) {
+ if (mZones.empty()) {
if (!utils::removeFile(utils::createFilePath(mConfig.zonesPath, ENABLED_FILE_NAME))) {
LOGE("Failed to remove enabled file.");
}
/**
* Create new zone.
*
- * @param zoneConfig config of new zone
+ * @param zoneConfigPath config of new zone
*/
void createZone(const std::string& zoneConfigPath);
"cpuQuotaForeground" : -1,
"cpuQuotaBackground" : 1000,
"runMountPoint" : "/tmp/ut-run/ut-zones-manager-console1-dbus",
+ "provisions" : [],
"permittedToSend" : [ "/tmp/.*", "/etc/secret2" ],
"permittedToRecv" : [ "/tmp/.*" ],
"validLinkPrefixes" : []
"cpuQuotaForeground" : -1,
"cpuQuotaBackground" : 1000,
"runMountPoint" : "/tmp/ut-run/ut-zones-manager-console2-dbus",
+ "provisions" : [],
"permittedToSend" : [ "/tmp/.*" ],
"permittedToRecv" : [ "/tmp/.*", "/etc/secret1" ],
"validLinkPrefixes" : []
"cpuQuotaForeground" : -1,
"cpuQuotaBackground" : 1000,
"runMountPoint" : "/tmp/ut-run/ut-zones-manager-console3-dbus",
+ "provisions" : [],
"permittedToSend" : [ "/tmp/.*" ],
"permittedToRecv" : [ "/tmp/.*" ],
"validLinkPrefixes" : []
FILE(GLOB zone_CONF ut-zone/*.conf)
FILE(GLOB zone_zone_CONF ut-zone/zones/*.conf)
+FILE(GLOB zone_provision_CONF ut-zone-provision/*.conf)
+
FILE(GLOB admin_zone_CONF ut-zone-admin/zones/*.conf)
FILE(GLOB connection_CONF ut-zone-connection/*.conf)
INSTALL(FILES ${zone_zone_CONF_GEN}
DESTINATION ${VSM_TEST_CONFIG_INSTALL_DIR}/server/ut-zone/zones)
+INSTALL(FILES ${zone_provision_CONF}
+ DESTINATION ${VSM_TEST_CONFIG_INSTALL_DIR}/server/ut-zone-provision)
+
INSTALL(FILES ${admin_zone_CONF}
DESTINATION ${VSM_TEST_CONFIG_INSTALL_DIR}/server/ut-zone-admin/zones)
"cpuQuotaForeground" : -1,
"cpuQuotaBackground" : 1000,
"runMountPoint" : "",
+ "provisions" : [],
"permittedToSend" : [],
"permittedToRecv" : [],
"validLinkPrefixes" : []
"cpuQuotaForeground" : -1,
"cpuQuotaBackground" : 1000,
"runMountPoint" : "",
+ "provisions" : [],
"permittedToSend" : [],
"permittedToRecv" : [],
"validLinkPrefixes" : []
"cpuQuotaForeground" : -1,
"cpuQuotaBackground" : 1000,
"runMountPoint" : "",
+ "provisions" : [],
"permittedToSend" : [],
"permittedToRecv" : [],
"validLinkPrefixes" : []
"cpuQuotaForeground" : -1,
"cpuQuotaBackground" : 1000,
"runMountPoint" : "",
+ "provisions" : [],
"permittedToSend" : [],
"permittedToRecv" : [],
"validLinkPrefixes" : []
"cpuQuotaForeground" : -1,
"cpuQuotaBackground" : 1000,
"runMountPoint" : "",
+ "provisions" : [],
"permittedToSend" : [],
"permittedToRecv" : [],
"validLinkPrefixes" : []
"cpuQuotaForeground" : -1,
"cpuQuotaBackground" : 1000,
"runMountPoint" : "",
+ "provisions" : [],
"permittedToSend" : [],
"permittedToRecv" : [],
"validLinkPrefixes" : []
"cpuQuotaForeground" : -1,
"cpuQuotaBackground" : 1000,
"runMountPoint" : "",
+ "provisions" : [],
"permittedToSend" : [],
"permittedToRecv" : [],
"validLinkPrefixes" : []
--- /dev/null
+{
+ "provisions" : []
+}
"cpuQuotaForeground" : -1,
"cpuQuotaBackground" : 1000,
"runMountPoint" : "",
+ "provisions" : [],
"permittedToSend" : [],
"permittedToRecv" : [],
"validLinkPrefixes" : []
"cpuQuotaForeground" : -1,
"cpuQuotaBackground" : 1000,
"runMountPoint" : "/tmp/ut-run/ut-zone-test-dbus",
+ "provisions" : [],
"permittedToSend" : [],
"permittedToRecv" : [],
"validLinkPrefixes" : []
"cpuQuotaForeground" : -1,
"cpuQuotaBackground" : 1000,
"runMountPoint" : "",
+ "provisions" : [],
"permittedToSend" : [],
"permittedToRecv" : [],
"validLinkPrefixes" : [ "/tmp" ]
"cpuQuotaForeground" : -1,
"cpuQuotaBackground" : 1000,
"runMountPoint" : "/tmp/ut-run/~NAME~",
+ "provisions" : [],
"permittedToSend" : [ "/tmp/.*" ],
"permittedToRecv" : [ "/tmp/.*" ],
"validLinkPrefixes" : []
"cpuQuotaForeground" : -1,
"cpuQuotaBackground" : 1000,
"runMountPoint" : "/tmp/ut-run/ut-zones-manager-console1-dbus",
+ "provisions" : [],
"permittedToSend" : [ "/tmp/.*", "/etc/secret2" ],
"permittedToRecv" : [ "/tmp/.*" ],
"validLinkPrefixes" : []
"cpuQuotaForeground" : -1,
"cpuQuotaBackground" : 1000,
"runMountPoint" : "",
+ "provisions" : [],
"permittedToSend" : [ "/tmp/.*" ],
"permittedToRecv" : [ "/tmp/.*" ],
"validLinkPrefixes" : []
"cpuQuotaForeground" : -1,
"cpuQuotaBackground" : 1000,
"runMountPoint" : "/tmp/ut-run/ut-zones-manager-console2-dbus",
+ "provisions" : [],
"permittedToSend" : [ "/tmp/.*" ],
"permittedToRecv" : [ "/tmp/.*", "/etc/secret1" ],
"validLinkPrefixes" : []
"cpuQuotaForeground" : -1,
"cpuQuotaBackground" : 1000,
"runMountPoint" : "",
+ "provisions" : [],
"permittedToSend" : [ "/tmp/.*" ],
"permittedToRecv" : [ "/tmp/.*" ],
"validLinkPrefixes" : []
"cpuQuotaForeground" : -1,
"cpuQuotaBackground" : 1000,
"runMountPoint" : "/tmp/ut-run/ut-zones-manager-console3-dbus",
+ "provisions" : [],
"permittedToSend" : [ "/tmp/.*" ],
"permittedToRecv" : [ "/tmp/.*" ],
"validLinkPrefixes" : []
"cpuQuotaForeground" : -1,
"cpuQuotaBackground" : 1000,
"runMountPoint" : "",
+ "provisions" : [],
"permittedToSend" : [ "/tmp/.*" ],
"permittedToRecv" : [ "/tmp/.*" ],
"validLinkPrefixes" : []
#include "utils/scoped-dir.hpp"
#include "utils/exception.hpp"
+#include "utils/fs.hpp"
#include "config/manager.hpp"
#include "zone-provision.hpp"
#include "zone-provision-config.hpp"
namespace {
-const std::string PROVISON_CONFIG_FILE = "provision.conf";
+const std::string TEST_CONFIG_PATH = VSM_TEST_CONFIG_INSTALL_DIR "/server/ut-zone-provision/test.conf";
const std::string ZONE = "ut-zone-provision-test";
const fs::path ZONES_PATH = "/tmp/ut-zones";
const fs::path LXC_TEMPLATES_PATH = VSM_TEST_LXC_TEMPLATES_INSTALL_DIR;
const fs::path ZONE_PATH = ZONES_PATH / fs::path(ZONE);
-const fs::path PROVISION_FILE_PATH = ZONE_PATH / fs::path(PROVISON_CONFIG_FILE);
-const fs::path ROOTFS_PATH = ZONE_PATH / fs::path("rootfs");
+const fs::path SOME_FILE_PATH = ZONE_PATH / "file.txt";
+const fs::path ROOTFS_PATH = ZONE_PATH / "rootfs";
+const fs::path DB_PATH = ZONES_PATH / "vasum.db";
+const std::string DB_PREFIX = "zone";
struct Fixture {
utils::ScopedDir mZonesPathGuard;
: mZonesPathGuard(ZONES_PATH.string())
, mRootfsPath(ROOTFS_PATH.string())
{
+ BOOST_REQUIRE(utils::saveFileContent(SOME_FILE_PATH.string(), "text"));
+ }
+
+ ZoneProvision create(const std::vector<std::string>& validLinkPrefixes)
+ {
+ return ZoneProvision(ROOTFS_PATH.string(),
+ TEST_CONFIG_PATH,
+ DB_PATH.string(),
+ DB_PREFIX,
+ validLinkPrefixes);
+ }
+
+ void load(ZoneProvisioningConfig& config)
+ {
+ config::loadFromKVStoreWithJsonFile(DB_PATH.string(), TEST_CONFIG_PATH, config, DB_PREFIX);
+ }
+
+ void save(const ZoneProvisioningConfig& config)
+ {
+ config::saveToKVStore(DB_PATH.string(), config, DB_PREFIX);
}
};
{
utils::ScopedDir provisionfs(mountSource.string());
- ZoneProvisioning config;
- ZoneProvisioning::Unit unit;
- unit.set(ZoneProvisioning::File({VSMFILE_DIRECTORY,
+ ZoneProvisioningConfig config;
+ ZoneProvisioningConfig::Provision provision;
+ provision.set(ZoneProvisioningConfig::File({VSMFILE_DIRECTORY,
mountTarget.string(),
0,
0777}));
- config.units.push_back(unit);
- unit.set(ZoneProvisioning::Mount({mountSource.string(),
+ config.provisions.push_back(provision);
+ provision.set(ZoneProvisioningConfig::Mount({mountSource.string(),
mountTarget.string(),
"",
MS_BIND,
""}));
- config.units.push_back(unit);
+ config.provisions.push_back(provision);
+ save(config);
- config::saveToJsonFile(PROVISION_FILE_PATH.string(), config);
- ZoneProvision zoneProvision(ZONE_PATH.string(), {});
+ ZoneProvision zoneProvision = create({});
zoneProvision.start();
}
BOOST_CHECK(!fs::exists(mountSource));
{
//TODO: Test Fifo
const fs::path regularFile = fs::path("/opt/usr/data/ut-regular-file");
- const fs::path copyFile = PROVISION_FILE_PATH;
+ const fs::path copyFile = SOME_FILE_PATH;
- ZoneProvisioning config;
- ZoneProvisioning::Unit unit;
- unit.set(ZoneProvisioning::File({VSMFILE_DIRECTORY,
+ ZoneProvisioningConfig config;
+ ZoneProvisioningConfig::Provision provision;
+ provision.set(ZoneProvisioningConfig::File({VSMFILE_DIRECTORY,
regularFile.parent_path().string(),
0,
0777}));
- config.units.push_back(unit);
+ config.provisions.push_back(provision);
- unit.set(ZoneProvisioning::File({VSMFILE_REGULAR,
+ provision.set(ZoneProvisioningConfig::File({VSMFILE_REGULAR,
regularFile.string(),
O_CREAT,
0777}));
- config.units.push_back(unit);
+ config.provisions.push_back(provision);
- unit.set(ZoneProvisioning::File({VSMFILE_DIRECTORY,
+ provision.set(ZoneProvisioningConfig::File({VSMFILE_DIRECTORY,
copyFile.parent_path().string(),
0,
0777}));
- config.units.push_back(unit);
- unit.set(ZoneProvisioning::File({VSMFILE_REGULAR,
+ config.provisions.push_back(provision);
+ provision.set(ZoneProvisioningConfig::File({VSMFILE_REGULAR,
copyFile.string(),
0,
0777}));
- config.units.push_back(unit);
- config::saveToJsonFile(PROVISION_FILE_PATH.string(), config);
+ config.provisions.push_back(provision);
+ save(config);
- ZoneProvision zoneProvision(ZONE_PATH.string(), {});
+ ZoneProvision zoneProvision = create({});
zoneProvision.start();
BOOST_CHECK(fs::exists(ROOTFS_PATH / regularFile.parent_path()));
utils::ScopedDir provisionfs(mountSource.string());
- ZoneProvisioning config;
- ZoneProvisioning::Unit unit;
- unit.set(ZoneProvisioning::File({VSMFILE_DIRECTORY,
+ ZoneProvisioningConfig config;
+ ZoneProvisioningConfig::Provision provision;
+ provision.set(ZoneProvisioningConfig::File({VSMFILE_DIRECTORY,
mountTarget.string(),
0,
0777}));
- config.units.push_back(unit);
- unit.set(ZoneProvisioning::Mount({mountSource.string(),
+ config.provisions.push_back(provision);
+ provision.set(ZoneProvisioningConfig::Mount({mountSource.string(),
mountTarget.string(),
"",
MS_BIND,
""}));
- config.units.push_back(unit);
- unit.set(ZoneProvisioning::File({VSMFILE_REGULAR,
+ config.provisions.push_back(provision);
+ provision.set(ZoneProvisioningConfig::File({VSMFILE_REGULAR,
(mountTarget / sharedFile).string(),
O_CREAT,
0777}));
- config.units.push_back(unit);
- config::saveToJsonFile(PROVISION_FILE_PATH.string(), config);
+ config.provisions.push_back(provision);
+ save(config);
- ZoneProvision zoneProvision(ZONE_PATH.string(), {});
+ ZoneProvision zoneProvision = create({});
zoneProvision.start();
BOOST_CHECK(fs::exists(ROOTFS_PATH / mountTarget));
BOOST_AUTO_TEST_CASE(LinkTest)
{
- const fs::path linkFile = fs::path("/ut-from-host-provision.conf");
+ const fs::path linkFile = fs::path("/ut-from-host-file.txt");
- ZoneProvisioning config;
- ZoneProvisioning::Unit unit;
+ ZoneProvisioningConfig config;
+ ZoneProvisioningConfig::Provision provision;
- unit.set(ZoneProvisioning::Link({PROVISION_FILE_PATH.string(),
+ provision.set(ZoneProvisioningConfig::Link({SOME_FILE_PATH.string(),
linkFile.string()}));
- config.units.push_back(unit);
- config::saveToJsonFile(PROVISION_FILE_PATH.string(), config);
+ config.provisions.push_back(provision);
+ save(config);
{
- ZoneProvision zoneProvision(ZONE_PATH.string(), {});
+ ZoneProvision zoneProvision = create({});
zoneProvision.start();
BOOST_CHECK(!fs::exists(ROOTFS_PATH / linkFile));
zoneProvision.stop();
}
{
- ZoneProvision zoneProvision(ZONE_PATH.string(), {"/tmp/"});
+ ZoneProvision zoneProvision = create({"/tmp/"});
zoneProvision.start();
BOOST_CHECK(fs::exists(ROOTFS_PATH / linkFile));
BOOST_AUTO_TEST_CASE(DeclareFileTest)
{
- ZoneProvision zoneProvision(ZONE_PATH.string(), {});
+ ZoneProvision zoneProvision = create({});
zoneProvision.declareFile(1, "path", 0747, 0777);
zoneProvision.declareFile(2, "path", 0747, 0777);
- ZoneProvisioning config;
- BOOST_REQUIRE_NO_THROW(loadFromJsonFile(PROVISION_FILE_PATH.string(), config));
- BOOST_REQUIRE_EQUAL(config.units.size(), 2);
- BOOST_REQUIRE(config.units[0].is<ZoneProvisioning::File>());
- BOOST_REQUIRE(config.units[1].is<ZoneProvisioning::File>());
- const ZoneProvisioning::File& unit = config.units[0].as<ZoneProvisioning::File>();
- BOOST_CHECK_EQUAL(unit.type, 1);
- BOOST_CHECK_EQUAL(unit.path, "path");
- BOOST_CHECK_EQUAL(unit.flags, 0747);
- BOOST_CHECK_EQUAL(unit.mode, 0777);
+ ZoneProvisioningConfig config;
+ load(config);
+ BOOST_REQUIRE_EQUAL(config.provisions.size(), 2);
+ BOOST_REQUIRE(config.provisions[0].is<ZoneProvisioningConfig::File>());
+ BOOST_REQUIRE(config.provisions[1].is<ZoneProvisioningConfig::File>());
+ const ZoneProvisioningConfig::File& provision = config.provisions[0].as<ZoneProvisioningConfig::File>();
+ BOOST_CHECK_EQUAL(provision.type, 1);
+ BOOST_CHECK_EQUAL(provision.path, "path");
+ BOOST_CHECK_EQUAL(provision.flags, 0747);
+ BOOST_CHECK_EQUAL(provision.mode, 0777);
}
BOOST_AUTO_TEST_CASE(DeclareMountTest)
{
- ZoneProvision zoneProvision(ZONE_PATH.string(), {});
+ ZoneProvision zoneProvision = create({});
zoneProvision.declareMount("/fake/path1", "/fake/path2", "tmpfs", 077, "fake");
zoneProvision.declareMount("/fake/path2", "/fake/path2", "tmpfs", 077, "fake");
- ZoneProvisioning config;
- BOOST_REQUIRE_NO_THROW(loadFromJsonFile(PROVISION_FILE_PATH.string(), config));
- BOOST_REQUIRE_EQUAL(config.units.size(), 2);
- BOOST_REQUIRE(config.units[0].is<ZoneProvisioning::Mount>());
- BOOST_REQUIRE(config.units[1].is<ZoneProvisioning::Mount>());
- const ZoneProvisioning::Mount& unit = config.units[0].as<ZoneProvisioning::Mount>();
- 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");
+ ZoneProvisioningConfig config;
+ load(config);
+ BOOST_REQUIRE_EQUAL(config.provisions.size(), 2);
+ BOOST_REQUIRE(config.provisions[0].is<ZoneProvisioningConfig::Mount>());
+ BOOST_REQUIRE(config.provisions[1].is<ZoneProvisioningConfig::Mount>());
+ const ZoneProvisioningConfig::Mount& provision = config.provisions[0].as<ZoneProvisioningConfig::Mount>();
+ BOOST_CHECK_EQUAL(provision.source, "/fake/path1");
+ BOOST_CHECK_EQUAL(provision.target, "/fake/path2");
+ BOOST_CHECK_EQUAL(provision.type, "tmpfs");
+ BOOST_CHECK_EQUAL(provision.flags, 077);
+ BOOST_CHECK_EQUAL(provision.data, "fake");
}
BOOST_AUTO_TEST_CASE(DeclareLinkTest)
{
- ZoneProvision zoneProvision(ZONE_PATH.string(), {});
+ ZoneProvision zoneProvision = create({});
zoneProvision.declareLink("/fake/path1", "/fake/path2");
zoneProvision.declareLink("/fake/path2", "/fake/path2");
- ZoneProvisioning config;
- BOOST_REQUIRE_NO_THROW(loadFromJsonFile(PROVISION_FILE_PATH.string(), config));
- BOOST_REQUIRE_EQUAL(config.units.size(), 2);
- BOOST_REQUIRE(config.units[0].is<ZoneProvisioning::Link>());
- BOOST_REQUIRE(config.units[1].is<ZoneProvisioning::Link>());
- const ZoneProvisioning::Link& unit = config.units[0].as<ZoneProvisioning::Link>();
- BOOST_CHECK_EQUAL(unit.source, "/fake/path1");
- BOOST_CHECK_EQUAL(unit.target, "/fake/path2");
+ ZoneProvisioningConfig config;
+ load(config);
+ BOOST_REQUIRE_EQUAL(config.provisions.size(), 2);
+ BOOST_REQUIRE(config.provisions[0].is<ZoneProvisioningConfig::Link>());
+ BOOST_REQUIRE(config.provisions[1].is<ZoneProvisioningConfig::Link>());
+ const ZoneProvisioningConfig::Link& provision = config.provisions[0].as<ZoneProvisioningConfig::Link>();
+ BOOST_CHECK_EQUAL(provision.source, "/fake/path1");
+ BOOST_CHECK_EQUAL(provision.target, "/fake/path2");
}
BOOST_AUTO_TEST_CASE(ProvisionedAlreadyTest)
{
- const fs::path dir = fs::path("/opt/usr/data/ut-from-host-provision");
- const fs::path linkFile = fs::path("/ut-from-host-provision.conf");
+ const fs::path dir = fs::path("/opt/usr/data/ut-from-host");
+ const fs::path linkFile = fs::path("/ut-from-host-file.txt");
const fs::path regularFile = fs::path("/opt/usr/data/ut-regular-file");
- ZoneProvisioning config;
- ZoneProvisioning::Unit unit;
- unit.set(ZoneProvisioning::File({VSMFILE_DIRECTORY,
+ ZoneProvisioningConfig config;
+ ZoneProvisioningConfig::Provision provision;
+ provision.set(ZoneProvisioningConfig::File({VSMFILE_DIRECTORY,
dir.string(),
0,
0777}));
- config.units.push_back(unit);
- unit.set(ZoneProvisioning::Link({PROVISION_FILE_PATH.string(),
+ config.provisions.push_back(provision);
+ provision.set(ZoneProvisioningConfig::Link({SOME_FILE_PATH.string(),
linkFile.string()}));
- config.units.push_back(unit);
- unit.set(ZoneProvisioning::File({VSMFILE_REGULAR,
+ config.provisions.push_back(provision);
+ provision.set(ZoneProvisioningConfig::File({VSMFILE_REGULAR,
regularFile.string(),
O_CREAT,
0777}));
- config.units.push_back(unit);
-
- config::saveToJsonFile(PROVISION_FILE_PATH.string(), config);
+ config.provisions.push_back(provision);
+ save(config);
- ZoneProvision zoneProvision(ZONE_PATH.string(), {"/tmp/"});
+ ZoneProvision zoneProvision = create({"/tmp/"});
zoneProvision.start();
BOOST_CHECK(fs::exists(ROOTFS_PATH / dir));
const std::string MISSING_CONFIG_PATH = "/this/is/a/missing/file/path/config.conf";
const std::string ZONES_PATH = "/tmp/ut-zones";
const std::string LXC_TEMPLATES_PATH = VSM_TEST_LXC_TEMPLATES_INSTALL_DIR;
+const std::string DB_PATH = ZONES_PATH + "/vasum.db";
struct Fixture {
utils::ScopedGlibLoop mLoop;
return std::unique_ptr<Zone>(new Zone(utils::Worker::create(),
ZONES_PATH,
configPath,
+ DB_PATH,
LXC_TEMPLATES_PATH,
""));
}