[hostcfgd] Fix Boolean String Evaluation (#5248)
New attribute 'has_timer' introduced to init_cfg.json does not evaluate as Bool, rather it evaluates as string. This PR fixes this issue. Also, this PR fixes an issue when there is system config unit (snmp, telemetry) that has no installation config (WantedBy=, RequiredBy=, Also=, Alias=) settings in the [Install] section. In the latter case, the .service should not be enabled. signed-off-by: Tamer Ahmed <tamer.ahmed@microsoft.com>
This commit is contained in:
parent
a8016a6987
commit
7d3ec60b1f
@ -1,6 +1,7 @@
|
|||||||
#!/usr/bin/python -u
|
#!/usr/bin/python -u
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import ast
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
@ -41,15 +42,15 @@ def obfuscate(data):
|
|||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
def update_feature_state(feature_name, state, has_timer=False):
|
def update_feature_state(feature_name, state, has_timer):
|
||||||
feature_suffixes = ["service"] + (["timer"] if has_timer else [])
|
feature_suffixes = ["service"] + (["timer"] if ast.literal_eval(has_timer) else [])
|
||||||
if state == "enabled":
|
if state == "enabled":
|
||||||
start_cmds = []
|
start_cmds = []
|
||||||
for suffix in feature_suffixes:
|
for suffix in feature_suffixes:
|
||||||
start_cmds.append("sudo systemctl unmask {}.{}".format(feature_name, suffix))
|
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/enable corresponding systemd .timer unit
|
||||||
# If feature has timer associated with it, start corresponding systemd .timer unit
|
# otherwise, start/enable corresponding systemd .service unit
|
||||||
# otherwise, start 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]))
|
start_cmds.append("sudo systemctl start {}.{}".format(feature_name, feature_suffixes[-1]))
|
||||||
for cmd in start_cmds:
|
for cmd in start_cmds:
|
||||||
syslog.syslog(syslog.LOG_INFO, "Running cmd: '{}'".format(cmd))
|
syslog.syslog(syslog.LOG_INFO, "Running cmd: '{}'".format(cmd))
|
||||||
|
Loading…
Reference in New Issue
Block a user