Blame SOURCES/0013-saveconfig-fix-failure-in-absence-of-save-file.patch

dbfba8
From 1dccdd8f1415c7fe63fb59044618435a09619e45 Mon Sep 17 00:00:00 2001
dbfba8
From: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
dbfba8
Date: Tue, 24 Apr 2018 16:33:36 +0530
dbfba8
Subject: [PATCH] saveconfig: fix failure in absence of save file
dbfba8
dbfba8
$ ls /etc/target/
dbfba8
backup
dbfba8
dbfba8
$ targetcli /backstores/user:glfs/testX saveconfig
dbfba8
[Errno 2] No such file or directory: '/etc/target/saveconfig.json'
dbfba8
dbfba8
Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
dbfba8
---
dbfba8
 rtslib/root.py | 9 ++++++---
dbfba8
 1 file changed, 6 insertions(+), 3 deletions(-)
dbfba8
dbfba8
diff --git a/rtslib/root.py b/rtslib/root.py
dbfba8
index 913d8ea..d5a6e43 100644
dbfba8
--- a/rtslib/root.py
dbfba8
+++ b/rtslib/root.py
dbfba8
@@ -184,9 +184,12 @@ class RTSRoot(CFSNode):
dbfba8
         '''
dbfba8
         current = self.dump()
dbfba8
 
dbfba8
-        with open(save_file, "r") as f:
dbfba8
-            saveconf = json.loads(f.read())
dbfba8
-            f.close()
dbfba8
+        if not os.path.exists(save_file):
dbfba8
+            saveconf = {'storage_objects': [], 'targets': []}
dbfba8
+        else:
dbfba8
+            with open(save_file, "r") as f:
dbfba8
+                saveconf = json.loads(f.read())
dbfba8
+                f.close()
dbfba8
 
dbfba8
         fetch_cur_so = False
dbfba8
         fetch_cur_tg = False
dbfba8
-- 
dbfba8
1.8.3.1
dbfba8