From 12e626b649ef4a928aa95e60d8b8c58b20bd3372 Mon Sep 17 00:00:00 2001
From: Andy Grover <agrover@redhat.com>
Date: Thu, 21 Sep 2017 16:45:30 -0700
Subject: [PATCH] Remove hba-only directories in clear_existing()
rtslib never creates hba directories without a storage object within it,
but if under some circumstance these existed then clear_existing() wouldn't
remove them, since StorageObject::all()'s glob ignores them.
Add code to ensure these are also removed.
Signed-off-by: Andy Grover <agrover@redhat.com>
---
rtslib/root.py | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/rtslib/root.py b/rtslib/root.py
index 0c3c231..72c0299 100644
--- a/rtslib/root.py
+++ b/rtslib/root.py
@@ -21,6 +21,7 @@ under the License.
import os
import stat
import json
+import glob
from .node import CFSNode
from .target import Target
@@ -206,6 +207,11 @@ class RTSRoot(CFSNode):
for so in self.storage_objects:
so.delete()
+ # If somehow some hbas still exist (no storage object within?) clean
+ # them up too.
+ for hba_dir in glob.glob("%s/core/*_*" % self.configfs_dir):
+ os.rmdir(hba_dir)
+
def restore(self, config, clear_existing=False, abort_on_error=False):
'''
Takes a dict generated by dump() and reconfigures the target to match.
--
1.8.3.1