This repository has been archived by the owner on Mar 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
add tests + standard test invocation #5
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
256fe3d
add tests
TomasTomecek 7d611bd
wip - test inside a container
TomasTomecek bd1b839
run tests inside CCCP
TomasTomecek e0b0877
standard test invocation
TomasTomecek 6ef1bd8
enforce creating root/
TomasTomecek 1d574af
standard test invocation: take 2
TomasTomecek 739b155
make: implement DEBUG_MODE to ease ansible debugging
TomasTomecek f063cb5
tests running in travis
TomasTomecek 887f26a
tests/make: correct obtaining VM image
TomasTomecek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
./Fedora-Cloud-Base-27-1.6.x86_64.qcow2 | ||
./tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
Dockerfile | ||
help/help.md.* | ||
root/ | ||
tests/artifacts/ | ||
|
||
*.qcow2 | ||
|
||
*.py[co] | ||
*.swp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,17 @@ | ||
language: python | ||
python: | ||
- "3.5" | ||
sudo: required | ||
services: | ||
- docker | ||
before_install: | ||
- sudo apt-get -y install acl python3-xattr python3-jinja2 ansible | ||
- pip install xattr conu distgen | ||
script: | ||
- hooks/pre_build | ||
# Docker Hub hack | ||
- sudo cp -av ./Dockerfile.template ./Dockerfile | ||
- make build | ||
env: | ||
- DG_BINARY="docker run -v $(pwd):/var/dgdir slavek/distgen" | ||
- make test | ||
notifications: | ||
email: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
FROM docker.io/modularitycontainers/conu | ||
COPY ./tests /tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
if grep "CentOS Linux 7" /etc/os-release >/dev/null; then | ||
cat >/etc/yum.repos.d/virt.repo <<EOF | ||
[virt7-container-common-candidate] | ||
name=virt7-container-common-candidate | ||
baseurl=https://cbs.centos.org/repos/virt7-container-common-candidate/x86_64/os/ | ||
enabled=1 | ||
gpgcheck=0 | ||
EOF | ||
# yum remove -y python-chardet # pip loves overlayfs | ||
yum install -y epel-release | ||
yum install -y acl nmap-ncat python2-pip python-six pyxattr python2-docker git | ||
pip install pytest | ||
pip install git+https://github.com/fedora-modularity/conu | ||
else | ||
echo "Unsupported distro" | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
.PHONY: check-local check-in-vm | ||
|
||
IMAGE_NAME := "" | ||
VM_IMAGE_NAME := Fedora-Cloud-Base-27-1.6.x86_64.qcow2 | ||
VM_IMAGE_PATH = ../$(VM_IMAGE_NAME) | ||
INVENTORY := /usr/share/ansible/inventory/standard-inventory-qcow2 | ||
ANSIBLE_EXTRA_ARGS ?= | ||
|
||
check-local: | ||
ansible-playbook $(ANSIBLE_EXTRA_ARGS) -e subject=$(IMAGE_NAME) ./local.yml | ||
|
||
check-in-vm: $(VM_IMAGE_PATH) | ||
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 | ||
|
||
$(VM_IMAGE_PATH): | ||
curl -L -o $(VM_IMAGE_PATH) https://download.fedoraproject.org/pub/fedora/linux/releases/27/CloudImages/x86_64/images/$(VM_IMAGE_NAME) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[defaults] | ||
inventory = ./inventory | ||
retry_files_enabled = false | ||
# roles_path = </path/to/the/repo>/roles |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# support use cases: | ||
# * testing an image built locally in current environment (set pull variable to false) | ||
# * testing an image built locally inside a VM (supply vm_image variable) | ||
# * testing an image present in registry in current environment (set pull to true) | ||
# * testing an image present in registry inside a VM (set pull and vm_image variables) | ||
--- | ||
- name: Integration tests for tools container image executed in current environment | ||
hosts: localhost | ||
vars: | ||
# don't pull the test subject by default | ||
pull: false | ||
|
||
# don't set up the environment by default (instal and start container runtime) | ||
setup: false | ||
|
||
required_packages: | ||
- python3-conu | ||
- python3-pytest | ||
|
||
# tests to be invoked (this is utilized by basic standard test role) | ||
tests: | ||
# test suites = directories, where the tests live | ||
- integration | ||
|
||
# our test subject | ||
subject: "" | ||
|
||
# path where the test artifacts will be stored - logs | ||
artifacts: "{{ playbook_dir }}/artifacts/" | ||
|
||
tasks: | ||
- name: prepare the environment to run tests | ||
block: | ||
- name: Install the container engine | ||
package: | ||
name: docker | ||
state: present | ||
become: true | ||
- name: Start the container engine | ||
systemd: | ||
name: docker | ||
state: started | ||
become: true | ||
when: setup | ||
|
||
- name: Pull the test subject (=container image) | ||
command: docker pull {{ subject }} | ||
when: pull | ||
|
||
- name: Copy test subject from host inside the VM | ||
block: | ||
# FIXME: make this configurable | ||
- name: Create temporary directory for the image | ||
tempfile: | ||
state: directory | ||
register: tmp | ||
- name: Save the image to a file | ||
command: 'docker save -o {{ tmp.path + "/image.tar.gz" }} {{ subject }}' | ||
- name: Copy the image from host to the target | ||
# synchronize is so unreliable | ||
synchronize: | ||
src: '{{ tmp.path + "/image.tar.gz" }}' | ||
dest: '/tmp/' | ||
mode: push | ||
ssh_args: "-o UserKnownHostsFile=/dev/null -i {{ ansible_ssh_private_key_file }}" | ||
- file: | ||
state: absent | ||
path: "{{ tmp.path }}" | ||
when: not pull | ||
delegate_to: localhost | ||
|
||
- block: | ||
- name: Load the image on the target into dockerd | ||
command: 'docker load -i /tmp/image.tar.gz' | ||
- file: | ||
state: absent | ||
path: "/tmp/image.tar.gz" | ||
when: not pull | ||
|
||
- name: Execute the role which performs testing | ||
import_role: | ||
name: standard-test-basic |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
|
||
pytest-3 -vv ./test_container.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#!/usr/bin/python3 | ||
|
||
import logging | ||
import os | ||
|
||
import conu | ||
|
||
import pytest | ||
|
||
|
||
IMAGE = os.environ.get("IMAGE_NAME", "docker.io/modularitycontainers/tools") | ||
TAG = os.environ.get("IMAGE_TAG", "latest") | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def container(request): | ||
with conu.DockerBackend(logging_level=logging.DEBUG) as backend: | ||
im = backend.ImageClass(IMAGE, tag=TAG) | ||
b = conu.DockerRunBuilder(command=["sleep", "infinity"]) | ||
b.options += [ | ||
"--net", "host", | ||
"--pid=host", | ||
"--ipc", "host", | ||
"-it", | ||
"--privileged", | ||
"-v", "/run:/run", | ||
"-v", "/:/host", | ||
"-v", "/var/log:/var/log", | ||
] | ||
machine_id_path = "/etc/machine-id" | ||
if os.path.exists(machine_id_path): | ||
b.options += [ | ||
"-v", "%s:%s" % (machine_id_path, machine_id_path) | ||
] | ||
localtime_path = "/etc/localtime" | ||
if os.path.exists(localtime_path): | ||
b.options += [ | ||
"-v", "%s:%s" % (localtime_path, localtime_path) | ||
] | ||
container = im.run_via_binary(b) | ||
yield container | ||
container.stop() | ||
container.delete() | ||
|
||
|
||
class TestContainer: | ||
def test_ethtool(self, container): | ||
# with self.container.mount() as fs: | ||
# networks_devices = os.listdir(fs.p("/sys/class/net")) | ||
networks_devices = ["lo"] | ||
for device in networks_devices: | ||
container.execute(["ethtool", device]) | ||
with pytest.raises(conu.ConuException): | ||
container.execute(["ethtool", "quantum-teleport"]) | ||
|
||
def test_netstat(self, container): | ||
container.execute(["netstat"]) | ||
|
||
def test_ss(self, container): | ||
container.execute(["ss"]) | ||
|
||
def test_pstack(self, container): | ||
container.execute(["pstack", "1"]) | ||
|
||
def test_nstat(self, container): | ||
container.execute(["nstat"]) | ||
|
||
def test_numastat(self, container): | ||
container.execute(["numastat"]) | ||
|
||
def test_pmap(self, container): | ||
container.execute(["pmap", "1"]) | ||
|
||
def test_strace(self, container): | ||
container.execute(["strace", "-V"]) | ||
|
||
|
||
if __name__ == '__main__': | ||
pytest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
localhost ansible_connection=local |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# support use cases: | ||
# * testing an image built locally in current environment (set pull variable to false) | ||
# * testing an image present in registry in current environment (set pull to true) | ||
--- | ||
- name: Integration tests for tools container image executed in current environment | ||
hosts: localhost | ||
vars: | ||
# don't pull the test subject by default | ||
pull: false | ||
|
||
# don't set up the environment by default (install and start container runtime) | ||
setup: false | ||
|
||
required_packages: | ||
- python3-conu | ||
- python3-pytest | ||
|
||
tests: | ||
- integration | ||
|
||
# our test subject | ||
subject: "" | ||
|
||
# path where the test artifacts will be stored - logs | ||
artifacts: "{{ playbook_dir }}/artifacts/" | ||
|
||
tasks: | ||
- name: prepare the environment to run tests | ||
block: | ||
- name: Install the container engine | ||
package: | ||
name: docker | ||
state: present | ||
become: true | ||
- name: Start the container engine | ||
systemd: | ||
name: docker | ||
state: started | ||
become: true | ||
when: setup | ||
|
||
- name: Pull the test subject (=container image) | ||
command: docker pull {{ subject }} | ||
when: pull | ||
|
||
- block: | ||
# should this be configurable? | ||
- name: Create temp dir to store tests | ||
tempfile: | ||
state: directory | ||
register: tmp_tests | ||
- name: Execute the role which performs testing | ||
import_role: | ||
name: standard-test-basic | ||
vars: | ||
tenv_workdir: "{{ tmp_tests.path }}" | ||
always: | ||
- name: delete the temp dir | ||
file: | ||
path: "{{ tmp_tests.path }}" | ||
state: absent |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where it creates a directory? In /tmp. Please make the comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
http://docs.ansible.com/ansible/latest/tempfile_module.html this is ansible 101, I'm not gonna comment on that