Running OpenStack Keystone tests in Docker container on Mac

  • Tutorial
The following describes how to run Keystone tests in a Docker container on OS X and why I needed it.



I sometimes write small patches in Openstack, mainly in Keystone. I do this on my laptop with OS X. In 2009, I switched from Linux to Mac, because at the latter it was no less convenient to develop, and doing everything else was much more convenient. Unfortunately, recently the first statement often turns out to be false. For example, Apple began to update system open source libraries very slowly, which affected Keystone tests - first because of the old OpenSSL, and then python-ldap. About this, for example, Keystone PTL Morgan Fainberg writes . He begins optimistic

NOTICE: OS X based testing / running of Keystone will likely be deprecated

You can fight it, but the pleasure is not that.

At first I switched to VM with Ubuntu, which removed all the problems with running the tests, but setting up and maintaining another development environment is a task that I would like to avoid. Starting a VM just because of tests is a waste. In addition, the small differences between Mac and Lunux (shell, MacVim) were a bit annoying. Therefore, I decided to continue development on Mac, running tests in a docker container in the same iTerm2. Further step by step instructions.

First, create a project
$ mkdir  ../docker
$ cd ../docker
$ vim Dockerfile


Writing a Dockerfile
FROM ubuntu:14.04
MAINTAINER XXX "xxx@gmail.com"
RUN apt-get update
RUN apt-get install -y python
RUN apt-get install -y git
RUN apt-get install -y python-setuptools
RUN apt-get install -y python-pip
RUN pip install virtualenv
RUN apt-get install -y gettext
RUN apt-get install -y python-dev python3-dev libxml2-dev libxslt1-dev
RUN apt-get install -y libsasl2-dev libsqlite3-dev libssl-dev libldap2-dev libffi-dev
RUN pip install tox
RUN apt-get install -y python-tox


Create a container:
$ docker build -t="hashmap/keystone-dev" .


We get:
Sending build context to Docker daemon 2.048 kB
Sending build context to Docker daemon 
Step 0 : FROM ubuntu:14.04
 ---> 63e3c10217b8
...
Unpacking python-tox (1.6.0-1ubuntu1) ...
Setting up libjs-jquery (1.7.2+dfsg-2ubuntu1) ...
Setting up libjs-underscore (1.4.4-2ubuntu1) ...
Setting up libjs-sphinxdoc (1.2.2+dfsg-1ubuntu1.1) ...
Setting up python-py (1.4.20-1) ...
Setting up python-virtualenv (1.11.4-1) ...
Setting up python-tox (1.6.0-1ubuntu1) ...
 ---> 41f003afb987
Removing intermediate container 52fa1fca6272
Successfully built 41f003afb987


Now we get the keystone sources
$ mkdir -p ~/projects/openstack/
$ cd  ~/projects/openstack/
$ git clone https://github.com/openstack/keystone.git


We launch the container
$ docker run -it -v ~/projects/openstack/keystone/:/keystone hashmap/keystone-dev


We get the session inside the container:
root@ecc4228056af:/# cd /keystone


Once we need to configure venv
$ python tools/install_venv.py
$ source .venv/bin/activate
$ python -c "import keystone"


If no errors have occurred, everything is configured. You can also update the database:
$ root@e29e21a501f0:/keystone# ./.venv/bin/keystone-manage db_sync


Now run the test
$ tox -e py27
...
 - Passed: 4254
 - Skipped: 1234
 - Expected Fail: 0
 - Unexpected Success: 0
 - Failed: 0
...
 py27: commands succeeded
 congratulations :)

Now you can run a container with tests from time to time. I didn’t measure it, but it’s noticeable that the tests are performed more slowly, on the other hand, I gave them exactly half of the laptop’s resources.

As a result, we have a Mac development environment with working tests, a luxury in the current situation!

PS If you liked KDPV - let me know, the docker-girl of our company will appear in the following posts.

Also popular now: