Unit tests configs refactor 79/31379/1
authorPiotr Bartosiewicz <p.bartosiewi@partner.samsung.com>
Thu, 4 Dec 2014 12:03:24 +0000 (13:03 +0100)
committerPiotr Bartosiewicz <p.bartosiewi@partner.samsung.com>
Thu, 4 Dec 2014 12:03:24 +0000 (13:03 +0100)
[Bug/Feature]   There was no possibility to test adding multiple zones
                using templates
[Cause]         N/A
[Solution]      N/A
[Verification]  Build, install, run tests

Change-Id: Ie5ea1c2c2a227e0bb4ed9d02aa2965e5b2443f44

14 files changed:
tests/unit_tests/client/configs/ut-client/containers/console1-dbus.conf.in
tests/unit_tests/client/configs/ut-client/containers/console2-dbus.conf.in
tests/unit_tests/client/configs/ut-client/containers/console3-dbus.conf.in
tests/unit_tests/client/ut-client.cpp
tests/unit_tests/lxc/templates/minimal-dbus.sh [moved from tests/unit_tests/lxc/templates/minimal-dbus1.sh with 95% similarity]
tests/unit_tests/lxc/templates/minimal-dbus2.sh [deleted file]
tests/unit_tests/lxc/templates/minimal-dbus3.sh [deleted file]
tests/unit_tests/server/configs/ut-container/containers/test-dbus.conf.in
tests/unit_tests/server/configs/ut-containers-manager/containers/console1-dbus.conf.in
tests/unit_tests/server/configs/ut-containers-manager/containers/console2-dbus.conf.in
tests/unit_tests/server/configs/ut-containers-manager/containers/console3-dbus.conf.in
tests/unit_tests/server/configs/ut-containers-manager/templates/template.conf.in
tests/unit_tests/server/ut-container.cpp
tests/unit_tests/server/ut-containers-manager.cpp

index bf8d1fc..267a812 100644 (file)
@@ -1,6 +1,6 @@
 {
     "name" : "ut-containers-manager-console1-dbus",
-    "lxcTemplate" : "minimal-dbus1.sh",
+    "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"],
     "ipv4Gateway" : "",
     "ipv4" : "",
@@ -10,7 +10,7 @@
     "enableDbusIntegration" : true,
     "cpuQuotaForeground" : -1,
     "cpuQuotaBackground" : 1000,
-    "runMountPoint" : "/tmp/ut-run1",
+    "runMountPoint" : "/tmp/ut-run/ut-containers-manager-console1-dbus",
     "permittedToSend" : [ "/tmp/.*", "/etc/secret2" ],
     "permittedToRecv" : [ "/tmp/.*" ]
 }
index 73ff1b3..f050525 100644 (file)
@@ -1,6 +1,6 @@
 {
     "name" : "ut-containers-manager-console2-dbus",
-    "lxcTemplate" : "minimal-dbus2.sh",
+    "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"],
     "ipv4Gateway" : "",
     "ipv4" : "",
@@ -10,7 +10,7 @@
     "enableDbusIntegration" : true,
     "cpuQuotaForeground" : -1,
     "cpuQuotaBackground" : 1000,
-    "runMountPoint" : "/tmp/ut-run2",
+    "runMountPoint" : "/tmp/ut-run/ut-containers-manager-console2-dbus",
     "permittedToSend" : [ "/tmp/.*" ],
     "permittedToRecv" : [ "/tmp/.*", "/etc/secret1" ]
 }
index c8a0a01..b78ac71 100644 (file)
@@ -1,6 +1,6 @@
 {
     "name" : "ut-containers-manager-console3-dbus",
-    "lxcTemplate" : "minimal-dbus3.sh",
+    "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"],
     "ipv4Gateway" : "",
     "ipv4" : "",
@@ -10,7 +10,7 @@
     "enableDbusIntegration" : true,
     "cpuQuotaForeground" : -1,
     "cpuQuotaBackground" : 1000,
-    "runMountPoint" : "/tmp/ut-run3",
+    "runMountPoint" : "/tmp/ut-run/ut-containers-manager-console3-dbus",
     "permittedToSend" : [ "/tmp/.*" ],
     "permittedToRecv" : [ "/tmp/.*" ]
 }
index 838f8bf..1240e51 100644 (file)
@@ -63,17 +63,13 @@ struct Loop {
 struct Fixture {
     Loop loop;
     utils::ScopedDir mContainersPathGuard;
-    utils::ScopedDir mRun1Guard;
-    utils::ScopedDir mRun2Guard;
-    utils::ScopedDir mRun3Guard;
+    utils::ScopedDir mRunGuard;
 
     ContainersManager cm;
 
     Fixture()
         : mContainersPathGuard(CONTAINERS_PATH)
-        , mRun1Guard("/tmp/ut-run1")
-        , mRun2Guard("/tmp/ut-run2")
-        , mRun3Guard("/tmp/ut-run3")
+        , mRunGuard("/tmp/ut-run")
         , cm(TEST_DBUS_CONFIG_PATH)
     {
         cm.startAll();
@@ -84,15 +80,15 @@ const int EVENT_TIMEOUT = 5000; ///< ms
 const std::map<std::string, std::string> EXPECTED_DBUSES_STARTED = {
     {
         "ut-containers-manager-console1-dbus",
-        "unix:path=/tmp/ut-run1/dbus/system_bus_socket"
+        "unix:path=/tmp/ut-run/ut-containers-manager-console1-dbus/dbus/system_bus_socket"
     },
     {
         "ut-containers-manager-console2-dbus",
-        "unix:path=/tmp/ut-run2/dbus/system_bus_socket"
+        "unix:path=/tmp/ut-run/ut-containers-manager-console2-dbus/dbus/system_bus_socket"
     },
     {
         "ut-containers-manager-console3-dbus",
-        "unix:path=/tmp/ut-run3/dbus/system_bus_socket"
+        "unix:path=/tmp/ut-run/ut-containers-manager-console3-dbus/dbus/system_bus_socket"
     }
 };
 
similarity index 95%
rename from tests/unit_tests/lxc/templates/minimal-dbus1.sh
rename to tests/unit_tests/lxc/templates/minimal-dbus.sh
index ff1f2de..82c76e8 100755 (executable)
@@ -65,7 +65,7 @@ lxc.mount.entry = /lib lib none ro,bind 0 0
 lxc.mount.entry = /sbin sbin none ro,bind 0 0
 lxc.mount.entry = /usr usr none ro,rbind 0 0
 lxc.mount.entry = /opt opt none ro,rbind 0 0
-lxc.mount.entry = /tmp/ut-run1 var/run none rw,bind 0 0
+lxc.mount.entry = /tmp/ut-run/${name} var/run none rw,bind 0 0
 EOF
 
 if [ "$(uname -m)" = "x86_64" ]; then
diff --git a/tests/unit_tests/lxc/templates/minimal-dbus2.sh b/tests/unit_tests/lxc/templates/minimal-dbus2.sh
deleted file mode 100755 (executable)
index 86984b7..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-#!/bin/bash
-
-echo UnitTest LXC template, args: $@
-
-options=$(getopt -o p:n: -l rootfs:,path:,name: -- "$@")
-if [ $? -ne 0 ]; then
-    exit 1
-fi
-eval set -- "$options"
-
-while true
-do
-    case "$1" in
-        -p|--path)      path=$2; shift 2;;
-        --rootfs)       rootfs=$2; shift 2;;
-        -n|--name)      name=$2; shift 2;;
-        --)             shift 1; break ;;
-        *)              break ;;
-    esac
-done
-
-# Prepare container rootfs
-ROOTFS_DIRS="\
-${rootfs}/bin \
-${rootfs}/dev \
-${rootfs}/dev/pts \
-${rootfs}/etc \
-${rootfs}/home \
-${rootfs}/lib \
-${rootfs}/lib64 \
-${rootfs}/proc \
-${rootfs}/root \
-${rootfs}/run \
-${rootfs}/sbin \
-${rootfs}/sys \
-${rootfs}/tmp \
-${rootfs}/usr \
-${rootfs}/opt \
-${rootfs}/var \
-${rootfs}/var/run
-"
-/bin/mkdir ${ROOTFS_DIRS}
-
-# Prepare container configuration file
-> ${path}/config
-cat <<EOF >> ${path}/config
-lxc.utsname = ${name}
-lxc.rootfs = ${rootfs}
-
-# userns 1-to-1 mapping
-lxc.id_map = u 0 0 65536
-lxc.id_map = g 0 0 65536
-
-lxc.haltsignal = SIGTERM
-
-lxc.pts = 256
-lxc.tty = 0
-
-lxc.cgroup.devices.deny = a
-
-lxc.mount.auto = proc sys cgroup
-lxc.mount.entry = /bin bin none ro,bind 0 0
-lxc.mount.entry = /etc etc none ro,bind 0 0
-lxc.mount.entry = /lib lib none ro,bind 0 0
-lxc.mount.entry = /sbin sbin none ro,bind 0 0
-lxc.mount.entry = /usr usr none ro,rbind 0 0
-lxc.mount.entry = /opt opt none ro,rbind 0 0
-lxc.mount.entry = /tmp/ut-run2 var/run none rw,bind 0 0
-EOF
-
-if [ "$(uname -m)" = "x86_64" ]; then
-cat <<EOF >> $path/config
-lxc.mount.entry = /lib64 lib64 none ro,bind 0 0
-EOF
-fi
-
diff --git a/tests/unit_tests/lxc/templates/minimal-dbus3.sh b/tests/unit_tests/lxc/templates/minimal-dbus3.sh
deleted file mode 100755 (executable)
index 034b4fd..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-#!/bin/bash
-
-echo UnitTest LXC template, args: $@
-
-options=$(getopt -o p:n: -l rootfs:,path:,name: -- "$@")
-if [ $? -ne 0 ]; then
-    exit 1
-fi
-eval set -- "$options"
-
-while true
-do
-    case "$1" in
-        -p|--path)      path=$2; shift 2;;
-        --rootfs)       rootfs=$2; shift 2;;
-        -n|--name)      name=$2; shift 2;;
-        --)             shift 1; break ;;
-        *)              break ;;
-    esac
-done
-
-# Prepare container rootfs
-ROOTFS_DIRS="\
-${rootfs}/bin \
-${rootfs}/dev \
-${rootfs}/dev/pts \
-${rootfs}/etc \
-${rootfs}/home \
-${rootfs}/lib \
-${rootfs}/lib64 \
-${rootfs}/proc \
-${rootfs}/root \
-${rootfs}/run \
-${rootfs}/sbin \
-${rootfs}/sys \
-${rootfs}/tmp \
-${rootfs}/usr \
-${rootfs}/opt \
-${rootfs}/var \
-${rootfs}/var/run
-"
-/bin/mkdir ${ROOTFS_DIRS}
-
-# Prepare container configuration file
-> ${path}/config
-cat <<EOF >> ${path}/config
-lxc.utsname = ${name}
-lxc.rootfs = ${rootfs}
-
-# userns 1-to-1 mapping
-lxc.id_map = u 0 0 65536
-lxc.id_map = g 0 0 65536
-
-lxc.haltsignal = SIGTERM
-
-lxc.pts = 256
-lxc.tty = 0
-
-lxc.cgroup.devices.deny = a
-
-lxc.mount.auto = proc sys cgroup
-lxc.mount.entry = /bin bin none ro,bind 0 0
-lxc.mount.entry = /etc etc none ro,bind 0 0
-lxc.mount.entry = /lib lib none ro,bind 0 0
-lxc.mount.entry = /sbin sbin none ro,bind 0 0
-lxc.mount.entry = /usr usr none ro,rbind 0 0
-lxc.mount.entry = /opt opt none ro,rbind 0 0
-lxc.mount.entry = /tmp/ut-run3 var/run none rw,bind 0 0
-EOF
-
-if [ "$(uname -m)" = "x86_64" ]; then
-cat <<EOF >> $path/config
-lxc.mount.entry = /lib64 lib64 none ro,bind 0 0
-EOF
-fi
-
index f8e60f6..ed9a976 100644 (file)
@@ -1,6 +1,6 @@
 {
     "name" : "ut-container-test-dbus",
-    "lxcTemplate" : "minimal-dbus1.sh",
+    "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"],
     "ipv4Gateway" : "",
     "ipv4" : "",
@@ -10,7 +10,7 @@
     "enableDbusIntegration" : true,
     "cpuQuotaForeground" : -1,
     "cpuQuotaBackground" : 1000,
-    "runMountPoint" : "/tmp/ut-run1",
+    "runMountPoint" : "/tmp/ut-run/ut-container-test-dbus",
     "permittedToSend" : [],
     "permittedToRecv" : []
 }
index bf8d1fc..267a812 100644 (file)
@@ -1,6 +1,6 @@
 {
     "name" : "ut-containers-manager-console1-dbus",
-    "lxcTemplate" : "minimal-dbus1.sh",
+    "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"],
     "ipv4Gateway" : "",
     "ipv4" : "",
@@ -10,7 +10,7 @@
     "enableDbusIntegration" : true,
     "cpuQuotaForeground" : -1,
     "cpuQuotaBackground" : 1000,
-    "runMountPoint" : "/tmp/ut-run1",
+    "runMountPoint" : "/tmp/ut-run/ut-containers-manager-console1-dbus",
     "permittedToSend" : [ "/tmp/.*", "/etc/secret2" ],
     "permittedToRecv" : [ "/tmp/.*" ]
 }
index 73ff1b3..f050525 100644 (file)
@@ -1,6 +1,6 @@
 {
     "name" : "ut-containers-manager-console2-dbus",
-    "lxcTemplate" : "minimal-dbus2.sh",
+    "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"],
     "ipv4Gateway" : "",
     "ipv4" : "",
@@ -10,7 +10,7 @@
     "enableDbusIntegration" : true,
     "cpuQuotaForeground" : -1,
     "cpuQuotaBackground" : 1000,
-    "runMountPoint" : "/tmp/ut-run2",
+    "runMountPoint" : "/tmp/ut-run/ut-containers-manager-console2-dbus",
     "permittedToSend" : [ "/tmp/.*" ],
     "permittedToRecv" : [ "/tmp/.*", "/etc/secret1" ]
 }
index c8a0a01..b78ac71 100644 (file)
@@ -1,6 +1,6 @@
 {
     "name" : "ut-containers-manager-console3-dbus",
-    "lxcTemplate" : "minimal-dbus3.sh",
+    "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"],
     "ipv4Gateway" : "",
     "ipv4" : "",
@@ -10,7 +10,7 @@
     "enableDbusIntegration" : true,
     "cpuQuotaForeground" : -1,
     "cpuQuotaBackground" : 1000,
-    "runMountPoint" : "/tmp/ut-run3",
+    "runMountPoint" : "/tmp/ut-run/ut-containers-manager-console3-dbus",
     "permittedToSend" : [ "/tmp/.*" ],
     "permittedToRecv" : [ "/tmp/.*" ]
 }
index f01cfff..7c35446 100644 (file)
@@ -1,6 +1,6 @@
 {
     "name" : "~NAME~",
-    "lxcTemplate" : "minimal-dbus1.sh",
+    "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"],
     "ipv4Gateway" : "",
     "ipv4" : "",
@@ -10,7 +10,7 @@
     "enableDbusIntegration" : true,
     "cpuQuotaForeground" : -1,
     "cpuQuotaBackground" : 1000,
-    "runMountPoint" : "/tmp/ut-run1",
+    "runMountPoint" : "/tmp/ut-run/~NAME~",
     "permittedToSend" : [ "/tmp/.*" ],
     "permittedToRecv" : [ "/tmp/.*" ]
 }
index c42b80d..3cb676e 100644 (file)
@@ -107,7 +107,7 @@ BOOST_AUTO_TEST_CASE(StartStopTest)
 
 BOOST_AUTO_TEST_CASE(DbusConnectionTest)
 {
-    mRunGuard.create("/tmp/ut-run1"); // the same path as in lxc template
+    mRunGuard.create("/tmp/ut-run"); // the same path as in lxc template
 
     auto c = create(TEST_DBUS_CONFIG_PATH);
     c->start();
index 73643a8..6d64c83 100644 (file)
@@ -449,8 +449,8 @@ private:
         if (isHost()) {
             return "unix:path=/var/run/dbus/system_bus_socket";
         }
-        return "unix:path=/tmp/ut-run" + std::to_string(mId) +
-               "/dbus/system_bus_socket";
+        return "unix:path=/tmp/ut-run/ut-containers-manager-console" + std::to_string(mId) +
+               "-dbus/dbus/system_bus_socket";
     }
 };
 
@@ -485,15 +485,11 @@ struct Fixture {
     security_containers::utils::ScopedGlibLoop mLoop;
 
     utils::ScopedDir mContainersPathGuard;
-    utils::ScopedDir mRun1Guard;
-    utils::ScopedDir mRun2Guard;
-    utils::ScopedDir mRun3Guard;
+    utils::ScopedDir mRunGuard;
 
     Fixture()
         : mContainersPathGuard(CONTAINERS_PATH)
-        , mRun1Guard("/tmp/ut-run1")
-        , mRun2Guard("/tmp/ut-run2")
-        , mRun3Guard("/tmp/ut-run3")
+        , mRunGuard("/tmp/ut-run")
     {}
 };
 
@@ -906,11 +902,11 @@ namespace {
 
     const DbusAccessory::Dbuses EXPECTED_DBUSES_STARTED = {
         {"ut-containers-manager-console1-dbus",
-         "unix:path=/tmp/ut-run1/dbus/system_bus_socket"},
+         "unix:path=/tmp/ut-run/ut-containers-manager-console1-dbus/dbus/system_bus_socket"},
         {"ut-containers-manager-console2-dbus",
-         "unix:path=/tmp/ut-run2/dbus/system_bus_socket"},
+         "unix:path=/tmp/ut-run/ut-containers-manager-console2-dbus/dbus/system_bus_socket"},
         {"ut-containers-manager-console3-dbus",
-         "unix:path=/tmp/ut-run3/dbus/system_bus_socket"}};
+         "unix:path=/tmp/ut-run/ut-containers-manager-console3-dbus/dbus/system_bus_socket"}};
 } // namespace
 
 BOOST_AUTO_TEST_CASE(GetContainerDbusesTest)