]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - test/test-exec-deserialization.py
test: convert ubuntu-ci to use deny-list
[thirdparty/systemd.git] / test / test-exec-deserialization.py
index b974b1c1336e342656013a4137732f857b77ad0d..8aa16fb7f94838201d1e82bb6d9a31e046965409 100755 (executable)
@@ -1,20 +1,7 @@
-#!/usr/bin/python3
-
-#
-#  Copyright 2017 Michal Sekletar <msekleta@redhat.com>
-#
-#  systemd is free software; you can redistribute it and/or modify it
-#  under the terms of the GNU Lesser General Public License as published by
-#  the Free Software Foundation; either version 2.1 of the License, or
-#  (at your option) any later version.
+#!/usr/bin/env python3
+# SPDX-License-Identifier: LGPL-2.1+
 #
-#  systemd is distributed in the hope that it will be useful, but
-#  WITHOUT ANY WARRANTY; without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-#  Lesser General Public License for more details.
-#
-#  You should have received a copy of the GNU Lesser General Public License
-#  along with systemd; If not, see <http://www.gnu.org/licenses/>.
+#  Copyright © 2017 Michal Sekletar <msekleta@redhat.com>
 
 # ATTENTION: This uses the *installed* systemd, not the one from the built
 # source tree.
@@ -24,6 +11,7 @@ import time
 import os
 import tempfile
 import subprocess
+import sys
 
 from enum import Enum
 
@@ -45,7 +33,7 @@ class ExecutionResumeTest(unittest.TestCase):
         unit_file_content = '''
         [Service]
         Type=oneshot
-        ExecStart=/bin/sleep 2
+        ExecStart=/bin/sleep 3
         ExecStart=/bin/bash -c "echo foo >> {0}"
         '''.format(self.output_file)
         self.unit_files[UnitFileChange.NO_CHANGE] = unit_file_content
@@ -54,7 +42,7 @@ class ExecutionResumeTest(unittest.TestCase):
         [Service]
         Type=oneshot
         ExecStart=/bin/bash -c "echo foo >> {0}"
-        ExecStart=/bin/sleep 2
+        ExecStart=/bin/sleep 3
         '''.format(self.output_file)
         self.unit_files[UnitFileChange.LINES_SWAPPED] = unit_file_content
 
@@ -62,7 +50,7 @@ class ExecutionResumeTest(unittest.TestCase):
         [Service]
         Type=oneshot
         ExecStart=/bin/bash -c "echo bar >> {0}"
-        ExecStart=/bin/sleep 2
+        ExecStart=/bin/sleep 3
         ExecStart=/bin/bash -c "echo foo >> {0}"
         '''.format(self.output_file)
         self.unit_files[UnitFileChange.COMMAND_ADDED_BEFORE] = unit_file_content
@@ -70,7 +58,7 @@ class ExecutionResumeTest(unittest.TestCase):
         unit_file_content = '''
         [Service]
         Type=oneshot
-        ExecStart=/bin/sleep 2
+        ExecStart=/bin/sleep 3
         ExecStart=/bin/bash -c "echo foo >> {0}"
         ExecStart=/bin/bash -c "echo bar >> {0}"
         '''.format(self.output_file)
@@ -80,7 +68,7 @@ class ExecutionResumeTest(unittest.TestCase):
         [Service]
         Type=oneshot
         ExecStart=/bin/bash -c "echo baz >> {0}"
-        ExecStart=/bin/sleep 2
+        ExecStart=/bin/sleep 3
         ExecStart=/bin/bash -c "echo foo >> {0}"
         ExecStart=/bin/bash -c "echo bar >> {0}"
         '''.format(self.output_file)
@@ -120,6 +108,7 @@ class ExecutionResumeTest(unittest.TestCase):
     def setup_unit(self):
         self.write_unit_file(UnitFileChange.NO_CHANGE)
         subprocess.check_call(['systemctl', '--job-mode=replace', '--no-block', 'start', self.unit])
+        time.sleep(1)
 
     def test_no_change(self):
         expected_output = 'foo\n'
@@ -178,6 +167,37 @@ class ExecutionResumeTest(unittest.TestCase):
 
         self.assertTrue(not os.path.exists(self.output_file))
 
+    def test_issue_6533(self):
+        unit = "test-issue-6533.service"
+        unitfile_path = "/run/systemd/system/{}".format(unit)
+
+        content = '''
+        [Service]
+        ExecStart=/bin/sleep 5
+        '''
+
+        with open(unitfile_path, 'w') as f:
+            f.write(content)
+
+        self.reload()
+
+        subprocess.check_call(['systemctl', '--job-mode=replace', '--no-block', 'start', unit])
+        time.sleep(2)
+
+        content = '''
+        [Service]
+        ExecStart=/bin/sleep 5
+        ExecStart=/bin/true
+        '''
+
+        with open(unitfile_path, 'w') as f:
+            f.write(content)
+
+        self.reload()
+        time.sleep(5)
+
+        self.assertTrue(subprocess.call("journalctl -b _PID=1  | grep -q 'Freezing execution'", shell=True) != 0)
+
     def tearDown(self):
         for f in [self.output_file, self.unitfile_path]:
             try:
@@ -189,4 +209,4 @@ class ExecutionResumeTest(unittest.TestCase):
         self.reload()
 
 if __name__ == '__main__':
-    unittest.main()
+    unittest.main(testRunner=unittest.TextTestRunner(stream=sys.stdout, verbosity=3))