#115 wip: new role to blackbox-test container images
Closed 6 years ago by ttomecek. Opened 6 years ago by ttomecek.
ttomecek/standard-test-roles fix-110  into  master

file added
+5
@@ -0,0 +1,5 @@ 

+ ENV := Fedora-Cloud-Base-27-1.6.x86_64.qcow2

+ 

+ run:

+ 	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

@@ -62,7 +62,10 @@ 

      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:
@@ -119,7 +122,6 @@ 

          os.dup2(tty, 2)

      except OSError:

          tty = None

-         pass

  

      # A directory for temporary stuff

      directory = tempfile.mkdtemp(prefix="inventory-cloud")

@@ -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.

@@ -0,0 +1,4 @@ 

+ ---

+ artifacts: "{{ lookup('env', 'TEST_ARTIFACTS')|default('./artifacts', true) }}"

+ pull_image: false

+ test_command: ""

@@ -0,0 +1,30 @@ 

+ ---

+ - 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

+ 

+ - block:

+   - 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

@@ -0,0 +1,2 @@ 

+ ---

+ tests: []

file added
+9
@@ -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 }}"

Commit with test data is there so that you can understand the use case. There is still some work to be done, I'm looking for feedback here.

I will squash the commits once the change is done.

TODO:

  • [ ] support executing the test suite locally
  • [x] support executing the test suite in a fresh VM
  • [ ] add support for executing in CentOS
  • [ ] add support for executing in RHEL
  • [ ] provision the VM within the role (making it a fixture; suggested by @stefw)

1 new commit added

  • bump
6 years ago

Hi,
my PR
https://pagure.io/standard-test-roles/pull-request/97
tries to discuss and solve same issue. how to deal with test subject.
Probably it could be merged together

I see two different logical changes:
1. Change of inventory/standard-inventory-qcow2
2. Introducing of a new role.

Therefore, please send two independent PR.

This PR has 4 commit. This is not big PR. All 4 commit will be in git history. Is it wise to have 4 commits in git history for such small PR?

For a new role I would ask you provide a justification and purpose. What motivation was for creating this role? Why basic role cannot be used? For me it seems very simple role that can be shipped with tests. How many tests will use this role?

See the description: this PR is far from being finished. I'll make it more obvious by adding wip in the title.

I already talked to Stef and he suggested to utilize the merge script and let the role provision the VM and make it a fixture, thus not utilize the dynamic inventory script.

Andrei, I agree that the basic role is a better fit, thus closing this.

Pull-Request has been closed by ttomecek

6 years ago