Comment 1 for bug 1776923

Revision history for this message
Bernhard Koessler (bkoessler) wrote :

to solve vourter provisioning in a multi-interface setup with specific routes I did the following hacks which leads to a working vrouter:

--- ../contrail_agent_utils.py.orig 2018-06-13 12:11:10.645817961 +0000
+++ contrail-charms/contrail-agent/hooks/contrail_agent_utils.py 2018-06-15 12:22:05.564341326 +0000
@@ -102,12 +102,33 @@

 def _get_iface_gateway_ip(iface):
- if hasattr(netifaces, "gateways"):
- data = netifaces.gateways()["default"][netifaces.AF_INET]
- return data[0] if data[1] == iface else None
-
- data = check_output("ip route | grep ^default", shell=True).split()
- return data[2] if data[4] == iface else None
+ for line in check_output(["route", "-n"]).splitlines()[2:]:
+ l = line.split()
+ if "G" in l[3] and ( l[7] == VROUTER_INTERFACE or l[7] == iface ):
+ log("Found gateway {} for interface {}".format(l[1], l[7]))
+ return l[1]
+ log("No gateway could be determined from routing table")
+ return None
+
+
+def _get_routes(iface):
+ routes = []
+ for line in check_output(["route", "-n"]).splitlines()[2:]:
+ route = []
+ l = line.split()
+ if "G" in l[3] and ( l[7] == VROUTER_INTERFACE or l[7] == iface ):
+ log("Found route {} {} via gw {} for interface {}".format(l[0], l[2], l[1], l[7]))
+ route = [ l[0], l[1], l[2] ]
+ routes.append(route)
+ return routes
+
+def _set_routes(routes):
+ for route in routes:
+ args = [ "route", "add", "-net", route[0], "netmask", route[2], "gw", route[1] ]
+ try:
+ check_call(args)
+ except Exception as e:
+ log("Could not add route {} {} via {}, error: {}".format(route[0], route[2], route[1], str(e)))

 def _vhost_cidr(iface):
@@ -139,6 +160,8 @@
         gateway_ip = _get_iface_gateway_ip(iface)
     config["vhost-gateway-ip"] = gateway_ip

+ routes = _get_routes(iface)
+
     if config["dpdk"]:
         fs = os.path.realpath("/sys/class/net/" + iface).split("/")
         # NOTE: why it's not an error?
@@ -154,6 +177,8 @@
         render("agent_param", "/etc/contrail/agent_param",
                {"interface": iface})

+ _set_routes(routes)
+

 def drop_caches():
     """Clears OS pagecache"""
@@ -184,8 +209,7 @@
     ready = (
         config.get("api_port")
         and (config.get("api_ip") or config.get("api_vip"))
- and config.get("analytics_servers")
- and info.get("cloud_orchestrator"))
+ and config.get("analytics_servers"))
     if config.get("vrouter-expected-provision-state"):
         if ready and not config.get("vrouter-provisioned"):
             try: