X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=resources%2Flibraries%2Fpython%2FDMM%2FSingleCliSer.py;h=8d7b648ea442f3cd5166f88b8da6359b2ee35ffc;hb=9fdc420129db69d20c8f603c15205f2aaf375d66;hp=e96843ac360bdd53f9fd79f9bd594f9cd3183207;hpb=19947738140e71d8d9fa90349e68f6261f5a612f;p=csit.git diff --git a/resources/libraries/python/DMM/SingleCliSer.py b/resources/libraries/python/DMM/SingleCliSer.py index e96843ac36..8d7b648ea4 100644 --- a/resources/libraries/python/DMM/SingleCliSer.py +++ b/resources/libraries/python/DMM/SingleCliSer.py @@ -13,158 +13,237 @@ """ -This module exists to provide the vs_epoll ping test for DMM on topology nodes. +This module exists to provide single client-server test for DMM +on topology nodes. """ import time +import os +import glob -from resources.libraries.python.ssh import exec_cmd_no_error +from resources.libraries.python.ssh import SSH +from resources.libraries.python.ssh import exec_cmd, exec_cmd_no_error from resources.libraries.python.DMM.DMMConstants import DMMConstants as con from resources.libraries.python.topology import Topology class SingleCliSer(object): - """Test the DMM vs_epoll ping function.""" + """Test DMM with single client-server topology.""" @staticmethod - def exec_the_base_vs_epoll_test(dut1_node, dut2_node, - dut1_if_name, dut2_if_name, - dut1_if_ip, dut2_if_ip): + def set_dmm_interface_address(dut_node, ifname, ip_addr, ip4_prefix): + """ + Flush ip, set ip, set interface up. + + :param dut_node: Node to set the interface address on. + :param ifname: Interface name. + :param ip_addr: IP address to configure. + :param ip4_prefix: Prefix length. + :type dut_node: dict + :type ifname: str + :type ip_addr: str + :type ip4_prefix: int + """ + cmd = 'sudo ip -4 addr flush dev {}'.format(ifname) + exec_cmd_no_error(dut_node, cmd) + cmd = 'sudo ip addr add {}/{} dev {}'\ + .format(ip_addr, ip4_prefix, ifname) + exec_cmd_no_error(dut_node, cmd) + cmd = 'sudo ip link set {0} up'.format(ifname) + exec_cmd_no_error(dut_node, cmd) + + @staticmethod + def setup_dmm_dut(dut1_node, dut2_node, dut1_if_name, dut2_if_name, + script_name, dut1_ip, dut2_ip, prefix_len): """ - Perform base vs_epoll test on DUT's. + Setup DMM on DUT nodes. - :param dut1_node: Node to execute vs_epoll on. - :param dut2_node: Node to execute vc_common on. + :param dut1_node: Node to setup DMM on. + :param dut2_node: Node to setup DMM on. :param dut1_if_name: DUT1 to DUT2 interface name. :param dut2_if_name: DUT2 to DUT1 interface name. - :param dut1_if_ip: DUT1 to DUT2 interface ip. - :param dut2_if_ip: DUT2 to DUT1 interface ip. + :param script_name: Name of the script to run. + :param dut1_ip: IP address to configure on DUT1. + :param dut2_ip: IP address to configure on DUT2. + :param prefix_len: Prefix length. :type dut1_node: dict :type dut2_node: dict :type dut1_if_name: str :type dut2_if_name: str - :type dut1_if_ip: str - :type dut2_if_ip: str + :type script_name: str + :type dut1_ip: str + :type dut2_ip: str + :type prefix_len: int """ - cmd = 'cd {0}/{1} && ./run_dmm.sh {2} {3} {4} {5} ' \ - .format(con.REMOTE_FW_DIR, con.DMM_SCRIPTS, 0, dut1_if_name, - dut1_if_ip, dut2_if_ip) + SingleCliSer.set_dmm_interface_address(dut1_node, dut1_if_name, + dut1_ip, prefix_len) + SingleCliSer.set_dmm_interface_address(dut2_node, dut2_if_name, + dut2_ip, prefix_len) + cmd = 'cd {0}/{1} && ./{2} setup 0 {3} {4} {5}'\ + .format(con.REMOTE_FW_DIR, con.DMM_RUN_SCRIPTS, script_name, + dut1_if_name, dut1_ip, dut2_ip) + exec_cmd(dut1_node, cmd) - cmd += '2>&1 | tee log_run_dmm.txt &' - exec_cmd_no_error(dut1_node, cmd) - time.sleep(10) - - cmd = 'cd {0}/{1} && ./run_dmm.sh {2} {3} {4} {5} ' \ - .format(con.REMOTE_FW_DIR, con.DMM_SCRIPTS, 1, dut2_if_name, - dut1_if_ip, dut2_if_ip) - - cmd += '2>&1 | tee log_run_dmm.txt' - exec_cmd_no_error(dut2_node, cmd) - - @staticmethod - def get_the_test_result(dut_node): - """ - After executing exec_the_base_vs_epoll_test, use this - to get the test result. - - :param dut_node: Node to get the test result on. - :type dut_node: dict - :returns: Word count of "send 50000" in the log. - :rtype: str - """ - cmd = 'cat {0}/{1}/log_run_dmm.txt | grep "send 50000" | wc -l' \ - .format(con.REMOTE_FW_DIR, con.DMM_SCRIPTS) - (stdout, _) = exec_cmd_no_error(dut_node, cmd) - return stdout + cmd = 'cd {0}/{1} && ./{2} setup 1 {3} {4} {5}'\ + .format(con.REMOTE_FW_DIR, con.DMM_RUN_SCRIPTS, script_name, + dut2_if_name, dut1_ip, dut2_ip) + exec_cmd(dut2_node, cmd) @staticmethod - def echo_dmm_logs(dut_node): + def execute_test(dut1_node, dut2_node, dut1_if_name, dut2_if_name, + script_name, dut1_ip, dut2_ip): """ - Get the prerequisites installation log from DUT. + Run the given test case. - :param dut_node: Node to get the installation log on. - :type dut_node: dict - """ - cmd = 'cat {0}/{1}/log_install_prereq.txt' \ - .format(con.REMOTE_FW_DIR, con.DMM_SCRIPTS) - exec_cmd_no_error(dut_node, cmd) - - @staticmethod - def exec_the_base_lwip_test(dut1_node, dut2_node, - dut1_if_name, dut2_if_name, - dut1_if_ip, dut2_if_ip): - """Test DMM with LWIP. - - :param dut1_node: Node to execute vs_epoll on. - :param dut2_node: Node to execute vc_common on. + :param dut1_node: Node to run an app with DMM on. + :param dut2_node: Node to run an app with DMM on. :param dut1_if_name: DUT1 to DUT2 interface name. :param dut2_if_name: DUT2 to DUT1 interface name. - :param dut1_if_ip: DUT1 to DUT2 interface ip. - :param dut2_if_ip: DUT2 to DUT1 interface ip. + :param script_name: Name of the script to run. + :param dut1_ip: DUT1 IP address. + :param dut2_ip: DUT2 IP address. :type dut1_node: dict :type dut2_node: dict :type dut1_if_name: str :type dut2_if_name: str - :type dut1_if_ip: str - :type dut2_if_ip: str + :type script_name: str + :type dut1_ip: str + :type dut2_ip: str """ - cmd = 'cd {0}/{1} && ./run_dmm_with_lwip.sh {2} {3} {4} {5} ' \ - .format(con.REMOTE_FW_DIR, con.DMM_SCRIPTS, 0, dut1_if_name, - dut1_if_ip, dut2_if_ip) - - cmd += '2>&1 | tee log_run_dmm_with_lwip.txt &' - exec_cmd_no_error(dut1_node, cmd) + cmd = 'cd {0}/{1} && ./{2} run 0 {3} {4} {5} ' \ + .format(con.REMOTE_FW_DIR, con.DMM_RUN_SCRIPTS, script_name, + dut1_if_name, dut1_ip, dut2_ip) + cmd += '2>&1 | tee log_{0}.txt &'.format(script_name) + exec_cmd(dut1_node, cmd) time.sleep(10) - cmd = 'cd {0}/{1} && ./run_dmm_with_lwip.sh {2} {3} {4} {5} ' \ - .format(con.REMOTE_FW_DIR, con.DMM_SCRIPTS, 1, dut2_if_name, - dut1_if_ip, dut2_if_ip) - - cmd += '2>&1 | tee log_run_dmm_with_lwip.txt' - exec_cmd_no_error(dut2_node, cmd) + cmd = 'cd {0}/{1} && ./{2} run 1 {3} {4} {5} ' \ + .format(con.REMOTE_FW_DIR, con.DMM_RUN_SCRIPTS, script_name, + dut2_if_name, dut1_ip, dut2_ip) + cmd += '2>&1 | tee log_{0}.txt'.format(script_name) + exec_cmd(dut2_node, cmd) @staticmethod - def get_lwip_test_result(dut_node): + def verify_test_result(dut1_node, dut2_node, script_name): """ - After executing exec_the_base_lwip_test, use this - to get the test result. + Verify the test and return result. - :param dut_node: Node to get the test result on. - :type dut_node: dict - :returns: Word count of "send 50" in the log. + :param dut1_node: Node to verify test result on. + :param dut2_node: Node to verify test result on. + :param script_name: Name of the script to run. + :type dut1_node: dict + :type dut2_node: dict + :type script_name: str + :returns: test result PASS/FAIL. :rtype: str """ - cmd = 'cat {0}/{1}/log_run_dmm_with_lwip.txt | grep "send 50" | wc -l' \ - .format(con.REMOTE_FW_DIR, con.DMM_SCRIPTS) + cmd = 'cd {0}/{1} && ./{2} verify 0' \ + .format(con.REMOTE_FW_DIR, con.DMM_RUN_SCRIPTS, script_name) + (_, stdout_ser, _) = exec_cmd(dut1_node, cmd) - (stdout, _) = exec_cmd_no_error(dut_node, cmd) - return stdout + cmd = 'cd {0}/{1} && ./{2} verify 1' \ + .format(con.REMOTE_FW_DIR, con.DMM_RUN_SCRIPTS, script_name) + (_, stdout_cli, _) = exec_cmd(dut2_node, cmd) + + if stdout_ser.find('DMM_CSIT_TEST_PASSED') != -1 \ + and stdout_cli.find('DMM_CSIT_TEST_PASSED') != -1: + return "PASS" + else: + return "FAIL" + + @staticmethod + def print_dmm_log(dut1_node, dut2_node, script_name): + """ + Print DMM logs. + + :param dut1_node: Node to print DMM logs of. + :param dut2_node: Node to print DMM logs of. + :param script_name: Name of the script to run. + :type dut1_node: dict + :type dut2_node: dict + :type script_name: str + """ + cmd = 'cd {0}/{1} && ./{2} log 0'\ + .format(con.REMOTE_FW_DIR, con.DMM_RUN_SCRIPTS, script_name) + exec_cmd(dut1_node, cmd) + + cmd = 'cd {0}/{1} && ./{2} log 1'\ + .format(con.REMOTE_FW_DIR, con.DMM_RUN_SCRIPTS, script_name) + exec_cmd(dut2_node, cmd) + cmd = 'mv /var/log/nStack/running.log /var/log/nStack/{0}_ser.log'\ + .format(script_name) + exec_cmd(dut1_node, cmd, sudo=True) + cmd = 'mv /var/log/nStack/running.log /var/log/nStack/{0}_cli.log'\ + .format(script_name) + exec_cmd(dut2_node, cmd, sudo=True) @staticmethod - def echo_running_log(dut1_node, dut2_node): + def cleanup_dmm_dut(dut1_node, dut2_node, script_name): """ - Get the running log. + Cleanup DMM DUT node. - :param dut1_node: Node to get the running log on. - :param dut2_node: Node to get the running log on. + :param dut1_node: DMM node to be cleaned up. + :param dut2_node: DMM node to be cleaned up. + :param script_name: Name of the script to run. :type dut1_node: dict :type dut2_node: dict + :type script_name: str """ - cmd = 'cat /var/log/nStack/running.log' - exec_cmd_no_error(dut1_node, cmd) - exec_cmd_no_error(dut2_node, cmd) + cmd = 'cd {0}/{1} && ./{2} cleanup 0'\ + .format(con.REMOTE_FW_DIR, con.DMM_RUN_SCRIPTS, script_name) + exec_cmd(dut1_node, cmd) + exec_cmd(dut2_node, cmd) + time.sleep(5) @staticmethod - def echo_dpdk_log(dut1_node, dut2_node): + def run_dmm_func_test_cases(dut1_node, dut2_node, dut1_if_name, + dut2_if_name, dut1_ip, dut2_ip, prefix_len): """ - Get the dpdk log. + Execute all the functional test cases and return result. - :param dut1_node: Node to get the DPDK log on. - :param dut2_node: Node to get the DPDK log on. + :param dut1_node: Node to run an app with DMM on. + :param dut2_node: Node to run an app with DMM on. + :param dut1_if_name: DUT1 to DUT2 interface name. + :param dut2_if_name: DUT2 to DUT1 interface name. + :param dut1_ip: IP address to configure on DUT1. + :param dut2_ip: IP address to configure on DUT2. + :param prefix_len: Prefix length. :type dut1_node: dict :type dut2_node: dict + :type dut1_if_name: str + :type dut2_if_name: str + :type dut1_ip: str + :type dut2_ip: str + :type prefix_len: int + :returns: Total testcase count, Passed testcase count. + :rtype: tuple(int, int) """ - cmd = 'cat /var/log/nstack-dpdk/nstack_dpdk.log' - exec_cmd_no_error(dut1_node, cmd) - exec_cmd_no_error(dut2_node, cmd) + passed = 0 + total = 0 + failed = 0 + path = '{0}/*'.format(con.DMM_RUN_SCRIPTS) + files = [os.path.basename(x) for x in glob.glob(path)] + print "list of files : {0}".format(files) + + for name in files: + print("file name : {}").format(name) + total += 1 + SingleCliSer.setup_dmm_dut(dut1_node, dut2_node, dut1_if_name, + dut2_if_name, name, dut1_ip, dut2_ip, + prefix_len) + SingleCliSer.execute_test(dut1_node, dut2_node, dut1_if_name, + dut2_if_name, name, dut1_ip, dut2_ip) + result = SingleCliSer.verify_test_result(dut1_node, dut2_node, + '{0}'.format(name)) + if result == "PASS": + passed += 1 + elif result == "FAIL": + failed += 1 + + SingleCliSer.print_dmm_log(dut1_node, dut2_node, name) + SingleCliSer.cleanup_dmm_dut(dut1_node, dut2_node, name) + print("TOTAL :{} PASSED : {} FAILED: {}").format\ + (total, passed, failed) + + return total, passed @staticmethod def dmm_get_interface_name(dut_node, dut_interface): @@ -185,23 +264,35 @@ class SingleCliSer(object): return interface_name @staticmethod - def set_dmm_interface_address(dut_node, ifname, ip_addr, ip4_prefix): + def get_logs_from_node(dut_node): """ - Flush ip, set ip, set interface up. + Get logs from node to the test executor machine. - :param dut_node: Node to set the interface address on. - :param ifname: Interface name. - :param ip_addr: IP address to configure. - :param ip4_prefix: Prefix length. + :param dut_node: Node to artifact the logs of. :type dut_node: dict - :type ifname: str - :type ip_addr: str - :type ip4_prefix: int """ - cmd = 'sudo ip -4 addr flush dev {}'.format(ifname) - exec_cmd_no_error(dut_node, cmd) - cmd = 'sudo ip addr add {}/{} dev {}'\ - .format(ip_addr, ip4_prefix, ifname) - exec_cmd_no_error(dut_node, cmd) - cmd = 'sudo ip link set {0} up'.format(ifname) - exec_cmd_no_error(dut_node, cmd) + ssh = SSH() + ssh.connect(dut_node) + ssh.scp(".", '/var/log/nStack/*.log', + get=True, timeout=60, wildcard=True) + + (ret, _, _) = exec_cmd(dut_node, 'ls -l /var/log/app*.log') + if ret == 0: + ssh.scp(".", '/var/log/app*.log', + get=True, timeout=60, wildcard=True) + + exec_cmd(dut_node, 'rm -rf /var/log/nStack/*.log', sudo=True) + exec_cmd(dut_node, 'rm -rf /var/log/app*.log', sudo=True) + + @staticmethod + def archive_dmm_logs(dut1_node, dut2_node): + """ + Get logs from both DUT's to the test executor machine. + + :param dut1_node: DUT1 node. + :param dut2_node: DUT2 node. + :type dut1_node: dict + :type dut2_node: dict + """ + SingleCliSer.get_logs_from_node(dut1_node) + SingleCliSer.get_logs_from_node(dut2_node)