Merge "1st & last sample timestamps in Resource representation"
This commit is contained in:
commit
4f009afbfd
@ -987,8 +987,11 @@ class Resource(_Base):
|
||||
user_id = wtypes.text
|
||||
"The ID of the user who created the resource or updated it last"
|
||||
|
||||
timestamp = datetime.datetime
|
||||
"UTC date and time of the last update to any meter for the resource"
|
||||
first_sample_timestamp = datetime.datetime
|
||||
"UTC date & time of the first sample associated with the resource"
|
||||
|
||||
last_sample_timestamp = datetime.datetime
|
||||
"UTC date & time of the last sample associated with the resource"
|
||||
|
||||
metadata = {wtypes.text: wtypes.text}
|
||||
"Arbitrary metadata associated with the resource"
|
||||
|
@ -23,6 +23,7 @@ import json
|
||||
import logging
|
||||
import testscenarios
|
||||
|
||||
from ceilometer.openstack.common import timeutils
|
||||
from ceilometer.publisher import rpc
|
||||
from ceilometer import sample
|
||||
from ceilometer.tests.api.v2 import FunctionalTest
|
||||
@ -40,7 +41,19 @@ class TestListResources(FunctionalTest,
|
||||
data = self.get_json('/resources')
|
||||
self.assertEqual([], data)
|
||||
|
||||
@staticmethod
|
||||
def _isotime(timestamp):
|
||||
# drop TZ specifier
|
||||
return unicode(timeutils.isotime(timestamp))[:-1]
|
||||
|
||||
def _verify_sample_timestamps(self, res, first, last):
|
||||
self.assertTrue('first_sample_timestamp' in res)
|
||||
self.assertEqual(res['first_sample_timestamp'], self._isotime(first))
|
||||
self.assertTrue('last_sample_timestamp' in res)
|
||||
self.assertEqual(res['last_sample_timestamp'], self._isotime(last))
|
||||
|
||||
def test_instance_no_metadata(self):
|
||||
timestamp = datetime.datetime(2012, 7, 2, 10, 40)
|
||||
sample1 = sample.Sample(
|
||||
'instance',
|
||||
'cumulative',
|
||||
@ -49,7 +62,7 @@ class TestListResources(FunctionalTest,
|
||||
'user-id',
|
||||
'project-id',
|
||||
'resource-id',
|
||||
timestamp=datetime.datetime(2012, 7, 2, 10, 40),
|
||||
timestamp=timestamp,
|
||||
resource_metadata=None,
|
||||
source='test',
|
||||
)
|
||||
@ -61,8 +74,13 @@ class TestListResources(FunctionalTest,
|
||||
|
||||
data = self.get_json('/resources')
|
||||
self.assertEqual(1, len(data))
|
||||
self._verify_sample_timestamps(data[0], timestamp, timestamp)
|
||||
|
||||
def test_instances(self):
|
||||
timestamps = {
|
||||
'resource-id': datetime.datetime(2012, 7, 2, 10, 40),
|
||||
'resource-id-alternate': datetime.datetime(2012, 7, 2, 10, 41),
|
||||
}
|
||||
sample1 = sample.Sample(
|
||||
'instance',
|
||||
'cumulative',
|
||||
@ -71,7 +89,7 @@ class TestListResources(FunctionalTest,
|
||||
'user-id',
|
||||
'project-id',
|
||||
'resource-id',
|
||||
timestamp=datetime.datetime(2012, 7, 2, 10, 40),
|
||||
timestamp=timestamps['resource-id'],
|
||||
resource_metadata={'display_name': 'test-server',
|
||||
'tag': 'self.sample',
|
||||
},
|
||||
@ -91,7 +109,7 @@ class TestListResources(FunctionalTest,
|
||||
'user-id',
|
||||
'project-id',
|
||||
'resource-id-alternate',
|
||||
timestamp=datetime.datetime(2012, 7, 2, 10, 41),
|
||||
timestamp=timestamps['resource-id-alternate'],
|
||||
resource_metadata={'display_name': 'test-server',
|
||||
'tag': 'self.sample2',
|
||||
},
|
||||
@ -105,6 +123,40 @@ class TestListResources(FunctionalTest,
|
||||
|
||||
data = self.get_json('/resources')
|
||||
self.assertEqual(2, len(data))
|
||||
for res in data:
|
||||
timestamp = timestamps.get(res['resource_id'])
|
||||
self._verify_sample_timestamps(res, timestamp, timestamp)
|
||||
|
||||
def test_instance_multiple_samples(self):
|
||||
timestamps = [
|
||||
datetime.datetime(2012, 7, 2, 10, 40),
|
||||
datetime.datetime(2012, 7, 2, 10, 41),
|
||||
datetime.datetime(2012, 7, 2, 10, 42),
|
||||
]
|
||||
for timestamp in timestamps:
|
||||
datapoint = sample.Sample(
|
||||
'instance',
|
||||
'cumulative',
|
||||
'',
|
||||
1,
|
||||
'user-id',
|
||||
'project-id',
|
||||
'resource-id',
|
||||
timestamp=timestamp,
|
||||
resource_metadata={'display_name': 'test-server',
|
||||
'tag': 'self.sample',
|
||||
},
|
||||
source='test',
|
||||
)
|
||||
msg = rpc.meter_message_from_counter(
|
||||
datapoint,
|
||||
self.CONF.publisher_rpc.metering_secret,
|
||||
)
|
||||
self.conn.record_metering_data(msg)
|
||||
|
||||
data = self.get_json('/resources')
|
||||
self.assertEqual(1, len(data))
|
||||
self._verify_sample_timestamps(data[0], timestamps[0], timestamps[-1])
|
||||
|
||||
def test_instances_one(self):
|
||||
sample1 = sample.Sample(
|
||||
|
Loading…
x
Reference in New Issue
Block a user