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