diff --git a/vitrage/tests/base.py b/vitrage/tests/base.py index 32a85ffcd..637b6564f 100644 --- a/vitrage/tests/base.py +++ b/vitrage/tests/base.py @@ -11,6 +11,8 @@ # 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 logging import os from oslo_utils import timeutils @@ -102,4 +104,5 @@ class BaseTest(base.BaseTestCase): return root def setUp(self): + logging.disable(logging.CRITICAL) super(BaseTest, self).setUp() diff --git a/vitrage/tests/functional/api_handler/test_apis.py b/vitrage/tests/functional/api_handler/test_apis.py index 52bbe0e25..c2045fa8a 100755 --- a/vitrage/tests/functional/api_handler/test_apis.py +++ b/vitrage/tests/functional/api_handler/test_apis.py @@ -14,6 +14,8 @@ import json +from testtools import matchers + from vitrage.api_handler.apis.alarm import AlarmApis from vitrage.api_handler.apis.rca import RcaApis from vitrage.api_handler.apis.resource import ResourceApis @@ -30,6 +32,7 @@ from vitrage.entity_graph.mappings.operational_alarm_severity import \ OperationalAlarmSeverity from vitrage.graph.driver.networkx_graph import NXGraph import vitrage.graph.utils as graph_utils +from vitrage.tests.base import IsEmpty from vitrage.tests.unit.entity_graph.base import TestEntityGraphUnitBase @@ -46,7 +49,7 @@ class TestApis(TestEntityGraphUnitBase): alarms = json.loads(alarms)['alarms'] # Test assertions - self.assertEqual(3, len(alarms)) + self.assertThat(alarms, matchers.HasLength(3)) self._check_projects_entities(alarms, 'project_1', True) def test_get_alarms_with_not_admin_project(self): @@ -60,7 +63,7 @@ class TestApis(TestEntityGraphUnitBase): alarms = json.loads(alarms)['alarms'] # Test assertions - self.assertEqual(2, len(alarms)) + self.assertThat(alarms, matchers.HasLength(2)) self._check_projects_entities(alarms, 'project_2', True) def test_get_alarm_counts_with_not_admin_project(self): @@ -91,7 +94,7 @@ class TestApis(TestEntityGraphUnitBase): alarms = json.loads(alarms)['alarms'] # Test assertions - self.assertEqual(5, len(alarms)) + self.assertThat(alarms, matchers.HasLength(5)) self._check_projects_entities(alarms, None, True) def test_get_alarm_counts_with_all_tenants(self): @@ -122,7 +125,7 @@ class TestApis(TestEntityGraphUnitBase): graph_rca = json.loads(graph_rca) # Test assertions - self.assertEqual(3, len(graph_rca['nodes'])) + self.assertThat(graph_rca['nodes'], matchers.HasLength(3)) self._check_projects_entities(graph_rca['nodes'], 'project_1', True) def test_get_rca_with_not_admin_project(self): @@ -138,7 +141,7 @@ class TestApis(TestEntityGraphUnitBase): graph_rca = json.loads(graph_rca) # Test assertions - self.assertEqual(2, len(graph_rca['nodes'])) + self.assertThat(graph_rca['nodes'], matchers.HasLength(2)) self._check_projects_entities(graph_rca['nodes'], 'project_2', True) def test_get_rca_with_not_admin_bla_project(self): @@ -152,7 +155,7 @@ class TestApis(TestEntityGraphUnitBase): graph_rca = json.loads(graph_rca) # Test assertions - self.assertEqual(3, len(graph_rca['nodes'])) + self.assertThat(graph_rca['nodes'], matchers.HasLength(3)) self._check_projects_entities(graph_rca['nodes'], 'project_2', True) def test_get_rca_with_all_tenants(self): @@ -166,7 +169,7 @@ class TestApis(TestEntityGraphUnitBase): graph_rca = json.loads(graph_rca) # Test assertions - self.assertEqual(5, len(graph_rca['nodes'])) + self.assertThat(graph_rca['nodes'], matchers.HasLength(5)) self._check_projects_entities(graph_rca['nodes'], None, True) def test_get_topology_with_admin_project(self): @@ -186,7 +189,7 @@ class TestApis(TestEntityGraphUnitBase): graph_topology = json.loads(graph_topology) # Test assertions - self.assertEqual(8, len(graph_topology['nodes'])) + self.assertThat(graph_topology['nodes'], matchers.HasLength(8)) self._check_projects_entities(graph_topology['nodes'], 'project_1', False) @@ -208,7 +211,7 @@ class TestApis(TestEntityGraphUnitBase): graph_topology = json.loads(graph_topology) # Test assertions - self.assertEqual(7, len(graph_topology['nodes'])) + self.assertThat(graph_topology['nodes'], matchers.HasLength(7)) self._check_projects_entities(graph_topology['nodes'], 'project_2', False) @@ -230,7 +233,7 @@ class TestApis(TestEntityGraphUnitBase): graph_topology = json.loads(graph_topology) # Test assertions - self.assertEqual(12, len(graph_topology['nodes'])) + self.assertThat(graph_topology['nodes'], matchers.HasLength(12)) def test_resource_list_with_admin_project(self): # Setup @@ -246,7 +249,7 @@ class TestApis(TestEntityGraphUnitBase): resources = json.loads(resources)['resources'] # Test assertions - self.assertEqual(5, len(resources)) + self.assertThat(resources, matchers.HasLength(5)) def test_resource_list_with_not_admin_project(self): # Setup @@ -262,7 +265,7 @@ class TestApis(TestEntityGraphUnitBase): resources = json.loads(resources)['resources'] # Test assertions - self.assertEqual(2, len(resources)) + self.assertThat(resources, matchers.HasLength(2)) def test_resource_list_with_not_admin_project_and_no_existing_type(self): # Setup @@ -278,7 +281,7 @@ class TestApis(TestEntityGraphUnitBase): resources = json.loads(resources)['resources'] # Test assertions - self.assertEqual(0, len(resources)) + self.assertThat(resources, IsEmpty()) def test_resource_list_with_not_admin_project_and_existing_type(self): # Setup @@ -294,7 +297,7 @@ class TestApis(TestEntityGraphUnitBase): resources = json.loads(resources)['resources'] # Test assertions - self.assertEqual(2, len(resources)) + self.assertThat(resources, matchers.HasLength(2)) def test_resource_list_with_all_tenants(self): # Setup @@ -310,7 +313,7 @@ class TestApis(TestEntityGraphUnitBase): resources = json.loads(resources)['resources'] # Test assertions - self.assertEqual(7, len(resources)) + self.assertThat(resources, matchers.HasLength(7)) def test_resource_show_with_admin_and_no_project_resource(self): # Setup diff --git a/vitrage/tests/functional/datasources/aodh/test_aodh.py b/vitrage/tests/functional/datasources/aodh/test_aodh.py index ac829fd68..7cc5f0c23 100644 --- a/vitrage/tests/functional/datasources/aodh/test_aodh.py +++ b/vitrage/tests/functional/datasources/aodh/test_aodh.py @@ -13,6 +13,7 @@ # under the License. from oslo_config import cfg +from testtools import matchers from vitrage.common.constants import DatasourceProperties as DSProp from vitrage.common.constants import EntityCategory @@ -55,8 +56,10 @@ class TestAodhAlarms(TestDataSourcesBase): def test_aodh_alarms_validity(self): # Setup processor = self._create_processor_with_graph(self.conf) - self.assertEqual(self._num_total_expected_vertices(), - len(processor.entity_graph)) + self.assertThat(processor.entity_graph, + matchers.HasLength( + self._num_total_expected_vertices()) + ) detail = {TransformerBase.QUERY_RESULT: '', DSProp.ENTITY_TYPE: AODH_DATASOURCE} @@ -75,19 +78,21 @@ class TestAodhAlarms(TestDataSourcesBase): processor.process_event(aodh_event) # Test assertions - self.assertEqual(self._num_total_expected_vertices() + 1, - len(processor.entity_graph)) + self.assertThat(processor.entity_graph, + matchers.HasLength( + self._num_total_expected_vertices() + 1) + ) aodh_vertices = processor.entity_graph.get_vertices( vertex_attr_filter={ VProps.VITRAGE_CATEGORY: EntityCategory.ALARM, VProps.VITRAGE_TYPE: AODH_DATASOURCE }) - self.assertEqual(1, len(aodh_vertices)) + self.assertThat(aodh_vertices, matchers.HasLength(1)) aodh_neighbors = processor.entity_graph.neighbors( aodh_vertices[0].vertex_id) - self.assertEqual(1, len(aodh_neighbors)) + self.assertThat(aodh_neighbors, matchers.HasLength(1)) self.assertEqual(NOVA_HOST_DATASOURCE, aodh_neighbors[0][VProps.VITRAGE_TYPE]) diff --git a/vitrage/tests/functional/datasources/ceilometer/test_ceilometer.py b/vitrage/tests/functional/datasources/ceilometer/test_ceilometer.py index c702481b8..c05b41acb 100644 --- a/vitrage/tests/functional/datasources/ceilometer/test_ceilometer.py +++ b/vitrage/tests/functional/datasources/ceilometer/test_ceilometer.py @@ -13,6 +13,7 @@ # under the License. from oslo_config import cfg +from testtools import matchers from vitrage.common.constants import DatasourceProperties as DSProp from vitrage.common.constants import EntityCategory @@ -56,8 +57,10 @@ class TestCeilometerAlarms(TestDataSourcesBase): def test_ceilometer_alarms_validity(self): # Setup processor = self._create_processor_with_graph(self.conf) - self.assertEqual(self._num_total_expected_vertices(), - len(processor.entity_graph)) + self.assertThat(processor.entity_graph, + matchers.HasLength( + self._num_total_expected_vertices()) + ) detail = {TransformerBase.QUERY_RESULT: '', DSProp.ENTITY_TYPE: CEILOMETER_DATASOURCE} @@ -76,19 +79,21 @@ class TestCeilometerAlarms(TestDataSourcesBase): processor.process_event(aodh_event) # Test assertions - self.assertEqual(self._num_total_expected_vertices() + 1, - len(processor.entity_graph)) + self.assertThat(processor.entity_graph, + matchers.HasLength( + self._num_total_expected_vertices() + 1) + ) aodh_vertices = processor.entity_graph.get_vertices( vertex_attr_filter={ VProps.VITRAGE_CATEGORY: EntityCategory.ALARM, VProps.VITRAGE_TYPE: CEILOMETER_DATASOURCE }) - self.assertEqual(1, len(aodh_vertices)) + self.assertThat(aodh_vertices, matchers.HasLength(1)) aodh_neighbors = processor.entity_graph.neighbors( aodh_vertices[0].vertex_id) - self.assertEqual(1, len(aodh_neighbors)) + self.assertThat(aodh_neighbors, matchers.HasLength(1)) self.assertEqual(NOVA_HOST_DATASOURCE, aodh_neighbors[0][VProps.VITRAGE_TYPE]) diff --git a/vitrage/tests/functional/datasources/cinder/test_cinder_volume.py b/vitrage/tests/functional/datasources/cinder/test_cinder_volume.py index fc563e959..d8eccde4b 100644 --- a/vitrage/tests/functional/datasources/cinder/test_cinder_volume.py +++ b/vitrage/tests/functional/datasources/cinder/test_cinder_volume.py @@ -13,6 +13,7 @@ # under the License. from oslo_config import cfg +from testtools import matchers from vitrage.common.constants import EntityCategory from vitrage.common.constants import VertexProperties as VProps @@ -53,8 +54,10 @@ class TestCinderVolume(TestDataSourcesBase): def test_cinder_volume_validity(self): # Setup processor = self._create_processor_with_graph(self.conf) - self.assertEqual(self._num_total_expected_vertices(), - len(processor.entity_graph)) + self.assertThat(processor.entity_graph, + matchers.HasLength( + self._num_total_expected_vertices()) + ) spec_list = mock_driver.simple_volume_generators( volume_num=1, @@ -70,19 +73,20 @@ class TestCinderVolume(TestDataSourcesBase): processor.process_event(cinder_volume_event) # Test assertions - self.assertEqual(self._num_total_expected_vertices() + 1, - len(processor.entity_graph)) + self.assertThat(processor.entity_graph, + matchers.HasLength( + self._num_total_expected_vertices() + 1) + ) cinder_vertices = processor.entity_graph.get_vertices( vertex_attr_filter={ VProps.VITRAGE_CATEGORY: EntityCategory.RESOURCE, VProps.VITRAGE_TYPE: CINDER_VOLUME_DATASOURCE }) - self.assertEqual(1, len(cinder_vertices)) + self.assertThat(cinder_vertices, matchers.HasLength(1)) cinder_neighbors = processor.entity_graph.neighbors( cinder_vertices[0].vertex_id) - self.assertEqual(1, len(cinder_neighbors)) - + self.assertThat(cinder_neighbors, matchers.HasLength(1)) self.assertEqual(NOVA_INSTANCE_DATASOURCE, cinder_neighbors[0][VProps.VITRAGE_TYPE]) diff --git a/vitrage/tests/functional/datasources/collectd/test_collectd.py b/vitrage/tests/functional/datasources/collectd/test_collectd.py index b2ee72ee7..7f57e9ea6 100644 --- a/vitrage/tests/functional/datasources/collectd/test_collectd.py +++ b/vitrage/tests/functional/datasources/collectd/test_collectd.py @@ -14,6 +14,7 @@ import time from oslo_config import cfg +from testtools import matchers from vitrage.common.constants import DatasourceProperties as DSProps from vitrage.common.constants import EntityCategory @@ -63,8 +64,10 @@ class TestCollectd(TestDataSourcesBase): def _test_collectd_alarm(self, resource_type, resource_name, host_name): # Setup processor = self._create_processor_with_graph(self.conf) - self.assertEqual(self._num_total_expected_vertices(), - len(processor.entity_graph)) + self.assertThat(processor.entity_graph, + matchers.HasLength( + self._num_total_expected_vertices()) + ) time1 = time.time() severity1 = 'WARNING' @@ -80,8 +83,10 @@ class TestCollectd(TestDataSourcesBase): processor.process_event(collectd_event) # Test assertions - self.assertEqual(self._num_total_expected_vertices() + 1, - len(processor.entity_graph)) + self.assertThat(processor.entity_graph, + matchers.HasLength( + self._num_total_expected_vertices() + 1) + ) collectd_vertices = processor.entity_graph.get_vertices( vertex_attr_filter={ @@ -89,7 +94,7 @@ class TestCollectd(TestDataSourcesBase): VProps.VITRAGE_TYPE: COLLECTD_DATASOURCE }) - self.assertEqual(1, len(collectd_vertices)) + self.assertThat(collectd_vertices, matchers.HasLength(1)) collectd_vertex1 = collectd_vertices[0] self._assert_collectd_vertex_equals(collectd_vertex1, time1, @@ -117,8 +122,10 @@ class TestCollectd(TestDataSourcesBase): processor.process_event(collectd_event) # Test assertions - the collectd alarm vertex should be the same - self.assertEqual(self._num_total_expected_vertices() + 1, - len(processor.entity_graph)) + self.assertThat(processor.entity_graph, + matchers.HasLength( + self._num_total_expected_vertices() + 1) + ) collectd_vertices = processor.entity_graph.get_vertices( vertex_attr_filter={ @@ -126,7 +133,7 @@ class TestCollectd(TestDataSourcesBase): VProps.VITRAGE_TYPE: COLLECTD_DATASOURCE }) - self.assertEqual(1, len(collectd_vertices)) + self.assertThat(collectd_vertices, matchers.HasLength(1)) collectd_vertex2 = collectd_vertices[0] self.assertEqual(collectd_vertex1[VProps.VITRAGE_ID], collectd_vertex2[VProps.VITRAGE_ID]) @@ -193,7 +200,7 @@ class TestCollectd(TestDataSourcesBase): collectd_neighbors, expected_resource_type, expected_resource_name): - self.assertEqual(1, len(collectd_neighbors)) + self.assertThat(collectd_neighbors, matchers.HasLength(1)) self.assertEqual(expected_resource_type, collectd_neighbors[0][VProps.VITRAGE_TYPE]) diff --git a/vitrage/tests/functional/datasources/heat/test_heat_stack.py b/vitrage/tests/functional/datasources/heat/test_heat_stack.py index 0916611ff..952276f6a 100644 --- a/vitrage/tests/functional/datasources/heat/test_heat_stack.py +++ b/vitrage/tests/functional/datasources/heat/test_heat_stack.py @@ -13,6 +13,7 @@ # under the License. from oslo_config import cfg +from testtools import matchers from vitrage.common.constants import EntityCategory from vitrage.common.constants import VertexProperties as VProps @@ -53,8 +54,10 @@ class TestHeatStack(TestDataSourcesBase): def test_heat_stack_validity(self): # Setup processor = self._create_processor_with_graph(self.conf) - self.assertEqual(self._num_total_expected_vertices(), - len(processor.entity_graph)) + self.assertThat(processor.entity_graph, + matchers.HasLength( + self._num_total_expected_vertices()) + ) spec_list = mock_driver.simple_stack_generators( stack_num=1, @@ -67,30 +70,33 @@ class TestHeatStack(TestDataSourcesBase): processor.process_event(heat_stack_event) # Test assertions - self.assertEqual(self._num_total_expected_vertices() + 3, - len(processor.entity_graph)) + self.assertThat(processor.entity_graph, + matchers.HasLength( + self._num_total_expected_vertices() + 3) + ) stack_vertices = processor.entity_graph.get_vertices( vertex_attr_filter={ VProps.VITRAGE_CATEGORY: EntityCategory.RESOURCE, VProps.VITRAGE_TYPE: HEAT_STACK_DATASOURCE }) - self.assertEqual(1, len(stack_vertices)) + self.assertThat(stack_vertices, matchers.HasLength(1)) instance_vertices = processor.entity_graph.get_vertices( vertex_attr_filter={ VProps.VITRAGE_CATEGORY: EntityCategory.RESOURCE, VProps.VITRAGE_TYPE: NOVA_INSTANCE_DATASOURCE }) - self.assertEqual(self.NUM_INSTANCES + 1, len(instance_vertices)) + self.assertThat(instance_vertices, + matchers.HasLength(self.NUM_INSTANCES + 1)) cinder_vertices = processor.entity_graph.get_vertices( vertex_attr_filter={ VProps.VITRAGE_CATEGORY: EntityCategory.RESOURCE, VProps.VITRAGE_TYPE: CINDER_VOLUME_DATASOURCE }) - self.assertEqual(1, len(cinder_vertices)) + self.assertThat(cinder_vertices, matchers.HasLength(1)) stack_neighbors = processor.entity_graph.neighbors( stack_vertices[0].vertex_id) - self.assertEqual(2, len(stack_neighbors)) + self.assertThat(stack_neighbors, matchers.HasLength(2)) diff --git a/vitrage/tests/functional/datasources/nagios/test_nagios.py b/vitrage/tests/functional/datasources/nagios/test_nagios.py index 9cfa799a9..a3079bc63 100644 --- a/vitrage/tests/functional/datasources/nagios/test_nagios.py +++ b/vitrage/tests/functional/datasources/nagios/test_nagios.py @@ -13,6 +13,7 @@ # under the License. from oslo_config import cfg +from testtools import matchers from vitrage.common.constants import EntityCategory from vitrage.common.constants import VertexProperties as VProps @@ -53,8 +54,10 @@ class TestNagios(TestDataSourcesBase): def test_nagios_validity(self): # Setup processor = self._create_processor_with_graph(self.conf) - self.assertEqual(self._num_total_expected_vertices(), - len(processor.entity_graph)) + self.assertThat(processor.entity_graph, + matchers.HasLength( + self._num_total_expected_vertices()) + ) spec_list = mock_driver.simple_nagios_alarm_generators( host_num=1, @@ -70,19 +73,21 @@ class TestNagios(TestDataSourcesBase): processor.process_event(nagios_event) # Test assertions - self.assertEqual(self._num_total_expected_vertices() + 1, - len(processor.entity_graph)) + self.assertThat(processor.entity_graph, + matchers.HasLength( + self._num_total_expected_vertices() + 1) + ) nagios_vertices = processor.entity_graph.get_vertices( vertex_attr_filter={ VProps.VITRAGE_CATEGORY: EntityCategory.ALARM, VProps.VITRAGE_TYPE: NAGIOS_DATASOURCE }) - self.assertEqual(1, len(nagios_vertices)) + self.assertThat(nagios_vertices, matchers.HasLength(1)) nagios_neighbors = processor.entity_graph.neighbors( nagios_vertices[0].vertex_id) - self.assertEqual(1, len(nagios_neighbors)) + self.assertThat(nagios_neighbors, matchers.HasLength(1)) self.assertEqual(NOVA_HOST_DATASOURCE, nagios_neighbors[0][VProps.VITRAGE_TYPE]) diff --git a/vitrage/tests/functional/datasources/static_physical/test_static_physical.py b/vitrage/tests/functional/datasources/static_physical/test_static_physical.py index 20635bad0..2028ada43 100644 --- a/vitrage/tests/functional/datasources/static_physical/test_static_physical.py +++ b/vitrage/tests/functional/datasources/static_physical/test_static_physical.py @@ -13,6 +13,7 @@ # under the License. from oslo_config import cfg +from testtools import matchers from vitrage.common.constants import DatasourceProperties as DSProps from vitrage.common.constants import EntityCategory @@ -58,8 +59,10 @@ class TestStaticPhysical(TestDataSourcesBase): processor = self._create_processor_with_graph(self.conf) transformers = processor.transformer_manager.transformers transformers[SWITCH] = transformers[STATIC_PHYSICAL_DATASOURCE] - self.assertEqual(self._num_total_expected_vertices(), - len(processor.entity_graph)) + self.assertThat(processor.entity_graph, + matchers.HasLength( + self._num_total_expected_vertices()) + ) spec_list = mock_driver.simple_switch_generators( switch_num=1, @@ -76,19 +79,21 @@ class TestStaticPhysical(TestDataSourcesBase): processor.process_event(static_physical_event) # Test assertions - self.assertEqual(self._num_total_expected_vertices() + 1, - len(processor.entity_graph)) + self.assertThat(processor.entity_graph, + matchers.HasLength( + self._num_total_expected_vertices() + 1) + ) static_physical_vertices = processor.entity_graph.get_vertices( vertex_attr_filter={ VProps.VITRAGE_CATEGORY: EntityCategory.RESOURCE, VProps.VITRAGE_TYPE: SWITCH }) - self.assertEqual(1, len(static_physical_vertices)) + self.assertThat(static_physical_vertices, matchers.HasLength(1)) static_physical_neighbors = processor.entity_graph.neighbors( static_physical_vertices[0].vertex_id) - self.assertEqual(1, len(static_physical_neighbors)) + self.assertThat(static_physical_neighbors, matchers.HasLength(1)) self.assertEqual(NOVA_HOST_DATASOURCE, static_physical_neighbors[0][VProps.VITRAGE_TYPE]) diff --git a/vitrage/tests/functional/entity_graph/consistency/test_consistency.py b/vitrage/tests/functional/entity_graph/consistency/test_consistency.py index aaa3723eb..82ab97cc6 100644 --- a/vitrage/tests/functional/entity_graph/consistency/test_consistency.py +++ b/vitrage/tests/functional/entity_graph/consistency/test_consistency.py @@ -18,7 +18,7 @@ import unittest from oslo_config import cfg from six.moves import queue - +from testtools import matchers from vitrage.common.constants import EdgeLabel from vitrage.common.constants import EntityCategory @@ -115,9 +115,11 @@ class TestConsistencyFunctional(TestFunctionalBase, TestConfiguration): self._create_processor_with_graph(self.conf, processor=self.processor) self._add_alarms() self._set_end_messages() - self.assertEqual(self._num_total_expected_vertices() + - num_of_host_alarms + self.NUM_INSTANCES, - len(self.processor.entity_graph.get_vertices())) + self.assertThat(self.processor.entity_graph.get_vertices(), + matchers.HasLength( + self._num_total_expected_vertices() + + num_of_host_alarms + self.NUM_INSTANCES) + ) # Action # eventlet.spawn(self._process_events) @@ -142,23 +144,28 @@ class TestConsistencyFunctional(TestFunctionalBase, TestConfiguration): VProps.VITRAGE_CATEGORY: EntityCategory.ALARM, VProps.VITRAGE_IS_DELETED: False }) - self.assertEqual(num_correct_alarms, len(alarm_vertices_in_graph)) + self.assertThat(alarm_vertices_in_graph, + matchers.HasLength(num_correct_alarms)) is_deleted_alarm_vertices_in_graph = \ self.processor.entity_graph.get_vertices({ VProps.VITRAGE_CATEGORY: EntityCategory.ALARM, VProps.VITRAGE_IS_DELETED: True }) - self.assertEqual(num_of_host_alarms * num_instances_per_host, - len(is_deleted_alarm_vertices_in_graph)) + self.assertEqual(is_deleted_alarm_vertices_in_graph, + matchers.HasLength( + num_of_host_alarms * num_instances_per_host) + ) instance_vertices = self.processor.entity_graph.get_vertices({ VProps.VITRAGE_CATEGORY: EntityCategory.ALARM, VProps.VITRAGE_TYPE: VITRAGE_DATASOURCE, VProps.VITRAGE_IS_DELETED: False }) - self.assertEqual(num_of_host_alarms * num_instances_per_host, - len(instance_vertices)) + self.assertThat(instance_vertices, + matchers.HasLength( + num_of_host_alarms * num_instances_per_host) + ) def test_periodic_process(self): # Setup @@ -181,10 +188,13 @@ class TestConsistencyFunctional(TestFunctionalBase, TestConfiguration): VProps.VITRAGE_TYPE: NOVA_INSTANCE_DATASOURCE, VProps.VITRAGE_IS_DELETED: True }) - self.assertEqual(self.NUM_INSTANCES - 3, len(instance_vertices)) - self.assertEqual(self._num_total_expected_vertices() - 3, - len(self.processor.entity_graph.get_vertices())) - self.assertEqual(3, len(deleted_instance_vertices)) + self.assertThat(instance_vertices, + matchers.HasLength(self.NUM_INSTANCES - 3)) + self.assertThat(self.processor.entity_graph.get_vertices(), + matchers.HasLength( + self._num_total_expected_vertices() - 3) + ) + self.assertThat(deleted_instance_vertices, matchers.HasLength(3)) def _periodic_process_setup_stage(self, consistency_interval): self._create_processor_with_graph(self.conf, processor=self.processor) @@ -200,7 +210,8 @@ class TestConsistencyFunctional(TestFunctionalBase, TestConfiguration): VProps.VITRAGE_CATEGORY: EntityCategory.RESOURCE, VProps.VITRAGE_TYPE: NOVA_INSTANCE_DATASOURCE }) - self.assertEqual(self.NUM_INSTANCES, len(instance_vertices)) + self.assertThat(instance_vertices, + matchers.HasLength(self.NUM_INSTANCES)) # set current timestamp of part of the instances self._update_timestamp(instance_vertices[0:3], current_time) diff --git a/vitrage/tests/functional/evaluator/test_scenario_evaluator.py b/vitrage/tests/functional/evaluator/test_scenario_evaluator.py index fa6bd4ebe..b9805a37e 100644 --- a/vitrage/tests/functional/evaluator/test_scenario_evaluator.py +++ b/vitrage/tests/functional/evaluator/test_scenario_evaluator.py @@ -12,6 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. from oslo_log import log +from testtools import matchers from vitrage.tests.functional.test_configuration import TestConfiguration @@ -44,6 +45,7 @@ from vitrage.evaluator.actions.evaluator_event_transformer \ from vitrage.evaluator.scenario_evaluator import ScenarioEvaluator from vitrage.evaluator.scenario_repository import ScenarioRepository from vitrage.graph import create_edge +from vitrage.tests.base import IsEmpty from vitrage.tests.functional.base import \ TestFunctionalBase import vitrage.tests.mocks.mock_driver as mock_driver @@ -234,11 +236,11 @@ class TestScenarioEvaluator(TestFunctionalBase, TestConfiguration): processor, _TARGET_HOST) alarms = \ self._get_deduced_alarms_on_host(host_v, processor.entity_graph) - self.assertEqual(1, len(alarms)) + self.assertThat(alarms, matchers.HasLength(1)) self.assertEqual(NagiosTestStatus.WARNING, alarms[0][VProps.SEVERITY]) causes = self._get_alarm_causes(alarms[0], processor.entity_graph) - self.assertEqual(1, len(causes)) + self.assertThat(causes, matchers.HasLength(1)) # next disable the alarm warning_test[NagiosProperties.STATUS] = NagiosTestStatus.OK @@ -246,7 +248,7 @@ class TestScenarioEvaluator(TestFunctionalBase, TestConfiguration): processor, _TARGET_HOST) alarms = \ self._get_deduced_alarms_on_host(host_v, processor.entity_graph) - self.assertEqual(0, len(alarms)) + self.assertThat(alarms, IsEmpty()) # recreate the nagios alarm warning_test[NagiosProperties.STATUS] = NagiosTestStatus.WARNING @@ -255,11 +257,11 @@ class TestScenarioEvaluator(TestFunctionalBase, TestConfiguration): processor, _TARGET_HOST) alarms = \ self._get_deduced_alarms_on_host(host_v, processor.entity_graph) - self.assertEqual(1, len(alarms)) + self.assertThat(alarms, matchers.HasLength(1)) self.assertEqual(NagiosTestStatus.WARNING, alarms[0][VProps.SEVERITY]) causes = self._get_alarm_causes(alarms[0], processor.entity_graph) - self.assertEqual(1, len(causes)) + self.assertThat(causes, matchers.HasLength(1)) # next disable the alarm warning_test[NagiosProperties.STATUS] = NagiosTestStatus.OK @@ -267,7 +269,7 @@ class TestScenarioEvaluator(TestFunctionalBase, TestConfiguration): processor, _TARGET_HOST) alarms = \ self._get_deduced_alarms_on_host(host_v, processor.entity_graph) - self.assertEqual(0, len(alarms)) + self.assertThat(alarms, IsEmpty()) def test_overlapping_deduced_alarm_1(self): @@ -284,11 +286,11 @@ class TestScenarioEvaluator(TestFunctionalBase, TestConfiguration): processor, _TARGET_HOST) alarms = \ self._get_deduced_alarms_on_host(host_v, processor.entity_graph) - self.assertEqual(1, len(alarms)) + self.assertThat(alarms, matchers.HasLength(1)) self.assertEqual(NagiosTestStatus.WARNING, alarms[0][VProps.SEVERITY]) causes = self._get_alarm_causes(alarms[0], processor.entity_graph) - self.assertEqual(1, len(causes)) + self.assertThat(causes, matchers.HasLength(1)) # generate CRITICAL nagios alarm to trigger vals = {NagiosProperties.STATUS: NagiosTestStatus.CRITICAL, @@ -301,11 +303,11 @@ class TestScenarioEvaluator(TestFunctionalBase, TestConfiguration): processor, _TARGET_HOST) alarms = \ self._get_deduced_alarms_on_host(host_v, processor.entity_graph) - self.assertEqual(1, len(alarms)) + self.assertThat(alarms, matchers.HasLength(1)) self.assertEqual(NagiosTestStatus.CRITICAL, alarms[0][VProps.SEVERITY]) causes = self._get_alarm_causes(alarms[0], processor.entity_graph) - self.assertEqual(2, len(causes)) + self.assertThat(causes, matchers.HasLength(2)) # remove WARNING nagios alarm, leaving only CRITICAL one warning_test[NagiosProperties.STATUS] = NagiosTestStatus.OK @@ -313,10 +315,10 @@ class TestScenarioEvaluator(TestFunctionalBase, TestConfiguration): processor, _TARGET_HOST) alarms = \ self._get_deduced_alarms_on_host(host_v, processor.entity_graph) - self.assertEqual(1, len(alarms)) + self.assertThat(alarms, matchers.HasLength(1)) self.assertEqual(NagiosTestStatus.CRITICAL, alarms[0][VProps.SEVERITY]) causes = self._get_alarm_causes(alarms[0], processor.entity_graph) - self.assertEqual(1, len(causes)) + self.assertThat(causes, matchers.HasLength(1)) # next disable the alarm critical_test[NagiosProperties.STATUS] = NagiosTestStatus.OK @@ -324,7 +326,7 @@ class TestScenarioEvaluator(TestFunctionalBase, TestConfiguration): processor, _TARGET_HOST) alarms = \ self._get_deduced_alarms_on_host(host_v, processor.entity_graph) - self.assertEqual(0, len(alarms)) + self.assertThat(alarms, IsEmpty()) def test_overlapping_deduced_alarm_2(self): @@ -342,7 +344,7 @@ class TestScenarioEvaluator(TestFunctionalBase, TestConfiguration): processor, _TARGET_HOST) alarms = \ self._get_deduced_alarms_on_host(host_v, processor.entity_graph) - self.assertEqual(1, len(alarms)) + self.assertThat(alarms, matchers.HasLength(1)) self.assertEqual(NagiosTestStatus.CRITICAL, alarms[0][VProps.SEVERITY]) @@ -357,7 +359,7 @@ class TestScenarioEvaluator(TestFunctionalBase, TestConfiguration): processor, _TARGET_HOST) alarms = \ self._get_deduced_alarms_on_host(host_v, processor.entity_graph) - self.assertEqual(1, len(alarms)) + self.assertThat(alarms, matchers.HasLength(1)) self.assertEqual(NagiosTestStatus.CRITICAL, alarms[0][VProps.SEVERITY]) @@ -367,7 +369,7 @@ class TestScenarioEvaluator(TestFunctionalBase, TestConfiguration): processor, _TARGET_HOST) alarms = \ self._get_deduced_alarms_on_host(host_v, processor.entity_graph) - self.assertEqual(1, len(alarms)) + self.assertThat(alarms, matchers.HasLength(1)) self.assertEqual(NagiosTestStatus.WARNING, alarms[0][VProps.SEVERITY]) @@ -459,7 +461,7 @@ class TestScenarioEvaluator(TestFunctionalBase, TestConfiguration): num_deduced_vertices, entity_graph.num_vertices()) self.assertEqual(num_orig_edges + num_added_edges + num_deduced_edges, entity_graph.num_edges()) - self.assertEqual(1, len(port_neighbors)) + self.assertThat(port_neighbors, matchers.HasLength(1)) self.assertEqual(EntityCategory.ALARM, port_neighbors[0][VProps.VITRAGE_CATEGORY]) self.assertEqual(VITRAGE_DATASOURCE, @@ -494,7 +496,7 @@ class TestScenarioEvaluator(TestFunctionalBase, TestConfiguration): VProps.VITRAGE_TYPE: VITRAGE_DATASOURCE} port_neighbors = entity_graph.neighbors(port_vertex.vertex_id, vertex_attr_filter=query) - self.assertEqual(1, len(port_neighbors)) + self.assertThat(port_neighbors, matchers.HasLength(1)) self.assertEqual(EntityCategory.ALARM, port_neighbors[0][VProps.VITRAGE_CATEGORY]) self.assertEqual(VITRAGE_DATASOURCE, @@ -546,7 +548,7 @@ class TestScenarioEvaluator(TestFunctionalBase, TestConfiguration): for counter in range(0, 1): port_neighbors = entity_graph.neighbors(port_vertex.vertex_id, vertex_attr_filter=query) - self.assertEqual(1, len(port_neighbors)) + self.assertThat(port_neighbors, matchers.HasLength(1)) self.assertEqual(port_neighbors[0][VProps.VITRAGE_CATEGORY], EntityCategory.ALARM) self.assertEqual(port_neighbors[0][VProps.VITRAGE_TYPE], @@ -602,7 +604,7 @@ class TestScenarioEvaluator(TestFunctionalBase, TestConfiguration): for counter in range(0, 1): port_neighbors = entity_graph.neighbors(port_vertex.vertex_id, vertex_attr_filter=query) - self.assertEqual(2, len(port_neighbors)) + self.assertThat(port_neighbors, matchers.HasLength(2)) for in_counter in range(0, 1): self.assertEqual( EntityCategory.ALARM, @@ -657,7 +659,7 @@ class TestScenarioEvaluator(TestFunctionalBase, TestConfiguration): for counter in range(0, 1): port_neighbors = entity_graph.neighbors(port_vertex.vertex_id, vertex_attr_filter=query) - self.assertEqual(2, len(port_neighbors)) + self.assertThat(port_neighbors, matchers.HasLength(2)) for in_counter in range(0, 1): self.assertEqual( EntityCategory.ALARM, @@ -765,7 +767,7 @@ class TestScenarioEvaluator(TestFunctionalBase, TestConfiguration): num_deduced_vertices, entity_graph.num_vertices()) self.assertEqual(num_orig_edges + num_added_edges + num_deduced_edges, entity_graph.num_edges()) - self.assertEqual(1, len(zone_neighbors)) + self.assertThat(zone_neighbors, matchers.HasLength(1)) self.assertEqual(EntityCategory.ALARM, zone_neighbors[0][VProps.VITRAGE_CATEGORY]) self.assertEqual(VITRAGE_DATASOURCE, @@ -799,7 +801,7 @@ class TestScenarioEvaluator(TestFunctionalBase, TestConfiguration): query = {VProps.VITRAGE_CATEGORY: EntityCategory.ALARM} network_neighbors = entity_graph.neighbors(network_vertex.vertex_id, vertex_attr_filter=query) - self.assertEqual(1, len(network_neighbors)) + self.assertThat(network_neighbors, matchers.HasLength(1)) self.assertEqual(EntityCategory.ALARM, network_neighbors[0][VProps.VITRAGE_CATEGORY]) self.assertEqual(NAGIOS_DATASOURCE, @@ -810,7 +812,7 @@ class TestScenarioEvaluator(TestFunctionalBase, TestConfiguration): zone_neighbors = entity_graph.neighbors(zone_vertex.vertex_id, vertex_attr_filter=query) - self.assertEqual(1, len(zone_neighbors)) + self.assertThat(zone_neighbors, matchers.HasLength(1)) self.assertEqual(EntityCategory.ALARM, zone_neighbors[0][VProps.VITRAGE_CATEGORY]) self.assertEqual(VITRAGE_DATASOURCE, @@ -839,7 +841,7 @@ class TestScenarioEvaluator(TestFunctionalBase, TestConfiguration): query = {VProps.VITRAGE_CATEGORY: EntityCategory.ALARM} network_neighbors = entity_graph.neighbors(network_vertex.vertex_id, vertex_attr_filter=query) - self.assertEqual(1, len(network_neighbors)) + self.assertThat(network_neighbors, matchers.HasLength(1)) self.assertEqual(EntityCategory.ALARM, network_neighbors[0][VProps.VITRAGE_CATEGORY]) self.assertEqual(NAGIOS_DATASOURCE, @@ -855,7 +857,7 @@ class TestScenarioEvaluator(TestFunctionalBase, TestConfiguration): for counter in range(0, 1): zone_neighbors = entity_graph.neighbors(zone_vertex.vertex_id, vertex_attr_filter=query) - self.assertEqual(1, len(zone_neighbors)) + self.assertThat(zone_neighbors, matchers.HasLength(1)) self.assertEqual(EntityCategory.ALARM, zone_neighbors[0][VProps.VITRAGE_CATEGORY]) self.assertEqual(VITRAGE_DATASOURCE, @@ -920,7 +922,7 @@ class TestScenarioEvaluator(TestFunctionalBase, TestConfiguration): VProps.VITRAGE_TYPE: CINDER_VOLUME_DATASOURCE} instance_neighbors = entity_graph.neighbors(instances[0].vertex_id, vertex_attr_filter=query) - self.assertEqual(1, len(instance_neighbors)) + self.assertThat(instance_neighbors, matchers.HasLength(1)) self.assertEqual(EntityCategory.RESOURCE, instance_neighbors[0][VProps.VITRAGE_CATEGORY]) self.assertEqual(CINDER_VOLUME_DATASOURCE, @@ -969,7 +971,7 @@ class TestScenarioEvaluator(TestFunctionalBase, TestConfiguration): VProps.VITRAGE_TYPE: CINDER_VOLUME_DATASOURCE} instance_neighbors = entity_graph.neighbors(instances[1].vertex_id, vertex_attr_filter=query) - self.assertEqual(1, len(instance_neighbors)) + self.assertThat(instance_neighbors, matchers.HasLength(1)) self.assertEqual(EntityCategory.RESOURCE, instance_neighbors[0][VProps.VITRAGE_CATEGORY]) self.assertEqual(CINDER_VOLUME_DATASOURCE, @@ -984,7 +986,7 @@ class TestScenarioEvaluator(TestFunctionalBase, TestConfiguration): VProps.NAME: 'ha_error_deduced_alarm'} host_neighbors = entity_graph.neighbors(hosts[0].vertex_id, vertex_attr_filter=query) - self.assertEqual(1, len(host_neighbors)) + self.assertThat(host_neighbors, matchers.HasLength(1)) self.assertEqual(EntityCategory.ALARM, host_neighbors[0][VProps.VITRAGE_CATEGORY]) self.assertEqual(VITRAGE_DATASOURCE, @@ -1000,7 +1002,7 @@ class TestScenarioEvaluator(TestFunctionalBase, TestConfiguration): VProps.NAME: 'ha_warning_deduced_alarm'} host_neighbors = entity_graph.neighbors(hosts[0].vertex_id, vertex_attr_filter=query) - self.assertEqual(1, len(host_neighbors)) + self.assertThat(host_neighbors, matchers.HasLength(1)) self.assertEqual(EntityCategory.ALARM, host_neighbors[0][VProps.VITRAGE_CATEGORY]) self.assertEqual(VITRAGE_DATASOURCE, @@ -1036,7 +1038,7 @@ class TestScenarioEvaluator(TestFunctionalBase, TestConfiguration): VProps.VITRAGE_TYPE: CINDER_VOLUME_DATASOURCE} instance_neighbors = entity_graph.neighbors(instances[1].vertex_id, vertex_attr_filter=query) - self.assertEqual(1, len(instance_neighbors)) + self.assertThat(instance_neighbors, matchers.HasLength(1)) self.assertEqual(EntityCategory.RESOURCE, instance_neighbors[0][VProps.VITRAGE_CATEGORY]) self.assertEqual(CINDER_VOLUME_DATASOURCE, @@ -1051,7 +1053,7 @@ class TestScenarioEvaluator(TestFunctionalBase, TestConfiguration): VProps.NAME: 'ha_error_deduced_alarm'} host_neighbors = entity_graph.neighbors(hosts[0].vertex_id, vertex_attr_filter=query) - self.assertEqual(1, len(host_neighbors)) + self.assertThat(host_neighbors, matchers.HasLength(1)) self.assertEqual(EntityCategory.ALARM, host_neighbors[0][VProps.VITRAGE_CATEGORY]) self.assertEqual(VITRAGE_DATASOURCE, @@ -1068,7 +1070,7 @@ class TestScenarioEvaluator(TestFunctionalBase, TestConfiguration): VProps.VITRAGE_IS_DELETED: False} host_neighbors = entity_graph.neighbors(hosts[0].vertex_id, vertex_attr_filter=query) - self.assertEqual(1, len(host_neighbors)) + self.assertThat(host_neighbors, matchers.HasLength(1)) self.assertEqual(EntityCategory.ALARM, host_neighbors[0][VProps.VITRAGE_CATEGORY]) self.assertEqual(VITRAGE_DATASOURCE, @@ -1085,7 +1087,7 @@ class TestScenarioEvaluator(TestFunctionalBase, TestConfiguration): VProps.VITRAGE_IS_DELETED: True} host_neighbors = entity_graph.neighbors(hosts[0].vertex_id, vertex_attr_filter=query) - self.assertEqual(1, len(host_neighbors)) + self.assertThat(host_neighbors, matchers.HasLength(1)) self.assertEqual(EntityCategory.ALARM, host_neighbors[0][VProps.VITRAGE_CATEGORY]) self.assertEqual(VITRAGE_DATASOURCE, @@ -1121,7 +1123,7 @@ class TestScenarioEvaluator(TestFunctionalBase, TestConfiguration): VProps.VITRAGE_TYPE: CINDER_VOLUME_DATASOURCE} instance_neighbors = entity_graph.neighbors(instances[0].vertex_id, vertex_attr_filter=query) - self.assertEqual(1, len(instance_neighbors)) + self.assertThat(instance_neighbors, matchers.HasLength(1)) self.assertEqual(EntityCategory.RESOURCE, instance_neighbors[0][VProps.VITRAGE_CATEGORY]) self.assertEqual(CINDER_VOLUME_DATASOURCE, @@ -1136,7 +1138,7 @@ class TestScenarioEvaluator(TestFunctionalBase, TestConfiguration): VProps.NAME: 'ha_error_deduced_alarm'} host_neighbors = entity_graph.neighbors(hosts[0].vertex_id, vertex_attr_filter=query) - self.assertEqual(1, len(host_neighbors)) + self.assertThat(host_neighbors, matchers.HasLength(1)) self.assertEqual(EntityCategory.ALARM, host_neighbors[0][VProps.VITRAGE_CATEGORY]) self.assertEqual(VITRAGE_DATASOURCE, @@ -1152,7 +1154,7 @@ class TestScenarioEvaluator(TestFunctionalBase, TestConfiguration): VProps.NAME: 'ha_warning_deduced_alarm'} host_neighbors = entity_graph.neighbors(hosts[0].vertex_id, vertex_attr_filter=query) - self.assertEqual(2, len(host_neighbors)) + self.assertThat(host_neighbors, matchers.HasLength(2)) self.assertEqual(EntityCategory.ALARM, host_neighbors[0][VProps.VITRAGE_CATEGORY]) @@ -1199,7 +1201,7 @@ class TestScenarioEvaluator(TestFunctionalBase, TestConfiguration): host_v = self.get_host_after_event(event_queue, alarm1_test, processor, _TARGET_HOST) alarms = self._get_alarms_on_host(host_v, processor.entity_graph) - self.assertEqual(2, len(alarms)) + self.assertThat(alarms, matchers.HasLength(2)) # generate nagios alarm2 to trigger test_vals = {NagiosProperties.STATUS: NagiosTestStatus.WARNING, @@ -1211,14 +1213,13 @@ class TestScenarioEvaluator(TestFunctionalBase, TestConfiguration): host_v = self.get_host_after_event(event_queue, alarm2_test, processor, _TARGET_HOST) alarms = self._get_alarms_on_host(host_v, processor.entity_graph) - self.assertEqual(3, len(alarms)) - + self.assertThat(alarms, matchers.HasLength(3)) # disable alarm1, alarm3 is not deleted alarm1_test[NagiosProperties.STATUS] = NagiosTestStatus.OK host_v = self.get_host_after_event(event_queue, alarm1_test, processor, _TARGET_HOST) alarms = self._get_alarms_on_host(host_v, processor.entity_graph) - self.assertEqual(2, len(alarms)) + self.assertThat(alarms, matchers.HasLength(2)) # disable alarm2, alarm3 is deleted alarm2_test[NagiosProperties.STATUS] = NagiosTestStatus.OK @@ -1226,7 +1227,7 @@ class TestScenarioEvaluator(TestFunctionalBase, TestConfiguration): host_v = self.get_host_after_event(event_queue, alarm2_test, processor, _TARGET_HOST) alarms = self._get_alarms_on_host(host_v, processor.entity_graph) - self.assertEqual(0, len(alarms)) + self.assertThat(alarms, IsEmpty()) def test_both_and_or_operator_for_tracker(self): """(alarm_a or alarm_b) and alarm_c use case @@ -1266,7 +1267,7 @@ class TestScenarioEvaluator(TestFunctionalBase, TestConfiguration): host_v = self.get_host_after_event(event_queue, alarm_a_test, processor, _TARGET_HOST) alarms = self._get_alarms_on_host(host_v, entity_graph) - self.assertEqual(1, len(alarms)) + self.assertThat(alarms, matchers.HasLength(1)) self.assertEqual(num_orig_vertices + 1, entity_graph.num_vertices()) self.assertEqual(num_orig_edges + 1, entity_graph.num_edges()) @@ -1280,7 +1281,7 @@ class TestScenarioEvaluator(TestFunctionalBase, TestConfiguration): host_v = self.get_host_after_event(event_queue, alarm_b_test, processor, _TARGET_HOST) alarms = self._get_alarms_on_host(host_v, entity_graph) - self.assertEqual(2, len(alarms)) + self.assertThat(alarms, matchers.HasLength(2)) self.assertEqual(num_orig_vertices + 2, entity_graph.num_vertices()) self.assertEqual(num_orig_edges + 2, entity_graph.num_edges()) @@ -1294,7 +1295,7 @@ class TestScenarioEvaluator(TestFunctionalBase, TestConfiguration): host_v = self.get_host_after_event(event_queue, alarm_c_test, processor, _TARGET_HOST) alarms = self._get_alarms_on_host(host_v, entity_graph) - self.assertEqual(4, len(alarms)) + self.assertThat(alarms, matchers.HasLength(4)) self.assertEqual(num_orig_vertices + 4, entity_graph.num_vertices()) self.assertEqual(num_orig_edges + 4, entity_graph.num_edges()) @@ -1308,7 +1309,7 @@ class TestScenarioEvaluator(TestFunctionalBase, TestConfiguration): host_v = self.get_host_after_event(event_queue, alarm_b_ok, processor, _TARGET_HOST) alarms = self._get_alarms_on_host(host_v, entity_graph) - self.assertEqual(3, len(alarms)) + self.assertThat(alarms, matchers.HasLength(3)) query = {VProps.VITRAGE_CATEGORY: EntityCategory.ALARM, VProps.VITRAGE_IS_DELETED: True} @@ -1333,7 +1334,7 @@ class TestScenarioEvaluator(TestFunctionalBase, TestConfiguration): host_v = self.get_host_after_event(event_queue, alarm_a_ok, processor, _TARGET_HOST) alarms = self._get_alarms_on_host(host_v, entity_graph) - self.assertEqual(1, len(alarms)) + self.assertThat(alarms, matchers.HasLength(1)) query = {VProps.VITRAGE_CATEGORY: EntityCategory.ALARM, VProps.VITRAGE_IS_DELETED: True} @@ -1388,7 +1389,6 @@ class TestScenarioEvaluator(TestFunctionalBase, TestConfiguration): VProps.ID: entity_id, VProps.NAME: entity_name} vertices = entity_graph.get_vertices(vertex_attr_filter=vertex_attrs) - # assert len(vertices) == 1, "incorrect number of vertices" return vertices[0] @staticmethod diff --git a/vitrage/tests/unit/common/test_utils.py b/vitrage/tests/unit/common/test_utils.py index 2e1e1895c..1c4279f08 100644 --- a/vitrage/tests/unit/common/test_utils.py +++ b/vitrage/tests/unit/common/test_utils.py @@ -15,6 +15,7 @@ import itertools from vitrage.common import utils from vitrage.tests import base +from vitrage.tests.base import IsEmpty class UtilsTest(base.BaseTest): @@ -60,9 +61,9 @@ class UtilsTest(base.BaseTest): self._assert_set_equal(union, set(all_items), 'chunks union differs') combinations = itertools.combinations(range(len(chunks)), 2) for i, j in combinations: - self.assertEqual( - 0, len(chunks[i].intersection(chunks[j])), - "Each two chunks should not have intersecting items") + self.assertThat(chunks[i].intersection(chunks[j]), IsEmpty(), + "Each two chunks should not have " + "intersecting items") max_size = len(max(chunks, key=lambda x: len(x))) min_size = len(min(chunks, key=lambda x: len(x))) expected_max_difference = 1 if len(all_items) % len(chunks) else 0 diff --git a/vitrage/tests/unit/datasources/aodh/test_aodh_transformer.py b/vitrage/tests/unit/datasources/aodh/test_aodh_transformer.py index 91af5f401..60b4eb14d 100644 --- a/vitrage/tests/unit/datasources/aodh/test_aodh_transformer.py +++ b/vitrage/tests/unit/datasources/aodh/test_aodh_transformer.py @@ -14,6 +14,7 @@ from oslo_config import cfg from oslo_log import log as logging +from testtools import matchers from vitrage.common.constants import DatasourceOpts as DSOpts from vitrage.common.constants import DatasourceProperties as DSProps @@ -104,7 +105,7 @@ class TestAodhAlarmTransformer(AodhTransformerBaseTest): self._validate_aodh_vertex_props(vertex, event) neighbors = wrapper.neighbors - self.assertEqual(1, len(neighbors)) + self.assertThat(neighbors, matchers.HasLength(1)) self._validate_neighbors(neighbors, vertex.vertex_id, event) self._validate_action(event, wrapper) @@ -155,7 +156,7 @@ class TestAodhAlarmPushTransformer(AodhTransformerBaseTest): self._validate_aodh_vertex_props(vertex, event) neighbors = wrapper.neighbors - self.assertEqual(1, len(neighbors)) + self.assertThat(neighbors, matchers.HasLength(1)) self._validate_neighbors(neighbors, vertex.vertex_id, event) self._validate_action(event, wrapper) diff --git a/vitrage/tests/unit/datasources/ceilometer/test_ceilometer_transformer.py b/vitrage/tests/unit/datasources/ceilometer/test_ceilometer_transformer.py index 186f9280a..6a919363c 100644 --- a/vitrage/tests/unit/datasources/ceilometer/test_ceilometer_transformer.py +++ b/vitrage/tests/unit/datasources/ceilometer/test_ceilometer_transformer.py @@ -14,6 +14,7 @@ from oslo_config import cfg from oslo_log import log as logging +from testtools import matchers from vitrage.common.constants import DatasourceOpts as DSOpts from vitrage.common.constants import DatasourceProperties as DSProps @@ -108,7 +109,7 @@ class TestCeilometerAlarmTransformer(CeilometerTransformerBaseTest): self._validate_aodh_vertex_props(vertex, event) neighbors = wrapper.neighbors - self.assertEqual(1, len(neighbors)) + self.assertThat(neighbors, matchers.HasLength(1)) self._validate_neighbors(neighbors, vertex.vertex_id, event) self._validate_action(event, wrapper) @@ -159,7 +160,7 @@ class TestCeilometerAlarmPushTransformer(CeilometerTransformerBaseTest): self._validate_aodh_vertex_props(vertex, event) neighbors = wrapper.neighbors - self.assertEqual(1, len(neighbors)) + self.assertThat(neighbors, matchers.HasLength(1)) self._validate_neighbors(neighbors, vertex.vertex_id, event) self._validate_action(event, wrapper) diff --git a/vitrage/tests/unit/datasources/cinder/test_cinder_volume_transformer.py b/vitrage/tests/unit/datasources/cinder/test_cinder_volume_transformer.py index d7f044500..e419e134f 100644 --- a/vitrage/tests/unit/datasources/cinder/test_cinder_volume_transformer.py +++ b/vitrage/tests/unit/datasources/cinder/test_cinder_volume_transformer.py @@ -16,6 +16,7 @@ import datetime from oslo_config import cfg from oslo_log import log as logging +from testtools import matchers from vitrage.common.constants import DatasourceOpts as DSOpts from vitrage.common.constants import DatasourceProperties as DSProps @@ -136,7 +137,7 @@ class TestCinderVolumeTransformer(base.BaseTest): self._validate_volume_vertex_props(vertex, event) neighbors = wrapper.neighbors - self.assertEqual(1, len(neighbors)) + self.assertThat(neighbors, matchers.HasLength(1)) self._validate_neighbors(neighbors, vertex.vertex_id, event) def test_update_transform(self): @@ -159,7 +160,7 @@ class TestCinderVolumeTransformer(base.BaseTest): self._validate_volume_vertex_props(vertex, event) neighbors = wrapper.neighbors - self.assertEqual(1, len(neighbors)) + self.assertThat(neighbors, matchers.HasLength(1)) self._validate_neighbors(neighbors, vertex.vertex_id, event) def _validate_volume_vertex_props(self, vertex, event): diff --git a/vitrage/tests/unit/datasources/heat/test_heat_stack_transformer.py b/vitrage/tests/unit/datasources/heat/test_heat_stack_transformer.py index 6b3195bc2..449668d38 100644 --- a/vitrage/tests/unit/datasources/heat/test_heat_stack_transformer.py +++ b/vitrage/tests/unit/datasources/heat/test_heat_stack_transformer.py @@ -16,6 +16,7 @@ import datetime from oslo_config import cfg from oslo_log import log as logging +from testtools import matchers from vitrage.common.constants import DatasourceOpts as DSOpts from vitrage.common.constants import DatasourceProperties as DSProps @@ -195,7 +196,7 @@ class TestHeatStackTransformer(base.BaseTest): self.assertFalse(vertex[VProps.VITRAGE_IS_DELETED]) def _validate_neighbors(self, neighbors, stack_vertex_id, event): - self.assertEqual(2, len(neighbors)) + self.assertThat(neighbors, matchers.HasLength(2)) instance_id = event['resources'][0]['physical_resource_id'] self._validate_neighbor(neighbors[0], diff --git a/vitrage/tests/unit/datasources/nagios/test_nagios_driver.py b/vitrage/tests/unit/datasources/nagios/test_nagios_driver.py index 5e1f29718..21ce2994c 100644 --- a/vitrage/tests/unit/datasources/nagios/test_nagios_driver.py +++ b/vitrage/tests/unit/datasources/nagios/test_nagios_driver.py @@ -13,6 +13,7 @@ # under the License. from oslo_config import cfg +from testtools import matchers from vitrage.common.constants import DatasourceOpts as DSOpts from vitrage.common.constants import DatasourceProperties as DSProps @@ -21,6 +22,7 @@ from vitrage.datasources.nagios import NAGIOS_DATASOURCE from vitrage.datasources.nagios.properties import NagiosProperties as \ NagiosProps from vitrage.datasources.nagios.properties import NagiosTestStatus +from vitrage.tests.base import IsEmpty from vitrage.tests.mocks import utils from vitrage.tests.unit.datasources.nagios.mock_driver import MockNagiosDriver from vitrage.tests.unit.datasources.nagios.nagios_base_test import \ @@ -75,7 +77,7 @@ class NagiosDriverTest(NagiosBaseTest): # Test assertions # Services with status OK should not be returned self.assertIsNotNone(services, 'No services returned') - self.assertEqual(0, len(services)) + self.assertThat(services, IsEmpty()) # Action service_data1 = {NagiosProps.RESOURCE_NAME: 'compute-0', @@ -96,7 +98,7 @@ class NagiosDriverTest(NagiosBaseTest): # Test assertions self.assertIsNotNone(services, 'No services returned') - self.assertEqual(1, len(services)) + self.assertThat(services, matchers.HasLength(1)) self._assert_contains(service_data1, services) # Action @@ -118,7 +120,7 @@ class NagiosDriverTest(NagiosBaseTest): # Test assertions self.assertIsNotNone(services, 'No services returned') - self.assertEqual(2, len(services)) + self.assertThat(services, matchers.HasLength(2)) self._assert_contains(service_data1, services) self._assert_contains(service_data2, services) @@ -143,7 +145,7 @@ class NagiosDriverTest(NagiosBaseTest): # The services of service_data1/2 should be returned although their # status is OK, because they were not OK earlier self.assertIsNotNone(services, 'No services returned') - self.assertEqual(2, len(services)) + self.assertThat(services, matchers.HasLength(2)) self._assert_contains(service_data1, services) self._assert_contains(service_data2, services) @@ -154,7 +156,7 @@ class NagiosDriverTest(NagiosBaseTest): # Calling get_services again should not return anything, since all # services are still OK self.assertIsNotNone(services, 'services is None') - self.assertEqual(0, len(services)) + self.assertThat(services, IsEmpty()) def test_get_changes(self): """Check get_changes functionality. @@ -186,7 +188,7 @@ class NagiosDriverTest(NagiosBaseTest): # Test assertions # Services with status OK should not be returned self.assertIsNotNone(services, 'No services returned') - self.assertEqual(0, len(services)) + self.assertThat(services, IsEmpty()) # Action service_data1 = {NagiosProps.RESOURCE_NAME: 'compute-0', @@ -207,7 +209,7 @@ class NagiosDriverTest(NagiosBaseTest): # Test assertions self.assertIsNotNone(services, 'No services returned') - self.assertEqual(1, len(services)) + self.assertThat(services, matchers.HasLength(1)) self._assert_contains(service_data1, services) # Action @@ -229,7 +231,7 @@ class NagiosDriverTest(NagiosBaseTest): # Test assertions self.assertIsNotNone(services, 'No services returned') - self.assertEqual(2, len(services)) + self.assertThat(services, matchers.HasLength(2)) self._assert_contains(service_data1, services) self._assert_contains(service_data2, services) @@ -252,7 +254,7 @@ class NagiosDriverTest(NagiosBaseTest): # Test assertions self.assertIsNotNone(services, 'No services returned') - self.assertEqual(1, len(services)) + self.assertThat(services, matchers.HasLength(1)) self._assert_contains(service_data2, services) # Action @@ -274,7 +276,7 @@ class NagiosDriverTest(NagiosBaseTest): # Test assertions self.assertIsNotNone(services, 'No services returned') - self.assertEqual(2, len(services)) + self.assertThat(services, matchers.HasLength(2)) self._assert_contains(service_data1, services) self._assert_contains(service_data2, services) @@ -283,7 +285,7 @@ class NagiosDriverTest(NagiosBaseTest): # Test assertions self.assertIsNotNone(services, 'services is None') - self.assertEqual(0, len(services)) + self.assertThat(services, IsEmpty()) def test_get_changes_and_get_all(self): """Check get_changes and get_all functionalities """ @@ -310,7 +312,7 @@ class NagiosDriverTest(NagiosBaseTest): # Test assertions self.assertIsNotNone(services, 'No services returned') - self.assertEqual(1, len(services)) + self.assertThat(services, matchers.HasLength(1)) self._assert_contains(service_data1, services) # Action @@ -319,14 +321,14 @@ class NagiosDriverTest(NagiosBaseTest): # Test assertions # Calling get_changes for the second time should return nothing self.assertIsNotNone(services, 'No services returned') - self.assertEqual(0, len(services)) + self.assertThat(services, IsEmpty()) # Action services = nagios_driver._get_all_alarms() # Test assertions self.assertIsNotNone(services, 'No services returned') - self.assertEqual(1, len(services)) + self.assertThat(services, matchers.HasLength(1)) self._assert_contains(service_data1, services) # Action @@ -335,7 +337,7 @@ class NagiosDriverTest(NagiosBaseTest): # Test assertions # Calling get_all for the second time should return the same results self.assertIsNotNone(services, 'No services returned') - self.assertEqual(1, len(services)) + self.assertThat(services, matchers.HasLength(1)) self._assert_contains(service_data1, services) # Action @@ -357,7 +359,7 @@ class NagiosDriverTest(NagiosBaseTest): # Test assertions self.assertIsNotNone(services, 'No services returned') - self.assertEqual(2, len(services)) + self.assertThat(services, matchers.HasLength(2)) self._assert_contains(service_data1, services) self._assert_contains(service_data2, services) @@ -367,7 +369,7 @@ class NagiosDriverTest(NagiosBaseTest): # Test assertions # Calling get_changes after get_all should return nothing self.assertIsNotNone(services, 'No services returned') - self.assertEqual(0, len(services)) + self.assertThat(services, IsEmpty()) # Action services = nagios_driver._get_all_alarms() @@ -375,7 +377,7 @@ class NagiosDriverTest(NagiosBaseTest): # Test assertions # Calling get_all for the second time should return the same results self.assertIsNotNone(services, 'No services returned') - self.assertEqual(2, len(services)) + self.assertThat(services, matchers.HasLength(2)) self._assert_contains(service_data1, services) self._assert_contains(service_data2, services) @@ -398,7 +400,7 @@ class NagiosDriverTest(NagiosBaseTest): # Test assertions self.assertIsNotNone(services, 'No services returned') - self.assertEqual(2, len(services)) + self.assertThat(services, matchers.HasLength(2)) self._assert_contains(service_data2, services) self._assert_contains(service_data3, services) @@ -421,7 +423,7 @@ class NagiosDriverTest(NagiosBaseTest): # Test assertions self.assertIsNotNone(services, 'No services returned') - self.assertEqual(1, len(services)) + self.assertThat(services, matchers.HasLength(1)) self._assert_contains(service_data1, services) # Action @@ -429,7 +431,7 @@ class NagiosDriverTest(NagiosBaseTest): # Test assertions self.assertIsNotNone(services, 'services is None') - self.assertEqual(0, len(services)) + self.assertThat(services, IsEmpty()) # Action services = nagios_driver._get_all_alarms() @@ -437,7 +439,7 @@ class NagiosDriverTest(NagiosBaseTest): # Test assertions # Calling get_all for the second time should return the same results self.assertIsNotNone(services, 'No services returned') - self.assertEqual(3, len(services)) + self.assertThat(services, matchers.HasLength(3)) self._assert_contains(service_data1, services) self._assert_contains(service_data2, services) self._assert_contains(service_data3, services) @@ -467,7 +469,7 @@ class NagiosDriverTest(NagiosBaseTest): # Test assertions self.assertIsNotNone(services, 'No services returned') - self.assertEqual(1, len(services)) + self.assertThat(services, matchers.HasLength(1)) self._assert_contains(service_data1, services) # Action - delete a service that was OK @@ -484,7 +486,7 @@ class NagiosDriverTest(NagiosBaseTest): # Test assertions self.assertIsNotNone(services, 'No services returned') - self.assertEqual(1, len(services)) + self.assertThat(services, matchers.HasLength(1)) self._assert_contains(service_data1, services) # Action - delete a service that was not OK @@ -498,7 +500,7 @@ class NagiosDriverTest(NagiosBaseTest): # Test assertions self.assertIsNotNone(services, 'No services returned') - self.assertEqual(1, len(services)) + self.assertThat(services, matchers.HasLength(1)) self._assert_contains(service_data1, services) self.assertEqual(GraphAction.DELETE_ENTITY, services[0][DSProps.EVENT_TYPE]) @@ -508,7 +510,7 @@ class NagiosDriverTest(NagiosBaseTest): # Test assertions self.assertIsNotNone(services, 'services is None') - self.assertEqual(0, len(services)) + self.assertThat(services, IsEmpty()) # Action - "undelete" the service that was OK service_data1 = {NagiosProps.RESOURCE_NAME: 'compute-0', @@ -524,7 +526,7 @@ class NagiosDriverTest(NagiosBaseTest): # Test assertions self.assertIsNotNone(services, 'No services returned') - self.assertEqual(1, len(services)) + self.assertThat(services, matchers.HasLength(1)) self._assert_contains(service_data1, services) self.assertNotIn(DSProps.EVENT_TYPE, services[0]) @@ -539,7 +541,7 @@ class NagiosDriverTest(NagiosBaseTest): # Test assertions self.assertIsNotNone(services, 'No services returned') - self.assertEqual(1, len(services)) + self.assertThat(services, matchers.HasLength(1)) self._assert_contains(service_data1, services) self.assertEqual(GraphAction.DELETE_ENTITY, services[0][DSProps.EVENT_TYPE]) diff --git a/vitrage/tests/unit/datasources/nagios/test_nagios_transformer.py b/vitrage/tests/unit/datasources/nagios/test_nagios_transformer.py index 40dc0a68e..769104a6b 100644 --- a/vitrage/tests/unit/datasources/nagios/test_nagios_transformer.py +++ b/vitrage/tests/unit/datasources/nagios/test_nagios_transformer.py @@ -14,6 +14,7 @@ from oslo_config import cfg from oslo_log import log as logging +from testtools import matchers from vitrage.common.constants import DatasourceAction from vitrage.common.constants import DatasourceOpts as DSOpts @@ -107,7 +108,7 @@ class NagiosTransformerTest(base.BaseTest): self._validate_vertex(wrapper.vertex, alarm) neighbors = wrapper.neighbors - self.assertEqual(1, len(neighbors)) + self.assertThat(neighbors, matchers.HasLength(1)) neighbor = neighbors[0] # Right now we are support only host as a resource diff --git a/vitrage/tests/unit/datasources/nova/test_nova_host_transformer.py b/vitrage/tests/unit/datasources/nova/test_nova_host_transformer.py index 89ac22c20..89b82e845 100644 --- a/vitrage/tests/unit/datasources/nova/test_nova_host_transformer.py +++ b/vitrage/tests/unit/datasources/nova/test_nova_host_transformer.py @@ -16,6 +16,7 @@ import datetime from oslo_config import cfg from oslo_log import log as logging +from testtools import matchers from vitrage.common.constants import DatasourceAction from vitrage.common.constants import DatasourceOpts as DSOpts @@ -135,7 +136,7 @@ class NovaHostTransformerTest(base.BaseTest): self._validate_vertex_props(wrapper.vertex, event) neighbors = wrapper.neighbors - self.assertEqual(1, len(neighbors)) + self.assertThat(neighbors, matchers.HasLength(1)) self._validate_zone_neighbor(neighbors[0], event) if DatasourceAction.SNAPSHOT == event[DSProps.DATASOURCE_ACTION]: diff --git a/vitrage/tests/unit/datasources/nova/test_nova_instance_transformer.py b/vitrage/tests/unit/datasources/nova/test_nova_instance_transformer.py index ad2fa12f7..dfa23b5a1 100644 --- a/vitrage/tests/unit/datasources/nova/test_nova_instance_transformer.py +++ b/vitrage/tests/unit/datasources/nova/test_nova_instance_transformer.py @@ -16,6 +16,7 @@ import datetime from oslo_config import cfg from oslo_log import log as logging +from testtools import matchers from vitrage.common.constants import DatasourceAction from vitrage.common.constants import DatasourceOpts as DSOpts @@ -118,9 +119,8 @@ class NovaInstanceTransformerTest(base.BaseTest): # Test assertions self._validate_vertex_props(wrapper.vertex, event) - self.assertEqual(1, - len(wrapper.neighbors), - 'Instance has only one host neighbor') + self.assertThat(wrapper.neighbors, matchers.HasLength(1), + 'Instance has only one host neighbor') host_neighbor = wrapper.neighbors[0] self._validate_host_neighbor(host_neighbor, event) @@ -150,7 +150,7 @@ class NovaInstanceTransformerTest(base.BaseTest): # Validate the neighbors: only one valid host neighbor neighbors = wrapper.neighbors - self.assertEqual(1, len(neighbors)) + self.assertThat(neighbors, matchers.HasLength(1)) self._validate_host_neighbor(neighbors[0], event) event_type = event[DSProps.EVENT_TYPE] @@ -163,7 +163,7 @@ class NovaInstanceTransformerTest(base.BaseTest): def _validate_vertex_props(self, vertex, event): - self.assertEqual(13, len(vertex.properties)) + self.assertThat(vertex.properties, matchers.HasLength(13)) is_update_event = tbase.is_update_event(event) diff --git a/vitrage/tests/unit/datasources/nova/test_nova_zone_transformer.py b/vitrage/tests/unit/datasources/nova/test_nova_zone_transformer.py index 6cadfc712..c93bbede3 100644 --- a/vitrage/tests/unit/datasources/nova/test_nova_zone_transformer.py +++ b/vitrage/tests/unit/datasources/nova/test_nova_zone_transformer.py @@ -16,6 +16,7 @@ import datetime from oslo_config import cfg from oslo_log import log as logging +from testtools import matchers from vitrage.common.constants import DatasourceOpts as DSOpts from vitrage.common.constants import DatasourceProperties as DSProps @@ -140,7 +141,7 @@ class NovaZoneTransformerTest(base.BaseTest): self._validate_vertex_props(vertex, event) neighbors = wrapper.neighbors - self.assertEqual(2, len(neighbors)) + self.assertThat(neighbors, matchers.HasLength(2)) self._validate_neighbors(neighbors, vertex.vertex_id, event) def _validate_neighbors(self, neighbors, zone_vertex_id, event): diff --git a/vitrage/tests/unit/datasources/static/test_static_driver.py b/vitrage/tests/unit/datasources/static/test_static_driver.py index 79c0921b5..6de54ff66 100644 --- a/vitrage/tests/unit/datasources/static/test_static_driver.py +++ b/vitrage/tests/unit/datasources/static/test_static_driver.py @@ -13,6 +13,7 @@ # under the License. from oslo_config import cfg +from testtools import matchers from vitrage.common.constants import DatasourceAction from vitrage.common.constants import DatasourceOpts as DSOpts @@ -21,6 +22,7 @@ from vitrage.datasources.static import driver from vitrage.datasources.static import STATIC_DATASOURCE from vitrage.datasources.static import StaticFields from vitrage.tests import base +from vitrage.tests.base import IsEmpty from vitrage.tests.mocks import utils @@ -73,7 +75,7 @@ class TestStaticDriver(base.BaseTest): DatasourceAction.INIT_SNAPSHOT) # Test assertions - self.assertEqual(9, len(static_entities)) + self.assertThat(static_entities, matchers.HasLength(9)) for entity in static_entities[:-1]: # exclude end message self._validate_static_entity(entity) @@ -82,7 +84,7 @@ class TestStaticDriver(base.BaseTest): def test_get_changes(self): # Setup entities = self.static_driver.get_all(DatasourceAction.UPDATE) - self.assertEqual(8, len(entities)) + self.assertThat(entities, matchers.HasLength(8)) self.conf = cfg.ConfigOpts() self.conf.register_opts(self.CHANGES_OPTS, @@ -94,7 +96,7 @@ class TestStaticDriver(base.BaseTest): GraphAction.UPDATE_ENTITY) # Test Assertions - self.assertEqual(0, len(changes)) + self.assertThat(changes, IsEmpty()) for entity in changes: self._validate_static_entity(entity) diff --git a/vitrage/tests/unit/datasources/static_physical/test_static_physical_driver.py b/vitrage/tests/unit/datasources/static_physical/test_static_physical_driver.py index 1ec115eb9..6d9fd0d3f 100644 --- a/vitrage/tests/unit/datasources/static_physical/test_static_physical_driver.py +++ b/vitrage/tests/unit/datasources/static_physical/test_static_physical_driver.py @@ -15,6 +15,7 @@ import os from oslo_config import cfg +from testtools import matchers from vitrage.common.constants import DatasourceAction from vitrage.common.constants import DatasourceOpts as DSOpts @@ -25,6 +26,7 @@ from vitrage.datasources.static_physical import driver from vitrage.datasources.static_physical import STATIC_PHYSICAL_DATASOURCE from vitrage.datasources.static_physical import SWITCH from vitrage.tests import base +from vitrage.tests.base import IsEmpty from vitrage.tests.mocks import utils from vitrage.utils import file as file_utils @@ -94,13 +96,13 @@ class TestStaticPhysicalDriver(base.BaseTest): self.static_physical_driver.get_all(DatasourceAction.UPDATE) # Test assertions - self.assertEqual(5, len(static_entities)) + self.assertThat(static_entities, matchers.HasLength(5)) # noinspection PyAttributeOutsideInit def test_get_changes(self): # Setup entities = self.static_physical_driver.get_all(DatasourceAction.UPDATE) - self.assertEqual(5, len(entities)) + self.assertThat(entities, matchers.HasLength(5)) self.conf = cfg.ConfigOpts() self.conf.register_opts(self.CHANGES_OPTS, @@ -133,11 +135,11 @@ class TestStaticPhysicalDriver(base.BaseTest): change[StaticFields.ID] == '56789' for change in changes) self.assertTrue(status) - self.assertEqual(4, len(changes)) + self.assertThat(changes, matchers.HasLength(4)) # Action changes = self.static_physical_driver.get_changes( GraphAction.UPDATE_ENTITY) # Test Assertions - self.assertEqual(0, len(changes)) + self.assertThat(changes, IsEmpty()) diff --git a/vitrage/tests/unit/datasources/test_alarm_transformer_base.py b/vitrage/tests/unit/datasources/test_alarm_transformer_base.py index d084541ba..f13a6e657 100644 --- a/vitrage/tests/unit/datasources/test_alarm_transformer_base.py +++ b/vitrage/tests/unit/datasources/test_alarm_transformer_base.py @@ -14,6 +14,8 @@ import abc +from testtools import matchers + from vitrage.common.constants import EdgeLabel from vitrage.common.constants import EntityCategory from vitrage.common.constants import GraphAction @@ -50,7 +52,7 @@ class BaseAlarmTransformerTest(BaseTransformerTest): alarm_id, host_name): - self.assertEqual(1, len(wrapper.neighbors)) + self.assertThat(wrapper.neighbors, matchers.HasLength(1)) host_neighbor = wrapper.neighbors[0] host_transformer = self.transformers[NOVA_HOST_DATASOURCE] diff --git a/vitrage/tests/unit/datasources/zabbix/test_zabbix_driver.py b/vitrage/tests/unit/datasources/zabbix/test_zabbix_driver.py index 9146b48a2..22f9a6779 100644 --- a/vitrage/tests/unit/datasources/zabbix/test_zabbix_driver.py +++ b/vitrage/tests/unit/datasources/zabbix/test_zabbix_driver.py @@ -15,12 +15,14 @@ import copy from oslo_config import cfg +from testtools import matchers from vitrage.common.constants import DatasourceOpts as DSOpts from vitrage.common.constants import DatasourceProperties as DSProps from vitrage.common.constants import GraphAction from vitrage.datasources.zabbix.properties import ZabbixProperties as ZProps from vitrage.datasources.zabbix import ZABBIX_DATASOURCE +from vitrage.tests.base import IsEmpty from vitrage.tests.mocks import utils from vitrage.tests.unit.datasources.zabbix.mock_driver import MockZabbixDriver from vitrage.tests.unit.datasources.zabbix.zabbix_base_test import \ @@ -63,7 +65,7 @@ class ZabbixDriverTest(ZabbixBaseTest): # Test assertions self.assertIsNotNone(alarms, 'No alarms returned') - self.assertEqual(1, len(alarms)) + self.assertThat(alarms, matchers.HasLength(1)) self._assert_contains(alarm_data3, alarms) def test_get_all_functionality(self): @@ -84,7 +86,7 @@ class ZabbixDriverTest(ZabbixBaseTest): # Test assertions self.assertIsNotNone(alarms, 'No alarms returned') - self.assertEqual(0, len(alarms)) + self.assertThat(alarms, IsEmpty()) # Step 2 - one raised alarm # Test setup @@ -97,7 +99,7 @@ class ZabbixDriverTest(ZabbixBaseTest): # Test assertions self.assertIsNotNone(alarms, 'No alarms returned') - self.assertEqual(1, len(alarms)) + self.assertThat(alarms, matchers.HasLength(1)) self._assert_contains(alarm_data1, alarms) # Step 3 - two raised alarms @@ -117,7 +119,7 @@ class ZabbixDriverTest(ZabbixBaseTest): # Test assertions self.assertIsNotNone(alarms, 'No alarms returned') - self.assertEqual(2, len(alarms)) + self.assertThat(alarms, matchers.HasLength(2)) self._assert_contains(expected_alarm1, alarms) self._assert_contains(expected_alarm2, alarms) @@ -140,7 +142,7 @@ class ZabbixDriverTest(ZabbixBaseTest): # The alarms of alarm_data1/2 should be returned although their # status is OK, because they were not OK earlier self.assertIsNotNone(alarms, 'No alarms returned') - self.assertEqual(2, len(alarms)) + self.assertThat(alarms, matchers.HasLength(2)) self._assert_contains(expected_alarm1, alarms) self._assert_contains(expected_alarm2, alarms) @@ -152,7 +154,7 @@ class ZabbixDriverTest(ZabbixBaseTest): # Test assertions self.assertIsNotNone(alarms, 'alarms is None') - self.assertEqual(0, len(alarms)) + self.assertThat(alarms, IsEmpty()) def test_get_changes_functionality(self): @@ -174,7 +176,7 @@ class ZabbixDriverTest(ZabbixBaseTest): # Test assertions self.assertIsNotNone(alarms, 'No alarms returned') - self.assertEqual(0, len(alarms)) + self.assertThat(alarms, IsEmpty()) # Step 2 - get changes when alarm is raised # Test setup @@ -187,7 +189,7 @@ class ZabbixDriverTest(ZabbixBaseTest): # Test assertions self.assertIsNotNone(alarms, 'No alarms returned') - self.assertEqual(1, len(alarms)) + self.assertThat(alarms, matchers.HasLength(1)) self._assert_contains(alarm_data1, alarms) # Step 3 - get changes when the priority of inactive alarm is changed @@ -201,7 +203,7 @@ class ZabbixDriverTest(ZabbixBaseTest): # Test assertions self.assertIsNotNone(alarms, 'No alarms returned') - self.assertEqual(0, len(alarms)) + self.assertThat(alarms, IsEmpty()) # Step 4 - get changes when: # 1. alarm1 - priority of active alarm is changed (should be returned) @@ -227,7 +229,7 @@ class ZabbixDriverTest(ZabbixBaseTest): # Test assertions self.assertIsNotNone(alarms, 'No alarms returned') - self.assertEqual(2, len(alarms)) + self.assertThat(alarms, matchers.HasLength(2)) self._assert_contains(expected_alarm1, alarms) self._assert_contains(expected_alarm2, alarms) @@ -248,7 +250,7 @@ class ZabbixDriverTest(ZabbixBaseTest): # Test assertions self.assertIsNotNone(alarms, 'No alarms returned') - self.assertEqual(2, len(alarms)) + self.assertThat(alarms, matchers.HasLength(2)) self._assert_contains(expected_alarm1, alarms) self._assert_contains(expected_alarm2, alarms) @@ -258,7 +260,7 @@ class ZabbixDriverTest(ZabbixBaseTest): # Test assertions self.assertIsNotNone(alarms, 'alarms is None') - self.assertEqual(0, len(alarms)) + self.assertThat(alarms, IsEmpty()) def test_get_changes_and_get_all(self): @@ -278,7 +280,7 @@ class ZabbixDriverTest(ZabbixBaseTest): # Step assertions self.assertIsNotNone(alarms, 'No alarms returned') - self.assertEqual(1, len(alarms)) + self.assertThat(alarms, matchers.HasLength(1)) self._assert_contains(alarm_data1, alarms) # Step 2 - get changes when no change occurred (returns nothing) @@ -287,7 +289,7 @@ class ZabbixDriverTest(ZabbixBaseTest): # Step assertions self.assertIsNotNone(alarms, 'No alarms returned') - self.assertEqual(0, len(alarms)) + self.assertThat(alarms, IsEmpty()) # Step 3 - get all # Step action @@ -295,7 +297,7 @@ class ZabbixDriverTest(ZabbixBaseTest): # Step assertions self.assertIsNotNone(alarms, 'No alarms returned') - self.assertEqual(1, len(alarms)) + self.assertThat(alarms, matchers.HasLength(1)) self._assert_contains(alarm_data1, alarms) # Step 4 - get all for second time @@ -305,7 +307,7 @@ class ZabbixDriverTest(ZabbixBaseTest): # Step assertions self.assertIsNotNone(alarms, 'No alarms returned') - self.assertEqual(1, len(alarms)) + self.assertThat(alarms, matchers.HasLength(1)) self._assert_contains(alarm_data1, alarms) # Step 5 - calling get changes right after get all (returns nothing) @@ -327,12 +329,12 @@ class ZabbixDriverTest(ZabbixBaseTest): # Step assertions self.assertIsNotNone(get_all_alarms, 'No alarms returned') - self.assertEqual(2, len(get_all_alarms)) + self.assertThat(get_all_alarms, matchers.HasLength(2)) self._assert_contains(expected_alarm1, get_all_alarms) self._assert_contains(expected_alarm2, get_all_alarms) self.assertIsNotNone(changed_alarms, 'No alarms returned') - self.assertEqual(0, len(changed_alarms)) + self.assertThat(changed_alarms, IsEmpty()) # Step 6 - get changes # Step setup @@ -356,7 +358,7 @@ class ZabbixDriverTest(ZabbixBaseTest): # Step assertions self.assertIsNotNone(alarms, 'No alarms returned') - self.assertEqual(2, len(alarms)) + self.assertThat(alarms, matchers.HasLength(2)) self._assert_contains(expected_alarm1, alarms) self._assert_contains(expected_alarm2, alarms) @@ -380,7 +382,7 @@ class ZabbixDriverTest(ZabbixBaseTest): # Step assertions self.assertIsNotNone(alarms, 'No alarms returned') - self.assertEqual(1, len(alarms)) + self.assertThat(alarms, matchers.HasLength(1)) self._assert_contains(alarm_data1, alarms) # Step 2 - delete active alarm @@ -392,7 +394,7 @@ class ZabbixDriverTest(ZabbixBaseTest): # Step assertions self.assertIsNotNone(alarms, 'No alarms returned') - self.assertEqual(1, len(alarms)) + self.assertThat(alarms, matchers.HasLength(1)) self._assert_contains(alarm_data1, alarms) self.assertEqual(GraphAction.DELETE_ENTITY, alarms[0][DSProps.EVENT_TYPE]) @@ -403,7 +405,7 @@ class ZabbixDriverTest(ZabbixBaseTest): # Step assertions self.assertIsNotNone(alarms, 'alarms is None') - self.assertEqual(0, len(alarms)) + self.assertThat(alarms, IsEmpty()) # Step 4 - # Step setup @@ -416,7 +418,7 @@ class ZabbixDriverTest(ZabbixBaseTest): # Step assertions self.assertIsNotNone(alarms, 'No alarms returned') - self.assertEqual(1, len(alarms)) + self.assertThat(alarms, matchers.HasLength(1)) self._assert_contains(alarm_data1, alarms) self.assertEqual(GraphAction.DELETE_ENTITY, alarms[0][DSProps.EVENT_TYPE]) diff --git a/vitrage/tests/unit/datasources/zabbix/test_zabbix_transformer.py b/vitrage/tests/unit/datasources/zabbix/test_zabbix_transformer.py index 7f7d79abe..7950a906f 100644 --- a/vitrage/tests/unit/datasources/zabbix/test_zabbix_transformer.py +++ b/vitrage/tests/unit/datasources/zabbix/test_zabbix_transformer.py @@ -14,6 +14,7 @@ from oslo_config import cfg from oslo_log import log as logging +from testtools import matchers from vitrage.common.constants import DatasourceAction from vitrage.common.constants import DatasourceOpts as DSOpts @@ -100,7 +101,7 @@ class ZabbixTransformerTest(base.BaseTest): self._validate_vertex(wrapper.vertex, alarm) neighbors = wrapper.neighbors - self.assertEqual(1, len(neighbors)) + self.assertThat(neighbors, matchers.HasLength(1)) neighbor = neighbors[0] # Right now we are support only host as a resource diff --git a/vitrage/tests/unit/entity_graph/processor/test_entity_graph.py b/vitrage/tests/unit/entity_graph/processor/test_entity_graph.py index 652181815..20872cb49 100644 --- a/vitrage/tests/unit/entity_graph/processor/test_entity_graph.py +++ b/vitrage/tests/unit/entity_graph/processor/test_entity_graph.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. +from testtools import matchers from vitrage.common.constants import EdgeLabel from vitrage.common.constants import EntityCategory @@ -111,4 +112,4 @@ class TestEntityGraphManager(base.TestBaseProcessor): # get neighbors types types = PUtils.find_neighbor_types(neighbors) - self.assertEqual(4, len(types)) + self.assertThat(types, matchers.HasLength(4)) diff --git a/vitrage/tests/unit/entity_graph/processor/test_processor.py b/vitrage/tests/unit/entity_graph/processor/test_processor.py index aca95e7ff..f23bfdf54 100644 --- a/vitrage/tests/unit/entity_graph/processor/test_processor.py +++ b/vitrage/tests/unit/entity_graph/processor/test_processor.py @@ -13,6 +13,7 @@ # under the License. from oslo_config import cfg +from testtools import matchers from vitrage.common.constants import DatasourceAction as DSAction from vitrage.common.constants import DatasourceProperties as DSProps @@ -408,7 +409,8 @@ class TestProcessor(TestEntityGraphUnitBase): num_vertices, num_edges, vertex_id=None): - self.assertEqual(num_vertices, len(processor.entity_graph)) + self.assertThat(processor.entity_graph, + matchers.HasLength(num_vertices)) if not vertex_id: self.assertEqual(num_edges, processor.entity_graph.num_edges()) diff --git a/vitrage/tests/unit/entity_graph/states/test_datasource_info_mapper.py b/vitrage/tests/unit/entity_graph/states/test_datasource_info_mapper.py index b0bfbc489..753bc8ff4 100644 --- a/vitrage/tests/unit/entity_graph/states/test_datasource_info_mapper.py +++ b/vitrage/tests/unit/entity_graph/states/test_datasource_info_mapper.py @@ -13,6 +13,7 @@ # under the License. from oslo_config import cfg +from testtools import matchers from vitrage.common.constants import EntityCategory from vitrage.common.constants import VertexProperties as VProps @@ -74,8 +75,8 @@ class TestDatasourceInfoMapper(base.BaseTest): # Total datasources plus the evaluator which is not definable total_datasources = len(self.conf.datasources.types) + 1 - self.assertEqual(total_datasources, - len(state_manager.datasources_state_confs)) + self.assertThat(state_manager.datasources_state_confs, + matchers.HasLength(total_datasources)) def test_load_datasources_state_with_errors(self): # setup @@ -97,7 +98,8 @@ class TestDatasourceInfoMapper(base.BaseTest): erroneous_values = 1 num_valid_datasources = len(state_manager.datasources_state_confs) + \ missing_states + erroneous_values - self.assertEqual(num_valid_datasources, len(conf.datasources.types)) + self.assertThat(conf.datasources.types, + matchers.HasLength(num_valid_datasources)) def test_vitrage_operational_state_exists(self): # setup diff --git a/vitrage/tests/unit/evaluator/recipes/test_add_causal_relationship_recipe.py b/vitrage/tests/unit/evaluator/recipes/test_add_causal_relationship_recipe.py index 6c0e5b621..feb30888b 100644 --- a/vitrage/tests/unit/evaluator/recipes/test_add_causal_relationship_recipe.py +++ b/vitrage/tests/unit/evaluator/recipes/test_add_causal_relationship_recipe.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. +from testtools import matchers from vitrage.common.constants import EdgeLabel from vitrage.common.constants import EdgeProperties @@ -50,11 +51,11 @@ class AddCausalRelationshipTest(base.BaseTest): # Test Assertions # expecting for one step: add edge - self.assertEqual(1, len(action_steps)) + self.assertThat(action_steps, matchers.HasLength(1)) self.assertEqual(ADD_EDGE, action_steps[0].type) add_edge_step_params = action_steps[0].params - self.assertEqual(3, len(add_edge_step_params)) + self.assertThat(add_edge_step_params, matchers.HasLength(3)) source = add_edge_step_params.get(TField.SOURCE) self.assertEqual(self.source_vertex.vertex_id, source) @@ -73,11 +74,11 @@ class AddCausalRelationshipTest(base.BaseTest): # Test Assertions # expecting for one step: remove edge - self.assertEqual(1, len(action_steps)) + self.assertThat(action_steps, matchers.HasLength(1)) self.assertEqual(REMOVE_EDGE, action_steps[0].type) add_edge_step_params = action_steps[0].params - self.assertEqual(3, len(add_edge_step_params)) + self.assertThat(add_edge_step_params, matchers.HasLength(3)) source = add_edge_step_params.get(TField.SOURCE) self.assertEqual(self.source_vertex.vertex_id, source) diff --git a/vitrage/tests/unit/evaluator/recipes/test_mark_down.py b/vitrage/tests/unit/evaluator/recipes/test_mark_down.py index ade57f490..4ecbd0baf 100644 --- a/vitrage/tests/unit/evaluator/recipes/test_mark_down.py +++ b/vitrage/tests/unit/evaluator/recipes/test_mark_down.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. +from testtools import matchers from vitrage.common.constants import VertexProperties as VProps from vitrage.evaluator.actions.base import ActionType @@ -41,11 +42,11 @@ class MarkDownRecipeTest(base.BaseTest): # Test Assertions # expecting for one step: [update_vertex] - self.assertEqual(1, len(action_steps)) + self.assertThat(action_steps, matchers.HasLength(1)) self.assertEqual(UPDATE_VERTEX, action_steps[0].type) update_vertex_step_params = action_steps[0].params - self.assertEqual(3, len(update_vertex_step_params)) + self.assertThat(update_vertex_step_params, matchers.HasLength(3)) is_marked_down = update_vertex_step_params[VProps.IS_MARKED_DOWN] self.assertTrue(is_marked_down) @@ -65,11 +66,11 @@ class MarkDownRecipeTest(base.BaseTest): # Test Assertions # expecting for one step: [update_vertex] - self.assertEqual(1, len(action_steps)) + self.assertThat(action_steps, matchers.HasLength(1)) self.assertEqual(UPDATE_VERTEX, action_steps[0].type) update_vertex_step_params = action_steps[0].params - self.assertEqual(3, len(update_vertex_step_params)) + self.assertThat(update_vertex_step_params, matchers.HasLength(3)) is_marked_down = update_vertex_step_params[VProps.IS_MARKED_DOWN] self.assertFalse(is_marked_down) diff --git a/vitrage/tests/unit/evaluator/recipes/test_raise_alarm.py b/vitrage/tests/unit/evaluator/recipes/test_raise_alarm.py index 1e7d44484..502683d1d 100644 --- a/vitrage/tests/unit/evaluator/recipes/test_raise_alarm.py +++ b/vitrage/tests/unit/evaluator/recipes/test_raise_alarm.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. +from testtools import matchers from vitrage.common.constants import VertexProperties as VProps from vitrage.datasources.alarm_properties import AlarmProperties @@ -48,11 +49,11 @@ class RaiseAlarmRecipeTest(base.BaseTest): # Test Assertions # expecting for one step: [add_vertex] - self.assertEqual(1, len(action_steps)) + self.assertThat(action_steps, matchers.HasLength(1)) self.assertEqual(ADD_VERTEX, action_steps[0].type) add_vertex_step_params = action_steps[0].params - self.assertEqual(4, len(add_vertex_step_params)) + self.assertThat(add_vertex_step_params, matchers.HasLength(4)) alarm_name = add_vertex_step_params[TFields.ALARM_NAME] self.assertEqual(self.props[TFields.ALARM_NAME], alarm_name) @@ -76,14 +77,14 @@ class RaiseAlarmRecipeTest(base.BaseTest): # Test Assertions # expecting for one step: [remove_vertex] - self.assertEqual(1, len(action_steps)) + self.assertThat(action_steps, matchers.HasLength(1)) self.assertEqual(REMOVE_VERTEX, action_steps[0].type) remove_vertex_step_params = action_steps[0].params # remove_vertex expects four params: alarm name, state, target, # and type - self.assertEqual(4, len(remove_vertex_step_params)) + self.assertThat(remove_vertex_step_params, matchers.HasLength(4)) alarm_name = remove_vertex_step_params[TFields.ALARM_NAME] self.assertEqual(self.props[TFields.ALARM_NAME], alarm_name) diff --git a/vitrage/tests/unit/evaluator/recipes/test_set_state_recipe.py b/vitrage/tests/unit/evaluator/recipes/test_set_state_recipe.py index b17c10f94..b6ed73196 100644 --- a/vitrage/tests/unit/evaluator/recipes/test_set_state_recipe.py +++ b/vitrage/tests/unit/evaluator/recipes/test_set_state_recipe.py @@ -11,6 +11,8 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. +from testtools import matchers + from vitrage.entity_graph.mappings.operational_resource_state import \ OperationalResourceState @@ -49,11 +51,12 @@ class SetStateRecipeTest(base.BaseTest): # Test Assertions # expecting for one step: [update_vertex] - self.assertEqual(1, len(action_steps)) + self.assertThat(action_steps, matchers.HasLength(1)) self.assertEqual(UPDATE_VERTEX, action_steps[0].type) update_vertex_step_params = action_steps[0].params - self.assertEqual(_SET_STATES_PARAM_LEN, len(update_vertex_step_params)) + self.assertThat(update_vertex_step_params, + matchers.HasLength(_SET_STATES_PARAM_LEN)) vitrage_state = update_vertex_step_params[VProps.VITRAGE_STATE] self.assertEqual(self.props[TFields.STATE], vitrage_state) @@ -69,11 +72,12 @@ class SetStateRecipeTest(base.BaseTest): # Test Assertions # expecting for one step: [update_vertex] - self.assertEqual(1, len(action_steps)) + self.assertThat(action_steps, matchers.HasLength(1)) self.assertEqual(UPDATE_VERTEX, action_steps[0].type) update_vertex_step_params = action_steps[0].params - self.assertEqual(_SET_STATES_PARAM_LEN, len(update_vertex_step_params)) + self.assertThat(update_vertex_step_params, + matchers.HasLength(_SET_STATES_PARAM_LEN)) vitrage_state = update_vertex_step_params[VProps.VITRAGE_STATE] self.assertIsNone(vitrage_state) diff --git a/vitrage/tests/unit/evaluator/test_scenario_repository.py b/vitrage/tests/unit/evaluator/test_scenario_repository.py index ecf5aa520..5507388cf 100644 --- a/vitrage/tests/unit/evaluator/test_scenario_repository.py +++ b/vitrage/tests/unit/evaluator/test_scenario_repository.py @@ -13,6 +13,7 @@ # under the License. from oslo_config import cfg +from testtools import matchers from vitrage.common.constants import EntityCategory from vitrage.common.constants import TemplateTypes as TType @@ -22,6 +23,7 @@ from vitrage.evaluator.template_validation.template_syntax_validator import \ syntax_validation from vitrage.graph import Vertex from vitrage.tests import base +from vitrage.tests.base import IsEmpty from vitrage.tests.functional.test_configuration import TestConfiguration from vitrage.tests.mocks import utils from vitrage.utils import file as file_utils @@ -58,10 +60,10 @@ class ScenarioRepositoryTest(base.BaseTest, TestConfiguration): # Test assertions self.assertIsNotNone(scenario_repository) - self.assertEqual( - 2, - len(scenario_repository.templates), - 'scenario_repository.templates should contain all valid templates') + self.assertThat(scenario_repository.templates, + matchers.HasLength(2), + 'scenario_repository.templates ' + 'should contain all valid templates') def test_init_scenario_repository(self): @@ -77,10 +79,10 @@ class ScenarioRepositoryTest(base.BaseTest, TestConfiguration): scenario_templates = self.scenario_repository.templates # there is one bad template - self.assertEqual( - valid_template_counter, - len(scenario_templates), - 'scenario_repository.templates should contain all valid templates') + self.assertThat(scenario_templates, + matchers.HasLength(valid_template_counter), + 'scenario_repository.templates ' + 'should contain all valid templates') entity_equivalences = self.scenario_repository.entity_equivalences for entity_props, equivalence in entity_equivalences.items(): @@ -136,7 +138,7 @@ class RegExTemplateTest(base.BaseTest, TestConfiguration): relevant_scenarios = \ self.scenario_repository.get_scenarios_by_vertex( event_vertex) - self.assertEqual(1, len(relevant_scenarios)) + self.assertThat(relevant_scenarios, matchers.HasLength(1)) relevant_scenario = relevant_scenarios[0] self.assertEqual("zabbix_alarm_pass", relevant_scenario[0].vertex_id) @@ -154,7 +156,7 @@ class RegExTemplateTest(base.BaseTest, TestConfiguration): relevant_scenarios = \ self.scenario_repository.get_scenarios_by_vertex( event_vertex) - self.assertEqual(1, len(relevant_scenarios)) + self.assertThat(relevant_scenarios, matchers.HasLength(1)) relevant_scenario = relevant_scenarios[0] self.assertEqual("exact_match", relevant_scenario[0].vertex_id) @@ -172,7 +174,7 @@ class RegExTemplateTest(base.BaseTest, TestConfiguration): relevant_scenarios = \ self.scenario_repository.get_scenarios_by_vertex( event_vertex) - self.assertEqual(0, len(relevant_scenarios)) + self.assertThat(relevant_scenarios, IsEmpty()) class EquivalentScenarioTest(base.BaseTest, TestConfiguration): @@ -207,11 +209,11 @@ class EquivalentScenarioTest(base.BaseTest, TestConfiguration): for key, scenarios in entity_scenarios.items(): if (VProps.VITRAGE_CATEGORY, EntityCategory.ALARM) in key: # scenarios expanded on the other alarm - self.assertEqual(2, len(scenarios)) + self.assertThat(scenarios, matchers.HasLength(2)) if (VProps.VITRAGE_CATEGORY, EntityCategory.RESOURCE) in key: # Scenarios expanded on the two alarms. Each alarm is expanded # to two equivalent alarms. Thus 2 x 2 = 4 in total - self.assertEqual(4, len(scenarios)) + self.assertThat(scenarios, matchers.HasLength(4)) # each relationship is expand to two. Thus 2 x 2 = 4 in total relationships = self.scenario_repository.relationship_scenarios.keys() - self.assertEqual(4, len(relationships)) + self.assertThat(relationships, matchers.HasLength(4)) diff --git a/vitrage/tests/unit/evaluator/test_template_loader.py b/vitrage/tests/unit/evaluator/test_template_loader.py index 64bee92b2..9bfc3f71c 100644 --- a/vitrage/tests/unit/evaluator/test_template_loader.py +++ b/vitrage/tests/unit/evaluator/test_template_loader.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. +from testtools import matchers from vitrage.common.constants import EdgeLabel from vitrage.common.constants import EdgeProperties @@ -250,12 +251,12 @@ class TemplateLoaderTest(base.BaseTest): template_data = TemplateLoader().load(template_definition) scenarios = template_data.scenarios self.assertIsNotNone(scenarios, 'Template should include a scenario') - self.assertEqual(1, len(scenarios), - 'Template should include a single scenario') + self.assertThat(scenarios, matchers.HasLength(1), + 'Template should include a single scenario') actions = scenarios[0].actions self.assertIsNotNone(actions, 'Scenario should include an action') - self.assertEqual(1, len(actions), - 'Scenario should include a single action') + self.assertThat(actions, matchers.HasLength(1), + 'Scenario should include a single action') return actions[0] def _assert_equal_actions(self, action1, action2): @@ -344,12 +345,12 @@ class TemplateLoaderTest(base.BaseTest): :param entities """ self.assertIsNotNone(scenarios) - self.assertEqual(1, len(scenarios)) + self.assertThat(scenarios, matchers.HasLength(1)) scenario = scenarios[0] condition = scenario.condition - self.assertEqual(1, len(condition)) + self.assertThat(condition, matchers.HasLength(1)) condition_var = condition[0][0] self.assertIsInstance(condition_var, ConditionVar) @@ -359,16 +360,16 @@ class TemplateLoaderTest(base.BaseTest): actions = scenario.actions self.assert_is_not_empty(scenario.actions) - self.assertEqual(1, len(actions)) + self.assertThat(actions, matchers.HasLength(1)) action = actions[0] self.assertEqual(action.type, ActionType.SET_STATE) targets = action.targets - self.assertEqual(1, len(targets)) + self.assertThat(targets, matchers.HasLength(1)) self.assertEqual('resource', targets['target']) properties = action.properties - self.assertEqual(1, len(properties)) + self.assertThat(properties, matchers.HasLength(1)) self.assertEqual(properties['state'], OperationalResourceState.SUBOPTIMAL) diff --git a/vitrage/tests/unit/graph/base.py b/vitrage/tests/unit/graph/base.py index a057d14ce..69695e41e 100644 --- a/vitrage/tests/unit/graph/base.py +++ b/vitrage/tests/unit/graph/base.py @@ -205,7 +205,4 @@ class GraphTestBase(base.BaseTest): if not expected_graph_size == len(g): raise VitrageError('Init failed, graph size unexpected {0} != {1}' .format(expected_graph_size, len(g))) - # cls.assertEqual( - # expected_graph_size, - # len(g), 'num of vertex node') return g diff --git a/vitrage/tests/unit/graph/test_graph.py b/vitrage/tests/unit/graph/test_graph.py index 5a9a61fcd..d961f82d8 100644 --- a/vitrage/tests/unit/graph/test_graph.py +++ b/vitrage/tests/unit/graph/test_graph.py @@ -18,11 +18,13 @@ test_vitrage graph Tests for `vitrage` graph driver """ +from testtools import matchers from vitrage.common.constants import EdgeProperties as EProps from vitrage.graph import Direction from vitrage.graph.filter import check_filter from vitrage.graph import utils +from vitrage.tests.base import IsEmpty from vitrage.tests.unit.graph.base import * # noqa LOG = logging.getLogger(__name__) @@ -33,20 +35,26 @@ class TestGraph(GraphTestBase): def test_graph(self): g = NXGraph('test_graph') self.assertEqual('test_graph', g.name, 'graph name') - self.assertEqual(0, len(g), 'graph __len__') + self.assertThat(g, IsEmpty(), 'graph __len__') g.add_vertex(v_node) g.add_vertex(v_host) g.add_edge(e_node_to_host) - self.assertEqual(2, len(g), 'graph __len__ after add vertices') + self.assertThat(g, + matchers.HasLength(2), + 'graph __len__ after add vertices') graph_copy = g.copy() self.assertEqual('test_graph', graph_copy.name, 'graph copy name') - self.assertEqual(2, len(graph_copy), 'graph copy __len__') + self.assertThat(graph_copy, + matchers.HasLength(2), + 'graph copy __len__') g.remove_vertex(v_node) - self.assertEqual(1, len(g), 'graph __len__ after remove vertex') - self.assertEqual(2, len(graph_copy), 'graph copy __len__') + self.assertThat(g, matchers.HasLength(1), + 'graph __len__ after remove vertex') + self.assertThat(graph_copy, matchers.HasLength(2), + 'graph copy __len__') updated_vertex = g.get_vertex(v_host.vertex_id) updated_vertex[VProps.VITRAGE_CATEGORY] = ALARM @@ -125,7 +133,8 @@ class TestGraph(GraphTestBase): # Remove the item g.remove_vertex(another_vertex) - self.assertEqual(1, len(g), 'graph __len__ after remove vertex') + self.assertThat(g, matchers.HasLength(1), + 'graph __len__ after remove vertex') v = g.get_vertex(another_vertex.vertex_id) self.assertIsNone(v, 'removed vertex not in graph') @@ -171,19 +180,17 @@ class TestGraph(GraphTestBase): # Edge is correct v_node_neig = g.neighbors(v_node.vertex_id, direction=Direction.OUT) - self.assertEqual(1, len(v_node_neig), - 'v_node OUT neighbor count') + self.assertThat(v_node_neig, matchers.HasLength(1), + 'v_node OUT neighbor count') self.assertEqual(v_host.vertex_id, v_node_neig.pop().vertex_id, 'v_node OUT neighbor is v_host') v_node_neig = g.neighbors(v_node.vertex_id, direction=Direction.IN) - self.assertEqual(0, len(v_node_neig), - 'v_node IN neighbor count') + self.assertThat(v_node_neig, IsEmpty(), 'v_node IN neighbor count') v_host_neig = g.neighbors(v_host.vertex_id, direction=Direction.OUT) - self.assertEqual(0, len(v_host_neig), - 'v_host OUT neighbor count') + self.assertThat(v_host_neig, IsEmpty(), 'v_host OUT neighbor count') v_host_neig = g.neighbors(v_host.vertex_id, direction=Direction.IN) - self.assertEqual(1, len(v_host_neig), - 'v_host IN neighbor count') + self.assertThat(v_host_neig, matchers.HasLength(1), + 'v_host IN neighbor count') self.assertEqual(v_node.vertex_id, v_host_neig.pop().vertex_id, 'v_host IN neighbor is v_node') @@ -400,13 +407,13 @@ class TestGraph(GraphTestBase): g.add_edge(e_node_to_host) all_vertices = g.get_vertices() - self.assertEqual(2, len(all_vertices), - 'get_vertices __len__ all vertices') + self.assertThat(all_vertices, matchers.HasLength(2), + 'get_vertices __len__ all vertices') node_vertices = g.get_vertices( vertex_attr_filter={VProps.VITRAGE_TYPE: OPENSTACK_CLUSTER}) - self.assertEqual(1, len(node_vertices), - 'get_vertices __len__ node vertices') + self.assertThat(node_vertices, matchers.HasLength(1), + 'get_vertices __len__ node vertices') found_vertex = node_vertices.pop() self.assertEqual(OPENSTACK_CLUSTER, found_vertex[VProps.VITRAGE_TYPE], 'get_vertices check node vertex') @@ -414,8 +421,8 @@ class TestGraph(GraphTestBase): node_vertices = g.get_vertices( vertex_attr_filter={VProps.VITRAGE_TYPE: OPENSTACK_CLUSTER, VProps.VITRAGE_CATEGORY: RESOURCE}) - self.assertEqual(1, len(node_vertices), - 'get_vertices __len__ node vertices') + self.assertThat(node_vertices, matchers.HasLength(1), + 'get_vertices __len__ node vertices') found_vertex = node_vertices.pop() self.assertEqual(OPENSTACK_CLUSTER, found_vertex[VProps.VITRAGE_TYPE], 'get_vertices check node vertex') @@ -519,7 +526,8 @@ class TestGraph(GraphTestBase): g2.add_edge(e_v3_v4) g1.union(g2) - self.assertEqual(4, len(g1), 'incorrect graph len after union') + self.assertThat(g1, matchers.HasLength(4), + 'incorrect graph len after union') e = g1.get_edge(e_v3_v4.source_id, e_v3_v4.target_id, e_v3_v4.label) self.assertIsNotNone(e, 'Edge missing after graphs union') diff --git a/vitrage/tests/unit/graph/test_graph_algo.py b/vitrage/tests/unit/graph/test_graph_algo.py index a801f21be..93deb19ff 100644 --- a/vitrage/tests/unit/graph/test_graph_algo.py +++ b/vitrage/tests/unit/graph/test_graph_algo.py @@ -18,6 +18,7 @@ test_vitrage graph algorithms Tests for `vitrage` graph driver algorithms """ +from testtools import matchers from vitrage.common.constants import EdgeLabel from vitrage.common.constants import EdgeProperties as EProps @@ -29,6 +30,7 @@ from vitrage.graph.algo_driver.sub_graph_matching import \ from vitrage.graph.algo_driver.sub_graph_matching import subgraph_matching from vitrage.graph.driver.elements import Edge from vitrage.graph.driver.graph import Direction +from vitrage.tests.base import IsEmpty from vitrage.tests.unit.graph.base import * # noqa ROOT_ID = EntityCategory.RESOURCE + ':' + OPENSTACK_CLUSTER + ':' + CLUSTER_ID @@ -176,8 +178,8 @@ class GraphAlgorithmTest(GraphTestBase): edge_query_dict=edge_query) alarms = subgraph.get_vertices( vertex_attr_filter={VProps.VITRAGE_CATEGORY: ALARM}) - self.assertEqual(len(alarms), 0, 'We filtered the ON relationship,' - ' so no alarms should exist') + self.assertThat(alarms, IsEmpty(), 'We filtered the ON relationship,' + ' so no alarms should exist') # check that the vitrage_is_deleted=True edges are deleted from the # graph @@ -301,9 +303,9 @@ class GraphAlgorithmTest(GraphTestBase): host_alarm, is_vertex=True), validate=True) - self.assertEqual( - 0, - len(mappings), + self.assertThat( + mappings, + IsEmpty(), 'Template - Single vertex alarm not in graph ' 'Template_root is a specific host alarm ') template_graph.remove_vertex(t_v_alarm_fail) @@ -313,9 +315,9 @@ class GraphAlgorithmTest(GraphTestBase): Mapping(t_v_host_alarm, host_alarm, is_vertex=True)) - self.assertEqual( - 1, - len(mappings), + self.assertThat( + mappings, + matchers.HasLength(1), 'Template - Single vertex (host alarm) ' 'Template_root is a specific host alarm ') @@ -324,9 +326,9 @@ class GraphAlgorithmTest(GraphTestBase): Mapping(t_v_host_alarm, host_alarm, is_vertex=True)) - self.assertEqual( - 0, - len(mappings), + self.assertThat( + mappings, + IsEmpty(), 'Template - Two disconnected vertices (host alarm , host)' 'Template_root is a specific host alarm ') @@ -335,8 +337,9 @@ class GraphAlgorithmTest(GraphTestBase): Mapping(t_v_host_alarm, host_alarm, is_vertex=True)) - self.assertEqual( - 1, len(mappings), + self.assertThat( + mappings, + matchers.HasLength(1), 'Template - Two connected vertices (host alarm -ON-> host)' ' template_root is a specific host alarm ') @@ -346,9 +349,9 @@ class GraphAlgorithmTest(GraphTestBase): Mapping(t_v_host, host_vertex, is_vertex=True)) - self.assertEqual( - ENTITY_GRAPH_ALARMS_PER_HOST, - len(mappings), + self.assertThat( + mappings, + matchers.HasLength(ENTITY_GRAPH_ALARMS_PER_HOST), 'Template - Two connected vertices (host alarm -ON-> host)' ' template_root is a specific host ') @@ -357,9 +360,9 @@ class GraphAlgorithmTest(GraphTestBase): Mapping(t_v_host_alarm, host_alarm, is_vertex=True)) - self.assertEqual( - 0, - len(mappings), + self.assertThat( + mappings, + IsEmpty(), 'Template - Two connected vertices and a disconnected vertex' '(host alarm -ON-> host, instance)' ' template_root is a specific host alarm ') @@ -369,9 +372,9 @@ class GraphAlgorithmTest(GraphTestBase): Mapping(t_v_vm_alarm, vm_alarm, is_vertex=True)) - self.assertEqual( - 0, - len(mappings), + self.assertThat( + mappings, + IsEmpty(), 'Template - Two connected vertices and two disconnected vertices' '(host alarm -ON-> host, instance, instance alarm)' ' template_root is a specific instance alarm ') @@ -381,9 +384,9 @@ class GraphAlgorithmTest(GraphTestBase): Mapping(t_v_vm_alarm, vm_alarm, is_vertex=True)) - self.assertEqual( - 0, - len(mappings), + self.assertThat( + mappings, + IsEmpty(), 'Template - Two connected vertices and two more connected vertices' '(host alarm -ON-> host, instance alarm -ON-> instance)' ' template_root is a specific instance alarm ') @@ -393,9 +396,9 @@ class GraphAlgorithmTest(GraphTestBase): Mapping(t_v_vm_alarm, vm_alarm, is_vertex=True)) - self.assertEqual( - ENTITY_GRAPH_ALARMS_PER_HOST, - len(mappings), + self.assertThat( + mappings, + matchers.HasLength(ENTITY_GRAPH_ALARMS_PER_HOST), 'Template - Four connected vertices' '(host alarm -ON-> host -CONTAINS-> instance <-ON- instance alarm)' ' template_root is a specific instance alarm ') @@ -404,9 +407,10 @@ class GraphAlgorithmTest(GraphTestBase): Mapping(t_v_host_alarm, host_alarm, is_vertex=True)) - self.assertEqual( - ENTITY_GRAPH_VMS_PER_HOST * ENTITY_GRAPH_ALARMS_PER_VM, - len(mappings), + self.assertThat( + mappings, + matchers.HasLength(ENTITY_GRAPH_VMS_PER_HOST * + ENTITY_GRAPH_ALARMS_PER_VM), 'Template - Four connected vertices' '(host alarm -ON-> host -CONTAINS-> instance <-ON- instance alarm)' ' template_root is a specific host alarm ') @@ -415,10 +419,11 @@ class GraphAlgorithmTest(GraphTestBase): Mapping(t_v_host, host_vertex, is_vertex=True)) - self.assertEqual( - ENTITY_GRAPH_VMS_PER_HOST * ENTITY_GRAPH_ALARMS_PER_VM * - ENTITY_GRAPH_ALARMS_PER_HOST, - len(mappings), + self.assertThat( + mappings, + matchers.HasLength(ENTITY_GRAPH_VMS_PER_HOST * + ENTITY_GRAPH_ALARMS_PER_VM * + ENTITY_GRAPH_ALARMS_PER_HOST), 'Template - Four connected vertices' '(host alarm -ON-> host -CONTAINS-> instance <-ON- instance alarm)' ' template_root is a specific host ') @@ -428,9 +433,9 @@ class GraphAlgorithmTest(GraphTestBase): Mapping(t_v_vm_alarm, vm_alarm, is_vertex=True)) - self.assertEqual( - 0, - len(mappings), + self.assertThat( + mappings, + IsEmpty(), 'Template - Four connected vertices and a disconnected vertex' '(host alarm -ON-> host -CONTAINS-> instance <-ON- instance alarm' ',switch) template_root is a instance alarm ') @@ -440,9 +445,9 @@ class GraphAlgorithmTest(GraphTestBase): Mapping(t_v_vm_alarm, vm_alarm, is_vertex=True)) - self.assertEqual( - ENTITY_GRAPH_ALARMS_PER_HOST, - len(mappings), + self.assertThat( + mappings, + matchers.HasLength(ENTITY_GRAPH_ALARMS_PER_HOST), 'Template - Five connected vertices' '(host alarm -ON-> host -CONTAINS-> instance <-ON- instance alarm' ',host -USES-> switch) template_root ' @@ -452,10 +457,11 @@ class GraphAlgorithmTest(GraphTestBase): Mapping(t_v_host, host_vertex, is_vertex=True)) - self.assertEqual( - ENTITY_GRAPH_VMS_PER_HOST * ENTITY_GRAPH_ALARMS_PER_VM * - ENTITY_GRAPH_ALARMS_PER_HOST, - len(mappings), + self.assertThat( + mappings, + matchers.HasLength(ENTITY_GRAPH_VMS_PER_HOST * + ENTITY_GRAPH_ALARMS_PER_VM * + ENTITY_GRAPH_ALARMS_PER_HOST), 'Template - Five connected vertices' '(host alarm -ON-> host -CONTAINS-> instance <-ON- instance alarm' ',host -USES-> switch) template_root is a specific host ') @@ -464,9 +470,9 @@ class GraphAlgorithmTest(GraphTestBase): Mapping(t_v_switch, v_switch, is_vertex=True), Mapping(t_v_vm_alarm, vm_alarm, is_vertex=True)], validate=False) - self.assertEqual( - ENTITY_GRAPH_ALARMS_PER_HOST, - len(mappings), + self.assertThat( + mappings, + matchers.HasLength(ENTITY_GRAPH_ALARMS_PER_HOST), 'Template - Five connected vertices, two mappings given' '(host alarm -ON-> host -CONTAINS-> instance <-ON- instance alarm' ',host -USES-> switch) 7template_root is a specific host ') @@ -477,9 +483,9 @@ class GraphAlgorithmTest(GraphTestBase): Mapping(t_v_vm_alarm, vm_alarm, is_vertex=True)) - self.assertEqual( - 0, - len(mappings), + self.assertThat( + mappings, + IsEmpty(), 'Template - Five connected vertices and a invalid edge' '(host alarm -ON-> host -CONTAINS-> instance <-ON- instance alarm' ',host -USES-> switch) template_root is a instance alarm ') @@ -493,9 +499,9 @@ class GraphAlgorithmTest(GraphTestBase): Mapping(t_v_vm_alarm, vm_alarm, is_vertex=True)) - self.assertEqual( - 1, - len(mappings), + self.assertThat( + mappings, + matchers.HasLength(1), 'Template - FIVE connected vertices' '(host -CONTAINS-> instance <-ON- instance alarm' ',node -CONTAINS-> host -USES-> switch, node-CONTAINS->switch)' @@ -504,9 +510,9 @@ class GraphAlgorithmTest(GraphTestBase): mappings = subgraph_matching(self.entity_graph, template_graph, [ Mapping(e_node_contains_switch, e_node_to_switch, is_vertex=False), Mapping(t_v_vm_alarm, vm_alarm, is_vertex=True)]) - self.assertEqual( - 1, - len(mappings), + self.assertThat( + mappings, + matchers.HasLength(1), 'Template - FIVE connected vertices' '(host -CONTAINS-> instance <-ON- instance alarm' ',node -CONTAINS-> host -USES-> switch, node-CONTAINS->switch)' @@ -516,9 +522,9 @@ class GraphAlgorithmTest(GraphTestBase): mappings = subgraph_matching(self.entity_graph, template_graph, [ Mapping(t_v_node, v_node, is_vertex=True), Mapping(t_v_switch, v_switch, is_vertex=True)], validate=True) - self.assertEqual( - 0, - len(mappings), + self.assertThat( + mappings, + IsEmpty(), 'Template - FIVE connected vertices - 2 Known Mapping[node,switch]' ' Check that ALL edges between the 2 known mappings are checked' ' we now have node-CONTAINS fail->switch AND node-CONTAINS->switch' @@ -529,9 +535,9 @@ class GraphAlgorithmTest(GraphTestBase): e_node_to_switch, is_vertex=False), validate=True) - self.assertEqual( - 0, - len(mappings), + self.assertThat( + mappings, + IsEmpty(), 'Template - FIVE connected vertices - 2 Known Mapping[node,switch]' ' Check that ALL edges between the 2 known mappings are checked' ' we now have node-CONTAINS fail->switch AND node-CONTAINS->switch' @@ -541,9 +547,9 @@ class GraphAlgorithmTest(GraphTestBase): mappings = subgraph_matching(self.entity_graph, template_graph, [ Mapping(t_v_node, v_node, is_vertex=True), Mapping(t_v_switch, v_switch, is_vertex=True)]) - self.assertEqual( - 0, - len(mappings), + self.assertThat( + mappings, + IsEmpty(), 'Template - FIVE connected vertices - 2 Known Mapping[node,switch]' ' But the edge between these 2 is not same as the graph ' '(host -CONTAINS-> instance <-ON- instance alarm' @@ -555,9 +561,9 @@ class GraphAlgorithmTest(GraphTestBase): Mapping(t_v_vm_alarm, vm_alarm, is_vertex=True)) - self.assertEqual( - 0, - len(mappings), + self.assertThat( + mappings, + IsEmpty(), 'Template - FIVE connected vertices' '(host -CONTAINS-> instance <-ON- instance alarm' ',node -CONTAINS-> host -USES-> switch, node-CONTAINS ' @@ -610,9 +616,9 @@ class GraphAlgorithmTest(GraphTestBase): mappings = ga.sub_graph_matching(template_graph, Mapping(t_v_host, host, True), validate=True) - self.assertEqual( - 1, - len(mappings), + self.assertThat( + mappings, + matchers.HasLength(1), 'Template - Single vertex alarm not in graph ' 'Template_root is a specific host ' + str(mappings)) @@ -621,8 +627,8 @@ class GraphAlgorithmTest(GraphTestBase): template_graph.add_edge(e_host_contains_vm) mappings = ga.sub_graph_matching(template_graph, Mapping(t_v_host, host, True)) - self.assertEqual( - ENTITY_GRAPH_VMS_PER_HOST, len(mappings), + self.assertThat( + mappings, matchers.HasLength(ENTITY_GRAPH_VMS_PER_HOST), 'Template - Two connected vertices (host -> vm)' ' template_root is a specific host ' + str(mappings)) @@ -631,9 +637,9 @@ class GraphAlgorithmTest(GraphTestBase): template_graph.add_edge(e_alarm_not_on_vm) mappings = ga.sub_graph_matching(template_graph, Mapping(t_v_host, host, True)) - self.assertEqual( - 0, - len(mappings), + self.assertThat( + mappings, + IsEmpty(), 'Template - Three connected vertices (host -> vm <- NOT alarm)' ' template_root is a specific host ' + str(mappings)) @@ -658,9 +664,9 @@ class GraphAlgorithmTest(GraphTestBase): mappings = temp_ga.sub_graph_matching(template_graph, Mapping(t_v_host, host, True)) - self.assertEqual( - 1, - len(mappings), + self.assertThat( + mappings, + matchers.HasLength(1), 'Template - Three connected vertices (host -> vm <- NOT alarm)' 'Template_root is a specific host ' + str(mappings)) @@ -669,9 +675,9 @@ class GraphAlgorithmTest(GraphTestBase): template_graph.add_edge(e_alarm_not_on_host) mappings = temp_ga.sub_graph_matching(template_graph, Mapping(t_v_host, host, True)) - self.assertEqual( - 1, - len(mappings), + self.assertThat( + mappings, + matchers.HasLength(1), 'Template - Four connected vertices ' '(NOT alarm -> host -> vm <- NOT alarm)' ' template_root is a specific host alarm ' + str(mappings)) @@ -698,9 +704,9 @@ class GraphAlgorithmTest(GraphTestBase): mappings = temp_ga.sub_graph_matching(template_graph, Mapping(t_v_host, host, True)) - self.assertEqual( - 2, - len(mappings), + self.assertThat( + mappings, + matchers.HasLength(2), 'Template - Three connected vertices (host -> vm <- NOT alarm)' 'Template_root is a specific host ' + str(mappings)) @@ -719,9 +725,9 @@ class GraphAlgorithmTest(GraphTestBase): mappings = temp_ga.sub_graph_matching(template_graph, Mapping(t_v_host, host, True)) - self.assertEqual( - 3, - len(mappings), + self.assertThat( + mappings, + matchers.HasLength(3), 'Template - Three connected vertices (host -> vm <- NOT alarm)' 'Template_root is a specific host ' + str(mappings)) @@ -740,9 +746,9 @@ class GraphAlgorithmTest(GraphTestBase): Mapping(t_v_vm_alarm, deleted_vertex, True)) - self.assertEqual( - 0, - len(mappings), + self.assertThat( + mappings, + IsEmpty(), 'Template - Four connected vertices ' '(NOT alarm -> host -> vm <- NOT alarm)' ' template_root is a specific host ' + str(mappings)) @@ -763,9 +769,9 @@ class GraphAlgorithmTest(GraphTestBase): Mapping(e_alarm_not_on_vm, deleted_edge, False)) - self.assertEqual( - 0, - len(mappings), + self.assertThat( + mappings, + IsEmpty(), 'Template - Four connected vertices ' '(NOT alarm -> host -> vm <- NOT alarm)' ' template_root is a specific host ' + str(mappings)) @@ -789,9 +795,9 @@ class GraphAlgorithmTest(GraphTestBase): Mapping(e_alarm_not_on_vm, deleted_edge, False)) - self.assertEqual( - 1, - len(mappings), + self.assertThat( + mappings, + matchers.HasLength(1), 'Template - Four connected vertices ' '(NOT alarm -> host -> vm <- NOT alarm)' ' template_root is a specific host ' + str(mappings)) @@ -859,18 +865,18 @@ class GraphAlgorithmTest(GraphTestBase): mappings = temp_ga.sub_graph_matching( template_graph, Mapping(e_alarm_not_on_vm, graph_alarm_edge, False)) - self.assertEqual( - 1, - len(mappings), + self.assertThat( + mappings, + matchers.HasLength(1), 'Template - Two not connected vertices (vm <- alarm)') # find subgraphs (when edges are deleted) with event on the alarm mappings = temp_ga.sub_graph_matching( template_graph, Mapping(t_v_vm_alarm, alarms[0], True)) - self.assertEqual( - 1, - len(mappings), + self.assertThat( + mappings, + matchers.HasLength(1), 'Template - Two not connected vertices (vm <- alarm)') ################################################################### @@ -891,18 +897,18 @@ class GraphAlgorithmTest(GraphTestBase): mappings = temp_ga.sub_graph_matching( template_graph, Mapping(e_alarm_not_on_vm, graph_alarm_edge, False)) - self.assertEqual( - 1, - len(mappings), + self.assertThat( + mappings, + matchers.HasLength(1), 'Template - Two not connected vertices (vm <- alarm)') # find subgraphs (when vertices are deleted) with event on the alarm mappings = temp_ga.sub_graph_matching( template_graph, Mapping(t_v_vm_alarm, alarms[0], True)) - self.assertEqual( - 0, - len(mappings), + self.assertThat( + mappings, + IsEmpty(), 'Template - Two not connected vertices (vm <- alarm)') ################################################################### @@ -928,9 +934,9 @@ class GraphAlgorithmTest(GraphTestBase): template_graph, Mapping(e_alarm_not_on_vm, graph_alarm_edge, False)) - self.assertEqual( - 1, - len(mappings), + self.assertThat( + mappings, + matchers.HasLength(1), 'Template - Two not connected vertices (vm <- alarm)') # find subgraphs (when vertices and edges are deleted) with event @@ -939,9 +945,9 @@ class GraphAlgorithmTest(GraphTestBase): template_graph, Mapping(t_v_vm_alarm, alarms[0], True)) - self.assertEqual( - 1, - len(mappings), + self.assertThat( + mappings, + matchers.HasLength(1), 'Template - Two not connected vertices (vm <- alarm)') ################################################################### @@ -961,9 +967,9 @@ class GraphAlgorithmTest(GraphTestBase): mappings = temp_ga.sub_graph_matching( template_graph, Mapping(e_alarm_not_on_vm, graph_alarm_edge, False)) - self.assertEqual( - 0, - len(mappings), + self.assertThat( + mappings, + IsEmpty(), 'Template - Two not connected vertices (vm <- alarm)') # find subgraphs (when one alarm of many is deleted) with event @@ -971,9 +977,9 @@ class GraphAlgorithmTest(GraphTestBase): mappings = temp_ga.sub_graph_matching( template_graph, Mapping(t_v_vm_alarm, alarms[0], True)) - self.assertEqual( - 0, - len(mappings), + self.assertThat( + mappings, + IsEmpty(), 'Template - Two not connected vertices (vm <- alarm)') ################################################################### @@ -994,9 +1000,9 @@ class GraphAlgorithmTest(GraphTestBase): template_graph, Mapping(e_alarm_not_on_vm, graph_alarm_edge, False)) - self.assertEqual( - 0, - len(mappings), + self.assertThat( + mappings, + IsEmpty(), 'Template - Two not connected vertices (vm <- alarm)') ################################################################### @@ -1019,9 +1025,9 @@ class GraphAlgorithmTest(GraphTestBase): template_graph, Mapping(e_alarm_not_on_vm, graph_alarm_edge, False)) - self.assertEqual( - 0, - len(mappings), + self.assertThat( + mappings, + IsEmpty(), 'Template - Two not connected vertices (vm <- alarm)') def test_template_matching_with_not_operator_of_problematic_subgraph(self): @@ -1127,18 +1133,18 @@ class GraphAlgorithmTest(GraphTestBase): mappings = temp_ga.sub_graph_matching( template_graph, Mapping(e_alarm_not_on_vm, graph_alarm_edge, False)) - self.assertEqual( - 0, - len(mappings), + self.assertThat( + mappings, + IsEmpty(), 'Template - Two not connected vertices (vm <- alarm)') # trigger on alarm mappings = temp_ga.sub_graph_matching( template_graph, Mapping(t_v_alarm, specific_alarm, True)) - self.assertEqual( - 0, - len(mappings), + self.assertThat( + mappings, + IsEmpty(), 'Template - Two not connected vertices (vm <- alarm)') ################################################################### @@ -1174,18 +1180,18 @@ class GraphAlgorithmTest(GraphTestBase): mappings = temp_ga.sub_graph_matching( template_graph, Mapping(e_alarm_not_on_vm, graph_alarm_edge, False)) - self.assertEqual( - 1, - len(mappings), + self.assertThat( + mappings, + matchers.HasLength(1), 'Template - Two not connected vertices (vm <- alarm)') # trigger on alarm mappings = temp_ga.sub_graph_matching( template_graph, Mapping(t_v_alarm, specific_alarm, True)) - self.assertEqual( - 1, - len(mappings), + self.assertThat( + mappings, + matchers.HasLength(1), 'Template - Two not connected vertices (vm <- alarm)') ################################################################### @@ -1219,18 +1225,18 @@ class GraphAlgorithmTest(GraphTestBase): mappings = temp_ga.sub_graph_matching( template_graph, Mapping(e_alarm_not_on_vm, graph_alarm_edge, False)) - self.assertEqual( - 1, - len(mappings), + self.assertThat( + mappings, + matchers.HasLength(1), 'Template - Two not connected vertices (vm <- alarm)') # trigger on alarm mappings = temp_ga.sub_graph_matching( template_graph, Mapping(t_v_alarm, specific_alarm, True)) - self.assertEqual( - 1, - len(mappings), + self.assertThat( + mappings, + matchers.HasLength(1), 'Template - Two not connected vertices (vm <- alarm)') ################################################################### @@ -1265,9 +1271,9 @@ class GraphAlgorithmTest(GraphTestBase): mappings = temp_ga.sub_graph_matching( template_graph, Mapping(e_alarm_not_on_vm, graph_alarm_edge, False)) - self.assertEqual( - 0, - len(mappings), + self.assertThat( + mappings, + IsEmpty(), 'Template - Two not connected vertices (vm <- alarm)') # trigger on edge (that wasn't deleted) between vm and alarm @@ -1281,27 +1287,27 @@ class GraphAlgorithmTest(GraphTestBase): mappings = temp_ga.sub_graph_matching( template_graph, Mapping(e_alarm_not_on_vm, graph_alarm_edge, False)) - self.assertEqual( - 0, - len(mappings), + self.assertThat( + mappings, + IsEmpty(), 'Template - Two not connected vertices (vm <- alarm)') # trigger on alarm mappings = temp_ga.sub_graph_matching( template_graph, Mapping(t_v_alarm, specific_alarm, True)) - self.assertEqual( - 0, - len(mappings), + self.assertThat( + mappings, + IsEmpty(), 'Template - Two not connected vertices (vm <- alarm)') # trigger on instance mappings = temp_ga.sub_graph_matching( template_graph, Mapping(t_v_vm, vms[3], True)) - self.assertEqual( - 0, - len(mappings), + self.assertThat( + mappings, + IsEmpty(), 'Template - Two not connected vertices (vm <- alarm)') ################################################################### @@ -1335,9 +1341,9 @@ class GraphAlgorithmTest(GraphTestBase): mappings = temp_ga.sub_graph_matching( template_graph, Mapping(e_alarm_not_on_vm, graph_alarm_edge, False)) - self.assertEqual( - 0, - len(mappings), + self.assertThat( + mappings, + IsEmpty(), 'Template - Two not connected vertices (vm <- alarm)') # trigger on edge (that wasn't deleted) between vm and alarm @@ -1351,27 +1357,27 @@ class GraphAlgorithmTest(GraphTestBase): mappings = temp_ga.sub_graph_matching( template_graph, Mapping(e_alarm_not_on_vm, graph_alarm_edge, False)) - self.assertEqual( - 0, - len(mappings), + self.assertThat( + mappings, + IsEmpty(), 'Template - Two not connected vertices (vm <- alarm)') # trigger on alarm mappings = temp_ga.sub_graph_matching( template_graph, Mapping(t_v_alarm, specific_alarm, True)) - self.assertEqual( - 0, - len(mappings), + self.assertThat( + mappings, + IsEmpty(), 'Template - Two not connected vertices (vm <- alarm)') # trigger on instance mappings = temp_ga.sub_graph_matching( template_graph, Mapping(t_v_vm, vms[4], True)) - self.assertEqual( - 0, - len(mappings), + self.assertThat( + mappings, + IsEmpty(), 'Template - Two not connected vertices (vm <- alarm)') @staticmethod diff --git a/vitrage/tests/unit/hacking/test_hacking.py b/vitrage/tests/unit/hacking/test_hacking.py index 575821364..5149564a2 100644 --- a/vitrage/tests/unit/hacking/test_hacking.py +++ b/vitrage/tests/unit/hacking/test_hacking.py @@ -15,137 +15,153 @@ import inspect +from testtools import matchers + from vitrage.hacking import checks from vitrage.tests import base +from vitrage.tests.base import IsEmpty class HackingTestCase(base.BaseTest): def test_assert_true_instance(self): - self.assertEqual(1, len(list(checks.assert_true_instance( + self.assertThat(list(checks.assert_true_instance( "self.assertTrue(isinstance(e, " - "exception.BuildAbortException))")))) + "exception.BuildAbortException))")), matchers.HasLength(1)) - self.assertEqual( - 0, len(list(checks.assert_true_instance("self.assertTrue()")))) + self.assertThat(list(checks.assert_true_instance("self.assertTrue(" + ")")), IsEmpty()) def test_assert_equal_type(self): - self.assertEqual(1, len(list(checks.assert_equal_type( - "self.assertEqual(type(als['QuicAssist']), list)")))) + self.assertThat(list(checks.assert_equal_type( + "self.assertEqual(type(als['QuicAssist']), list)")), + matchers.HasLength(1)) - self.assertEqual( - 0, len(list(checks.assert_equal_type("self.assertTrue()")))) + self.assertThat(list(checks.assert_equal_type("self.assertTrue()")), + IsEmpty()) def test_no_translate_logs(self): for log in checks._all_log_levels: bad = 'LOG.%s(_("Bad"))' % log - self.assertEqual(1, len(list(checks.no_translate_logs(bad)))) + self.assertThat(list(checks.no_translate_logs(bad)), + matchers.HasLength(1)) # Catch abuses when used with a variable and not a literal bad = 'LOG.%s(_(msg))' % log - self.assertEqual(1, len(list(checks.no_translate_logs(bad)))) + self.assertThat(list(checks.no_translate_logs(bad)), + matchers.HasLength(1)) def test_no_direct_use_of_unicode_function(self): - self.assertEqual(1, len(list(checks.no_direct_use_of_unicode_function( - "unicode('the party don't start til the unicode walks in')")))) - self.assertEqual(1, len(list(checks.no_direct_use_of_unicode_function( + self.assertThat(list(checks.no_direct_use_of_unicode_function( + "unicode('the party don't start til the unicode walks in')")), + matchers.HasLength(1)) + self.assertThat(list(checks.no_direct_use_of_unicode_function( """unicode('something ' - 'something else""")))) - self.assertEqual(0, len(list(checks.no_direct_use_of_unicode_function( - "six.text_type('party over')")))) - self.assertEqual(0, len(list(checks.no_direct_use_of_unicode_function( - "not_actually_unicode('something completely different')")))) + 'something else""")), matchers.HasLength(1)) + self.assertThat(list(checks.no_direct_use_of_unicode_function( + "six.text_type('party over')")), IsEmpty()) + self.assertThat(list(checks.no_direct_use_of_unicode_function( + "not_actually_unicode('something completely different')")), + IsEmpty()) def test_no_contextlib_nested(self): - self.assertEqual(1, len(list(checks.check_no_contextlib_nested( - "with contextlib.nested(")))) + self.assertThat(list(checks.check_no_contextlib_nested( + "with contextlib.nested(")), matchers.HasLength(1)) - self.assertEqual(1, len(list(checks.check_no_contextlib_nested( - "with nested(")))) + self.assertThat(list(checks.check_no_contextlib_nested( + "with nested(")), matchers.HasLength(1)) - self.assertEqual(0, len(list(checks.check_no_contextlib_nested( - "with foo as bar")))) + self.assertThat(list(checks.check_no_contextlib_nested( + "with foo as bar")), IsEmpty()) def test_dict_constructor_with_list_copy(self): - self.assertEqual(1, len(list(checks.dict_constructor_with_list_copy( - " dict([(i, connect_info[i])")))) + self.assertThat(list(checks.dict_constructor_with_list_copy( + " dict([(i, connect_info[i])")), matchers.HasLength(1)) - self.assertEqual(1, len(list(checks.dict_constructor_with_list_copy( - " attrs = dict([(k, _from_json(v))")))) + self.assertThat(list(checks.dict_constructor_with_list_copy( + " attrs = dict([(k, _from_json(v))")), matchers.HasLength(1)) - self.assertEqual(1, len(list(checks.dict_constructor_with_list_copy( - " type_names = dict((value, key) for key, value in")))) + self.assertThat(list(checks.dict_constructor_with_list_copy( + " type_names = dict((value, key) for key, value in")), + matchers.HasLength(1)) - self.assertEqual(1, len(list(checks.dict_constructor_with_list_copy( - " dict((value, key) for key, value in")))) + self.assertThat(list(checks.dict_constructor_with_list_copy( + " dict((value, key) for key, value in")), matchers.HasLength(1)) - self.assertEqual(1, len(list(checks.dict_constructor_with_list_copy( - "foo(param=dict((k, v) for k, v in bar.items()))")))) + self.assertThat(list(checks.dict_constructor_with_list_copy( + "foo(param=dict((k, v) for k, v in bar.items()))")), + matchers.HasLength(1)) - self.assertEqual(1, len(list(checks.dict_constructor_with_list_copy( - " dict([[i,i] for i in range(3)])")))) + self.assertThat(list(checks.dict_constructor_with_list_copy( + " dict([[i,i] for i in range(3)])")), matchers.HasLength(1)) - self.assertEqual(1, len(list(checks.dict_constructor_with_list_copy( - " dd = dict([i,i] for i in range(3))")))) + self.assertThat(list(checks.dict_constructor_with_list_copy( + " dd = dict([i,i] for i in range(3))")), matchers.HasLength(1)) - self.assertEqual(0, len(list(checks.dict_constructor_with_list_copy( - " create_kwargs = dict(snapshot=snapshot,")))) + self.assertThat(list(checks.dict_constructor_with_list_copy( + " create_kwargs = dict(snapshot=snapshot,")), IsEmpty()) - self.assertEqual(0, len(list(checks.dict_constructor_with_list_copy( - " self._render_dict(xml, data_el, data.__dict__)")))) + self.assertThat(list(checks.dict_constructor_with_list_copy( + " self._render_dict(xml, data_el, data.__dict__)")), + IsEmpty()) def test_check_python3_xrange(self): func = checks.check_python3_xrange - self.assertEqual(1, len(list(func('for i in xrange(10)')))) - self.assertEqual(1, len(list(func('for i in xrange (10)')))) - self.assertEqual(0, len(list(func('for i in range(10)')))) - self.assertEqual(0, len(list(func('for i in six.moves.range(10)')))) - self.assertEqual(0, len(list(func('testxrange(10)')))) + self.assertThat(list(func('for i in xrange(10)')), + matchers.HasLength(1)) + self.assertThat(list(func('for i in xrange (10)')), + matchers.HasLength(1)) + self.assertThat(list(func('for i in range(10)')), IsEmpty()) + self.assertThat(list(func('for i in six.moves.range(10)')), IsEmpty()) + self.assertThat(list(func('testxrange(10)')), IsEmpty()) def test_dict_iteritems(self): - self.assertEqual(1, len(list(checks.check_python3_no_iteritems( - "obj.iteritems()")))) + self.assertThat(list(checks.check_python3_no_iteritems( + "obj.iteritems()")), matchers.HasLength(1)) - self.assertEqual(0, len(list(checks.check_python3_no_iteritems( - "six.iteritems(obj)")))) + self.assertThat(list(checks.check_python3_no_iteritems( + "six.iteritems(obj)")), IsEmpty()) - self.assertEqual(0, len(list(checks.check_python3_no_iteritems( - "obj.items()")))) + self.assertThat(list(checks.check_python3_no_iteritems( + "obj.items()")), IsEmpty()) def test_dict_iterkeys(self): - self.assertEqual(1, len(list(checks.check_python3_no_iterkeys( - "obj.iterkeys()")))) + self.assertThat(list(checks.check_python3_no_iterkeys( + "obj.iterkeys()")), matchers.HasLength(1)) - self.assertEqual(0, len(list(checks.check_python3_no_iterkeys( - "six.iterkeys(obj)")))) + self.assertThat(list(checks.check_python3_no_iterkeys( + "six.iterkeys(obj)")), IsEmpty()) - self.assertEqual(0, len(list(checks.check_python3_no_iterkeys( - "obj.keys()")))) + self.assertThat(list(checks.check_python3_no_iterkeys( + "obj.keys()")), IsEmpty()) def test_dict_itervalues(self): - self.assertEqual(1, len(list(checks.check_python3_no_itervalues( - "obj.itervalues()")))) + self.assertThat(list(checks.check_python3_no_itervalues( + "obj.itervalues()")), matchers.HasLength(1)) - self.assertEqual(0, len(list(checks.check_python3_no_itervalues( - "six.itervalues(ob)")))) + self.assertThat(list(checks.check_python3_no_itervalues( + "six.itervalues(ob)")), IsEmpty()) - self.assertEqual(0, len(list(checks.check_python3_no_itervalues( - "obj.values()")))) + self.assertThat(list(checks.check_python3_no_itervalues( + "obj.values()")), IsEmpty()) def test_no_mutable_default_args(self): - self.assertEqual(1, len(list(checks.no_mutable_default_args( - " def fake_suds_context(calls={}):")))) + self.assertThat(list(checks.no_mutable_default_args( + " def fake_suds_context(calls={}):")), matchers.HasLength(1)) - self.assertEqual(1, len(list(checks.no_mutable_default_args( - "def get_info_from_bdm(virt_type, bdm, mapping=[])")))) + self.assertThat(list(checks.no_mutable_default_args( + "def get_info_from_bdm(virt_type, bdm, mapping=[])")), + matchers.HasLength(1)) - self.assertEqual(0, len(list(checks.no_mutable_default_args( - "defined = []")))) + self.assertThat(list(checks.no_mutable_default_args( + "defined = []")), IsEmpty()) - self.assertEqual(0, len(list(checks.no_mutable_default_args( - "defined, undefined = [], {}")))) + self.assertThat(list(checks.no_mutable_default_args( + "defined, undefined = [], {}")), IsEmpty()) def test_no_log_warn(self): - self.assertEqual(0, len(list(checks.no_log_warn('LOG.warning("bl")')))) - self.assertEqual(1, len(list(checks.no_log_warn('LOG.warn("foo")')))) + self.assertThat(list(checks.no_log_warn('LOG.warning("bl")')), + IsEmpty()) + self.assertThat(list(checks.no_log_warn('LOG.warn("foo")')), + matchers.HasLength(1)) def test_asserttruefalse(self): true_fail_code1 = """ @@ -172,16 +188,16 @@ class HackingTestCase(base.BaseTest): test_bool = False self.assertFalse(test_bool) """ - self.assertEqual(1, len( - list(checks.check_assert_true_false(true_fail_code1)))) - self.assertEqual(1, len( - list(checks.check_assert_true_false(true_fail_code2)))) - self.assertEqual(0, len( - list(checks.check_assert_true_false(true_pass_code)))) - self.assertEqual(1, len( - list(checks.check_assert_true_false(false_fail_code1)))) - self.assertEqual(1, len( - list(checks.check_assert_true_false(false_fail_code2)))) + self.assertThat(list(checks.check_assert_true_false( + true_fail_code1)), matchers.HasLength(1)) + self.assertThat(list(checks.check_assert_true_false( + true_fail_code2)), matchers.HasLength(1)) + self.assertThat(list(checks.check_assert_true_false( + true_pass_code)), IsEmpty()) + self.assertThat(list(checks.check_assert_true_false( + false_fail_code1)), matchers.HasLength(1)) + self.assertThat(list(checks.check_assert_true_false( + false_fail_code2)), matchers.HasLength(1)) self.assertFalse(list(checks.check_assert_true_false(false_pass_code))) def test_factory(self): diff --git a/vitrage/tests/unit/machine_learning/jaccard_correlation/test_jaccard_correlation.py b/vitrage/tests/unit/machine_learning/jaccard_correlation/test_jaccard_correlation.py index 3379949ff..5ccc7b443 100644 --- a/vitrage/tests/unit/machine_learning/jaccard_correlation/test_jaccard_correlation.py +++ b/vitrage/tests/unit/machine_learning/jaccard_correlation/test_jaccard_correlation.py @@ -17,6 +17,8 @@ import os.path from oslo_config import cfg import time +from testtools import matchers + from vitrage.common.constants import EntityCategory from vitrage.common.constants import VertexProperties as VProps from vitrage.datasources.aodh import AODH_DATASOURCE @@ -240,14 +242,14 @@ class JaccardCorrelationTest(base.BaseTest): self.data_manager.active_start_times) expected_activity_dict_len = len(ACTIVE_ALARMS) - self.assertEqual(expected_activity_dict_len, - len(self.data_manager.alarms_activity)) + self.assertThat(self.data_manager.alarms_activity, + matchers.HasLength(expected_activity_dict_len)) # choose 2 expected_intersections_dict_len = \ (len(ACTIVE_ALARMS) * (len(ACTIVE_ALARMS) - 1)) / 2 - self.assertEqual(expected_intersections_dict_len, - len(self.data_manager.alarms_intersects)) + self.assertThat(self.data_manager.alarms_intersects, + matchers.HasLength(expected_intersections_dict_len)) def _test_append_inactive(self): deleted_alarm_ids = [] diff --git a/vitrage/tests/unit/notifier/snmp_notifier/test_snmp_sender_with_severity_map.py b/vitrage/tests/unit/notifier/snmp_notifier/test_snmp_sender_with_severity_map.py index 024220afe..eafc3a1b9 100644 --- a/vitrage/tests/unit/notifier/snmp_notifier/test_snmp_sender_with_severity_map.py +++ b/vitrage/tests/unit/notifier/snmp_notifier/test_snmp_sender_with_severity_map.py @@ -14,6 +14,7 @@ from oslo_config import cfg from pysnmp.proto.rfc1902 import OctetString +from testtools import matchers from vitrage.common.constants import VertexProperties as VProps import vitrage.notifier.plugins.snmp.snmp_sender as sender @@ -58,8 +59,8 @@ class SnmpNotifierTest(base.BaseTest): oids, var_lst = self.snmp_sender._build_oids() - self.assertEqual(4, len(oids)) - self.assertEqual(3, len(var_lst)) + self.assertThat(oids, matchers.HasLength(4)) + self.assertThat(var_lst, matchers.HasLength(3)) self.assertIn(VProps.NAME, oids) self.assertIn(VProps.VITRAGE_IS_DELETED, oids) @@ -78,7 +79,7 @@ class SnmpNotifierTest(base.BaseTest): var_binds = self.snmp_sender._get_var_binds(common.alarm_data) - self.assertEqual(3, len(var_binds)) + self.assertThat(var_binds, matchers.HasLength(3)) self.assertIn((oid_with_alarm_objects + '.' + common.NAME_OID, OctetString(common.alarm_data.get(VProps.NAME, diff --git a/vitrage/tests/unit/notifier/snmp_notifier/test_snmp_sender_without_severity_map.py b/vitrage/tests/unit/notifier/snmp_notifier/test_snmp_sender_without_severity_map.py index 5f65dac85..2e473487a 100644 --- a/vitrage/tests/unit/notifier/snmp_notifier/test_snmp_sender_without_severity_map.py +++ b/vitrage/tests/unit/notifier/snmp_notifier/test_snmp_sender_without_severity_map.py @@ -13,6 +13,7 @@ # under the License. from oslo_config import cfg +from testtools import matchers from vitrage.common.constants import VertexProperties as VProps import vitrage.notifier.plugins.snmp.snmp_sender as sender @@ -57,8 +58,8 @@ class SnmpNotifierTest(base.BaseTest): oids, var_lst = self.snmp_sender._build_oids() - self.assertEqual(4, len(oids)) - self.assertEqual(3, len(var_lst)) + self.assertThat(oids, matchers.HasLength(4)) + self.assertThat(var_lst, matchers.HasLength(3)) self.assertIn(VProps.NAME, oids) self.assertIn(VProps.VITRAGE_IS_DELETED, oids)