Merge "use vitrage_client attribute where possible"

This commit is contained in:
Zuul 2019-02-26 09:47:06 +00:00 committed by Gerrit Code Review
commit 8f4de82480
10 changed files with 75 additions and 104 deletions

View File

@ -35,7 +35,6 @@ from vitrage_tempest_plugin.tests.common.constants import VertexProperties \
from vitrage_tempest_plugin.tests.common.constants import VITRAGE_DATASOURCE
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.common.tempest_clients import TempestClients
from vitrage_tempest_plugin.tests.common import vitrage_utils
LOG = logging.getLogger(__name__)
@ -45,7 +44,8 @@ VITRAGE_ALARM_NAME = 'instance_deduce'
class BaseRcaTest(BaseAlarmsTest):
def _clean_all(self):
@staticmethod
def _clean_all():
nova_utils.delete_all_instances()
aodh_utils.delete_all_aodh_alarms()
@ -102,7 +102,7 @@ class BaseRcaTest(BaseAlarmsTest):
LOG.info("The alarms list is : " + str(json.dumps(alarms)))
# Find the vitrage_id of the deduced alarms using their original id.
vitrage_resources = TempestClients.vitrage().resource.list(
vitrage_resources = self.vitrage_client.resource.list(
all_tenants=False)
vitrage_instance_0_id = g_utils.first_match(vitrage_resources,
id=instances[0].id)

View File

@ -23,7 +23,6 @@ from vitrage_tempest_plugin.tests.common.constants import TemplateStatus
from vitrage_tempest_plugin.tests.common.constants import TemplateTypes as \
TTypes
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
@ -110,11 +109,6 @@ class TestValidate(BaseTemplateTest):
class TemplatesDBTest(BaseTemplateTest):
"""Template DB test class for vitrage API tests"""
@classmethod
def setUpClass(cls):
super(TemplatesDBTest, cls).setUpClass()
cls.client = TempestClients.vitrage()
def test_template_add(self):
"""template add test
@ -193,7 +187,7 @@ class TemplatesDBTest(BaseTemplateTest):
templates_names = self._add_templates()
cli_templates_list = utils.run_vitrage_command(
"vitrage template list")
api_templates_list = self.client.template.list()
api_templates_list = self.vitrage_client.template.list()
self.assertThat(api_templates_list, IsNotEmpty(),
'The template list taken from api is empty')
@ -220,7 +214,7 @@ class TemplatesDBTest(BaseTemplateTest):
name='host_high_memory_usage_scenarios',
type=TTypes.STANDARD,
status=TemplateStatus.ACTIVE)
payload_from_db = self.client.template.show(db_row['uuid'])
payload_from_db = self.vitrage_client.template.show(db_row['uuid'])
with open(template_path, 'r') as stream:
payload_from_file = yaml.load(stream, Loader=yaml.BaseLoader)
self.assert_dict_equal(payload_from_file, payload_from_db,

View File

@ -16,7 +16,6 @@ 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
from vitrageclient.exceptions import ClientException
LOG = logging.getLogger(__name__)
@ -35,17 +34,17 @@ class TestWebhook(BaseVitrageTempest):
def setUpClass(cls):
super(TestWebhook, cls).setUpClass()
cls.pre_test_webhook_count = \
len(TempestClients.vitrage().webhook.list())
len(cls.vitrage_client.webhook.list())
def test_add_webhook(self):
webhooks = TempestClients.vitrage().webhook.list()
webhooks = self.vitrage_client.webhook.list()
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(
created_webhook = self.vitrage_client.webhook.add(
url="https://www.test.com",
regex_filter=REGEX_PROPS,
headers=HEADERS_PROPS
@ -63,27 +62,27 @@ class TestWebhook(BaseVitrageTempest):
"https://www.test.com",
'URL not created correctly')
webhooks = TempestClients.vitrage().webhook.list()
webhooks = self.vitrage_client.webhook.list()
self.assertThat(webhooks,
matchers.HasLength(self.pre_test_webhook_count + 1))
TempestClients.vitrage().webhook.delete(
self.vitrage_client.webhook.delete(
created_webhook['id'])
def test_delete_webhook(self):
webhooks = TempestClients.vitrage().webhook.list()
webhooks = self.vitrage_client.webhook.list()
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(
created_webhook = self.vitrage_client.webhook.add(
url="https://www.test.com",
regex_filter=REGEX_PROPS,
headers=HEADERS_PROPS
)
created_webhook = TempestClients.vitrage().webhook.delete(
created_webhook = self.vitrage_client.webhook.delete(
id=created_webhook['id'])
self.assertIsNotNone(created_webhook.get('SUCCESS'),
'failed to delete')
@ -93,24 +92,24 @@ class TestWebhook(BaseVitrageTempest):
def test_delete_non_existing_webhook(self):
self.assertRaises(ClientException,
TempestClients.vitrage().webhook.delete,
self.vitrage_client.webhook.delete,
('non existant'))
def test_list_webhook(self):
webhooks = TempestClients.vitrage().webhook.list()
webhooks = self.vitrage_client.webhook.list()
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(
created_webhook = self.vitrage_client.webhook.add(
url="https://www.test.com",
regex_filter=REGEX_PROPS,
headers=HEADERS_PROPS
)
webhooks = TempestClients.vitrage().webhook.list()
webhooks = self.vitrage_client.webhook.list()
self.assertThat(webhooks,
matchers.HasLength(self.pre_test_webhook_count + 1))
self.assertEqual(created_webhook[HEADERS], webhooks[0][HEADERS])
@ -118,25 +117,22 @@ class TestWebhook(BaseVitrageTempest):
self.assertEqual(created_webhook[REGEX_FILTER],
webhooks[0][REGEX_FILTER])
TempestClients.vitrage().webhook.delete(
created_webhook['id'])
self.vitrage_client.webhook.delete(created_webhook['id'])
def test_show_webhook(self):
webhooks = TempestClients.vitrage().webhook.list()
webhooks = self.vitrage_client.webhook.list()
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(
created_webhook = self.vitrage_client.webhook.add(
url="https://www.test.com",
regex_filter=REGEX_PROPS,
headers=HEADERS_PROPS
)
show_webhook = TempestClients.vitrage().webhook.show(
created_webhook['id']
)
show_webhook = self.vitrage_client.webhook.show(created_webhook['id'])
self.assertIsNotNone(show_webhook, 'webhook not listed')
self.assertEqual(created_webhook[HEADERS],
@ -149,5 +145,4 @@ class TestWebhook(BaseVitrageTempest):
show_webhook[URL],
'URL mismatch')
TempestClients.vitrage().webhook.delete(
created_webhook['id'])
self.vitrage_client.webhook.delete(created_webhook['id'])

View File

@ -117,6 +117,8 @@ class BaseVitrageTempest(test.BaseTestCase):
warnings.filterwarnings(action="ignore",
message="unclosed",
category=ResourceWarning)
logger = logging.getLogger('urllib3.connectionpool').logger
logger.setLevel(logging.INFO)
def tearDown(self):
super(BaseVitrageTempest, self).tearDown()

View File

@ -20,7 +20,6 @@ from vitrage_tempest_plugin.tests.base import BaseVitrageTempest
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.tempest_clients import TempestClients
from vitrage_tempest_plugin.tests.common import vitrage_utils
LOG = logging.getLogger(__name__)
@ -54,9 +53,8 @@ class TestActionsBase(BaseVitrageTempest):
time.sleep(2)
def _check_deduced(self, deduced_count, deduced_props, resource_id):
alarms = TempestClients.vitrage().alarm.list(
vitrage_id=resource_id,
all_tenants=True)
alarms = self.vitrage_client.alarm.list(vitrage_id=resource_id,
all_tenants=True)
deduces = g_utils.all_matches(alarms, **deduced_props)
self.assertThat(deduces, matchers.HasLength(deduced_count),
'Expected %s deduces\n - \n%s\n - \n%s' %

View File

@ -253,7 +253,7 @@ class TestBasicActions(TestActionsBase):
try:
# Do
self._trigger_do_action(trigger_name)
alarms = TempestClients.vitrage().alarm.list(
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))
@ -262,13 +262,13 @@ class TestBasicActions(TestActionsBase):
trigger = g_utils.first_match(alarms, **trigger_alarm_props)
# Get Rca for the deduced
rca = TempestClients.vitrage().rca.get(
deduced[VProps.VITRAGE_ID], all_tenants=True)
rca = self.vitrage_client.rca.get(deduced[VProps.VITRAGE_ID],
all_tenants=True)
self._check_rca(rca, [deduced, trigger], deduced_props)
# Get Rca for the trigger
rca = TempestClients.vitrage().rca.get(
trigger[VProps.VITRAGE_ID], all_tenants=True)
rca = self.vitrage_client.rca.get(trigger[VProps.VITRAGE_ID],
all_tenants=True)
self._check_rca(rca, [deduced, trigger], trigger_alarm_props)
finally:
self._trigger_undo_action(trigger_name)

View File

@ -24,7 +24,6 @@ import time
from vitrage_tempest_plugin.tests.base import IsEmpty
from vitrage_tempest_plugin.tests.common.constants import VertexProperties as \
VProps
from vitrage_tempest_plugin.tests.common.tempest_clients import TempestClients
from vitrage_tempest_plugin.tests.common import vitrage_utils as v_utils
from vitrage_tempest_plugin.tests.e2e.test_actions_base import TestActionsBase
@ -100,11 +99,9 @@ class TestWebhook(TestActionsBase):
try:
# Add webhook with filter matching alarm
TempestClients.vitrage().webhook.add(
url=self.URL_PROPS,
regex_filter=NAME_FILTER,
headers=HEADERS_PROPS
)
self.vitrage_client.webhook.add(url=self.URL_PROPS,
regex_filter=NAME_FILTER,
headers=HEADERS_PROPS)
# Raise alarm
self._trigger_do_action(TRIGGER_ALARM_1)
@ -133,10 +130,8 @@ class TestWebhook(TestActionsBase):
try:
# Add webhook
TempestClients.vitrage().webhook.add(
url=self.URL_PROPS,
regex_filter=NAME_FILTER,
)
self.vitrage_client.webhook.add(url=self.URL_PROPS,
regex_filter=NAME_FILTER)
# Raise alarm
self._trigger_do_action(TRIGGER_ALARM_1)
@ -163,10 +158,8 @@ class TestWebhook(TestActionsBase):
try:
# Add webhook
TempestClients.vitrage().webhook.add(
url=self.URL_PROPS,
regex_filter=FILTER_NO_MATCH,
)
self.vitrage_client.webhook.add(url=self.URL_PROPS,
regex_filter=FILTER_NO_MATCH)
# Raise alarm
self._trigger_do_action(TRIGGER_ALARM_1)
@ -196,14 +189,10 @@ class TestWebhook(TestActionsBase):
try:
# Add webhook
TempestClients.vitrage().webhook.add(
url=self.URL_PROPS,
regex_filter=TYPE_FILTER,
)
self.vitrage_client.webhook.add(url=self.URL_PROPS,
regex_filter=TYPE_FILTER)
TempestClients.vitrage().webhook.add(
url=self.URL_PROPS
)
self.vitrage_client.webhook.add(url=self.URL_PROPS)
# Raise alarm
self._trigger_do_action(TRIGGER_ALARM_1)
@ -228,11 +217,10 @@ class TestWebhook(TestActionsBase):
try:
# Add webhook with filter for the deduced alarm
TempestClients.vitrage().webhook.add(
self.vitrage_client.webhook.add(
url=self.URL_PROPS,
regex_filter=NAME_FILTER_FOR_DEDUCED,
headers=HEADERS_PROPS
)
headers=HEADERS_PROPS)
# Raise the trigger alarm
self._trigger_do_action(TRIGGER_ALARM_WITH_DEDUCED)
@ -261,10 +249,8 @@ class TestWebhook(TestActionsBase):
try:
TempestClients.vitrage().webhook.add(
url=self.URL_PROPS,
headers=HEADERS_PROPS
)
self.vitrage_client.webhook.add(url=self.URL_PROPS,
headers=HEADERS_PROPS)
# Raise the trigger alarm
self._trigger_do_action(TRIGGER_ALARM_1)
@ -319,11 +305,11 @@ class TestWebhook(TestActionsBase):
finally:
self._trigger_undo_action(TRIGGER_ALARM_1)
@staticmethod
def _delete_webhooks():
webhooks = TempestClients.vitrage().webhook.list()
@classmethod
def _delete_webhooks(cls):
webhooks = cls.vitrage_client.webhook.list()
for webhook in webhooks:
TempestClients.vitrage().webhook.delete(webhook['id'])
cls.vitrage_client.webhook.delete(webhook['id'])
def _get_free_port():

View File

@ -169,7 +169,7 @@ class TestOverlappingActions(TestActionsBase):
# ---- Do first & second ----
self._trigger_do_action(TRIGGER_ALARM_1)
self._trigger_do_action(TRIGGER_ALARM_2)
alarms = TempestClients.vitrage().alarm.list(
alarms = self.vitrage_client.alarm.list(
vitrage_id=self.orig_host.get(VProps.VITRAGE_ID),
all_tenants=True)
@ -178,23 +178,23 @@ class TestOverlappingActions(TestActionsBase):
trigger2 = g_utils.first_match(alarms, **TRIGGER_ALARM_2_PROPS)
# Get Rca for the deduced
rca = TempestClients.vitrage().rca.get(
deduced[VProps.VITRAGE_ID], all_tenants=True)
rca = self.vitrage_client.rca.get(deduced[VProps.VITRAGE_ID],
all_tenants=True)
self._check_rca(rca, [deduced, trigger1, trigger2], DEDUCED_PROPS)
# Get Rca for trigger 1
rca = TempestClients.vitrage().rca.get(
trigger1[VProps.VITRAGE_ID], all_tenants=True)
rca = self.vitrage_client.rca.get(trigger1[VProps.VITRAGE_ID],
all_tenants=True)
self._check_rca(rca, [deduced, trigger1], TRIGGER_ALARM_1_PROPS)
# Get Rca for trigger 2
rca = TempestClients.vitrage().rca.get(
trigger2[VProps.VITRAGE_ID], all_tenants=True)
rca = self.vitrage_client.rca.get(trigger2[VProps.VITRAGE_ID],
all_tenants=True)
self._check_rca(rca, [deduced, trigger2], TRIGGER_ALARM_2_PROPS)
# ---- Undo - first ----
self._trigger_undo_action(TRIGGER_ALARM_1)
alarms = TempestClients.vitrage().alarm.list(
alarms = self.vitrage_client.alarm.list(
vitrage_id=self.orig_host.get(VProps.VITRAGE_ID),
all_tenants=True)
@ -202,18 +202,18 @@ class TestOverlappingActions(TestActionsBase):
trigger2 = g_utils.first_match(alarms, **TRIGGER_ALARM_2_PROPS)
# Get Rca for the deduced
rca = TempestClients.vitrage().rca.get(
deduced[VProps.VITRAGE_ID], all_tenants=True)
rca = self.vitrage_client.rca.get(deduced[VProps.VITRAGE_ID],
all_tenants=True)
self._check_rca(rca, [deduced, trigger2], DEDUCED_PROPS)
# Get Rca for trigger 2
rca = TempestClients.vitrage().rca.get(
trigger2[VProps.VITRAGE_ID], all_tenants=True)
rca = self.vitrage_client.rca.get(trigger2[VProps.VITRAGE_ID],
all_tenants=True)
self._check_rca(rca, [deduced, trigger2], TRIGGER_ALARM_2_PROPS)
# ---- Undo - second ----
self._trigger_undo_action(TRIGGER_ALARM_2)
alarms = TempestClients.vitrage().alarm.list(
alarms = self.vitrage_client.alarm.list(
vitrage_id=self.orig_host.get(VProps.VITRAGE_ID),
all_tenants=True)
self.assertThat(

View File

@ -178,10 +178,10 @@ class TestMistralNotifier(BaseTestEvents):
num_alarms=num_alarms),
'Vitrage trigger alarm was not deleted')
@staticmethod
def _check_num_vitrage_alarms(num_alarms):
vitrage_alarms = TempestClients.vitrage().alarm.list(vitrage_id='all',
all_tenants=True)
@classmethod
def _check_num_vitrage_alarms(cls, num_alarms):
vitrage_alarms = cls.vitrage_client.alarm.list(vitrage_id='all',
all_tenants=True)
if len(vitrage_alarms) == num_alarms:
return True
return False

View File

@ -21,7 +21,6 @@ from tempest import config
from vitrage_tempest_plugin.tests.common.constants import VertexProperties
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
from vitrage_tempest_plugin.tests.e2e.test_actions_base import TestActionsBase
from vitrage_tempest_plugin.tests import utils
@ -86,8 +85,7 @@ class TestLongProcessing(TestActionsBase):
time.sleep(MAX_FAIL_OVER_TIME)
doctor_events_thread.join(timeout=10)
alarm_count = TempestClients.vitrage().alarm.count(
all_tenants=True)
alarm_count = self.vitrage_client.alarm.count(all_tenants=True)
self.assertTrue(self.num_of_sent_events > 0,
'Test did not create events')
self.assertEqual(
@ -106,12 +104,12 @@ class TestLongProcessing(TestActionsBase):
self._check_template_instance_3rd_degree_scenarios()
# 2. check fast fail-over - start from database
topo1 = TempestClients.vitrage().topology.get(all_tenants=True)
topo1 = self.vitrage_client.topology.get(all_tenants=True)
v_utils.restart_graph()
time.sleep(MAX_FAIL_OVER_TIME)
for i in range(5):
self._check_template_instance_3rd_degree_scenarios()
topo2 = TempestClients.vitrage().topology.get(all_tenants=True)
topo2 = self.vitrage_client.topology.get(all_tenants=True)
self.assert_graph_equal(
topo1, topo2, 'comparing graph items iteration ' + str(i))
time.sleep(CONF.root_cause_analysis_service.snapshots_interval)
@ -122,8 +120,7 @@ class TestLongProcessing(TestActionsBase):
def _check_template_instance_3rd_degree_scenarios(self):
alarm_count = TempestClients.vitrage().alarm.count(
all_tenants=True)
alarm_count = self.vitrage_client.alarm.count(all_tenants=True)
self.assertEqual(
CONF.root_cause_analysis_service.instances_per_host,
alarm_count['SEVERE'],
@ -138,8 +135,8 @@ class TestLongProcessing(TestActionsBase):
expected_rca.extend([{'name': DEDUCED_1}, {'name': DEDUCED_2}])
def check_rca(alarm):
rca = TempestClients.vitrage().rca.get(alarm['vitrage_id'],
all_tenants=True)
rca = self.vitrage_client.rca.get(alarm['vitrage_id'],
all_tenants=True)
try:
self._check_rca(rca, expected_rca, alarm)
return True
@ -148,8 +145,8 @@ class TestLongProcessing(TestActionsBase):
return False
# 10 threads calling rca api
alarms = TempestClients.vitrage().alarm.list(all_tenants=True,
vitrage_id='all')
alarms = self.vitrage_client.alarm.list(all_tenants=True,
vitrage_id='all')
deduced_alarms = g_utils.all_matches(
alarms, vitrage_type='vitrage', name=DEDUCED_2)
workers = futures.ThreadPoolExecutor(max_workers=10)
@ -158,8 +155,7 @@ class TestLongProcessing(TestActionsBase):
self.assertTrue(all(workers_result))
def _check_template_instance_3rd_degree_scenarios_deleted(self):
alarm_count = TempestClients.vitrage().alarm.count(
all_tenants=True)
alarm_count = self.vitrage_client.alarm.count(all_tenants=True)
self.assertEqual(
0,
alarm_count['SEVERE'],