Merge "make test more readable"

This commit is contained in:
Zuul 2018-03-08 06:21:59 +00:00 committed by Gerrit Code Review
commit 77915aeb26
14 changed files with 151 additions and 127 deletions

View File

@ -15,9 +15,11 @@
import json
from oslo_log import log as logging
from testtools import matchers
from vitrage.datasources.aodh import AODH_DATASOURCE
from vitrage_tempest_plugin.tests.api.alarms.base import BaseAlarmsTest
from vitrage_tempest_plugin.tests.base import IsNotEmpty
from vitrage_tempest_plugin.tests.common import aodh_utils
from vitrage_tempest_plugin.tests.common import general_utils as g_utils
from vitrage_tempest_plugin.tests.common import nova_utils
@ -56,7 +58,7 @@ class TestAlarms(BaseAlarmsTest):
try:
instances = nova_utils.create_instances(num_instances=1,
set_public_network=True)
self.assertNotEqual(len(instances), 0,
self.assertThat(instances, IsNotEmpty(),
'The instances list is empty')
aodh_utils.create_aodh_alarm(
resource_id=instances[0].id,
@ -79,9 +81,9 @@ class TestAlarms(BaseAlarmsTest):
def _compare_alarms_lists(self, api_alarms, cli_alarms,
resource_type, resource_id):
"""Validate alarm existence """
self.assertNotEqual(len(api_alarms), 0,
self.assertThat(api_alarms, IsNotEmpty(),
'The alarms list taken from api is empty')
self.assertIsNotNone(cli_alarms,
self.assertThat(cli_alarms, IsNotEmpty(),
'The alarms list taken from cli is empty')
LOG.info("The alarms list taken from cli is : " +
@ -99,5 +101,5 @@ class TestAlarms(BaseAlarmsTest):
cli_by_id = cli_alarms.count(resource_id)
self.assertEqual(len(cli_items), len(api_alarms) + 4)
self.assertEqual(cli_by_type, len(api_by_type))
self.assertEqual(cli_by_id, len(api_by_id))
self.assertThat(api_by_type, matchers.HasLength(cli_by_type))
self.assertThat(api_by_id, matchers.HasLength(cli_by_id))

View File

@ -16,15 +16,16 @@ import six
from datetime import datetime
from oslo_log import log as logging
from testtools import matchers
from vitrage.common.constants import EntityCategory
from vitrage.common.constants import EventProperties as EventProps
from vitrage.common.constants import VertexProperties as VProps
from vitrage_tempest_plugin.tests.api.event.base import BaseTestEvents
from vitrage_tempest_plugin.tests.base import IsEmpty
from vitrage_tempest_plugin.tests.common.vitrage_utils import DOWN
from vitrage_tempest_plugin.tests.utils import wait_for_answer
LOG = logging.getLogger(__name__)
@ -51,8 +52,8 @@ class TestEvents(BaseTestEvents):
api_alarms = wait_for_answer(2, 0.5, self._check_alarms)
# expect to get a 'host down alarm', generated by Doctor datasource
self.assertIsNotNone(api_alarms, 'Expected host down alarm')
self.assertEqual(1, len(api_alarms), 'Expected host down alarm')
self.assertThat(api_alarms, matchers.HasLength(1),
'Expected host down alarm')
alarm = api_alarms[0]
event_time_tz = six.u(event_time.strftime('%Y-%m-%dT%H:%M:%SZ'))
@ -65,7 +66,7 @@ class TestEvents(BaseTestEvents):
api_alarms = wait_for_answer(2, 0.5, self._check_alarms)
self.assertIsNotNone(api_alarms, 'Expected host down alarm')
self.assertEqual(0, len(api_alarms), 'Expected host down alarm')
self.assertThat(api_alarms, IsEmpty(), 'Expected host down alarm')
except Exception as e:
LOG.exception(e)

View File

@ -15,6 +15,7 @@
import json
from oslo_log import log as logging
from testtools import matchers
from vitrage.common.constants import EdgeLabel
from vitrage.common.constants import EdgeProperties
@ -29,6 +30,7 @@ from vitrage.entity_graph.mappings.operational_resource_state \
from vitrage.evaluator.actions.evaluator_event_transformer \
import VITRAGE_DATASOURCE
from vitrage_tempest_plugin.tests.api.alarms.base import BaseAlarmsTest
from vitrage_tempest_plugin.tests.base import IsNotEmpty
from vitrage_tempest_plugin.tests.common import aodh_utils
from vitrage_tempest_plugin.tests.common import general_utils as g_utils
from vitrage_tempest_plugin.tests.common import nova_utils
@ -72,7 +74,8 @@ class BaseRcaTest(BaseAlarmsTest):
return expected_alarm[0]
def _compare_rca(self, api_rca, cli_rca):
self.assertNotEqual(len(api_rca), 0, 'The rca taken from api is empty')
self.assertThat(api_rca, IsNotEmpty(),
'The rca taken from api is empty')
self.assertIsNotNone(cli_rca, 'The rca taken from cli is empty')
LOG.info("The rca taken from cli is : " + str(cli_rca))
@ -84,7 +87,7 @@ class BaseRcaTest(BaseAlarmsTest):
self.assertEqual(sorted_cli_graph, sorted_api_graph)
def _validate_rca(self, rca):
self.assertNotEqual(len(rca), 0, 'The rca is empty')
self.assertThat(rca, IsNotEmpty, 'The rca is empty')
LOG.info("The rca alarms list is : " + str(json.dumps(rca)))
resource_alarm = g_utils.all_matches(
@ -98,13 +101,13 @@ class BaseRcaTest(BaseAlarmsTest):
name=VITRAGE_ALARM_NAME,
severity=OperationalAlarmSeverity.WARNING)
self.assertEqual(3, len(rca))
self.assertEqual(1, len(resource_alarm))
self.assertEqual(2, len(deduce_alarms))
self.assertThat(rca, matchers.HasLength(3))
self.assertThat(resource_alarm, matchers.HasLength(1))
self.assertThat(deduce_alarms, matchers.HasLength(2))
def _validate_deduce_alarms(self, alarms, instances):
"""Validate alarm existence """
self.assertNotEqual(len(alarms), 0, 'The alarms list is empty')
self.assertThat(alarms, IsNotEmpty(), 'The alarms list is empty')
LOG.info("The alarms list is : " + str(json.dumps(alarms)))
# Find the vitrage_id of the deduced alarms using their original id.
@ -131,14 +134,16 @@ class BaseRcaTest(BaseAlarmsTest):
vitrage_resource_type=NOVA_INSTANCE_DATASOURCE,
vitrage_resource_id=vitrage_instance_1_id[VProps.VITRAGE_ID])
self.assertEqual(3, len(alarms), "Expected 3 alarms - 1 on host and "
"2 deduced")
self.assertEqual(1, len(deduce_alarms_1), "Deduced alarm not found")
self.assertEqual(1, len(deduce_alarms_2), "Deduced alarm not found")
self.assertThat(alarms, matchers.HasLength(3),
"Expected 3 alarms - 1 on host and 2 deduced")
self.assertThat(deduce_alarms_1, matchers.HasLength(1),
"Deduced alarm not found")
self.assertThat(deduce_alarms_2, matchers.HasLength(1),
"Deduced alarm not found")
def _validate_relationship(self, links, alarms):
self.assertNotEqual(len(links), 0, 'The links list is empty')
self.assertNotEqual(len(alarms), 0, 'The alarms list is empty')
self.assertThat(links, IsNotEmpty(), 'The links list is empty')
self.assertThat(alarms, IsNotEmpty(), 'The alarms list is empty')
flag = True
for item in links:
@ -150,11 +155,11 @@ class BaseRcaTest(BaseAlarmsTest):
or target_alarm_name != VITRAGE_ALARM_NAME:
flag = False
self.assertEqual(3, len(alarms))
self.assertThat(alarms, matchers.HasLength(3))
self.assertTrue(flag)
def _validate_set_state(self, topology, instances):
self.assertNotEqual(len(topology), 0, 'The topology graph is empty')
self.assertThat(topology, IsNotEmpty(), 'The topology graph is empty')
host = g_utils.all_matches(
topology,
vitrage_type=NOVA_HOST_DATASOURCE,
@ -176,13 +181,13 @@ class BaseRcaTest(BaseAlarmsTest):
vitrage_state=OperationalResourceState.SUBOPTIMAL,
vitrage_aggregated_state=OperationalResourceState.SUBOPTIMAL)
self.assertEqual(1, len(host))
self.assertEqual(1, len(vm1))
self.assertEqual(1, len(vm2))
self.assertThat(host, matchers.HasLength(1))
self.assertThat(vm1, matchers.HasLength(1))
self.assertThat(vm2, matchers.HasLength(1))
def _validate_notifier(self, alarms, vitrage_alarms):
self.assertNotEqual(len(alarms), 0, 'The aodh alarms list is empty')
self.assertNotEqual(len(vitrage_alarms), 0,
self.assertThat(alarms, IsNotEmpty(), 'The aodh alarms list is empty')
self.assertThat(vitrage_alarms, IsNotEmpty(),
'The vitrage alarms list is empty')
validation = 0
@ -199,8 +204,8 @@ class BaseRcaTest(BaseAlarmsTest):
validation += 1
break
self.assertEqual(validation, len(vitrage_alarms))
self.assertEqual(3, len(alarms))
self.assertThat(vitrage_alarms, matchers.HasLength(validation))
self.assertThat(alarms, matchers.HasLength(3))
def _get_hostname(self):
host = vitrage_utils.get_first_host()

View File

@ -17,6 +17,7 @@ from oslo_log import log as logging
from vitrage.common.constants import VertexProperties as VProps
from vitrage_tempest_plugin.tests.api.rca.base import BaseRcaTest
from vitrage_tempest_plugin.tests.api.rca.base import RCA_ALARM_NAME
from vitrage_tempest_plugin.tests.base import IsNotEmpty
from vitrage_tempest_plugin.tests.common import nova_utils
from vitrage_tempest_plugin.tests.common.tempest_clients import TempestClients
from vitrage_tempest_plugin.tests.common import vitrage_utils as v_utils
@ -57,7 +58,8 @@ class TestRca(BaseRcaTest):
try:
instances = nova_utils.create_instances(num_instances=1,
set_public_network=True)
self.assertNotEqual(len(instances), 0, 'Failed to create instance')
self.assertThat(instances, IsNotEmpty(),
'Failed to create instance')
instance_alarm = self._create_alarm(
resource_id=instances[0].id,

View File

@ -15,13 +15,15 @@
import json
from oslo_log import log as logging
from testtools import matchers
import unittest
from vitrage.common.constants import VertexProperties as VProps
from vitrage.datasources import CINDER_VOLUME_DATASOURCE
from vitrage.datasources import NOVA_INSTANCE_DATASOURCE
from vitrage_tempest_plugin.tests.base import BaseVitrageTempest
from vitrage_tempest_plugin.tests.base import IsEmpty
from vitrage_tempest_plugin.tests.base import IsNotEmpty
from vitrage_tempest_plugin.tests.common import nova_utils
from vitrage_tempest_plugin.tests import utils
from vitrageclient.exceptions import ClientException
@ -54,7 +56,7 @@ class TestResource(BaseVitrageTempest):
try:
instances = nova_utils.create_instances(num_instances=1,
set_public_network=True)
self.assertNotEqual(len(instances), 0,
self.assertThat(instances, IsNotEmpty(),
'The instances list is empty')
api_resources = self.vitrage_client.resource.list(
all_tenants=True)
@ -80,10 +82,10 @@ class TestResource(BaseVitrageTempest):
try:
instances = nova_utils.create_instances(num_instances=1,
set_public_network=True)
self.assertNotEqual(len(instances), 0,
self.assertThat(instances, IsNotEmpty(),
'The instances list is empty')
resources = self.vitrage_client.resource.list(all_tenants=False)
self.assertEqual(3, len(resources))
self.assertThat(resources, matchers.HasLength(3))
except Exception as e:
self._handle_exception(e)
raise
@ -102,7 +104,7 @@ class TestResource(BaseVitrageTempest):
all_tenants=True)
instances = nova_utils.create_instances(num_instances=1,
set_public_network=True)
self.assertNotEqual(len(instances), 0,
self.assertThat(instances, IsNotEmpty(),
'The instances list is empty')
resources = self.vitrage_client.resource.list(all_tenants=True)
@ -122,12 +124,12 @@ class TestResource(BaseVitrageTempest):
try:
instances = nova_utils.create_instances(num_instances=1,
set_public_network=True)
self.assertNotEqual(len(instances), 0,
self.assertThat(instances, IsNotEmpty(),
'The instances list is empty')
resources = self.vitrage_client.resource.list(
resource_type=NOVA_INSTANCE_DATASOURCE,
all_tenants=True)
self.assertEqual(1, len(resources))
self.assertThat(resources, matchers.HasLength(1))
except Exception as e:
self._handle_exception(e)
raise
@ -140,12 +142,12 @@ class TestResource(BaseVitrageTempest):
try:
instances = nova_utils.create_instances(num_instances=1,
set_public_network=True)
self.assertNotEqual(len(instances), 0,
self.assertThat(instances, IsNotEmpty(),
'The instances list is empty')
resources = self.vitrage_client.resource.list(
resource_type=CINDER_VOLUME_DATASOURCE,
all_tenants=True)
self.assertEqual(0, len(resources))
self.assertThat(resources, IsEmpty())
except Exception as e:
self._handle_exception(e)
raise
@ -156,7 +158,7 @@ class TestResource(BaseVitrageTempest):
def test_compare_resource_show(self):
"""resource_show test"""
resource_list = self.vitrage_client.resource.list(all_tenants=False)
self.assertNotEqual(len(resource_list), 0)
self.self.assertThat(resource_list, IsNotEmpty())
for resource in resource_list:
api_resource_show = \
self.vitrage_client.resource.get(resource[VProps.VITRAGE_ID])
@ -181,10 +183,10 @@ class TestResource(BaseVitrageTempest):
nova_utils.delete_all_instances()
def _compare_resources(self, api_resources, cli_resources):
self.assertNotEqual(len(api_resources), 0,
self.assertThat(api_resources, IsNotEmpty(),
'The resources taken from rest api is empty')
self.assertThat(cli_resources, IsNotEmpty(),
'The resources taken from rest api is empty')
self.assertNotEqual(len(cli_resources), 0,
'The resources taken from terminal is empty')
sorted_cli_resources = sorted(
json.loads(cli_resources),

View File

@ -14,9 +14,11 @@
import json
from oslo_log import log as logging
from testtools import matchers
from vitrage.common.exception import VitrageError
from vitrage_tempest_plugin.tests.base import BaseVitrageTempest
from vitrage_tempest_plugin.tests.base import IsNotEmpty
from vitrage_tempest_plugin.tests.common import general_utils as g_utils
from vitrage_tempest_plugin.tests.common import vitrage_utils
from vitrage_tempest_plugin.tests import utils
@ -51,7 +53,7 @@ class BaseTemplateTest(BaseVitrageTempest):
super(BaseTemplateTest, cls).setUpClass()
def _compare_template_lists(self, api_templates, cli_templates):
self.assertNotEqual(len(api_templates), 0,
self.assertThat(api_templates, IsNotEmpty(),
'The template list taken from api is empty')
self.assertIsNotNone(cli_templates,
'The template list taken from cli is empty')
@ -67,7 +69,7 @@ class BaseTemplateTest(BaseVitrageTempest):
self._validate_templates_existence_in_default_folder(api_templates)
def _compare_template_validations(self, api_templates, cli_templates):
self.assertNotEqual(len(api_templates), 0,
self.assertThat(api_templates, IsNotEmpty(),
'The template validations taken from api is empty')
self.assertIsNotNone(
cli_templates, 'The template validations taken from cli is empty')
@ -91,7 +93,8 @@ class BaseTemplateTest(BaseVitrageTempest):
api_templates,
**{'status details': self.OK_MSG})
cli_passes_templates = cli_templates.count(' ' + self.OK_MSG + ' ')
self.assertEqual(cli_passes_templates, len(api_passes_templates))
self.assertThat(api_passes_templates,
matchers.HasLength(cli_passes_templates))
def _compare_each_template_in_list(self, api_templates, cli_templates):
counter = 0
@ -102,7 +105,7 @@ class BaseTemplateTest(BaseVitrageTempest):
if name_start > 0 and status_start > 0:
counter += 1
break
self.assertEqual(counter, len(api_templates))
self.assertThat(api_templates, matchers.HasLength(counter))
def _validate_templates_existence_in_default_folder(self, templates_list):
counter = 0
@ -111,11 +114,11 @@ class BaseTemplateTest(BaseVitrageTempest):
name_start = text_out.count(' ' + item['name'] + ' ')
if name_start > -1:
counter += 1
self.assertEqual(counter, len(templates_list))
self.assertThat(templates_list, matchers.HasLength(counter))
def _run_default_template_validation(
self, template, validation, path):
self.assertNotEqual(len(validation), 0,
self.assertThat(validation, IsNotEmpty(),
'The template validation is empty')
self.assertEqual(path, validation['file path'])
self.assertEqual(0, validation['status code'])
@ -138,7 +141,7 @@ class BaseTemplateTest(BaseVitrageTempest):
self.assertEqual(self.OK_MSG, validation['message'])
def _compare_template_show(self, api_templates, cli_templates):
self.assertNotEqual(len(api_templates), 0,
self.assertThat(api_templates, IsNotEmpty(),
'The template validations taken from api is empty')
self.assertIsNotNone(
cli_templates, 'The template validations taken from cli is empty')
@ -163,14 +166,13 @@ class BaseTemplateTest(BaseVitrageTempest):
relationships = template_content.count('relationship:')
scenarios = template_content.count('scenario:')
self.assertIn(
template_show['metadata']['name'], template_content)
self.assertEqual(
entities, len(template_show['definitions']['entities']))
self.assertEqual(
relationships, len(template_show['definitions']['relationships']))
self.assertEqual(
scenarios, len(template_show['scenarios']))
self.assertIn(template_show['metadata']['name'], template_content)
self.assertThat(template_show['definitions']['entities'],
matchers.HasLength(entities))
self.assertThat(template_show['definitions']['relationships'],
matchers.HasLength(relationships))
self.assertThat(template_show['scenarios'],
matchers.HasLength(scenarios))
def _rollback_to_default(self, templates):
try:

View File

@ -15,14 +15,17 @@
import unittest
from oslo_log import log as logging
from testtools import matchers
from vitrage.common.constants import TemplateStatus
from vitrage.common.constants import TemplateTypes as TTypes
from vitrage.utils import file
from vitrage_tempest_plugin.tests.api.templates.base import BaseTemplateTest
from vitrage_tempest_plugin.tests.base import IsNotEmpty
from vitrage_tempest_plugin.tests.common import general_utils as g_utils
from vitrage_tempest_plugin.tests.common.tempest_clients import TempestClients
from vitrage_tempest_plugin.tests.common import vitrage_utils as v_utils
import vitrage_tempest_plugin.tests.utils as utils
LOG = logging.getLogger(__name__)
@ -92,7 +95,7 @@ class TestValidate(BaseTemplateTest):
"""
path = self.DEFAULT_PATH
validation = self.vitrage_client.template.validate(path=path)
self.assertNotEqual(len(validation), 0)
self.assertThat(validation, IsNotEmpty())
for item in validation['results']:
self._run_template_validation(item, path)
@ -119,7 +122,7 @@ class TestValidate(BaseTemplateTest):
try:
path = self.TEST_PATH + self.ERROR_FILE
validation = self.vitrage_client.template.validate(path=path)
self.assertEqual(1, len(validation['results']))
self.assertThat(validation['results'], matchers.HasLength(1))
self._run_template_validation(
validation['results'][0], path, negative=True)
except Exception:
@ -133,7 +136,7 @@ class TestValidate(BaseTemplateTest):
try:
path = self.TEST_PATH + self.OK_FILE
validation = self.vitrage_client.template.validate(path=path)
self.assertEqual(1, len(validation['results']))
self.assertThat(validation['results'], matchers.HasLength(1))
self._run_template_validation(
validation['results'][0], path)
except Exception:
@ -148,7 +151,7 @@ class TestValidate(BaseTemplateTest):
(in /etc/vitrage/templates folder)
"""
template_list = self.vitrage_client.template.list()
self.assertNotEqual(len(template_list), 0)
self.assertThat(template_list, IsNotEmpty())
for item in template_list:
api_template_show = self.vitrage_client.template.show(item['uuid'])
cli_template_show = utils.run_vitrage_command(
@ -257,7 +260,7 @@ class TemplatesDBTest(BaseTemplateTest):
"vitrage template list", self.conf)
api_templates_list = self.client.template.list()
self.assertNotEqual(len(api_templates_list), 0,
self.assertThat(api_templates_list, IsNotEmpty(),
'The template list taken from api is empty')
self.assertIsNotNone(cli_templates_list,
'The template list taken from cli is empty')

View File

@ -13,6 +13,7 @@
# under the License.
from oslo_log import log as logging
from testtools import matchers
from vitrage_tempest_plugin.tests.api.templates.base import BaseTemplateTest
@ -37,7 +38,7 @@ class TestValidateV2(BaseTemplateTest):
try:
path = self.TEST_PATH + NO_TYPE_TEMPLATE
validation = self.vitrage_client.template.validate(path=path)
self.assertEqual(1, len(validation['results']))
self.assertThat(validation['results'], matchers.HasLength(1))
self._run_template_validation(
validation['results'][0], path, negative=True)
except Exception:
@ -47,7 +48,7 @@ class TestValidateV2(BaseTemplateTest):
try:
path = self.TEST_PATH + EXECUTE_MISTRAL_TEMPLATE
validation = self.vitrage_client.template.validate(path=path)
self.assertEqual(1, len(validation['results']))
self.assertThat(validation['results'], matchers.HasLength(1))
self._run_template_validation(
validation['results'][0], path)
except Exception:
@ -57,7 +58,7 @@ class TestValidateV2(BaseTemplateTest):
try:
path = self.TEST_PATH + DEFINITION_TEMPLATE
validation = self.vitrage_client.template.validate(path=path)
self.assertEqual(1, len(validation['results']))
self.assertThat(validation['results'], matchers.HasLength(1))
self._run_template_validation(
validation['results'][0], path)
except Exception:

View File

@ -18,6 +18,7 @@ import time
from vitrage.common.constants import VertexProperties as VProps
from vitrage_tempest_plugin.tests.base import BaseVitrageTempest
from vitrage_tempest_plugin.tests.base import IsNotEmpty
from vitrage_tempest_plugin.tests.base import LOG
from vitrage_tempest_plugin.tests.common import cinder_utils
from vitrage_tempest_plugin.tests.common import nova_utils
@ -57,7 +58,8 @@ class BaseTopologyTest(BaseVitrageTempest):
def _create_entities(self, num_instances, num_volumes=0, end_sleep=3):
resources = nova_utils.create_instances(num_instances)
self.assertNotEqual(len(resources), 0, 'The instances list is empty')
self.assertThat(resources, IsNotEmpty(),
'The instances list is empty')
if num_volumes > 0:
cinder_utils.create_volume_and_attach('volume-1', 1,
resources[0].id,
@ -78,9 +80,9 @@ class BaseTopologyTest(BaseVitrageTempest):
def _compare_graphs(self, api_graph, cli_graph):
"""Compare Graph object to graph form terminal """
self.assertNotEqual(len(api_graph), 0,
self.assertThat(api_graph, IsNotEmpty(),
'The topology graph taken from rest api is empty')
self.assertNotEqual(len(cli_graph), 0,
self.assertThat(cli_graph, IsNotEmpty(),
'The topology graph taken from terminal is empty')
parsed_topology = json.loads(cli_graph)

View File

@ -17,6 +17,7 @@ from oslo_log import log as logging
from vitrage.common.constants import VertexProperties as VProps
from vitrage.datasources import OPENSTACK_CLUSTER
from vitrage_tempest_plugin.tests.api.topology.base import BaseTopologyTest
from vitrage_tempest_plugin.tests.base import IsEmpty
import vitrage_tempest_plugin.tests.utils as utils
from vitrageclient.exceptions import ClientException
@ -382,12 +383,9 @@ class TestTopology(BaseTopologyTest):
query=self._graph_no_match_query(), all_tenants=True)
# Test Assertions
self.assertEqual(
0,
len(api_graph['nodes']), 'num of vertex node')
self.assertEqual(
0,
len(api_graph['links']), 'num of edges')
self.assertThat(api_graph['nodes'],
IsEmpty(), 'num of vertex node')
self.assertThat(api_graph['links'], IsEmpty(), 'num of edges')
except Exception as e:
self._handle_exception(e)
raise

View File

@ -13,6 +13,7 @@
# under the License.
from oslo_log import log as logging
from testtools import matchers
from vitrage_tempest_plugin.tests.base import BaseVitrageTempest
from vitrage_tempest_plugin.tests.common.tempest_clients import TempestClients
@ -39,10 +40,10 @@ class TestWebhook(BaseVitrageTempest):
def test_add_webhook(self):
webhooks = TempestClients.vitrage().webhook.list()
self.assertEqual(self.pre_test_webhook_count,
len(webhooks),
'Amount of webhooks should be the same as '
'before the test')
self.assertThat(webhooks,
matchers.HasLength(self.pre_test_webhook_count),
'Amount of webhooks should be '
'the same as before the test')
created_webhook = TempestClients.vitrage().webhook.add(
url="https://www.test.com",
@ -64,16 +65,17 @@ class TestWebhook(BaseVitrageTempest):
webhooks = TempestClients.vitrage().webhook.list()
self.assertEqual(self.pre_test_webhook_count + 1, len(webhooks))
self.assertThat(webhooks,
matchers.HasLength(self.pre_test_webhook_count + 1))
TempestClients.vitrage().webhook.delete(
created_webhook['id'])
def test_delete_webhook(self):
webhooks = TempestClients.vitrage().webhook.list()
self.assertEqual(self.pre_test_webhook_count,
len(webhooks),
'Amount of webhooks should be the same as '
'before the test')
self.assertThat(webhooks,
matchers.HasLength(self.pre_test_webhook_count),
'Amount of webhooks should '
'be the same as before the test')
created_webhook = TempestClients.vitrage().webhook.add(
url="https://www.test.com",
@ -85,7 +87,8 @@ class TestWebhook(BaseVitrageTempest):
id=created_webhook['id'])
self.assertIsNotNone(created_webhook.get('SUCCESS'),
'failed to delete')
self.assertEqual(self.pre_test_webhook_count, len(webhooks),
self.assertThat(webhooks,
matchers.HasLength(self.pre_test_webhook_count),
'No webhooks should exist after deletion')
def test_delete_non_existing_webhook(self):
@ -96,10 +99,10 @@ class TestWebhook(BaseVitrageTempest):
def test_list_webhook(self):
webhooks = TempestClients.vitrage().webhook.list()
self.assertEqual(self.pre_test_webhook_count,
len(webhooks),
'Amount of webhooks should be the same as '
'before the test')
self.assertThat(webhooks,
matchers.HasLength(self.pre_test_webhook_count),
'Amount of webhooks should be '
'the same as before the test')
created_webhook = TempestClients.vitrage().webhook.add(
url="https://www.test.com",
@ -108,7 +111,8 @@ class TestWebhook(BaseVitrageTempest):
)
webhooks = TempestClients.vitrage().webhook.list()
self.assertEqual(self.pre_test_webhook_count + 1, len(webhooks))
self.assertThat(webhooks,
matchers.HasLength(self.pre_test_webhook_count + 1))
self.assertEqual(created_webhook[HEADERS], webhooks[0][HEADERS])
self.assertEqual(created_webhook['id'], webhooks[0]['id'])
self.assertEqual(created_webhook[REGEX_FILTER],
@ -119,10 +123,10 @@ class TestWebhook(BaseVitrageTempest):
def test_show_webhook(self):
webhooks = TempestClients.vitrage().webhook.list()
self.assertEqual(self.pre_test_webhook_count,
len(webhooks),
'Amount of webhooks should be the same as '
'before the test')
self.assertThat(webhooks,
matchers.HasLength(self.pre_test_webhook_count),
'Amount of webhooks should be '
'the same as before the test')
created_webhook = TempestClients.vitrage().webhook.add(
url="https://www.test.com",

View File

@ -20,6 +20,7 @@ from oslo_log import log as logging
from oslo_utils import timeutils
from oslotest import base
from testtools.matchers import HasLength
from testtools.matchers import Not
from vitrage.common.constants import EdgeProperties
from vitrage.common.constants import EntityCategory
@ -46,6 +47,7 @@ import warnings
LOG = logging.getLogger(__name__)
IsEmpty = lambda: HasLength(0)
IsNotEmpty = lambda: Not(IsEmpty())
if six.PY2:
class ResourceWarning(Warning):

View File

@ -14,6 +14,7 @@
import time
from oslo_log import log as logging
from testtools import matchers
from vitrage.common.constants import VertexProperties as VProps
from vitrage_tempest_plugin.tests.base import BaseVitrageTempest
@ -62,9 +63,7 @@ class TestActionsBase(BaseVitrageTempest):
vitrage_id=resource_id,
all_tenants=True)
deduces = g_utils.all_matches(alarms, **deduced_props)
self.assertEqual(
deduced_count,
len(deduces),
self.assertThat(deduces, matchers.HasLength(deduced_count),
'Expected %s deduces\n - \n%s\n - \n%s' %
(str(deduced_count), str(alarms), str(deduces)))

View File

@ -20,6 +20,7 @@ from vitrage.common.constants import VertexProperties as VProps
from vitrage.datasources.doctor import DOCTOR_DATASOURCE
from vitrage.evaluator.actions.evaluator_event_transformer import \
VITRAGE_DATASOURCE
from vitrage_tempest_plugin.tests.base import IsEmpty
from vitrage_tempest_plugin.tests.common import general_utils as g_utils
from vitrage_tempest_plugin.tests.common.tempest_clients import TempestClients
from vitrage_tempest_plugin.tests.common import vitrage_utils as v_utils
@ -231,17 +232,17 @@ class TestOverlappingActions(TestActionsBase):
alarms = TempestClients.vitrage().alarm.list(
vitrage_id=self.orig_host.get(VProps.VITRAGE_ID),
all_tenants=True)
self.assertEqual(
0,
len(g_utils.all_matches(alarms, **TRIGGER_ALARM_1_PROPS)),
self.assertThat(
g_utils.all_matches(alarms, **TRIGGER_ALARM_1_PROPS),
IsEmpty(),
'trigger alarm 1 should have been removed')
self.assertEqual(
0,
len(g_utils.all_matches(alarms, **TRIGGER_ALARM_2_PROPS)),
self.assertThat(
g_utils.all_matches(alarms, **TRIGGER_ALARM_2_PROPS),
IsEmpty(),
'trigger alarm 2 should have been removed')
self.assertEqual(
0,
len(g_utils.all_matches(alarms, **DEDUCED_PROPS)),
self.assertThat(
g_utils.all_matches(alarms, **DEDUCED_PROPS),
IsEmpty(),
'deduced alarm should have been removed')
except Exception as e: