summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2017-06-19 15:10:03 +0000
committerGerrit Code Review <review@openstack.org>2017-06-19 15:10:03 +0000
commit542ca3677d237b0288e0b7184b9315286ce4e7f2 (patch)
tree6a2271d5311327c3a7b5d6e75e62a1f56184a16f
parent0894e673e770e6fabab15fcae2d0eb3a9d1bd3e4 (diff)
parenta9a43fdc1793bda2a16b80f0ce2589c53567d2ac (diff)
Merge "event tempst test changes"
-rw-r--r--vitrage_tempest_tests/tests/api/event/test_events.py43
-rw-r--r--vitrage_tempest_tests/tests/utils.py14
2 files changed, 35 insertions, 22 deletions
diff --git a/vitrage_tempest_tests/tests/api/event/test_events.py b/vitrage_tempest_tests/tests/api/event/test_events.py
index a6aaf93..4da7c79 100644
--- a/vitrage_tempest_tests/tests/api/event/test_events.py
+++ b/vitrage_tempest_tests/tests/api/event/test_events.py
@@ -13,7 +13,6 @@
13# under the License. 13# under the License.
14 14
15import six 15import six
16import time
17 16
18from datetime import datetime 17from datetime import datetime
19from oslo_log import log as logging 18from oslo_log import log as logging
@@ -24,8 +23,10 @@ from vitrage.common.constants import EventProperties as EventProps
24from vitrage.common.constants import VertexProperties as VProps 23from vitrage.common.constants import VertexProperties as VProps
25from vitrage import keystone_client 24from vitrage import keystone_client
26from vitrage import service 25from vitrage import service
26from vitrage_tempest_tests.tests.utils import wait_for_answer
27from vitrageclient import client as v_client 27from vitrageclient import client as v_client
28 28
29
29LOG = logging.getLogger(__name__) 30LOG = logging.getLogger(__name__)
30 31
31 32
@@ -52,16 +53,27 @@ class TestEvents(base.BaseTestCase):
52 } 53 }
53 self._test_send_doctor_event(details) 54 self._test_send_doctor_event(details)
54 55
56 def test_send_doctor_event_without_resource_id_v2(self):
57 """Sending an event in Doctor format should result in an alarm"""
58 details = {
59 'hostname': 'host457',
60 'source': 'sample_monitor',
61 'cause': 'another alarm',
62 'severity': 'critical',
63 'status': 'down',
64 'monitor_id': 'sample monitor',
65 'monitor_event_id': '103',
66 }
67 self._test_send_doctor_event(details)
68
55 def _test_send_doctor_event(self, details): 69 def _test_send_doctor_event(self, details):
56 try: 70 try:
57 # post an event to the message bus 71 # post an event to the message bus
58 event_time = datetime.now() 72 event_time = datetime.now()
59 event_time_iso = event_time.isoformat() 73 event_time_iso = event_time.isoformat()
60 event_type = 'compute.host.down' 74 event_type = 'compute.host.down'
61
62 self.vitrage_client.event.post(event_time_iso, event_type, details) 75 self.vitrage_client.event.post(event_time_iso, event_type, details)
63 76 api_alarms = wait_for_answer(2, 0.5, self._check_alarms)
64 api_alarms = self._wait_for_status(2, self._check_alarms)
65 77
66 # expect to get a 'host down alarm', generated by Doctor datasource 78 # expect to get a 'host down alarm', generated by Doctor datasource
67 self.assertIsNotNone(api_alarms, 'Expected host down alarm') 79 self.assertIsNotNone(api_alarms, 'Expected host down alarm')
@@ -70,14 +82,15 @@ class TestEvents(base.BaseTestCase):
70 alarm = api_alarms[0] 82 alarm = api_alarms[0]
71 event_time_tz = six.u(event_time.strftime('%Y-%m-%dT%H:%M:%SZ')) 83 event_time_tz = six.u(event_time.strftime('%Y-%m-%dT%H:%M:%SZ'))
72 self._check_alarm(alarm, event_time_tz, event_type, details) 84 self._check_alarm(alarm, event_time_tz, event_type, details)
85
73 event_time = datetime.now() 86 event_time = datetime.now()
74 event_time_iso = event_time.isoformat() 87 event_time_iso = event_time.isoformat()
75 details['status'] = 'up' 88 details['status'] = 'up'
76 self.vitrage_client.event.post(event_time_iso, event_type, details) 89 self.vitrage_client.event.post(event_time_iso, event_type, details)
77 self._wait_for_status(2, self._check_alarms) 90
78 # TODO(iaffek) 91 api_alarms = wait_for_answer(2, 0.5, self._check_alarms)
79 # self.assertIsNotNone(api_alarms, 'Expected host down alarm') 92 self.assertIsNotNone(api_alarms, 'Expected host down alarm')
80 # self.assertEqual(0, len(api_alarms), 'Expected host down alarm') 93 self.assertEqual(0, len(api_alarms), 'Expected host down alarm')
81 94
82 except Exception as e: 95 except Exception as e:
83 LOG.exception(e) 96 LOG.exception(e)
@@ -90,7 +103,6 @@ class TestEvents(base.BaseTestCase):
90 all_tenants=True) 103 all_tenants=True)
91 if api_alarms: 104 if api_alarms:
92 return True, api_alarms 105 return True, api_alarms
93
94 return False, api_alarms 106 return False, api_alarms
95 107
96 def _check_alarm(self, alarm, event_time, event_type, details): 108 def _check_alarm(self, alarm, event_time, event_type, details):
@@ -100,16 +112,3 @@ class TestEvents(base.BaseTestCase):
100 self.assertEqual(details['status'], alarm['status']) 112 self.assertEqual(details['status'], alarm['status'])
101 self.assertFalse(alarm[VProps.VITRAGE_IS_DELETED]) 113 self.assertFalse(alarm[VProps.VITRAGE_IS_DELETED])
102 self.assertFalse(alarm[VProps.VITRAGE_IS_PLACEHOLDER]) 114 self.assertFalse(alarm[VProps.VITRAGE_IS_PLACEHOLDER])
103
104 @staticmethod
105 def _wait_for_status(max_waiting, func, **kwargs):
106 count = 0
107 status, res = False, None
108 while count < max_waiting:
109 status, res = func(**kwargs)
110 if status:
111 return res
112 count += 1
113 time.sleep(2)
114 LOG.info("wait_for_status - False")
115 return res
diff --git a/vitrage_tempest_tests/tests/utils.py b/vitrage_tempest_tests/tests/utils.py
index 27e7407..766c9c0 100644
--- a/vitrage_tempest_tests/tests/utils.py
+++ b/vitrage_tempest_tests/tests/utils.py
@@ -15,6 +15,7 @@
15from functools import wraps 15from functools import wraps
16 16
17import socket 17import socket
18import time
18 19
19from oslo_config import cfg 20from oslo_config import cfg
20from oslo_config.cfg import NoSuchOptError 21from oslo_config.cfg import NoSuchOptError
@@ -125,3 +126,16 @@ def tempest_logger(func):
125 return result 126 return result
126 127
127 return func_name_print_func 128 return func_name_print_func
129
130
131def wait_for_answer(max_waiting, time_between_attempts, func, **kwargs):
132 """time_between_attempts should be in range of 0 to 1"""
133 status, res = False, None
134 start_time = time.time()
135 while time.time() - start_time < max_waiting:
136 time.sleep(time_between_attempts)
137 status, res = func(**kwargs)
138 if status:
139 return res
140 LOG.info("wait for answer- False")
141 return res