From 88b9ef65fe38d0a82f0353bb6272ba1993cc006b Mon Sep 17 00:00:00 2001
From: Luis Araujo <luis.araujo@collabora.co.uk>
Date: Fri, 23 Nov 2018 19:12:48 +0800
Subject: [PATCH] Add remaining test cases for tiny containers

- Add the remaining test cases for tiny containers.
- Add a new image type: tiny-lxc
- Add new execution type: all

Signed-off-by: Luis Araujo <luis.araujo@collabora.co.uk>
---
 format_template.yaml                          |  4 +-
 renderer/parser.py                            | 48 ++++++++++---------
 tests-cases/check-tiny-system-containers.yaml | 30 ++++++++++++
 tests-cases/check-tiny-user-containers.yaml   | 31 ++++++++++++
 tests-cases/sanity-check.yaml                 |  2 +-
 5 files changed, 90 insertions(+), 25 deletions(-)
 create mode 100644 tests-cases/check-tiny-system-containers.yaml
 create mode 100644 tests-cases/check-tiny-user-containers.yaml

diff --git a/format_template.yaml b/format_template.yaml
index cc3d646..469b2b6 100644
--- a/format_template.yaml
+++ b/format_template.yaml
@@ -4,7 +4,7 @@ metadata:
 
   format: "Apertis Test Definition 1.0"
 
-  # [ target, minimal, ostree, development, SDK, any ].
+  # [ any, development, minimal, SDK, target, tiny-lxc ].
   image-type:
 
   # [ amd64, arm64, armhf, any ]
@@ -13,7 +13,7 @@ metadata:
   # [ functional, sanity, system ]
   type:
 
-  # [ manual , automated ]
+  # [ all, automated, manual ]
   exec-type:
 
   # [ low, medium, high, critical ]
diff --git a/renderer/parser.py b/renderer/parser.py
index 8747fed..b2c90ef 100644
--- a/renderer/parser.py
+++ b/renderer/parser.py
@@ -7,33 +7,37 @@
 import sys
 import yaml
 
+image_types = [ "any", "development", "minimal", "SDK", "target", "tiny-lxc" ]
+image_arch = ['any', 'amd64', 'arm64', 'armhf']
+tests_types = ['compatibility', 'functional', 'performance', 'sanity', 'system']
+priorities = ['critical', 'high', 'low', 'medium']
+execution_type = ['all', 'automated', 'manual']
+
 # This structure defines the test case YAML file format.
 test_case_format = {
-    'metadata' : (True, {
-        'name' : (True, ""),
-        'format' : (False, ""),
-        'image-type' : (True, [ 'target', 'minimal', 'ostree',
-                                'development', 'SDK', 'any' ]),
-        'image-arch' : (True, ['amd64', 'arm64', 'armhf', 'any']),
-        'type' : (True, ['compatibility', 'functional', 'performance',
-                         'sanity', 'system']),
-        'exec-type' : (True, ['manual' , 'automated']),
-        'priority' : (True, ['low', 'medium', 'high', 'critical']),
-        'maintainer' : (False, ""),
-        'description' : (True, ""),
-        'resources' : (False, []),
-        'pre-conditions' : (False, []),
-        'expected' : (True, []),
-        'notes' : (False, []),
-        'post-conditions' : (False, [])
+    'metadata': (True, {
+        'name':            (True,  ""),
+        'format':          (False, ""),
+        'image-type':      (True,  image_types),
+        'image-arch':      (True,  image_arch),
+        'type':            (True,  tests_types),
+        'exec-type':       (True,  execution_type),
+        'priority':        (True,  priorities),
+        'maintainer':      (False, ""),
+        'description':     (True,  ""),
+        'resources':       (False, []),
+        'pre-conditions':  (False, []),
+        'expected':        (True,  []),
+        'notes':           (False, []),
+        'post-conditions': (False, [])
     }),
-    'install' : (False, {
-        'deps' : (True, [])
+    'install': (False, {
+        'deps': (True, [])
     }),
-    'run' : (True, {
-        'steps' : (True, [])
+    'run': (True, {
+        'steps': (True, [])
     }),
-    'parse' : (False, {})
+    'parse': (False, {})
 }
 
 def _parse_format(test_case, test_case_format):
diff --git a/tests-cases/check-tiny-system-containers.yaml b/tests-cases/check-tiny-system-containers.yaml
new file mode 100644
index 0000000..68d5461
--- /dev/null
+++ b/tests-cases/check-tiny-system-containers.yaml
@@ -0,0 +1,30 @@
+metadata:
+  name: check-tiny-system-containers
+  format: "Apertis Test Definition 1.0"
+  image-type: tiny-lxc
+  image-arch: any
+  type: functional
+  exec-type: automated
+  priority: medium
+  maintainer: "Apertis Project"
+  description: "Test of Tiny system-wide privileged container using shared
+                networking with the host"
+
+  expected:
+    - "Test command should report \"pass\"."
+
+install:
+  deps:
+  - libpam-cgfs
+  - lxc
+  - lxc-templates
+  - uidmap
+
+run:
+  steps:
+  - "# Execute the following commands:"
+  - sed s/__NAMESPACE_PLACEHOLDER__/lxc-apertis-tiny-system/g lxc/lxc-tiny-connectivity-profile-template | apparmor_parser -qr
+  - lavatests/check-tiny-containers -a "$ARCH" -r "$RELEASE" -d "$IMAGE_DATE" -t lxc/lxc-tiny-connectivity --aa-namespace "lxc-apertis-tiny-system"
+
+parse:
+  pattern: "(?P<test_case_id>.*-*):\\s+(?P<result>(pass|fail))"
diff --git a/tests-cases/check-tiny-user-containers.yaml b/tests-cases/check-tiny-user-containers.yaml
new file mode 100644
index 0000000..ea30e34
--- /dev/null
+++ b/tests-cases/check-tiny-user-containers.yaml
@@ -0,0 +1,31 @@
+metadata:
+  name: check-tiny-user-containers
+  format: "Apertis Test Definition 1.0"
+  image-type: tiny-lxc
+  image-arch: any
+  type: functional
+  exec-type: automated
+  priority: medium
+  maintainer: "Apertis Project"
+  description: "Test of Tiny unprivileged container without any networking
+                started as user"
+
+  expected:
+    - "Test command should report \"pass\"."
+
+install:
+  deps:
+  - libpam-cgfs
+  - lxc
+  - lxc-templates
+  - uidmap
+
+run:
+  steps:
+  - "# Execute the following commands:"
+  - sysctl -w kernel.unprivileged_userns_clone=1
+  - sed s/__NAMESPACE_PLACEHOLDER__/lxc-apertis-tiny-userns/g lxc/lxc-tiny-connectivity-profile-template | apparmor_parser -qr
+  - sudo -u user -H lavatests/check-tiny-containers -a "$ARCH" -r "$RELEASE" -d "$IMAGE_DATE" -t lxc/lxc-tiny-connectivity --aa-namespace "lxc-apertis-tiny-userns"
+
+parse:
+  pattern: "(?P<test_case_id>.*-*):\\s+(?P<result>(pass|fail))"
diff --git a/tests-cases/sanity-check.yaml b/tests-cases/sanity-check.yaml
index 2743a80..ad040da 100644
--- a/tests-cases/sanity-check.yaml
+++ b/tests-cases/sanity-check.yaml
@@ -4,7 +4,7 @@ metadata:
   image-type: any
   image-arch: any
   type: sanity
-  exec-type: automated
+  exec-type: all
   priority: critical
   maintainer: "Apertis Project"
   description: "This test checks that the system bus is up, that a user session is
-- 
GitLab