def add_chassis_node(self, fake_multinode_args={}, iteration=0): node_net = fake_multinode_args.get("node_net") node_net_len = fake_multinode_args.get("node_net_len") node_cidr = netaddr.IPNetwork("{}/{}".format(node_net, node_net_len)) node_ip = str(node_cidr.ip + iteration + 1) ovn_fake_path = fake_multinode_args.get("cluster_cmd_path") sandbox = self.sandboxes[iteration % len(self.sandboxes)] print("***** adding %s controller *****" % sandbox["name"]) if fake_multinode_args.get("ovn_monitor_all"): monitor_cmd = "OVN_MONITOR_ALL=yes" else: monitor_cmd = "OVN_MONITOR_ALL=no" if fake_multinode_args.get("ovn_cluster_db"): cluster_db_cmd = "OVN_DB_CLUSTER=yes" else: cluster_db_cmd = "OVN_DB_CLUSTER=no" cmd = "cd {} && IP_HOST={} IP_CIDR={} IP_START={} {} {} ./ovn_cluster.sh add-chassis {} {}".format( ovn_fake_path, node_net, node_net_len, node_ip, monitor_cmd, cluster_db_cmd, sandbox["name"], "tcp:0.0.0.1:6642") client = ovn_utils.RemoteConn(ssh=sandbox["ssh"], log=self.log) client.run(cmd)
def add_central(self, fake_multinode_args={}, nbctld_config={}): print("***** creating central node *****") node_net = fake_multinode_args.get("node_net") node_net_len = fake_multinode_args.get("node_net_len") node_ip = fake_multinode_args.get("node_ip") ovn_fake_path = fake_multinode_args.get("cluster_cmd_path") if fake_multinode_args.get("ovn_monitor_all"): monitor_cmd = "OVN_MONITOR_ALL=yes" else: monitor_cmd = "OVN_MONITOR_ALL=no" if fake_multinode_args.get("ovn_cluster_db"): cluster_db_cmd = "OVN_DB_CLUSTER=yes" else: cluster_db_cmd = "OVN_DB_CLUSTER=no" cmd = "cd {} && CHASSIS_COUNT=0 GW_COUNT=0 IP_HOST={} IP_CIDR={} IP_START={} {} {} CREATE_FAKE_VMS=no ./ovn_cluster.sh start".format( ovn_fake_path, node_net, node_net_len, node_ip, monitor_cmd, cluster_db_cmd) client = ovn_utils.RemoteConn(node=self.controller, log=self.log) client.run(cmd=cmd) if nbctld_config.get("daemon", False): self.nbctl.start_daemon(nbctld_config=nbctld_config) time.sleep(5)
def ping_port(self, lport=None, sandbox=None, wait_timeout_s=20): start_time = datetime.now() client = ovn_utils.RemoteConn(ssh=sandbox["ssh"], container=sandbox["name"], log=self.log) if lport.get("ext-gw"): dest = lport["ext-gw"] else: dest = lport["gw"] while True: try: cmd = "ip netns exec {} ping -q -c 1 -W 0.1 {}".format( lport["name"], dest) client.run(cmd=cmd, raise_on_error=True) break except: pass if (datetime.now() - start_time).seconds > wait_timeout_s: print( "***** Error: Timeout waiting for port {} to be able to ping gateway {} *****" .format(lport["name"], dest)) # FIXME: we need better error reporting. # raise ovn_utils.OvnPingTimeoutException() break
def add_chassis_node_localnet(self, fake_multinode_args={}, iteration=0): sandbox = self.sandboxes[iteration % len(self.sandboxes)] print("***** creating localnet on %s controller *****" % sandbox["name"]) cmd = "ovs-vsctl -- set open_vswitch . external-ids:ovn-bridge-mappings={}:br-ex".format( fake_multinode_args.get("physnet", "providernet")) client = ovn_utils.RemoteConn(ssh=sandbox["ssh"], container=sandbox["name"], log=self.log) client.run(cmd=cmd)
def connect_chassis_node(self, fake_multinode_args={}, iteration=0): sandbox = self.sandboxes[iteration % len(self.sandboxes)] node_prefix = fake_multinode_args.get("node_prefix", "") print("***** connecting %s controller *****" % sandbox["name"]) central_ip = fake_multinode_args.get("central_ip") sb_proto = fake_multinode_args.get("sb_proto", "ssl") ovn_fake_path = fake_multinode_args.get("cluster_cmd_path") central_ips = [ip.strip() for ip in central_ip.split('-')] remote = ",".join( ["{}:{}:6642".format(sb_proto, r) for r in central_ips]) cmd = "cd {} && ./ovn_cluster.sh set-chassis-ovn-remote {} {}".format( ovn_fake_path, sandbox["name"], remote) client = ovn_utils.RemoteConn(ssh=sandbox["ssh"], log=self.log) client.run(cmd=cmd)
def add_chassis_external_host(self, lnetwork_create_args={}, iteration=0): sandbox = self.sandboxes[iteration % len(self.sandboxes)] cidr = netaddr.IPNetwork(lnetwork_create_args.get('start_ext_cidr')) ext_cidr = cidr.next(iteration) gw_ip = netaddr.IPAddress(ext_cidr.last - 1) host_ip = netaddr.IPAddress(ext_cidr.last - 2) client = ovn_utils.RemoteConn(ssh=sandbox["ssh"], container=sandbox["name"], log=self.log) client.run(cmd="ip link add veth0 type veth peer name veth1") client.run(cmd="ip link add veth0 type veth peer name veth1") client.run(cmd="ip netns add ext-ns") client.run(cmd="ip link set netns ext-ns dev veth0") client.run(cmd="ip netns exec ext-ns ip link set dev veth0 up") client.run( cmd="ip netns exec ext-ns ip addr add {}/{} dev veth0".format( host_ip, ext_cidr.prefixlen)) client.run(cmd="ip netns exec ext-ns ip route add default via {}". format(gw_ip)) client.run(cmd="ip link set dev veth1 up") client.run(cmd="ovs-vsctl add-port br-ex veth1")