Tempest tests for v3 template

Story: 2004871
Task: 29129
Change-Id: Ica592866ca79afec4730955395e10316b7373ce9
This commit is contained in:
Idan Hefetz 2019-01-27 15:54:40 +00:00
parent aca285b10c
commit dcde8a970e
4 changed files with 196 additions and 33 deletions

View File

@ -36,36 +36,66 @@ TRIGGER_ALARM_4 = 'e2e.test_basic_actions.trigger.alarm4'
TRIGGER_ALARM_5 = 'e2e.test_basic_actions.trigger.alarm5'
DEDUCED = 'e2e.test_basic_actions.deduced.alarm'
TRIGGER_ALARM_1_V3 = 'e2e.test_basic_actions.trigger.alarm1.v3'
TRIGGER_ALARM_2_V3 = 'e2e.test_basic_actions.trigger.alarm2.v3'
TRIGGER_ALARM_3_V3 = 'e2e.test_basic_actions.trigger.alarm3.v3'
TRIGGER_ALARM_4_V3 = 'e2e.test_basic_actions.trigger.alarm4.v3'
TRIGGER_ALARM_5_V3 = 'e2e.test_basic_actions.trigger.alarm5.v3'
DEDUCED_V3 = 'e2e.test_basic_actions.deduced.alarm.v3'
TRIGGER_ALARM_2_PROPS = {
VProps.NAME: TRIGGER_ALARM_2,
VProps.VITRAGE_CATEGORY: EntityCategory.ALARM,
VProps.VITRAGE_TYPE: DOCTOR_DATASOURCE,
}
TRIGGER_ALARM_2_PROPS_V3 = {
VProps.NAME: TRIGGER_ALARM_2_V3,
VProps.VITRAGE_CATEGORY: EntityCategory.ALARM,
VProps.VITRAGE_TYPE: DOCTOR_DATASOURCE,
}
DEDUCED_PROPS = {
VProps.NAME: DEDUCED,
VProps.VITRAGE_CATEGORY: EntityCategory.ALARM,
VProps.VITRAGE_TYPE: VITRAGE_DATASOURCE,
}
DEDUCED_PROPS_V3 = {
VProps.NAME: DEDUCED_V3,
VProps.VITRAGE_CATEGORY: EntityCategory.ALARM,
VProps.VITRAGE_TYPE: VITRAGE_DATASOURCE,
}
class TestBasicActions(TestActionsBase):
@classmethod
def setUpClass(cls):
super(TestBasicActions, cls).setUpClass()
cls._template = v_utils.add_template("e2e_test_basic_actions.yaml")
cls._templates = []
cls._templates.append(
v_utils.add_template("e2e_test_basic_actions.yaml"))
cls._templates.append(
v_utils.add_template("e2e_test_basic_actions_v3.yaml"))
@classmethod
def tearDownClass(cls):
if cls._template is not None:
v_utils.delete_template(cls._template['uuid'])
for t in cls._templates:
v_utils.delete_template(t['uuid'])
@utils.tempest_logger
def test_action_set_state_host(self):
self._do_test_action_set_state_host(TRIGGER_ALARM_1)
@utils.tempest_logger
def test_action_set_state_host_v3(self):
self._do_test_action_set_state_host(TRIGGER_ALARM_1_V3)
def _do_test_action_set_state_host(self, trigger):
try:
# Do
self._trigger_do_action(TRIGGER_ALARM_1)
self._trigger_do_action(trigger)
curr_host = v_utils.get_first_host()
self.assertEqual(
'ERROR',
@ -73,7 +103,7 @@ class TestBasicActions(TestActionsBase):
'state should change after set_state action')
# Undo
self._trigger_undo_action(TRIGGER_ALARM_1)
self._trigger_undo_action(trigger)
curr_host = v_utils.get_first_host()
self.assertEqual(
self.orig_host.get(VProps.VITRAGE_AGGREGATED_STATE),
@ -83,10 +113,17 @@ class TestBasicActions(TestActionsBase):
self._handle_exception(e)
raise
finally:
self._trigger_undo_action(TRIGGER_ALARM_1)
self._trigger_undo_action(trigger)
@utils.tempest_logger
def test_action_set_state_instance(self):
self._do_test_action_set_state_instance(TRIGGER_ALARM_3)
@utils.tempest_logger
def test_action_set_state_instance_v3(self):
self._do_test_action_set_state_instance(TRIGGER_ALARM_3_V3)
def _do_test_action_set_state_instance(self, trigger):
vm_id = ""
try:
@ -94,7 +131,7 @@ class TestBasicActions(TestActionsBase):
# Do
orig_instance = v_utils.get_first_instance(id=vm_id)
self._trigger_do_action(TRIGGER_ALARM_3)
self._trigger_do_action(trigger)
curr_instance = v_utils.get_first_instance(id=vm_id)
self.assertEqual(
'ERROR',
@ -102,7 +139,7 @@ class TestBasicActions(TestActionsBase):
'state should change after set_state action')
# Undo
self._trigger_undo_action(TRIGGER_ALARM_3)
self._trigger_undo_action(trigger)
curr_instance = v_utils.get_first_instance(id=vm_id)
self.assertEqual(
orig_instance.get(VProps.VITRAGE_AGGREGATED_STATE),
@ -112,22 +149,29 @@ class TestBasicActions(TestActionsBase):
self._handle_exception(e)
raise
finally:
self._trigger_undo_action(TRIGGER_ALARM_3)
self._trigger_undo_action(trigger)
nova_utils.delete_all_instances(id=vm_id)
@utils.tempest_logger
def test_action_mark_down_host(self):
self._do_test_action_mark_down_host(TRIGGER_ALARM_4)
@utils.tempest_logger
def test_action_mark_down_host_v3(self):
self._do_test_action_mark_down_host(TRIGGER_ALARM_4_V3)
def _do_test_action_mark_down_host(self, trigger):
try:
host_name = self.orig_host.get(VProps.NAME)
# Do
self._trigger_do_action(TRIGGER_ALARM_4)
self._trigger_do_action(trigger)
nova_service = TempestClients.nova().services.list(
host=host_name, binary='nova-compute')[0]
self.assertEqual("down", str(nova_service.state))
# Undo
self._trigger_undo_action(TRIGGER_ALARM_4)
self._trigger_undo_action(trigger)
nova_service = TempestClients.nova().services.list(
host=host_name, binary='nova-compute')[0]
self.assertEqual("up", str(nova_service.state))
@ -135,22 +179,29 @@ class TestBasicActions(TestActionsBase):
self._handle_exception(e)
raise
finally:
self._trigger_undo_action(TRIGGER_ALARM_4)
self._trigger_undo_action(trigger)
# nova.host datasource may take up to snapshot_intreval to update
time.sleep(130)
@utils.tempest_logger
def test_action_mark_down_instance(self):
self._do_test_action_mark_down_instance(TRIGGER_ALARM_5)
@utils.tempest_logger
def test_action_mark_down_instance_v3(self):
self._do_test_action_mark_down_instance(TRIGGER_ALARM_5_V3)
def _do_test_action_mark_down_instance(self, trigger):
vm_id = ""
try:
vm_id = nova_utils.create_instances(set_public_network=True)[0].id
# Do
self._trigger_do_action(TRIGGER_ALARM_5)
self._trigger_do_action(trigger)
nova_instance = TempestClients.nova().servers.get(vm_id)
self.assertEqual("ERROR", str(nova_instance.status))
# Undo
self._trigger_undo_action(TRIGGER_ALARM_5)
self._trigger_undo_action(trigger)
nova_instance = TempestClients.nova().servers.get(vm_id)
self.assertEqual("ACTIVE", str(nova_instance.status))
except Exception as e:
@ -158,51 +209,72 @@ class TestBasicActions(TestActionsBase):
raise
finally:
pass
self._trigger_undo_action(TRIGGER_ALARM_5)
self._trigger_undo_action(trigger)
nova_utils.delete_all_instances(id=vm_id)
@utils.tempest_logger
def test_action_deduce_alarm(self):
self._do_test_action_deduce_alarm(TRIGGER_ALARM_2, DEDUCED_PROPS)
@utils.tempest_logger
def test_action_deduce_alarm_v3(self):
self._do_test_action_deduce_alarm(TRIGGER_ALARM_2_V3, DEDUCED_PROPS_V3)
def _do_test_action_deduce_alarm(self, trigger, deduced_props):
try:
host_id = self.orig_host.get(VProps.VITRAGE_ID)
# Do
self._trigger_do_action(TRIGGER_ALARM_2)
self._check_deduced(1, DEDUCED_PROPS, host_id)
self._trigger_do_action(trigger)
self._check_deduced(1, deduced_props, host_id)
# Undo
self._trigger_undo_action(TRIGGER_ALARM_2)
self._check_deduced(0, DEDUCED_PROPS, host_id)
self._trigger_undo_action(trigger)
self._check_deduced(0, deduced_props, host_id)
except Exception as e:
self._handle_exception(e)
raise
finally:
self._trigger_undo_action(TRIGGER_ALARM_2)
self._trigger_undo_action(trigger)
@utils.tempest_logger
def test_action_add_causal_relationship(self):
self._do_test_action_add_causal_relationship(TRIGGER_ALARM_2,
DEDUCED_PROPS,
TRIGGER_ALARM_2_PROPS)
@utils.tempest_logger
def test_action_add_causal_relationship_v3(self):
self._do_test_action_add_causal_relationship(TRIGGER_ALARM_2_V3,
DEDUCED_PROPS_V3,
TRIGGER_ALARM_2_PROPS_V3)
def _do_test_action_add_causal_relationship(self,
trigger,
deduced_props,
trigger_alarm_props):
try:
# Do
self._trigger_do_action(TRIGGER_ALARM_2)
self._trigger_do_action(trigger)
alarms = TempestClients.vitrage().alarm.list(
vitrage_id=self.orig_host.get(VProps.VITRAGE_ID),
all_tenants=True)
self.assertTrue(len(alarms) >= 2, 'alarms %s' % str(alarms))
deduced = g_utils.first_match(alarms, **DEDUCED_PROPS)
trigger = g_utils.first_match(alarms, **TRIGGER_ALARM_2_PROPS)
deduced = g_utils.first_match(alarms, **deduced_props)
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)
self._check_rca(rca, [deduced, trigger], DEDUCED_PROPS)
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)
self._check_rca(rca, [deduced, trigger], TRIGGER_ALARM_2_PROPS)
self._check_rca(rca, [deduced, trigger], trigger_alarm_props)
except Exception as e:
self._handle_exception(e)
raise
finally:
self._trigger_undo_action(TRIGGER_ALARM_2)
self._trigger_undo_action(trigger)

View File

@ -47,7 +47,10 @@ class TestMistralNotifier(BaseTestEvents):
TRIGGER_ALARM_1 = "notifiers.mistral.trigger.alarm.1"
TRIGGER_ALARM_2 = "notifiers.mistral.trigger.alarm.2"
TRIGGER_ALARM_3 = "notifiers.mistral.trigger.alarm.3"
TRIGGER_ALARM_FOR_FUNCTION = "notifiers.mistral.trigger.alarm.for.function"
TRIGGER_ALARM_FOR_FUNCTION_v3 = \
"notifiers.mistral.trigger.alarm.for.function.v3"
@classmethod
def setUpClass(cls):
@ -56,12 +59,14 @@ class TestMistralNotifier(BaseTestEvents):
cls._templates = []
cls._templates.append(v_utils.add_template('v1_execute_mistral.yaml'))
cls._templates.append(v_utils.add_template('v2_execute_mistral.yaml'))
cls._templates.append(v_utils.add_template('v3_execute_mistral.yaml'))
@classmethod
def tearDownClass(cls):
if cls._templates is not None:
v_utils.delete_template(cls._templates[0]['uuid'])
v_utils.delete_template(cls._templates[1]['uuid'])
v_utils.delete_template(cls._templates[2]['uuid'])
@utils.tempest_logger
def test_execute_mistral_v1(self):
@ -72,32 +77,39 @@ class TestMistralNotifier(BaseTestEvents):
self._do_test_execute_mistral(self.TRIGGER_ALARM_2)
@utils.tempest_logger
def test_execute_mistral_with_function(self):
def test_execute_mistral_v3(self):
self._do_test_execute_mistral(self.TRIGGER_ALARM_3)
@utils.tempest_logger
def test_execute_mistral_with_function_v2(self):
# Execute the basic test
self._do_test_execute_mistral(self.TRIGGER_ALARM_FOR_FUNCTION)
self._do_test_function(self.TRIGGER_ALARM_FOR_FUNCTION)
@utils.tempest_logger
def test_execute_mistral_with_function_v3(self):
# Execute the basic test
self._do_test_execute_mistral(self.TRIGGER_ALARM_FOR_FUNCTION_v3)
self._do_test_function(self.TRIGGER_ALARM_FOR_FUNCTION_v3)
def _do_test_function(self, trigger):
# Make sure that the workflow execution was done with the correct input
# (can be checked even if the Vitrage alarm is already down)
executions = self.mistral_client.executions.list()
last_execution = executions[0]
for execution in executions:
if execution.updated_at > last_execution.updated_at:
last_execution = execution
execution_input_str = last_execution.input
self.assertIsNotNone(execution_input_str,
'The last execution had no input')
self.assertIn('farewell', execution_input_str,
'No \'farewell\' key in the last execution input')
execution_input = json.loads(execution_input_str)
farewell_value = execution_input['farewell']
self.assertIsNotNone(farewell_value, '\'farewell\' input parameter is '
'None in last workflow execution')
self.assertEqual(self.TRIGGER_ALARM_FOR_FUNCTION, farewell_value,
self.assertEqual(trigger, farewell_value,
'\'farewell\' input parameter does not match the'
'alarm name')

View File

@ -0,0 +1,54 @@
metadata:
version: 3
name: e2e_test_basic_actions v3
description: this template includes vitrage basic actions
type: standard
entities:
trigger_alarm_1:
name: e2e.test_basic_actions.trigger.alarm1.v3
trigger_alarm_2:
name: e2e.test_basic_actions.trigger.alarm2.v3
trigger_alarm_3:
name: e2e.test_basic_actions.trigger.alarm3.v3
trigger_alarm_4:
name: e2e.test_basic_actions.trigger.alarm4.v3
trigger_alarm_5:
name: e2e.test_basic_actions.trigger.alarm5.v3
deduced_alarm:
name: e2e.test_basic_actions.deduced.alarm.v3
type: vitrage
host:
type: nova.host
instance:
type: nova.instance
scenarios:
- condition: trigger_alarm_1 [ on ] host
actions:
- set_state:
state: ERROR
target: host
- condition: trigger_alarm_4 [ on ] host
actions:
- mark_down:
target: host
- condition: trigger_alarm_2 [ on ] host
actions:
- raise_alarm:
target: host
alarm_name: e2e.test_basic_actions.deduced.alarm.v3
severity: WARNING
# causing_alarm: trigger_alarm_2
- condition: trigger_alarm_2 [ on ] host AND deduced_alarm [on] host
actions:
- add_causal_relationship:
source: trigger_alarm_2
target: deduced_alarm
- condition: trigger_alarm_3 [ on ] host AND host [ contains ] instance
actions:
- set_state:
state: ERROR
target: instance
- condition: trigger_alarm_5 [ on ] host AND host [ contains ] instance
actions:
- mark_down:
target: instance

View File

@ -0,0 +1,25 @@
metadata:
version: 3
name: v3_execute_mistral
description: execute mistral
type: standard
entities:
alarm_3:
name: notifiers.mistral.trigger.alarm.3
alarm_for_func:
name: notifiers.mistral.trigger.alarm.for.function.v3
host:
type: nova.host
scenarios:
- condition: alarm_3 [on] host
actions:
- execute_mistral:
workflow: wf_for_tempest_test_1234
input:
farewell: Hello and Goodbye
- condition: alarm_for_func [on] host
actions:
- execute_mistral:
workflow: wf_for_tempest_test_1234
input:
farewell: get_attr(alarm_for_func,name)