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:
Eyal 2017-03-19 10:39:45 +02:00
parent 2e43bf4de6
commit 6f318ce8d6
2 changed files with 19 additions and 19 deletions

View File

@ -21,7 +21,7 @@ DEVSTACK_PATH="$BASE/new"
if [ "$1" = "api" ]; then if [ "$1" = "api" ]; then
TESTS="topology" TESTS="topology"
elif [ "$1" = "datasources" ]; then elif [ "$1" = "datasources" ]; then
TESTS="datasources" TESTS="datasources\|test_events"
else else
TESTS="topology" TESTS="topology"
fi fi

View File

@ -19,7 +19,6 @@ from datetime import datetime
from oslo_log import log as logging from oslo_log import log as logging
from oslotest import base from oslotest import base
from vitrage.common.constants import DatasourceProperties as DSProps
from vitrage.common.constants import EntityCategory from vitrage.common.constants import EntityCategory
from vitrage.common.constants import EventProperties as EventProps from vitrage.common.constants import EventProperties as EventProps
from vitrage.common.constants import VertexProperties as VProps 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) self.vitrage_client.event.post(event_time_iso, event_type, details)
# list all alarms api_alarms = self._wait_for_status(2, self._check_alarms)
api_alarms = self.vitrage_client.alarm.list(vitrage_id='all',
all_tenants=False)
# expect to get a 'host down alarm', generated by Doctor datasource # expect to get a 'host down alarm', generated by Doctor datasource
self.assertIsNotNone(api_alarms, 'Expected host down alarm') self.assertIsNotNone(api_alarms, 'Expected host down alarm')
self.assertEqual(1, len(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")) alarm = api_alarms[0]
self._wait_for_status(2, event_time_tz = six.u(event_time.strftime('%Y-%m-%dT%H:%M:%SZ'))
self._check_alarm, self._check_alarm(alarm, event_time_tz, event_type, details)
alarm=alarm,
event_time=event_time_tz,
event_type=event_type,
details=details)
except Exception as e: except Exception as e:
LOG.exception(e) LOG.exception(e)
@ -83,23 +75,31 @@ class TestEvents(base.BaseTestCase):
# do what? # do what?
LOG.warning('done') 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): 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(EntityCategory.ALARM, alarm[VProps.CATEGORY])
self.assertEqual(event_type, alarm[VProps.NAME]) self.assertEqual(event_type, alarm[VProps.NAME])
self.assertEqual(event_time, alarm[EventProps.TIME]) self.assertEqual(event_time, alarm[EventProps.TIME])
self.assertEqual(event_type, alarm[DSProps.ENTITY_TYPE]) self.assertEqual(details['status'], alarm['status'])
self.assertEqual(details['status'], alarm[VProps.STATE])
self.assertFalse(alarm[VProps.IS_DELETED]) self.assertFalse(alarm[VProps.IS_DELETED])
self.assertFalse(alarm[VProps.IS_PLACEHOLDER]) self.assertFalse(alarm[VProps.IS_PLACEHOLDER])
@staticmethod @staticmethod
def _wait_for_status(max_waiting, func, **kwargs): def _wait_for_status(max_waiting, func, **kwargs):
count = 0 count = 0
status, res = False, None
while count < max_waiting: while count < max_waiting:
if func(**kwargs): status, res = func(**kwargs)
return True if status:
return res
count += 1 count += 1
time.sleep(2) time.sleep(2)
LOG.info("wait_for_status - False") LOG.info("wait_for_status - False")
return False return res