Merge "Fixed random failures in storage tests"
This commit is contained in:
@@ -18,6 +18,8 @@
|
|||||||
import copy
|
import copy
|
||||||
import decimal
|
import decimal
|
||||||
|
|
||||||
|
import six
|
||||||
|
|
||||||
from cloudkitty import utils as ck_utils
|
from cloudkitty import utils as ck_utils
|
||||||
|
|
||||||
TENANT = 'f266f30b11f246b589fd266f85eeec39'
|
TENANT = 'f266f30b11f246b589fd266f85eeec39'
|
||||||
@@ -107,7 +109,8 @@ def split_storage_data(raw_data):
|
|||||||
frame['period']['begin'] = ck_utils.ts2iso(frame['period']['begin'])
|
frame['period']['begin'] = ck_utils.ts2iso(frame['period']['begin'])
|
||||||
frame['period']['end'] = ck_utils.ts2iso(frame['period']['end'])
|
frame['period']['end'] = ck_utils.ts2iso(frame['period']['end'])
|
||||||
usage_buffer = frame.pop('usage')
|
usage_buffer = frame.pop('usage')
|
||||||
for service, data in usage_buffer.items():
|
# Sort to have a consistent result as we are converting it to a list
|
||||||
|
for service, data in sorted(six.iteritems(usage_buffer)):
|
||||||
new_frame = copy.deepcopy(frame)
|
new_frame = copy.deepcopy(frame)
|
||||||
new_frame['usage'] = {service: data}
|
new_frame['usage'] = {service: data}
|
||||||
new_frame['usage'][service][0]['tenant_id'] = TENANT
|
new_frame['usage'][service][0]['tenant_id'] = TENANT
|
||||||
|
@@ -18,6 +18,7 @@
|
|||||||
import copy
|
import copy
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
|
import six
|
||||||
import sqlalchemy
|
import sqlalchemy
|
||||||
import testscenarios
|
import testscenarios
|
||||||
|
|
||||||
@@ -119,7 +120,7 @@ class StorageTest(tests.TestCase):
|
|||||||
def test_send_nodata_between_data(self):
|
def test_send_nodata_between_data(self):
|
||||||
working_data = copy.deepcopy(samples.RATED_DATA)
|
working_data = copy.deepcopy(samples.RATED_DATA)
|
||||||
for period in working_data:
|
for period in working_data:
|
||||||
for service, data in sorted(period['usage'].items()):
|
for service, data in sorted(six.iteritems(period['usage'])):
|
||||||
sub_data = [{
|
sub_data = [{
|
||||||
'period': period['period'],
|
'period': period['period'],
|
||||||
'usage': {
|
'usage': {
|
||||||
@@ -149,6 +150,11 @@ class StorageTest(tests.TestCase):
|
|||||||
# We only stored the first timeframe, the second one is waiting for a
|
# We only stored the first timeframe, the second one is waiting for a
|
||||||
# commit or an append with the next timeframe.
|
# commit or an append with the next timeframe.
|
||||||
del expected_data[2]
|
del expected_data[2]
|
||||||
|
# NOTE(sheeprine): Quick and dirty sort (ensure result consistency,
|
||||||
|
# order is not significant to the test result)
|
||||||
|
if 'image' in stored_data[0]['usage']:
|
||||||
|
stored_data[0]['usage'], stored_data[1]['usage'] = (
|
||||||
|
stored_data[1]['usage'], stored_data[0]['usage'])
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
expected_data,
|
expected_data,
|
||||||
stored_data)
|
stored_data)
|
||||||
|
Reference in New Issue
Block a user