[PATCH 3/3] Create the image file in losetup stub test (#706099)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



losetup needs the image file to be present when creating
the loop device.
---
 command-stubs/losetup-test |   53 +++++++++++++++++++++++++------------------
 1 files changed, 31 insertions(+), 22 deletions(-)

diff --git a/command-stubs/losetup-test b/command-stubs/losetup-test
index 1b1c934..230f2ad 100644
--- a/command-stubs/losetup-test
+++ b/command-stubs/losetup-test
@@ -24,33 +24,42 @@ import sys
 
 
 def loop_device_test(device, image):
-    # new loop device
-    rc = call(['losetup', device, image])
-    if not rc == 0:
-        print('losetup: create new loop device test failed')
-        sys.exit(1)
+    # create the image file
+    f = open(image, 'w')
+    f.truncate(1000)
+    f.close()
 
     try:
-        os.stat(device)
-    except OSError:
-        print('losetup: create new loop device test failed')
-        sys.exit(1)
+        # new loop device
+        rc = call(['losetup', device, image])
+        if not rc == 0:
+            print('losetup: create new loop device test failed')
+            sys.exit(1)
 
-    # existing loop device
-    fail = False
-    rc = call(['losetup', device, image])
-    if rc == 0:
-        print('losetup: create existing loop device test failed')
-        fail = True
+        try:
+            os.stat(device)
+        except OSError:
+            print('losetup: create new loop device test failed')
+            sys.exit(1)
 
-    # remove loop device (cleanup)
-    rc = call(['losetup', '-d', device])
-    if not rc == 0:
-        print('losetup: remove loop device test failed')
-        sys.exit(1)
+        # existing loop device
+        fail = False
+        rc = call(['losetup', device, image])
+        if rc == 0:
+            print('losetup: create existing loop device test failed')
+            fail = True
 
-    if fail:
-        sys.exit(1)
+        # remove loop device (cleanup)
+        rc = call(['losetup', '-d', device])
+        if not rc == 0:
+            print('losetup: remove loop device test failed')
+            sys.exit(1)
+
+        if fail:
+            sys.exit(1)
+
+    finally:
+        os.unlink(image)
 
 def wrong_usage_test():
     try:
-- 
1.7.3.2

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list


[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux