From c621ce83e89dea5d7c1a19d0d802d6406d406ca5 Mon Sep 17 00:00:00 2001 From: Nic Boet Date: Sun, 2 Apr 2023 11:07:46 -0500 Subject: [PATCH] improve view exception Signed-off-by: Nic Boet --- update-zonefile.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/update-zonefile.py b/update-zonefile.py index a85b0d6..f2094fb 100755 --- a/update-zonefile.py +++ b/update-zonefile.py @@ -221,17 +221,25 @@ def check_zone(origin, zonefile): return r == 0 def rndc_reload(cmd): - r = subprocess.call(cmd) - if r != 0: - raise Exception('rndc failed with return code {}'.format(r)) + try: + r = subprocess.check_output(cmd, stderr=subprocess.PIPE) + + except subprocess.CalledProcessError as e: + print( '{}'.format( e.stderr.decode(sys.getfilesystemencoding()) ) ) + if "multiple" in e.stderr.decode('utf-8'): + sys.exit('Please pass --views the list of configured BIND views containing origin zone.') + if e.returncode != 0: + sys.exit('rndc failed with return code {}'.format(e.returncode)) + + print( '{}'.format( r.decode(sys.getfilesystemencoding()) ) ) def reload_zone(origin, views): if views: for v in views.split(): - print (f"view {v}, {origin} ", end='', flush=True) + print ("view {}, {} ".format(v, origin), end='', flush=True) rndc_reload( ['rndc', 'reload', origin, "IN", v] ) else: - print (f"{origin} ", end='', flush=True) + print ("{} ".format(origin), end='', flush=True) rndc_reload( ['rndc', 'reload', origin] ) def is_exe(fpath):