udisks2/SOURCES/udisks-2.10.0-iscsi_test_03_iscsid_cache_clean.patch
2023-03-29 11:31:07 +00:00

85 lines
4.2 KiB
Diff

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