def bonding_test_trex(t_time,pkt_size,dst_mac_one,dst_mac_two): trex_server_ip = get_env("TRAFFICGEN_TREX_HOST_IP_ADDR") trex_url = get_env("TREX_URL") trex_dir = os.path.basename(trex_url).replace(".tar.gz","") trex_name = os.path.basename(trex_url) #init trex package and lua traffic generator # [ -e trafficgen ] || git clone https://github.com/atheurer/trafficgen.git # [ -e trafficgen ] || git clone https://github.com/wanghekai/trafficgen.git with pushd("/opt"): cmd = fr""" [ -e trafficgen ] || git clone https://github.com/atheurer/trafficgen.git mkdir -p trex pushd trex &>/dev/null [ -f {trex_name} ] || wget -nv -N {trex_url};tar xf {trex_name};ln -sf {trex_dir} current; ls -l; popd &>/dev/null chmod 777 /opt/trex -R """ log_and_run(cmd) pass with pushd(case_path): ret = bash(f"ping {trex_server_ip} -c 3") if ret.code != 0: log("Trex server {} not up please check ".format(trex_server_ip)) pass # cmd = f""" # ./binary-search.py \ # --trex-host={trex_server_ip} \ # --traffic-generator=trex-txrx \ # --frame-size={pkt_size} \ # --dst-macs={dst_mac_one},{dst_mac_two} \ # --traffic-direction=bidirectional \ # --search-granularity=5 \ # --search-runtime={t_time} \ # --validation-runtime=10 \ # --max-loss-pct=0.0 \ # --rate-unit=% \ # --rate=100 # """ # --search-granularity=1 \ with pushd("/opt/trafficgen"): cmd = f""" python ./binary-search.py \ --trex-host={trex_server_ip} \ --traffic-generator=trex-txrx \ --frame-size={pkt_size} \ --traffic-direction=bidirectional \ --search-runtime={t_time} \ --search-granularity=0.5 \ --validation-runtime=10 \ --negative-packet-loss=fail \ --max-loss-pct=0.0 \ --rate-unit=% \ --rate=100 """ log(cmd) py3_run(cmd) return 0
def install_rpms(): with pushd(case_path): all_package = """ yum-utils scl-utils python36 python36-devel python-netifaces python3-pyelftools wget nano ftp git tuna openssl sysstat libvirt libvirt-devel virt-install virt-manager virt-viewer czmq-devel libguestfs-tools ethtool vim lrzip libnl3-devel """.split() for pack in all_package: check_install(pack) bash("systemctl restart libvirtd") return 0
def vcpupin_in_xml(numa_node, template_xml, new_xml, cpu_list): with pushd(case_path): config_file_checks() local.path(template_xml).copy(new_xml) xml_tool.xml_add_vcpupin_item(new_xml, len(cpu_list)) xml_tool.update_numa(new_xml,numa_node) for i in range(len(cpu_list)): xml_tool.update_vcpu(new_xml, i, cpu_list[i]) return 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
def config_file_checks(): log("*** Checking Config File ***") with pushd(case_path): str_all_name = """ NIC1 NIC2 PMD_CPU_1 PMD_CPU_2 PMD_CPU_3 PMD_CPU_4 VCPU1 VCPU2 VCPU3 VCPU4 VCPU5 TXD_SIZE RXD_SIZE SRIOV_TXD_SIZE SRIOV_RXD_SIZE TRAFFICGEN_TREX_HOST_IP_ADDR TRAFFICGEN_TREX_PORT1 TRAFFICGEN_TREX_PORT2 NIC1_VF NIC2_VF ONE_QUEUE_IMAGE TWO_QUEUE_IMAGE DPDK_VER DPDK_URL DPDK_TOOL_URL TREX_URL """.split() for name in str_all_name: if False == check_env_var(name): log(f"Please set the config Var {name} in Perf-Verify.conf file") return 1 return 0
def download_VNF_image(): cmd = f""" chmod 777 {image_dir} """ log_and_run(cmd) with pushd(case_path): one_queue_image = get_env("ONE_QUEUE_IMAGE") two_queue_image = get_env("TWO_QUEUE_IMAGE") one_queue_image_name = os.path.basename(one_queue_image) two_queue_image_name = os.path.basename(two_queue_image) one_queue_image_backup_name = "backup_" + one_queue_image_name two_queue_image_backup_name = "backup_" + two_queue_image_name #for one queue image backup if not os.path.exists(f"{image_dir}/{one_queue_image_backup_name}"): log_info = """ *********************************************************************** Downloading and decompressing VNF image. This may take a while! *********************************************************************** """ log(log_info) cmd = f""" wget {one_queue_image} -O {image_dir}/{one_queue_image_backup_name} > /dev/null 2>&1 """ log_and_run(cmd) #for two queue image backup if not os.path.exists(f"{image_dir}/{two_queue_image_backup_name}"): log_info = """ *********************************************************************** Downloading and decompressing VNF image. This may take a while! *********************************************************************** """ log(log_info) cmd = f""" wget {two_queue_image} -O {image_dir}/{two_queue_image_backup_name}> /dev/null 2>&1 """ log_and_run(cmd) #config a new image from backup image if os.path.exists(f"{image_dir}/{one_queue_image_name}"): with pushd(f"{image_dir}"): cmd = f""" rm -f {one_queue_image_name} cp {one_queue_image_backup_name} {one_queue_image_name} """ log_and_run(cmd) else: with pushd(f"{image_dir}"): cmd = f""" cp {one_queue_image_backup_name} {one_queue_image_name} """ log_and_run(cmd) #config a new two queue image from backup image if os.path.exists(f"{image_dir}/{two_queue_image_name}"): with pushd(f"{image_dir}"): cmd = f""" rm -f {two_queue_image_name} cp {two_queue_image_backup_name} {two_queue_image_name} """ log_and_run(cmd) else: with pushd(f"{image_dir}"): cmd = f""" cp {two_queue_image_backup_name} {two_queue_image_name} """ log_and_run(cmd) udev_file = "60-persistent-net.rules" data = """ ACTION=="add", SUBSYSTEM=="net", KERNELS=="0000:03:00.0", NAME:="eth1" ACTION=="add", SUBSYSTEM=="net", KERNELS=="0000:04:00.0", NAME:="eth2" """ log("add net rules to guest image") log(data) local.path(udev_file).write(data) cmd = f""" virt-copy-in -a {image_dir}/{one_queue_image_name} {udev_file} /etc/udev/rules.d/ virt-copy-in -a {image_dir}/{two_queue_image_name} {udev_file} /etc/udev/rules.d/ """ log_and_run(cmd) dpdk_url = get_env("DPDK_URL") dpdk_tool_url = get_env("DPDK_TOOL_URL") dpdk_ver = get_env("DPDK_VER") cmd = f""" rm -rf /root/{dpdk_ver} mkdir -p /root/{dpdk_ver} wget -P /root/{dpdk_ver}/ {dpdk_url} > /dev/null 2>&1 wget -P /root/{dpdk_ver}/ {dpdk_tool_url} > /dev/null 2>&1 virt-copy-in -a {image_dir}/{one_queue_image_name} /root/{dpdk_ver} /root/ virt-copy-in -a {image_dir}/{two_queue_image_name} /root/{dpdk_ver} /root/ sleep 5 """ log_and_run(cmd) return 0