Add Amulet functional tests

Add amulet tests; these are currently a copy of the
tests from the openvswitch-odl charm but do provide
some base level of functional verification of the
charm.

Enable test targets for currently supported releases
of OpenStack and Ubuntu.

Change-Id: I8486e30297b7d5e4bc9649ef94a6e447315bfbd8
This commit is contained in:
James Page 2016-04-19 09:33:49 +01:00
parent baf633e1d0
commit 931b4b8bb1
10 changed files with 331 additions and 1 deletions

17
.project Normal file
View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>neutron-api-odl</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.python.pydev.PyDevBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.python.pydev.pythonNature</nature>
</natures>
</projectDescription>

8
.pydevproject Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?eclipse-pydev version="1.0"?><pydev_project>
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
<path>/neutron-api-odl</path>
</pydev_pathproperty>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.7</pydev_property>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
</pydev_project>

View File

@ -11,7 +11,7 @@ test:
functional_test:
@echo Starting Amulet tests...
@tests/setup/00-setup
@juju test -v -p AMULET_HTTP_PROXY,AMULET_OS_VIP --timeout 2700
@juju test -v -p AMULET_HTTP_PROXY,AMULET_OS_VIP,AMULET_ODL_LOCATION,AMULET_ODL_BE_LOCATION --timeout 2700
bin/charm_helpers_sync.py:
@mkdir -p bin

View File

@ -0,0 +1,8 @@
#!/usr/bin/python
"""Amulet tests on a basic openvswitch ODL deployment on trusty-icehouse."""
from basic_deployment import NeutronAPIODLBasicDeployment
if __name__ == '__main__':
deployment = NeutronAPIODLBasicDeployment(series='trusty')
deployment.run_tests()

10
tests/017-basic-trusty-kilo Executable file
View File

@ -0,0 +1,10 @@
#!/usr/bin/python
"""Amulet tests on a basic openvswitch ODL deployment on trusty-kilo."""
from basic_deployment import NeutronAPIODLBasicDeployment
if __name__ == '__main__':
deployment = NeutronAPIODLBasicDeployment(series='trusty',
openstack='cloud:trusty-kilo',
source='cloud:trusty-updates/kilo')
deployment.run_tests()

10
tests/018-basic-trusty-liberty Executable file
View File

@ -0,0 +1,10 @@
#!/usr/bin/python
"""Amulet tests on a basic openvswitch ODL deployment on trusty-liberty."""
from basic_deployment import NeutronAPIODLBasicDeployment
if __name__ == '__main__':
deployment = NeutronAPIODLBasicDeployment(series='trusty',
openstack='cloud:trusty-liberty',
source='cloud:trusty-updates/liberty')
deployment.run_tests()

10
tests/019-basic-trusty-mitaka Executable file
View File

@ -0,0 +1,10 @@
#!/usr/bin/python
"""Amulet tests on a basic openvswitch ODL deployment on trusty-mitaka."""
from basic_deployment import NeutronAPIODLBasicDeployment
if __name__ == '__main__':
deployment = NeutronAPIODLBasicDeployment(series='trusty',
openstack='cloud:trusty-mitaka',
source='cloud:trusty-updates/mitaka')
deployment.run_tests()

8
tests/020-basic-wily-liberty Executable file
View File

@ -0,0 +1,8 @@
#!/usr/bin/python
"""Amulet tests on a basic openvswitch ODL deployment on wily-liberty."""
from basic_deployment import NeutronAPIODLBasicDeployment
if __name__ == '__main__':
deployment = NeutronAPIODLBasicDeployment(series='wily')
deployment.run_tests()

9
tests/021-basic-xenial-mitaka Executable file
View File

@ -0,0 +1,9 @@
#!/usr/bin/python
"""Amulet tests on a basic openvswitch ODL deployment on xenial-mitaka."""
from basic_deployment import NeutronAPIODLBasicDeployment
if __name__ == '__main__':
deployment = NeutronAPIODLBasicDeployment(series='xenial',
odl_version='beryllium')
deployment.run_tests()

250
tests/basic_deployment.py Normal file
View File

@ -0,0 +1,250 @@
#!/usr/bin/python
import amulet
import os
from neutronclient.v2_0 import client as neutronclient
from charmhelpers.contrib.openstack.amulet.deployment import (
OpenStackAmuletDeployment
)
from charmhelpers.contrib.openstack.amulet.utils import (
OpenStackAmuletUtils,
DEBUG,
)
# Use DEBUG to turn on debug logging
u = OpenStackAmuletUtils(DEBUG)
ODL_QUERY_PATH = '/restconf/operational/opendaylight-inventory:nodes/'
ODL_PROFILES = {
'helium': {
'location': 'AMULET_ODL_LOCATION',
'profile': 'openvswitch-odl'
},
'beryllium': {
'location': 'AMULET_ODL_BE_LOCATION',
'profile': 'openvswitch-odl-beryllium'
},
}
class NeutronAPIODLBasicDeployment(OpenStackAmuletDeployment):
"""Amulet tests on a basic neutron-openvswtich deployment."""
def __init__(self, series, openstack=None, source=None, git=False,
stable=False, odl_version='helium'):
"""Deploy the entire test environment."""
super(NeutronAPIODLBasicDeployment, self).__init__(series, openstack,
source, stable)
self.odl_version = odl_version
self._add_services()
self._add_relations()
self._configure_services()
self._deploy()
self._initialize_tests()
def _add_services(self):
"""Add services
Add the services that we're testing, where openvswitch-odl is local,
and the rest of the service are from lp branches that are
compatible with the local charm (e.g. stable or next).
"""
this_service = {'name': 'neutron-api-odl'}
other_services = [
{
'name': 'nova-compute',
'constraints': {'mem': '4G'},
},
{
'name': 'openvswitch-odl',
},
{
'name': 'neutron-gateway',
},
{
'name': 'odl-controller',
'constraints': {'mem': '8G'},
},
{
'name': 'neutron-api',
},
{'name': 'mysql'},
{'name': 'rabbitmq-server'},
{'name': 'keystone'},
{'name': 'nova-cloud-controller'},
{'name': 'glance'},
]
super(NeutronAPIODLBasicDeployment, self)._add_services(this_service,
other_services)
def _add_relations(self):
"""Add all of the relations for the services."""
relations = {
'neutron-api:neutron-plugin-api-subordinate':
'neutron-api-odl:neutron-plugin-api-subordinate',
'nova-compute:neutron-plugin': 'openvswitch-odl:neutron-plugin',
'openvswitch-odl:ovsdb-manager': 'odl-controller:ovsdb-manager',
'neutron-api-odl:odl-controller': 'odl-controller:controller-api',
'keystone:shared-db': 'mysql:shared-db',
'nova-cloud-controller:shared-db': 'mysql:shared-db',
'nova-cloud-controller:amqp': 'rabbitmq-server:amqp',
'nova-cloud-controller:image-service': 'glance:image-service',
'nova-cloud-controller:identity-service':
'keystone:identity-service',
'nova-compute:cloud-compute':
'nova-cloud-controller:cloud-compute',
'nova-compute:amqp': 'rabbitmq-server:amqp',
'nova-compute:image-service': 'glance:image-service',
'glance:shared-db': 'mysql:shared-db',
'glance:identity-service': 'keystone:identity-service',
'glance:amqp': 'rabbitmq-server:amqp',
'neutron-api:shared-db': 'mysql:shared-db',
'neutron-api:amqp': 'rabbitmq-server:amqp',
'neutron-api:neutron-api': 'nova-cloud-controller:neutron-api',
'neutron-api:identity-service': 'keystone:identity-service',
'neutron-gateway:amqp': 'rabbitmq-server:amqp',
'neutron-gateway:neutron-plugin-api':
'neutron-api:neutron-plugin-api',
'neutron-gateway:quantum-network-service':
'nova-cloud-controller:quantum-network-service',
'neutron-gateway:juju-info': 'openvswitch-odl:container',
}
super(NeutronAPIODLBasicDeployment, self)._add_relations(relations)
def _configure_services(self):
"""Configure all of the services."""
neutron_api = {
'neutron-security-groups': False,
}
nova_compute = {
'enable-live-migration': False,
}
keystone = {
'admin-password': 'openstack',
'admin-token': 'ubuntutesting',
}
mysql = {
'dataset-size': '50%',
}
odl_controller = {}
if os.environ.get(ODL_PROFILES[self.odl_version]['location']):
odl_controller['install-url'] = \
os.environ.get(ODL_PROFILES[self.odl_version]['location'])
if os.environ.get('AMULET_HTTP_PROXY'):
odl_controller['http-proxy'] = \
os.environ['AMULET_HTTP_PROXY']
if os.environ.get('AMULET_HTTP_PROXY'):
odl_controller['https-proxy'] = \
os.environ['AMULET_HTTP_PROXY']
odl_controller['profile'] = \
ODL_PROFILES[self.odl_version]['profile']
neutron_gateway = {
'plugin': 'ovs-odl'
}
neutron_api_odl = {
'overlay-network-type': 'vxlan gre',
}
nova_cc = {
'network-manager': 'Neutron',
}
configs = {
'neutron-api': neutron_api,
'nova-compute': nova_compute,
'keystone': keystone,
'mysql': mysql,
'odl-controller': odl_controller,
'neutron-api-odl': neutron_api_odl,
'neutron-gateway': neutron_gateway,
'nova-cloud-controller': nova_cc,
}
super(NeutronAPIODLBasicDeployment, self)._configure_services(configs)
def _initialize_tests(self):
"""Perform final initialization before tests get run."""
# Access the sentries for inspecting service units
self.compute_sentry = self.d.sentry['nova-compute'][0]
self.neutron_api_sentry = self.d.sentry['neutron-api'][0]
self.ovsodl_sentry = self.d.sentry['openvswitch-odl'][0]
self.mysql_sentry = self.d.sentry['mysql'][0]
self.rabbitmq_server_sentry = self.d.sentry['rabbitmq-server'][0]
self.keystone_sentry = self.d.sentry['keystone'][0]
self.glance_sentry = self.d.sentry['glance'][0]
self.nova_cc_sentry = self.d.sentry['nova-cloud-controller'][0]
self.neutron_api_odl_sentry = self.d.sentry['neutron-api-odl'][0]
self.odl_controller_sentry = self.d.sentry['odl-controller'][0]
self.gateway_sentry = self.d.sentry['neutron-gateway'][0]
self.keystone = u.authenticate_keystone_admin(self.keystone_sentry,
user='admin',
password='openstack',
tenant='admin')
ep = self.keystone.service_catalog.url_for(service_type='identity',
endpoint_type='publicURL')
self.neutron = neutronclient.Client(auth_url=ep,
username='admin',
password='openstack',
tenant_name='admin',
region_name='RegionOne')
def test_services(self):
"""Verify the expected services are running on the corresponding
service units."""
commands = {
self.compute_sentry: ['nova-compute',
'openvswitch-switch'],
self.gateway_sentry: ['openvswitch-switch',
'neutron-dhcp-agent',
'neutron-l3-agent',
'neutron-metadata-agent',
'neutron-metering-agent',
'neutron-lbaas-agent',
'nova-api-metadata'],
self.odl_controller_sentry: ['odl-controller'],
}
ret = u.validate_services_by_name(commands)
if ret:
amulet.raise_status(amulet.FAIL, msg=ret)
def test_gateway_bridges(self):
"""Ensure that all bridges are present and configured with the
ODL controller as their NorthBound controller URL."""
odl_ip = self.odl_controller_sentry.relation(
'ovsdb-manager',
'openvswitch-odl:ovsdb-manager'
)['private-address']
# NOTE: 6633 is legacy 6653 is IANA assigned
if self.odl_version == 'helium':
controller_url = "tcp:{}:6633".format(odl_ip)
check_bridges = ['br-int', 'br-ex', 'br-data']
else:
controller_url = "tcp:{}:6653".format(odl_ip)
# NOTE: later ODL releases only manage br-int
check_bridges = ['br-int']
cmd = 'ovs-vsctl list-br'
output, _ = self.gateway_sentry.run(cmd)
bridges = output.split()
for bridge in check_bridges:
if bridge not in bridges:
amulet.raise_status(
amulet.FAIL,
msg="Missing bridge {} from gateway unit".format(bridge)
)
cmd = 'ovs-vsctl get-controller {}'.format(bridge)
br_controllers, _ = self.gateway_sentry.run(cmd)
# Beware of duplicate entries:
# https://bugs.opendaylight.org/show_bug.cgi?id=960
br_controllers = list(set(br_controllers.split('\n')))
if len(br_controllers) != 1 or br_controllers[0] != controller_url:
status, _ = self.gateway_sentry.run('ovs-vsctl show')
amulet.raise_status(
amulet.FAIL,
msg="Controller configuration on bridge"
" {} incorrect: {} != {}\n"
"{}".format(bridge,
br_controllers,
controller_url,
status)
)