raise exception if password prompt encountered by run cmd
This commit is contained in:
parent
5b2784c15d
commit
b360278f82
@ -103,6 +103,10 @@ def run_cmd(cmd, print_output=True):
|
|||||||
output = []
|
output = []
|
||||||
try:
|
try:
|
||||||
child = pexpect.spawn(cmd)
|
child = pexpect.spawn(cmd)
|
||||||
|
index = child.expect([pexpect.EOF, '[sudo] password'])
|
||||||
|
if index == 1:
|
||||||
|
raise Exception(
|
||||||
|
'Insufficient permissions to run command "%s"' % cmd)
|
||||||
child.maxsize = 1
|
child.maxsize = 1
|
||||||
child.timeout = 86400
|
child.timeout = 86400
|
||||||
for line in child:
|
for line in child:
|
||||||
@ -110,12 +114,15 @@ def run_cmd(cmd, print_output=True):
|
|||||||
output.append(outline)
|
output.append(outline)
|
||||||
if print_output:
|
if print_output:
|
||||||
log.info(outline)
|
log.info(outline)
|
||||||
child.close()
|
|
||||||
if child.exitstatus != 0:
|
|
||||||
err_flag = True
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
err_flag = True
|
err_flag = True
|
||||||
output.append('%s' % e)
|
output.append('%s' % e)
|
||||||
|
finally:
|
||||||
|
if child:
|
||||||
|
child.close()
|
||||||
|
if child.exitstatus != 0:
|
||||||
|
err_flag = True
|
||||||
return err_flag, output
|
return err_flag, output
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user