From b2c343dc5074292cd9d455fe43b079d5af57103c Mon Sep 17 00:00:00 2001 From: Ifat Afek Date: Tue, 2 Jan 2018 09:58:12 +0000 Subject: [PATCH] Sync tempest changes made in https://review.openstack.org/#/c/529332 Change-Id: If2e622ac04eb5cd9dd62f96103fc0f1772713bb5 --- vitrage_tempest_tests/tests/api/event/base.py | 7 +-- .../tests/api/event/test_events.py | 2 +- .../tests/common/vitrage_utils.py | 5 +- .../tests/notifiers/test_mistral_notifier.py | 62 +++++++++++-------- ...e_mistral.yaml => v1_execute_mistral.yaml} | 13 ++-- .../templates/api/v2_execute_mistral.yaml | 30 +++++++++ 6 files changed, 80 insertions(+), 39 deletions(-) rename vitrage_tempest_tests/tests/resources/templates/api/{execute_mistral.yaml => v1_execute_mistral.yaml} (69%) create mode 100644 vitrage_tempest_tests/tests/resources/templates/api/v2_execute_mistral.yaml diff --git a/vitrage_tempest_tests/tests/api/event/base.py b/vitrage_tempest_tests/tests/api/event/base.py index ea9bdb8..86f0508 100644 --- a/vitrage_tempest_tests/tests/api/event/base.py +++ b/vitrage_tempest_tests/tests/api/event/base.py @@ -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 diff --git a/vitrage_tempest_tests/tests/api/event/test_events.py b/vitrage_tempest_tests/tests/api/event/test_events.py index 3a6fc7d..7ddea5b 100644 --- a/vitrage_tempest_tests/tests/api/event/test_events.py +++ b/vitrage_tempest_tests/tests/api/event/test_events.py @@ -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 diff --git a/vitrage_tempest_tests/tests/common/vitrage_utils.py b/vitrage_tempest_tests/tests/common/vitrage_utils.py index 4610799..d016b85 100644 --- a/vitrage_tempest_tests/tests/common/vitrage_utils.py +++ b/vitrage_tempest_tests/tests/common/vitrage_utils.py @@ -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 = { diff --git a/vitrage_tempest_tests/tests/notifiers/test_mistral_notifier.py b/vitrage_tempest_tests/tests/notifiers/test_mistral_notifier.py index de94ff1..1672911 100644 --- a/vitrage_tempest_tests/tests/notifiers/test_mistral_notifier.py +++ b/vitrage_tempest_tests/tests/notifiers/test_mistral_notifier.py @@ -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: diff --git a/vitrage_tempest_tests/tests/resources/templates/api/execute_mistral.yaml b/vitrage_tempest_tests/tests/resources/templates/api/v1_execute_mistral.yaml similarity index 69% rename from vitrage_tempest_tests/tests/resources/templates/api/execute_mistral.yaml rename to vitrage_tempest_tests/tests/resources/templates/api/v1_execute_mistral.yaml index b180d75..94c1c64 100644 --- a/vitrage_tempest_tests/tests/resources/templates/api/execute_mistral.yaml +++ b/vitrage_tempest_tests/tests/resources/templates/api/v1_execute_mistral.yaml @@ -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 diff --git a/vitrage_tempest_tests/tests/resources/templates/api/v2_execute_mistral.yaml b/vitrage_tempest_tests/tests/resources/templates/api/v2_execute_mistral.yaml new file mode 100644 index 0000000..60585c3 --- /dev/null +++ b/vitrage_tempest_tests/tests/resources/templates/api/v2_execute_mistral.yaml @@ -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