X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=xenserver%2Fusr_share_openvswitch_scripts_ovs-xapi-sync;h=f458654468917f56361bc4e5f9c357c66ed5061d;hb=1b0fdca5faa8674a5e67f7435a43b361fca003cf;hp=7109609ecc52f6b22a924b0c25075137509ca719;hpb=b54bdbe993b89829aa33b7a207c61274b953faa5;p=sliver-openvswitch.git diff --git a/xenserver/usr_share_openvswitch_scripts_ovs-xapi-sync b/xenserver/usr_share_openvswitch_scripts_ovs-xapi-sync index 7109609ec..f45865446 100755 --- a/xenserver/usr_share_openvswitch_scripts_ovs-xapi-sync +++ b/xenserver/usr_share_openvswitch_scripts_ovs-xapi-sync @@ -40,6 +40,7 @@ import ovs.util import ovs.daemon import ovs.db.idl +root_prefix = '' # Prefix for absolute file names, for testing. s_log = logging.getLogger("ovs-xapi-sync") vsctl = "/usr/bin/ovs-vsctl" session = None @@ -59,9 +60,9 @@ def init_session(): try: session = XenAPI.xapi_local() session.xenapi.login_with_password("", "") - except: + except XenAPI.Failure, e: session = None - s_log.warning("Couldn't login to XAPI") + s_log.warning("Couldn't login to XAPI (%s)" % e) return False return True @@ -218,8 +219,10 @@ def usage(): print "usage: %s [OPTIONS] DATABASE" % sys.argv[0] print "where DATABASE is a socket on which ovsdb-server is listening." ovs.daemon.usage() - print "Other options:" - print " -h, --help display this help message" + print """\ +Other options: + --root-prefix=DIR Use DIR as alternate root directory (for testing). + -h, --help display this help message""" sys.exit(0) @@ -232,16 +235,21 @@ def handler(signum, _): def main(argv): global force_run - l_handler = logging.handlers.RotatingFileHandler( + s_log.addHandler(logging.StreamHandler()) + try: + l_handler = logging.handlers.RotatingFileHandler( "/var/log/openvswitch/ovs-xapi-sync.log") - l_formatter = logging.Formatter('%(filename)s: %(levelname)s: %(message)s') - l_handler.setFormatter(l_formatter) - s_log.addHandler(l_handler) + l_formatter = logging.Formatter('%(filename)s: %(levelname)s: %(message)s') + l_handler.setFormatter(l_formatter) + s_log.addHandler(l_handler) + except IOError, e: + logging.basicConfig() + s_log.warn("failed to open logfile (%s)" % e) s_log.setLevel(logging.INFO) try: options, args = getopt.gnu_getopt( - argv[1:], 'h', ['help'] + ovs.daemon.LONG_OPTIONS) + argv[1:], 'h', ['help', 'root-prefix='] + ovs.daemon.LONG_OPTIONS) except getopt.GetoptError, geo: sys.stderr.write("%s: %s\n" % (ovs.util.PROGRAM_NAME, geo.msg)) sys.exit(1) @@ -249,6 +257,9 @@ def main(argv): for key, value in options: if key in ['-h', '--help']: usage() + elif key == '--root-prefix': + global root_prefix + root_prefix = value elif not ovs.daemon.parse_opt(key, value): sys.stderr.write("%s: unhandled option %s\n" % (ovs.util.PROGRAM_NAME, key)) @@ -269,7 +280,8 @@ def main(argv): # This daemon is usually started before XAPI, but to complete our # tasks, we need it. Wait here until it's up. - while not os.path.exists("/var/run/xapi_init_complete.cookie"): + cookie_file = root_prefix + "/var/run/xapi_init_complete.cookie" + while not os.path.exists(cookie_file): time.sleep(1) signal.signal(signal.SIGHUP, handler)