From 7be055d4393c75734e94efae89bc16d0d253c9db Mon Sep 17 00:00:00 2001 From: YuanHui Xu Date: Sun, 26 Jul 2015 23:13:49 -0500 Subject: [PATCH] Add mock cases for IBM FlashSystem This patch adds the mock method into create_volume for the IBM FlashSystem unittest code. * Case for create_volume with mocked empty return value * Case for create_volume with mocked error message for storage backend Closes-Bug: #1477820 Change-Id: Ic96551b19ccde18943279f979b952d8eea45f1f7 --- cinder/tests/unit/test_ibm_flashsystem.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/cinder/tests/unit/test_ibm_flashsystem.py b/cinder/tests/unit/test_ibm_flashsystem.py index 231be396a..f4c7f606a 100644 --- a/cinder/tests/unit/test_ibm_flashsystem.py +++ b/cinder/tests/unit/test_ibm_flashsystem.py @@ -846,10 +846,28 @@ class FlashSystemDriverTestCase(test.TestCase): attr_size = float(attributes['capacity']) / units.Gi self.assertEqual(float(vol['size']), attr_size) - # case 2: delete volume + # case 2: create volume with empty returning value + with mock.patch.object(FlashSystemFakeDriver, + '_ssh') as mock_ssh: + mock_ssh.return_value = ("", "") + vol1 = self._generate_vol_info(None) + self.assertRaises(exception.VolumeBackendAPIException, + self.driver.create_volume, vol1) + + # case 3: create volume with error returning value + with mock.patch.object(FlashSystemFakeDriver, + '_ssh') as mock_ssh: + mock_ssh.return_value = ("CMMVC6070E", + "An invalid or duplicated " + "parameter has been detected.") + vol2 = self._generate_vol_info(None) + self.assertRaises(exception.VolumeBackendAPIException, + self.driver.create_volume, vol2) + + # case 4: delete volume self.driver.delete_volume(vol) - # case 3: delete volume that doesn't exist (expected not fail) + # case 5: delete volume that doesn't exist (expected not fail) vol_no_exist = self._generate_vol_info(None) self.driver.delete_volume(vol_no_exist) -- 2.45.2