Merge "Update error messages for ceilometer event scenarios"

This commit is contained in:
Jenkins 2016-09-09 17:02:20 +00:00 committed by Gerrit Code Review
commit 826312b22e
2 changed files with 52 additions and 3 deletions

View File

@ -13,6 +13,7 @@
# under the License.
from rally import consts
from rally import exceptions
from rally.plugins.openstack import scenario
from rally.plugins.openstack.scenarios.ceilometer import utils as cutils
from rally.plugins.openstack.scenarios.keystone import utils as kutils
@ -39,7 +40,11 @@ class CeilometerEventsCreateUserAndListEvents(cutils.CeilometerScenario,
fetches list of all events using GET /v2/events.
"""
self._user_create()
self._list_events()
events = self._list_events()
if not events:
raise exceptions.RallyException(
"Events list is empty, but it should include at least one "
"event about user creation")
@validation.required_services(consts.Service.CEILOMETER,
@ -58,7 +63,11 @@ class CeilometerEventsCreateUserAndListEventTypes(cutils.CeilometerScenario,
fetches list of all events types using GET /v2/event_types.
"""
self._user_create()
self._list_event_types()
event_types = self._list_event_types()
if not event_types:
raise exceptions.RallyException(
"Event types list is empty, but it should include at least one"
" type about user creation")
@validation.required_services(consts.Service.CEILOMETER,
@ -77,5 +86,10 @@ class CeilometerEventsCreateUserAndGetEvent(cutils.CeilometerScenario,
fetches one event using GET /v2/events/<message_id>.
"""
self._user_create()
event = self._list_events()[0]
events = self._list_events()
if not events:
raise exceptions.RallyException(
"Events list is empty, but it should include at least one "
"event about user creation")
event = events[0]
self._get_event(event_id=event.message_id)

View File

@ -14,6 +14,7 @@
import mock
from rally import exceptions
from rally.plugins.openstack.scenarios.ceilometer import events
from tests.unit import test
@ -29,6 +30,16 @@ class CeilometerEventsTestCase(test.ScenarioTestCase):
scenario._user_create.assert_called_once_with()
scenario._list_events.assert_called_once_with()
def test_list_events_fails(self):
scenario = events.CeilometerEventsCreateUserAndListEvents(self.context)
scenario._user_create = mock.MagicMock()
scenario._list_events = mock.MagicMock(return_value=[])
self.assertRaises(exceptions.RallyException, scenario.run)
scenario._user_create.assert_called_once_with()
scenario._list_events.assert_called_once_with()
def test_list_event_types(self):
scenario = events.CeilometerEventsCreateUserAndListEventTypes(
self.context)
@ -39,6 +50,17 @@ class CeilometerEventsTestCase(test.ScenarioTestCase):
scenario._user_create.assert_called_once_with()
scenario._list_event_types.assert_called_once_with()
def test_list_event_types_fails(self):
scenario = events.CeilometerEventsCreateUserAndListEventTypes(
self.context)
scenario._user_create = mock.MagicMock()
scenario._list_event_types = mock.MagicMock(return_value=[])
self.assertRaises(exceptions.RallyException, scenario.run)
scenario._user_create.assert_called_once_with()
scenario._list_event_types.assert_called_once_with()
def test_get_event(self):
scenario = events.CeilometerEventsCreateUserAndGetEvent(self.context)
@ -50,3 +72,16 @@ class CeilometerEventsTestCase(test.ScenarioTestCase):
scenario._user_create.assert_called_once_with()
scenario._list_events.assert_called_with()
scenario._get_event.assert_called_with(event_id="fake_id")
def test_get_event_fails(self):
scenario = events.CeilometerEventsCreateUserAndGetEvent(self.context)
scenario._user_create = mock.MagicMock()
scenario._list_events = mock.MagicMock(return_value=[])
scenario._get_event = mock.MagicMock()
self.assertRaises(exceptions.RallyException, scenario.run)
scenario._user_create.assert_called_once_with()
scenario._list_events.assert_called_with()
self.assertFalse(scenario._get_event.called)