add some delay between post and get
add to datasource tempest the doctor test to run in gate Change-Id: I9655f9358d7ea2b36f663b4e2f6adf20c7de0cbf
This commit is contained in:
parent
2e43bf4de6
commit
6f318ce8d6
@ -21,7 +21,7 @@ DEVSTACK_PATH="$BASE/new"
|
||||
if [ "$1" = "api" ]; then
|
||||
TESTS="topology"
|
||||
elif [ "$1" = "datasources" ]; then
|
||||
TESTS="datasources"
|
||||
TESTS="datasources\|test_events"
|
||||
else
|
||||
TESTS="topology"
|
||||
fi
|
||||
|
@ -19,7 +19,6 @@ from datetime import datetime
|
||||
from oslo_log import log as logging
|
||||
from oslotest import base
|
||||
|
||||
from vitrage.common.constants import DatasourceProperties as DSProps
|
||||
from vitrage.common.constants import EntityCategory
|
||||
from vitrage.common.constants import EventProperties as EventProps
|
||||
from vitrage.common.constants import VertexProperties as VProps
|
||||
@ -59,22 +58,15 @@ class TestEvents(base.BaseTestCase):
|
||||
|
||||
self.vitrage_client.event.post(event_time_iso, event_type, details)
|
||||
|
||||
# list all alarms
|
||||
api_alarms = self.vitrage_client.alarm.list(vitrage_id='all',
|
||||
all_tenants=False)
|
||||
api_alarms = self._wait_for_status(2, self._check_alarms)
|
||||
|
||||
# expect to get a 'host down alarm', generated by Doctor datasource
|
||||
self.assertIsNotNone(api_alarms, 'Expected host down alarm')
|
||||
self.assertEqual(1, len(api_alarms), 'Expected host down alarm')
|
||||
alarm = api_alarms[0]
|
||||
|
||||
event_time_tz = six.u(event_time.strftime("%Y-%m-%d %H:%M:%SZ"))
|
||||
self._wait_for_status(2,
|
||||
self._check_alarm,
|
||||
alarm=alarm,
|
||||
event_time=event_time_tz,
|
||||
event_type=event_type,
|
||||
details=details)
|
||||
alarm = api_alarms[0]
|
||||
event_time_tz = six.u(event_time.strftime('%Y-%m-%dT%H:%M:%SZ'))
|
||||
self._check_alarm(alarm, event_time_tz, event_type, details)
|
||||
|
||||
except Exception as e:
|
||||
LOG.exception(e)
|
||||
@ -83,23 +75,31 @@ class TestEvents(base.BaseTestCase):
|
||||
# do what?
|
||||
LOG.warning('done')
|
||||
|
||||
def _check_alarms(self):
|
||||
api_alarms = self.vitrage_client.alarm.list(vitrage_id='all',
|
||||
all_tenants=False)
|
||||
if api_alarms:
|
||||
return True, api_alarms
|
||||
|
||||
return False, api_alarms
|
||||
|
||||
def _check_alarm(self, alarm, event_time, event_type, details):
|
||||
LOG.info('alarm = %s', str(alarm))
|
||||
self.assertEqual(EntityCategory.ALARM, alarm[VProps.CATEGORY])
|
||||
self.assertEqual(event_type, alarm[VProps.NAME])
|
||||
self.assertEqual(event_time, alarm[EventProps.TIME])
|
||||
self.assertEqual(event_type, alarm[DSProps.ENTITY_TYPE])
|
||||
self.assertEqual(details['status'], alarm[VProps.STATE])
|
||||
self.assertEqual(details['status'], alarm['status'])
|
||||
self.assertFalse(alarm[VProps.IS_DELETED])
|
||||
self.assertFalse(alarm[VProps.IS_PLACEHOLDER])
|
||||
|
||||
@staticmethod
|
||||
def _wait_for_status(max_waiting, func, **kwargs):
|
||||
count = 0
|
||||
status, res = False, None
|
||||
while count < max_waiting:
|
||||
if func(**kwargs):
|
||||
return True
|
||||
status, res = func(**kwargs)
|
||||
if status:
|
||||
return res
|
||||
count += 1
|
||||
time.sleep(2)
|
||||
LOG.info("wait_for_status - False")
|
||||
return False
|
||||
return res
|
||||
|
Loading…
Reference in New Issue
Block a user