def __init__(self, configfile=None): if configfile is None: if os.path.exists(CONF_FILE): configfile = CONF_FILE else: configfile = find_config(os.path.abspath( os.path.dirname(__file__))) if configfile is None: raise Exception("Configuration file \"%s\" doesn't exist" % (configfile)) LOG.debug("Using configuration file: %s" % configfile) conf = config.parse(configfile) options = {"sql_connection": conf.DATABASE.sql_connection} reconnect_interval = conf.DATABASE.reconnect_interval options.update({"reconnect_interval": reconnect_interval}) db.configure_db(options) self.vmap = VlanMap() # Populate the map with anything that is already present in the # database vlans = ovs_db.get_vlans() for x in vlans: vlan_id, network_id = x LOG.debug("Adding already populated vlan %s -> %s" % (vlan_id, network_id)) self.vmap.already_used(vlan_id, network_id)
def test_defaults(self): configs = """ """ (fd, path) = tempfile.mkstemp(prefix='ovs_config', suffix='.ini') try: os.write(fd, configs) os.close(fd) conf = config.parse(path) self.assertFalse(conf.OVS.enable_tunneling) self.assertEqual('br-int', conf.OVS.integration_bridge) self.assertEqual('br-tun', conf.OVS.tunnel_bridge) self.assertEqual('sqlite://', conf.DATABASE.sql_connection) self.assertEqual(-1, conf.DATABASE.sql_max_retries) self.assertEqual(2, conf.DATABASE.reconnect_interval) self.assertEqual(2, conf.AGENT.polling_interval) self.assertEqual('sudo', conf.AGENT.root_helper) self.assertEqual(conf.DATABASE.sql_connection, cfg.CONF.DATABASE.sql_connection) self.assertEqual(conf.AGENT.root_helper, cfg.CONF.AGENT.root_helper) finally: os.remove(path)
def __init__(self, configfile=None): if configfile is None: if os.path.exists(CONF_FILE): configfile = CONF_FILE else: configfile = find_config( os.path.abspath(os.path.dirname(__file__))) if configfile is None: raise Exception("Configuration file \"%s\" doesn't exist" % (configfile)) LOG.debug("Using configuration file: %s" % configfile) conf = config.parse(configfile) options = {"sql_connection": conf.DATABASE.sql_connection} reconnect_interval = conf.DATABASE.reconnect_interval options.update({"reconnect_interval": reconnect_interval}) db.configure_db(options) vlan_min = conf.OVS.vlan_min vlan_max = conf.OVS.vlan_max if vlan_min > vlan_max: LOG.warn("Using default VLAN values! vlan_min = %s is larger" " than vlan_max = %s!" % (vlan_min, vlan_max)) vlan_min = 1 vlan_max = 4094 self.vmap = VlanMap(vlan_min, vlan_max) # Populate the map with anything that is already present in the # database vlans = ovs_db.get_vlans() for x in vlans: vlan_id, network_id = x LOG.debug("Adding already populated vlan %s -> %s" % (vlan_id, network_id)) self.vmap.already_used(vlan_id, network_id)
def test_tunnel(self): configs = """[DATABASE] sql_connection = testlink reconnect_interval=100 [OVS] enable_tunneling = True integration_bridge = mybrint tunnel_bridge = mybrtun local_ip = 10.0.0.3 [AGENT] root_helper = mysudo polling_interval=50 """ (fd, path) = tempfile.mkstemp(prefix='ovs_config', suffix='.ini') try: os.write(fd, configs) os.close(fd) conf = config.parse(path) self.assertTrue(conf.OVS.enable_tunneling) self.assertEqual('mybrint', conf.OVS.integration_bridge) self.assertEqual('mybrtun', conf.OVS.tunnel_bridge) self.assertEqual('testlink', conf.DATABASE.sql_connection) self.assertEqual(100, conf.DATABASE.reconnect_interval) self.assertEqual(50, conf.AGENT.polling_interval) self.assertEqual('mysudo', conf.AGENT.root_helper) finally: os.remove(path)
def main(): usagestr = "%prog [OPTIONS] <config file>" parser = OptionParser(usage=usagestr) parser.add_option("-v", "--verbose", dest="verbose", action="store_true", default=False, help="turn on verbose logging") options, args = parser.parse_args() if options.verbose: LOG.setLevel(logging.DEBUG) else: LOG.setLevel(logging.WARNING) if len(args) != 1: parser.print_help() sys.exit(1) config_file = args[0] conf = config.parse(config_file) if conf.AGENT.log_file: # Avoid to redirect traces to stdout/stderr logging.getLogger().handlers = [] handler = logging.FileHandler(conf.AGENT.log_file) formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s') handler.setFormatter(formatter) LOG.addHandler(handler) LOG.debug('Verbose: %s', options.verbose) # Determine which agent type to use. enable_tunneling = conf.OVS.enable_tunneling integ_br = conf.OVS.integration_bridge db_connection_url = conf.DATABASE.sql_connection polling_interval = conf.AGENT.polling_interval reconnect_interval = conf.DATABASE.reconnect_interval root_helper = conf.AGENT.root_helper # Determine API Version to use target_v2_api = conf.AGENT.target_v2_api if enable_tunneling: # Get parameters for OVSQuantumTunnelAgent tun_br = conf.OVS.tunnel_bridge # Mandatory parameter. local_ip = conf.OVS.local_ip plugin = OVSQuantumTunnelAgent(integ_br, tun_br, local_ip, root_helper, polling_interval, reconnect_interval, target_v2_api) else: # Get parameters for OVSQuantumAgent. plugin = OVSQuantumAgent(integ_br, root_helper, polling_interval, reconnect_interval, target_v2_api) # Start everything. plugin.daemon_loop(db_connection_url) sys.exit(0)
def __init__(self, configfile=None): conf = config.parse(CONF_FILE) options = {"sql_connection": conf.DATABASE.sql_connection} options.update({'base': models_v2.model_base.BASEV2}) reconnect_interval = conf.DATABASE.reconnect_interval options.update({"reconnect_interval": reconnect_interval}) db.configure_db(options) self.vmap = VlanMap(conf.OVS.vlan_min, conf.OVS.vlan_max) self.vmap.populate_already_used(ovs_db_v2.get_vlans())
def __init__(self, configfile=None): conf = config.parse(CONF_FILE) options = {"sql_connection": conf.DATABASE.sql_connection} reconnect_interval = conf.DATABASE.reconnect_interval options.update({"reconnect_interval": reconnect_interval}) db.configure_db(options) self.vmap = VlanMap(conf.OVS.vlan_min, conf.OVS.vlan_max) # Populate the map with anything that is already present in the # database self.vmap.populate_already_used(ovs_db.get_vlans())
def test_without_tunnel(self): configs = """ [OVS] enable_tunneling = False """ (fd, path) = tempfile.mkstemp(prefix='ovs_config', suffix='.ini') try: os.write(fd, configs) os.close(fd) conf = config.parse(path) self.assertFalse(conf.OVS.enable_tunneling) finally: os.remove(path)
def main(): usagestr = "%prog [OPTIONS] <config file>" parser = OptionParser(usage=usagestr) parser.add_option("-v", "--verbose", dest="verbose", action="store_true", default=False, help="turn on verbose logging") options, args = parser.parse_args() if options.verbose: LOG.setLevel(logging.DEBUG) else: LOG.setLevel(logging.WARNING) if len(args) != 1: parser.print_help() sys.exit(1) config_file = args[0] conf = config.parse(config_file) # Determine which agent type to use. enable_tunneling = conf.OVS.enable_tunneling integ_br = conf.OVS.integration_bridge db_connection_url = conf.DATABASE.sql_connection polling_interval = conf.AGENT.polling_interval reconnect_interval = conf.DATABASE.reconnect_interval root_helper = conf.AGENT.root_helper if enable_tunneling: # Get parameters for OVSQuantumTunnelAgent tun_br = conf.OVS.tunnel_bridge # Mandatory parameter. local_ip = conf.OVS.local_ip plugin = OVSQuantumTunnelAgent(integ_br, tun_br, local_ip, root_helper, polling_interval, reconnect_interval) else: # Get parameters for OVSQuantumAgent. plugin = OVSQuantumAgent(integ_br, root_helper, polling_interval, reconnect_interval) # Start everything. plugin.daemon_loop(db_connection_url) sys.exit(0)
def test_invalid_values(self): configs = """ [OVS] enable_tunneling = notbool """ (fd, path) = tempfile.mkstemp(prefix='ovs_config', suffix='.ini') try: os.write(fd, configs) os.close(fd) conf = config.parse(path) exception_raised = False try: tunnel = conf.OVS.enable_tunneling except ConfigFileValueError: exception_raised = True self.assertTrue(exception_raised) finally: os.remove(path)
def test_defaults(self): configs = """ """ (fd, path) = tempfile.mkstemp(prefix='ovs_config', suffix='.ini') try: os.write(fd, configs) os.close(fd) conf = config.parse(path) self.assertFalse(conf.OVS.enable_tunneling) self.assertEqual('br-int', conf.OVS.integration_bridge) self.assertEqual('br-tun', conf.OVS.tunnel_bridge) self.assertEqual('sqlite://', conf.DATABASE.sql_connection) self.assertEqual(2, conf.DATABASE.reconnect_interval) self.assertEqual(2, conf.AGENT.polling_interval) self.assertEqual('sudo', conf.AGENT.root_helper) finally: os.remove(path)