From 84668a42dcaefa30c886a4eff3b04a07cedd88d5 Mon Sep 17 00:00:00 2001 From: Pete Vander Giessen Date: Mon, 24 Jul 2017 15:00:41 +0000 Subject: [PATCH] Added snapstack test. Tweaked tox.ini to invoke snapstack, and added test_snapstack.py to tests dir. Also added glance.sh to glance/tests, as part of the plan to move those scripts from snap-test to the individual snaps. Change-Id: Ifbd53392c394ee36cf61d1a07dba825f7b7097b8 --- tests/glance.sh | 41 +++++++++++++++++++++++++++++++++++++++++ tests/snapstack_test.py | 26 ++++++++++++++++++++++++++ tox.ini | 14 +++++++++----- 3 files changed, 76 insertions(+), 5 deletions(-) create mode 100755 tests/glance.sh create mode 100644 tests/snapstack_test.py diff --git a/tests/glance.sh b/tests/glance.sh new file mode 100755 index 0000000..68d8449 --- /dev/null +++ b/tests/glance.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +set -ex + +source $BASE_DIR/admin-openrc + +while sudo [ ! -d /var/snap/glance/common/etc/glance/ ]; do sleep 0.1; done; +sudo cp -r $BASE_DIR/etc/snap-glance/* /var/snap/glance/common/etc/ + +openstack user show glance || { + openstack user create --domain default --password glance glance + openstack role add --project service --user glance admin +} + +openstack service show image || { + openstack service create --name glance --description "OpenStack Image" image + for endpoint in internal admin public; do + openstack endpoint create --region RegionOne \ + image $endpoint http://localhost:9292 || : + done +} + +# Manually define alias if snap isn't installed from snap store. +# Otherwise, snap store defines this alias automatically. +snap aliases glance | grep glance-manage || sudo snap alias glance.manage glance-manage + +sudo glance-manage db_sync + +sudo systemctl restart snap.glance.* + +while ! nc -z localhost 9292; do sleep 0.1; done; + +openstack image show xenial || { + [ -f $HOME/images/xenial-server-cloudimg-amd64-disk1.img ] || { + mkdir -p $HOME/images + wget http://cloud-images.ubuntu.com/xenial/current/xenial-server-cloudimg-amd64-disk1.img \ + -O ${HOME}/images/xenial-server-cloudimg-amd64-disk1.img + } + openstack image create --file ${HOME}/images/xenial-server-cloudimg-amd64-disk1.img \ + --public --container-format=bare --disk-format=qcow2 xenial +} diff --git a/tests/snapstack_test.py b/tests/snapstack_test.py new file mode 100644 index 0000000..913ac62 --- /dev/null +++ b/tests/snapstack_test.py @@ -0,0 +1,26 @@ +import unittest + +from snapstack import Plan, Setup, Step + +class SnapstackTest(unittest.TestCase): + + def test_snapstack(self): + ''' + _test_snapstack_ + + Run a basic smoke test, utilizing our snapstack testing harness. + + ''' + # snapstack already installs glance. Override the 'glance' + # step with a locally built snap. neutron, nova, etc. will still + # be installed as normal from the store. + setup = Setup() + setup.add_steps(('glance', Step( + snap='glance', + script_loc='./tests/', + scripts=['glance.sh'], + snap_store=False))) + + # Execute the snapstack tests + plan = Plan(base_setup=setup.steps()) + plan.run() diff --git a/tox.ini b/tox.ini index 7360ffc..a6fe96f 100644 --- a/tox.ini +++ b/tox.ini @@ -5,14 +5,18 @@ skipsdist = True [testenv] basepython = python3.5 install_command = pip install {opts} {packages} -passenv = HOME TERM +passenv = + HOME + TERM + SNAP_BUILD_PROXY whitelist_externals = sudo snapcraft [testenv:snap] -deps = -r{toxinidir}/requirements.txt +deps = + -r{toxinidir}/requirements.txt + git+https://github.com/openstack-snaps/snapstack + pytest commands = - sudo snap install core - snapcraft clean - snapcraft snap + py.test -s tests/