]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fix some unittest cases failed on osx
authorHaomai Wang <haomai@unitedstack.com>
Tue, 11 Jun 2013 08:36:42 +0000 (16:36 +0800)
committerHaomai Wang <haomai@unitedstack.com>
Wed, 12 Jun 2013 07:49:28 +0000 (15:49 +0800)
dd shouldn't actually be called in the unit tests to begin with. Stub these
improper calls out.

Fixes bug: 1188972

Change-Id: I2966382a66eebbf49ce74e091e444a91ab274869

cinder/tests/test_scality.py

index ec1ed0501c3240f56e6cb7b511a896d0bf783d58..4eaa41d0720a0027a7b4662664a940445454e08f 100644 (file)
@@ -19,6 +19,8 @@ Unit tests for the Scality SOFS Volume Driver.
 import errno
 import os
 
+import mox as mox_lib
+
 from cinder import exception
 from cinder import test
 from cinder import utils
@@ -104,6 +106,7 @@ class ScalityDriverTestCase(test.TestCase):
         self._remove_fake_mount()
         self._driver = scality.ScalityDriver()
         self._driver.set_execute(self._execute_wrapper)
+        self._mox = mox_lib.Mox()
 
         self._create_fake_mount()
         self._create_fake_config()
@@ -163,18 +166,35 @@ class ScalityDriverTestCase(test.TestCase):
 
     def test_create_snapshot(self):
         """Expected behaviour for create_snapshot."""
-        self._driver.create_volume(self.TEST_VOLUME)
+        mox = self._mox
+
+        vol_size = self._driver._size_bytes(self.TEST_VOLSIZE)
+
+        mox.StubOutWithMock(self._driver, '_create_file')
+        self._driver._create_file(self.TEST_SNAPPATH, vol_size)
+        mox.StubOutWithMock(self._driver, '_copy_file')
+        self._driver._copy_file(self.TEST_VOLPATH, self.TEST_SNAPPATH)
+
+        mox.ReplayAll()
+
         self._driver.create_snapshot(self.TEST_SNAPSHOT)
-        self.assertTrue(os.path.isfile(self.TEST_SNAPPATH))
-        self.assertEqual(os.stat(self.TEST_SNAPPATH).st_size,
-                         100 * 1024 * 1024)
+
+        mox.UnsetStubs()
+        mox.VerifyAll()
 
     def test_delete_snapshot(self):
         """Expected behaviour for delete_snapshot."""
-        self._driver.create_volume(self.TEST_VOLUME)
-        self._driver.create_snapshot(self.TEST_SNAPSHOT)
+        mox = self._mox
+
+        mox.StubOutWithMock(os, 'remove')
+        os.remove(self.TEST_SNAPPATH)
+
+        mox.ReplayAll()
+
         self._driver.delete_snapshot(self.TEST_SNAPSHOT)
-        self.assertFalse(os.path.isfile(self.TEST_SNAPPATH))
+
+        mox.UnsetStubs()
+        mox.VerifyAll()
 
     def test_initialize_connection(self):
         """Expected behaviour for initialize_connection."""