From 7a98693095d76a10cc0fb474adc5ca9b87cc17ea Mon Sep 17 00:00:00 2001 From: Pete Vander Giessen Date: Tue, 15 Aug 2017 13:52:41 +0000 Subject: [PATCH] Added snapstack tests. We now test the cinder snap in the middle of a deployed openstack environment. Change-Id: I10ed4d67f96caef5623d9c411ef55946c0bfd216 --- .gitignore | 9 +++ tests/cinder.sh | 62 +++++++++++++++++++ tests/cinder_cleanup.sh | 14 +++++ .../cinder/cinder/cinder.conf.d/database.conf | 2 + .../cinder/cinder/cinder.conf.d/keystone.conf | 13 ++++ .../cinder/cinder/cinder.conf.d/lvm.conf | 11 ++++ .../cinder/cinder/cinder.conf.d/rabbitmq.conf | 2 + .../snap-cinder/tgt/conf.d/cinder_tgt.conf | 1 + tests/snapstack_test.py | 28 +++++++++ tox.ini | 15 +++-- 10 files changed, 152 insertions(+), 5 deletions(-) create mode 100755 tests/cinder.sh create mode 100644 tests/cinder_cleanup.sh create mode 100644 tests/etc/snap-cinder/cinder/cinder/cinder.conf.d/database.conf create mode 100644 tests/etc/snap-cinder/cinder/cinder/cinder.conf.d/keystone.conf create mode 100644 tests/etc/snap-cinder/cinder/cinder/cinder.conf.d/lvm.conf create mode 100644 tests/etc/snap-cinder/cinder/cinder/cinder.conf.d/rabbitmq.conf create mode 100644 tests/etc/snap-cinder/tgt/conf.d/cinder_tgt.conf create mode 100644 tests/snapstack_test.py diff --git a/.gitignore b/.gitignore index 07ee36e..be29be6 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,12 @@ prime stage *.snap .tox + +# Snapcraft +.snapcraft +__pycache__ +.cache + +# emacs +*~ +\#* diff --git a/tests/cinder.sh b/tests/cinder.sh new file mode 100755 index 0000000..5b74192 --- /dev/null +++ b/tests/cinder.sh @@ -0,0 +1,62 @@ +#!/bin/bash + +set -ex + +DEBIAN_FRONTEND='noninteractive' sudo -E apt install --yes tgt + +sudo mysql -u root << EOF +CREATE DATABASE IF NOT EXISTS cinder; +GRANT ALL PRIVILEGES ON cinder.* TO 'cinder'@'localhost' \ + IDENTIFIED BY 'cinder'; +EOF + +source $BASE_DIR/admin-openrc + +while sudo [ ! -d /var/snap/cinder/common/etc/cinder/ ]; do sleep 0.1; done; +sudo cp -r $BASE_DIR/etc/snap-cinder/cinder/* /var/snap/cinder/common/etc/ +sudo cp -r $BASE_DIR/etc/snap-cinder/tgt/* /etc/tgt/ + +openstack user show cinder || { + openstack user create --domain default --password cinder cinder + openstack role add --project service --user cinder admin +} + +openstack service show volumev2 || { + openstack service create --name cinderv2 \ + --description "OpenStack Block Storage" volumev2 + + for endpoint in internal admin public; do + openstack endpoint create --region RegionOne \ + volumev2 $endpoint http://localhost:8776/v2/%\(project_id\)s || : + done +} + +openstack service show volumev3 || { + openstack service create --name cinderv3 \ + --description "OpenStack Block Storage" volumev3 + + for endpoint in internal admin public; do + openstack endpoint create --region RegionOne \ + volumev3 $endpoint http://localhost:8776/v3/%\(project_id\)s || : + done +} + +# Manually define alias if snap isn't installed from snap store. +# Otherwise, snap store defines this alias automatically. +snap aliases cinder | grep cinder-manage || sudo snap alias cinder.manage cinder-manage + +sudo cinder-manage db sync + +# Create a file-based loopback device with the cinder volume group on it +if [ ! -e /var/cinder/cinder-volumes-file ]; then + sudo mkdir -p /var/cinder + sudo truncate -s 4096M /var/cinder/cinder-volumes-file + loop_dev=$(sudo losetup -f --show /var/cinder/cinder-volumes-file) + sudo vgcreate cinder-volumes $loop_dev + sudo vgs cinder-volumes +fi + +sudo systemctl restart tgt +sudo systemctl restart snap.cinder.* + +while ! nc -z localhost 8776; do sleep 0.1; done; diff --git a/tests/cinder_cleanup.sh b/tests/cinder_cleanup.sh new file mode 100644 index 0000000..c979874 --- /dev/null +++ b/tests/cinder_cleanup.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +set -x + +sudo mysql -u root << EOF +DROP DATABASE cinder; +EOF + +# Clean up the cinder volume group and file-based loopback device +sudo lvremove -f cinder-volumes +sudo vgremove -f cinder-volumes +loop_dev=$(sudo losetup -j /var/cinder/cinder-volumes-file | awk -F':' '/'cinder-volumes-file'/ { print $1}') +[ -n $loop_dev ] || sudo losetup -d $loop_dev +[ -e /var/cinder/cinder-volumes-file ] && sudo rm /var/cinder/cinder-volumes-file diff --git a/tests/etc/snap-cinder/cinder/cinder/cinder.conf.d/database.conf b/tests/etc/snap-cinder/cinder/cinder/cinder.conf.d/database.conf new file mode 100644 index 0000000..3cc1a68 --- /dev/null +++ b/tests/etc/snap-cinder/cinder/cinder/cinder.conf.d/database.conf @@ -0,0 +1,2 @@ +[database] +connection = mysql+pymysql://cinder:cinder@localhost/cinder diff --git a/tests/etc/snap-cinder/cinder/cinder/cinder.conf.d/keystone.conf b/tests/etc/snap-cinder/cinder/cinder/cinder.conf.d/keystone.conf new file mode 100644 index 0000000..7a32d68 --- /dev/null +++ b/tests/etc/snap-cinder/cinder/cinder/cinder.conf.d/keystone.conf @@ -0,0 +1,13 @@ +[DEFAULT] +auth_strategy = keystone + +[keystone_authtoken] +auth_uri = http://localhost:5000 +auth_url = http://localhost:35357 +memcached_servers = localhost:11211 +auth_type = password +project_domain_name = default +user_domain_name = default +project_name = service +username = cinder +password = cinder diff --git a/tests/etc/snap-cinder/cinder/cinder/cinder.conf.d/lvm.conf b/tests/etc/snap-cinder/cinder/cinder/cinder.conf.d/lvm.conf new file mode 100644 index 0000000..dff75e2 --- /dev/null +++ b/tests/etc/snap-cinder/cinder/cinder/cinder.conf.d/lvm.conf @@ -0,0 +1,11 @@ +[DEFAULT] +enabled_backends = lvm + +[lvm] +volume_group = cinder-volumes +volume_driver = cinder.volume.drivers.lvm.LVMVolumeDriver +volume_name_template = volume-%s +volume_backend_name = lvm +volumes_dir = /var/snap/cinder/common/lib/volumes +iscsi_protocol = iscsi +iscsi_helper = tgtadm diff --git a/tests/etc/snap-cinder/cinder/cinder/cinder.conf.d/rabbitmq.conf b/tests/etc/snap-cinder/cinder/cinder/cinder.conf.d/rabbitmq.conf new file mode 100644 index 0000000..7988700 --- /dev/null +++ b/tests/etc/snap-cinder/cinder/cinder/cinder.conf.d/rabbitmq.conf @@ -0,0 +1,2 @@ +[DEFAULT] +transport_url = rabbit://openstack:rabbitmq@localhost diff --git a/tests/etc/snap-cinder/tgt/conf.d/cinder_tgt.conf b/tests/etc/snap-cinder/tgt/conf.d/cinder_tgt.conf new file mode 100644 index 0000000..d44228d --- /dev/null +++ b/tests/etc/snap-cinder/tgt/conf.d/cinder_tgt.conf @@ -0,0 +1 @@ +include /var/snap/cinder/common/lib/volumes/* diff --git a/tests/snapstack_test.py b/tests/snapstack_test.py new file mode 100644 index 0000000..3db0659 --- /dev/null +++ b/tests/snapstack_test.py @@ -0,0 +1,28 @@ +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. + + ''' + cinder = Step( + snap='cinder', + script_loc='./tests/', + scripts=['cinder.sh'], + files=[ + 'etc/snap-cinder/cinder/cinder/cinder.conf.d/database.conf', + 'etc/snap-cinder/cinder/cinder/cinder.conf.d/keystone.conf', + 'etc/snap-cinder/cinder/cinder/cinder.conf.d/lvm.conf', + 'etc/snap-cinder/cinder/cinder/cinder.conf.d/rabbitmq.conf', + 'etc/snap-cinder/tgt/conf.d/cinder_tgt.conf' + ], + snap_store=False) + + plan = Plan(tests=[cinder]) + plan.run() diff --git a/tox.ini b/tox.ini index 7360ffc..936e0d9 100644 --- a/tox.ini +++ b/tox.ini @@ -5,14 +5,19 @@ skipsdist = True [testenv] basepython = python3.5 install_command = pip install {opts} {packages} -passenv = HOME TERM +passenv = + HOME + TERM + SNAPSTACK_HTTP_PROXY + SNAPSTACK_HTTPS_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/