Configure OpenStack CI to run functional tests

For our default CI jobs, we can add a test-setup.sh script that will run
before OpenStack CI revokes sudo for the "jenkins" user.

At the moment, we cannot add the jenkins user to the docker group to
allow the jenkins user to use docker. Instead, we have to make docker
launch itself so that the jenkins group can access the socket.

Change-Id: I732d144e4635dffe8034c0d374eee591df078f52
This commit is contained in:
Ian Cordasco 2017-02-16 11:31:36 -06:00
parent 656535624e
commit 65c6f941e1
3 changed files with 40 additions and 0 deletions

1
bindep.txt Normal file
View File

@ -0,0 +1 @@
docker.io [platform:dpkg]

View File

@ -7,6 +7,10 @@ from sqlalchemy import MetaData
import testtools
import threading
from oslo_log import log as logging
LOG = logging.getLogger(__name__)
FAKE_DATA_GEN_USERNAME = 'demo'
FAKE_DATA_GEN_TOKEN = 'demo'
@ -32,10 +36,12 @@ class DockerSetup(threading.Thread):
if is_ok != 'OK':
msg = 'Docker daemon ping failed.'
self.error = msg
LOG.error(self.error)
self.container_is_ready.set()
return
except Exception as err:
self.error = err
LOG.error(self.error)
self.container_is_ready.set()
return
@ -45,6 +51,7 @@ class DockerSetup(threading.Thread):
dockerfile='Dockerfile',
pull=True,
forcerm=True)
LOG.debug(build_output)
output_last_line = ""
for output_last_line in build_output:
pass

32
tools/test-setup.sh Executable file
View File

@ -0,0 +1,32 @@
#!/bin/sh
# This script will execute before OpenStack infrastructure revokes sudo
# We need it to allow the Jenkins user to interact with docker
# This tells docker to use the current user's primary group to run the unix
# domain socket for docker. This side-steps the need for the current user to
# be added to the docker group and then have to log out and back in.
sudo dd of=/lib/systemd/system/docker.socket << _EOF_
[Unit]
Description=Docker Socket for the API
PartOf=docker.service
[Socket]
ListenStream=/var/run/docker.sock
SocketMode=0660
SocketUser=root
SocketGroup=$(id -gn)
[Install]
WantedBy=sockets.target
_EOF_
echo "=> Restarting docker"
sudo systemctl daemon-reload
sudo systemctl restart docker
echo "=> Checking permissions on the socket"
stat /var/run/docker.sock
echo "=> Discovering docker version installed"
docker version