From f42bcd77f2407bd60b9d4f7c4e1ea0a2f7ad7388 Mon Sep 17 00:00:00 2001 From: Artem Date: Fri, 22 Jul 2016 17:00:39 +0300 Subject: [PATCH] Add functional tests for Redis plugin Change-Id: I4fa49a2fb8f56c2cf8ffb20c443bf75cab3849f0 --- stacklight_tests/ceilometer_redis/api.py | 34 +++++++++++ .../ceilometer_redis/test_functional.py | 61 ++++++++++++------- stacklight_tests/helpers/helpers.py | 12 ++++ 3 files changed, 84 insertions(+), 23 deletions(-) diff --git a/stacklight_tests/ceilometer_redis/api.py b/stacklight_tests/ceilometer_redis/api.py index f309427..f9248a3 100644 --- a/stacklight_tests/ceilometer_redis/api.py +++ b/stacklight_tests/ceilometer_redis/api.py @@ -12,7 +12,12 @@ # License for the specific language governing permissions and limitations # under the License. +import datetime +import time + import ceilometerclient.v2.client +from proboscis import asserts +from six.moves import configparser from stacklight_tests import base_test from stacklight_tests.ceilometer_redis import plugin_settings @@ -93,3 +98,32 @@ class CeilometerRedisPluginApi(base_test.PluginApi): def check_uninstall_failure(self): return self.helpers.check_plugin_cannot_be_uninstalled( self.settings.name, self.settings.version) + + def disable_coordination(self): + ceilometer_conf = '/etc/ceilometer/ceilometer.conf' + controllers = self.fuel_web.get_nailgun_cluster_nodes_by_roles( + self.helpers.cluster_id, ['controller']) + for controller in controllers: + with self.fuel_web.get_ssh_for_nailgun_node(controller) as remote: + with remote.open(ceilometer_conf) as f: + parser = configparser.RawConfigParser() + parser.readfp(f) + parser.remove_option('coordination', 'backend_url') + with remote.open(ceilometer_conf, 'w') as f: + parser.write(f) + with self.fuel_web.get_ssh_for_nailgun_node(controllers[0]) as remote: + self.remote_ops.manage_pacemaker_service( + remote, 'p_ceilometer-agent-central', operation='restart') + + def check_sample_count(self, expected_count): + image = self.helpers.create_image() + time.sleep(2 * self.settings.polling_interval) + f = datetime.datetime.now() - datetime.timedelta(seconds=600) + query = [{'field': 'timestamp', 'op': 'ge', 'value': f.isoformat()}, + {'field': 'resource_id', 'op': 'eq', 'value': image.id}] + actual_count = self.ceilometer.statistics.list( + q=query, meter_name='image')[0].count + msg = ("Expected {0} image sample for one " + "polling period , got : {1} .").format(expected_count, + actual_count) + asserts.assert_true(expected_count == actual_count, msg) diff --git a/stacklight_tests/ceilometer_redis/test_functional.py b/stacklight_tests/ceilometer_redis/test_functional.py index e1cc721..5a96471 100644 --- a/stacklight_tests/ceilometer_redis/test_functional.py +++ b/stacklight_tests/ceilometer_redis/test_functional.py @@ -12,10 +12,6 @@ # License for the specific language governing permissions and limitations # under the License. -import datetime -import tempfile -import time - from proboscis import asserts from proboscis import test @@ -35,7 +31,7 @@ class TestFunctionalCeilometerRedisPlugin(api.CeilometerRedisPluginApi): """Verify that all measurements are collected after stopping one of central agents. """ - + self.env.revert_snapshot("deploy_ceilometer_redis") controller = self.fuel_web.get_nailgun_cluster_nodes_by_roles( self.helpers.cluster_id, ['controller'])[0] with self.fuel_web.get_ssh_for_nailgun_node(controller) as remote: @@ -55,7 +51,7 @@ class TestFunctionalCeilometerRedisPlugin(api.CeilometerRedisPluginApi): """Check 'Joined partitioning group agent-central' in the aodh-evaluator logs. """ - + self.env.revert_snapshot("deploy_ceilometer_redis") controllers = self.fuel_web.get_nailgun_cluster_nodes_by_roles( self.helpers.cluster_id, ['controller']) for controller in controllers: @@ -76,7 +72,7 @@ class TestFunctionalCeilometerRedisPlugin(api.CeilometerRedisPluginApi): """Check 'Joined partitioning group alarm_evaluator' in the ceilometer-polling logs. """ - + self.env.revert_snapshot("deploy_ceilometer_redis") controllers = self.fuel_web.get_nailgun_cluster_nodes_by_roles( self.helpers.cluster_id, ['controller']) for controller in controllers: @@ -95,20 +91,39 @@ class TestFunctionalCeilometerRedisPlugin(api.CeilometerRedisPluginApi): def check_samples_ceilometer_redis(self): """Check that for one polling interval only one 'image' sample exists. """ + self.env.revert_snapshot("deploy_ceilometer_redis") + self.check_sample_count(expected_count=1) - with tempfile.TemporaryFile() as fp: - fp.write('Test') - fp.seek(0) - image = self.helpers.os_conn.create_image(name='Redis', - container_format='bare', - disk_format='qcow2', - data=fp) - time.sleep(2 * self.settings.polling_interval) - f = datetime.datetime.now() - datetime.timedelta(seconds=600) - query = [{'field': 'timestamp', 'op': 'ge', 'value': f.isoformat()}, - {'field': 'resource_id', 'op': 'eq', 'value': image.id}] - sample_count = self.ceilometer.statistics.list( - q=query, meter_name='image')[0].count - msg = ("Expected 1 image sample for one " - "polling period , got : {0} .").format(sample_count) - asserts.assert_true(sample_count == 1, msg) + @test(depends_on_groups=["deploy_ceilometer_redis"], + groups=["check_samples_with_one_agent_ceilometer_redis", + "ceilometer_redis", + "functional"]) + @log_snapshot_after_test + def check_samples_with_one_agent_ceilometer_redis(self): + """Check samples after ban two of three ceilometer-agent-central. + """ + self.env.revert_snapshot("deploy_ceilometer_redis") + controllers = self.fuel_web.get_nailgun_cluster_nodes_by_roles( + self.helpers.cluster_id, ['controller']) + for controller in controllers[:2]: + with self.fuel_web.get_ssh_for_nailgun_node(controller) as remote: + remote.execute('pcs resource ban p_ceilometer-agent-central ' + '$(hostname) --wait=100') + result = remote.execute(' ps aux | grep -v grep | grep' + ' -c ceilometer-polling')['stdout'][0] + msg = "Agent central wasn't stopped" + asserts.assert_true(int(result) == 0, msg) + self.check_sample_count(expected_count=1) + + @test(depends_on_groups=["deploy_ceilometer_redis"], + groups=["check_central_disabled_coordination_ceilometer_redis", + "ceilometer_redis", + "functional"]) + @log_snapshot_after_test + def check_central_disabled_coordination_ceilometer_redis(self): + """Check that after disable coordination we have 3 + image sample for the one polling period. + """ + self.env.revert_snapshot("deploy_ceilometer_redis") + self.disable_coordination() + self.check_sample_count(expected_count=3) diff --git a/stacklight_tests/helpers/helpers.py b/stacklight_tests/helpers/helpers.py index 5bb2a20..b71f83b 100644 --- a/stacklight_tests/helpers/helpers.py +++ b/stacklight_tests/helpers/helpers.py @@ -14,6 +14,7 @@ import os import re +import tempfile import time import urllib2 @@ -652,3 +653,14 @@ class PluginHelper(object): nac_subdict[option]['value'] = value self.nailgun_client.update_cluster_attributes( self.cluster_id, attributes) + + def create_image(self): + + with tempfile.TemporaryFile() as fp: + fp.write('Test') + fp.seek(0) + image = self.os_conn.create_image(name='Redis', + container_format='bare', + disk_format='qcow2', + data=fp) + return image