summaryrefslogtreecommitdiff
path: root/src/op_mode
diff options
context:
space:
mode:
authorThomas Mangin <thomas.mangin@exa.net.uk>2020-04-09 19:08:24 +0100
committerGitHub <noreply@github.com>2020-04-09 20:08:24 +0200
commit9875a21bdb26df19f2faf3e81153dea15e4f9e3c (patch)
tree8a1ecc1b318d80db156f397c34bc75f40c184728 /src/op_mode
parentc8a86d3ccee63b972c36346e6cb1c712c6801ad2 (diff)
downloadvyos-1x-9875a21bdb26df19f2faf3e81153dea15e4f9e3c.tar.gz
vyos-1x-9875a21bdb26df19f2faf3e81153dea15e4f9e3c.zip
util: T2226: os.system was wrongly converted to run
os.system does print the ouput of the command, run() does not. A new function called call() does the printing and return the error code.
Diffstat (limited to 'src/op_mode')
-rwxr-xr-xsrc/op_mode/connect_disconnect.py6
-rwxr-xr-xsrc/op_mode/dns_forwarding_reset.py6
-rwxr-xr-xsrc/op_mode/dynamic_dns.py6
-rwxr-xr-xsrc/op_mode/format_disk.py6
-rwxr-xr-xsrc/op_mode/powerctrl.py6
-rwxr-xr-xsrc/op_mode/reset_vpn.py3
-rwxr-xr-xsrc/op_mode/restart_dhcp_relay.py6
-rwxr-xr-xsrc/op_mode/restart_frr.py10
-rwxr-xr-xsrc/op_mode/show_acceleration.py13
-rwxr-xr-xsrc/op_mode/show_dhcp.py4
-rwxr-xr-xsrc/op_mode/show_dhcpv6.py4
-rwxr-xr-xsrc/op_mode/snmp.py4
-rwxr-xr-xsrc/op_mode/version.py6
13 files changed, 44 insertions, 36 deletions
diff --git a/src/op_mode/connect_disconnect.py b/src/op_mode/connect_disconnect.py
index 192fd80ec..b191f630d 100755
--- a/src/op_mode/connect_disconnect.py
+++ b/src/op_mode/connect_disconnect.py
@@ -21,7 +21,7 @@ from sys import exit
from psutil import process_iter
from time import strftime, localtime, time
-from vyos.util import run
+from vyos.util import call
PPP_LOGFILE = '/var/log/vyatta/ppp_{}.log'
@@ -59,7 +59,7 @@ def connect(interface):
tm = strftime("%a %d %b %Y %I:%M:%S %p %Z", localtime(time()))
with open(PPP_LOGFILE.format(interface), 'a') as f:
f.write('{}: user {} started PPP daemon for {} by connect command\n'.format(tm, user, interface))
- run('umask 0; setsid sh -c "nohup /usr/sbin/pppd call {0} > /tmp/{0}.log 2>&1 &"'.format(interface))
+ call('umask 0; setsid sh -c "nohup /usr/sbin/pppd call {0} > /tmp/{0}.log 2>&1 &"'.format(interface))
def disconnect(interface):
@@ -77,7 +77,7 @@ def disconnect(interface):
tm = strftime("%a %d %b %Y %I:%M:%S %p %Z", localtime(time()))
with open(PPP_LOGFILE.format(interface), 'a') as f:
f.write('{}: user {} stopped PPP daemon for {} by disconnect command\n'.format(tm, user, interface))
- run('/usr/bin/poff "{}"'.format(interface))
+ call('/usr/bin/poff "{}"'.format(interface))
def main():
parser = argparse.ArgumentParser()
diff --git a/src/op_mode/dns_forwarding_reset.py b/src/op_mode/dns_forwarding_reset.py
index dad78d7e8..8e2ee546c 100755
--- a/src/op_mode/dns_forwarding_reset.py
+++ b/src/op_mode/dns_forwarding_reset.py
@@ -25,7 +25,7 @@ import argparse
from sys import exit
from vyos.config import Config
-from vyos.util import run
+from vyos.util import call
parser = argparse.ArgumentParser()
parser.add_argument("-a", "--all", action="store_true", help="Reset all cache")
@@ -41,11 +41,11 @@ if __name__ == '__main__':
exit(0)
if args.all:
- run("rec_control wipe-cache \'.$\'")
+ call("rec_control wipe-cache \'.$\'")
exit(0)
elif args.domain:
- run("rec_control wipe-cache \'{0}$\'".format(args.domain))
+ call("rec_control wipe-cache \'{0}$\'".format(args.domain))
else:
parser.print_help()
diff --git a/src/op_mode/dynamic_dns.py b/src/op_mode/dynamic_dns.py
index d991848ad..405dd9f04 100755
--- a/src/op_mode/dynamic_dns.py
+++ b/src/op_mode/dynamic_dns.py
@@ -21,7 +21,7 @@ import sys
import time
from vyos.config import Config
-from vyos.util import run
+from vyos.util import call
cache_file = r'/var/cache/ddclient/ddclient.cache'
@@ -86,9 +86,9 @@ def show_status():
def update_ddns():
- run('systemctl stop ddclient')
+ call('systemctl stop ddclient')
os.remove(cache_file)
- run('systemctl start ddclient')
+ call('systemctl start ddclient')
def main():
diff --git a/src/op_mode/format_disk.py b/src/op_mode/format_disk.py
index 9d3797f17..df4486bce 100755
--- a/src/op_mode/format_disk.py
+++ b/src/op_mode/format_disk.py
@@ -22,7 +22,9 @@ from datetime import datetime
from time import sleep
from vyos.util import is_admin, ask_yes_no
-from vyos.util import run, cmd, DEVNULL
+from vyos.util import call
+from vyos.util import cmd
+from vyos.util import DEVNULL
def list_disks():
disks = set()
@@ -36,7 +38,7 @@ def list_disks():
def is_busy(disk: str):
"""Check if given disk device is busy by re-reading it's partition table"""
- return run(f'sudo blockdev --rereadpt /dev/{disk}', stderr=DEVNULL) != 0
+ return call(f'sudo blockdev --rereadpt /dev/{disk}', stderr=DEVNULL) != 0
def backup_partitions(disk: str):
diff --git a/src/op_mode/powerctrl.py b/src/op_mode/powerctrl.py
index 772bb8198..0f3619411 100755
--- a/src/op_mode/powerctrl.py
+++ b/src/op_mode/powerctrl.py
@@ -21,7 +21,9 @@ import re
from datetime import datetime, timedelta, time as type_time, date as type_date
from vyos.util import ask_yes_no
-from vyos.util import cmd, run
+from vyos.util import cmd
+from vyos.util import call
+from vyos.util import run
systemd_sched_file = "/run/systemd/shutdown/scheduled"
@@ -132,7 +134,7 @@ def chk_vyatta_based_reboots():
if os.path.exists(f):
jid = open(f).read().strip()
if jid != 0:
- run(f'sudo atrm {jid}')
+ call(f'sudo atrm {jid}')
os.remove(f)
def main():
diff --git a/src/op_mode/reset_vpn.py b/src/op_mode/reset_vpn.py
index b47212f88..8962df212 100755
--- a/src/op_mode/reset_vpn.py
+++ b/src/op_mode/reset_vpn.py
@@ -19,7 +19,8 @@ import sys
import argparse
#import re
-from vyos.util import run, DEVNULL
+from vyos.util import run
+from vyos.util import DEVNULL
pptp_base = '/usr/bin/accel-cmd -p 2003 terminate {} {}'
l2tp_base = '/usr/bin/accel-cmd -p 2004 terminate {} {}'
diff --git a/src/op_mode/restart_dhcp_relay.py b/src/op_mode/restart_dhcp_relay.py
index 057b4dcd8..66dc435b3 100755
--- a/src/op_mode/restart_dhcp_relay.py
+++ b/src/op_mode/restart_dhcp_relay.py
@@ -23,7 +23,7 @@ import argparse
import os
import vyos.config
-from vyos.util import run
+from vyos.util import call
parser = argparse.ArgumentParser()
@@ -39,7 +39,7 @@ if __name__ == '__main__':
if not c.exists_effective('service dhcp-relay'):
print("DHCP relay service not configured")
else:
- run('sudo systemctl restart isc-dhcp-relay.service')
+ call('sudo systemctl restart isc-dhcp-relay.service')
sys.exit(0)
elif args.ipv6:
@@ -47,7 +47,7 @@ if __name__ == '__main__':
if not c.exists_effective('service dhcpv6-relay'):
print("DHCPv6 relay service not configured")
else:
- run('sudo systemctl restart isc-dhcpv6-relay.service')
+ call('sudo systemctl restart isc-dhcpv6-relay.service')
sys.exit(0)
else:
diff --git a/src/op_mode/restart_frr.py b/src/op_mode/restart_frr.py
index 6304e72db..d1b66b33f 100755
--- a/src/op_mode/restart_frr.py
+++ b/src/op_mode/restart_frr.py
@@ -22,7 +22,7 @@ from logging.handlers import SysLogHandler
from pathlib import Path
import psutil
-from vyos.util import run
+from vyos.util import call
# some default values
watchfrr = '/usr/lib/frr/watchfrr.sh'
@@ -87,7 +87,7 @@ def _write_config():
Path(frrconfig_tmp).mkdir(parents=False, exist_ok=True)
# save frr.conf to it
command = "{} -n -w --config_dir {} 2> /dev/null".format(vtysh, frrconfig_tmp)
- return_code = run(command)
+ return_code = call(command)
if not return_code == 0:
logger.error("Failed to save active config: \"{}\" returned exit code: {}".format(command, return_code))
return False
@@ -109,7 +109,7 @@ def _cleanup():
# check if daemon is running
def _daemon_check(daemon):
command = "{} print_status {}".format(watchfrr, daemon)
- return_code = run(command)
+ return_code = call(command)
if not return_code == 0:
logger.error("Daemon \"{}\" is not running".format(daemon))
return False
@@ -120,7 +120,7 @@ def _daemon_check(daemon):
# restart daemon
def _daemon_restart(daemon):
command = "{} restart {}".format(watchfrr, daemon)
- return_code = run(command)
+ return_code = call(command)
if not return_code == 0:
logger.error("Failed to restart daemon \"{}\"".format(daemon))
return False
@@ -136,7 +136,7 @@ def _reload_config(daemon):
else:
command = "{} -n -b --config_dir {} 2> /dev/null".format(vtysh, frrconfig_tmp)
- return_code = run(command)
+ return_code = call(command)
if not return_code == 0:
logger.error("Failed to reinstall configuration")
return False
diff --git a/src/op_mode/show_acceleration.py b/src/op_mode/show_acceleration.py
index 05d3d8906..6d44b0f66 100755
--- a/src/op_mode/show_acceleration.py
+++ b/src/op_mode/show_acceleration.py
@@ -21,7 +21,8 @@ import re
import argparse
from vyos.config import Config
-from vyos.util import popen, run
+from vyos.util import popen
+from vyos.util import call
def detect_qat_dev():
@@ -43,7 +44,7 @@ def show_qat_status():
sys.exit(1)
# Show QAT service
- run('sudo /etc/init.d/vyos-qat-utilities status')
+ call('sudo /etc/init.d/vyos-qat-utilities status')
# Return QAT devices
def get_qat_devices():
@@ -94,20 +95,20 @@ args = parser.parse_args()
if args.hw:
detect_qat_dev()
# Show availible Intel QAT devices
- run('sudo lspci -nn | egrep -e \'8086:37c8|8086:19e2|8086:0435|8086:6f54\'')
+ call('sudo lspci -nn | egrep -e \'8086:37c8|8086:19e2|8086:0435|8086:6f54\'')
elif args.flow and args.dev:
check_qat_if_conf()
- run('sudo cat '+get_qat_proc_path(args.dev)+"fw_counters")
+ call('sudo cat '+get_qat_proc_path(args.dev)+"fw_counters")
elif args.interrupts:
check_qat_if_conf()
# Delete _dev from args.dev
- run('sudo cat /proc/interrupts | grep qat')
+ call('sudo cat /proc/interrupts | grep qat')
elif args.status:
check_qat_if_conf()
show_qat_status()
elif args.conf and args.dev:
check_qat_if_conf()
- run('sudo cat '+get_qat_proc_path(args.dev)+"dev_cfg")
+ call('sudo cat '+get_qat_proc_path(args.dev)+"dev_cfg")
elif args.dev_list:
get_qat_devices()
else:
diff --git a/src/op_mode/show_dhcp.py b/src/op_mode/show_dhcp.py
index 4e3e08263..a79033f69 100755
--- a/src/op_mode/show_dhcp.py
+++ b/src/op_mode/show_dhcp.py
@@ -27,7 +27,7 @@ from datetime import datetime
from isc_dhcp_leases import Lease, IscDhcpLeases
from vyos.config import Config
-from vyos.util import run
+from vyos.util import call
lease_file = "/config/dhcpd.leases"
@@ -193,7 +193,7 @@ if __name__ == '__main__':
sys.exit(0)
# if dhcp server is down, inactive leases may still be shown as active, so warn the user.
- if run('systemctl -q is-active isc-dhcpv4-server.service') != 0:
+ if call('systemctl -q is-active isc-dhcpv4-server.service') != 0:
print("WARNING: DHCP server is configured but not started. Data may be stale.")
if args.leases:
diff --git a/src/op_mode/show_dhcpv6.py b/src/op_mode/show_dhcpv6.py
index 4ef4849ff..18baa5517 100755
--- a/src/op_mode/show_dhcpv6.py
+++ b/src/op_mode/show_dhcpv6.py
@@ -27,7 +27,7 @@ from datetime import datetime
from isc_dhcp_leases import Lease, IscDhcpLeases
from vyos.config import Config
-from vyos.util import run
+from vyos.util import call
lease_file = "/config/dhcpdv6.leases"
pool_key = "shared-networkname"
@@ -179,7 +179,7 @@ if __name__ == '__main__':
sys.exit(0)
# if dhcp server is down, inactive leases may still be shown as active, so warn the user.
- if run('systemctl -q is-active isc-dhcpv6-server.service') != 0:
+ if call('systemctl -q is-active isc-dhcpv6-server.service') != 0:
print("WARNING: DHCPv6 server is configured but not started. Data may be stale.")
if args.leases:
diff --git a/src/op_mode/snmp.py b/src/op_mode/snmp.py
index b09eab97f..5fae67881 100755
--- a/src/op_mode/snmp.py
+++ b/src/op_mode/snmp.py
@@ -24,7 +24,7 @@ import sys
import argparse
from vyos.config import Config
-from vyos.util import run
+from vyos.util import call
config_file_daemon = r'/etc/snmp/snmpd.conf'
@@ -54,7 +54,7 @@ def show_all():
def show_community(c, h):
print('Status of SNMP community {0} on {1}'.format(c, h), flush=True)
- run('/usr/bin/snmpstatus -t1 -v1 -c {0} {1}'.format(c, h))
+ call('/usr/bin/snmpstatus -t1 -v1 -c {0} {1}'.format(c, h))
if __name__ == '__main__':
args = parser.parse_args()
diff --git a/src/op_mode/version.py b/src/op_mode/version.py
index 34eca44b1..fe6ecbae5 100755
--- a/src/op_mode/version.py
+++ b/src/op_mode/version.py
@@ -30,7 +30,9 @@ import pystache
import vyos.version
import vyos.limericks
-from vyos.util import cmd, run
+from vyos.util import cmd
+from vyos.util import call
+from vyos.util import run
parser = argparse.ArgumentParser()
@@ -119,7 +121,7 @@ if __name__ == '__main__':
if args.all:
print("Package versions:")
- run("dpkg -l")
+ call("dpkg -l")
if args.funny:
print(vyos.limericks.get_random())