Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip service_enable if already enabled #885

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions charmhelpers/core/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,11 @@ def service_resume(service_name, init_dir="/etc/init",
upstart_file = os.path.join(init_dir, "{}.conf".format(service_name))
sysv_file = os.path.join(initd_dir, service_name)
if init_is_systemd(service_name=service_name):
service('unmask', service_name)
service('enable', service_name)
if service('is-enabled', service_name):
log('service {} already enabled'.format(service_name), level=DEBUG)
else:
service('unmask', service_name)
service('enable', service_name)
elif os.path.exists(upstart_file):
override_path = os.path.join(
init_dir, '{}.override'.format(service_name))
Expand Down
27 changes: 27 additions & 0 deletions tests/core/test_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,18 @@ def test_resumes_a_stopped_systemd_unit(self, service, systemd,
service_name = 'foo-service'
service_running.return_value = False
systemd.return_value = True

def fake_service(action, name):
if action == 'is-enabled':
return False

if action == 'start':
return True

service.side_effect = fake_service
self.assertTrue(host.service_resume(service_name))
service.assert_has_calls([
call('is-enabled', service_name),
call('unmask', service_name),
# Ensures a package starts up if disabled but not masked,
# per lp:1692178
Expand Down Expand Up @@ -455,6 +465,23 @@ def test_resume_a_running_sysv_service(self, service, check_call,
self.assertFalse(service.called)
check_call.assert_called_with(["update-rc.d", service_name, "enable"])

@patch.object(host, 'service_running')
@patch.object(host, 'init_is_systemd')
@patch.object(host, 'service')
def test_resume_an_enabled_systemd_service(self, service, systemd,
service_running):
service_name = 'foo-service'
systemd.return_value = True
service_running.return_value = True

def fake_service(action, name):
if action == 'is-enabled':
return True

service.side_effect = fake_service
self.assertTrue(host.service_resume(service_name))
service.assert_has_calls([call('is-enabled', service_name)])

@patch.object(host, 'service_running')
@patch.object(host, 'init_is_systemd')
@patch.object(host, 'service')
Expand Down
Loading