df2958
From fbe970add68e6d9d998fb7f78377368c403e200d Mon Sep 17 00:00:00 2001
df2958
From: Tomas Bzatek <tbzatek@redhat.com>
df2958
Date: Mon, 31 Oct 2022 15:15:31 +0100
df2958
Subject: [PATCH] tests: Restart iscsid on every InitiatorName change
df2958
df2958
The test LIO target config expects a specific initiator name as set
df2958
by the ACLs. However the iscsid daemon only seems to be reading
df2958
the InitiatorName string on startup and in case the service is running
df2958
with a different name, the auth tests will fail.
df2958
df2958
As a workaround, restart the iscsid service after each change.
df2958
A proper way through libiscsi or libopeniscsiusr would be nice -> TODO.
df2958
---
df2958
 src/tests/dbus-tests/test_30_iscsi.py | 12 ++++++++++++
df2958
 1 file changed, 12 insertions(+)
df2958
df2958
diff --git a/src/tests/dbus-tests/test_30_iscsi.py b/src/tests/dbus-tests/test_30_iscsi.py
df2958
index f2594d992..09e975f30 100644
df2958
--- a/src/tests/dbus-tests/test_30_iscsi.py
df2958
+++ b/src/tests/dbus-tests/test_30_iscsi.py
df2958
@@ -48,9 +48,21 @@ def _force_lougout(self, target):
df2958
     def _set_initiator_name(self):
df2958
         manager = self.get_object('/Manager')
df2958
 
df2958
+        # make backup of INITIATOR_FILE and restore it at the end
df2958
+        try:
df2958
+            initiatorname_backup = self.read_file(INITIATOR_FILE)
df2958
+            self.addCleanup(self.write_file, INITIATOR_FILE, initiatorname_backup)
df2958
+        except FileNotFoundError as e:
df2958
+            # no existing file, simply remove it once finished
df2958
+            self.addCleanup(self.remove_file, INITIATOR_FILE, True)
df2958
+
df2958
         manager.SetInitiatorName(self.initiator, self.no_options,
df2958
                                  dbus_interface=self.iface_prefix + '.Manager.ISCSI.Initiator')
df2958
 
df2958
+        # running iscsid needs to be restarted to reflect the change
df2958
+        self.run_command('systemctl try-reload-or-restart iscsid.service')
df2958
+        # ignore the return code in case of non-systemd distros
df2958
+
df2958
         init = manager.GetInitiatorName(self.no_options,
df2958
                                         dbus_interface=self.iface_prefix + '.Manager.ISCSI.Initiator')
df2958
         self.assertEqual(init, self.initiator)