Introduce client testing
This is a first implementation probably a bit raw. So it needs improvement. Tests require: - docker available on host. - docker credentials to the user who is running the tests. Current tests: - Check docker socket - Check docker can be used by api. - Check source installation on Ubuntu, Debian, Fedora. - Check pip installation in Fedora. - Check if client can show an empty configuration. - Check client version format (basic).
This commit is contained in:
parent
3404767cdc
commit
096d58f25e
13
redfish-client/tests/Dockerfile.debian
Normal file
13
redfish-client/tests/Dockerfile.debian
Normal file
@ -0,0 +1,13 @@
|
||||
FROM debian:jessie
|
||||
ENV DEBIAN_FRONTEND noninteractive
|
||||
RUN apt-get update && \
|
||||
apt-get install -y apt-utils && \
|
||||
apt-get install -y python-pip
|
||||
COPY python-redfish.src.tar.gz /python-redfish.src.tar.gz
|
||||
RUN mkdir /var/log/python-redfish
|
||||
RUN tar xvvf python-redfish.src.tar.gz
|
||||
RUN cd python-redfish* && \
|
||||
pip install -r requirements.txt && \
|
||||
python setup.py install
|
||||
CMD ["/bin/bash"]
|
||||
|
11
redfish-client/tests/Dockerfile.fedora
Normal file
11
redfish-client/tests/Dockerfile.fedora
Normal file
@ -0,0 +1,11 @@
|
||||
FROM fedora:23
|
||||
RUN dnf install -y python-pip && \
|
||||
dnf install -y git && \
|
||||
dnf install -y tar
|
||||
COPY python-redfish.src.tar.gz /python-redfish.src.tar.gz
|
||||
RUN mkdir /var/log/python-redfish
|
||||
RUN tar xvvf python-redfish.src.tar.gz
|
||||
RUN cd python-redfish* && \
|
||||
pip install -r requirements.txt && \
|
||||
python setup.py install
|
||||
CMD ["/bin/bash"]
|
7
redfish-client/tests/Dockerfile.fedorapip
Normal file
7
redfish-client/tests/Dockerfile.fedorapip
Normal file
@ -0,0 +1,7 @@
|
||||
FROM fedora:23
|
||||
RUN dnf install -y python-pip && \
|
||||
dnf install -y git
|
||||
RUN mkdir /var/log/python-redfish
|
||||
RUN pip install python-redfish
|
||||
CMD ["/bin/bash"]
|
||||
|
13
redfish-client/tests/Dockerfile.ubuntu
Normal file
13
redfish-client/tests/Dockerfile.ubuntu
Normal file
@ -0,0 +1,13 @@
|
||||
FROM ubuntu:wily
|
||||
ENV DEBIAN_FRONTEND noninteractive
|
||||
RUN apt-get update && \
|
||||
apt-get install -y apt-utils && \
|
||||
apt-get install -y python-pip
|
||||
COPY python-redfish.src.tar.gz /python-redfish.src.tar.gz
|
||||
RUN mkdir /var/log/python-redfish
|
||||
RUN tar xvvf python-redfish.src.tar.gz
|
||||
RUN cd python-redfish* && \
|
||||
pip install -r requirements.txt && \
|
||||
python setup.py install
|
||||
CMD ["/bin/bash"]
|
||||
|
89
redfish-client/tests/test_client.py
Normal file
89
redfish-client/tests/test_client.py
Normal file
@ -0,0 +1,89 @@
|
||||
# coding=utf-8
|
||||
import os
|
||||
import stat
|
||||
import subprocess
|
||||
import re
|
||||
from docker import Client
|
||||
from path import Path
|
||||
|
||||
|
||||
class DockerTest():
|
||||
def __init__(self):
|
||||
self.cli = Client(base_url='unix://var/run/docker.sock')
|
||||
|
||||
def build(self, dockerfile):
|
||||
dockerfile = Path(dockerfile)
|
||||
tag = 'rf' + dockerfile.basename().replace('Dockerfile.', '')
|
||||
dockerfile.copy('redfish-client/tests/Dockerfile')
|
||||
response = [line for line in self.cli.build(
|
||||
path='redfish-client/tests',
|
||||
tag=tag,
|
||||
rm=True)]
|
||||
return(response)
|
||||
|
||||
def run(self, image, command):
|
||||
container = self.cli.create_container(image=image,
|
||||
command=command,
|
||||
tty=True,
|
||||
stdin_open=True)
|
||||
self.cli.start(container=container.get('Id'))
|
||||
self.cli.wait(container=container.get('Id'))
|
||||
response = self.cli.logs(container=container.get('Id'),
|
||||
stdout=True)
|
||||
return(response)
|
||||
|
||||
|
||||
def test_dockersocket():
|
||||
mode = os.stat('/var/run/docker.sock').st_mode
|
||||
isSocket = stat.S_ISSOCK(mode)
|
||||
assert isSocket, 'Make sure docker services are running'
|
||||
|
||||
|
||||
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'
|
||||
|
||||
|
||||
def test_sources():
|
||||
output = subprocess.check_output(["python", "setup.py", "sdist"])
|
||||
search = re.search(r"removing '(\S+)'", output)
|
||||
filename = Path('dist/' + search.group(1) + '.tar.gz')
|
||||
filename.copy('redfish-client/tests/python-redfish.src.tar.gz')
|
||||
assert Path('redfish-client/tests/python-redfish.src.tar.gz').isfile()
|
||||
|
||||
|
||||
def test_dockerbuild():
|
||||
docker = DockerTest()
|
||||
dockerfiles = ('redfish-client/tests/Dockerfile.ubuntu',
|
||||
'redfish-client/tests/Dockerfile.debian',
|
||||
'redfish-client/tests/Dockerfile.fedora',
|
||||
'redfish-client/tests/Dockerfile.fedorapip')
|
||||
for dockerfile in dockerfiles:
|
||||
print('Testing : {}'.format(dockerfile))
|
||||
response = docker.build(dockerfile)
|
||||
status = response.pop()
|
||||
assert 'Successfully built' in status
|
||||
|
||||
|
||||
def test_install():
|
||||
docker = DockerTest()
|
||||
images = ('rfubuntu', 'rfdebian', 'rffedora', 'rffedorapip')
|
||||
for img in images:
|
||||
print('Testing : {}'.format(img))
|
||||
response = docker.run(img, 'redfish-client config showall')
|
||||
print(response)
|
||||
assert ('Managers configured' in response and 'None' in response)
|
||||
|
||||
|
||||
def test_versionformat():
|
||||
docker = DockerTest()
|
||||
images = ('rfubuntu', 'rfdebian', 'rffedora', 'rffedorapip')
|
||||
for img in images:
|
||||
print('Testing : {}'.format(img))
|
||||
response = docker.run(img, 'redfish-client --version')
|
||||
print(response)
|
||||
assert (re.match('redfish-client \d+\.\d+', response))
|
||||
|
@ -2,14 +2,8 @@
|
||||
# of appearance. Changing the order has an impact on the overall integration
|
||||
# process, which may cause wedges in the gate later.
|
||||
|
||||
hacking<0.11,>=0.10.0
|
||||
|
||||
pytest>=2.6.4
|
||||
coverage>=3.6
|
||||
discover
|
||||
python-subunit>=0.0.18
|
||||
sphinx>=1.1.2,!=1.2.0,!=1.3b1,<1.3
|
||||
#oslosphinx>=2.2.0 # Apache-2.0
|
||||
#oslotest>=1.2.0 # Apache-2.0
|
||||
testrepository>=0.0.18
|
||||
testscenarios>=0.4
|
||||
testtools>=0.9.36,!=1.2.0
|
||||
mock>=1.0.1
|
||||
docker-py>=1.1.0
|
||||
path.py>=5.2
|
||||
|
Loading…
Reference in New Issue
Block a user