From e55bd553aa67180394fbe5c104675eae6e5686e7 Mon Sep 17 00:00:00 2001 From: Ilya Shakhat Date: Fri, 19 Jul 2019 16:02:58 +0200 Subject: [PATCH] Fix representation of signal.SIG* constants Pass signals as strings instead of using python constants which depend on host system and have different types on py27 vs py3. Change-Id: Ib8d7136bb3aed125a987678672142ce72e33af6f Closes-bug: #1836736 --- os_faults/ansible/modules/freeze.py | 4 ++-- os_faults/ansible/modules/kill.py | 2 +- os_faults/drivers/services/process.py | 7 +++---- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/os_faults/ansible/modules/freeze.py b/os_faults/ansible/modules/freeze.py index 8b03039..b5a569b 100644 --- a/os_faults/ansible/modules/freeze.py +++ b/os_faults/ansible/modules/freeze.py @@ -30,8 +30,8 @@ def main(): 'echo -en \'/bin/bash\\npids=`ps ax | ' 'grep -v grep | ' 'grep %s | awk {{\\047print $1\\047}}`; ' - 'echo $pids | xargs kill -19; sleep %s; ' - 'echo $pids | xargs kill -18; rm \' >> $tf; ' + 'echo $pids | xargs kill -SIGSTOP; sleep %s; ' + 'echo $pids | xargs kill -SIGCONT; rm \' >> $tf; ' 'echo -n $tf >> $tf; ' 'chmod 770 $tf; nohup $tf &"') % (grep, sec) rc, stdout, stderr = module.run_command(cmd, check_rc=True) diff --git a/os_faults/ansible/modules/kill.py b/os_faults/ansible/modules/kill.py index 15dd69d..c8b9605 100644 --- a/os_faults/ansible/modules/kill.py +++ b/os_faults/ansible/modules/kill.py @@ -19,7 +19,7 @@ def main(): module = AnsibleModule( argument_spec=dict( grep=dict(required=True, type='str'), - sig=dict(required=True, type='int') + sig=dict(required=True, type='str') )) grep = module.params['grep'] diff --git a/os_faults/drivers/services/process.py b/os_faults/drivers/services/process.py index 2f0897f..5f573fd 100644 --- a/os_faults/drivers/services/process.py +++ b/os_faults/drivers/services/process.py @@ -12,7 +12,6 @@ # limitations under the License. import logging -import signal from os_faults.ansible import executor from os_faults.api import error @@ -121,7 +120,7 @@ class ServiceAsProcess(service.Service): def kill(self, nodes=None): task = { 'kill': { - 'grep': self.grep, 'sig': signal.SIGKILL + 'grep': self.grep, 'sig': 'SIGKILL' }, 'become': 'yes', } @@ -138,7 +137,7 @@ class ServiceAsProcess(service.Service): else: task = { 'kill': { - 'grep': self.grep, 'sig': signal.SIGSTOP + 'grep': self.grep, 'sig': 'SIGSTOP' }, 'become': 'yes', } @@ -148,7 +147,7 @@ class ServiceAsProcess(service.Service): def unfreeze(self, nodes=None): task = { 'kill': { - 'grep': self.grep, 'sig': signal.SIGCONT + 'grep': self.grep, 'sig': 'SIGCONT' }, 'become': 'yes', }