From b0b0ef24cd169ac16fdb3c5364cebb174bd8b84c Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Tue, 23 Sep 2014 17:32:52 +0200 Subject: [PATCH] tweak privatebridge to remove exception message when ovs is not installed - prints out warning instead --- plugins/privatebridge.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/plugins/privatebridge.py b/plugins/privatebridge.py index 263cf79..72bff53 100644 --- a/plugins/privatebridge.py +++ b/plugins/privatebridge.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python """ Private Bridge configurator. """ @@ -60,11 +60,24 @@ def log_call_read(command,timeout=logger.default_timeout_minutes*60,poll=1): logger.log("log_call:end terminating command (%s) - exceeded timeout %d s"%(message,timeout)) return (-2, None) break - except: - logger.log_exc("failed to run command %s" % message) + except Exception as e: + logger.log_exc("failed to run command %s -> %s" % (message,e)) return (-1, None) +### Thierry - 23 Sept 2014 +# regardless of this being shipped on lxc-only or on all nodes, +# it is safer to check for the availability of the ovs-vsctl command and just print +# out a warning when it's not there, instead of a nasty traceback +def ovs_available (): + "return True if ovs-vsctl can be run" + try: + child = subprocess.Popen (['ovs-ovsctl', '--help']) + child.communicate() + return True + except: + return False + def ovs_vsctl(args): return log_call_read(["ovs-vsctl"] + args) @@ -150,6 +163,11 @@ def configure_slicebridge(sliver, attributes): ensure_slicebridge_neighbors(slice_bridge_name, sliver_id, slice_bridge_neighbors) def GetSlivers(data, conf = None, plc = None): + + if not ovs_available(): + logger.log ("privatebridge: warning, ovs-vsctl not found - exiting") + return + node_id = tools.node_id() if 'slivers' not in data: -- 2.43.0