diff --git a/tests/api/v2/test_acl.py b/tests/api/v2/acl.py similarity index 100% rename from tests/api/v2/test_acl.py rename to tests/api/v2/acl.py diff --git a/tests/api/v2/test_alarm.py b/tests/api/v2/alarm.py similarity index 100% rename from tests/api/v2/test_alarm.py rename to tests/api/v2/alarm.py diff --git a/tests/api/v2/base.py b/tests/api/v2/base.py index 7ea43eaa0..70fc216f4 100644 --- a/tests/api/v2/base.py +++ b/tests/api/v2/base.py @@ -20,7 +20,4 @@ from ceilometer.tests import api class FunctionalTest(api.FunctionalTest): - - database_connection = 'mongodb://__test__' - PATH_PREFIX = '/v2' diff --git a/tests/api/v2/test_compute_duration_by_resource.py b/tests/api/v2/compute_duration_by_resource.py similarity index 100% rename from tests/api/v2/test_compute_duration_by_resource.py rename to tests/api/v2/compute_duration_by_resource.py diff --git a/tests/api/v2/test_list_events.py b/tests/api/v2/list_events.py similarity index 100% rename from tests/api/v2/test_list_events.py rename to tests/api/v2/list_events.py diff --git a/tests/api/v2/test_list_meters.py b/tests/api/v2/list_meters.py similarity index 100% rename from tests/api/v2/test_list_meters.py rename to tests/api/v2/list_meters.py diff --git a/tests/api/v2/test_list_resources.py b/tests/api/v2/list_resources.py similarity index 100% rename from tests/api/v2/test_list_resources.py rename to tests/api/v2/list_resources.py diff --git a/tests/api/v2/test_post_samples.py b/tests/api/v2/post_samples.py similarity index 100% rename from tests/api/v2/test_post_samples.py rename to tests/api/v2/post_samples.py diff --git a/tests/api/v2/statistics.py b/tests/api/v2/statistics.py new file mode 100644 index 000000000..239b102a7 --- /dev/null +++ b/tests/api/v2/statistics.py @@ -0,0 +1,477 @@ +# -*- encoding: utf-8 -*- +# +# Copyright © 2012 New Dream Network, LLC (DreamHost) +# +# Author: Doug Hellmann +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +"""Test events statistics retrieval.""" + +import datetime + +from oslo.config import cfg + +from . import base +from ceilometer import counter +from ceilometer.storage.impl_mongodb import require_map_reduce +from ceilometer.publisher import rpc + + +class TestMaxProjectVolume(base.FunctionalTest): + + PATH = '/meters/volume.size/statistics' + + def setUp(self): + super(TestMaxProjectVolume, self).setUp() + require_map_reduce(self.conn) + + self.counters = [] + for i in range(3): + c = counter.Counter( + 'volume.size', + 'gauge', + 'GiB', + 5 + i, + 'user-id', + 'project1', + 'resource-id-%s' % i, + timestamp=datetime.datetime(2012, 9, 25, 10 + i, 30 + i), + resource_metadata={'display_name': 'test-volume', + 'tag': 'self.counter', + } + ) + self.counters.append(c) + msg = rpc.meter_message_from_counter( + c, + cfg.CONF.publisher_rpc.metering_secret, + 'source1', + ) + self.conn.record_metering_data(msg) + + def test_no_time_bounds(self): + data = self.get_json(self.PATH, q=[{'field': 'project_id', + 'value': 'project1', + }]) + self.assertEqual(data[0]['max'], 7) + self.assertEqual(data[0]['count'], 3) + + def test_start_timestamp(self): + data = self.get_json(self.PATH, q=[{'field': 'project_id', + 'value': 'project1', + }, + {'field': 'timestamp', + 'op': 'ge', + 'value': '2012-09-25T11:30:00', + }, + ]) + self.assertEqual(data[0]['max'], 7) + self.assertEqual(data[0]['count'], 2) + + def test_start_timestamp_after(self): + data = self.get_json(self.PATH, q=[{'field': 'project_id', + 'value': 'project1', + }, + {'field': 'timestamp', + 'op': 'ge', + 'value': '2012-09-25T12:34:00', + }, + ]) + self.assertEqual(data, []) + + def test_end_timestamp(self): + data = self.get_json(self.PATH, q=[{'field': 'project_id', + 'value': 'project1', + }, + {'field': 'timestamp', + 'op': 'le', + 'value': '2012-09-25T11:30:00', + }, + ]) + self.assertEqual(data[0]['max'], 5) + self.assertEqual(data[0]['count'], 1) + + def test_end_timestamp_before(self): + data = self.get_json(self.PATH, q=[{'field': 'project_id', + 'value': 'project1', + }, + {'field': 'timestamp', + 'op': 'le', + 'value': '2012-09-25T09:54:00', + }, + ]) + self.assertEqual(data, []) + + def test_start_end_timestamp(self): + data = self.get_json(self.PATH, q=[{'field': 'project_id', + 'value': 'project1', + }, + {'field': 'timestamp', + 'op': 'ge', + 'value': '2012-09-25T11:30:00', + }, + {'field': 'timestamp', + 'op': 'le', + 'value': '2012-09-25T11:32:00', + }, + ]) + self.assertEqual(data[0]['max'], 6) + self.assertEqual(data[0]['count'], 1) + + +class TestMaxResourceVolume(base.FunctionalTest): + + PATH = '/meters/volume.size/statistics' + + def setUp(self): + super(TestMaxResourceVolume, self).setUp() + require_map_reduce(self.conn) + + self.counters = [] + for i in range(3): + c = counter.Counter( + 'volume.size', + 'gauge', + 'GiB', + 5 + i, + 'user-id', + 'project1', + 'resource-id', + timestamp=datetime.datetime(2012, 9, 25, 10 + i, 30 + i), + resource_metadata={'display_name': 'test-volume', + 'tag': 'self.counter', + } + ) + self.counters.append(c) + msg = rpc.meter_message_from_counter( + c, + cfg.CONF.publisher_rpc.metering_secret, + 'source1', + ) + self.conn.record_metering_data(msg) + + def test_no_time_bounds(self): + data = self.get_json(self.PATH, q=[{'field': 'resource_id', + 'value': 'resource-id', + }]) + self.assertEqual(data[0]['max'], 7) + self.assertEqual(data[0]['count'], 3) + + def test_no_time_bounds_with_period(self): + data = self.get_json(self.PATH, + q=[{'field': 'resource_id', + 'value': 'resource-id'}], + period=3600) + self.assertEqual(len(data), 3) + self.assertEqual(set(x['duration_start'] for x in data), + set([u'2012-09-25T10:30:00', + u'2012-09-25T12:32:00', + u'2012-09-25T11:31:00'])) + self.assertEqual(data[0]['period'], 3600) + self.assertEqual(set(x['period_start'] for x in data), + set([u'2012-09-25T10:00:00', + u'2012-09-25T11:00:00', + u'2012-09-25T12:00:00'])) + + def test_start_timestamp(self): + data = self.get_json(self.PATH, q=[{'field': 'resource_id', + 'value': 'resource-id', + }, + {'field': 'timestamp', + 'op': 'ge', + 'value': '2012-09-25T11:30:00', + }, + ]) + self.assertEqual(data[0]['max'], 7) + self.assertEqual(data[0]['count'], 2) + + def test_start_timestamp_after(self): + data = self.get_json(self.PATH, q=[{'field': 'resource_id', + 'value': 'resource-id', + }, + {'field': 'timestamp', + 'op': 'ge', + 'value': '2012-09-25T12:34:00', + }, + ]) + self.assertEqual(data, []) + + def test_end_timestamp(self): + data = self.get_json(self.PATH, q=[{'field': 'resource_id', + 'value': 'resource-id', + }, + {'field': 'timestamp', + 'op': 'le', + 'value': '2012-09-25T11:30:00', + }, + ]) + self.assertEqual(data[0]['max'], 5) + self.assertEqual(data[0]['count'], 1) + + def test_end_timestamp_before(self): + data = self.get_json(self.PATH, q=[{'field': 'resource_id', + 'value': 'resource-id', + }, + {'field': 'timestamp', + 'op': 'le', + 'value': '2012-09-25T09:54:00', + }, + ]) + self.assertEqual(data, []) + + def test_start_end_timestamp(self): + data = self.get_json(self.PATH, q=[{'field': 'resource_id', + 'value': 'resource-id', + }, + {'field': 'timestamp', + 'op': 'ge', + 'value': '2012-09-25T11:30:00', + }, + {'field': 'timestamp', + 'op': 'le', + 'value': '2012-09-25T11:32:00', + }, + ]) + self.assertEqual(data[0]['max'], 6) + self.assertEqual(data[0]['count'], 1) + + +class TestSumProjectVolume(base.FunctionalTest): + + PATH = '/meters/volume.size/statistics' + + def setUp(self): + super(TestSumProjectVolume, self).setUp() + require_map_reduce(self.conn) + + self.counters = [] + for i in range(3): + c = counter.Counter( + 'volume.size', + 'gauge', + 'GiB', + 5 + i, + 'user-id', + 'project1', + 'resource-id-%s' % i, + timestamp=datetime.datetime(2012, 9, 25, 10 + i, 30 + i), + resource_metadata={'display_name': 'test-volume', + 'tag': 'self.counter', + } + ) + self.counters.append(c) + msg = rpc.meter_message_from_counter( + c, + cfg.CONF.publisher_rpc.metering_secret, + 'source1', + ) + self.conn.record_metering_data(msg) + + def test_no_time_bounds(self): + data = self.get_json(self.PATH, q=[{'field': 'project_id', + 'value': 'project1', + }]) + expected = 5 + 6 + 7 + self.assertEqual(data[0]['sum'], expected) + self.assertEqual(data[0]['count'], 3) + + def test_start_timestamp(self): + data = self.get_json(self.PATH, q=[{'field': 'project_id', + 'value': 'project1', + }, + {'field': 'timestamp', + 'op': 'ge', + 'value': '2012-09-25T11:30:00', + }, + ]) + expected = 6 + 7 + self.assertEqual(data[0]['sum'], expected) + self.assertEqual(data[0]['count'], 2) + + def test_start_timestamp_after(self): + data = self.get_json(self.PATH, q=[{'field': 'project_id', + 'value': 'project1', + }, + {'field': 'timestamp', + 'op': 'ge', + 'value': '2012-09-25T12:34:00', + }, + ]) + self.assertEqual(data, []) + + def test_end_timestamp(self): + data = self.get_json(self.PATH, q=[{'field': 'project_id', + 'value': 'project1', + }, + {'field': 'timestamp', + 'op': 'le', + 'value': '2012-09-25T11:30:00', + }, + ]) + self.assertEqual(data[0]['sum'], 5) + self.assertEqual(data[0]['count'], 1) + + def test_end_timestamp_before(self): + data = self.get_json(self.PATH, q=[{'field': 'project_id', + 'value': 'project1', + }, + {'field': 'timestamp', + 'op': 'le', + 'value': '2012-09-25T09:54:00', + }, + ]) + self.assertEqual(data, []) + + def test_start_end_timestamp(self): + data = self.get_json(self.PATH, q=[{'field': 'project_id', + 'value': 'project1', + }, + {'field': 'timestamp', + 'op': 'ge', + 'value': '2012-09-25T11:30:00', + }, + {'field': 'timestamp', + 'op': 'le', + 'value': '2012-09-25T11:32:00', + }, + ]) + self.assertEqual(data[0]['sum'], 6) + self.assertEqual(data[0]['count'], 1) + + +class TestSumResourceVolume(base.FunctionalTest): + + PATH = '/meters/volume.size/statistics' + + def setUp(self): + super(TestSumResourceVolume, self).setUp() + require_map_reduce(self.conn) + + self.counters = [] + for i in range(3): + c = counter.Counter( + 'volume.size', + 'gauge', + 'GiB', + 5 + i, + 'user-id', + 'project1', + 'resource-id', + timestamp=datetime.datetime(2012, 9, 25, 10 + i, 30 + i), + resource_metadata={'display_name': 'test-volume', + 'tag': 'self.counter', + } + ) + self.counters.append(c) + msg = rpc.meter_message_from_counter( + c, + cfg.CONF.publisher_rpc.metering_secret, + 'source1', + ) + self.conn.record_metering_data(msg) + + def test_no_time_bounds(self): + data = self.get_json(self.PATH, q=[{'field': 'resource_id', + 'value': 'resource-id', + }]) + self.assertEqual(data[0]['sum'], 5 + 6 + 7) + self.assertEqual(data[0]['count'], 3) + + def test_no_time_bounds_with_period(self): + data = self.get_json(self.PATH, + q=[{'field': 'resource_id', + 'value': 'resource-id'}], + period=1800) + self.assertEqual(len(data), 3) + self.assertEqual(set(x['duration_start'] for x in data), + set([u'2012-09-25T10:30:00', + u'2012-09-25T12:32:00', + u'2012-09-25T11:31:00'])) + self.assertEqual(data[0]['period'], 1800) + self.assertEqual(set(x['period_start'] for x in data), + set([u'2012-09-25T10:30:00', + u'2012-09-25T11:30:00', + u'2012-09-25T12:30:00'])) + + def test_start_timestamp(self): + data = self.get_json(self.PATH, q=[{'field': 'resource_id', + 'value': 'resource-id', + }, + {'field': 'timestamp', + 'op': 'ge', + 'value': '2012-09-25T11:30:00', + }]) + self.assertEqual(data[0]['sum'], 6 + 7) + self.assertEqual(data[0]['count'], 2) + + def test_start_timestamp_with_period(self): + data = self.get_json(self.PATH, + q=[{'field': 'resource_id', + 'value': 'resource-id'}, + {'field': 'timestamp', + 'op': 'ge', + 'value': '2012-09-25T10:15:00'}], + period=7200) + self.assertEqual(len(data), 2) + self.assertEqual(set(x['duration_start'] for x in data), + set([u'2012-09-25T10:30:00', + u'2012-09-25T12:32:00'])) + self.assertEqual(data[0]['period'], 7200) + self.assertEqual(set(x['period_start'] for x in data), + set([u'2012-09-25T10:15:00', + u'2012-09-25T12:15:00'])) + + def test_start_timestamp_after(self): + data = self.get_json(self.PATH, q=[{'field': 'resource_id', + 'value': 'resource-id', + }, + {'field': 'timestamp', + 'op': 'ge', + 'value': '2012-09-25T12:34:00', + }]) + self.assertEqual(data, []) + + def test_end_timestamp(self): + data = self.get_json(self.PATH, q=[{'field': 'resource_id', + 'value': 'resource-id', + }, + {'field': 'timestamp', + 'op': 'le', + 'value': '2012-09-25T11:30:00', + }]) + self.assertEqual(data[0]['sum'], 5) + self.assertEqual(data[0]['count'], 1) + + def test_end_timestamp_before(self): + data = self.get_json(self.PATH, q=[{'field': 'resource_id', + 'value': 'resource-id', + }, + {'field': 'timestamp', + 'op': 'le', + 'value': '2012-09-25T09:54:00', + }]) + self.assertEqual(data, []) + + def test_start_end_timestamp(self): + data = self.get_json(self.PATH, q=[{'field': 'resource_id', + 'value': 'resource-id', + }, + {'field': 'timestamp', + 'op': 'ge', + 'value': '2012-09-25T11:30:00', + }, + {'field': 'timestamp', + 'op': 'lt', + 'value': '2012-09-25T11:32:00', + }]) + self.assertEqual(data[0]['sum'], 6) + self.assertEqual(data[0]['count'], 1) diff --git a/tests/api/v2/test_app.py b/tests/api/v2/test_app.py index 2a20c80aa..3b0b41d24 100644 --- a/tests/api/v2/test_app.py +++ b/tests/api/v2/test_app.py @@ -61,6 +61,9 @@ class TestApp(base.TestCase): class TestApiMiddleware(FunctionalTest): + # This doesn't really matter + database_connection = 'mongodb://__test__' + def test_json_parsable_error_middleware_404(self): response = self.get_json('/invalid_path', expect_errors=True, diff --git a/tests/api/v2/test_impl_hbase.py b/tests/api/v2/test_impl_hbase.py new file mode 100644 index 000000000..5c00b0566 --- /dev/null +++ b/tests/api/v2/test_impl_hbase.py @@ -0,0 +1,76 @@ +# -*- encoding: utf-8 -*- +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +# from . import acl +# from . import alarm +# from . import compute_duration_by_resource +# from . import list_events +from . import list_meters +# from . import list_resources +from . import post_samples +# from . import statistics + + +# TODO(jd) Fix the HBase driver to pass these tests! +# class TestAPIAcl(acl.TestAPIACL): +# database_connection = 'hbase://__test__' + +# TODO(jd) Fix the HBase driver to pass these tests! +# class TestListEvents(list_events.TestListEvents): +# database_connection = 'hbase://__test__' + +# TODO(jd) Fix the HBase driver to pass these tests! +# class TestListEmptyAlarms(alarm.TestListEmptyAlarms): +# database_connection = 'hbase://__test__' + +# TODO(jd) Fix the HBase driver to pass these tests! +# class TestAlarms(alarm.TestAlarms): +# database_connection = 'hbase://__test__' + +# TODO(jd) Fix the HBase driver to pass these tests! +# class TestComputeDurationByResource( +# compute_duration_by_resource.TestComputeDurationByResource): +# database_connection = 'hbase://__test__' + + +class TestListEmptyMeters(list_meters.TestListEmptyMeters): + database_connection = 'hbase://__test__' + +# TODO(jd) Fix the HBase driver to pass these tests! +# class TestListMeters(list_meters.TestListMeters): +# database_connection = 'hbase://__test__' + +# TODO(jd) Fix the HBase driver to pass these tests! +# class TestListResources(list_resources.TestListResources): +# database_connection = 'hbase://__test__' + +# TODO(jd) Fix the HBase driver to pass these tests! +# class TestMaxProjectVolume(statistics.TestMaxProjectVolume): +# database_connection = 'hbase://__test__' + +# TODO(jd) Fix the HBase driver to pass these tests! +# class TestMaxResourceVolume(statistics.TestMaxResourceVolume): +# database_connection = 'hbase://__test__' + +# TODO(jd) Fix the HBase driver to pass these tests! +# class TestSumProjectVolume(statistics.TestSumProjectVolume): +# database_connection = 'hbase://__test__' + +# TODO(jd) Fix the HBase driver to pass these tests! +# class TestSumResourceVolume(statistics.TestSumProjectVolume): +# database_connection = 'hbase://__test__' + + +class TestPostSamples(post_samples.TestPostSamples): + database_connection = 'hbase://__test__' diff --git a/tests/api/v2/test_impl_mongodb.py b/tests/api/v2/test_impl_mongodb.py new file mode 100644 index 000000000..105c76046 --- /dev/null +++ b/tests/api/v2/test_impl_mongodb.py @@ -0,0 +1,75 @@ +# -*- encoding: utf-8 -*- +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from . import acl +from . import alarm +from . import compute_duration_by_resource +from . import list_events +from . import list_meters +from . import list_resources +from . import post_samples +from . import statistics + + +class TestAPIAcl(acl.TestAPIACL): + database_connection = 'mongodb://__test__' + + +class TestListEvents(list_events.TestListEvents): + database_connection = 'mongodb://__test__' + + +class TestListEmptyAlarms(alarm.TestListEmptyAlarms): + database_connection = 'mongodb://__test__' + + +class TestAlarms(alarm.TestAlarms): + database_connection = 'mongodb://__test__' + + +class TestComputeDurationByResource( + compute_duration_by_resource.TestComputeDurationByResource): + database_connection = 'mongodb://__test__' + + +class TestListEmptyMeters(list_meters.TestListEmptyMeters): + database_connection = 'mongodb://__test__' + + +class TestListMeters(list_meters.TestListMeters): + database_connection = 'mongodb://__test__' + + +class TestListResources(list_resources.TestListResources): + database_connection = 'mongodb://__test__' + + +class TestMaxProjectVolume(statistics.TestMaxProjectVolume): + database_connection = 'mongodb://__test__' + + +class TestMaxResourceVolume(statistics.TestMaxResourceVolume): + database_connection = 'mongodb://__test__' + + +class TestSumProjectVolume(statistics.TestSumProjectVolume): + database_connection = 'mongodb://__test__' + + +class TestSumResourceVolume(statistics.TestSumProjectVolume): + database_connection = 'mongodb://__test__' + + +class TestPostSamples(post_samples.TestPostSamples): + database_connection = 'mongodb://__test__' diff --git a/tests/api/v2/test_impl_sqlalchemy.py b/tests/api/v2/test_impl_sqlalchemy.py new file mode 100644 index 000000000..230de3014 --- /dev/null +++ b/tests/api/v2/test_impl_sqlalchemy.py @@ -0,0 +1,75 @@ +# -*- encoding: utf-8 -*- +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from . import acl +from . import alarm +# from . import compute_duration_by_resource +from . import list_events +from . import list_meters +from . import list_resources +from . import post_samples +# from . import statistics + + +class TestAPIAcl(acl.TestAPIACL): + database_connection = 'sqlite://' + + +class TestListEvents(list_events.TestListEvents): + database_connection = 'sqlite://' + + +class TestListEmptyAlarms(alarm.TestListEmptyAlarms): + database_connection = 'sqlite://' + + +class TestAlarms(alarm.TestAlarms): + database_connection = 'sqlite://' + +# TODO(jd) fix SQL driver to pass this test! +# class TestComputeDurationByResource( +# compute_duration_by_resource.TestComputeDurationByResource): +# database_connection = 'sqlite://' + + +class TestListEmptyMeters(list_meters.TestListEmptyMeters): + database_connection = 'sqlite://' + + +class TestListMeters(list_meters.TestListMeters): + database_connection = 'sqlite://' + + +class TestListResources(list_resources.TestListResources): + database_connection = 'sqlite://' + +# TODO(jd) fix SQL driver to pass this test! +# class TestMaxProjectVolume(statistics.TestMaxProjectVolume): +# database_connection = 'sqlite://' + +# TODO(jd) fix SQL driver to pass this test! +# class TestMaxResourceVolume(statistics.TestMaxResourceVolume): +# database_connection = 'sqlite://' + +# TODO(jd) fix SQL driver to pass this test! +# class TestSumProjectVolume(statistics.TestSumProjectVolume): +# database_connection = 'sqlite:// ' + +# TODO(jd) fix SQL driver to pass this test! +# class TestSumResourceVolume(statistics.TestSumProjectVolume): +# database_connection = 'sqlite:// ' + + +class TestPostSamples(post_samples.TestPostSamples): + database_connection = 'sqlite:// ' diff --git a/tests/api/v2/test_max_project_volume.py b/tests/api/v2/test_max_project_volume.py deleted file mode 100644 index 87942bea4..000000000 --- a/tests/api/v2/test_max_project_volume.py +++ /dev/null @@ -1,131 +0,0 @@ -# -*- encoding: utf-8 -*- -# -# Copyright © 2012 New Dream Network, LLC (DreamHost) -# -# Author: Steven Berler -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -"""Test getting the max resource volume. -""" - -import datetime - -from oslo.config import cfg - -from ceilometer.publisher import rpc -from ceilometer import counter - -from ceilometer.storage.impl_mongodb import require_map_reduce - -from .base import FunctionalTest - - -class TestMaxProjectVolume(FunctionalTest): - - PATH = '/meters/volume.size/statistics' - - def setUp(self): - super(TestMaxProjectVolume, self).setUp() - require_map_reduce(self.conn) - - self.counters = [] - for i in range(3): - c = counter.Counter( - 'volume.size', - 'gauge', - 'GiB', - 5 + i, - 'user-id', - 'project1', - 'resource-id-%s' % i, - timestamp=datetime.datetime(2012, 9, 25, 10 + i, 30 + i), - resource_metadata={'display_name': 'test-volume', - 'tag': 'self.counter', - } - ) - self.counters.append(c) - msg = rpc.meter_message_from_counter( - c, - cfg.CONF.publisher_rpc.metering_secret, - 'source1', - ) - self.conn.record_metering_data(msg) - - def test_no_time_bounds(self): - data = self.get_json(self.PATH, q=[{'field': 'project_id', - 'value': 'project1', - }]) - self.assertEqual(data[0]['max'], 7) - self.assertEqual(data[0]['count'], 3) - - def test_start_timestamp(self): - data = self.get_json(self.PATH, q=[{'field': 'project_id', - 'value': 'project1', - }, - {'field': 'timestamp', - 'op': 'ge', - 'value': '2012-09-25T11:30:00', - }, - ]) - self.assertEqual(data[0]['max'], 7) - self.assertEqual(data[0]['count'], 2) - - def test_start_timestamp_after(self): - data = self.get_json(self.PATH, q=[{'field': 'project_id', - 'value': 'project1', - }, - {'field': 'timestamp', - 'op': 'ge', - 'value': '2012-09-25T12:34:00', - }, - ]) - self.assertEqual(data, []) - - def test_end_timestamp(self): - data = self.get_json(self.PATH, q=[{'field': 'project_id', - 'value': 'project1', - }, - {'field': 'timestamp', - 'op': 'le', - 'value': '2012-09-25T11:30:00', - }, - ]) - self.assertEqual(data[0]['max'], 5) - self.assertEqual(data[0]['count'], 1) - - def test_end_timestamp_before(self): - data = self.get_json(self.PATH, q=[{'field': 'project_id', - 'value': 'project1', - }, - {'field': 'timestamp', - 'op': 'le', - 'value': '2012-09-25T09:54:00', - }, - ]) - self.assertEqual(data, []) - - def test_start_end_timestamp(self): - data = self.get_json(self.PATH, q=[{'field': 'project_id', - 'value': 'project1', - }, - {'field': 'timestamp', - 'op': 'ge', - 'value': '2012-09-25T11:30:00', - }, - {'field': 'timestamp', - 'op': 'le', - 'value': '2012-09-25T11:32:00', - }, - ]) - self.assertEqual(data[0]['max'], 6) - self.assertEqual(data[0]['count'], 1) diff --git a/tests/api/v2/test_max_resource_volume.py b/tests/api/v2/test_max_resource_volume.py deleted file mode 100644 index 51bb9bdcb..000000000 --- a/tests/api/v2/test_max_resource_volume.py +++ /dev/null @@ -1,146 +0,0 @@ -# -*- encoding: utf-8 -*- -# -# Copyright © 2012 New Dream Network, LLC (DreamHost) -# -# Author: Steven Berler -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -"""Test getting the max resource volume. -""" - -import datetime - -from oslo.config import cfg - -from ceilometer.publisher import rpc -from ceilometer import counter - -from .base import FunctionalTest -from ceilometer.storage.impl_mongodb import require_map_reduce - - -class TestMaxResourceVolume(FunctionalTest): - - PATH = '/meters/volume.size/statistics' - - def setUp(self): - super(TestMaxResourceVolume, self).setUp() - require_map_reduce(self.conn) - - self.counters = [] - for i in range(3): - c = counter.Counter( - 'volume.size', - 'gauge', - 'GiB', - 5 + i, - 'user-id', - 'project1', - 'resource-id', - timestamp=datetime.datetime(2012, 9, 25, 10 + i, 30 + i), - resource_metadata={'display_name': 'test-volume', - 'tag': 'self.counter', - } - ) - self.counters.append(c) - msg = rpc.meter_message_from_counter( - c, - cfg.CONF.publisher_rpc.metering_secret, - 'source1', - ) - self.conn.record_metering_data(msg) - - def test_no_time_bounds(self): - data = self.get_json(self.PATH, q=[{'field': 'resource_id', - 'value': 'resource-id', - }]) - self.assertEqual(data[0]['max'], 7) - self.assertEqual(data[0]['count'], 3) - - def test_no_time_bounds_with_period(self): - data = self.get_json(self.PATH, - q=[{'field': 'resource_id', - 'value': 'resource-id'}], - period=3600) - self.assertEqual(len(data), 3) - self.assertEqual(set(x['duration_start'] for x in data), - set([u'2012-09-25T10:30:00', - u'2012-09-25T12:32:00', - u'2012-09-25T11:31:00'])) - self.assertEqual(data[0]['period'], 3600) - self.assertEqual(set(x['period_start'] for x in data), - set([u'2012-09-25T10:00:00', - u'2012-09-25T11:00:00', - u'2012-09-25T12:00:00'])) - - def test_start_timestamp(self): - data = self.get_json(self.PATH, q=[{'field': 'resource_id', - 'value': 'resource-id', - }, - {'field': 'timestamp', - 'op': 'ge', - 'value': '2012-09-25T11:30:00', - }, - ]) - self.assertEqual(data[0]['max'], 7) - self.assertEqual(data[0]['count'], 2) - - def test_start_timestamp_after(self): - data = self.get_json(self.PATH, q=[{'field': 'resource_id', - 'value': 'resource-id', - }, - {'field': 'timestamp', - 'op': 'ge', - 'value': '2012-09-25T12:34:00', - }, - ]) - self.assertEqual(data, []) - - def test_end_timestamp(self): - data = self.get_json(self.PATH, q=[{'field': 'resource_id', - 'value': 'resource-id', - }, - {'field': 'timestamp', - 'op': 'le', - 'value': '2012-09-25T11:30:00', - }, - ]) - self.assertEqual(data[0]['max'], 5) - self.assertEqual(data[0]['count'], 1) - - def test_end_timestamp_before(self): - data = self.get_json(self.PATH, q=[{'field': 'resource_id', - 'value': 'resource-id', - }, - {'field': 'timestamp', - 'op': 'le', - 'value': '2012-09-25T09:54:00', - }, - ]) - self.assertEqual(data, []) - - def test_start_end_timestamp(self): - data = self.get_json(self.PATH, q=[{'field': 'resource_id', - 'value': 'resource-id', - }, - {'field': 'timestamp', - 'op': 'ge', - 'value': '2012-09-25T11:30:00', - }, - {'field': 'timestamp', - 'op': 'le', - 'value': '2012-09-25T11:32:00', - }, - ]) - self.assertEqual(data[0]['max'], 6) - self.assertEqual(data[0]['count'], 1) diff --git a/tests/api/v2/test_statistics.py b/tests/api/v2/test_statistics.py index 7f82a3bdc..949b6fe96 100644 --- a/tests/api/v2/test_statistics.py +++ b/tests/api/v2/test_statistics.py @@ -15,19 +15,14 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. -"""Test listing raw events. -""" +"""Test statistics objects.""" import datetime -import logging from ceilometer.api.controllers import v2 from ceilometer.tests import base -LOG = logging.getLogger(__name__) - - class TestStatisticsDuration(base.TestCase): def setUp(self): diff --git a/tests/api/v2/test_sum_project_volume.py b/tests/api/v2/test_sum_project_volume.py deleted file mode 100644 index 9f059e4f5..000000000 --- a/tests/api/v2/test_sum_project_volume.py +++ /dev/null @@ -1,132 +0,0 @@ -# -*- encoding: utf-8 -*- -# -# Copyright © 2012 New Dream Network, LLC (DreamHost) -# -# Author: Steven Berler -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -"""Test getting the sum project volume. -""" - -import datetime - -from oslo.config import cfg - -from ceilometer.publisher import rpc -from ceilometer import counter - -from .base import FunctionalTest -from ceilometer.storage.impl_mongodb import require_map_reduce - - -class TestSumProjectVolume(FunctionalTest): - - PATH = '/meters/volume.size/statistics' - - def setUp(self): - super(TestSumProjectVolume, self).setUp() - require_map_reduce(self.conn) - - self.counters = [] - for i in range(3): - c = counter.Counter( - 'volume.size', - 'gauge', - 'GiB', - 5 + i, - 'user-id', - 'project1', - 'resource-id-%s' % i, - timestamp=datetime.datetime(2012, 9, 25, 10 + i, 30 + i), - resource_metadata={'display_name': 'test-volume', - 'tag': 'self.counter', - } - ) - self.counters.append(c) - msg = rpc.meter_message_from_counter( - c, - cfg.CONF.publisher_rpc.metering_secret, - 'source1', - ) - self.conn.record_metering_data(msg) - - def test_no_time_bounds(self): - data = self.get_json(self.PATH, q=[{'field': 'project_id', - 'value': 'project1', - }]) - expected = 5 + 6 + 7 - self.assertEqual(data[0]['sum'], expected) - self.assertEqual(data[0]['count'], 3) - - def test_start_timestamp(self): - data = self.get_json(self.PATH, q=[{'field': 'project_id', - 'value': 'project1', - }, - {'field': 'timestamp', - 'op': 'ge', - 'value': '2012-09-25T11:30:00', - }, - ]) - expected = 6 + 7 - self.assertEqual(data[0]['sum'], expected) - self.assertEqual(data[0]['count'], 2) - - def test_start_timestamp_after(self): - data = self.get_json(self.PATH, q=[{'field': 'project_id', - 'value': 'project1', - }, - {'field': 'timestamp', - 'op': 'ge', - 'value': '2012-09-25T12:34:00', - }, - ]) - self.assertEqual(data, []) - - def test_end_timestamp(self): - data = self.get_json(self.PATH, q=[{'field': 'project_id', - 'value': 'project1', - }, - {'field': 'timestamp', - 'op': 'le', - 'value': '2012-09-25T11:30:00', - }, - ]) - self.assertEqual(data[0]['sum'], 5) - self.assertEqual(data[0]['count'], 1) - - def test_end_timestamp_before(self): - data = self.get_json(self.PATH, q=[{'field': 'project_id', - 'value': 'project1', - }, - {'field': 'timestamp', - 'op': 'le', - 'value': '2012-09-25T09:54:00', - }, - ]) - self.assertEqual(data, []) - - def test_start_end_timestamp(self): - data = self.get_json(self.PATH, q=[{'field': 'project_id', - 'value': 'project1', - }, - {'field': 'timestamp', - 'op': 'ge', - 'value': '2012-09-25T11:30:00', - }, - {'field': 'timestamp', - 'op': 'le', - 'value': '2012-09-25T11:32:00', - }, - ]) - self.assertEqual(data[0]['sum'], 6) - self.assertEqual(data[0]['count'], 1) diff --git a/tests/api/v2/test_sum_resource_volume.py b/tests/api/v2/test_sum_resource_volume.py deleted file mode 100644 index 8a9f519f8..000000000 --- a/tests/api/v2/test_sum_resource_volume.py +++ /dev/null @@ -1,158 +0,0 @@ -# -*- encoding: utf-8 -*- -# -# Copyright © 2012 New Dream Network, LLC (DreamHost) -# -# Author: Doug Hellmann -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -"""Test getting the total resource volume. -""" - -import datetime - -from oslo.config import cfg - -from ceilometer.publisher import rpc -from ceilometer import counter - -from .base import FunctionalTest -from ceilometer.storage.impl_mongodb import require_map_reduce - - -class TestSumResourceVolume(FunctionalTest): - - PATH = '/meters/volume.size/statistics' - - def setUp(self): - super(TestSumResourceVolume, self).setUp() - require_map_reduce(self.conn) - - self.counters = [] - for i in range(3): - c = counter.Counter( - 'volume.size', - 'gauge', - 'GiB', - 5 + i, - 'user-id', - 'project1', - 'resource-id', - timestamp=datetime.datetime(2012, 9, 25, 10 + i, 30 + i), - resource_metadata={'display_name': 'test-volume', - 'tag': 'self.counter', - } - ) - self.counters.append(c) - msg = rpc.meter_message_from_counter( - c, - cfg.CONF.publisher_rpc.metering_secret, - 'source1', - ) - self.conn.record_metering_data(msg) - - def test_no_time_bounds(self): - data = self.get_json(self.PATH, q=[{'field': 'resource_id', - 'value': 'resource-id', - }]) - self.assertEqual(data[0]['sum'], 5 + 6 + 7) - self.assertEqual(data[0]['count'], 3) - - def test_no_time_bounds_with_period(self): - data = self.get_json(self.PATH, - q=[{'field': 'resource_id', - 'value': 'resource-id'}], - period=1800) - self.assertEqual(len(data), 3) - self.assertEqual(set(x['duration_start'] for x in data), - set([u'2012-09-25T10:30:00', - u'2012-09-25T12:32:00', - u'2012-09-25T11:31:00'])) - self.assertEqual(data[0]['period'], 1800) - self.assertEqual(set(x['period_start'] for x in data), - set([u'2012-09-25T10:30:00', - u'2012-09-25T11:30:00', - u'2012-09-25T12:30:00'])) - - def test_start_timestamp(self): - data = self.get_json(self.PATH, q=[{'field': 'resource_id', - 'value': 'resource-id', - }, - {'field': 'timestamp', - 'op': 'ge', - 'value': '2012-09-25T11:30:00', - }]) - self.assertEqual(data[0]['sum'], 6 + 7) - self.assertEqual(data[0]['count'], 2) - - def test_start_timestamp_with_period(self): - data = self.get_json(self.PATH, - q=[{'field': 'resource_id', - 'value': 'resource-id'}, - {'field': 'timestamp', - 'op': 'ge', - 'value': '2012-09-25T10:15:00'}], - period=7200) - self.assertEqual(len(data), 2) - self.assertEqual(set(x['duration_start'] for x in data), - set([u'2012-09-25T10:30:00', - u'2012-09-25T12:32:00'])) - self.assertEqual(data[0]['period'], 7200) - self.assertEqual(set(x['period_start'] for x in data), - set([u'2012-09-25T10:15:00', - u'2012-09-25T12:15:00'])) - - def test_start_timestamp_after(self): - data = self.get_json(self.PATH, q=[{'field': 'resource_id', - 'value': 'resource-id', - }, - {'field': 'timestamp', - 'op': 'ge', - 'value': '2012-09-25T12:34:00', - }]) - self.assertEqual(data, []) - - def test_end_timestamp(self): - data = self.get_json(self.PATH, q=[{'field': 'resource_id', - 'value': 'resource-id', - }, - {'field': 'timestamp', - 'op': 'le', - 'value': '2012-09-25T11:30:00', - }]) - self.assertEqual(data[0]['sum'], 5) - self.assertEqual(data[0]['count'], 1) - - def test_end_timestamp_before(self): - data = self.get_json(self.PATH, q=[{'field': 'resource_id', - 'value': 'resource-id', - }, - {'field': 'timestamp', - 'op': 'le', - 'value': '2012-09-25T09:54:00', - }]) - self.assertEqual(data, []) - - def test_start_end_timestamp(self): - data = self.get_json(self.PATH, q=[{'field': 'resource_id', - 'value': 'resource-id', - }, - {'field': 'timestamp', - 'op': 'ge', - 'value': '2012-09-25T11:30:00', - }, - {'field': 'timestamp', - 'op': 'lt', - 'value': '2012-09-25T11:32:00', - }]) - self.assertEqual(data[0]['sum'], 6) - self.assertEqual(data[0]['count'], 1)