Merge "Added missing source variable in storage drivers"
This commit is contained in:
commit
7677c321eb
@ -334,6 +334,7 @@ class Connection(base.Connection):
|
|||||||
yield models.Resource(
|
yield models.Resource(
|
||||||
resource_id=resource_id,
|
resource_id=resource_id,
|
||||||
project_id=data['f:project_id'],
|
project_id=data['f:project_id'],
|
||||||
|
source=data['f:source'],
|
||||||
user_id=data['f:user_id'],
|
user_id=data['f:user_id'],
|
||||||
metadata=json.loads(data['f:metadata']),
|
metadata=json.loads(data['f:metadata']),
|
||||||
meter=[
|
meter=[
|
||||||
@ -381,6 +382,7 @@ class Connection(base.Connection):
|
|||||||
unit=unit,
|
unit=unit,
|
||||||
resource_id=data['f:resource_id'],
|
resource_id=data['f:resource_id'],
|
||||||
project_id=data['f:project_id'],
|
project_id=data['f:project_id'],
|
||||||
|
source=data['f:source'],
|
||||||
user_id=data['f:user_id'],
|
user_id=data['f:user_id'],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -392,6 +392,7 @@ class Connection(base.Connection):
|
|||||||
yield models.Resource(
|
yield models.Resource(
|
||||||
resource_id=resource['_id'],
|
resource_id=resource['_id'],
|
||||||
project_id=resource['project_id'],
|
project_id=resource['project_id'],
|
||||||
|
source=resource['source'],
|
||||||
user_id=resource['user_id'],
|
user_id=resource['user_id'],
|
||||||
metadata=resource['metadata'],
|
metadata=resource['metadata'],
|
||||||
meter=[
|
meter=[
|
||||||
@ -435,6 +436,7 @@ class Connection(base.Connection):
|
|||||||
unit=r_meter.get('counter_unit', ''),
|
unit=r_meter.get('counter_unit', ''),
|
||||||
resource_id=r['_id'],
|
resource_id=r['_id'],
|
||||||
project_id=r['project_id'],
|
project_id=r['project_id'],
|
||||||
|
source=r['source'],
|
||||||
user_id=r['user_id'],
|
user_id=r['user_id'],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -255,6 +255,7 @@ class Connection(base.Connection):
|
|||||||
yield api_models.Resource(
|
yield api_models.Resource(
|
||||||
resource_id=meter.resource_id,
|
resource_id=meter.resource_id,
|
||||||
project_id=meter.project_id,
|
project_id=meter.project_id,
|
||||||
|
source=meter.sources[0].id,
|
||||||
user_id=meter.user_id,
|
user_id=meter.user_id,
|
||||||
metadata=meter.resource_metadata,
|
metadata=meter.resource_metadata,
|
||||||
meter=[
|
meter=[
|
||||||
@ -303,6 +304,7 @@ class Connection(base.Connection):
|
|||||||
unit=meter.counter_unit,
|
unit=meter.counter_unit,
|
||||||
resource_id=resource.id,
|
resource_id=resource.id,
|
||||||
project_id=resource.project_id,
|
project_id=resource.project_id,
|
||||||
|
source=resource.sources[0].id,
|
||||||
user_id=resource.user_id,
|
user_id=resource.user_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -47,10 +47,12 @@ class Resource(Model):
|
|||||||
"""Something for which sample data has been collected.
|
"""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 resource_id: UUID of the resource
|
||||||
:param project_id: UUID of project owning 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 user_id: UUID of user owning the resource
|
||||||
:param metadata: most current metadata for the resource (a dict)
|
:param metadata: most current metadata for the resource (a dict)
|
||||||
:param meter: list of the meters reporting data for the resource,
|
:param meter: list of the meters reporting data for the resource,
|
||||||
@ -58,6 +60,7 @@ class Resource(Model):
|
|||||||
Model.__init__(self,
|
Model.__init__(self,
|
||||||
resource_id=resource_id,
|
resource_id=resource_id,
|
||||||
project_id=project_id,
|
project_id=project_id,
|
||||||
|
source=source,
|
||||||
user_id=user_id,
|
user_id=user_id,
|
||||||
metadata=metadata,
|
metadata=metadata,
|
||||||
meter=meter,
|
meter=meter,
|
||||||
@ -88,13 +91,15 @@ class Meter(Model):
|
|||||||
"""Definition of a meter for which sample data has been collected.
|
"""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 name: name of the meter
|
||||||
:param type: type of the meter (guage, counter)
|
:param type: type of the meter (guage, counter)
|
||||||
:param unit: unit of the meter
|
:param unit: unit of the meter
|
||||||
:param resource_id: UUID of the resource
|
:param resource_id: UUID of the resource
|
||||||
:param project_id: UUID of project owning 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 user_id: UUID of user owning the resource
|
||||||
"""
|
"""
|
||||||
Model.__init__(self,
|
Model.__init__(self,
|
||||||
@ -103,6 +108,7 @@ class Meter(Model):
|
|||||||
unit=unit,
|
unit=unit,
|
||||||
resource_id=resource_id,
|
resource_id=resource_id,
|
||||||
project_id=project_id,
|
project_id=project_id,
|
||||||
|
source=source,
|
||||||
user_id=user_id,
|
user_id=user_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -157,6 +157,7 @@ class ProjectTest(DBTestBase):
|
|||||||
class ResourceTest(DBTestBase):
|
class ResourceTest(DBTestBase):
|
||||||
|
|
||||||
def test_get_resources(self):
|
def test_get_resources(self):
|
||||||
|
msgs_sources = [msg['source'] for msg in self.msgs]
|
||||||
resources = list(self.conn.get_resources())
|
resources = list(self.conn.get_resources())
|
||||||
assert len(resources) == 4
|
assert len(resources) == 4
|
||||||
for resource in resources:
|
for resource in resources:
|
||||||
@ -164,6 +165,7 @@ class ResourceTest(DBTestBase):
|
|||||||
continue
|
continue
|
||||||
assert resource.resource_id == 'resource-id'
|
assert resource.resource_id == 'resource-id'
|
||||||
assert resource.project_id == 'project-id'
|
assert resource.project_id == 'project-id'
|
||||||
|
self.assertIn(resource.source, msgs_sources)
|
||||||
assert resource.user_id == 'user-id'
|
assert resource.user_id == 'user-id'
|
||||||
assert resource.metadata['display_name'] == 'test-server'
|
assert resource.metadata['display_name'] == 'test-server'
|
||||||
self.assertIn(models.ResourceMeter('instance', 'cumulative', ''),
|
self.assertIn(models.ResourceMeter('instance', 'cumulative', ''),
|
||||||
@ -236,8 +238,11 @@ class ResourceTest(DBTestBase):
|
|||||||
class MeterTest(DBTestBase):
|
class MeterTest(DBTestBase):
|
||||||
|
|
||||||
def test_get_meters(self):
|
def test_get_meters(self):
|
||||||
|
msgs_sources = [msg['source'] for msg in self.msgs]
|
||||||
results = list(self.conn.get_meters())
|
results = list(self.conn.get_meters())
|
||||||
assert len(results) == 4
|
assert len(results) == 4
|
||||||
|
for meter in results:
|
||||||
|
self.assertIn(meter.source, msgs_sources)
|
||||||
|
|
||||||
def test_get_meters_by_user(self):
|
def test_get_meters_by_user(self):
|
||||||
results = list(self.conn.get_meters(user='user-id'))
|
results = list(self.conn.get_meters(user='user-id'))
|
||||||
|
Loading…
Reference in New Issue
Block a user