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

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
Signed-off-by: Tomas Tomecek <[email protected]>
  • Loading branch information
TomasTomecek committed Oct 11, 2017
1 parent d99cea8 commit f7e1101
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
language: python
python:
- "2.7"
- "3.5"
- "3.6"
sudo: required
services:
- docker
before_install:
- sudo apt-get -y install acl netcat
- pip install docker six xattr
- pip install git+https://github.com/fedora-modularity/conu
script:
- hooks/pre_build
# Docker Hub hack
- sudo cp -av ./Dockerfile.template ./Dockerfile
- make build
- make test
env:
- DG_BINARY="docker run -v $(pwd):/var/dgdir slavek/distgen"
notifications:
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ run:
enumerate-tools:
docker run -it -v ${PWD}:/src -e TOOLS_PACKAGES=$(shell $(DG_EXEC) --template="{{spec.packages|join(\",\")}}") --rm $(REPOSITORY) /src/enumerate-tools.py

test:
IMAGE_NAME=$(REPOSITORY) pytest

clean:
rm Dockerfile || :
rm root/README.md || :
Expand Down
82 changes: 82 additions & 0 deletions tests/test_container.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/usr/bin/python3

import logging
import os

import conu
import conu.apidefs.exceptions
import conu.backend.docker

import pytest


IMAGE = os.environ.get("IMAGE_NAME", "docker.io/modularitycontainers/tools")
TAG = os.environ.get("IMAGE_TAG", "latest")


class TestContainer:
image = None
container = None
backend = None

@classmethod
def setup_class(cls):
cls.backend = conu.DockerBackend(logging_level=logging.DEBUG)
cls.image = cls.backend.ImageClass(IMAGE, tag=TAG)
c = conu.backend.docker.DockerRunCommand(command=["sleep", "infinity"])
c.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):
c.options += [
"-v", "%s:%s" % (machine_id_path, machine_id_path)
]
localtime_path = "/etc/localtime"
if os.path.exists(localtime_path):
c.options += [
"-v", "%s:%s" % (localtime_path, localtime_path)
]

cls.container = cls.backend.ContainerClass.run_via_binary(cls.image, c)

def test_ethtool(self):
# with self.container.mount() as fs:
# networks_devices = os.listdir(fs.p("/sys/class/net"))
networks_devices = ["lo"]
for device in networks_devices:
self.container.execute(["ethtool", device])
with pytest.raises(conu.apidefs.exceptions.ConuException):
self.container.execute(["ethtool", "quantum-teleport"])

def test_netstat(self):
self.container.execute(["netstat"])

def test_ss(self):
self.container.execute(["ss"])

def test_pstack(self):
self.container.execute(["pstack", "1"])

def test_nstat(self):
self.container.execute(["nstat"])

def test_numastat(self):
self.container.execute(["numastat"])

def test_pmap(self):
self.container.execute(["pmap", "1"])

def test_strace(self):
self.container.execute(["strace", "-V"])


if __name__ == '__main__':
pytest.main()

0 comments on commit f7e1101

Please sign in to comment.