6903c7
commit 68115b16181db7a38f852b101ec965b9fc3e59cb
6903c7
Author: Tomas Bzatek <tbzatek@redhat.com>
6903c7
Date:   Thu Oct 20 17:32:29 2022 +0200
6903c7
6903c7
    tests: Clean the discovered test target iscsid node cache
6903c7
    
6903c7
    After each DiscoverSendTargets() and Login() calls iscsid caches
6903c7
    the node info in /var/lib/iscsi/nodes. That includes auth info and
6903c7
    passwords in plaintext. This might potentially lead to lingering
6903c7
    attributes sneaking into subsequent tests, affecting the results.
6903c7
    
6903c7
    Let's clean that after each test run.
6903c7
6903c7
diff --git a/src/tests/dbus-tests/test_30_iscsi.py b/src/tests/dbus-tests/test_30_iscsi.py
6903c7
index 6ac8386b..2b75462a 100644
6903c7
--- a/src/tests/dbus-tests/test_30_iscsi.py
6903c7
+++ b/src/tests/dbus-tests/test_30_iscsi.py
6903c7
@@ -6,6 +6,7 @@ import os
6903c7
 import re
6903c7
 import six
6903c7
 import time
6903c7
+import shutil
6903c7
 import unittest
6903c7
 
6903c7
 
6903c7
@@ -26,6 +27,7 @@ class UdisksISCSITest(udiskstestcase.UdisksTestCase):
6903c7
     chap_iqn = 'iqn.2003-01.udisks.test:iscsi-test-chap'
6903c7
     mutual_iqn = 'iqn.2003-01.udisks.test:iscsi-test-mutual'
6903c7
 
6903c7
+
6903c7
     # Define common D-Bus method call timeout that needs to be slightly longer
6903c7
     # than the corresponding timeout defined in libiscsi:
6903c7
     #   #define ISCSID_REQ_TIMEOUT 1000
6903c7
@@ -61,6 +63,10 @@ class UdisksISCSITest(udiskstestcase.UdisksTestCase):
6903c7
         initiator = bytearray(data)
6903c7
         return initiator.strip().split(b"InitiatorName=")[1]
6903c7
 
6903c7
+    def _clean_iscsid_node_dir(self):
6903c7
+        for iqn in [self.noauth_iqn, self.chap_iqn, self.mutual_iqn]:
6903c7
+            shutil.rmtree(os.path.join('/var/lib/iscsi/nodes/', iqn), ignore_errors=True)
6903c7
+
6903c7
     def test__manager_interface(self):
6903c7
         '''Test for module D-Bus Manager interface presence'''
6903c7
 
6903c7
@@ -86,6 +92,7 @@ class UdisksISCSITest(udiskstestcase.UdisksTestCase):
6903c7
         nodes, _ = manager.DiscoverSendTargets(self.address, self.port, self.no_options,
6903c7
                                                dbus_interface=self.iface_prefix + '.Manager.ISCSI.Initiator',
6903c7
                                                timeout=self.iscsi_timeout)
6903c7
+        self.addCleanup(self._clean_iscsid_node_dir)
6903c7
 
6903c7
         node = next((node for node in nodes if node[0] == self.noauth_iqn), None)
6903c7
         self.assertIsNotNone(node)
6903c7
@@ -131,6 +138,7 @@ class UdisksISCSITest(udiskstestcase.UdisksTestCase):
6903c7
         nodes, _ = manager.DiscoverSendTargets(self.address, self.port, self.no_options,
6903c7
                                                dbus_interface=self.iface_prefix + '.Manager.ISCSI.Initiator',
6903c7
                                                timeout=self.iscsi_timeout)
6903c7
+        self.addCleanup(self._clean_iscsid_node_dir)
6903c7
 
6903c7
         node = next((node for node in nodes if node[0] == self.chap_iqn), None)
6903c7
         self.assertIsNotNone(node)
6903c7
@@ -190,6 +198,7 @@ class UdisksISCSITest(udiskstestcase.UdisksTestCase):
6903c7
         nodes, _ = manager.DiscoverSendTargets(self.address, self.port, self.no_options,
6903c7
                                                dbus_interface=self.iface_prefix + '.Manager.ISCSI.Initiator',
6903c7
                                                timeout=self.iscsi_timeout)
6903c7
+        self.addCleanup(self._clean_iscsid_node_dir)
6903c7
 
6903c7
         node = next((node for node in nodes if node[0] == self.mutual_iqn), None)
6903c7
         self.assertIsNotNone(node)
6903c7
@@ -246,6 +255,7 @@ class UdisksISCSITest(udiskstestcase.UdisksTestCase):
6903c7
         nodes, _ = manager.DiscoverSendTargets(self.address, self.port, self.no_options,
6903c7
                                                dbus_interface=self.iface_prefix + '.Manager.ISCSI.Initiator',
6903c7
                                                timeout=self.iscsi_timeout)
6903c7
+        self.addCleanup(self._clean_iscsid_node_dir)
6903c7
 
6903c7
         node = next((node for node in nodes if node[0] == self.noauth_iqn), None)
6903c7
         self.assertIsNotNone(node)
6903c7
@@ -293,6 +303,7 @@ class UdisksISCSITest(udiskstestcase.UdisksTestCase):
6903c7
         nodes, _ = manager.DiscoverSendTargets(self.address, self.port, self.no_options,
6903c7
                                                dbus_interface=self.iface_prefix + '.Manager.ISCSI.Initiator',
6903c7
                                                timeout=self.iscsi_timeout)
6903c7
+        self.addCleanup(self._clean_iscsid_node_dir)
6903c7
 
6903c7
         node = next((node for node in nodes if node[0] == self.noauth_iqn), None)
6903c7
         self.assertIsNotNone(node)