From 33f4796ec6f4405725b82dbaa353e6ee39005018 Mon Sep 17 00:00:00 2001 From: James Page Date: Mon, 30 Jan 2017 12:33:13 +0000 Subject: [PATCH] Add basic amulet tests, with AMULET overrides for configuration --- src/test-requirements.txt | 23 ++++ src/tests/basic_deployment.py | 158 ++++++++++----------------- src/tests/gate-basic-trusty-icehouse | 19 ---- src/tests/gate-basic-trusty-liberty | 21 ---- src/tests/gate-basic-trusty-mitaka | 16 ++- src/tests/gate-basic-xenial-mitaka | 12 +- src/tox.ini | 42 ++----- tox.ini | 14 ++- 8 files changed, 122 insertions(+), 183 deletions(-) create mode 100644 src/test-requirements.txt delete mode 100755 src/tests/gate-basic-trusty-icehouse delete mode 100755 src/tests/gate-basic-trusty-liberty diff --git a/src/test-requirements.txt b/src/test-requirements.txt new file mode 100644 index 0000000..613b081 --- /dev/null +++ b/src/test-requirements.txt @@ -0,0 +1,23 @@ +# charm-proof +charm-tools>=2.0.0 +# amulet deployment helpers +bzr+lp:charm-helpers#egg=charmhelpers +# BEGIN: Amulet OpenStack Charm Helper Requirements +# Liberty client lower constraints +amulet>=1.14.3,<2.0 +bundletester>=0.6.1,<1.0 +aodhclient>=0.1.0 +python-ceilometerclient>=1.5.0,<2.0 +python-cinderclient>=1.4.0,<2.0 +python-glanceclient>=1.1.0,<2.0 +python-heatclient>=0.8.0,<1.0 +python-keystoneclient>=1.7.1,<2.0 +python-neutronclient>=3.1.0,<4.0 +python-novaclient>=2.30.1,<3.0 +python-openstackclient>=1.7.0,<2.0 +python-swiftclient>=2.6.0,<3.0 +pika>=0.10.0,<1.0 +distro-info +# END: Amulet OpenStack Charm Helper Requirements +# NOTE: workaround for 14.04 pip/tox +pytz diff --git a/src/tests/basic_deployment.py b/src/tests/basic_deployment.py index fef51b2..0a1816a 100644 --- a/src/tests/basic_deployment.py +++ b/src/tests/basic_deployment.py @@ -1,20 +1,21 @@ -# Copyright 2016 Canonical Ltd +# +# Copyright 2017 Canonical Ltd +# # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at +# # http://www.apache.org/licenses/LICENSE-2.0 +# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +import os import amulet -import json -import subprocess -import time - import charmhelpers.contrib.openstack.amulet.deployment as amulet_deployment import charmhelpers.contrib.openstack.amulet.utils as os_amulet_utils @@ -23,13 +24,13 @@ import charmhelpers.contrib.openstack.amulet.utils as os_amulet_utils u = os_amulet_utils.OpenStackAmuletUtils(os_amulet_utils.DEBUG) -class SDNCharmDeployment(amulet_deployment.OpenStackAmuletDeployment): +class KeystoneLDAPCharmDeployment(amulet_deployment.OpenStackAmuletDeployment): """Amulet tests on a basic sdn_charm deployment.""" def __init__(self, series, openstack=None, source=None, stable=False): """Deploy the entire test environment.""" - super(SDNCharmDeployment, self).__init__(series, openstack, - source, stable) + super(KeystoneLDAPCharmDeployment, self).__init__(series, openstack, + source, stable) self._add_services() self._add_relations() self._configure_services() @@ -48,63 +49,65 @@ class SDNCharmDeployment(amulet_deployment.OpenStackAmuletDeployment): 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': 'sdn_charm'} + this_service = {'name': 'keystone-ldap'} other_services = [ - { - 'name': 'nova-compute', - 'constraints': {'mem': '4G'}, - }, - { - 'name': 'neutron-api', - }, - { - 'name': 'neutron-gateway', - }, - {'name': 'mysql'}, - {'name': 'rabbitmq-server'}, {'name': 'keystone'}, - {'name': 'nova-cloud-controller'}, - {'name': 'glance'}, + {'name': 'percona-cluster', 'constraints': {'mem': '3072M'}}, ] - super(SDNCharmDeployment, self)._add_services(this_service, - other_services) + super(KeystoneLDAPCharmDeployment, self)._add_services(this_service, + other_services) def _add_relations(self): """Add all of the relations for the services.""" relations = { - 'nova-compute:neutron-plugin': 'sdn_charm:neutron-plugin', - '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': 'sdn_charm:container', + 'keystone:domain-backend': 'keystone-ldap:domain-backend', + 'keystone:shared-db': 'percona-cluster:shared-db', } - super(SDNCharmDeployment, self)._add_relations(relations) + super(KeystoneLDAPCharmDeployment, self)._add_relations(relations) def _configure_services(self): """Configure all of the services.""" - keystone_config = {'admin-password': 'openstack', - 'admin-token': 'ubuntutesting'} - configs = {'keystone': keystone_config} - super(SDNCharmDeployment, self)._configure_services(configs) + keystone_config = { + 'admin-password': 'openstack', + 'admin-token': 'ubuntutesting', + 'preferred-api-version': 3, + } + keystone_ldap_config = self._get_ldap_config() + pxc_config = { + 'dataset-size': '25%', + 'max-connections': 1000, + 'root-password': 'ChangeMe123', + 'sst-password': 'ChangeMe123', + } + configs = {'keystone': keystone_config, + 'keystone-ldap': keystone_ldap_config, + 'percona-cluster': pxc_config} + super(KeystoneLDAPCharmDeployment, self)._configure_services(configs) + + def _get_ldap_config(self): + # NOTE(jamespage): use amulet variables for CI specific config + keystone_ldap_config = { + 'ldap-server': os.environ.get('AMULET_LDAP_SERVER'), + 'ldap-user': os.environ.get('AMULET_LDAP_USER'), + 'ldap-password': os.environ.get('AMULET_LDAP_PASSWORD'), + 'ldap-suffix': os.environ.get('AMULET_LDAP_SUFFIX'), + 'domain-name': 'userdomain', + } + if all(keystone_ldap_config.values()): + self.ldap_configured = True + return keystone_ldap_config + else: + # NOTE(jamespage): Use mock values to check deployment only + # as no test fixture has been supplied + self.ldap_configured = False + return { + 'ldap-server': 'myserver', + 'ldap-user': 'myuser', + 'ldap-password': 'mypassword', + 'ldap-suffix': 'mysuffix', + 'domain-name': 'userdomain', + } + def _get_token(self): return self.keystone.service_catalog.catalog['token']['id'] @@ -112,63 +115,22 @@ class SDNCharmDeployment(amulet_deployment.OpenStackAmuletDeployment): def _initialize_tests(self): """Perform final initialization before tests get run.""" # Access the sentries for inspecting service units - self.sdn_charm_sentry = self.d.sentry['sdn_charm'][0] - self.mysql_sentry = self.d.sentry['mysql'][0] + self.keystone_ldap = self.d.sentry['keystone-ldap'][0] + self.mysql_sentry = self.d.sentry['percona-cluster'][0] self.keystone_sentry = self.d.sentry['keystone'][0] - self.rabbitmq_sentry = self.d.sentry['rabbitmq-server'][0] - self.sdn_charm_svcs = [ - 'sdn_charm-agent', 'sdn_charm-api'] - # Authenticate admin with keystone endpoint self.keystone = u.authenticate_keystone_admin(self.keystone_sentry, user='admin', password='openstack', tenant='admin') - def check_and_wait(self, check_command, interval=2, max_wait=200, - desc=None): - waited = 0 - while not check_command() or waited > max_wait: - if desc: - u.log.debug(desc) - time.sleep(interval) - waited = waited + interval - if waited > max_wait: - raise Exception('cmd failed {}'.format(check_command)) - - def _run_action(self, unit_id, action, *args): - command = ["juju", "action", "do", "--format=json", unit_id, action] - command.extend(args) - print("Running command: %s\n" % " ".join(command)) - output = subprocess.check_output(command) - output_json = output.decode(encoding="UTF-8") - data = json.loads(output_json) - action_id = data[u'Action queued with id'] - return action_id - - def _wait_on_action(self, action_id): - command = ["juju", "action", "fetch", "--format=json", action_id] - while True: - try: - output = subprocess.check_output(command) - except Exception as e: - print(e) - return False - output_json = output.decode(encoding="UTF-8") - data = json.loads(output_json) - if data[u"status"] == "completed": - return True - elif data[u"status"] == "failed": - return False - time.sleep(2) - def test_100_services(self): """Verify the expected services are running on the corresponding service units.""" u.log.debug('Checking system services on units...') service_names = { - self.sdn_charm_sentry: self.sdn_charm_svcs, + self.keystone_ldap: [], } ret = u.validate_services_by_name(service_names) diff --git a/src/tests/gate-basic-trusty-icehouse b/src/tests/gate-basic-trusty-icehouse deleted file mode 100755 index 10219c4..0000000 --- a/src/tests/gate-basic-trusty-icehouse +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env python -# Copyright 2016 Canonical Ltd -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# http://www.apache.org/licenses/LICENSE-2.0 -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Amulet tests on a basic SDN Charm deployment on trusty-icehouse.""" - -from basic_deployment import SDNCharmDeployment - -if __name__ == '__main__': - deployment = SDNCharmDeployment(series='trusty') - deployment.run_tests() diff --git a/src/tests/gate-basic-trusty-liberty b/src/tests/gate-basic-trusty-liberty deleted file mode 100755 index 88bb4cf..0000000 --- a/src/tests/gate-basic-trusty-liberty +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env python -# Copyright 2016 Canonical Ltd -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# http://www.apache.org/licenses/LICENSE-2.0 -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Amulet tests on a basic SDN Charm deployment on trusty-liberty.""" - -from basic_deployment import SDNCharmDeployment - -if __name__ == '__main__': - deployment = SDNCharmDeployment(series='trusty', - openstack='cloud:trusty-liberty', - source='cloud:trusty-updates/liberty') - deployment.run_tests() diff --git a/src/tests/gate-basic-trusty-mitaka b/src/tests/gate-basic-trusty-mitaka index 018fb27..aded40e 100755 --- a/src/tests/gate-basic-trusty-mitaka +++ b/src/tests/gate-basic-trusty-mitaka @@ -1,21 +1,25 @@ #!/usr/bin/env python -# Copyright 2016 Canonical Ltd +# +# Copyright 2017 Canonical Ltd +# # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at +# # http://www.apache.org/licenses/LICENSE-2.0 +# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -"""Amulet tests on a basic SDN Charm deployment on trusty-mitaka.""" +"""Amulet tests on a basic Keystone LDAP Charm deployment on trusty-mitaka.""" -from basic_deployment import SDNCharmDeployment +from basic_deployment import KeystoneLDAPCharmDeployment if __name__ == '__main__': - deployment = SDNCharmDeployment(series='trusty', - openstack='cloud:trusty-mitaka', - source='cloud:trusty-updates/mitaka') + deployment = KeystoneLDAPCharmDeployment(series='trusty', + openstack='cloud:trusty-mitaka', + source='cloud:trusty-updates/mitaka') deployment.run_tests() diff --git a/src/tests/gate-basic-xenial-mitaka b/src/tests/gate-basic-xenial-mitaka index f6df242..0db6601 100755 --- a/src/tests/gate-basic-xenial-mitaka +++ b/src/tests/gate-basic-xenial-mitaka @@ -1,19 +1,23 @@ #!/usr/bin/env python -# Copyright 2016 Canonical Ltd +# +# Copyright 2017 Canonical Ltd +# # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at +# # http://www.apache.org/licenses/LICENSE-2.0 +# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -"""Amulet tests on a basic SDN Charm deployment on xenial-mitaka.""" +"""Amulet tests on a basic Keystone LDAP Charm deployment on xenial-mitaka.""" -from basic_deployment import SDNCharmDeployment +from basic_deployment import KeystoneLDAPCharmDeployment if __name__ == '__main__': - deployment = SDNCharmDeployment(series='xenial') + deployment = KeystoneLDAPCharmDeployment(series='xenial') deployment.run_tests() diff --git a/src/tox.ini b/src/tox.ini index 9e2a4cc..479d7bb 100644 --- a/src/tox.ini +++ b/src/tox.ini @@ -1,77 +1,53 @@ +# Source charm: ./src/tox.ini +# This file is managed centrally by release-tools and should not be modified +# within individual charm repos. [tox] -# Default to current LTS -envlist = pep8,py27 +envlist = pep8 skipsdist = True [testenv] setenv = VIRTUAL_ENV={envdir} PYTHONHASHSEED=0 - CHARM_DIR={envdir} AMULET_SETUP_TIMEOUT=2700 +whitelist_externals = juju passenv = HOME TERM AMULET_* +deps = -r{toxinidir}/test-requirements.txt install_command = pip install --allow-unverified python-apt {opts} {packages} -commands = ostestr {posargs} - -[testenv:py27] -basepython = python2.7 -deps = -r{toxinidir}/requirements.txt - -r{toxinidir}/test-requirements.txt [testenv:pep8] basepython = python2.7 -deps = -r{toxinidir}/requirements.txt - -r{toxinidir}/test-requirements.txt -commands = flake8 {posargs} hooks unit_tests tests - charm-proof - -[testenv:venv] -commands = {posargs} +commands = charm-proof [testenv:func27-noop] # DRY RUN - For Debug basepython = python2.7 -deps = -r{toxinidir}/requirements.txt - -r{toxinidir}/test-requirements.txt commands = bundletester -vl DEBUG -r json -o func-results.json --test-pattern "gate-*" -n --no-destroy [testenv:func27] -# Charm Functional Test # Run all gate tests which are +x (expected to always pass) basepython = python2.7 -deps = -r{toxinidir}/requirements.txt - -r{toxinidir}/test-requirements.txt commands = bundletester -vl DEBUG -r json -o func-results.json --test-pattern "gate-*" --no-destroy [testenv:func27-smoke] -# Charm Functional Test # Run a specific test as an Amulet smoke test (expected to always pass) basepython = python2.7 -deps = -r{toxinidir}/requirements.txt - -r{toxinidir}/test-requirements.txt commands = bundletester -vl DEBUG -r json -o func-results.json gate-basic-xenial-mitaka --no-destroy [testenv:func27-dfs] -# Charm Functional Test # Run all deploy-from-source tests which are +x (may not always pass!) basepython = python2.7 -deps = -r{toxinidir}/requirements.txt - -r{toxinidir}/test-requirements.txt commands = bundletester -vl DEBUG -r json -o func-results.json --test-pattern "dfs-*" --no-destroy [testenv:func27-dev] -# Charm Functional Test # Run all development test targets which are +x (may not always pass!) basepython = python2.7 -deps = -r{toxinidir}/requirements.txt - -r{toxinidir}/test-requirements.txt commands = bundletester -vl DEBUG -r json -o func-results.json --test-pattern "dev-*" --no-destroy -[flake8] -ignore = E402,E226 -exclude = hooks/charmhelpers +[testenv:venv] +commands = {posargs} diff --git a/tox.ini b/tox.ini index df765e0..3ba2b23 100644 --- a/tox.ini +++ b/tox.ini @@ -1,3 +1,6 @@ +# Source charm: ./tox.ini +# This file is managed centrally by release-tools and should not be modified +# within individual charm repos. [tox] skipsdist = True envlist = pep8,py34,py35 @@ -7,7 +10,6 @@ skip_missing_interpreters = True setenv = VIRTUAL_ENV={envdir} PYTHONHASHSEED=0 TERM=linux - INTERFACE_PATH={toxinidir}/interfaces LAYER_PATH={toxinidir}/layers INTERFACE_PATH={toxinidir}/interfaces JUJU_REPOSITORY={toxinidir}/build @@ -22,6 +24,14 @@ basepython = python2.7 commands = charm-build --log-level DEBUG -o {toxinidir}/build src {posargs} +[testenv:py27] +basepython = python2.7 +# Reactive source charms are Python3-only, but a py27 unit test target +# is required by OpenStack Governance. Remove this shim as soon as +# permitted. http://governance.openstack.org/reference/cti/python_cti.html +whitelist_externals = true +commands = true + [testenv:py34] basepython = python3.4 deps = -r{toxinidir}/test-requirements.txt @@ -33,7 +43,7 @@ deps = -r{toxinidir}/test-requirements.txt commands = ostestr {posargs} [testenv:pep8] -basepython = python2.7 +basepython = python3.5 deps = -r{toxinidir}/test-requirements.txt commands = flake8 {posargs} src unit_tests