From 80f9cba33e44b65517d1d2193afaa440b40d6374 Mon Sep 17 00:00:00 2001 From: Sean McGinnis Date: Wed, 21 Mar 2018 13:36:33 +0000 Subject: [PATCH] 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 --- .../volume/flows/test_create_volume_flow.py | 55 ++++++++++--------- 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/cinder/tests/unit/volume/flows/test_create_volume_flow.py b/cinder/tests/unit/volume/flows/test_create_volume_flow.py index 72466a23d29..985c6033f5b 100644 --- a/cinder/tests/unit/volume/flows/test_create_volume_flow.py +++ b/cinder/tests/unit/volume/flows/test_create_volume_flow.py @@ -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