summaryrefslogtreecommitdiff
path: root/cloudinit/config/cc_power_state_change.py
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2012-11-13 13:24:37 -0500
committerScott Moser <smoser@ubuntu.com>2012-11-13 13:24:37 -0500
commitefd02682c7cfb054490308443f7f9facf83363b5 (patch)
tree1c11f136f93612c95fbe96c00e227388e722d285 /cloudinit/config/cc_power_state_change.py
parentd8b4f9245331cb8b6f04d63a3a62e45563486512 (diff)
downloadvyos-cloud-init-efd02682c7cfb054490308443f7f9facf83363b5.tar.gz
vyos-cloud-init-efd02682c7cfb054490308443f7f9facf83363b5.zip
clean up exit to single function call
Diffstat (limited to 'cloudinit/config/cc_power_state_change.py')
-rw-r--r--cloudinit/config/cc_power_state_change.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/cloudinit/config/cc_power_state_change.py b/cloudinit/config/cc_power_state_change.py
index 7f6e780d..22f1aade 100644
--- a/cloudinit/config/cc_power_state_change.py
+++ b/cloudinit/config/cc_power_state_change.py
@@ -28,6 +28,8 @@ import time
frequency = PER_INSTANCE
+EXIT_FAIL = 254
+
def handle(_name, cfg, _cloud, log, _args):
@@ -90,14 +92,19 @@ def load_power_state(cfg):
return (args, timeout)
+def doexit(sysexit):
+ os._exit(sysexit) # pylint: disable=W0212
+
+
def execmd(exe_args, output=None, data_in=None):
try:
proc = subprocess.Popen(exe_args, stdin=subprocess.PIPE,
stdout=output, stderr=subprocess.STDOUT)
proc.communicate(data_in)
+ ret = proc.returncode
except Exception:
- sys.exit(254)
- sys.exit(proc.returncode())
+ doexit(EXIT_FAIL)
+ doexit(ret)
def run_after_pid_gone(pid, pidcmdline, timeout, log, func, args):
@@ -112,7 +119,7 @@ def run_after_pid_gone(pid, pidcmdline, timeout, log, func, args):
def fatal(msg):
if log:
log.warn(msg)
- sys.exit(254)
+ doexit(EXIT_FAIL)
while True:
if time.time() > end_time: