summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@vyos.io>2020-06-25 09:22:46 +0300
committerDaniil Baturin <daniil@vyos.io>2020-06-25 09:22:46 +0300
commit9fc8158f98ba7154da9867d9a28f00e39f76d0e0 (patch)
tree0dcb75891ee511c3c5eceb4a9e0f120849d9b3f4
parent39174c079ab5ed824c694b92954b506ffc3dab17 (diff)
downloadvyos-1x-9fc8158f98ba7154da9867d9a28f00e39f76d0e0.tar.gz
vyos-1x-9fc8158f98ba7154da9867d9a28f00e39f76d0e0.zip
T2487: add an exception for the case when VRRP stats aren't available.
-rw-r--r--python/vyos/ifconfig/vrrp.py5
-rwxr-xr-xsrc/op_mode/vrrp.py22
2 files changed, 18 insertions, 9 deletions
diff --git a/python/vyos/ifconfig/vrrp.py b/python/vyos/ifconfig/vrrp.py
index a872725b2..5e6387881 100644
--- a/python/vyos/ifconfig/vrrp.py
+++ b/python/vyos/ifconfig/vrrp.py
@@ -28,6 +28,9 @@ from vyos import util
class VRRPError(Exception):
pass
+class VRRPNoData(VRRPError):
+ pass
+
class VRRP(object):
_vrrp_prefix = '00:00:5E:00:01:'
location = {
@@ -96,6 +99,8 @@ class VRRP(object):
# shoud look for file size change ?
sleep(0.2)
return util.read_file(fname)
+ except FileNotFoundError:
+ raise VRRPNoData("VRRP data is not available (process not running or no active groups)")
except Exception:
name = cls._name[what]
raise VRRPError(f'VRRP {name} is not available')
diff --git a/src/op_mode/vrrp.py b/src/op_mode/vrrp.py
index e024d7f63..2c1db20bf 100755
--- a/src/op_mode/vrrp.py
+++ b/src/op_mode/vrrp.py
@@ -24,7 +24,7 @@ import tabulate
import vyos.util
from vyos.ifconfig.vrrp import VRRP
-from vyos.ifconfig.vrrp import VRRPError
+from vyos.ifconfig.vrrp import VRRPError, VRRPNoData
parser = argparse.ArgumentParser()
@@ -40,12 +40,16 @@ if not VRRP.is_running():
print('VRRP is not running')
sys.exit(0)
-if args.summary:
- print(VRRP.format(VRRP.collect('json')))
-elif args.statistics:
- print(VRRP.collect('stats'))
-elif args.data:
- print(VRRP.collect('state'))
-else:
- parser.print_help()
+try:
+ if args.summary:
+ print(VRRP.format(VRRP.collect('json')))
+ elif args.statistics:
+ print(VRRP.collect('stats'))
+ elif args.data:
+ print(VRRP.collect('state'))
+ else:
+ parser.print_help()
+ sys.exit(1)
+except VRRPNoData as e:
+ print(e)
sys.exit(1)