Added snapstack tests.

We now test the cinder snap in the middle of a deployed openstack
environment.

Change-Id: I10ed4d67f96caef5623d9c411ef55946c0bfd216
This commit is contained in:
Pete Vander Giessen 2017-08-15 13:52:41 +00:00
parent dc4a038712
commit 7a98693095
10 changed files with 152 additions and 5 deletions

9
.gitignore vendored
View File

@ -3,3 +3,12 @@ prime
stage
*.snap
.tox
# Snapcraft
.snapcraft
__pycache__
.cache
# emacs
*~
\#*

62
tests/cinder.sh Executable file
View File

@ -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;

14
tests/cinder_cleanup.sh Normal file
View File

@ -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

View File

@ -0,0 +1,2 @@
[database]
connection = mysql+pymysql://cinder:cinder@localhost/cinder

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,2 @@
[DEFAULT]
transport_url = rabbit://openstack:rabbitmq@localhost

View File

@ -0,0 +1 @@
include /var/snap/cinder/common/lib/volumes/*

28
tests/snapstack_test.py Normal file
View File

@ -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()

15
tox.ini
View File

@ -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/