Merge "Return numberic type for volume in /measurements"
This commit is contained in:
commit
2e373aae7f
|
@ -17,6 +17,7 @@ import json
|
|||
|
||||
from oslo_log import log as logging
|
||||
|
||||
from distil.common import constants
|
||||
from distil.common import general
|
||||
from distil.db import api as db_api
|
||||
|
||||
|
@ -35,7 +36,7 @@ def _build_project_dict(project, usage):
|
|||
|
||||
for entry in usage:
|
||||
service = {'name': entry.get('service'),
|
||||
'volume': str(entry.get('volume')),
|
||||
'volume': float(entry.get('volume')),
|
||||
'unit': entry.get('unit')}
|
||||
|
||||
resource = project_dict['resources'][entry.get('resource_id')]
|
||||
|
|
|
@ -102,8 +102,11 @@ class TestAPI(base.APITest):
|
|||
db_api.resource_add(
|
||||
default_project, res_id, {'type': 'Virtual Machine'}
|
||||
)
|
||||
# NOTE(flwang): Based on current data model of usage entry:
|
||||
# volume = Column(Numeric(precision=20, scale=2), nullable=False)
|
||||
# it's only necessary to test the case of scale=2.
|
||||
db_api.usage_add(
|
||||
default_project, res_id, {'instance': 100}, 'hour',
|
||||
default_project, res_id, {'instance': 100.12}, 'hour',
|
||||
datetime.strptime(start, constants.iso_time),
|
||||
datetime.strptime(end, constants.iso_time),
|
||||
)
|
||||
|
@ -131,7 +134,7 @@ class TestAPI(base.APITest):
|
|||
'type': 'Virtual Machine',
|
||||
'services': [{
|
||||
'name': 'instance',
|
||||
'volume': '100.00',
|
||||
'volume': 100.12,
|
||||
'unit': 'hour'
|
||||
}]
|
||||
}
|
||||
|
|
|
@ -42,13 +42,13 @@ class MeasurementsTest(base.DistilWithDbTestCase):
|
|||
{
|
||||
'resource_id': '111',
|
||||
'service': 'srv1',
|
||||
'volume': 10,
|
||||
'volume': 10.12,
|
||||
'unit': 'byte',
|
||||
},
|
||||
{
|
||||
'resource_id': '222',
|
||||
'service': 'srv2',
|
||||
'volume': 20,
|
||||
'volume': 20.1,
|
||||
'unit': 'byte',
|
||||
}
|
||||
]
|
||||
|
@ -76,13 +76,13 @@ class MeasurementsTest(base.DistilWithDbTestCase):
|
|||
'111': {
|
||||
'name': 'resource1',
|
||||
'services': [
|
||||
{'name': 'srv1', 'volume': '10', 'unit': 'byte'}
|
||||
{'name': 'srv1', 'volume': 10.12, 'unit': 'byte'}
|
||||
]
|
||||
},
|
||||
'222': {
|
||||
'name': 'resource2',
|
||||
'services': [
|
||||
{'name': 'srv2', 'volume': '20', 'unit': 'byte'}
|
||||
{'name': 'srv2', 'volume': 20.1, 'unit': 'byte'}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue