Change-Id: If2e622ac04eb5cd9dd62f96103fc0f1772713bb5
This commit is contained in:
Ifat Afek 2018-01-02 09:58:12 +00:00
parent f0f878fa50
commit b2c343dc50
6 changed files with 80 additions and 39 deletions

View File

@ -14,14 +14,13 @@
from datetime import datetime from datetime import datetime
from oslo_log import log as logging from oslo_log import log as logging
from vitrage_tempest_tests.tests.base import BaseVitrageTempest
from vitrage_tempest_tests.tests.e2e.test_basic_actions import TestActionsBase
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
DOWN = 'down'
UP = 'up'
class BaseTestEvents(BaseVitrageTempest): class BaseTestEvents(TestActionsBase):
"""Test class for Vitrage event API""" """Test class for Vitrage event API"""
# noinspection PyPep8Naming # noinspection PyPep8Naming

View File

@ -21,7 +21,7 @@ from vitrage.common.constants import EntityCategory
from vitrage.common.constants import EventProperties as EventProps from vitrage.common.constants import EventProperties as EventProps
from vitrage.common.constants import VertexProperties as VProps from vitrage.common.constants import VertexProperties as VProps
from vitrage_tempest_tests.tests.api.event.base import BaseTestEvents from vitrage_tempest_tests.tests.api.event.base import BaseTestEvents
from vitrage_tempest_tests.tests.api.event.base import DOWN from vitrage_tempest_tests.tests.common.vitrage_utils import DOWN
from vitrage_tempest_tests.tests.utils import wait_for_answer from vitrage_tempest_tests.tests.utils import wait_for_answer

View File

@ -15,11 +15,12 @@ from datetime import datetime
from vitrage.datasources import NOVA_HOST_DATASOURCE from vitrage.datasources import NOVA_HOST_DATASOURCE
from vitrage.datasources import NOVA_INSTANCE_DATASOURCE from vitrage.datasources import NOVA_INSTANCE_DATASOURCE
from vitrage_tempest_tests.tests.api.event.base import DOWN
from vitrage_tempest_tests.tests.api.event.base import UP
from vitrage_tempest_tests.tests.common import general_utils as g_utils from vitrage_tempest_tests.tests.common import general_utils as g_utils
from vitrage_tempest_tests.tests.common.tempest_clients import TempestClients from vitrage_tempest_tests.tests.common.tempest_clients import TempestClients
DOWN = 'down'
UP = 'up'
def generate_fake_host_alarm(hostname, event_type, enabled=True): def generate_fake_host_alarm(hostname, event_type, enabled=True):
details = { details = {

View File

@ -17,10 +17,7 @@ from testtools.matchers import HasLength
from vitrage import os_clients from vitrage import os_clients
from vitrage_tempest_tests.tests.api.event.base import BaseTestEvents from vitrage_tempest_tests.tests.api.event.base import BaseTestEvents
from vitrage_tempest_tests.tests.api.event.base import DOWN
from vitrage_tempest_tests.tests.api.event.base import UP
from vitrage_tempest_tests.tests.common.tempest_clients import TempestClients from vitrage_tempest_tests.tests.common.tempest_clients import TempestClients
from vitrage_tempest_tests.tests.common import vitrage_utils
from vitrage_tempest_tests.tests import utils from vitrage_tempest_tests.tests import utils
from vitrage_tempest_tests.tests.utils import wait_for_status from vitrage_tempest_tests.tests.utils import wait_for_status
@ -46,25 +43,34 @@ wf_for_tempest_test_1234:
class TestMistralNotifier(BaseTestEvents): class TestMistralNotifier(BaseTestEvents):
TRIGGER_ALARM_1 = "notifiers.mistral.trigger.alarm.1"
TRIGGER_ALARM_2 = "notifiers.mistral.trigger.alarm.2"
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
super(TestMistralNotifier, cls).setUpClass() super(TestMistralNotifier, cls).setUpClass()
cls.mistral_client = os_clients.mistral_client(cls.conf) cls.mistral_client = os_clients.mistral_client(cls.conf)
@utils.tempest_logger @utils.tempest_logger
def test_execute_mistral(self): def test_execute_mistral_v1(self):
hostname = vitrage_utils.get_first_host()['name'] self._do_test_execute_mistral(self.TRIGGER_ALARM_1)
@utils.tempest_logger
def test_execute_mistral_v2(self):
self._do_test_execute_mistral(self.TRIGGER_ALARM_2)
def _do_test_execute_mistral(self, trigger_alarm):
workflows = self.mistral_client.workflows.list() workflows = self.mistral_client.workflows.list()
self.assertIsNotNone(workflows) self.assertIsNotNone(workflows, 'Failed to get the list of workflows')
num_workflows = len(workflows) num_workflows = len(workflows)
executions = self.mistral_client.executions.list() executions = self.mistral_client.executions.list()
self.assertIsNotNone(executions) self.assertIsNotNone(executions,
'Failed to get the list of workflow executions')
num_executions = len(executions) num_executions = len(executions)
alarms = utils.wait_for_answer(2, 0.5, self._check_alarms) alarms = utils.wait_for_answer(2, 0.5, self._check_alarms)
self.assertIsNotNone(alarms) self.assertIsNotNone(alarms, 'Failed to get the list of alarms')
num_alarms = len(alarms) num_alarms = len(alarms)
try: try:
@ -73,54 +79,58 @@ class TestMistralNotifier(BaseTestEvents):
# Validate the workflow creation # Validate the workflow creation
workflows = self.mistral_client.workflows.list() workflows = self.mistral_client.workflows.list()
self.assertIsNotNone(workflows) self.assertIsNotNone(workflows,
self.assertThat(workflows, HasLength(num_workflows + 1)) 'Failed to get the list of workflows')
self.assertThat(workflows, HasLength(num_workflows + 1),
'Mistral workflow was not created')
# Send a Doctor event that should generate an alarm. According to # Trigger an alarm. According to v1_execute_mistral.yaml template,
# execute_mistral.yaml template, the alarm should cause execution # the alarm should cause execution of the workflow
# of the workflow self._trigger_do_action(trigger_alarm)
details = self._create_doctor_event_details(hostname, DOWN)
self._post_event(details)
# Wait for the alarm to be raised # Wait for the alarm to be raised
self.assertTrue(wait_for_status( self.assertTrue(wait_for_status(
10, 10,
self._check_num_vitrage_alarms, self._check_num_vitrage_alarms,
num_alarms=num_alarms + 1)) num_alarms=num_alarms + 1),
'Trigger alarm was not raised')
# Wait for the Mistral workflow execution # Wait for the Mistral workflow execution
self.assertTrue(wait_for_status( self.assertTrue(wait_for_status(
20, 20,
self._check_mistral_workflow_execution, self._check_mistral_workflow_execution,
num_executions=num_executions + 1)) num_executions=num_executions + 1),
'Mistral workflow was not executed')
except Exception as e: except Exception as e:
self._handle_exception(e) self._handle_exception(e)
raise raise
finally: finally:
self._rollback_to_default(WF_NAME, num_workflows, self._rollback_to_default(WF_NAME, num_workflows,
hostname, num_alarms) trigger_alarm, num_alarms)
pass pass
def _rollback_to_default(self, workflow_name, num_workflows, def _rollback_to_default(self, workflow_name, num_workflows,
hostname, num_alarms): trigger_alarm, num_alarms):
# Delete the workflow # Delete the workflow
self.mistral_client.workflows.delete(workflow_name) self.mistral_client.workflows.delete(workflow_name)
workflows = self.mistral_client.workflows.list() workflows = self.mistral_client.workflows.list()
self.assertIsNotNone(workflows) self.assertIsNotNone(workflows, 'Failed to get the list of workflows')
self.assertThat(workflows, HasLength(num_workflows)) self.assertThat(workflows, HasLength(num_workflows),
'Failed to remove the test workflow')
# Clear the host down event and wait for the alarm to be deleted # Clear the trigger alarm and wait it to be deleted
details = self._create_doctor_event_details(hostname, UP) self._trigger_undo_action(trigger_alarm)
self._post_event(details)
self.assertTrue(wait_for_status( self.assertTrue(wait_for_status(
10, 10,
self._check_num_vitrage_alarms, self._check_num_vitrage_alarms,
num_alarms=num_alarms)) num_alarms=num_alarms),
'Vitrage trigger alarm was not deleted')
def _check_num_vitrage_alarms(self, num_alarms): @staticmethod
def _check_num_vitrage_alarms(num_alarms):
vitrage_alarms = TempestClients.vitrage().alarm.list(vitrage_id='all', vitrage_alarms = TempestClients.vitrage().alarm.list(vitrage_id='all',
all_tenants=True) all_tenants=True)
if len(vitrage_alarms) == num_alarms: if len(vitrage_alarms) == num_alarms:

View File

@ -1,25 +1,26 @@
metadata: metadata:
name: execute_mistral version: 1
name: v1_execute_mistral
description: execute mistral description: execute mistral
definitions: definitions:
entities: entities:
- entity: - entity:
category: ALARM category: ALARM
name: compute.host.down name: notifiers.mistral.trigger.alarm.1
template_id: host_down_alarm template_id: alarm
- entity: - entity:
category: RESOURCE category: RESOURCE
type: nova.host type: nova.host
template_id: host template_id: host
relationships: relationships:
- relationship: - relationship:
source: host_down_alarm source: alarm
relationship_type: on relationship_type: on
target: host target: host
template_id : host_down_alarm_on_host template_id : alarm_on_host
scenarios: scenarios:
- scenario: - scenario:
condition: host_down_alarm_on_host condition: alarm_on_host
actions: actions:
- action: - action:
action_type: execute_mistral action_type: execute_mistral

View File

@ -0,0 +1,30 @@
metadata:
version: 2
name: v2_execute_mistral
description: execute mistral
definitions:
entities:
- entity:
category: ALARM
name: notifiers.mistral.trigger.alarm.2
template_id: alarm
- entity:
category: RESOURCE
type: nova.host
template_id: host
relationships:
- relationship:
source: alarm
relationship_type: on
target: host
template_id : alarm_on_host
scenarios:
- scenario:
condition: alarm_on_host
actions:
- action:
action_type: execute_mistral
properties:
workflow: wf_for_tempest_test_1234
input:
farewell: Hello and Goodbye