Change in vdsm[master]: tests: Use MonkeyPatchScope to inject failures

alitke at redhat.com alitke at redhat.com
Mon May 2 17:35:06 UTC 2016


Adam Litke has uploaded a new change for review.

Change subject: tests: Use MonkeyPatchScope to inject failures
......................................................................

tests: Use MonkeyPatchScope to inject failures

The FileVolumeArtifactsTests checked volume creation failures by
directly replacing VolumeArtifacts methods with a boobytrapped method.
We can make these tests clearer and more resilient by using
MonkeyPatchScope.  They will also look more like the Block tests that
test similar failure scenarios.

Change-Id: Iceed070c2da36460f6aa60a72f079d2e185da6a7
Signed-off-by: Adam Litke <alitke at redhat.com>
---
M tests/storage_volume_artifacts_test.py
1 file changed, 16 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/36/56936/1

diff --git a/tests/storage_volume_artifacts_test.py b/tests/storage_volume_artifacts_test.py
index 2f9e9f6..e8cb229 100644
--- a/tests/storage_volume_artifacts_test.py
+++ b/tests/storage_volume_artifacts_test.py
@@ -30,7 +30,7 @@
 from vdsm.storage import exception as se
 from vdsm.storage.constants import TEMP_VOL_LVTAG
 
-from storage import image, misc, sd, blockVolume, volume
+from storage import image, misc, sd, blockVolume, fileVolume, volume
 from storage.sdm.api import create_volume
 
 
@@ -191,9 +191,11 @@
         with self.fake_env() as env:
             artifacts = env.sd_manifest.get_volume_artifacts(
                 self.img_id, self.vol_id)
-            artifacts._create_metadata_artifact = failure
-            self.assertRaises(ExpectedFailure, artifacts.create,
-                              *BASE_RAW_PARAMS)
+            with MonkeyPatchScope([
+                [volume.VolumeMetadata, '__init__', failure]
+            ]):
+                self.assertRaises(ExpectedFailure, artifacts.create,
+                                  *BASE_RAW_PARAMS)
             self.validate_new_image_path(artifacts)
             self.validate_domain_has_garbage(env.sd_manifest)
 
@@ -203,9 +205,11 @@
         with self.fake_env() as env:
             artifacts = env.sd_manifest.get_volume_artifacts(
                 self.img_id, self.vol_id)
-            artifacts._create_lease_file = failure
-            self.assertRaises(ExpectedFailure, artifacts.create,
-                              *BASE_RAW_PARAMS)
+            with MonkeyPatchScope([
+                [fileVolume.FileVolumeManifest, 'newVolumeLease', failure]
+            ]):
+                self.assertRaises(ExpectedFailure, artifacts.create,
+                                  *BASE_RAW_PARAMS)
             self.validate_new_image_path(artifacts, has_md=True)
             self.validate_domain_has_garbage(env.sd_manifest)
 
@@ -215,9 +219,11 @@
         with self.fake_env() as env:
             artifacts = env.sd_manifest.get_volume_artifacts(
                 self.img_id, self.vol_id)
-            artifacts._create_volume_file = failure
-            self.assertRaises(ExpectedFailure, artifacts.create,
-                              *BASE_RAW_PARAMS)
+            with MonkeyPatchScope([
+                [artifacts, '_create_volume_file', failure]
+            ]):
+                self.assertRaises(ExpectedFailure, artifacts.create,
+                                  *BASE_RAW_PARAMS)
             self.validate_new_image_path(artifacts,
                                          has_md=True, has_lease=True)
             self.validate_domain_has_garbage(env.sd_manifest)


-- 
To view, visit https://gerrit.ovirt.org/56936
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iceed070c2da36460f6aa60a72f079d2e185da6a7
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Adam Litke <alitke at redhat.com>


More information about the vdsm-patches mailing list