Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 11 additions & 25 deletions sqswatcher/plugins/torque.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,22 @@

log = logging.getLogger(__name__)

if not hasattr(sub, 'check_output'):
# Fuction adapted from Python 2.7 and used for Python 2.6
def check_output(*popenargs, **kwargs):
if 'stdout' in kwargs:
raise ValueError('stdout argument not allowed, it will be overridden.')
process = sub.Popen(stdout=sub.PIPE, *popenargs, **kwargs)
output, unused_err = process.communicate()
retcode = process.poll()
if retcode:
cmd = kwargs.get("args")
if cmd is None:
cmd = popenargs[0]
exc = sub.CalledProcessError(retcode, cmd)
exc.output = output
raise exc
return output

sub.check_output = check_output


def __runCommand(command):
output = None
log.debug(repr(command))
_command = shlex.split(str(command))
log.debug(_command)

DEV_NULL = open(os.devnull, "rb")
try:
output = sub.check_output(_command, env=dict(os.environ), stderr=sub.STDOUT)
except sub.CalledProcessError as exc:
log.error("Failed to run %s:\n%s" % (_command, exc.output))
return output
process = sub.Popen(_command, env=dict(os.environ), stdout=sub.PIPE, stderr=sub.STDOUT, stdin=DEV_NULL)
stdout = process.communicate()[0]
exitcode = process.poll()
if exitcode != 0:
log.error("Failed to run %s:\n%s" % (_command, stdout))
return stdout
finally:
DEV_NULL.close()


def isHostInitState(host_state):
# Node states http://docs.adaptivecomputing.com/torque/6-0-2/adminGuide/help.htm#topics/torque/8-resources/resources.htm#nodeStates
Expand Down