From f1b758a8b5df32655dfe6a70dac0806053d0e3b6 Mon Sep 17 00:00:00 2001
From: Tomas Tomecek <ttomecek@redhat.com>
Date: Feb 05 2018 17:39:52 +0000
Subject: [PATCH 1/4] inventory,qcow2: remove noop


Signed-off-by: Tomas Tomecek <ttomecek@redhat.com>

---

diff --git a/inventory/standard-inventory-qcow2 b/inventory/standard-inventory-qcow2
index 7a6feea..0a571ac 100755
--- a/inventory/standard-inventory-qcow2
+++ b/inventory/standard-inventory-qcow2
@@ -119,7 +119,6 @@ def host(image):
         os.dup2(tty, 2)
     except OSError:
         tty = None
-        pass
 
     # A directory for temporary stuff
     directory = tempfile.mkdtemp(prefix="inventory-cloud")

From ca2ab6123b056137a335eb8c06d146eb18c8ffb7 Mon Sep 17 00:00:00 2001
From: Tomas Tomecek <ttomecek@redhat.com>
Date: Feb 05 2018 17:40:32 +0000
Subject: [PATCH 2/4] new role to blackbox-test container images


Signed-off-by: Tomas Tomecek <ttomecek@redhat.com>

---

diff --git a/inventory/standard-inventory-qcow2 b/inventory/standard-inventory-qcow2
index 0a571ac..9ee6cfc 100755
--- a/inventory/standard-inventory-qcow2
+++ b/inventory/standard-inventory-qcow2
@@ -62,7 +62,10 @@ def main(argv):
     parser = argparse.ArgumentParser(description="Inventory for a QCow2 test image")
     parser.add_argument("--list", action="store_true", help="Verbose output")
     parser.add_argument('--host', help="Get host variables")
-    parser.add_argument("subjects", nargs="*", default=shlex.split(os.environ.get("TEST_SUBJECTS", "")))
+
+    default_subjects = os.environ.get("TEST_SUBJECTS", os.environ.get("TEST_ENV", ""))
+    parser.add_argument("subjects", nargs="*", default=shlex.split(default_subjects))
+
     opts = parser.parse_args()
 
     try:
diff --git a/roles/standard-test-container/README.md b/roles/standard-test-container/README.md
new file mode 100644
index 0000000..5bfe565
--- /dev/null
+++ b/roles/standard-test-container/README.md
@@ -0,0 +1,10 @@
+# Ansible role for container tests
+
+Requirements:
+
+ * You have to define `test_command` variable -- this is the command which validates your container image.
+
+
+Configuration:
+
+ * You can set a variable `pull_image: true` to pull the test subject. It is set to `false` by default.
diff --git a/roles/standard-test-container/defaults/main.yml b/roles/standard-test-container/defaults/main.yml
new file mode 100644
index 0000000..83794c8
--- /dev/null
+++ b/roles/standard-test-container/defaults/main.yml
@@ -0,0 +1,4 @@
+---
+artifacts: "{{ lookup('env', 'TEST_ARTIFACTS')|default('./artifacts', true) }}"
+pull_image: false
+test_command: ""
diff --git a/roles/standard-test-container/tasks/main.yml b/roles/standard-test-container/tasks/main.yml
new file mode 100644
index 0000000..473739b
--- /dev/null
+++ b/roles/standard-test-container/tasks/main.yml
@@ -0,0 +1,29 @@
+---
+- name: Install the container engine
+  package: name=docker state=present
+
+- name: Start the container engine
+  systemd: name=docker state=started
+
+- name: Pull the test subject (=container image)
+  command: docker pull {{ subjects }}
+  when: pull_image
+
+# TODO: add a way to copy the image from host
+
+- name: Make artifacts directory exists
+  file: path={{ artifacts }} state=directory owner=root mode=755 recurse=yes
+
+# TODO: install deps
+
+# TODO: copy tests inside
+
+- name: Execute the test suite
+  shell: exec 2>>{{artifacts}}/test.log 1>>{{artifacts}}/test.log; {{ test_command }}
+
+- always:
+  - name: Pull out the logs
+    fetch:
+      dest: "{{artifacts}}/"
+      src: "{{artifacts}}/"
+      flat: yes
diff --git a/roles/standard-test-container/vars/main.yml b/roles/standard-test-container/vars/main.yml
new file mode 100644
index 0000000..c2acc48
--- /dev/null
+++ b/roles/standard-test-container/vars/main.yml
@@ -0,0 +1,2 @@
+---
+tests: []

From 36a343b8bc617a47adc61832a00fae0c62e0d5d2 Mon Sep 17 00:00:00 2001
From: Tomas Tomecek <ttomecek@redhat.com>
Date: Feb 05 2018 17:46:55 +0000
Subject: [PATCH 3/4] test data


Signed-off-by: Tomas Tomecek <ttomecek@redhat.com>

---

diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..b845c98
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,3 @@
+run:
+	curl -O http://ftp.fi.muni.cz/pub/linux/fedora/linux/releases/27/CloudImages/x86_64/images/Fedora-Cloud-Base-27-1.6.x86_64.qcow2
+	TEST_ENV=Fedora-Cloud-Base-27-1.6.x86_64.qcow2 ansible-playbook -e 'ansible_python_interpreter=/usr/bin/python3' -i ./inventory/standard-inventory-qcow2 ./t.yaml
diff --git a/t.yaml b/t.yaml
new file mode 100644
index 0000000..d2aa1e5
--- /dev/null
+++ b/t.yaml
@@ -0,0 +1,9 @@
+---
+- hosts: localhost
+  vars:
+    subject: "docker.io/library/busybox"
+  roles:
+  - role: standard-test-container
+    test_command: "docker run -ti --rm {{ subject }} true"
+    pull_image: true
+    subjects: "{{ subject }}"

From 8d151de1c48573cc3a383803b400936fa67fd0d3 Mon Sep 17 00:00:00 2001
From: Tomas Tomecek <ttomecek@redhat.com>
Date: Feb 05 2018 18:00:34 +0000
Subject: [PATCH 4/4] bump


Signed-off-by: Tomas Tomecek <ttomecek@redhat.com>

---

diff --git a/Makefile b/Makefile
index b845c98..faa64c3 100644
--- a/Makefile
+++ b/Makefile
@@ -1,3 +1,5 @@
+ENV := Fedora-Cloud-Base-27-1.6.x86_64.qcow2
+
 run:
-	curl -O http://ftp.fi.muni.cz/pub/linux/fedora/linux/releases/27/CloudImages/x86_64/images/Fedora-Cloud-Base-27-1.6.x86_64.qcow2
-	TEST_ENV=Fedora-Cloud-Base-27-1.6.x86_64.qcow2 ansible-playbook -e 'ansible_python_interpreter=/usr/bin/python3' -i ./inventory/standard-inventory-qcow2 ./t.yaml
+	test -f $(ENV) || curl -O http://ftp.fi.muni.cz/pub/linux/fedora/linux/releases/27/CloudImages/x86_64/images/$(ENV)
+	TEST_ENV=$(ENV) ansible-playbook -e 'ansible_python_interpreter=/usr/bin/python3' -i ./inventory/standard-inventory-qcow2 ./t.yaml
diff --git a/roles/standard-test-container/tasks/main.yml b/roles/standard-test-container/tasks/main.yml
index 473739b..67d2fcb 100644
--- a/roles/standard-test-container/tasks/main.yml
+++ b/roles/standard-test-container/tasks/main.yml
@@ -18,10 +18,11 @@
 
 # TODO: copy tests inside
 
-- name: Execute the test suite
-  shell: exec 2>>{{artifacts}}/test.log 1>>{{artifacts}}/test.log; {{ test_command }}
+- block:
+  - name: Execute the test suite
+    shell: exec 2>>{{artifacts}}/test.log 1>>{{artifacts}}/test.log; {{ test_command }}
 
-- always:
+  always:
   - name: Pull out the logs
     fetch:
       dest: "{{artifacts}}/"

