Simplify code by letting run() generate exception on non zero exit status
This commit is contained in:
parent
f3f8bd5dc6
commit
34f871ae75
@ -9,12 +9,10 @@ def pfctl_cfg_read(anchor):
|
|||||||
cmd = [_SUDO, _PFCTL, '-a', anchor, '-sr']
|
cmd = [_SUDO, _PFCTL, '-a', anchor, '-sr']
|
||||||
logging.info('Running %s', cmd)
|
logging.info('Running %s', cmd)
|
||||||
|
|
||||||
res = run(cmd, capture_output=True)
|
res = run(cmd, capture_output=True, check=True)
|
||||||
|
|
||||||
if res and res.stdout:
|
logging.info('Result: %s', res)
|
||||||
logging.info('Result: %s', res)
|
return res.stdout.splitlines()
|
||||||
res.check_returncode()
|
|
||||||
return res.stdout.splitlines()
|
|
||||||
|
|
||||||
|
|
||||||
def pfctl_cfg_write(anchor, cfg):
|
def pfctl_cfg_write(anchor, cfg):
|
||||||
@ -24,12 +22,11 @@ def pfctl_cfg_write(anchor, cfg):
|
|||||||
|
|
||||||
res = run(cmd,
|
res = run(cmd,
|
||||||
input=cfg,
|
input=cfg,
|
||||||
|
check=True,
|
||||||
capture_output=True)
|
capture_output=True)
|
||||||
|
|
||||||
if res:
|
logging.info('Result: %s', res)
|
||||||
logging.info('Result: %s', res)
|
return res.stdout.splitlines()
|
||||||
res.check_returncode()
|
|
||||||
return res.stdout.splitlines()
|
|
||||||
|
|
||||||
|
|
||||||
def pfctl_table_op(anchor, **kwargs):
|
def pfctl_table_op(anchor, **kwargs):
|
||||||
@ -40,9 +37,9 @@ def pfctl_table_op(anchor, **kwargs):
|
|||||||
|
|
||||||
logging.info('Running %s', cmd)
|
logging.info('Running %s', cmd)
|
||||||
|
|
||||||
res = run([x for x in cmd if x is not None], capture_output=True)
|
res = run([x for x in cmd if x is not None],
|
||||||
|
capture_output=True,
|
||||||
|
check=True)
|
||||||
|
|
||||||
if res:
|
logging.debug(res)
|
||||||
logging.debug(res)
|
return res.stdout.splitlines()
|
||||||
res.check_returncode()
|
|
||||||
return res.stdout.splitlines()
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user