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 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__)
DOWN = 'down'
UP = 'up'
class BaseTestEvents(BaseVitrageTempest):
class BaseTestEvents(TestActionsBase):
"""Test class for Vitrage event API"""
# 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 VertexProperties as VProps
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

View File

@ -15,11 +15,12 @@ from datetime import datetime
from vitrage.datasources import NOVA_HOST_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.tempest_clients import TempestClients
DOWN = 'down'
UP = 'up'
def generate_fake_host_alarm(hostname, event_type, enabled=True):
details = {

View File

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

View File

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