diff --git a/rally/plugins/openstack/scenarios/ceilometer/meters.py b/rally/plugins/openstack/scenarios/ceilometer/meters.py index 6510f716..75db7576 100644 --- a/rally/plugins/openstack/scenarios/ceilometer/meters.py +++ b/rally/plugins/openstack/scenarios/ceilometer/meters.py @@ -18,37 +18,40 @@ from rally.plugins.openstack.scenarios.ceilometer import utils as ceiloutils from rally.task import validation -class CeilometerMeters(ceiloutils.CeilometerScenario): - """Benchmark scenarios for Ceilometer Meters API.""" +"""Scenarios for Ceilometer Meters API.""" - @validation.required_services(consts.Service.CEILOMETER) - @validation.required_contexts("ceilometer") - @validation.required_openstack(users=True) - @scenario.configure() - def list_meters(self, metadata_query=None, limit=None): + +@validation.required_services(consts.Service.CEILOMETER) +@validation.required_contexts("ceilometer") +@validation.required_openstack(users=True) +@scenario.configure(name="CeilometerMeters.list_meters") +class ListMeters(ceiloutils.CeilometerScenario): + + def run(self, metadata_query=None, limit=None): """Check all available queries for list resource request. :param metadata_query: dict with metadata fields and values :param limit: limit of meters in response """ - self.list_matched_meters(filter_by_project_id=True) - self.list_matched_meters(filter_by_user_id=True) - self.list_matched_meters(filter_by_resource_id=True) + scenario = ListMatchedMeters(self.context) + scenario.run(filter_by_project_id=True) + scenario.run(filter_by_user_id=True) + scenario.run(filter_by_resource_id=True) if metadata_query: - self.list_matched_meters(metadata_query=metadata_query) + scenario.run(metadata_query=metadata_query) if limit: - self.list_matched_meters(limit=limit) + scenario.run(limit=limit) - @validation.required_services(consts.Service.CEILOMETER) - @validation.required_contexts("ceilometer") - @validation.required_openstack(users=True) - @scenario.configure() - def list_matched_meters(self, filter_by_user_id=False, - filter_by_project_id=False, - filter_by_resource_id=False, - metadata_query=None, - limit=None): + +@validation.required_services(consts.Service.CEILOMETER) +@validation.required_contexts("ceilometer") +@validation.required_openstack(users=True) +@scenario.configure(name="CeilometerMeters.list_matched_meters") +class ListMatchedMeters(ceiloutils.CeilometerScenario): + + def run(self, filter_by_user_id=False, filter_by_project_id=False, + filter_by_resource_id=False, metadata_query=None, limit=None): """Get meters that matched fields from context and args. :param filter_by_user_id: flag for query by user_id @@ -57,8 +60,9 @@ class CeilometerMeters(ceiloutils.CeilometerScenario): :param metadata_query: dict with metadata fields and values for query :param limit: count of resources in response """ + query = self._make_general_query(filter_by_project_id, filter_by_user_id, filter_by_resource_id, metadata_query) - self._list_meters(query, limit) + self._list_meters(query, limit) \ No newline at end of file diff --git a/rally/plugins/openstack/scenarios/ceilometer/resources.py b/rally/plugins/openstack/scenarios/ceilometer/resources.py index 1ab15291..a331716c 100644 --- a/rally/plugins/openstack/scenarios/ceilometer/resources.py +++ b/rally/plugins/openstack/scenarios/ceilometer/resources.py @@ -19,45 +19,48 @@ from rally.plugins.openstack.scenarios.ceilometer import utils as ceiloutils from rally.task import validation -class CeilometerResource(ceiloutils.CeilometerScenario): - """Benchmark scenarios for Ceilometer Resource API.""" +"""Scenarios for Ceilometer Resource API.""" - @validation.required_services(consts.Service.CEILOMETER) - @validation.required_contexts("ceilometer") - @validation.required_openstack(users=True) - @scenario.configure() - def list_resources(self, metadata_query=None, - start_time=None, - end_time=None, - limit=None): + +@validation.required_services(consts.Service.CEILOMETER) +@validation.required_contexts("ceilometer") +@validation.required_openstack(users=True) +@scenario.configure(name="CeilometerResource.list_resources") +class ListResources(ceiloutils.CeilometerScenario): + + def run(self, metadata_query=None, start_time=None, + end_time=None, limit=None): """Check all available queries for list resource request. This scenario fetches list of all resources using GET /v2/resources. + :param metadata_query: dict with metadata fields and values for query :param start_time: lower bound of resource timestamp in isoformat :param end_time: upper bound of resource timestamp in isoformat :param limit: count of resources in response """ - - self.list_matched_resources(filter_by_project_id=True) - self.list_matched_resources(filter_by_user_id=True) - self.list_matched_resources(filter_by_resource_id=True) + scenario = ListMatchedResources(self.context) + scenario.run(filter_by_project_id=True) + scenario.run(filter_by_user_id=True) + scenario.run(filter_by_resource_id=True) if metadata_query: - self.list_matched_resources(metadata_query=metadata_query) + scenario.run(metadata_query=metadata_query) if start_time: - self.list_matched_resources(start_time=start_time) + scenario.run(start_time=start_time) if end_time: - self.list_matched_resources(end_time=end_time) + scenario.run(end_time=end_time) if start_time and end_time: - self.list_matched_resources(start_time=start_time, - end_time=end_time) + scenario.run(start_time=start_time, end_time=end_time) if limit: - self.list_matched_resources(limit=limit) + scenario.run(limit=limit) - @validation.required_services(consts.Service.CEILOMETER) - @validation.required_openstack(users=True) - @scenario.configure() - def get_tenant_resources(self): + +@validation.required_services(consts.Service.CEILOMETER) +@validation.required_openstack(users=True) +@scenario.configure(name="CeilometerResource.get_tenant_resources") +class GetTenantResources(ceiloutils.CeilometerScenario): + + def run(self): """Get all tenant resources. This scenario retrieves information about tenant resources using @@ -71,18 +74,16 @@ class CeilometerResource(ceiloutils.CeilometerScenario): for res_id in resources: self._get_resource(res_id) - @validation.required_services(consts.Service.CEILOMETER) - @validation.required_contexts("ceilometer") - @validation.required_openstack(users=True) - @scenario.configure() - def list_matched_resources(self, filter_by_user_id=False, - filter_by_project_id=False, - filter_by_resource_id=False, - metadata_query=None, - start_time=None, - end_time=None, - limit=None): +@validation.required_services(consts.Service.CEILOMETER) +@validation.required_contexts("ceilometer") +@validation.required_openstack(users=True) +@scenario.configure(name="CeilometerResource.list_matched_resources") +class ListMatchedResources(ceiloutils.CeilometerScenario): + + def run(self, filter_by_user_id=False, filter_by_project_id=False, + filter_by_resource_id=False, metadata_query=None, start_time=None, + end_time=None, limit=None): """Get resources that matched fields from context and args. :param filter_by_user_id: flag for query by user_id @@ -99,4 +100,4 @@ class CeilometerResource(ceiloutils.CeilometerScenario): filter_by_resource_id, metadata_query) query += self._make_timestamp_query(start_time, end_time) - self._list_resources(query, limit) + self._list_resources(query, limit) \ No newline at end of file diff --git a/rally/plugins/openstack/scenarios/ceilometer/samples.py b/rally/plugins/openstack/scenarios/ceilometer/samples.py index 8b8f7f91..b3d92e8a 100644 --- a/rally/plugins/openstack/scenarios/ceilometer/samples.py +++ b/rally/plugins/openstack/scenarios/ceilometer/samples.py @@ -18,17 +18,17 @@ from rally.plugins.openstack.scenarios.ceilometer import utils as ceiloutils from rally.task import validation -class CeilometerSamples(ceiloutils.CeilometerScenario): - """Benchmark scenarios for Ceilometer Samples API.""" +"""Scenarios for Ceilometer Samples API.""" - @validation.required_services(consts.Service.CEILOMETER) - @validation.required_contexts("ceilometer") - @validation.required_openstack(users=True) - @scenario.configure() - def list_matched_samples(self, filter_by_resource_id=False, - filter_by_project_id=False, - filter_by_user_id=False, - metadata_query=None, limit=None): + +@validation.required_services(consts.Service.CEILOMETER) +@validation.required_contexts("ceilometer") +@validation.required_openstack(users=True) +@scenario.configure(name="CeilometerSamples.list_matched_samples") +class ListMatchedSamples(ceiloutils.CeilometerScenario): + + def run(self, filter_by_resource_id=False, filter_by_project_id=False, + filter_by_user_id=False, metadata_query=None, limit=None): """Get list of samples that matched fields from context and args. :param filter_by_user_id: flag for query by user_id @@ -43,20 +43,25 @@ class CeilometerSamples(ceiloutils.CeilometerScenario): metadata_query) self._list_samples(query, limit) - @validation.required_services(consts.Service.CEILOMETER) - @validation.required_contexts("ceilometer") - @validation.required_openstack(users=True) - @scenario.configure() - def list_samples(self, metadata_query=None, limit=None): + +@validation.required_services(consts.Service.CEILOMETER) +@validation.required_contexts("ceilometer") +@validation.required_openstack(users=True) +@scenario.configure(name="CeilometerSamples.list_samples") +class ListSamples(ceiloutils.CeilometerScenario): + + def run(self, metadata_query=None, limit=None): """Fetch all available queries for list sample request. :param metadata_query: dict with metadata fields and values for query :param limit: count of samples in response """ - self.list_matched_samples(filter_by_project_id=True) - self.list_matched_samples(filter_by_user_id=True) - self.list_matched_samples(filter_by_resource_id=True) + + scenario = ListMatchedSamples(self.context) + scenario.run(filter_by_project_id=True) + scenario.run(filter_by_user_id=True) + scenario.run(filter_by_resource_id=True) if metadata_query: - self.list_matched_samples(metadata_query=metadata_query) + scenario.run(metadata_query=metadata_query) if limit: - self.list_matched_samples(limit=limit) + scenario.run(limit=limit) \ No newline at end of file diff --git a/rally/plugins/openstack/scenarios/ceilometer/stats.py b/rally/plugins/openstack/scenarios/ceilometer/stats.py index 83dbef31..997ccf82 100644 --- a/rally/plugins/openstack/scenarios/ceilometer/stats.py +++ b/rally/plugins/openstack/scenarios/ceilometer/stats.py @@ -19,15 +19,17 @@ from rally.plugins.openstack.scenarios.ceilometer import utils from rally.task import validation -class CeilometerStats(utils.CeilometerScenario): - """Benchmark scenarios for Ceilometer Stats API.""" +"""Scenarios for Ceilometer Stats API.""" + + +@validation.required_services(consts.Service.CEILOMETER) +@validation.required_openstack(users=True) +@scenario.configure(name="CeilometerStats.create_meter_and_get_stats") +class CreateMeterAndGetStats(utils.CeilometerScenario): @logging.log_deprecated("Use 'get_stats' method, now samples are created" "in context", "0.1.2") - @validation.required_services(consts.Service.CEILOMETER) - @validation.required_openstack(users=True) - @scenario.configure() - def create_meter_and_get_stats(self, **kwargs): + def run(self, **kwargs): """Create a meter and fetch its statistics. Meter is first created and then statistics is fetched for the same @@ -38,14 +40,16 @@ class CeilometerStats(utils.CeilometerScenario): meter = self._create_meter(**kwargs) self._get_stats(meter.counter_name) - @validation.required_services(consts.Service.CEILOMETER) - @validation.required_contexts("ceilometer") - @validation.required_openstack(users=True) - @scenario.configure() - def get_stats(self, meter_name, filter_by_user_id=False, - filter_by_project_id=False, filter_by_resource_id=False, - metadata_query=None, period=None, groupby=None, - aggregates=None): + +@validation.required_services(consts.Service.CEILOMETER) +@validation.required_contexts("ceilometer") +@validation.required_openstack(users=True) +@scenario.configure(name="CeilometerStats.get_stats") +class GetStats(utils.CeilometerScenario): + + def run(self, meter_name, filter_by_user_id=False, + filter_by_project_id=False, filter_by_resource_id=False, + metadata_query=None, period=None, groupby=None, aggregates=None): """Fetch statistics for certain meter. Statistics is fetched for the using @@ -66,4 +70,4 @@ class CeilometerStats(utils.CeilometerScenario): filter_by_user_id, filter_by_resource_id, metadata_query) - self._get_stats(meter_name, query, period, groupby, aggregates) + self._get_stats(meter_name, query, period, groupby, aggregates) \ No newline at end of file diff --git a/rally/plugins/openstack/scenarios/ceilometer/traits.py b/rally/plugins/openstack/scenarios/ceilometer/traits.py index 3eadcf21..2ccf4890 100644 --- a/rally/plugins/openstack/scenarios/ceilometer/traits.py +++ b/rally/plugins/openstack/scenarios/ceilometer/traits.py @@ -19,19 +19,23 @@ from rally.plugins.openstack.scenarios.keystone import utils as kutils from rally.task import validation -class CeilometerTraits(cutils.CeilometerScenario, kutils.KeystoneScenario): - """Benchmark scenarios for Ceilometer Events API.""" +"""Scenarios for Ceilometer Events API.""" - # NOTE(idegtiarov): to work with traits we need to create event firstly, - # there are no other way except emit suitable notification from one of - # services, for example create new user in keystone. - @validation.required_services(consts.Service.CEILOMETER, - consts.Service.KEYSTONE) - @validation.required_openstack(admin=True) - @scenario.configure(context={"admin_cleanup": ["keystone"], - "cleanup": ["ceilometer"]}) - def create_user_and_list_traits(self): +# NOTE(idegtiarov): to work with traits we need to create event firstly, +# there are no other way except emit suitable notification from one of +# services, for example create new user in keystone. + +@validation.required_services(consts.Service.CEILOMETER, + consts.Service.KEYSTONE) +@validation.required_openstack(admin=True) +@scenario.configure(context={"admin_cleanup": ["keystone"], + "cleanup": ["ceilometer"]}, + name="CeilometerTraits.create_user_and_list_traits") +class CreateUserAndListTraits(cutils.CeilometerScenario, + kutils.KeystoneScenario): + + def run(self): """Create user and fetch all event traits. This scenario creates user to store new event and @@ -44,12 +48,18 @@ class CeilometerTraits(cutils.CeilometerScenario, kutils.KeystoneScenario): self._list_event_traits(event_type=event.event_type, trait_name=trait_name) - @validation.required_services(consts.Service.CEILOMETER, - consts.Service.KEYSTONE) - @validation.required_openstack(admin=True) - @scenario.configure(context={"admin_cleanup": ["keystone"], - "cleanup": ["ceilometer"]}) - def create_user_and_list_trait_descriptions(self): + +@validation.required_services(consts.Service.CEILOMETER, + consts.Service.KEYSTONE) +@validation.required_openstack(admin=True) +@scenario.configure(context={"admin_cleanup": ["keystone"], + "cleanup": ["ceilometer"]}, + name="CeilometerTraits.create_user_and" + "_list_trait_descriptions") +class CreateUserAndListTraitDescriptions( + cutils.CeilometerScenario, kutils.KeystoneScenario): + + def run(self): """Create user and fetch all trait descriptions. This scenario creates user to store new event and @@ -58,4 +68,4 @@ class CeilometerTraits(cutils.CeilometerScenario, kutils.KeystoneScenario): """ self._user_create() event = self._list_events()[0] - self._list_event_trait_descriptions(event_type=event.event_type) + self._list_event_trait_descriptions(event_type=event.event_type) \ No newline at end of file diff --git a/tests/unit/plugins/openstack/scenarios/ceilometer/test_meters.py b/tests/unit/plugins/openstack/scenarios/ceilometer/test_meters.py index 18dd7e61..a5634e45 100644 --- a/tests/unit/plugins/openstack/scenarios/ceilometer/test_meters.py +++ b/tests/unit/plugins/openstack/scenarios/ceilometer/test_meters.py @@ -18,37 +18,47 @@ from rally.plugins.openstack.scenarios.ceilometer import meters from tests.unit import test +BASE = "rally.plugins.openstack.scenarios.ceilometer" + + class CeilometerMetersTestCase(test.ScenarioTestCase): - def test_all_meter_list_queries(self): - scenario = meters.CeilometerMeters(self.context) - scenario.list_matched_meters = mock.MagicMock() + @mock.patch("%s.meters.ListMatchedMeters.run" % BASE) + def test_all_meter_list_queries( + self, mock_list_matched_meters_run): + scenario = meters.ListMeters(self.context) metadata_query = {"a": "test"} limit = 100 - scenario.list_meters(metadata_query, limit) - scenario.list_matched_meters.assert_any_call(limit=100) - scenario.list_matched_meters.assert_any_call( + scenario.run(metadata_query, limit) + + mock_list_matched_meters_run.assert_any_call(limit=100) + mock_list_matched_meters_run.assert_any_call( metadata_query=metadata_query) - scenario.list_matched_meters.assert_any_call(filter_by_user_id=True) - scenario.list_matched_meters.assert_any_call(filter_by_project_id=True) - scenario.list_matched_meters.assert_any_call( + mock_list_matched_meters_run.assert_any_call(filter_by_user_id=True) + mock_list_matched_meters_run.assert_any_call(filter_by_project_id=True) + mock_list_matched_meters_run.assert_any_call( filter_by_resource_id=True) - def test_meter_list_queries_without_limit_and_metadata(self): - scenario = meters.CeilometerMeters(self.context) - scenario.list_matched_meters = mock.MagicMock() - scenario.list_meters() + @mock.patch("%s.meters.ListMatchedMeters.run" % BASE) + def test_meter_list_queries_without_limit_and_metadata( + self, mock_list_matched_meters_run): + + scenario = meters.ListMeters(self.context) + scenario.run() expected_call_args_list = [ mock.call(filter_by_project_id=True), mock.call(filter_by_user_id=True), mock.call(filter_by_resource_id=True) ] - self.assertSequenceEqual(expected_call_args_list, - scenario.list_matched_meters.call_args_list) + self.assertSequenceEqual( + expected_call_args_list, + mock_list_matched_meters_run.call_args_list) - def test_list_matched_meters(self): - scenario = meters.CeilometerMeters(self.context) - scenario._list_meters = mock.MagicMock() + @mock.patch("%s.meters.ListMatchedMeters._list_meters" % BASE) + def test_list_matched_meters( + self, mock_list_matched_meters__list_meters): + mock_func = mock_list_matched_meters__list_meters + scenario = meters.ListMatchedMeters(self.context) context = {"user": {"tenant_id": "fake", "id": "fake_id"}, "tenant": {"id": "fake_id", "resources": ["fake_resource"]}} @@ -56,8 +66,8 @@ class CeilometerMetersTestCase(test.ScenarioTestCase): metadata_query = {"a": "test"} limit = 100 - scenario.list_matched_meters(True, True, True, metadata_query, limit) - scenario._list_meters.assert_called_once_with( + scenario.run(True, True, True, metadata_query, limit) + mock_func.assert_called_once_with( [{"field": "user_id", "value": "fake_id", "op": "eq"}, {"field": "project_id", "value": "fake_id", "op": "eq"}, {"field": "resource_id", "value": "fake_resource", "op": "eq"}, diff --git a/tests/unit/plugins/openstack/scenarios/ceilometer/test_resources.py b/tests/unit/plugins/openstack/scenarios/ceilometer/test_resources.py index 94cea6af..85dbcd9f 100644 --- a/tests/unit/plugins/openstack/scenarios/ceilometer/test_resources.py +++ b/tests/unit/plugins/openstack/scenarios/ceilometer/test_resources.py @@ -19,32 +19,36 @@ from rally.plugins.openstack.scenarios.ceilometer import resources from tests.unit import test +BASE = "rally.plugins.openstack.scenarios.ceilometer" + + class CeilometerResourcesTestCase(test.ScenarioTestCase): - def test_all_resource_list_queries(self): - scenario = resources.CeilometerResource(self.context) - scenario.list_matched_resources = mock.MagicMock() + @mock.patch("%s.resources.ListMatchedResources.run" % BASE) + def test_all_resource_list_queries( + self, mock_list_matched_resources_run): metadata_query = {"a": "test"} start_time = "fake start time" end_time = "fake end time" limit = 100 - scenario.list_resources(metadata_query, start_time, - end_time, limit) - scenario.list_matched_resources.assert_any_call(limit=100) - scenario.list_matched_resources.assert_any_call(start_time=start_time, + scenario = resources.ListResources(self.context) + scenario.run(metadata_query, start_time, end_time, limit) + mock_list_matched_resources_run.assert_any_call(limit=100) + mock_list_matched_resources_run.assert_any_call(start_time=start_time, end_time=end_time) - scenario.list_matched_resources.assert_any_call(end_time=end_time) - scenario.list_matched_resources.assert_any_call(start_time=start_time) - scenario.list_matched_resources.assert_any_call( + mock_list_matched_resources_run.assert_any_call(end_time=end_time) + mock_list_matched_resources_run.assert_any_call(start_time=start_time) + mock_list_matched_resources_run.assert_any_call( metadata_query=metadata_query) - scenario.list_matched_resources.assert_any_call(filter_by_user_id=True) - scenario.list_matched_resources.assert_any_call( + mock_list_matched_resources_run.assert_any_call( + filter_by_user_id=True) + mock_list_matched_resources_run.assert_any_call( filter_by_project_id=True) - scenario.list_matched_resources.assert_any_call( + mock_list_matched_resources_run.assert_any_call( filter_by_resource_id=True) def test_list_matched_resources(self): - scenario = resources.CeilometerResource(self.context) + scenario = resources.ListMatchedResources(self.context) scenario._list_resources = mock.MagicMock() context = {"user": {"tenant_id": "fake", "id": "fake_id"}, "tenant": {"id": "fake_id", @@ -55,8 +59,8 @@ class CeilometerResourcesTestCase(test.ScenarioTestCase): start_time = "2015-09-09T00:00:00" end_time = "2015-09-10T00:00:00" limit = 100 - scenario.list_matched_resources(True, True, True, metadata_query, - start_time, end_time, limit) + scenario.run(True, True, True, metadata_query, + start_time, end_time, limit) scenario._list_resources.assert_called_once_with( [{"field": "user_id", "value": "fake_id", "op": "eq"}, {"field": "project_id", "value": "fake_id", "op": "eq"}, @@ -70,20 +74,21 @@ class CeilometerResourcesTestCase(test.ScenarioTestCase): 100) def test_get_tenant_resources(self): - scenario = resources.CeilometerResource(self.context) + scenario = resources.GetTenantResources(self.context) resource_list = ["id1", "id2", "id3", "id4"] context = {"user": {"tenant_id": "fake"}, "tenant": {"id": "fake", "resources": resource_list}} scenario.context = context scenario._get_resource = mock.MagicMock() - scenario.get_tenant_resources() + scenario.run() for resource_id in resource_list: scenario._get_resource.assert_any_call(resource_id) - def test_resource_list_queries_without_limit_and_metadata(self): - scenario = resources.CeilometerResource(self.context) - scenario.list_matched_resources = mock.MagicMock() - scenario.list_resources() + @mock.patch("%s.resources.ListMatchedResources.run" % BASE) + def test_resource_list_queries_without_limit_and_metadata( + self, mock_list_matched_resources_run): + scenario = resources.ListResources() + scenario.run() expected_call_args_list = [ mock.call(filter_by_project_id=True), mock.call(filter_by_user_id=True), @@ -91,13 +96,12 @@ class CeilometerResourcesTestCase(test.ScenarioTestCase): ] self.assertSequenceEqual( expected_call_args_list, - scenario.list_matched_resources.call_args_list) + mock_list_matched_resources_run.call_args_list) def test_get_tenant_resources_with_exception(self): - scenario = resources.CeilometerResource(self.context) + scenario = resources.GetTenantResources(self.context) resource_list = [] context = {"user": {"tenant_id": "fake"}, "tenant": {"id": "fake", "resources": resource_list}} scenario.context = context - self.assertRaises(exceptions.NotFoundException, - scenario.get_tenant_resources) + self.assertRaises(exceptions.NotFoundException, scenario.run) diff --git a/tests/unit/plugins/openstack/scenarios/ceilometer/test_samples.py b/tests/unit/plugins/openstack/scenarios/ceilometer/test_samples.py index 09c97a1d..366a88cc 100644 --- a/tests/unit/plugins/openstack/scenarios/ceilometer/test_samples.py +++ b/tests/unit/plugins/openstack/scenarios/ceilometer/test_samples.py @@ -18,38 +18,44 @@ from rally.plugins.openstack.scenarios.ceilometer import samples from tests.unit import test +BASE = "rally.plugins.openstack.scenarios.ceilometer" + + class CeilometerSamplesTestCase(test.ScenarioTestCase): - def test_all_list_samples(self): - scenario = samples.CeilometerSamples(self.context) - scenario.list_matched_samples = mock.MagicMock() + @mock.patch("%s.samples.ListMatchedSamples.run" % BASE) + def test_all_list_samples(self, mock_list_matched_samples_run): metadata_query = {"a": "test"} limit = 10 - scenario.list_samples(metadata_query, limit) - scenario.list_matched_samples.assert_any_call(limit=10) - scenario.list_matched_samples.assert_any_call( + scenario = samples.ListSamples(self.context) + scenario.run(metadata_query, limit) + mock_list_matched_samples_run.assert_any_call(limit=10) + mock_list_matched_samples_run.assert_any_call( metadata_query=metadata_query) - scenario.list_matched_samples.assert_any_call( + mock_list_matched_samples_run.assert_any_call( filter_by_resource_id=True) - scenario.list_matched_samples.assert_any_call( + mock_list_matched_samples_run.assert_any_call( filter_by_user_id=True) - scenario.list_matched_samples.assert_any_call( + mock_list_matched_samples_run.assert_any_call( filter_by_project_id=True) - def test_list_samples_without_limit_and_metadata(self): - scenario = samples.CeilometerSamples(self.context) - scenario.list_matched_samples = mock.MagicMock() - scenario.list_samples() + @mock.patch("%s.samples.ListMatchedSamples.run" % BASE) + def test_list_samples_without_limit_and_metadata( + self, + mock_list_matched_samples_run): + scenario = samples.ListSamples() + scenario.run() expected_call_args_list = [ mock.call(filter_by_project_id=True), mock.call(filter_by_user_id=True), mock.call(filter_by_resource_id=True) ] - self.assertSequenceEqual(expected_call_args_list, - scenario.list_matched_samples.call_args_list) + self.assertSequenceEqual( + expected_call_args_list, + mock_list_matched_samples_run.call_args_list) def test_list_matched_samples(self): - scenario = samples.CeilometerSamples(self.context) + scenario = samples.ListMatchedSamples() scenario._list_samples = mock.MagicMock() context = {"user": {"tenant_id": "fake", "id": "fake_id"}, "tenant": {"id": "fake_id", @@ -57,7 +63,7 @@ class CeilometerSamplesTestCase(test.ScenarioTestCase): scenario.context = context metadata_query = {"a": "test"} limit = 10 - scenario.list_matched_samples(True, True, True, metadata_query, limit) + scenario.run(True, True, True, metadata_query, limit) scenario._list_samples.assert_called_once_with( [{"field": "user_id", "value": "fake_id", "op": "eq"}, {"field": "project_id", "value": "fake_id", "op": "eq"}, diff --git a/tests/unit/plugins/openstack/scenarios/ceilometer/test_stats.py b/tests/unit/plugins/openstack/scenarios/ceilometer/test_stats.py index 41a235d8..b5f0a974 100644 --- a/tests/unit/plugins/openstack/scenarios/ceilometer/test_stats.py +++ b/tests/unit/plugins/openstack/scenarios/ceilometer/test_stats.py @@ -21,7 +21,7 @@ from tests.unit import test class CeilometerStatsTestCase(test.ScenarioTestCase): def test_get_stats(self): - scenario = stats.CeilometerStats(self.context) + scenario = stats.GetStats(self.context) scenario._get_stats = mock.MagicMock() context = {"user": {"tenant_id": "fake", "id": "fake_id"}, "tenant": {"id": "fake_id", @@ -31,8 +31,8 @@ class CeilometerStatsTestCase(test.ScenarioTestCase): groupby = "user_id" aggregates = "sum" scenario.context = context - scenario.get_stats("fake_meter", True, True, True, metadata_query, - period, groupby, aggregates) + scenario.run("fake_meter", True, True, True, metadata_query, + period, groupby, aggregates) scenario._get_stats.assert_called_once_with( "fake_meter", [{"field": "user_id", "value": "fake_id", "op": "eq"}, diff --git a/tests/unit/plugins/openstack/scenarios/ceilometer/test_traits.py b/tests/unit/plugins/openstack/scenarios/ceilometer/test_traits.py index 0866520a..20c81e0c 100644 --- a/tests/unit/plugins/openstack/scenarios/ceilometer/test_traits.py +++ b/tests/unit/plugins/openstack/scenarios/ceilometer/test_traits.py @@ -21,7 +21,7 @@ from tests.unit import test class CeilometerTraitsTestCase(test.ScenarioTestCase): def test_list_traits(self): - scenario = traits.CeilometerTraits(self.context) + scenario = traits.CreateUserAndListTraits(self.context) scenario._user_create = mock.MagicMock() scenario._list_events = mock.MagicMock() @@ -30,14 +30,15 @@ class CeilometerTraitsTestCase(test.ScenarioTestCase): event_type="fake_event_type", traits=[{"name": "fake_trait_name"}]) ] - scenario.create_user_and_list_traits() + scenario.run() scenario._user_create.assert_called_once_with() scenario._list_events.assert_called_with() scenario._list_event_traits.assert_called_once_with( event_type="fake_event_type", trait_name="fake_trait_name") def test_list_trait_descriptions(self): - scenario = traits.CeilometerTraits(self.context) + scenario = traits.CreateUserAndListTraitDescriptions( + self.context) scenario._user_create = mock.MagicMock() scenario._list_events = mock.MagicMock() @@ -45,7 +46,7 @@ class CeilometerTraitsTestCase(test.ScenarioTestCase): scenario._list_events.return_value = [mock.Mock( event_type="fake_event_type") ] - scenario.create_user_and_list_trait_descriptions() + scenario.run() scenario._user_create.assert_called_once_with() scenario._list_events.assert_called_with() scenario._list_event_trait_descriptions.assert_called_once_with(