Makes running api tests via tox simpler

Change-Id: I92c7a010e6e6119f082459ca6b6748ca93cf95bd
This commit is contained in:
Obulpathi 2015-02-16 16:04:19 -05:00 committed by amitgandhinz
parent 149975ed11
commit 9ba23456cd
5 changed files with 71 additions and 24 deletions

View File

@ -0,0 +1,5 @@
cassandra:
build: ../cassandra/.
ports:
- "9160:9160"
- "9042:9042"

View File

@ -23,6 +23,17 @@ from poppy.openstack.common import log
LOG = log.getLogger(__name__)
_CLI_OPTIONS = (
cfg.BoolOpt('daemon', default=False,
help='Run Poppy server in the background.'),
)
# NOTE (Obulpathi): Register daemon command line option for
# poppy-server
CONF = cfg.CONF
CONF.register_cli_opts(_CLI_OPTIONS)
_DEFAULT_OPTIONS = [
cfg.StrOpt('datacenter', default='',
help='Host datacenter of the API'),

View File

@ -12,6 +12,7 @@
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
from oslo.config import cfg
@ -28,4 +29,35 @@ def run():
conf(project='poppy', prog='poppy')
server = bootstrap.Bootstrap(conf)
# The following code is to daemonize poppy-server to avoid
# an issue with wsgiref writing to stdout/stderr when we don't
# want it to. This is specifically needed to allow poppy to
# run under devstack, but it may also be useful for other scenarios.
# Open /dev/zero and /dev/null for redirection.
# Daemonizing poppy-server is needed *just* when running under devstack
# and when poppy is invoked with `daemon` command line option.
if conf.daemon:
zerofd = os.open('/dev/zero', os.O_RDONLY)
nullfd = os.open('/dev/null', os.O_WRONLY)
# Close the stdthings and reassociate them with a non terminal
os.dup2(zerofd, 0)
os.dup2(nullfd, 1)
os.dup2(nullfd, 2)
# Detach process context, this requires 2 forks.
try:
pid = os.fork()
if pid > 0:
os._exit(0)
except OSError:
os._exit(1)
try:
pid = os.fork()
if pid > 0:
os._exit(0)
except OSError:
os._exit(2)
server.run()

View File

@ -21,11 +21,14 @@ To run the tests
export CAFE_ROOT_LOG_PATH=~/.poppy/logs
export CAFE_TEST_LOG_PATH=~/.poppy/logs
3. Copy the api.conf file to the path set by CAFE_CONFIG_FILE_PATH::
3. The API tests require a running database (eg cassandra), in order to
run via tox.
4. Copy the api.conf file to the path set by CAFE_CONFIG_FILE_PATH::
cp tests/etc/api.conf ~/.poppy/tests.conf
4. Once you are ready to run the tests::
5. Once you are ready to run the tests::
cd tests/api
nosetests
@ -34,26 +37,18 @@ To run the tests
Tox Support
-----------
The API tests require cassandra running in your local machine, in order to
run via tox. It is assumed you already have the Cassandra instance up &
running locally. You can make the API tests part of tox, by overriding the
default positional argument in tox.ini::
tox -- --exclude=None
You can run tox using a docker container hosting Cassandra::
Alternatively, you can run tox with docker containers running Cassandra::
Note - This will require docker (or boot2docker for MacOSX) to already be installed on the system.
This will require docker (or boot2docker for MacOSX) to already be installed on the system.
It will use the fig_local.yaml file to mount your local folder, as described in the Docker folder.
Also, dont forget to update your ~/.poppy/tests.conf to point to your docker ip address.
Example 1: Run all API tests::
tox -e apidocker api
Example 2: Run a particular test function::
tox -e apidocker api/services/test_services.py:TestCreateService -- -m test_create_service_positive
1. Update your `~/.poppy/tests.conf` to point to your docker cassandra container ip address.
Example 1: Run all API tests against a docker hosted cassandra instance::
tox -e api
Example 2: Run a particular API test function::
tox -e api api/services/test_services.py:TestCreateService -- -m test_create_service_positive

10
tox.ini
View File

@ -61,10 +61,12 @@ exclude = .venv*,venv*,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*.egg,
[hacking]
import_exceptions = poppy.openstack.common.gettextutils._
[testenv:apidocker]
[testenv:api]
deps = -r{toxinidir}/requirements/requirements.txt
-r{toxinidir}/tests/test-requirements.txt
whitelist_externals = docker
whitelist_externals =
docker
sleep
setenv = CAFE_CONFIG_FILE_PATH={homedir}/.poppy/tests.conf
CAFE_ROOT_LOG_PATH={homedir}/.poppy/logs
CAFE_TEST_LOG_PATH={homedir}/.poppy/logs
@ -80,5 +82,7 @@ commands =
pip install git+https://github.com/stackforge/opencafe.git#egg=cafe
pip install -U fig
{toxinidir}/docker/fig/dev -f fig_local.yml up -d
fig -f docker/fig/fig_cassandra.yml up -d
sleep 5
poppy-server --daemon
nosetests {posargs:--nologcapture}