Blame SOURCES/0003-nvmetcli-Improve-IOError-handling-on-restore.patch

26b18e
From 48b8f318e0594d7adfec290ae47d9308eb0f65af Mon Sep 17 00:00:00 2001
26b18e
From: Tony Asleson <tasleson@redhat.com>
26b18e
Date: Thu, 26 Mar 2020 13:07:45 -0500
26b18e
Subject: [PATCH 03/12] nvmetcli: Improve IOError handling on restore
26b18e
26b18e
Not all IOErrors are caused by specifying a missing configuration
26b18e
file.  When the file is present, dump the error exception text too,
26b18e
so the user has a better idea what is wrong.
26b18e
26b18e
Signed-off-by: Tony Asleson <tasleson@redhat.com>
26b18e
Signed-off-by: Christoph Hellwig <hch@lst.de>
26b18e
---
26b18e
 nvmetcli | 19 +++++++++++++++----
26b18e
 1 file changed, 15 insertions(+), 4 deletions(-)
26b18e
26b18e
diff --git a/nvmetcli b/nvmetcli
26b18e
index 3d8c16e..a646232 100755
26b18e
--- a/nvmetcli
26b18e
+++ b/nvmetcli
26b18e
@@ -24,6 +24,7 @@ import os
26b18e
 import sys
26b18e
 import configshell_fb as configshell
26b18e
 import nvmet as nvme
26b18e
+import errno
26b18e
 from string import hexdigits
26b18e
 import uuid
26b18e
 
26b18e
@@ -674,16 +675,26 @@ def save(to_file):
26b18e
 
26b18e
 
26b18e
 def restore(from_file):
26b18e
+    errors = None
26b18e
+
26b18e
     try:
26b18e
         errors = nvme.Root().restore_from_file(from_file)
26b18e
-    except IOError:
26b18e
-        # Not an error if the restore file is not present
26b18e
-        print("No saved config file at %s, ok, exiting" % from_file)
26b18e
-    sys.exit(0)
26b18e
+    except IOError as e:
26b18e
+        if e.errno == errno.ENOENT:
26b18e
+            # Not an error if the restore file is not present
26b18e
+            print("No saved config file at %s, ok, exiting" % from_file)
26b18e
+            sys.exit(0)
26b18e
+        else:
26b18e
+            print("Error processing config file at %s, error %s, exiting" %
26b18e
+                  (from_file, str(e)))
26b18e
+            sys.exit(1)
26b18e
 
26b18e
+    # These errors are non-fatal
26b18e
     for error in errors:
26b18e
         print(error)
26b18e
 
26b18e
+    sys.exit(0)
26b18e
+
26b18e
 
26b18e
 def clear(unused):
26b18e
     nvme.Root().clear_existing()
26b18e
-- 
26b18e
2.29.2
26b18e