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
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
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)
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)
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))
# 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)