Mock local directory testing for image conversion

A few unit tests hit the path in create volume that now checks for
and creates the image conversion directory. For unit test runs,
this results in a 'conversion' dir being created in the root of
the repo. This adds mocking to prevent local filesystem modification.

Change-Id: I9d3d15411089fc020257b4021a5263a18433eece
This commit is contained in:
Sean McGinnis 2018-03-21 13:36:33 +00:00
parent 41321d4bc0
commit 80f9cba33e
1 changed files with 29 additions and 26 deletions

View File

@ -1543,12 +1543,13 @@ class CreateVolumeFlowManagerImageCacheTestCase(test.TestCase):
image_volume_cache=self.mock_cache
)
manager._create_from_image(self.ctxt,
volume,
image_location,
image_id,
image_meta,
self.mock_image_service)
with mock.patch('os.path.exists', return_value=True):
manager._create_from_image(self.ctxt,
volume,
image_location,
image_id,
image_meta,
self.mock_image_service)
# Make sure clone_image is always called
self.assertTrue(self.mock_driver.clone_image.called)
@ -1612,16 +1613,17 @@ class CreateVolumeFlowManagerImageCacheTestCase(test.TestCase):
image_volume_cache=self.mock_cache
)
self.assertRaises(
exception.CinderException,
manager._create_from_image,
self.ctxt,
volume,
image_location,
image_id,
image_meta,
self.mock_image_service
)
with mock.patch('os.path.exists', return_value=True):
self.assertRaises(
exception.CinderException,
manager._create_from_image,
self.ctxt,
volume,
image_location,
image_id,
image_meta,
self.mock_image_service
)
# Make sure clone_image is always called
self.assertTrue(self.mock_driver.clone_image.called)
@ -1743,16 +1745,17 @@ class CreateVolumeFlowManagerImageCacheTestCase(test.TestCase):
image_volume_cache=self.mock_cache
)
self.assertRaises(
exception.ImageUnacceptable,
manager._create_from_image,
self.ctxt,
volume,
image_location,
image_id,
image_meta,
self.mock_image_service
)
with mock.patch('os.path.exists', return_value=True):
self.assertRaises(
exception.ImageUnacceptable,
manager._create_from_image,
self.ctxt,
volume,
image_location,
image_id,
image_meta,
self.mock_image_service
)
self.assertTrue(mock_cleanup_cg.called)
# The volume size should NOT be changed when in this case