Skip to content
This repository has been archived by the owner on Feb 29, 2024. It is now read-only.

Commit

Permalink
Ensure we don't have any trailing "requires" for paunch units
Browse files Browse the repository at this point in the history
It might happen people want to disable the health checks in an update.
This change will ensure paunch cleans things up before (re)creating the
main service unit file, in order to avoid failed dependencies in systemd
configuration.

Change-Id: Ia8ebe35a9edc41f3ec635cc05dde08783c5e2a44
  • Loading branch information
cjeanner committed May 29, 2019
1 parent 52d0b2d commit ecc2047
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
9 changes: 8 additions & 1 deletion paunch/tests/test_utils_systemd.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@

class TestUtilsSystemd(base.TestCase):

@mock.patch('shutil.rmtree', autospec=True)
@mock.patch('os.path.exists', autospec=True)
@mock.patch('subprocess.check_call', autospec=True)
@mock.patch('os.chmod')
def test_service_create(self, mock_chmod, mock_subprocess_check_call):
def test_service_create(self, mock_chmod, mock_subprocess_check_call,
mock_exists, mock_rmtree):
container = 'my_app'
service = 'tripleo_' + container
cconfig = {'depends_on': ['something'], 'restart': 'unless-stopped',
Expand All @@ -46,6 +49,10 @@ def test_service_create(self, mock_chmod, mock_subprocess_check_call):
mock.call(['systemctl', 'enable', '--now', service]),
])

mock_rmtree.assert_has_calls([
mock.call(sysd_unit_f + '.requires')
])

os.rmdir(tempdir)

@mock.patch('subprocess.check_call', autospec=True)
Expand Down
5 changes: 5 additions & 0 deletions paunch/utils/systemd.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ def service_create(container, cconfig, sysdir=constants.SYSTEMD_DIR, log=None):
'stop_grace_period': stop_grace_period,
'sys_exec': '\n'.join(['%s=%s' % (x, y) for x, y in sys_exec.items()]),
}
# Ensure we don't have some trailing .requires directory and content for
# this service
if os.path.exists(sysd_unit_f + '.requires'):
shutil.rmtree(sysd_unit_f + '.requires')

with open(sysd_unit_f, 'w') as unit_file:
os.chmod(unit_file.name, 0o644)
unit_file.write("""[Unit]
Expand Down

0 comments on commit ecc2047

Please sign in to comment.