Merge "Added missing source variable in storage drivers"

This commit is contained in:
Jenkins 2013-05-22 23:38:37 +00:00 committed by Gerrit Code Review
commit 7677c321eb
5 changed files with 19 additions and 2 deletions

View File

@ -334,6 +334,7 @@ class Connection(base.Connection):
yield models.Resource(
resource_id=resource_id,
project_id=data['f:project_id'],
source=data['f:source'],
user_id=data['f:user_id'],
metadata=json.loads(data['f:metadata']),
meter=[
@ -381,6 +382,7 @@ class Connection(base.Connection):
unit=unit,
resource_id=data['f:resource_id'],
project_id=data['f:project_id'],
source=data['f:source'],
user_id=data['f:user_id'],
)

View File

@ -392,6 +392,7 @@ class Connection(base.Connection):
yield models.Resource(
resource_id=resource['_id'],
project_id=resource['project_id'],
source=resource['source'],
user_id=resource['user_id'],
metadata=resource['metadata'],
meter=[
@ -435,6 +436,7 @@ class Connection(base.Connection):
unit=r_meter.get('counter_unit', ''),
resource_id=r['_id'],
project_id=r['project_id'],
source=r['source'],
user_id=r['user_id'],
)

View File

@ -255,6 +255,7 @@ class Connection(base.Connection):
yield api_models.Resource(
resource_id=meter.resource_id,
project_id=meter.project_id,
source=meter.sources[0].id,
user_id=meter.user_id,
metadata=meter.resource_metadata,
meter=[
@ -303,6 +304,7 @@ class Connection(base.Connection):
unit=meter.counter_unit,
resource_id=resource.id,
project_id=resource.project_id,
source=resource.sources[0].id,
user_id=resource.user_id,
)

View File

@ -47,10 +47,12 @@ class Resource(Model):
"""Something for which sample data has been collected.
"""
def __init__(self, resource_id, project_id, user_id, metadata, meter):
def __init__(self, resource_id, project_id, source, user_id, metadata,
meter):
"""
:param resource_id: UUID of the resource
:param project_id: UUID of project owning the resource
:param source: the identifier for the user/project id definition
:param user_id: UUID of user owning the resource
:param metadata: most current metadata for the resource (a dict)
:param meter: list of the meters reporting data for the resource,
@ -58,6 +60,7 @@ class Resource(Model):
Model.__init__(self,
resource_id=resource_id,
project_id=project_id,
source=source,
user_id=user_id,
metadata=metadata,
meter=meter,
@ -88,13 +91,15 @@ class Meter(Model):
"""Definition of a meter for which sample data has been collected.
"""
def __init__(self, name, type, unit, resource_id, project_id, user_id):
def __init__(self, name, type, unit, resource_id, project_id, source,
user_id):
"""
:param name: name of the meter
:param type: type of the meter (guage, counter)
:param unit: unit of the meter
:param resource_id: UUID of the resource
:param project_id: UUID of project owning the resource
:param source: the identifier for the user/project id definition
:param user_id: UUID of user owning the resource
"""
Model.__init__(self,
@ -103,6 +108,7 @@ class Meter(Model):
unit=unit,
resource_id=resource_id,
project_id=project_id,
source=source,
user_id=user_id,
)

View File

@ -157,6 +157,7 @@ class ProjectTest(DBTestBase):
class ResourceTest(DBTestBase):
def test_get_resources(self):
msgs_sources = [msg['source'] for msg in self.msgs]
resources = list(self.conn.get_resources())
assert len(resources) == 4
for resource in resources:
@ -164,6 +165,7 @@ class ResourceTest(DBTestBase):
continue
assert resource.resource_id == 'resource-id'
assert resource.project_id == 'project-id'
self.assertIn(resource.source, msgs_sources)
assert resource.user_id == 'user-id'
assert resource.metadata['display_name'] == 'test-server'
self.assertIn(models.ResourceMeter('instance', 'cumulative', ''),
@ -236,8 +238,11 @@ class ResourceTest(DBTestBase):
class MeterTest(DBTestBase):
def test_get_meters(self):
msgs_sources = [msg['source'] for msg in self.msgs]
results = list(self.conn.get_meters())
assert len(results) == 4
for meter in results:
self.assertIn(meter.source, msgs_sources)
def test_get_meters_by_user(self):
results = list(self.conn.get_meters(user='user-id'))