Fixes the mgmt.test_datastores errors

The test in mgmt.test_datastores.TestDatastoreVersion.test_version_index
is failing because of concurrency race problems.

Executing in sequence the delete method would delete one
of the datastore versions and
while executing another test for index method,
the setup method would recreate the deleted object
so that queries work correctly.

But because of delete and index methods running concurrently
on different threads, the delete is deleting the object
during the execution of setup/index method on another thread
because of which the object query is failing.

As a fix, did two things,
1. Since 'test_vr1' is only used by delete method,
   shifted the query of test_vr1 to delete method.
2. Updated the mocked method used in test_version_index from
   models.Datastore.load to models.DatastoreVersion.load_by_uuid
   the former is not needed in test_version_index,
   the not-useful mock got left, probably,
   while the code for index method was updated.

Change-Id: I816b602579892588d3179a0dc08b9fc5668f1e5b
Closes-Bug: #1492130
This commit is contained in:
Sushil Kumar 2015-09-04 08:48:38 +00:00
parent f8f3183527
commit ca576ac6d2
1 changed files with 6 additions and 5 deletions

View File

@ -36,7 +36,6 @@ class TestDatastoreVersion(trove_testtools.TestCase):
'test_ds', 'test_vr2', 'mysql',
'154b350d-4d86-4214-9067-9c54b230c0da', 'pkg-1', '1')
self.ds = models.Datastore.load('test_ds')
self.ds_version1 = models.DatastoreVersion.load(self.ds, 'test_vr1')
self.ds_version2 = models.DatastoreVersion.load(self.ds, 'test_vr2')
self.context = Mock()
@ -100,18 +99,20 @@ class TestDatastoreVersion(trove_testtools.TestCase):
self.version_controller.create, self.req, body, self.tenant_id)
def test_version_delete(self):
ds_version1 = models.DatastoreVersion.load(self.ds, 'test_vr1')
output = self.version_controller.delete(self.req,
self.tenant_id,
self.ds_version1.id)
ds_version1.id)
err_msg = ("Datastore version '%s' cannot be found." %
self.ds_version1.id)
ds_version1.id)
self.assertEqual(202, output.status)
# Try to find deleted version, this should raise exception.
self.assertRaisesRegexp(
exception.DatastoreVersionNotFound,
err_msg, models.DatastoreVersion.load_by_uuid, self.ds_version1.id)
err_msg, models.DatastoreVersion.load_by_uuid, ds_version1.id)
@patch.object(remote, 'create_nova_client')
def test_version_update(self, mock_client):
@ -140,7 +141,7 @@ class TestDatastoreVersion(trove_testtools.TestCase):
self.version_controller.edit, self.req, body,
self.tenant_id, self.ds_version2.id)
@patch.object(models.Datastore, 'load')
@patch.object(models.DatastoreVersion, 'load_by_uuid')
def test_version_index(self, mock_load):
output = self.version_controller.index(
self.req, self.tenant_id)