From 36fa3966bc8210c31500485e599611b328fa5808 Mon Sep 17 00:00:00 2001 From: Eyal Date: Thu, 28 Feb 2019 13:44:42 +0200 Subject: [PATCH] use the right graph compare also fix some logging issues Change-Id: I6b857347879ced1054f8cdb75f10a287b219ccb0 --- vitrage_tempest_plugin/tests/api/rca/base.py | 8 ++-- .../tests/api/templates/base.py | 7 +--- .../tests/api/topology/base.py | 29 ------------- .../tests/api/topology/test_topology.py | 6 +-- vitrage_tempest_plugin/tests/base.py | 35 ++++++++++++++++ .../test_3rd_degree_scenarios.py | 41 ++----------------- vitrage_tempest_plugin/tests/utils.py | 4 +- 7 files changed, 48 insertions(+), 82 deletions(-) diff --git a/vitrage_tempest_plugin/tests/api/rca/base.py b/vitrage_tempest_plugin/tests/api/rca/base.py index cf057ed..bf25dd2 100644 --- a/vitrage_tempest_plugin/tests/api/rca/base.py +++ b/vitrage_tempest_plugin/tests/api/rca/base.py @@ -67,8 +67,8 @@ class BaseRcaTest(BaseVitrageTempest): 'The rca taken from api is empty') self.assertIsNotNone(cli_rca, 'The rca taken from cli is empty') - LOG.info("The rca taken from cli is : " + str(cli_rca)) - LOG.info("The rca taken by api is : " + str(json.dumps(api_rca))) + LOG.debug("The rca taken from cli is : %s", cli_rca) + LOG.debug("The rca taken by api is : %s", api_rca) parsed_rca = json.loads(cli_rca) sorted_cli_graph = self._clean_timestamps(sorted(parsed_rca.items())) @@ -77,7 +77,7 @@ class BaseRcaTest(BaseVitrageTempest): def _validate_rca(self, rca): self.assertThat(rca, IsNotEmpty, 'The rca is empty') - LOG.info("The rca alarms list is : " + str(json.dumps(rca))) + LOG.debug("The rca alarms list is : %s", rca) resource_alarm = g_utils.all_matches( rca, @@ -97,7 +97,7 @@ class BaseRcaTest(BaseVitrageTempest): def _validate_deduce_alarms(self, alarms, instances): """Validate alarm existence """ self.assertThat(alarms, IsNotEmpty(), 'The alarms list is empty') - LOG.info("The alarms list is : " + str(json.dumps(alarms))) + LOG.debug("The alarms list is : %s", alarms) # Find the vitrage_id of the deduced alarms using their original id. vitrage_resources = self.vitrage_client.resource.list( diff --git a/vitrage_tempest_plugin/tests/api/templates/base.py b/vitrage_tempest_plugin/tests/api/templates/base.py index d1afb28..e58bff0 100644 --- a/vitrage_tempest_plugin/tests/api/templates/base.py +++ b/vitrage_tempest_plugin/tests/api/templates/base.py @@ -11,7 +11,6 @@ # 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 json from oslo_log import log as logging from testtools import matchers @@ -54,10 +53,8 @@ class BaseTemplateTest(BaseVitrageTempest): self.assertIsNotNone(cli_templates, 'The template list taken from cli is empty') - LOG.info("The template list taken from cli is : " + - str(cli_templates)) - LOG.info("The template list taken by api is : " + - str(json.dumps(api_templates))) + LOG.debug("The template list taken from cli is : %s", cli_templates) + LOG.debug("The template list taken by api is : %s", api_templates) self._validate_templates_list_length(api_templates, cli_templates) self._validate_passed_templates_length(api_templates, cli_templates) diff --git a/vitrage_tempest_plugin/tests/api/topology/base.py b/vitrage_tempest_plugin/tests/api/topology/base.py index 01f7c21..bfbdc3e 100644 --- a/vitrage_tempest_plugin/tests/api/topology/base.py +++ b/vitrage_tempest_plugin/tests/api/topology/base.py @@ -12,7 +12,6 @@ # License for the specific language governing permissions and limitations # under the License. -import json import time @@ -20,8 +19,6 @@ from vitrage_tempest_plugin.tests.base import BaseVitrageTempest from vitrage_tempest_plugin.tests.base import IsNotEmpty from vitrage_tempest_plugin.tests.base import LOG from vitrage_tempest_plugin.tests.common import cinder_utils -from vitrage_tempest_plugin.tests.common.constants import VertexProperties as \ - VProps from vitrage_tempest_plugin.tests.common import nova_utils @@ -73,32 +70,6 @@ class BaseTopologyTest(BaseVitrageTempest): # entity graph processor time.sleep(2) - def _compare_graphs(self, api_graph, cli_graph): - """Compare Graph object to graph form terminal """ - self.assertThat(api_graph, IsNotEmpty(), - 'The topology graph taken from rest api is empty') - self.assertThat(cli_graph, IsNotEmpty(), - 'The topology graph taken from terminal is empty') - - parsed_topology = json.loads(cli_graph) - - sorted_cli_graph = sorted(parsed_topology.items()) - sorted_api_graph = sorted(api_graph.items()) - - for item in sorted_cli_graph[4][1]: - item.pop(VProps.UPDATE_TIMESTAMP, None) - - for item in sorted_api_graph[4][1]: - item.pop(VProps.UPDATE_TIMESTAMP, None) - - for item in sorted_cli_graph[4][1]: - item.pop(VProps.VITRAGE_SAMPLE_TIMESTAMP, None) - - for item in sorted_api_graph[4][1]: - item.pop(VProps.VITRAGE_SAMPLE_TIMESTAMP, None) - - self.assert_list_equal(sorted_cli_graph, sorted_api_graph) - @staticmethod def _graph_query(): return '{"and": [{"==": {"vitrage_category": "RESOURCE"}},' \ diff --git a/vitrage_tempest_plugin/tests/api/topology/test_topology.py b/vitrage_tempest_plugin/tests/api/topology/test_topology.py index 91a0fdf..6a7f15b 100644 --- a/vitrage_tempest_plugin/tests/api/topology/test_topology.py +++ b/vitrage_tempest_plugin/tests/api/topology/test_topology.py @@ -11,6 +11,7 @@ # 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 json from oslo_log import log as logging from testtools import ExpectedException @@ -51,10 +52,7 @@ class TestTopology(BaseTopologyTest): cli_graph = utils.run_vitrage_command( 'vitrage topology show --all-tenants') - LOG.info('api-graph=%(api)s cli-graph=%(cli)s', {'api': api_graph, - 'cli': cli_graph}) - - self._compare_graphs(api_graph, cli_graph) + self._assert_graph_equal(api_graph, json.loads(cli_graph)) @utils.tempest_logger def test_default_graph_all_tenants(self): diff --git a/vitrage_tempest_plugin/tests/base.py b/vitrage_tempest_plugin/tests/base.py index d3bced2..4597000 100644 --- a/vitrage_tempest_plugin/tests/base.py +++ b/vitrage_tempest_plugin/tests/base.py @@ -169,6 +169,41 @@ class BaseVitrageTempest(test.BaseTestCase): return graph + def _assert_graph_equal(self, g1, g2, msg=''): + """Checks that two graphs are equals. + + This relies on assert_dict_equal when comparing the nodes and the + edges of each graph. + """ + g1_nodes = g1['nodes'] + g1_links = g1['links'] + + g2_nodes = g2['nodes'] + g2_links = g1['links'] + + to_remove = {'vitrage_sample_timestamp', + 'update_timestamp', + 'graph_index'} + + self._remove_keys_from_dicts(g1_nodes, g2_nodes, to_remove) + + self.assert_items_equal(g1_nodes, g2_nodes, + msg + "Nodes of each graph are not equal") + self.assert_items_equal(g1_links, g2_links, + msg + "Edges of each graph are not equal") + + def _remove_keys_from_dicts(self, dictionaries1, + dictionaries2, keys_to_remove): + self._delete_keys_from_dict(dictionaries1, keys_to_remove) + self._delete_keys_from_dict(dictionaries2, keys_to_remove) + + @staticmethod + def _delete_keys_from_dict(dictionaries, keys_to_remove): + for dictionary in dictionaries: + for key in keys_to_remove: + if key in dictionary: + del dictionary[key] + def _create_graph_from_tree_dictionary(self, api_graph, graph=None, diff --git a/vitrage_tempest_plugin/tests/resources/mock_datasource/test_3rd_degree_scenarios.py b/vitrage_tempest_plugin/tests/resources/mock_datasource/test_3rd_degree_scenarios.py index f214986..ab869b0 100644 --- a/vitrage_tempest_plugin/tests/resources/mock_datasource/test_3rd_degree_scenarios.py +++ b/vitrage_tempest_plugin/tests/resources/mock_datasource/test_3rd_degree_scenarios.py @@ -110,8 +110,8 @@ class TestLongProcessing(TestActionsBase): for i in range(5): self._check_template_instance_3rd_degree_scenarios() topo2 = self.vitrage_client.topology.get(all_tenants=True) - self.assert_graph_equal( - topo1, topo2, 'comparing graph items iteration ' + str(i)) + self._assert_graph_equal( + topo1, topo2, 'comparing graph items iteration %s' % i) time.sleep(CONF.root_cause_analysis_service.snapshots_interval) v_utils.delete_template(name=TEMPLATE_NAME) @@ -165,41 +165,6 @@ class TestLongProcessing(TestActionsBase): alarm_count['CRITICAL'], 'found CRITICAL deduced alarms after template delete') - def assert_graph_equal(self, g1, g2, msg): - """Checks that two graphs are equals. - - This relies on assert_dict_equal when comparing the nodes and the - edges of each graph. - """ - g1_nodes = g1['nodes'] - g1_links = g1['links'] - - g2_nodes = g2['nodes'] - g2_links = g1['links'] - - to_remove = {'vitrage_sample_timestamp', - 'update_timestamp', - 'graph_index'} - - self._remove_keys_from_dicts(g1_nodes, g2_nodes, to_remove) - - self.assert_items_equal(g1_nodes, g2_nodes, - msg + "Nodes of each graph are not equal") - self.assert_items_equal(g1_links, g2_links, - "Edges of each graph are not equal") - - def _remove_keys_from_dicts(self, dictionaries1, - dictionaries2, keys_to_remove): - self._delete_keys_from_dict(dictionaries1, keys_to_remove) - self._delete_keys_from_dict(dictionaries2, keys_to_remove) - - @staticmethod - def _delete_keys_from_dict(dictionaries, keys_to_remove): - for dictionary in dictionaries: - for key in keys_to_remove: - if key in dictionary: - del dictionary[key] - def _async_doctor_events(self, spacing=1): def do_create(): @@ -226,7 +191,7 @@ class TestLongProcessing(TestActionsBase): try: v_utils.generate_fake_host_alarm( 'nova.host-0-nova.zone-0-openstack.cluster-0', - 'test_high_availability_events' + str(i), + 'test_high_availability_events %s' % i, enabled=False) except Exception: continue diff --git a/vitrage_tempest_plugin/tests/utils.py b/vitrage_tempest_plugin/tests/utils.py index 08c21bc..069856e 100644 --- a/vitrage_tempest_plugin/tests/utils.py +++ b/vitrage_tempest_plugin/tests/utils.py @@ -61,7 +61,7 @@ def run_vitrage_command(command): user_domain_id_param, project_domain_id_par) - LOG.info('Full command: %s', full_command) + LOG.debug('Full command: %s', full_command) child = subprocess.Popen(full_command, shell=True, @@ -76,7 +76,7 @@ def run_vitrage_command(command): output = stdout.decode('utf-8') - LOG.info('cli stdout: %s', output) + LOG.debug('cli stdout: %s', output) if child.returncode: LOG.error('process return code is not 0 : return code = %d',