]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
update tests to recognize cgns profile 836/head
authorSerge Hallyn <serge.hallyn@ubuntu.com>
Mon, 22 Feb 2016 05:09:42 +0000 (21:09 -0800)
committerSerge Hallyn <serge.hallyn@ubuntu.com>
Mon, 22 Feb 2016 05:09:42 +0000 (21:09 -0800)
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
src/tests/attach.c
src/tests/lxc-test-apparmor-mount
src/tests/lxc-test-ubuntu

index ee827c1ba3828640f93c1344efb63f0766479594..af03862da02a96f987da6b3109b1f8824f9b072a 100644 (file)
@@ -23,6 +23,7 @@
 #include "lxc/utils.h"
 #include "lxc/lsm/lsm.h"
 
+#include <sys/types.h>
 #include <string.h>
 #include <sys/stat.h>
 #include <errno.h>
 static const char *lsm_config_key = NULL;
 static const char *lsm_label = NULL;
 
+bool file_exists(const char *f)
+{
+       struct stat statbuf;
+
+       return stat(f, &statbuf) == 0;
+}
+
 static void test_lsm_detect(void)
 {
        if (lsm_enabled()) {
@@ -48,7 +56,10 @@ static void test_lsm_detect(void)
                }
                else if (!strcmp(lsm_name(), "AppArmor")) {
                        lsm_config_key = "lxc.aa_profile";
-                       lsm_label      = "lxc-container-default";
+                       if (file_exists("/proc/self/ns/cgroup"))
+                               lsm_label      = "lxc-container-default-cgns";
+                       else
+                               lsm_label      = "lxc-container-default";
                }
                else {
                        TSTERR("unknown lsm %s enabled, add test code here", lsm_name());
index e3712c7ee1a7fb197566ba7122aa6ca3f443c296..0c5c7cd66616eb96c4e005ad1c355be78d81ad9d 100755 (executable)
 
 set -e
 
+if [ -f /proc/self/ns/cgroup ]; then
+       default_profile="lxc-container-default-cgns (enforce)"
+else
+       default_profile="lxc-container-default (enforce)"
+fi
+
 FAIL() {
        echo -n "Failed " >&2
        echo "$*" >&2
@@ -144,7 +150,7 @@ run_cmd lxc-start -n $cname -d
 run_cmd lxc-wait -n $cname -s RUNNING
 pid=`run_cmd lxc-info -p -H -n $cname`
 profile=`cat /proc/$pid/attr/current`
-if [ "x$profile" != "xlxc-container-default (enforce)" ]; then
+if [ "x$profile" != "x${default_profile}" ]; then
        echo "FAIL: confined container was in profile $profile"
        exit 1
 fi
@@ -203,7 +209,7 @@ if [ "$pid" = "-1" ]; then
        exit 1
 fi
 profile=`cat /proc/$pid/attr/current`
-if [ "x$profile" != "xlxc-container-default (enforce)" ]; then
+if [ "x$profile" != "x${default_profile}" ]; then
        echo "FAIL: confined container was in profile $profile"
        exit 1
 fi
index ff716bc0ccf7da0ed15fabbc77e5f2cdc41b36cb..dc06804ebe8e2f7e41b6bb54735b6b36eb5f15a3 100755 (executable)
@@ -65,7 +65,9 @@ for template in ubuntu ubuntu-cloud; do
        # Check apparmor
        lxcpid=`lxc-info -n $name -p -H`
        aa=`cat /proc/$lxcpid/attr/current`
-       if [ "$aa" != "lxc-container-default-with-nesting (enforce)" -a "$aa" != "lxc-container-default (enforce)" ]; then
+       if [ "$aa" != "lxc-container-default-with-nesting (enforce)" -a \
+                       "$aa" != "lxc-container-default-cgns (enforce)" -a \
+                       "$aa" != "lxc-container-default (enforce)" ]; then
                FAIL " to correctly set apparmor profile (profile is \"$aa\")"
        fi
        lxc-stop -n $name -k