From 707b36c0f805ea50daebfa56aff8c929c6f1aa62 Mon Sep 17 00:00:00 2001 From: Aurelien Lourot Date: Tue, 3 Mar 2020 14:06:59 +0100 Subject: [PATCH] Add a ceilometer test case and fix existing ones for trusty/mitaka https://bugs.launchpad.net/charm-ceilometer/+bug/1828424 --- setup.py | 1 + .../openstack/charm_tests/ceilometer/tests.py | 44 ++++++++++++++----- zaza/openstack/charm_tests/test_utils.py | 4 +- 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/setup.py b/setup.py index d212ae8..6873ef9 100644 --- a/setup.py +++ b/setup.py @@ -44,6 +44,7 @@ install_require = [ 'python-novaclient', 'python-neutronclient', 'python-octaviaclient', + 'python-ceilometerclient', 'python-cinderclient', 'python-swiftclient', 'zaza@git+https://github.com/openstack-charmers/zaza.git#egg=zaza', diff --git a/zaza/openstack/charm_tests/ceilometer/tests.py b/zaza/openstack/charm_tests/ceilometer/tests.py index 2741191..5701cfb 100644 --- a/zaza/openstack/charm_tests/ceilometer/tests.py +++ b/zaza/openstack/charm_tests/ceilometer/tests.py @@ -19,8 +19,9 @@ import copy import logging -import zaza.openstack.utilities.openstack as openstack_utils +import ceilometerclient.v2.client as ceilo_client import zaza.openstack.charm_tests.test_utils as test_utils +import zaza.openstack.utilities.openstack as openstack_utils class CeilometerTest(test_utils.OpenStackBaseTest): @@ -39,11 +40,11 @@ class CeilometerTest(test_utils.OpenStackBaseTest): def setUpClass(cls): """Run class setup for running Ceilometer tests.""" super(CeilometerTest, cls).setUpClass() + cls.current_release = openstack_utils.get_os_release() @property def services(self): - """Return a list services for Openstack Release.""" - self.current_release = openstack_utils.get_os_release() + """Return a list of services for Openstack Release.""" services = [] if self.application_name == 'ceilometer-agent': @@ -89,20 +90,43 @@ class CeilometerTest(test_utils.OpenStackBaseTest): return services - # NOTE(beisner): need to add more functional tests - - def test_900_restart_on_config_change(self): - """Checking restart happens on config change.""" - _services = copy.deepcopy(self.services) + @property + def restartable_services(self): + """Return a list of services that are known to be restartable. + For Openstack Release these services are known to be able to be stopped + and started with no issues. + """ # Due to Bug #1861321 ceilometer-collector does not reliably # restart. + _services = copy.deepcopy(self.services) if self.current_release <= CeilometerTest.TRUSTY_MITAKA: try: _services.remove('ceilometer-collector') except ValueError: pass + return _services + def test_400_api_connection(self): + """Simple api calls to check service is up and responding.""" + if self.current_release >= CeilometerTest.XENIAL_PIKE: + logging.info('Skipping API checks as ceilometer api has been ' + 'removed') + return + + logging.info('Instantiating ceilometer client...') + ceil = ceilo_client.Client( + session=openstack_utils.get_overcloud_keystone_session() + ) + + logging.info('Checking api functionality...') + assert(ceil.samples.list() == []) + assert(ceil.meters.list() == []) + + # NOTE(beisner): need to add more functional tests + + def test_900_restart_on_config_change(self): + """Checking restart happens on config change.""" config_name = 'debug' if self.application_name == 'ceilometer-agent': @@ -138,7 +162,7 @@ class CeilometerTest(test_utils.OpenStackBaseTest): set_alternate, default_entry, alternate_entry, - _services) + self.restartable_services) def test_901_pause_resume(self): """Run pause and resume tests. @@ -146,5 +170,5 @@ class CeilometerTest(test_utils.OpenStackBaseTest): Pause service and check services are stopped then resume and check they are started. """ - with self.pause_resume(self.services): + with self.pause_resume(self.restartable_services): logging.info("Testing pause and resume") diff --git a/zaza/openstack/charm_tests/test_utils.py b/zaza/openstack/charm_tests/test_utils.py index 5903119..e33bd69 100644 --- a/zaza/openstack/charm_tests/test_utils.py +++ b/zaza/openstack/charm_tests/test_utils.py @@ -335,8 +335,8 @@ class OpenStackBaseTest(unittest.TestCase): Pause and then resume a unit checking that services are in the required state after each action - :param services: Services expected to be restarted when config_file is - changed. + :param services: Services expected to be restarted when the unit is + paused/resumed. :type services: list :param pgrep_full: Should pgrep be used rather than pidof to identify a service.