From edf25cb299d6ca265bbba2e60d7ae085a4762a5d Mon Sep 17 00:00:00 2001 From: Uggla Date: Sun, 5 Feb 2017 23:26:14 +0100 Subject: [PATCH] Re enable redfish-client tests - Check if local docker is available, if not skip the tests. So this should allow gerrit tests to pass. - Stick to docker-py 1.x, because 2.0 has lot of naming changes. - Use Fedora 25 instead of 23. - Use Ubuntu 16.04 instead of 14.04. - Use pip --pre parameter. Allowing to test dev release (pre). - Rename Dockerfiles to get more consistency using a new naming convention. - Naming convention that I hope will make Bruno happy ! ;) Change-Id: I3cbd51f201c4805ba58ebcabb023237624d4dfc8 --- .../centos-7-src-p2.dkf} | 0 .../debian-8-src-p2.dkf} | 2 +- .../fedora-25-pip-p2.dkf} | 4 +- .../fedora-25-src-p2.dkf} | 2 +- .../fedora-25-src-p3.dkf} | 2 +- .../check_client.py => tests/test_client.py} | 62 +++++++++++++------ .../ubuntu-16.04-src-p2.dkf} | 2 +- test-requirements.txt | 4 +- 8 files changed, 52 insertions(+), 26 deletions(-) rename redfish-client/{local-checks/Dockerfile.centos => tests/centos-7-src-p2.dkf} (100%) rename redfish-client/{local-checks/Dockerfile.ubuntu => tests/debian-8-src-p2.dkf} (96%) rename redfish-client/{local-checks/Dockerfile.fedorapip => tests/fedora-25-pip-p2.dkf} (61%) rename redfish-client/{local-checks/Dockerfile.fedora => tests/fedora-25-src-p2.dkf} (95%) rename redfish-client/{local-checks/Dockerfile.fedorap3 => tests/fedora-25-src-p3.dkf} (95%) rename redfish-client/{local-checks/check_client.py => tests/test_client.py} (63%) rename redfish-client/{local-checks/Dockerfile.debian => tests/ubuntu-16.04-src-p2.dkf} (96%) diff --git a/redfish-client/local-checks/Dockerfile.centos b/redfish-client/tests/centos-7-src-p2.dkf similarity index 100% rename from redfish-client/local-checks/Dockerfile.centos rename to redfish-client/tests/centos-7-src-p2.dkf diff --git a/redfish-client/local-checks/Dockerfile.ubuntu b/redfish-client/tests/debian-8-src-p2.dkf similarity index 96% rename from redfish-client/local-checks/Dockerfile.ubuntu rename to redfish-client/tests/debian-8-src-p2.dkf index 1b9e542..a1ccfc6 100644 --- a/redfish-client/local-checks/Dockerfile.ubuntu +++ b/redfish-client/tests/debian-8-src-p2.dkf @@ -1,4 +1,4 @@ -FROM ubuntu:wily +FROM debian:8 ENV DEBIAN_FRONTEND noninteractive RUN apt-get update && \ apt-get install -y apt-utils && \ diff --git a/redfish-client/local-checks/Dockerfile.fedorapip b/redfish-client/tests/fedora-25-pip-p2.dkf similarity index 61% rename from redfish-client/local-checks/Dockerfile.fedorapip rename to redfish-client/tests/fedora-25-pip-p2.dkf index 4d29b63..3e2aee5 100644 --- a/redfish-client/local-checks/Dockerfile.fedorapip +++ b/redfish-client/tests/fedora-25-pip-p2.dkf @@ -1,6 +1,6 @@ -FROM fedora:23 +FROM fedora:25 RUN dnf install -y python-pip RUN mkdir /var/log/python-redfish -RUN pip install python-redfish +RUN pip install python-redfish --pre CMD ["/bin/bash"] diff --git a/redfish-client/local-checks/Dockerfile.fedora b/redfish-client/tests/fedora-25-src-p2.dkf similarity index 95% rename from redfish-client/local-checks/Dockerfile.fedora rename to redfish-client/tests/fedora-25-src-p2.dkf index b28b8dd..a0c1ad2 100644 --- a/redfish-client/local-checks/Dockerfile.fedora +++ b/redfish-client/tests/fedora-25-src-p2.dkf @@ -1,4 +1,4 @@ -FROM fedora:23 +FROM fedora:25 RUN dnf install -y python-pip && \ dnf install -y tar COPY python-redfish.src.tar.gz /python-redfish.src.tar.gz diff --git a/redfish-client/local-checks/Dockerfile.fedorap3 b/redfish-client/tests/fedora-25-src-p3.dkf similarity index 95% rename from redfish-client/local-checks/Dockerfile.fedorap3 rename to redfish-client/tests/fedora-25-src-p3.dkf index f2fbc89..8f86378 100644 --- a/redfish-client/local-checks/Dockerfile.fedorap3 +++ b/redfish-client/tests/fedora-25-src-p3.dkf @@ -1,4 +1,4 @@ -FROM fedora:23 +FROM fedora:25 RUN dnf install -y python3-pip && \ dnf install -y tar COPY python-redfish.src.tar.gz /python-redfish.src.tar.gz diff --git a/redfish-client/local-checks/check_client.py b/redfish-client/tests/test_client.py similarity index 63% rename from redfish-client/local-checks/check_client.py rename to redfish-client/tests/test_client.py index 9a4ba15..083d1fd 100644 --- a/redfish-client/local-checks/check_client.py +++ b/redfish-client/tests/test_client.py @@ -10,6 +10,7 @@ import os import stat import subprocess import re +import pytest from docker import Client from path import Path standard_library.install_aliases() @@ -21,7 +22,7 @@ class DockerTest(object): def build(self, dockerfile): dockerfile = Path(dockerfile) - tag = 'rf' + dockerfile.basename().replace('Dockerfile.', '') + tag = 'rf-' + dockerfile.basename().replace('.dkf', '') dockerfile.copy('redfish-client/tests/Dockerfile') response = [line for line in self.cli.build( path='redfish-client/tests', @@ -42,20 +43,31 @@ class DockerTest(object): return(response.decode('utf8')) -def test_dockersocket(): - mode = os.stat('/var/run/docker.sock').st_mode +def local_docker_available(): + try: + mode = os.stat('/var/run/docker.sock').st_mode + except OSError: + return False isSocket = stat.S_ISSOCK(mode) - assert isSocket, 'Make sure docker services are running' + if not isSocket: + print('Make sure docker services are running') + return False - -def test_docker(): cli = Client(base_url='unix://var/run/docker.sock') response = cli.containers() - assert isinstance(response, list), 'Ensure you have sufficiant' + \ - 'credentials to use docker with' + \ - 'your current user' + if not isinstance(response, list): + print('Ensure you have sufficiant' + + 'credentials to use docker with' + + 'your current user') + return False + return True +local_docker = pytest.mark.skipif( + not local_docker_available(), reason="Docker is not available locally") + + +@local_docker def test_sources(): output = subprocess.check_output(["python", "setup.py", "sdist"]) search = re.search(r"removing '(\S+)'", str(output)) @@ -64,15 +76,17 @@ def test_sources(): assert Path('redfish-client/tests/python-redfish.src.tar.gz').isfile() +@local_docker def test_dockerbuild(): docker = DockerTest() # Warning : Image tag is derived from file name, do not use uppercase !!! - dockerfiles = ('redfish-client/tests/Dockerfile.ubuntu', - 'redfish-client/tests/Dockerfile.debian', - 'redfish-client/tests/Dockerfile.centos', - 'redfish-client/tests/Dockerfile.fedora', - 'redfish-client/tests/Dockerfile.fedorap3', - 'redfish-client/tests/Dockerfile.fedorapip') + # because docker image tags can not use uppercase so far. + dockerfiles = ('redfish-client/tests/ubuntu-16.04-src-p2.dkf', + 'redfish-client/tests/debian-8-src-p2.dkf', + 'redfish-client/tests/centos-7-src-p2.dkf', + 'redfish-client/tests/fedora-25-src-p2.dkf', + 'redfish-client/tests/fedora-25-src-p3.dkf', + 'redfish-client/tests/fedora-25-pip-p2.dkf',) for dockerfile in dockerfiles: print('Testing : {}'.format(dockerfile)) response = docker.build(dockerfile) @@ -80,10 +94,15 @@ def test_dockerbuild(): assert 'Successfully built' in status +@local_docker def test_install(): docker = DockerTest() - images = ('rfubuntu', 'rfdebian', 'rfcentos', - 'rffedora', 'rffedorap3', 'rffedorapip') + images = ('rf-ubuntu-16.04-src-p2', + 'rf-debian-8-src-p2', + 'rf-centos-7-src-p2', + 'rf-fedora-25-src-p2', + 'rf-fedora-25-src-p3', + 'rf-fedora-25-pip-p2') for img in images: print('Testing : {}'.format(img)) response = docker.run(img, 'redfish-client config showall') @@ -91,10 +110,15 @@ def test_install(): assert ('Managers configured' in response and 'None' in response) +@local_docker def test_versionformat(): docker = DockerTest() - images = ('rfubuntu', 'rfdebian', 'rfcentos', - 'rffedora', 'rffedorap3', 'rffedorapip') + images = ('rf-ubuntu-16.04-src-p2', + 'rf-debian-8-src-p2', + 'rf-centos-7-src-p2', + 'rf-fedora-25-src-p2', + 'rf-fedora-25-src-p3', + 'rf-fedora-25-pip-p2') for img in images: print('Testing : {}'.format(img)) response = docker.run(img, 'redfish-client --version') diff --git a/redfish-client/local-checks/Dockerfile.debian b/redfish-client/tests/ubuntu-16.04-src-p2.dkf similarity index 96% rename from redfish-client/local-checks/Dockerfile.debian rename to redfish-client/tests/ubuntu-16.04-src-p2.dkf index e5c01fc..87d61ce 100644 --- a/redfish-client/local-checks/Dockerfile.debian +++ b/redfish-client/tests/ubuntu-16.04-src-p2.dkf @@ -1,4 +1,4 @@ -FROM debian:jessie +FROM ubuntu:16.04 ENV DEBIAN_FRONTEND noninteractive RUN apt-get update && \ apt-get install -y apt-utils && \ diff --git a/test-requirements.txt b/test-requirements.txt index 9ba4b3c..0ce4eb0 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -5,7 +5,9 @@ pytest>=2.6.4 coverage>=3.6 mock>=1.0.1 -docker-py>=1.1.0 +# docker-py has a lot of naming changes coming with 2.0 so stick with 1.x +# the library 2.0 will be called docker instead of docker-py +docker-py>=1.8.1 # Apache-2.0 path.py>=5.2 testrepository>=0.0.20 flake8<2.6.0,>=2.5.4 # MIT