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

systemd: Support 'None' as value for 'running' #327

Merged
merged 2 commits into from Feb 21, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 16 additions & 13 deletions bundlewrap/items/svc_systemd.py
Expand Up @@ -45,6 +45,7 @@ class SvcSystemd(Item):
A service managed by systemd.
"""
BUNDLE_ATTRIBUTE_NAME = "svc_systemd"
# bw 3.0: Both should default to True.
ITEM_ATTRIBUTES = {
'enabled': None,
'running': True,
Expand All @@ -58,26 +59,25 @@ def __repr__(self):
self.attributes['running'],
)

# Note for bw 3.0: We're planning to make "True" the default value
# for "enabled". Once that's done, we can remove this custom cdict.
def cdict(self):
cdict = self.attributes.copy()
if 'enabled' in cdict and cdict['enabled'] is None:
del cdict['enabled']
cdict = {}
for option, value in self.attributes.items():
if value is not None:
cdict[option] = value
return cdict

def fix(self, status):
if 'enabled' in status.keys_to_fix:
if self.attributes['enabled'] is False:
svc_disable(self.node, self.name)
else:
if self.attributes['enabled']:
svc_enable(self.node, self.name)
else:
svc_disable(self.node, self.name)

if 'running' in status.keys_to_fix:
if self.attributes['running'] is False:
svc_stop(self.node, self.name)
else:
if self.attributes['running']:
svc_start(self.node, self.name)
else:
svc_stop(self.node, self.name)

def get_canned_actions(self):
return {
Expand All @@ -100,9 +100,12 @@ def sdict(self):
@classmethod
def validate_attributes(cls, bundle, item_id, attributes):
for attribute in ('enabled', 'running'):
if not isinstance(attributes.get(attribute, True), bool):
if (
not isinstance(attributes.get(attribute, True), bool) and
not attributes.get(attribute, None) is None
):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if attributes.get(attribute, None) not in (True, False, None)

raise BundleError(_(
"expected boolean for '{attribute}' on {item} in bundle '{bundle}'"
"expected boolean or None for '{attribute}' on {item} in bundle '{bundle}'"
).format(
attribute=attribute,
bundle=bundle.name,
Expand Down
2 changes: 1 addition & 1 deletion docs/content/items/svc_systemd.md
Expand Up @@ -28,7 +28,7 @@ See also: [The list of generic builtin item attributes](../repo/bundles.md#built

### running

`True` if the service is expected to be running on the system; `False` if it should be stopped.
`True` if the service is expected to be running on the system; `False` if it should be stopped. `None` makes BundleWrap ignore this setting.

<br>

Expand Down