]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Mock out image source file in image_utils tests
authorJohn Griffith <john.griffith8@gmail.com>
Sat, 16 Aug 2014 00:18:33 +0000 (18:18 -0600)
committerJohn Griffith <john.griffith8@gmail.com>
Tue, 19 Aug 2014 15:28:58 +0000 (09:28 -0600)
Change 202ebc2d987c86984ba9cf8e8e36c32899baaa3b
added some metrics gathering around time to fetch
and convert images.  To do this it uses os.stat,
and when it was written and tested on Linux everything
was cool.

Turns out however there were a few more methods that needed
mocks for the stat command.  This patch adds them.

Also, it was pointed out that for this specific set of tests
we don't actually need to set the class stat_results, mock
will just work for us here since we're not checking an explicit
value.  So this patch also removes those class decl's from
previous methods as they're not needed and we should keep
things consistent.

Change-Id: I31e85694bd167c08a585594b2675dc7232429e05

cinder/tests/test_image_utils.py

index c26f1707e8183a624926cf52c9539c5ae2d0295e..5a542db24cec8582313665a95b116bfd61d17f78 100644 (file)
@@ -81,9 +81,6 @@ class TestUtils(test.TestCase):
     @mock.patch('os.stat')
     def test_convert_image(self, mock_stat):
 
-        class stat_result:
-            st_size = 1048576
-
         mox = self._mox
         mox.StubOutWithMock(utils, 'execute')
 
@@ -271,9 +268,6 @@ class TestUtils(test.TestCase):
                     "cluster_size: 65536\n"
                     "disk_size: 196K (200704 bytes)\n")
 
-        class stat_result:
-            st_size = 1048576
-
         self._test_fetch_to_raw(src_inf=SRC_INFO, dest_inf=DST_INFO)
 
         image_utils.fetch_to_raw(context, self._image_service,
@@ -294,9 +288,6 @@ class TestUtils(test.TestCase):
                     "cluster_size: 65536\n"
                     "disk_size: 196K (200704 bytes)\n")
 
-        class stat_result:
-            st_size = 1048576
-
         self._test_fetch_to_raw(src_inf=SRC_INFO, dest_inf=DST_INFO,
                                 bps_limit=1048576)
 
@@ -357,9 +348,6 @@ class TestUtils(test.TestCase):
                     "cluster_size: 65536\n"
                     "disk_size: 196K (200704 bytes)")
 
-        class stat_result:
-            st_size = 1048576
-
         self._test_fetch_to_raw(src_inf=IMG_INFO, dest_inf=IMG_INFO)
 
         self.assertRaises(exception.ImageUnacceptable,
@@ -440,13 +428,15 @@ class TestUtils(test.TestCase):
 
         self._test_fetch_verify_image(TEST_RETURN)
 
-    def test_upload_volume(self, bps_limit=0):
+    @mock.patch('os.stat')
+    def test_upload_volume(self, mock_stat, bps_limit=0):
         image_meta = {'id': 1, 'disk_format': 'qcow2'}
         TEST_RET = "image: qemu.qcow2\n"\
                    "file_format: qcow2 \n"\
                    "virtual_size: 50M (52428800 bytes)\n"\
                    "cluster_size: 65536\n"\
                    "disk_size: 196K (200704 bytes)"
+
         if bps_limit:
             CONF.set_override('volume_copy_bps_limit', bps_limit)
             prefix = ('cgexec', '-g', 'blkio:test')
@@ -474,7 +464,9 @@ class TestUtils(test.TestCase):
                                   image_meta, '/dev/loop1')
         m.VerifyAll()
 
-    def test_upload_volume_with_bps_limit(self):
+    @mock.patch('os.stat')
+    def test_upload_volume_with_bps_limit(self, mock_stat):
+
         self.test_upload_volume(bps_limit=1048576)
 
     def test_upload_volume_with_raw_image(self):
@@ -490,7 +482,8 @@ class TestUtils(test.TestCase):
                                       image_meta, f.name)
         mox.VerifyAll()
 
-    def test_upload_volume_on_error(self):
+    @mock.patch('os.stat')
+    def test_upload_volume_on_error(self, mock_stat):
         image_meta = {'id': 1, 'disk_format': 'qcow2'}
         TEST_RET = "image: qemu.vhd\n"\
                    "file_format: vhd \n"\