Skip to content
This repository was archived by the owner on Mar 7, 2019. It is now read-only.

Commit 70f9184

Browse files
authored
Merge pull request #5 from TomasTomecek/add-tests
add tests + standard test invocation
2 parents 48d8242 + 887f26a commit 70f9184

14 files changed

Lines changed: 303 additions & 8 deletions

.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
./Fedora-Cloud-Base-27-1.6.x86_64.qcow2
2+
./tests

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
Dockerfile
22
help/help.md.*
33
root/
4+
tests/artifacts/
5+
6+
*.qcow2
47

58
*.py[co]
69
*.swp

.travis.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1+
language: python
2+
python:
3+
- "3.5"
14
sudo: required
25
services:
36
- docker
7+
before_install:
8+
- sudo apt-get -y install acl python3-xattr python3-jinja2 ansible
9+
- pip install xattr conu distgen
410
script:
511
- hooks/pre_build
612
# Docker Hub hack
713
- sudo cp -av ./Dockerfile.template ./Dockerfile
814
- make build
9-
env:
10-
- DG_BINARY="docker run -v $(pwd):/var/dgdir slavek/distgen"
15+
- make test
1116
notifications:
1217
email: false

Dockerfile.tests

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
FROM docker.io/modularitycontainers/conu
2+
COPY ./tests /tests

Makefile

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1-
.PHONY: build run default enumerate-tools upstream fedora-downstream source
1+
.PHONY: build run default enumerate-tools upstream fedora-downstream source test check
22

33
DISTRO := fedora-27-x86_64
44
VARIANT := upstream
55
DG_BINARY ?= dg
66
DG_EXEC = $(DG_BINARY) --max-passes 25 --spec specs/common.yml --multispec specs/multispec.yaml --distro $(DISTRO).yaml --multispec-selector variant=$(VARIANT)
7+
# set to 1 to enable debugging
8+
DEBUG_MODE ?= 0
9+
ifeq ($(DEBUG_MODE), 1)
10+
ANSIBLE_EXTRA_ARGS := -vv
11+
endif
712

813
REPOSITORY = $(shell ${DG_EXEC} --template={{spec.repository}})
914

@@ -17,18 +22,21 @@ RENDERED_DOCKERFILE_MD := ./Dockerfile
1722

1823
default: run
1924

20-
$(RENDERED_DOCKERFILE_MD): $(SOURCE_DOCKERFILE_MD)
25+
root/:
26+
mkdir -p ./root
27+
28+
$(RENDERED_DOCKERFILE_MD): $(SOURCE_DOCKERFILE_MD) specs/*
2129
$(DG_EXEC) --template $(SOURCE_DOCKERFILE_MD) --output $(RENDERED_DOCKERFILE_MD)
2230

23-
$(RENDERED_README_MD): $(SOURCE_README_MD)
31+
$(RENDERED_README_MD): $(SOURCE_README_MD) specs/*
2432
$(DG_EXEC) --template $(SOURCE_README_MD) --output $(RENDERED_README_MD)
2533

26-
$(RENDERED_HELP_MD): $(SOURCE_HELP_MD) specs/multispec.yaml
34+
$(RENDERED_HELP_MD): $(SOURCE_HELP_MD) specs/*
2735
@# FIXME: current go-md2man can't convert tables :<
2836
@# go-md2man -in=${SOURCE_HELP_MD} -out=./root/help.1
2937
$(shell TOOLS_CONTAINER_SKIP_ENUMERATION=false $(DG_EXEC) --template $(SOURCE_HELP_MD) --output $(RENDERED_HELP_MD))
3038

31-
source: $(RENDERED_HELP_MD) $(RENDERED_README_MD) $(RENDERED_DOCKERFILE_MD)
39+
source: root/ $(RENDERED_HELP_MD) $(RENDERED_README_MD) $(RENDERED_DOCKERFILE_MD)
3240

3341
fedora-downstream:
3442
make -e source VARIANT="fedora"
@@ -45,6 +53,14 @@ run:
4553
enumerate-tools:
4654
docker run -it -v ${PWD}:/src -e TOOLS_PACKAGES=$(shell $(DG_EXEC) --template="{{spec.packages|join(\",\")}}") --rm $(REPOSITORY) /src/enumerate-tools.py
4755

56+
check: test
57+
58+
test: build
59+
make -C tests/ check-local IMAGE_NAME=$(REPOSITORY) ANSIBLE_EXTRA_ARGS=$(ANSIBLE_EXTRA_ARGS)
60+
61+
check-in-vm: build
62+
make -C tests/ check-in-vm IMAGE_NAME=$(REPOSITORY) ANSIBLE_EXTRA_ARGS=$(ANSIBLE_EXTRA_ARGS)
63+
4864
clean:
4965
rm Dockerfile || :
5066
rm root/README.md || :

cccp.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ test-skip : True
1919

2020
# This is path of the script that initiates the user defined tests. It must be able to
2121
# return an exit code.
22-
test-script : null
22+
test-script : ./requirements.sh && pytest -vv ./tests/
2323

2424
# This is the path of custom build script.
2525
build-script : null

requirements.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
if grep "CentOS Linux 7" /etc/os-release >/dev/null; then
6+
cat >/etc/yum.repos.d/virt.repo <<EOF
7+
[virt7-container-common-candidate]
8+
name=virt7-container-common-candidate
9+
baseurl=https://cbs.centos.org/repos/virt7-container-common-candidate/x86_64/os/
10+
enabled=1
11+
gpgcheck=0
12+
EOF
13+
# yum remove -y python-chardet # pip loves overlayfs
14+
yum install -y epel-release
15+
yum install -y acl nmap-ncat python2-pip python-six pyxattr python2-docker git
16+
pip install pytest
17+
pip install git+https://github.com/fedora-modularity/conu
18+
else
19+
echo "Unsupported distro"
20+
exit 1
21+
fi

tests/Makefile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.PHONY: check-local check-in-vm
2+
3+
IMAGE_NAME := ""
4+
VM_IMAGE_NAME := Fedora-Cloud-Base-27-1.6.x86_64.qcow2
5+
VM_IMAGE_PATH = ../$(VM_IMAGE_NAME)
6+
INVENTORY := /usr/share/ansible/inventory/standard-inventory-qcow2
7+
ANSIBLE_EXTRA_ARGS ?=
8+
9+
check-local:
10+
ansible-playbook $(ANSIBLE_EXTRA_ARGS) -e subject=$(IMAGE_NAME) ./local.yml
11+
12+
check-in-vm: $(VM_IMAGE_PATH)
13+
TEST_SUBJECTS=$(VM_IMAGE_PATH) ansible-playbook $(ANSIBLE_EXTRA_ARGS) -e ansible_python_interpreter=/usr/bin/python3 -e subject=$(IMAGE_NAME) -i $(INVENTORY) -e setup=true -e vm_image=$(VM_IMAGE) ./in-vm.yml
14+
15+
$(VM_IMAGE_PATH):
16+
curl -L -o $(VM_IMAGE_PATH) https://download.fedoraproject.org/pub/fedora/linux/releases/27/CloudImages/x86_64/images/$(VM_IMAGE_NAME)

tests/ansible.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[defaults]
2+
inventory = ./inventory
3+
retry_files_enabled = false
4+
# roles_path = </path/to/the/repo>/roles

tests/in-vm.yml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# support use cases:
2+
# * testing an image built locally in current environment (set pull variable to false)
3+
# * testing an image built locally inside a VM (supply vm_image variable)
4+
# * testing an image present in registry in current environment (set pull to true)
5+
# * testing an image present in registry inside a VM (set pull and vm_image variables)
6+
---
7+
- name: Integration tests for tools container image executed in current environment
8+
hosts: localhost
9+
vars:
10+
# don't pull the test subject by default
11+
pull: false
12+
13+
# don't set up the environment by default (instal and start container runtime)
14+
setup: false
15+
16+
required_packages:
17+
- python3-conu
18+
- python3-pytest
19+
20+
# tests to be invoked (this is utilized by basic standard test role)
21+
tests:
22+
# test suites = directories, where the tests live
23+
- integration
24+
25+
# our test subject
26+
subject: ""
27+
28+
# path where the test artifacts will be stored - logs
29+
artifacts: "{{ playbook_dir }}/artifacts/"
30+
31+
tasks:
32+
- name: prepare the environment to run tests
33+
block:
34+
- name: Install the container engine
35+
package:
36+
name: docker
37+
state: present
38+
become: true
39+
- name: Start the container engine
40+
systemd:
41+
name: docker
42+
state: started
43+
become: true
44+
when: setup
45+
46+
- name: Pull the test subject (=container image)
47+
command: docker pull {{ subject }}
48+
when: pull
49+
50+
- name: Copy test subject from host inside the VM
51+
block:
52+
# FIXME: make this configurable
53+
- name: Create temporary directory for the image
54+
tempfile:
55+
state: directory
56+
register: tmp
57+
- name: Save the image to a file
58+
command: 'docker save -o {{ tmp.path + "/image.tar.gz" }} {{ subject }}'
59+
- name: Copy the image from host to the target
60+
# synchronize is so unreliable
61+
synchronize:
62+
src: '{{ tmp.path + "/image.tar.gz" }}'
63+
dest: '/tmp/'
64+
mode: push
65+
ssh_args: "-o UserKnownHostsFile=/dev/null -i {{ ansible_ssh_private_key_file }}"
66+
- file:
67+
state: absent
68+
path: "{{ tmp.path }}"
69+
when: not pull
70+
delegate_to: localhost
71+
72+
- block:
73+
- name: Load the image on the target into dockerd
74+
command: 'docker load -i /tmp/image.tar.gz'
75+
- file:
76+
state: absent
77+
path: "/tmp/image.tar.gz"
78+
when: not pull
79+
80+
- name: Execute the role which performs testing
81+
import_role:
82+
name: standard-test-basic

0 commit comments

Comments
 (0)