From a2ad9c92d0c1092be6e5ed9a662a95e7125b3e59 Mon Sep 17 00:00:00 2001 From: Tamer Ahmed Date: Tue, 25 Aug 2020 12:25:06 -0700 Subject: [PATCH 1/2] [hostcfgd] Fix Boolean String Evaluation New attribute 'has_timer' introduced to init_cfg.json does not evaluate as Bool, rather it evaluates as string. This PR fixes this issue signed-off-by: Tamer Ahmed --- files/image_config/hostcfgd/hostcfgd | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/files/image_config/hostcfgd/hostcfgd b/files/image_config/hostcfgd/hostcfgd index 29c88eb6456a..64dd0911b410 100755 --- a/files/image_config/hostcfgd/hostcfgd +++ b/files/image_config/hostcfgd/hostcfgd @@ -1,6 +1,7 @@ #!/usr/bin/python -u # -*- coding: utf-8 -*- +import ast import os import sys import subprocess @@ -41,8 +42,8 @@ def obfuscate(data): return data -def update_feature_state(feature_name, state, has_timer=False): - feature_suffixes = ["service"] + (["timer"] if has_timer else []) +def update_feature_state(feature_name, state, has_timer): + feature_suffixes = ["service"] + (["timer"] if ast.literal_eval(has_timer) else []) if state == "enabled": start_cmds = [] for suffix in feature_suffixes: From ed7f56f96b0b3cd2ccbb3b791d180262d8c49c7f Mon Sep 17 00:00:00 2001 From: Tamer Ahmed Date: Tue, 25 Aug 2020 14:16:03 -0700 Subject: [PATCH 2/2] do not enable .service systemd unit if it has timer associated and if has no installation config (WantedBy=, RequiredBy=, Also=, Alias= settings in the [Install] section --- files/image_config/hostcfgd/hostcfgd | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/files/image_config/hostcfgd/hostcfgd b/files/image_config/hostcfgd/hostcfgd index 64dd0911b410..acfc3d0c8055 100755 --- a/files/image_config/hostcfgd/hostcfgd +++ b/files/image_config/hostcfgd/hostcfgd @@ -48,9 +48,9 @@ def update_feature_state(feature_name, state, has_timer): start_cmds = [] for suffix in feature_suffixes: start_cmds.append("sudo systemctl unmask {}.{}".format(feature_name, suffix)) - start_cmds.append("sudo systemctl enable {}.{}".format(feature_name, suffix)) - # If feature has timer associated with it, start corresponding systemd .timer unit - # otherwise, start corresponding systemd .service unit + # If feature has timer associated with it, start/enable corresponding systemd .timer unit + # otherwise, start/enable corresponding systemd .service unit + start_cmds.append("sudo systemctl enable {}.{}".format(feature_name, feature_suffixes[-1])) start_cmds.append("sudo systemctl start {}.{}".format(feature_name, feature_suffixes[-1])) for cmd in start_cmds: syslog.syslog(syslog.LOG_INFO, "Running cmd: '{}'".format(cmd))