Wait for a configured test router to become active
The router VM that is spawned during RUG startup may not be active until some time after the test suite, causing tests to start before the thing is active. This adds an assertion to the functional test setUp to wait for a configured router to become active before continuing on with any tests. The router to wait on is now configured in test.conf. run_functional.sh will attempt to find the devstack created one, and error if there are multiples. Users can specify their own test router if running outside of the gate env. Change-Id: I2b54ddfcce8dab446ac7418cca61320b370bc999
This commit is contained in:
parent
edb11d9ab1
commit
9942eb1433
|
@ -34,3 +34,5 @@ AUTHORS
|
|||
ChangeLog
|
||||
|
||||
test.conf
|
||||
|
||||
*.swp
|
||||
|
|
|
@ -3,6 +3,7 @@ import ConfigParser
|
|||
import mock
|
||||
import os
|
||||
import testtools
|
||||
import time
|
||||
|
||||
from akanda.rug.api import akanda_client
|
||||
|
||||
|
@ -10,6 +11,7 @@ from novaclient.v1_1 import client as _novaclient
|
|||
from neutronclient.v2_0 import client as _neutronclient
|
||||
|
||||
DEFAULT_CONFIG = os.path.join(os.path.dirname(__file__), 'test.conf')
|
||||
DEFAULT_ACTIVE_TIMEOUT = 340
|
||||
|
||||
|
||||
class AkandaFunctionalBase(testtools.TestCase):
|
||||
|
@ -46,11 +48,12 @@ class AkandaFunctionalBase(testtools.TestCase):
|
|||
self.skipTest('Skipping, no test config found @ %s' %
|
||||
config_file)
|
||||
|
||||
conf_settings = ['os_auth_url', 'os_username', 'os_password',
|
||||
'os_tenant_name', 'service_tenant_name',
|
||||
'service_tenant_id', 'appliance_api_port']
|
||||
req_conf_settings = ['os_auth_url', 'os_username', 'os_password',
|
||||
'os_tenant_name', 'service_tenant_name',
|
||||
'service_tenant_id', 'appliance_api_port',
|
||||
'akanda_test_router_uuid']
|
||||
out = {}
|
||||
for c in conf_settings:
|
||||
for c in req_conf_settings:
|
||||
try:
|
||||
out[c] = config.get('functional', c)
|
||||
except ConfigParser.NoOptionError:
|
||||
|
@ -59,6 +62,15 @@ class AkandaFunctionalBase(testtools.TestCase):
|
|||
if missing:
|
||||
self.fail('Missing required setting in test.conf (%s)'
|
||||
(config_file, ','.join(missing)))
|
||||
|
||||
opt_conf_settings = {
|
||||
'appliance_active_timeout': DEFAULT_ACTIVE_TIMEOUT,
|
||||
}
|
||||
for setting, default in opt_conf_settings.items():
|
||||
try:
|
||||
out[setting] = config.get('functional', setting)
|
||||
except ConfigParser.NoOptionError:
|
||||
out[setting] = default
|
||||
return out
|
||||
|
||||
@property
|
||||
|
@ -78,3 +90,17 @@ class AkandaFunctionalBase(testtools.TestCase):
|
|||
self.fail('"mgt" port not found on service vm %s (%s)' %
|
||||
(service_vm.id, service_vm.name))
|
||||
return self._management_address['addr']
|
||||
|
||||
def assert_router_is_active(self, router_uuid=None):
|
||||
if not router_uuid:
|
||||
router_uuid = self.config['akanda_test_router_uuid']
|
||||
i = 0
|
||||
router = self.neutronclient.show_router(router_uuid)['router']
|
||||
while router['status'] != 'ACTIVE':
|
||||
if i >= int(self.config['appliance_active_timeout']):
|
||||
raise Exception(
|
||||
'Timed out waiting for router %s to become ACTIVE, '
|
||||
'current status=%s' % (router_uuid, router['status']))
|
||||
time.sleep(1)
|
||||
router = self.neutronclient.show_router(router_uuid)['router']
|
||||
i += 1
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
[functional]
|
||||
os_auth_url=http://127.0.0.1:5000/v2.0
|
||||
os_username=admin
|
||||
os_password=secret
|
||||
os_tenant_name=admin
|
||||
service_tenant_name=service
|
||||
service_tenant_id=5d58fe467c73483c8d68b8610c38554b
|
||||
appliance_api_port=5000
|
|
@ -0,0 +1,17 @@
|
|||
[functional]
|
||||
# OpenStack credentials for the service user
|
||||
os_auth_url=http://127.0.0.1:5000/v2.0
|
||||
os_username=admin
|
||||
os_password=secretadmin
|
||||
os_tenant_name=admin
|
||||
service_tenant_name=service
|
||||
service_tenant_id=80095e2039db4af0a88351d6360c1977
|
||||
|
||||
# The configured appliance API port
|
||||
appliance_api_port=5000
|
||||
|
||||
# The UUID of a running akanda router that will be used for running
|
||||
# tests against. Devstack creates this for you but you may have one
|
||||
# that you wish to use instead. If not supplied here, tools/run_functional.sh
|
||||
# will attempt to find it for you.
|
||||
akanda_test_router_uuid=650da79d-30ee-460f-bf91-8b7e04a5a5f6
|
|
@ -6,6 +6,13 @@ class AkandaApplianceVMTest(base.AkandaFunctionalBase):
|
|||
"""Basic tests to ensure a service VM and its associated router is alive
|
||||
and well.
|
||||
"""
|
||||
def setUp(self):
|
||||
super(AkandaApplianceVMTest, self).setUp()
|
||||
# ensure the devstack spawned router VM becomes active before starting
|
||||
# to run any test cases. this in itself is a test that devstack
|
||||
# produced a functional router.
|
||||
self.assert_router_is_active()
|
||||
|
||||
def test_appliance_is_alive(self):
|
||||
self.assertTrue(
|
||||
self.ak_client.is_alive(
|
||||
|
|
|
@ -9,8 +9,28 @@ if [ -z "$SERVICE_TENANT_ID" ]; then
|
|||
SERVICE_TENANT_ID="$(keystone tenant-list | grep $SERVICE_TENANT_NAME | awk '{ print $2 }')"
|
||||
fi
|
||||
|
||||
# Functional tests require a test akanda router be created prior to the test
|
||||
# run. Devstack does this, but you may specify another here. If not specified,
|
||||
# the ID of the devstack created router will be used.
|
||||
AKANDA_TEST_ROUTER_UUID=${AKANDA_TEST_ROUTER_UUID:-''}
|
||||
|
||||
function find_router() {
|
||||
# Find the UUID of the akanda router created by devstack.
|
||||
router=$(neutron router-list | grep "ak-" | awk '{ print $2 }')
|
||||
if [ $(echo "$router" | wc -l) -gt 1 ]; then
|
||||
echo "ERROR: Found multiple akanda routers, cannot continue."
|
||||
exit 1
|
||||
elif [ -z "$router" ]; then
|
||||
echo "ERROR: Could not locate akanda router."
|
||||
exit 1
|
||||
fi
|
||||
echo $router
|
||||
}
|
||||
|
||||
|
||||
cat <<END >$CONFIG_FILE
|
||||
[functional]
|
||||
appliance_active_timeout=240
|
||||
os_auth_url=$OS_AUTH_URL
|
||||
os_username=$OS_USERNAME
|
||||
os_password=$OS_PASSWORD
|
||||
|
@ -20,4 +40,9 @@ service_tenant_id=$SERVICE_TENANT_ID
|
|||
appliance_api_port=$APPLIANCE_API_PORT
|
||||
END
|
||||
|
||||
sudo -E tox -e functional
|
||||
if [ -z "$AKANDA_TEST_ROUTER_UUID" ]; then
|
||||
AKANDA_TEST_ROUTER_UUID="$(find_router)"
|
||||
fi
|
||||
echo "akanda_test_router_uuid=$AKANDA_TEST_ROUTER_UUID" >>$CONFIG_FILE
|
||||
|
||||
tox -e functional
|
||||
|
|
Loading…
Reference in New Issue