Provide explicit image create value in Registry v2 API test

Assign an explicit created_at datetime value to image db fixtures,
it be used to fixes race condition in Registry v2 API test cases.

Closes-Bug: #1279753
Change-Id: Ia1957e8c024f81eeaa3c0bc094dd62db1be52d07
Signed-off-by: Zhi Yan Liu <zhiyanl@cn.ibm.com>
This commit is contained in:
Zhi Yan Liu 2014-01-31 19:08:39 +08:00
parent 870030e1b0
commit 31bcc97214
1 changed files with 68 additions and 33 deletions

View File

@ -51,6 +51,9 @@ class TestRegistryRPC(base.IsolatedUnitTest):
self.api = test_utils.FakeAuthMiddleware(rserver.API(self.mapper),
is_admin=True)
uuid1_time = timeutils.utcnow()
uuid2_time = uuid1_time + datetime.timedelta(seconds=5)
self.FIXTURES = [
{'id': UUID1,
'name': 'fake image #1',
@ -58,8 +61,8 @@ class TestRegistryRPC(base.IsolatedUnitTest):
'disk_format': 'ami',
'container_format': 'ami',
'is_public': False,
'created_at': timeutils.utcnow(),
'updated_at': timeutils.utcnow(),
'created_at': uuid1_time,
'updated_at': uuid1_time,
'deleted_at': None,
'deleted': False,
'checksum': None,
@ -75,8 +78,8 @@ class TestRegistryRPC(base.IsolatedUnitTest):
'disk_format': 'vhd',
'container_format': 'ovf',
'is_public': True,
'created_at': timeutils.utcnow(),
'updated_at': timeutils.utcnow(),
'created_at': uuid2_time,
'updated_at': uuid2_time,
'deleted_at': None,
'deleted': False,
'checksum': None,
@ -184,9 +187,9 @@ class TestRegistryRPC(base.IsolatedUnitTest):
Tests that the registry API returns list of
public images that conforms to a marker query param
"""
time1 = timeutils.utcnow() + datetime.timedelta(seconds=5)
time2 = timeutils.utcnow() + datetime.timedelta(seconds=4)
time3 = timeutils.utcnow()
uuid5_time = timeutils.utcnow() + datetime.timedelta(seconds=10)
uuid4_time = uuid5_time + datetime.timedelta(seconds=5)
uuid3_time = uuid4_time + datetime.timedelta(seconds=5)
UUID3 = _gen_uuid()
extra_fixture = {'id': UUID3,
@ -197,7 +200,8 @@ class TestRegistryRPC(base.IsolatedUnitTest):
'name': 'new name! #123',
'size': 19,
'checksum': None,
'created_at': time1}
'created_at': uuid3_time,
'updated_at': uuid3_time}
db_api.image_create(self.context, extra_fixture)
@ -210,7 +214,8 @@ class TestRegistryRPC(base.IsolatedUnitTest):
'name': 'new name! #123',
'size': 20,
'checksum': None,
'created_at': time2}
'created_at': uuid4_time,
'updated_at': uuid4_time}
db_api.image_create(self.context, extra_fixture)
@ -223,7 +228,8 @@ class TestRegistryRPC(base.IsolatedUnitTest):
'name': 'new name! #123',
'size': 20,
'checksum': None,
'created_at': time3}
'created_at': uuid5_time,
'updated_at': uuid5_time}
db_api.image_create(self.context, extra_fixture)
@ -466,6 +472,9 @@ class TestRegistryRPC(base.IsolatedUnitTest):
Tests that the registry API returns list of
public images that conforms to a limit query param
"""
uuid3_time = timeutils.utcnow() + datetime.timedelta(seconds=10)
uuid4_time = uuid3_time + datetime.timedelta(seconds=5)
UUID3 = _gen_uuid()
extra_fixture = {'id': UUID3,
'status': 'active',
@ -474,7 +483,9 @@ class TestRegistryRPC(base.IsolatedUnitTest):
'container_format': 'ovf',
'name': 'new name! #123',
'size': 19,
'checksum': None}
'checksum': None,
'created_at': uuid3_time,
'updated_at': uuid3_time}
db_api.image_create(self.context, extra_fixture)
@ -486,7 +497,9 @@ class TestRegistryRPC(base.IsolatedUnitTest):
'container_format': 'ovf',
'name': 'new name! #123',
'size': 20,
'checksum': None}
'checksum': None,
'created_at': uuid4_time,
'updated_at': uuid4_time}
db_api.image_create(self.context, extra_fixture)
@ -512,6 +525,9 @@ class TestRegistryRPC(base.IsolatedUnitTest):
Tests that the registry API returns list of
public images that conforms to limit and marker query params
"""
uuid3_time = timeutils.utcnow() + datetime.timedelta(seconds=10)
uuid4_time = uuid3_time + datetime.timedelta(seconds=5)
UUID3 = _gen_uuid()
extra_fixture = {'id': UUID3,
'status': 'active',
@ -520,7 +536,9 @@ class TestRegistryRPC(base.IsolatedUnitTest):
'container_format': 'ovf',
'name': 'new name! #123',
'size': 19,
'checksum': None}
'checksum': None,
'created_at': uuid3_time,
'updated_at': uuid3_time}
db_api.image_create(self.context, extra_fixture)
@ -531,7 +549,9 @@ class TestRegistryRPC(base.IsolatedUnitTest):
'container_format': 'ovf',
'name': 'new name! #123',
'size': 20,
'checksum': None}
'checksum': None,
'created_at': uuid4_time,
'updated_at': uuid4_time}
db_api.image_create(self.context, extra_fixture)
@ -712,9 +732,9 @@ class TestRegistryRPC(base.IsolatedUnitTest):
Tests that the registry API returns list of
public images that conforms to a default sort key/dir
"""
time1 = timeutils.utcnow() + datetime.timedelta(seconds=5)
time2 = timeutils.utcnow() + datetime.timedelta(seconds=4)
time3 = timeutils.utcnow()
uuid5_time = timeutils.utcnow() + datetime.timedelta(seconds=10)
uuid4_time = uuid5_time + datetime.timedelta(seconds=5)
uuid3_time = uuid4_time + datetime.timedelta(seconds=5)
UUID3 = _gen_uuid()
extra_fixture = {'id': UUID3,
@ -725,7 +745,8 @@ class TestRegistryRPC(base.IsolatedUnitTest):
'name': 'new name! #123',
'size': 19,
'checksum': None,
'created_at': time1}
'created_at': uuid3_time,
'updated_at': uuid3_time}
db_api.image_create(self.context, extra_fixture)
@ -738,7 +759,8 @@ class TestRegistryRPC(base.IsolatedUnitTest):
'name': 'new name! #123',
'size': 20,
'checksum': None,
'created_at': time2}
'created_at': uuid4_time,
'updated_at': uuid4_time}
db_api.image_create(self.context, extra_fixture)
@ -751,7 +773,8 @@ class TestRegistryRPC(base.IsolatedUnitTest):
'name': 'new name! #123',
'size': 20,
'checksum': None,
'created_at': time3}
'created_at': uuid5_time,
'updated_at': uuid5_time}
db_api.image_create(self.context, extra_fixture)
@ -842,6 +865,8 @@ class TestRegistryRPC(base.IsolatedUnitTest):
public images sorted alphabetically by status in
descending order.
"""
uuid4_time = timeutils.utcnow() + datetime.timedelta(seconds=10)
UUID3 = _gen_uuid()
extra_fixture = {'id': UUID3,
'status': 'queued',
@ -862,7 +887,9 @@ class TestRegistryRPC(base.IsolatedUnitTest):
'container_format': 'ovf',
'name': 'xyz',
'size': 20,
'checksum': None}
'checksum': None,
'created_at': uuid4_time,
'updated_at': uuid4_time}
db_api.image_create(self.context, extra_fixture)
@ -890,6 +917,8 @@ class TestRegistryRPC(base.IsolatedUnitTest):
public images sorted alphabetically by disk_format in
ascending order.
"""
uuid3_time = timeutils.utcnow() + datetime.timedelta(seconds=5)
UUID3 = _gen_uuid()
extra_fixture = {'id': UUID3,
'status': 'active',
@ -898,7 +927,9 @@ class TestRegistryRPC(base.IsolatedUnitTest):
'container_format': 'ami',
'name': 'asdf',
'size': 19,
'checksum': None}
'checksum': None,
'created_at': uuid3_time,
'updated_at': uuid3_time}
db_api.image_create(self.context, extra_fixture)
@ -938,6 +969,8 @@ class TestRegistryRPC(base.IsolatedUnitTest):
public images sorted alphabetically by container_format in
descending order.
"""
uuid3_time = timeutils.utcnow() + datetime.timedelta(seconds=5)
UUID3 = _gen_uuid()
extra_fixture = {'id': UUID3,
'status': 'active',
@ -946,7 +979,9 @@ class TestRegistryRPC(base.IsolatedUnitTest):
'container_format': 'ami',
'name': 'asdf',
'size': 19,
'checksum': None}
'checksum': None,
'created_at': uuid3_time,
'updated_at': uuid3_time}
db_api.image_create(self.context, extra_fixture)
@ -1034,9 +1069,8 @@ class TestRegistryRPC(base.IsolatedUnitTest):
Tests that the registry API returns list of
public images sorted by created_at in ascending order.
"""
now = timeutils.utcnow()
time1 = now + datetime.timedelta(seconds=5)
time2 = now
uuid4_time = timeutils.utcnow() + datetime.timedelta(seconds=10)
uuid3_time = uuid4_time + datetime.timedelta(seconds=5)
UUID3 = _gen_uuid()
extra_fixture = {'id': UUID3,
@ -1047,7 +1081,8 @@ class TestRegistryRPC(base.IsolatedUnitTest):
'name': 'new name! #123',
'size': 19,
'checksum': None,
'created_at': time1}
'created_at': uuid3_time,
'updated_at': uuid3_time}
db_api.image_create(self.context, extra_fixture)
@ -1060,7 +1095,8 @@ class TestRegistryRPC(base.IsolatedUnitTest):
'name': 'new name! #123',
'size': 20,
'checksum': None,
'created_at': time2}
'created_at': uuid4_time,
'updated_at': uuid4_time}
db_api.image_create(self.context, extra_fixture)
@ -1088,9 +1124,8 @@ class TestRegistryRPC(base.IsolatedUnitTest):
Tests that the registry API returns list of
public images sorted by updated_at in descending order.
"""
now = timeutils.utcnow()
time1 = now + datetime.timedelta(seconds=5)
time2 = now
uuid4_time = timeutils.utcnow() + datetime.timedelta(seconds=10)
uuid3_time = uuid4_time + datetime.timedelta(seconds=5)
UUID3 = _gen_uuid()
extra_fixture = {'id': UUID3,
@ -1102,7 +1137,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
'size': 19,
'checksum': None,
'created_at': None,
'updated_at': time1}
'updated_at': uuid3_time}
db_api.image_create(self.context, extra_fixture)
@ -1116,7 +1151,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
'size': 20,
'checksum': None,
'created_at': None,
'updated_at': time2}
'updated_at': uuid4_time}
db_api.image_create(self.context, extra_fixture)