コード例 #1
0
def destroy_guest():
    cmd = """
    virsh destroy gg
    virsh undefine gg
    """
    run(cmd)
    return 0
コード例 #2
0
def start_guest(guest_xml):
    with pushd(case_path):
        run("systemctl list-units --state=stop --type=service | grep libvirtd || systemctl restart libvirtd")
        download_VNF_image()
        cmd = f"""
        virsh define {case_path}/{guest_xml}
        virsh start gg
        """
        run(cmd)
    return 0
コード例 #3
0
def ovs_bridge_with_kernel(nic1_name, nic2_name):
    cmd = f"""
	modprobe openvswitch
	systemctl stop openvswitch
	sleep 3
	systemctl start openvswitch
	sleep 3
	ovs-vsctl --if-exists del-br ovsbr0
	sleep 5

    ovs-vsctl set Open_vSwitch . other_config={{}}
	systemctl restart openvswitch

    ovs-vsctl --timeout 10 add-br ovsbr0
    ovs-vsctl --timeout 10 set Open_vSwitch . other_config:max-idle=30000

    ip addr flush dev {nic1_name}
    ip link set dev {nic1_name} up
    ovs-vsctl --timeout 10 add-port ovsbr0 {nic1_name}
    
    ip addr flush dev {nic2_name}
    ip link set dev {nic2_name} up
    ovs-vsctl --timeout 10 add-port ovsbr0 {nic2_name}
    
    ip tuntap del tap0 mode tap
    ip tuntap add tap0 mode tap
    ip addr flush dev tap0
    ip link set dev tap0 up
    ovs-vsctl --timeout 10 add-port ovsbr0 tap0
    
    ip tuntap del tap1 mode tap
    ip tuntap add tap1 mode tap
    ip addr flush dev tap1
    ip link set dev tap1 up
    ovs-vsctl --timeout 10 add-port ovsbr0 tap1

    ovs-vsctl set Interface {nic1_name}  ofport_request=1
    ovs-vsctl set Interface {nic2_name}  ofport_request=2
    ovs-vsctl set Interface tap0 ofport_request=3
    ovs-vsctl set Interface tap1 ofport_request=4

    ovs-ofctl -O OpenFlow13 --timeout 10 del-flows ovsbr0 
    ovs-ofctl -O OpenFlow13 --timeout 10 add-flow ovsbr0 in_port=1,idle_timeout=0,action=output:3
    ovs-ofctl -O OpenFlow13 --timeout 10 add-flow ovsbr0 in_port=3,idle_timeout=0,action=output:1
    ovs-ofctl -O OpenFlow13 --timeout 10 add-flow ovsbr0 in_port=4,idle_timeout=0,action=output:2
    ovs-ofctl -O OpenFlow13 --timeout 10 add-flow ovsbr0 in_port=2,idle_timeout=0,action=output:4

	sleep 2
	ovs-vsctl show
    """
    run(cmd)
    return 0
コード例 #4
0
def clear_env():
    cmd = """
    systemctl start openvswitch
    ovs-vsctl --if-exists del-br ovsbr0
    virsh destroy gg
    virsh undefine gg
    systemctl stop openvswitch
    ip tuntap del tap0 mode tap
    ip tuntap del tap1 mode tap
    """
    run(cmd,"0,1")
    clear_dpdk_interface()
    clear_hugepage()
    # log_and_run("ip link show")
    log_and_run("sleep 10")
    log_and_run("ip link show")
    return 0
コード例 #5
0
def ovs_bridge_with_dpdk_with_mac(nic1_mac, nic2_mac, mtu_val, pmd_cpu_mask):
    cmd = f"""
	modprobe openvswitch
	systemctl stop openvswitch
	sleep 3
	systemctl start openvswitch
	sleep 3
	ovs-vsctl --if-exists del-br ovsbr0
	sleep 5

	ovs-vsctl set Open_vSwitch . other_config={{}}
	ovs-vsctl --no-wait set Open_vSwitch . other_config:dpdk-init=true
	ovs-vsctl --no-wait set Open_vSwitch . other_config:dpdk-socket-mem="4096,4096"
	ovs-vsctl set Open_vSwitch . other_config:pmd-cpu-mask="{pmd_cpu_mask}"
    ovs-vsctl --no-wait set Open_vSwitch . other_config:vhost-iommu-support=true
	systemctl restart openvswitch
	sleep 3
	ovs-vsctl add-br ovsbr0 -- set bridge ovsbr0 datapath_type=netdev

    ovs-vsctl add-port ovsbr0 dpdk0 -- set Interface dpdk0 type=dpdk options:dpdk-devargs="class=eth,mac={nic1_mac}" mtu_request={mtu_val}
    ovs-vsctl add-port ovsbr0 dpdk1 -- set Interface dpdk1 type=dpdk options:dpdk-devargs="class=eth,mac={nic2_mac}" mtu_request={mtu_val}

    ovs-vsctl add-port ovsbr0 vhost0 -- set interface vhost0 type=dpdkvhostuserclient options:vhost-server-path=/tmp/vhost0 mtu_request={mtu_val}
    ovs-vsctl add-port ovsbr0 vhost1 -- set interface vhost1 type=dpdkvhostuserclient options:vhost-server-path=/tmp/vhost1 mtu_request={mtu_val}

    ovs-vsctl set Interface dpdk0  ofport_request=1
    ovs-vsctl set Interface dpdk1  ofport_request=2
    ovs-vsctl set Interface vhost0 ofport_request=3
    ovs-vsctl set Interface vhost1 ofport_request=4

    ovs-ofctl del-flows ovsbr0
    /usr/bin/ovs-ofctl -O OpenFlow13 --timeout 10 add-flow ovsbr0 idle_timeout=0,in_port=1,action=output:3
    /usr/bin/ovs-ofctl -O OpenFlow13 --timeout 10 add-flow ovsbr0 idle_timeout=0,in_port=3,action=output:1
    /usr/bin/ovs-ofctl -O OpenFlow13 --timeout 10 add-flow ovsbr0 idle_timeout=0,in_port=2,action=output:4
    /usr/bin/ovs-ofctl -O OpenFlow13 --timeout 10 add-flow ovsbr0 idle_timeout=0,in_port=4,action=output:2
	#ovs-ofctl add-flow ovsbr0 actions=NORMAL

	sleep 2
	ovs-vsctl show
    """
    run(cmd)
    return 0
コード例 #6
0
def check_install(pkg_name):
    run("rpm -q {} || yum -y install {}".format(pkg_name, pkg_name))
    pass
コード例 #7
0
def py3_run(cmd,str_ret_val="0"):
    run(f"source {case_path}/venv/bin/activate")
    run(cmd,str_ret_val)
    run("deactivate")
    pass