From 544533c50fae7fdf9cf872d750ba876e57cbae9c Mon Sep 17 00:00:00 2001 From: Alexey Weyl Date: Tue, 24 Jan 2017 17:13:54 +0000 Subject: [PATCH] more tempests changes Change-Id: Iae320b09f8002574bf5f833d40aa37916199778f --- .../tests/api/alarms/test_alarms.py | 12 +++--- vitrage_tempest_tests/tests/api/base.py | 2 +- .../tests/api/datasources/test_aodh.py | 10 ++++- .../api/datasources/test_cinder_volume.py | 6 ++- .../tests/api/datasources/test_heat_stack.py | 5 ++- .../tests/api/datasources/test_neutron.py | 6 ++- .../tests/api/datasources/test_nova.py | 6 ++- .../api/datasources/test_static_physical.py | 5 ++- vitrage_tempest_tests/tests/api/rca/base.py | 8 ++-- .../tests/api/rca/test_rca.py | 21 ++++++--- .../tests/api/templates/base.py | 24 +++++------ .../tests/api/templates/test_template.py | 4 +- .../tests/api/topology/test_topology.py | 43 ++++++++++++++----- vitrage_tempest_tests/tests/utils.py | 12 ++++++ 14 files changed, 118 insertions(+), 46 deletions(-) diff --git a/vitrage_tempest_tests/tests/api/alarms/test_alarms.py b/vitrage_tempest_tests/tests/api/alarms/test_alarms.py index 7e18849be..5b96b49e3 100644 --- a/vitrage_tempest_tests/tests/api/alarms/test_alarms.py +++ b/vitrage_tempest_tests/tests/api/alarms/test_alarms.py @@ -32,6 +32,7 @@ class TestAlarms(BaseAlarmsTest): def setUpClass(cls): super(TestAlarms, cls).setUpClass() + @utils.tempest_logger def test_compare_cli_vs_api_alarms(self): """Wrapper that returns a test graph.""" try: @@ -47,7 +48,8 @@ class TestAlarms(BaseAlarmsTest): self._compare_alarms_lists( api_alarms, cli_alarms, AODH_DATASOURCE, utils.uni2str(instances[0].id)) - except Exception: + except Exception as e: + LOG.exception(e) traceback.print_exc() raise finally: @@ -62,10 +64,10 @@ class TestAlarms(BaseAlarmsTest): self.assertIsNotNone(cli_alarms, 'The alarms list taken from cli is empty') - print("The alarms list taken from cli is : " + - str(cli_alarms)) - print("The alarms list taken by api is : " + - str(json.dumps(api_alarms))) + LOG.info("The alarms list taken from cli is : " + + str(cli_alarms)) + LOG.info("The alarms list taken by api is : " + + str(json.dumps(api_alarms))) cli_items = cli_alarms.splitlines() diff --git a/vitrage_tempest_tests/tests/api/base.py b/vitrage_tempest_tests/tests/api/base.py index 7b38273da..e191c11e8 100644 --- a/vitrage_tempest_tests/tests/api/base.py +++ b/vitrage_tempest_tests/tests/api/base.py @@ -240,7 +240,7 @@ class BaseApiTest(base.BaseTestCase): return True count += 1 time.sleep(2) - print("wait_for_status - False") + LOG.info("wait_for_status - False") return False def _entities_validation_data(self, **kwargs): diff --git a/vitrage_tempest_tests/tests/api/datasources/test_aodh.py b/vitrage_tempest_tests/tests/api/datasources/test_aodh.py index cdb3f114f..112459eb4 100644 --- a/vitrage_tempest_tests/tests/api/datasources/test_aodh.py +++ b/vitrage_tempest_tests/tests/api/datasources/test_aodh.py @@ -11,9 +11,11 @@ # 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 traceback from oslo_log import log as logging +from vitrage_tempest_tests.tests import utils from vitrage_tempest_tests.tests.api.alarms.base import BaseAlarmsTest @@ -28,6 +30,7 @@ class TestAodhAlarm(BaseAlarmsTest): def setUpClass(cls): super(TestAodhAlarm, cls).setUpClass() + @utils.tempest_logger def test_alarm_with_resource_id(self): try: # Action @@ -55,13 +58,15 @@ class TestAodhAlarm(BaseAlarmsTest): num_entities, num_edges, entities) - except Exception: + except Exception as e: traceback.print_exc() + LOG.exception(e) raise finally: self._delete_ceilometer_alarms() self._delete_instances() + @utils.tempest_logger def test_alarm_without_resource_id(self): try: # Action @@ -84,8 +89,9 @@ class TestAodhAlarm(BaseAlarmsTest): num_entities, num_edges, entities) - except Exception: + except Exception as e: traceback.print_exc() + LOG.exception(e) raise finally: self._delete_ceilometer_alarms() diff --git a/vitrage_tempest_tests/tests/api/datasources/test_cinder_volume.py b/vitrage_tempest_tests/tests/api/datasources/test_cinder_volume.py index 7e9e2a7d0..f4f435051 100644 --- a/vitrage_tempest_tests/tests/api/datasources/test_cinder_volume.py +++ b/vitrage_tempest_tests/tests/api/datasources/test_cinder_volume.py @@ -11,10 +11,12 @@ # 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 traceback from oslo_log import log as logging from vitrage_tempest_tests.tests.api.topology.base import BaseTopologyTest +from vitrage_tempest_tests.tests import utils LOG = logging.getLogger(__name__) @@ -27,6 +29,7 @@ class TestCinderVolume(BaseTopologyTest): def setUpClass(cls): super(TestCinderVolume, cls).setUpClass() + @utils.tempest_logger def test_volume(self): try: # Action @@ -54,8 +57,9 @@ class TestCinderVolume(BaseTopologyTest): num_entities, num_edges, entities) - except Exception: + except Exception as e: traceback.print_exc() + LOG.exception(e) raise finally: self._rollback_to_default() diff --git a/vitrage_tempest_tests/tests/api/datasources/test_heat_stack.py b/vitrage_tempest_tests/tests/api/datasources/test_heat_stack.py index 781ac7bf0..84e55a4b9 100644 --- a/vitrage_tempest_tests/tests/api/datasources/test_heat_stack.py +++ b/vitrage_tempest_tests/tests/api/datasources/test_heat_stack.py @@ -16,6 +16,7 @@ import time import traceback from oslo_log import log as logging +from vitrage_tempest_tests.tests import utils from vitrage_tempest_tests.tests.api.topology.base import BaseTopologyTest @@ -29,6 +30,7 @@ class TestHeatStack(BaseTopologyTest): def setUpClass(cls): super(TestHeatStack, cls).setUpClass() + @utils.tempest_logger def test_heat_stack(self): """heat stack test @@ -63,8 +65,9 @@ class TestHeatStack(BaseTopologyTest): num_entities, num_edges, entities) - except Exception: + except Exception as e: traceback.print_exc() + LOG.exception(e) raise finally: self._delete_stacks() diff --git a/vitrage_tempest_tests/tests/api/datasources/test_neutron.py b/vitrage_tempest_tests/tests/api/datasources/test_neutron.py index 07cff69b5..f9c9cd1cc 100644 --- a/vitrage_tempest_tests/tests/api/datasources/test_neutron.py +++ b/vitrage_tempest_tests/tests/api/datasources/test_neutron.py @@ -11,12 +11,14 @@ # 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 traceback from oslo_log import log as logging from vitrage.common.constants import VertexProperties as VProps from vitrage_tempest_tests.tests.api.topology.base import BaseTopologyTest +from vitrage_tempest_tests.tests import utils LOG = logging.getLogger(__name__) @@ -28,6 +30,7 @@ class TestNeutron(BaseTopologyTest): def setUpClass(cls): super(TestNeutron, cls).setUpClass() + @utils.tempest_logger def test_neutron(self): """neutron test @@ -62,8 +65,9 @@ class TestNeutron(BaseTopologyTest): num_entities, num_edges, entities) - except Exception: + except Exception as e: traceback.print_exc() + LOG.exception(e) raise finally: self._delete_instances() diff --git a/vitrage_tempest_tests/tests/api/datasources/test_nova.py b/vitrage_tempest_tests/tests/api/datasources/test_nova.py index c5be18be1..38a2339a4 100644 --- a/vitrage_tempest_tests/tests/api/datasources/test_nova.py +++ b/vitrage_tempest_tests/tests/api/datasources/test_nova.py @@ -11,10 +11,12 @@ # 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 traceback from oslo_log import log as logging from vitrage_tempest_tests.tests.api.topology.base import BaseTopologyTest +from vitrage_tempest_tests.tests import utils LOG = logging.getLogger(__name__) @@ -26,6 +28,7 @@ class TestNova(BaseTopologyTest): def setUpClass(cls): super(TestNova, cls).setUpClass() + @utils.tempest_logger def test_nova_entities(self): try: # Action @@ -50,8 +53,9 @@ class TestNova(BaseTopologyTest): num_entities, num_edges, entities) - except Exception: + except Exception as e: traceback.print_exc() + LOG.exception(e) raise finally: self._rollback_to_default() diff --git a/vitrage_tempest_tests/tests/api/datasources/test_static_physical.py b/vitrage_tempest_tests/tests/api/datasources/test_static_physical.py index 81028ef33..a20b4c6e9 100644 --- a/vitrage_tempest_tests/tests/api/datasources/test_static_physical.py +++ b/vitrage_tempest_tests/tests/api/datasources/test_static_physical.py @@ -19,6 +19,7 @@ import traceback from oslo_log import log as logging from vitrage_tempest_tests.tests.api.base import BaseApiTest +from vitrage_tempest_tests.tests import utils LOG = logging.getLogger(__name__) @@ -31,6 +32,7 @@ class TestStaticPhysical(BaseApiTest): def setUpClass(cls): super(TestStaticPhysical, cls).setUpClass() + @utils.tempest_logger def test_switches(self): try: # Action @@ -54,8 +56,9 @@ class TestStaticPhysical(BaseApiTest): num_entities, num_edges, entities) - except Exception: + except Exception as e: traceback.print_exc() + LOG.exception(e) raise finally: self._delete_switches() diff --git a/vitrage_tempest_tests/tests/api/rca/base.py b/vitrage_tempest_tests/tests/api/rca/base.py index bba743804..758afdd8d 100644 --- a/vitrage_tempest_tests/tests/api/rca/base.py +++ b/vitrage_tempest_tests/tests/api/rca/base.py @@ -60,8 +60,8 @@ class BaseRcaTest(BaseAlarmsTest): self.assertNotEqual(len(api_rca), 0, 'The rca taken from api is empty') self.assertIsNotNone(cli_rca, 'The rca taken from cli is empty') - print("The rca taken from cli is : " + str(cli_rca)) - print("The rca taken by api is : " + str(json.dumps(api_rca))) + LOG.info("The rca taken from cli is : " + str(cli_rca)) + LOG.info("The rca taken by api is : " + str(json.dumps(api_rca))) parsed_rca = json.loads(cli_rca) sorted_cli_graph = self._clean_timestamps(sorted(parsed_rca.items())) @@ -70,7 +70,7 @@ class BaseRcaTest(BaseAlarmsTest): def _validate_rca(self, rca): self.assertNotEqual(len(rca), 0, 'The rca is empty') - print("The rca alarms list is : " + str(json.dumps(rca))) + LOG.info("The rca alarms list is : " + str(json.dumps(rca))) resource_alarm = self._filter_list_by_pairs_parameters( rca, [VProps.TYPE, VProps.NAME], @@ -88,7 +88,7 @@ class BaseRcaTest(BaseAlarmsTest): def _validate_deduce_alarms(self, alarms, instances): """Validate alarm existence """ self.assertNotEqual(len(alarms), 0, 'The alarms list is empty') - print("The alarms list is : " + str(json.dumps(alarms))) + LOG.info("The alarms list is : " + str(json.dumps(alarms))) deduce_alarms_1 = self._filter_list_by_pairs_parameters( alarms, diff --git a/vitrage_tempest_tests/tests/api/rca/test_rca.py b/vitrage_tempest_tests/tests/api/rca/test_rca.py index 363d9e934..279ade57b 100644 --- a/vitrage_tempest_tests/tests/api/rca/test_rca.py +++ b/vitrage_tempest_tests/tests/api/rca/test_rca.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 traceback from oslo_log import log as logging @@ -30,6 +31,7 @@ class TestRca(BaseRcaTest): def setUpClass(cls): super(TestRca, cls).setUpClass() + @utils.tempest_logger def test_compare_cil_and_api(self): """compare_cil_and_api test @@ -51,12 +53,14 @@ class TestRca(BaseRcaTest): 'vitrage rca show ' + vitrage_id, self.conf) self._compare_rca(api_rca, cli_rca) - except Exception: + except Exception as e: traceback.print_exc() + LOG.exception(e) raise finally: self._clean_all() + @utils.tempest_logger def test_validate_rca(self): """validate_rca test @@ -79,12 +83,14 @@ class TestRca(BaseRcaTest): self._validate_rca(rca=api_rca['nodes']) self._validate_relationship(links=api_rca['links'], alarms=api_rca['nodes']) - except Exception: + except Exception as e: traceback.print_exc() + LOG.exception(e) raise finally: self._clean_all() + @utils.tempest_logger def test_validate_deduce_alarms(self): """validate_deduce_alarms test @@ -101,12 +107,14 @@ class TestRca(BaseRcaTest): self._validate_deduce_alarms(alarms=api_alarms, instances=instances) - except Exception: + except Exception as e: traceback.print_exc() + LOG.exception(e) raise finally: self._clean_all() + @utils.tempest_logger def test_validate_set_state(self): """validate_set_state test @@ -124,12 +132,14 @@ class TestRca(BaseRcaTest): self._validate_set_state(topology=topology['nodes'], instances=instances) - except Exception: + except Exception as e: traceback.print_exc() + LOG.exception(e) raise finally: self._clean_all() + @utils.tempest_logger def test_validate_notifier(self): """validate_notifier test @@ -148,8 +158,9 @@ class TestRca(BaseRcaTest): self._validate_notifier(alarms=ceilometer_alarms, vitrage_alarms=vitrage_alarms) - except Exception: + except Exception as e: traceback.print_exc() + LOG.exception(e) raise finally: self._clean_all() diff --git a/vitrage_tempest_tests/tests/api/templates/base.py b/vitrage_tempest_tests/tests/api/templates/base.py index 97f4c3bf4..30c236349 100644 --- a/vitrage_tempest_tests/tests/api/templates/base.py +++ b/vitrage_tempest_tests/tests/api/templates/base.py @@ -48,10 +48,10 @@ class BaseTemplateTest(BaseApiTest): self.assertIsNotNone(cli_templates, 'The template list taken from cli is empty') - print("The template list taken from cli is : " + - str(cli_templates)) - print("The template list taken by api is : " + - str(json.dumps(api_templates))) + 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))) self._validate_templates_list_length(api_templates, cli_templates) self._validate_passed_templates_length(api_templates, cli_templates) @@ -64,10 +64,10 @@ class BaseTemplateTest(BaseApiTest): self.assertIsNotNone( cli_templates, 'The template validations taken from cli is empty') - print("The template validations taken from cli is : " + - str(cli_templates)) - print("The template validations taken by api is : " + - str(json.dumps(api_templates))) + LOG.info("The template validations taken from cli is : " + + str(cli_templates)) + LOG.info("The template validations taken by api is : " + + str(json.dumps(api_templates))) parsed_topology = json.loads(cli_templates) sorted_cli_templates = sorted(parsed_topology.items()) @@ -134,10 +134,10 @@ class BaseTemplateTest(BaseApiTest): self.assertIsNotNone( cli_templates, 'The template validations taken from cli is empty') - print("The template validations taken from cli is : " + - str(cli_templates)) - print("The template validations taken by api is : " + - str(json.dumps(api_templates))) + LOG.info("The template validations taken from cli is : " + + str(cli_templates)) + LOG.info("The template validations taken by api is : " + + str(json.dumps(api_templates))) parsed_topology = json.loads(cli_templates) sorted_cli_templates = sorted(parsed_topology.items()) diff --git a/vitrage_tempest_tests/tests/api/templates/test_template.py b/vitrage_tempest_tests/tests/api/templates/test_template.py index 286e21b80..f5a6d1456 100644 --- a/vitrage_tempest_tests/tests/api/templates/test_template.py +++ b/vitrage_tempest_tests/tests/api/templates/test_template.py @@ -94,7 +94,7 @@ class TestValidate(BaseTemplateTest): self._run_template_validation( validation['results'][0], path, negative=True) except Exception: - print('Failed to get validation of corrupted template file') + LOG.error('Failed to get validation of corrupted template file') def test_templates_validate_correct_template(self): """templates_validate test @@ -108,7 +108,7 @@ class TestValidate(BaseTemplateTest): self._run_template_validation( validation['results'][0], path) except Exception: - print('Failed to get validation of template file') + LOG.error('Failed to get validation of template file') def test_compare_template_show(self): """templates_show test diff --git a/vitrage_tempest_tests/tests/api/topology/test_topology.py b/vitrage_tempest_tests/tests/api/topology/test_topology.py index 789007a3d..48e1c6a28 100644 --- a/vitrage_tempest_tests/tests/api/topology/test_topology.py +++ b/vitrage_tempest_tests/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 traceback from oslo_log import log as logging @@ -42,6 +43,7 @@ class TestTopology(BaseTopologyTest): def setUpClass(cls): super(TestTopology, cls).setUpClass() + @utils.tempest_logger def test_compare_api_and_cli(self): """compare_api_and_cli @@ -53,6 +55,7 @@ class TestTopology(BaseTopologyTest): self.conf) self._compare_graphs(api_graph, cli_graph) + @utils.tempest_logger def test_default_graph(self): """default_graph @@ -84,12 +87,14 @@ class TestTopology(BaseTopologyTest): num_entities, num_edges, entities) - except Exception: + except Exception as e: traceback.print_exc() + LOG.exception(e) raise finally: self._rollback_to_default() + @utils.tempest_logger def test_graph_with_query(self): """graph_with_query @@ -119,12 +124,14 @@ class TestTopology(BaseTopologyTest): num_entities, num_edges, entities) - except Exception: + except Exception as e: traceback.print_exc() + LOG.exception(e) raise finally: self._rollback_to_default() + @utils.tempest_logger def test_nova_tree(self): """nova_tree @@ -152,12 +159,14 @@ class TestTopology(BaseTopologyTest): num_entities, num_edges, entities) - except Exception: + except Exception as e: traceback.print_exc() + LOG.exception(e) raise finally: self._rollback_to_default() + @utils.tempest_logger def test_tree_with_query(self): """tree_with_query @@ -180,12 +189,14 @@ class TestTopology(BaseTopologyTest): self.num_default_entities, self.num_default_edges, entities) - except Exception: + except Exception as e: traceback.print_exc() + LOG.exception(e) raise finally: self._rollback_to_default() + @utils.tempest_logger def test_tree_with_depth_exclude_instance(self): """tree_with_query @@ -208,12 +219,14 @@ class TestTopology(BaseTopologyTest): self.num_default_entities, self.num_default_edges, entities) - except Exception: + except Exception as e: traceback.print_exc() + LOG.exception(e) raise finally: self._rollback_to_default() + @utils.tempest_logger def test_tree_with_depth_include_instance(self): """tree_with_query @@ -241,13 +254,15 @@ class TestTopology(BaseTopologyTest): num_entities, num_edges, entities) - except Exception: + except Exception as e: traceback.print_exc() + LOG.exception(e) raise finally: self._rollback_to_default() @unittest.skip("testing skipping") + @utils.tempest_logger def test_graph_with_root_and_depth_exclude_instance(self): """tree_with_query @@ -272,13 +287,15 @@ class TestTopology(BaseTopologyTest): self.num_default_entities, self.num_default_edges, entities) - except Exception: + except Exception as e: traceback.print_exc() + LOG.exception(e) raise finally: self._rollback_to_default() @unittest.skip("testing skipping") + @utils.tempest_logger def test_graph_with_root_and_depth_include_instance(self): """graph_with_root_and_depth_include_instance @@ -308,12 +325,14 @@ class TestTopology(BaseTopologyTest): num_entities, num_edges, entities) - except Exception: + except Exception as e: traceback.print_exc() + LOG.exception(e) raise finally: self._rollback_to_default() + @utils.tempest_logger def test_graph_with_depth_and_no_root(self): """graph_with_depth_and_no_root @@ -339,6 +358,7 @@ class TestTopology(BaseTopologyTest): finally: self._rollback_to_default() + @utils.tempest_logger def test_graph_with_no_match_query(self): """graph_with_no_match_query @@ -361,12 +381,14 @@ class TestTopology(BaseTopologyTest): self.assertEqual( 0, len(api_graph['links']), 'num of edges') - except Exception: + except Exception as e: traceback.print_exc() + LOG.exception(e) raise finally: self._rollback_to_default() + @utils.tempest_logger def test_tree_with_no_match_query(self): """tree_with_no_match_query @@ -385,8 +407,9 @@ class TestTopology(BaseTopologyTest): # Test Assertions self.assertEqual({}, api_graph) - except Exception: + except Exception as e: traceback.print_exc() + LOG.exception(e) raise finally: self._rollback_to_default() diff --git a/vitrage_tempest_tests/tests/utils.py b/vitrage_tempest_tests/tests/utils.py index 64b738346..f27206137 100644 --- a/vitrage_tempest_tests/tests/utils.py +++ b/vitrage_tempest_tests/tests/utils.py @@ -110,3 +110,15 @@ def get_regex_result(pattern, text): def uni2str(text): return text.encode('ascii', 'ignore') + + +def tempest_logger(func): + func_name = func.func_name + + def func_name_print_func(*args, **kwargs): + LOG.info('Test Start: ' + func_name) + result = func(*args, **kwargs) + LOG.info('Test End: ' + func_name) + return result + + return func_name_print_func