some cleaning

* remove unused methods
* use testools assert exceptions
* use tearDown where possible
* redundant str()

Change-Id: I18af00599461ead7bf9084168aeed7321adfd4c0
This commit is contained in:
Eyal 2019-02-26 10:09:19 +02:00
parent 8f4de82480
commit 83efcb9e52
26 changed files with 331 additions and 590 deletions

View File

@ -1,28 +0,0 @@
# Copyright 2016 Nokia
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# 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 vitrage_tempest_plugin.tests.base import BaseVitrageTempest
from vitrage_tempest_plugin.tests.common.constants import AodhProperties
from vitrage_tempest_plugin.tests.common.tempest_clients import TempestClients
class BaseAlarmsTest(BaseVitrageTempest):
"""Topology test class for Vitrage API tests."""
def _check_num_alarms(self, num_alarms=0, state=''):
if len(TempestClients.aodh().alarm.list()) != num_alarms:
return False
return all(alarm[AodhProperties.STATE].upper() == state.upper()
for alarm in TempestClients.aodh().alarm.list())

View File

@ -1,66 +0,0 @@
# Copyright 2016 Nokia
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import json
from oslo_log import log as logging
from testtools import matchers
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 general_utils as g_utils
from vitrage_tempest_plugin.tests.common import vitrage_utils as v_utils
LOG = logging.getLogger(__name__)
class TestAlarms(BaseAlarmsTest):
"""Alarms test class for Vitrage API tests."""
@classmethod
def setUpClass(cls):
super(TestAlarms, cls).setUpClass()
cls._template = v_utils.add_template('nagios_alarm_for_alarms.yaml')
# noinspection PyPep8Naming
@classmethod
def tearDownClass(cls):
if cls._template is not None:
v_utils.delete_template(cls._template['uuid'])
def _compare_alarms_lists(self, api_alarms, cli_alarms,
resource_type, resource_id):
"""Validate alarm existence """
self.assertThat(api_alarms, IsNotEmpty(),
'The alarms list taken from api is empty')
self.assertThat(cli_alarms, IsNotEmpty(),
'The alarms list taken from cli is empty')
LOG.info("The alarms list taken from cli is : " +
str(cli_alarms))
LOG.info("The alarms list taken by api is : " +
str(json.dumps(api_alarms)))
cli_items = cli_alarms.splitlines()
api_by_type = g_utils.all_matches(
api_alarms, vitrage_type=resource_type)
cli_by_type = cli_alarms.count(' ' + resource_type + ' ')
api_by_id = g_utils.all_matches(api_alarms, resource_id=resource_id)
cli_by_id = cli_alarms.count(resource_id)
self.assertEqual(len(cli_items), len(api_alarms) + 4)
self.assertThat(api_by_type, matchers.HasLength(cli_by_type))
self.assertThat(api_by_id, matchers.HasLength(cli_by_id))

View File

@ -17,12 +17,10 @@ import json
from oslo_log import log as logging
from testtools import matchers
from vitrage_tempest_plugin.tests.api.alarms.base import BaseAlarmsTest
from vitrage_tempest_plugin.tests.base import BaseVitrageTempest
from vitrage_tempest_plugin.tests.base import IsNotEmpty
from vitrage_tempest_plugin.tests.common import aodh_utils
from vitrage_tempest_plugin.tests.common.constants import AODH_DATASOURCE
from vitrage_tempest_plugin.tests.common.constants import EdgeLabel
from vitrage_tempest_plugin.tests.common.constants import EdgeProperties
from vitrage_tempest_plugin.tests.common.constants import NOVA_HOST_DATASOURCE
from vitrage_tempest_plugin.tests.common.constants import \
NOVA_INSTANCE_DATASOURCE
@ -42,7 +40,7 @@ RCA_ALARM_NAME = 'rca_test_host_alarm'
VITRAGE_ALARM_NAME = 'instance_deduce'
class BaseRcaTest(BaseAlarmsTest):
class BaseRcaTest(BaseVitrageTempest):
@staticmethod
def _clean_all():
@ -132,24 +130,6 @@ class BaseRcaTest(BaseAlarmsTest):
self.assertThat(deduce_alarms_2, matchers.HasLength(1),
"Deduced alarm not found")
def _validate_relationship(self, links, alarms):
self.assertThat(links, IsNotEmpty(), 'The links list is empty')
self.assertThat(alarms, IsNotEmpty(), 'The alarms list is empty')
flag = True
for item in links:
source_alarm_name = alarms[item['source']].get(VProps.NAME)
target_alarm_name = alarms[item['target']].get(VProps.NAME)
relationship_type = item.get(EdgeProperties.RELATIONSHIP_TYPE)
if (item.get('key') != EdgeLabel.CAUSES or
relationship_type != EdgeLabel.CAUSES or
source_alarm_name != RCA_ALARM_NAME or
target_alarm_name != VITRAGE_ALARM_NAME):
flag = False
self.assertThat(alarms, matchers.HasLength(3))
self.assertTrue(flag)
def _validate_set_state(self, topology, instances):
self.assertThat(topology, IsNotEmpty(), 'The topology graph is empty')
host = g_utils.all_matches(
@ -177,29 +157,8 @@ class BaseRcaTest(BaseAlarmsTest):
self.assertThat(vm1, matchers.HasLength(1))
self.assertThat(vm2, matchers.HasLength(1))
def _validate_notifier(self, alarms, vitrage_alarms):
self.assertThat(alarms, IsNotEmpty(), 'The aodh alarms list is empty')
self.assertThat(vitrage_alarms, IsNotEmpty(),
'The vitrage alarms list is empty')
validation = 0
for itemC in alarms:
vitrage_id = filter(
lambda item: item['field'] == VProps.VITRAGE_ID,
itemC.event_rule['query'])
for itemV in vitrage_alarms:
if not vitrage_id:
if itemC.name == itemV[VProps.NAME]:
validation += 1
break
elif vitrage_id[0]['value'] == itemV[VProps.VITRAGE_ID]:
validation += 1
break
self.assertThat(vitrage_alarms, matchers.HasLength(validation))
self.assertThat(alarms, matchers.HasLength(3))
def _get_hostname(self):
@staticmethod
def _get_hostname():
host = vitrage_utils.get_first_host()
return host.get(VProps.ID)

View File

@ -26,6 +26,10 @@ LOG = logging.getLogger(__name__)
class TestRca(BaseRcaTest):
"""RCA test class for Vitrage API tests."""
def tearDown(self):
super(TestRca, self).tearDown()
self._clean_all()
@classmethod
def setUpClass(cls):
super(TestRca, cls).setUpClass()
@ -45,19 +49,16 @@ class TestRca(BaseRcaTest):
(created by special template file), and equals there
resource_id with created instances id
"""
try:
instances = nova_utils.create_instances(num_instances=2,
set_public_network=True)
self._create_alarm(
resource_id=self._get_hostname(),
alarm_name=RCA_ALARM_NAME)
api_alarms = self.vitrage_client.alarm.list(vitrage_id='all',
all_tenants=True)
instances = nova_utils.create_instances(num_instances=2,
set_public_network=True)
self._create_alarm(
resource_id=self._get_hostname(),
alarm_name=RCA_ALARM_NAME)
api_alarms = self.vitrage_client.alarm.list(vitrage_id='all',
all_tenants=True)
self._validate_deduce_alarms(alarms=api_alarms,
instances=instances)
finally:
self._clean_all()
self._validate_deduce_alarms(alarms=api_alarms,
instances=instances)
@utils.tempest_logger
def test_validate_set_state(self):
@ -68,18 +69,12 @@ class TestRca(BaseRcaTest):
source state - ERROR
target state - SUBOPTIMAL (caused 2 created instance)
"""
try:
instances = nova_utils.create_instances(num_instances=2,
set_public_network=True)
self._create_alarm(
resource_id=self._get_hostname(),
alarm_name=RCA_ALARM_NAME)
topology = self.vitrage_client.topology.get(all_tenants=True)
instances = nova_utils.create_instances(num_instances=2,
set_public_network=True)
self._create_alarm(
resource_id=self._get_hostname(),
alarm_name=RCA_ALARM_NAME)
topology = self.vitrage_client.topology.get(all_tenants=True)
self._validate_set_state(topology=topology['nodes'],
instances=instances)
except Exception as e:
self._handle_exception(e)
raise
finally:
self._clean_all()
self._validate_set_state(topology=topology['nodes'],
instances=instances)

View File

@ -200,14 +200,3 @@ class TestResource(BaseVitrageTempest):
self.assertEqual(
cli_resource.get("State").lower(),
api_resource.get(VProps.VITRAGE_OPERATIONAL_STATE).lower())
def _compare_resource_show(self, api_resource_show,
cli_resource_show):
self.assertIsNotNone(api_resource_show,
'The resource show taken from rest api is empty')
self.assertIsNotNone(cli_resource_show,
'The resource show taken from terminal is empty')
for item in self.properties:
self.assertEqual(api_resource_show.get(item),
cli_resource_show.get(item))

View File

@ -39,6 +39,15 @@ class BaseTemplateTest(BaseVitrageTempest):
VALIDATION_OK = 'validation OK'
OK_MSG = 'Template validation is OK'
def tearDown(self):
super(BaseTemplateTest, self).tearDown()
self._delete_templates()
def _delete_templates(self):
templates = self.vitrage_client.template.list()
template_ids = [template['uuid'] for template in templates]
self.vitrage_client.template.delete(template_ids)
def _compare_template_lists(self, api_templates, cli_templates):
self.assertThat(api_templates, IsNotEmpty(),
'The template list taken from api is empty')
@ -54,22 +63,6 @@ class BaseTemplateTest(BaseVitrageTempest):
self._validate_passed_templates_length(api_templates, cli_templates)
self._compare_each_template_in_list(api_templates, cli_templates)
def _compare_template_validations(self, api_templates, cli_templates):
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')
LOG.info("The template validations taken from cli is : " +
str(cli_templates))
LOG.info("The template validations taken by api is : " +
str(json.dumps(api_templates)))
parsed_topology = json.loads(cli_templates)
sorted_cli_templates = sorted(parsed_topology.items())
sorted_api_templates = sorted(api_templates.items())
self.assert_list_equal(sorted_api_templates, sorted_cli_templates)
def _validate_templates_list_length(self, api_templates, cli_templates):
self.assertEqual(len(cli_templates.splitlines()),
len(api_templates) + 4)
@ -93,16 +86,6 @@ class BaseTemplateTest(BaseVitrageTempest):
break
self.assertThat(api_templates, matchers.HasLength(counter))
def _run_default_template_validation(
self, template, validation, path):
self.assertThat(validation, IsNotEmpty(),
'The template validation is empty')
self.assertEqual(path, validation['file path'])
self.assertEqual(0, validation['status code'])
self.assertEqual(self.VALIDATION_OK, validation['status'])
self.assertEqual(self.OK_MSG, validation['message'])
self.assertEqual(validation['message'], template['status details'])
def _assert_validate_result(self, validation, path, negative=False,
status_code=0):
self.assertThat(validation['results'], matchers.HasLength(1))
@ -110,14 +93,14 @@ class BaseTemplateTest(BaseVitrageTempest):
self.assertIn(path, result['file path'])
if negative:
self.assertEqual(status_code, result['status code'])
self.assertEqual(self.VALIDATION_FAILED, result['status'])
self.assertNotEqual(result['message'], self.OK_MSG)
self.assertEqual(status_code, result['status code'])
return
self.assertEqual(0, result['status code'])
self.assertEqual(self.VALIDATION_OK, result['status'])
self.assertEqual(self.OK_MSG, result['message'])
self.assertEqual(0, result['status code'])
def _assert_add_result(self, result, status, message):
self.assertThat(result, matchers.HasLength(1))
@ -125,22 +108,6 @@ class BaseTemplateTest(BaseVitrageTempest):
self.assertThat(result[0]['status details'],
matchers.StartsWith(message))
def _compare_template_show(self, api_templates, cli_templates):
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')
LOG.info("The template validations taken from cli is : " +
str(cli_templates))
LOG.info("The template validations taken by api is : " +
str(json.dumps(api_templates)))
parsed_topology = json.loads(cli_templates)
sorted_cli_templates = sorted(parsed_topology.items())
sorted_api_templates = sorted(api_templates.items())
self.assert_list_equal(sorted_api_templates, sorted_cli_templates)
@staticmethod
def _rollback_to_default(templates):
for t in templates:

View File

@ -69,13 +69,10 @@ class TestValidate(BaseTemplateTest):
There negative test - validate error message
in case of non-exist template file
"""
try:
path = self.TEST_PATH + self.NON_EXIST_FILE
validation = self.vitrage_client.template.validate(path=path)
self.assertIsNone(validation)
except Exception as up:
self.assertEqual('No such file or directory', up.strerror)
self.assertEqual(2, up.errno)
path = self.TEST_PATH + self.NON_EXIST_FILE
self.assertRaises(IOError,
self.vitrage_client.template.validate,
path=path)
def test_templates_validate_corrupted_templates(self):
"""templates_validate test
@ -83,27 +80,21 @@ class TestValidate(BaseTemplateTest):
There negative test - validate correctness of error
message in case of corrupted template file
"""
try:
path = self.TEST_PATH + self.ERROR_FILE
validation = self.vitrage_client.template.validate(path=path)
self.assertThat(validation['results'], matchers.HasLength(1))
self._assert_validate_result(
validation, path, negative=True, status_code=3)
except Exception:
LOG.error('Failed to get validation of corrupted template file')
path = self.TEST_PATH + self.ERROR_FILE
validation = self.vitrage_client.template.validate(path=path)
self.assertThat(validation['results'], matchers.HasLength(1))
self._assert_validate_result(validation, path,
negative=True, status_code=3)
def test_templates_validate_correct_template(self):
"""templates_validate test
There test validate correctness of template file
"""
try:
path = self.TEST_PATH + self.OK_FILE
validation = self.vitrage_client.template.validate(path=path)
self.assertThat(validation['results'], matchers.HasLength(1))
self._assert_validate_result(validation, path)
except Exception:
LOG.error('Failed to get validation of template file')
path = self.TEST_PATH + self.OK_FILE
validation = self.vitrage_client.template.validate(path=path)
self.assertThat(validation['results'], matchers.HasLength(1))
self._assert_validate_result(validation, path)
class TemplatesDBTest(BaseTemplateTest):
@ -114,47 +105,42 @@ class TemplatesDBTest(BaseTemplateTest):
test standard , definition and equivalence templates
"""
templates_names = list()
try:
# TODO(ikinory): add folder of templates
# Add standard ,equivalence and definition templates
templates_names = self._add_templates()
# assert standard template
db_row = v_utils.get_first_template(
name='host_high_memory_usage_scenarios', type=TTypes.STANDARD)
self.assertEqual(db_row['name'],
'host_high_memory_usage_scenarios',
'standard template not found in list')
# TODO(ikinory): add folder of templates
# Add standard ,equivalence and definition templates
self._add_templates()
# assert standard template
db_row = v_utils.get_first_template(
name='host_high_memory_usage_scenarios', type=TTypes.STANDARD)
self.assertEqual(db_row['name'],
'host_high_memory_usage_scenarios',
'standard template not found in list')
# assert equivalence template
db_row = v_utils.get_first_template(
name='entity equivalence example',
type=TTypes.EQUIVALENCE)
self.assertEqual(db_row['name'],
'entity equivalence example',
'equivalence template not found in list')
# assert equivalence template
db_row = v_utils.get_first_template(
name='entity equivalence example',
type=TTypes.EQUIVALENCE)
self.assertEqual(db_row['name'],
'entity equivalence example',
'equivalence template not found in list')
# assert definition template
db_row = v_utils.get_first_template(
name='basic_def_template',
type=TTypes.DEFINITION,
status=TemplateStatus.ACTIVE)
# assert definition template
db_row = v_utils.get_first_template(
name='basic_def_template',
type=TTypes.DEFINITION,
status=TemplateStatus.ACTIVE)
self.assertEqual(db_row['name'],
'basic_def_template',
'definition template not found in list')
self.assertEqual(db_row['name'],
'basic_def_template',
'definition template not found in list')
# assert corrupted template - validate failed
db_row = v_utils.get_first_template(
name='corrupted_template',
type=TTypes.STANDARD,
status=TemplateStatus.ERROR)
self.assertIsNotNone(
db_row,
'corrupted template template presented in list')
finally:
self._rollback_to_default(templates_names)
# assert corrupted template - validate failed
db_row = v_utils.get_first_template(
name='corrupted_template',
type=TTypes.STANDARD,
status=TemplateStatus.ERROR)
self.assertIsNotNone(
db_row,
'corrupted template template presented in list')
def test_template_delete(self):
@ -181,26 +167,22 @@ class TemplatesDBTest(BaseTemplateTest):
to cli template list
compares each template in list
"""
templates_names = list()
try:
# Add standard ,equivalence and definition templates
templates_names = self._add_templates()
cli_templates_list = utils.run_vitrage_command(
"vitrage template list")
api_templates_list = self.vitrage_client.template.list()
# Add standard ,equivalence and definition templates
self._add_templates()
cli_templates_list = utils.run_vitrage_command(
"vitrage template list")
api_templates_list = self.vitrage_client.template.list()
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')
self._validate_templates_list_length(api_templates_list,
cli_templates_list)
self._validate_passed_templates_length(api_templates_list,
cli_templates_list)
self._compare_each_template_in_list(api_templates_list,
cli_templates_list)
finally:
self._rollback_to_default(templates_names)
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')
self._validate_templates_list_length(api_templates_list,
cli_templates_list)
self._validate_passed_templates_length(api_templates_list,
cli_templates_list)
self._compare_each_template_in_list(api_templates_list,
cli_templates_list)
def test_template_show(self):
"""Compare template content from file to DB"""
@ -221,7 +203,8 @@ class TemplatesDBTest(BaseTemplateTest):
"Template content doesn't match")
v_utils.delete_template(db_row['uuid'])
def _add_templates(self):
@staticmethod
def _add_templates():
v_utils.add_template(STANDARD_TEMPLATE,
template_type=TTypes.STANDARD)
v_utils.add_template(EQUIVALENCE_TEMPLATE,

View File

@ -32,15 +32,11 @@ TEMPLATE_VALIDATION_OK = 'Template validation is OK'
class TestTemplatesApis(BaseTemplateTest):
def tearDown(self):
super(TestTemplatesApis, self).tearDown()
self._delete_templates()
def _validate_no_type_templates(self, template_name):
path = self.TEST_PATH + template_name
validation = self.vitrage_client.template.validate(path=path)
self._assert_validate_result(
validation, path, negative=True, status_code='')
validation, path, negative=True, status_code=66)
def _validate_standard_template(self, template_name):
path = self.TEST_PATH + template_name
@ -98,18 +94,9 @@ class TestTemplatesApis(BaseTemplateTest):
result = self.vitrage_client.template.add(path=path, params=params)
self._assert_add_result(result, LOADING_STATUS, TEMPLATE_VALIDATION_OK)
def _delete_templates(self):
templates = self.vitrage_client.template.list()
template_ids = [template['uuid'] for template in templates]
self.vitrage_client.template.delete(template_ids)
class TestTemplatesV2(TestTemplatesApis):
def tearDown(self):
super(TestTemplatesV2, self).tearDown()
self._delete_templates()
def test_templates_validate_no_type_templates(self):
self._validate_no_type_templates(NO_TYPE_TEMPLATE)

View File

@ -13,13 +13,10 @@
# under the License.
from oslo_log import log as logging
from testtools import ExpectedException
from vitrage_tempest_plugin.tests.api.topology.base import BaseTopologyTest
from vitrage_tempest_plugin.tests.base import IsEmpty
from vitrage_tempest_plugin.tests.common.constants import OPENSTACK_CLUSTER
from vitrage_tempest_plugin.tests.common.constants import VertexProperties as \
VProps
import vitrage_tempest_plugin.tests.utils as utils
from vitrageclient.exceptions import ClientException
@ -39,10 +36,9 @@ class TestTopology(BaseTopologyTest):
NUM_INSTANCE = 3
NUM_VOLUME = 1
def _get_root_vertex_id(self):
items = self.vitrage_client.resource.list(
resource_type=OPENSTACK_CLUSTER, all_tenants=True)
return items[0][VProps.VITRAGE_ID]
def tearDown(self):
super(TestTopology, self).tearDown()
self._rollback_to_default()
@utils.tempest_logger
def test_compare_api_and_cli(self):
@ -277,21 +273,18 @@ class TestTopology(BaseTopologyTest):
This test validate correctness of topology
graph with depth and without root
"""
try:
# Action
self._create_entities(num_instances=self.NUM_INSTANCE,
num_volumes=self.NUM_VOLUME)
# Action
self._create_entities(num_instances=self.NUM_INSTANCE,
num_volumes=self.NUM_VOLUME)
with ExpectedException(ClientException,
"Graph-type 'graph' "
"requires a 'root' with 'depth'"):
# Calculate expected results
self.vitrage_client.topology.get(
limit=2,
root=None,
all_tenants=True)
except ClientException as e:
self.assertEqual(403, e.code)
self.assertEqual(
"Graph-type 'graph' requires a 'root' with 'depth'",
str(e.message))
@utils.tempest_logger
def test_graph_with_no_match_query(self):

View File

@ -93,7 +93,7 @@ class TestWebhook(BaseVitrageTempest):
def test_delete_non_existing_webhook(self):
self.assertRaises(ClientException,
self.vitrage_client.webhook.delete,
('non existant'))
'non existent')
def test_list_webhook(self):

View File

@ -334,11 +334,7 @@ class BaseVitrageTempest(test.BaseTestCase):
(timestamp_name, vertex, utils.TIMESTAMP_FORMAT))
@staticmethod
def _get_value(item, key):
return utils.uni2str(item[key])
@classmethod
def _calc_num_admin_tenant_networks(cls):
def _calc_num_admin_tenant_networks():
neutron_client = TempestClients.neutron()
admin_creds = common_creds.get_configured_admin_credentials()
tenant_networks = neutron_client.list_networks(

View File

@ -41,7 +41,7 @@ def create_instances(num_instances=1, set_public_network=False, name='vm'):
return resources
if not success:
LOG.warning("create instance failed, delete and retry %s",
str(resources))
resources)
delete_created_instances(resources)
time.sleep(10)
raise AssertionError("Unable to create vms, retries failed")

View File

@ -15,7 +15,7 @@
from oslo_log import log as logging
from vitrage_tempest_plugin.tests import utils
from vitrage_tempest_plugin.tests.api.alarms.base import BaseAlarmsTest
from vitrage_tempest_plugin.tests.base import BaseVitrageTempest
from vitrage_tempest_plugin.tests.common import aodh_utils
from vitrage_tempest_plugin.tests.common import nova_utils
from vitrage_tempest_plugin.tests.common.tempest_clients import TempestClients
@ -23,130 +23,120 @@ from vitrage_tempest_plugin.tests.common.tempest_clients import TempestClients
LOG = logging.getLogger(__name__)
class TestAodhAlarm(BaseAlarmsTest):
class TestAodhAlarm(BaseVitrageTempest):
NUM_INSTANCE = 1
NUM_ALARM = 1
def tearDown(self):
super(TestAodhAlarm, self).tearDown()
aodh_utils.delete_all_aodh_alarms()
aodh_utils.delete_all_gnocchi_metrics()
nova_utils.delete_all_instances()
@utils.tempest_logger
def test_alarm_with_resource_id(self):
try:
# Action
nova_utils.create_instances(num_instances=self.NUM_INSTANCE)
aodh_utils.create_aodh_alarm(self._find_instance_resource_id())
# Calculate expected results
api_graph = self.vitrage_client.topology.get(all_tenants=True)
graph = self._create_graph_from_graph_dictionary(api_graph)
entities = self._entities_validation_data(
host_entities=1,
host_edges=1 + self.NUM_INSTANCE,
instance_entities=self.NUM_INSTANCE,
instance_edges=2 * self.NUM_INSTANCE + self.NUM_ALARM,
aodh_entities=self.NUM_ALARM,
aodh_edges=self.NUM_ALARM)
num_entities = self.num_default_entities + \
2 * self.NUM_INSTANCE + self.NUM_ALARM + \
self.num_default_networks + self.num_default_ports
num_edges = self.num_default_edges + 3 * self.NUM_INSTANCE + \
self.NUM_ALARM + self.num_default_ports
# Action
nova_utils.create_instances(num_instances=self.NUM_INSTANCE)
aodh_utils.create_aodh_alarm(self._find_instance_resource_id())
# Calculate expected results
api_graph = self.vitrage_client.topology.get(all_tenants=True)
graph = self._create_graph_from_graph_dictionary(api_graph)
entities = self._entities_validation_data(
host_entities=1,
host_edges=1 + self.NUM_INSTANCE,
instance_entities=self.NUM_INSTANCE,
instance_edges=2 * self.NUM_INSTANCE + self.NUM_ALARM,
aodh_entities=self.NUM_ALARM,
aodh_edges=self.NUM_ALARM)
num_entities = self.num_default_entities + \
2 * self.NUM_INSTANCE + self.NUM_ALARM + \
self.num_default_networks + self.num_default_ports
num_edges = self.num_default_edges + 3 * self.NUM_INSTANCE + \
self.NUM_ALARM + self.num_default_ports
# Test Assertions
self._validate_graph_correctness(graph,
num_entities,
num_edges,
entities)
finally:
aodh_utils.delete_all_aodh_alarms()
nova_utils.delete_all_instances()
# Test Assertions
self._validate_graph_correctness(graph,
num_entities,
num_edges,
entities)
@utils.tempest_logger
def test_gnocchi_aggregation_by_metrics_threshold_alarm(self):
try:
# Action
nova_utils.create_instances(num_instances=self.NUM_INSTANCE)
aodh_utils.create_aodh_metrics_threshold_alarm()
# Action
nova_utils.create_instances(num_instances=self.NUM_INSTANCE)
aodh_utils.create_aodh_metrics_threshold_alarm()
api_graph = self.vitrage_client.topology.get(all_tenants=True)
graph = self._create_graph_from_graph_dictionary(api_graph)
entities = self._entities_validation_data(
host_entities=1,
host_edges=1 + self.NUM_INSTANCE,
instance_entities=self.NUM_INSTANCE,
instance_edges=2 * self.NUM_INSTANCE,
aodh_entities=self.NUM_ALARM,
aodh_edges=0)
num_entities = self.num_default_entities + \
2 * self.NUM_INSTANCE + self.NUM_ALARM + \
self.num_default_networks + self.num_default_ports
num_edges = self.num_default_edges + 3 * self.NUM_INSTANCE + \
self.num_default_ports
api_graph = self.vitrage_client.topology.get(all_tenants=True)
graph = self._create_graph_from_graph_dictionary(api_graph)
entities = self._entities_validation_data(
host_entities=1,
host_edges=1 + self.NUM_INSTANCE,
instance_entities=self.NUM_INSTANCE,
instance_edges=2 * self.NUM_INSTANCE,
aodh_entities=self.NUM_ALARM,
aodh_edges=0)
num_entities = self.num_default_entities + \
2 * self.NUM_INSTANCE + self.NUM_ALARM + \
self.num_default_networks + self.num_default_ports
num_edges = self.num_default_edges + 3 * self.NUM_INSTANCE + \
self.num_default_ports
self._validate_graph_correctness(graph,
num_entities,
num_edges,
entities)
finally:
aodh_utils.delete_all_aodh_alarms()
aodh_utils.delete_all_gnocchi_metrics()
nova_utils.delete_all_instances()
self._validate_graph_correctness(graph,
num_entities,
num_edges,
entities)
@utils.tempest_logger
def test_gnocchi_aggregation_by_resources_threshold(self):
try:
# Action
nova_utils.create_instances(num_instances=self.NUM_INSTANCE)
aodh_utils.create_aodh_resources_threshold_alarm(
resource_id=self._find_instance_resource_id())
# Action
nova_utils.create_instances(num_instances=self.NUM_INSTANCE)
aodh_utils.create_aodh_resources_threshold_alarm(
resource_id=self._find_instance_resource_id())
api_graph = self.vitrage_client.topology.get(all_tenants=True)
graph = self._create_graph_from_graph_dictionary(api_graph)
entities = self._entities_validation_data(
host_entities=1,
host_edges=1 + self.NUM_INSTANCE,
instance_entities=self.NUM_INSTANCE,
instance_edges=2 * self.NUM_INSTANCE + self.NUM_ALARM,
aodh_entities=self.NUM_ALARM,
aodh_edges=self.NUM_ALARM)
num_entities = self.num_default_entities + \
2 * self.NUM_INSTANCE + self.NUM_ALARM + \
self.num_default_networks + self.num_default_ports
num_edges = self.num_default_edges + 3 * self.NUM_INSTANCE + \
+ self.NUM_ALARM + self.num_default_ports
api_graph = self.vitrage_client.topology.get(all_tenants=True)
graph = self._create_graph_from_graph_dictionary(api_graph)
entities = self._entities_validation_data(
host_entities=1,
host_edges=1 + self.NUM_INSTANCE,
instance_entities=self.NUM_INSTANCE,
instance_edges=2 * self.NUM_INSTANCE + self.NUM_ALARM,
aodh_entities=self.NUM_ALARM,
aodh_edges=self.NUM_ALARM)
num_entities = self.num_default_entities + \
2 * self.NUM_INSTANCE + self.NUM_ALARM + \
self.num_default_networks + self.num_default_ports
num_edges = self.num_default_edges + 3 * self.NUM_INSTANCE + \
+ self.NUM_ALARM + self.num_default_ports
self._validate_graph_correctness(graph,
num_entities,
num_edges,
entities)
finally:
aodh_utils.delete_all_aodh_alarms()
aodh_utils.delete_all_gnocchi_metrics()
nova_utils.delete_all_instances()
self._validate_graph_correctness(graph,
num_entities,
num_edges,
entities)
@utils.tempest_logger
def test_alarm_without_resource_id(self):
try:
# Action
aodh_utils.create_aodh_alarm()
# Action
aodh_utils.create_aodh_alarm()
# Calculate expected results
api_graph = self.vitrage_client.topology.get(all_tenants=True)
graph = self._create_graph_from_graph_dictionary(api_graph)
entities = self._entities_validation_data(
host_entities=1,
host_edges=1,
aodh_entities=self.NUM_ALARM,
aodh_edges=0)
num_entities = self.num_default_entities + self.NUM_ALARM + \
self.num_default_networks + self.num_default_ports
num_edges = self.num_default_edges + self.num_default_ports
# Calculate expected results
api_graph = self.vitrage_client.topology.get(all_tenants=True)
graph = self._create_graph_from_graph_dictionary(api_graph)
entities = self._entities_validation_data(
host_entities=1,
host_edges=1,
aodh_entities=self.NUM_ALARM,
aodh_edges=0)
num_entities = self.num_default_entities + self.NUM_ALARM + \
self.num_default_networks + self.num_default_ports
num_edges = self.num_default_edges + self.num_default_ports
# Test Assertions
self._validate_graph_correctness(graph,
num_entities,
num_edges,
entities)
finally:
aodh_utils.delete_all_aodh_alarms()
# Test Assertions
self._validate_graph_correctness(graph,
num_entities,
num_edges,
entities)
def _find_instance_resource_id(self):
@staticmethod
def _find_instance_resource_id():
servers = TempestClients.nova().servers.list()
return servers[0].id

View File

@ -23,6 +23,10 @@ class TestCinderVolume(BaseTopologyTest):
NUM_INSTANCE = 3
NUM_VOLUME = 1
def tearDown(self):
super(TestCinderVolume, self).tearDown()
self._rollback_to_default()
@utils.tempest_logger
def test_volume(self):
# Action

View File

@ -28,6 +28,10 @@ LOG = logging.getLogger(__name__)
class TestHeatStack(BaseTopologyTest):
NUM_STACKS = 1
def tearDown(self):
super(TestHeatStack, self).tearDown()
heat_utils.delete_all_stacks()
@utils.tempest_logger
def test_nested_heat_stack(self):
self._test_heat_stack(nested=True,
@ -44,34 +48,31 @@ class TestHeatStack(BaseTopologyTest):
"""
template_file = tempest_resources_dir() + '/heat/' + tmpl_file
image = glance_utils.get_first_image()
try:
# Action
heat_utils.create_stacks(self.NUM_STACKS, nested, template_file,
image['name'])
# Action
heat_utils.create_stacks(self.NUM_STACKS, nested, template_file,
image['name'])
# Calculate expected results
api_graph = self.vitrage_client.topology.get(all_tenants=True)
graph = self._create_graph_from_graph_dictionary(api_graph)
entities = self._entities_validation_data(
host_entities=1,
host_edges=1 + self.NUM_STACKS,
instance_entities=self.NUM_STACKS,
instance_edges=3 * self.NUM_STACKS,
network_entities=self.num_default_networks,
network_edges=self.num_default_ports + self.NUM_STACKS,
port_entities=self.num_default_ports + self.NUM_STACKS,
port_edges=self.num_default_ports + 2 * self.NUM_STACKS,
stack_entities=self.NUM_STACKS,
stack_edges=self.NUM_STACKS)
num_entities = self.num_default_entities + 3 * self.NUM_STACKS + \
self.num_default_networks + self.num_default_ports
num_edges = self.num_default_edges + 4 * self.NUM_STACKS + \
self.num_default_ports
# Calculate expected results
api_graph = self.vitrage_client.topology.get(all_tenants=True)
graph = self._create_graph_from_graph_dictionary(api_graph)
entities = self._entities_validation_data(
host_entities=1,
host_edges=1 + self.NUM_STACKS,
instance_entities=self.NUM_STACKS,
instance_edges=3 * self.NUM_STACKS,
network_entities=self.num_default_networks,
network_edges=self.num_default_ports + self.NUM_STACKS,
port_entities=self.num_default_ports + self.NUM_STACKS,
port_edges=self.num_default_ports + 2 * self.NUM_STACKS,
stack_entities=self.NUM_STACKS,
stack_edges=self.NUM_STACKS)
num_entities = self.num_default_entities + 3 * self.NUM_STACKS + \
self.num_default_networks + self.num_default_ports
num_edges = self.num_default_edges + 4 * self.NUM_STACKS + \
self.num_default_ports
# Test Assertions
self._validate_graph_correctness(graph,
num_entities,
num_edges,
entities)
finally:
heat_utils.delete_all_stacks()
# Test Assertions
self._validate_graph_correctness(graph,
num_entities,
num_edges,
entities)

View File

@ -15,9 +15,6 @@
from oslo_log import log as logging
from vitrage_tempest_plugin.tests.api.topology.base import BaseTopologyTest
from vitrage_tempest_plugin.tests.common.constants import VertexProperties as \
VProps
from vitrage_tempest_plugin.tests.common import general_utils as g_utils
from vitrage_tempest_plugin.tests.common import nova_utils
from vitrage_tempest_plugin.tests import utils
@ -27,6 +24,10 @@ LOG = logging.getLogger(__name__)
class TestNeutron(BaseTopologyTest):
NUM_INSTANCE = 3
def tearDown(self):
super(TestNeutron, self).tearDown()
nova_utils.delete_all_instances()
@utils.tempest_logger
def test_neutron(self):
"""neutron test
@ -34,65 +35,30 @@ class TestNeutron(BaseTopologyTest):
This test validate correctness topology graph with neutron module
"""
try:
# Action
nova_utils.create_instances(num_instances=self.NUM_INSTANCE,
set_public_network=True)
# Action
nova_utils.create_instances(num_instances=self.NUM_INSTANCE,
set_public_network=True)
# Calculate expected results
api_graph = self.vitrage_client.topology.get(all_tenants=True)
graph = self._create_graph_from_graph_dictionary(api_graph)
entities = self._entities_validation_data(
host_entities=1,
host_edges=1 + self.NUM_INSTANCE,
instance_entities=self.NUM_INSTANCE,
instance_edges=2 * self.NUM_INSTANCE,
network_entities=self.num_default_networks,
network_edges=self.num_default_ports + self.NUM_INSTANCE,
port_entities=self.num_default_ports + self.NUM_INSTANCE,
port_edges=self.num_default_ports + 2 * self.NUM_INSTANCE)
num_entities = self.num_default_entities + \
2 * self.NUM_INSTANCE + \
self.num_default_networks + self.num_default_ports
num_edges = self.num_default_edges + 3 * self.NUM_INSTANCE + \
self.num_default_ports
# Calculate expected results
api_graph = self.vitrage_client.topology.get(all_tenants=True)
graph = self._create_graph_from_graph_dictionary(api_graph)
entities = self._entities_validation_data(
host_entities=1,
host_edges=1 + self.NUM_INSTANCE,
instance_entities=self.NUM_INSTANCE,
instance_edges=2 * self.NUM_INSTANCE,
network_entities=self.num_default_networks,
network_edges=self.num_default_ports + self.NUM_INSTANCE,
port_entities=self.num_default_ports + self.NUM_INSTANCE,
port_edges=self.num_default_ports + 2 * self.NUM_INSTANCE)
num_entities = self.num_default_entities + \
2 * self.NUM_INSTANCE + \
self.num_default_networks + self.num_default_ports
num_edges = self.num_default_edges + 3 * self.NUM_INSTANCE + \
self.num_default_ports
# Test Assertions
self._validate_graph_correctness(graph,
num_entities,
num_edges,
entities)
finally:
nova_utils.delete_all_instances()
@staticmethod
def _get_network_name(instance, networks):
for network in networks:
try:
if len(instance.networks[network[VProps.NAME]]) > 0:
return network[VProps.NAME]
except Exception:
pass
return None
@staticmethod
def _port_to_inst_edges(instances, network_name, ports):
counter = 0
for vm in instances:
for port in ports:
ips_number = 0
for vm_ip in vm.addresses[network_name]:
for port_ip in port['fixed_ips']:
if vm_ip['addr'] == port_ip['ip_address']:
ips_number += 1
break
if ips_number == len(vm.addresses[network_name]):
counter += 1
break
return counter
def _port_to_network_edges(self, networks, ports):
counter = 0
for net in networks:
counter += len(g_utils.all_matches(ports, network_id=net['id']))
return counter
# Test Assertions
self._validate_graph_correctness(graph,
num_entities,
num_edges,
entities)

View File

@ -22,6 +22,10 @@ LOG = logging.getLogger(__name__)
class TestNova(BaseTopologyTest):
NUM_INSTANCE = 3
def tearDown(self):
super(TestNova, self).tearDown()
self._rollback_to_default()
@utils.tempest_logger
def test_nova_entities(self):
# Action

View File

@ -44,32 +44,27 @@ class TestPrometheus(BaseTestEvents):
FIRING))
def _test_send_prometheus_alert(self, details):
try:
# post an event to the message bus
event_time = datetime.now()
event_type = 'prometheus.alarm'
self._post_event(event_time, event_type, details)
api_alarms = wait_for_answer(2, 0.5, self._check_alarms)
# post an event to the message bus
event_time = datetime.now()
event_type = 'prometheus.alarm'
self._post_event(event_time, event_type, details)
api_alarms = wait_for_answer(2, 0.5, self._check_alarms)
# expect to get a 'prometheus.alarm', generated by Prometheus
# datasource
self.assertThat(api_alarms, matchers.HasLength(1),
'Expected Prometheus alarm')
# expect to get a 'prometheus.alarm', generated by Prometheus
# datasource
self.assertThat(api_alarms, matchers.HasLength(1),
'Expected Prometheus alarm')
alarm = api_alarms[0]
self._check_alarm(alarm, details)
alarm = api_alarms[0]
self._check_alarm(alarm, details)
event_time = datetime.now()
self._resolve_alerts(details)
self._post_event(event_time, event_type, details)
event_time = datetime.now()
self._resolve_alerts(details)
self._post_event(event_time, event_type, details)
api_alarms = wait_for_answer(2, 0.5, self._check_alarms)
self.assertIsNotNone(api_alarms,)
self.assertThat(api_alarms, IsEmpty(), 'Expected no alarms')
except Exception as e:
LOG.exception(e)
raise
api_alarms = wait_for_answer(2, 0.5, self._check_alarms)
self.assertIsNotNone(api_alarms)
self.assertThat(api_alarms, IsEmpty(), 'Expected no alarms')
def _check_alarm(self, alarm, details):
self.assertEqual(EntityCategory.ALARM, alarm[VProps.VITRAGE_CATEGORY])

View File

@ -29,35 +29,37 @@ class TestStatic(BaseVitrageTempest):
NUM_SWITCH = 1
NUM_NIC = 1
def setUp(self):
super(TestStatic, self).setUp()
self._create_switches()
def tearDown(self):
super(TestStatic, self).tearDown()
self._delete_switches()
@utils.tempest_logger
def test_switches(self):
try:
# Action
self._create_switches()
# Calculate expected results
api_graph = self.vitrage_client.topology.get(all_tenants=True)
graph = self._create_graph_from_graph_dictionary(api_graph)
entities = self._entities_validation_data(
host_entities=1,
host_edges=1,
switch_entities=self.NUM_SWITCH,
switch_edges=1,
nic_entities=self.NUM_NIC,
nic_edges=1)
num_entities = self.num_default_entities + self.NUM_SWITCH + \
self.NUM_NIC + self.num_default_networks + \
self.num_default_ports
num_edges = self.num_default_edges + self.NUM_SWITCH + \
self.num_default_ports
# Calculate expected results
api_graph = self.vitrage_client.topology.get(all_tenants=True)
graph = self._create_graph_from_graph_dictionary(api_graph)
entities = self._entities_validation_data(
host_entities=1,
host_edges=1,
switch_entities=self.NUM_SWITCH,
switch_edges=1,
nic_entities=self.NUM_NIC,
nic_edges=1)
num_entities = self.num_default_entities + self.NUM_SWITCH + \
self.NUM_NIC + self.num_default_networks + \
self.num_default_ports
num_edges = self.num_default_edges + self.NUM_SWITCH + \
self.num_default_ports
# Test Assertions
self._validate_graph_correctness(graph,
num_entities,
num_edges,
entities)
finally:
self._delete_switches()
# Test Assertions
self._validate_graph_correctness(graph,
num_entities,
num_edges,
entities)
@staticmethod
def _create_switches():

View File

@ -33,7 +33,7 @@ class TestActionsBase(BaseVitrageTempest):
if not host:
raise Exception("No host found")
if not host.get(VProps.VITRAGE_AGGREGATED_STATE) == 'AVAILABLE':
raise Exception("Host is not running %s", str(host))
raise Exception("Host is not running %s" % host)
cls.orig_host = host
def _trigger_do_action(self, trigger_name):
@ -58,7 +58,7 @@ class TestActionsBase(BaseVitrageTempest):
deduces = g_utils.all_matches(alarms, **deduced_props)
self.assertThat(deduces, matchers.HasLength(deduced_count),
'Expected %s deduces\n - \n%s\n - \n%s' %
(str(deduced_count), str(alarms), str(deduces)))
(deduced_count, alarms, deduces))
def _check_rca(self, rca, expected_alarms, inspected):
rca_nodes = [n for n in rca['nodes'] if not n.get('end_timestamp')]
@ -66,8 +66,8 @@ class TestActionsBase(BaseVitrageTempest):
for expected_alarm in expected_alarms:
self.assertIsNotNone(
g_utils.first_match(rca_nodes, **expected_alarm),
'expected_alarm is not in the rca %s' % str(expected_alarm))
'expected_alarm is not in the rca %s' % expected_alarm)
rca_inspected = rca['nodes'][rca['inspected_index']]
self.assertTrue(g_utils.is_subset(inspected, rca_inspected),
'Invalid inspected item \n%s\n%s' %
(str(rca_inspected), str(inspected)))
(rca_inspected, inspected))

View File

@ -256,7 +256,7 @@ class TestBasicActions(TestActionsBase):
alarms = self.vitrage_client.alarm.list(
vitrage_id=self.orig_host.get(VProps.VITRAGE_ID),
all_tenants=True)
self.assertTrue(len(alarms) >= 2, 'alarms %s' % str(alarms))
self.assertTrue(len(alarms) >= 2, 'alarms %s' % alarms)
deduced = g_utils.first_match(alarms, **deduced_props)
trigger = g_utils.first_match(alarms, **trigger_alarm_props)

View File

@ -329,7 +329,7 @@ class MockHTTPServer(BaseHTTPServer.HTTPServer):
def process_request(self, request, client_address):
self.requests.append(request)
LOG.info('received request: %s', str(request))
LOG.info('received request: %s', request)
BaseHTTPServer.HTTPServer.process_request(
self, client_address=client_address, request=request)

View File

@ -132,11 +132,11 @@ class TestOverlappingActions(TestActionsBase):
self._trigger_undo_action(TRIGGER_ALARM_4)
nova_service = TempestClients.nova().services.list(
host=host_name, binary='nova-compute')[0]
self.assertEqual("up", str(nova_service.state))
self.assertEqual("up", nova_service.state)
finally:
self._trigger_undo_action(TRIGGER_ALARM_3)
self._trigger_undo_action(TRIGGER_ALARM_4)
# nova.host datasource may take up to snapshot_intreval to update
# nova.host datasource may take up to snapshot_interval to update
time.sleep(130)
@utils.tempest_logger

View File

@ -1,5 +1,7 @@
metadata:
name: corrupted_template
type: standard
version: 2
definitions:
entities:
- entity:

View File

@ -1,5 +1,7 @@
metadata:
name: first_deduced_alarm_ever_nagios
type: standard
version: 2
definitions:
entities:
- entity: