class Uperf(Test): """ Uperf Test """ def setUp(self): """ To check and install dependencies for the test """ self.peer_ip = self.params.get("peer_ip", default="") self.peer_public_ip = self.params.get("peer_public_ip", default="") self.peer_user = self.params.get("peer_user_name", default="root") self.peer_password = self.params.get("peer_password", '*', default="None") interfaces = netifaces.interfaces() self.iface = self.params.get("interface", default="") if self.iface not in interfaces: self.cancel("%s interface is not available" % self.iface) self.ipaddr = self.params.get("host_ip", default="") self.netmask = self.params.get("netmask", default="") local = LocalHost() self.networkinterface = NetworkInterface(self.iface, local) try: self.networkinterface.add_ipaddr(self.ipaddr, self.netmask) self.networkinterface.save(self.ipaddr, self.netmask) except Exception: self.networkinterface.save(self.ipaddr, self.netmask) self.networkinterface.bring_up() self.session = Session(self.peer_ip, user=self.peer_user, password=self.peer_password) if not self.session.connect(): self.cancel("failed connecting to peer") smm = SoftwareManager() detected_distro = distro.detect() pkgs = ["gcc", "autoconf", "perl", "m4", "git-core", "automake"] if detected_distro.name == "Ubuntu": pkgs.extend(["libsctp1", "libsctp-dev", "lksctp-tools"]) else: pkgs.extend(["lksctp-tools", "lksctp-tools-devel"]) for pkg in pkgs: if not smm.check_installed(pkg) and not smm.install(pkg): self.cancel("%s package is need to test" % pkg) cmd = "%s install %s" % (smm.backend.base_command, pkg) output = self.session.cmd(cmd) if not output.exit_status == 0: self.cancel("unable to install the package %s on peer machine " % pkg) if self.peer_ip == "": self.cancel("%s peer machine is not available" % self.peer_ip) self.mtu = self.params.get("mtu", default=1500) self.remotehost = RemoteHost(self.peer_ip, self.peer_user, password=self.peer_password) self.peer_interface = self.remotehost.get_interface_by_ipaddr(self.peer_ip).name self.peer_networkinterface = NetworkInterface(self.peer_interface, self.remotehost) self.remotehost_public = RemoteHost(self.peer_public_ip, self.peer_user, password=self.peer_password) self.peer_public_networkinterface = NetworkInterface(self.peer_interface, self.remotehost_public) if self.peer_networkinterface.set_mtu(self.mtu) is not None: self.cancel("Failed to set mtu in peer") if self.networkinterface.set_mtu(self.mtu) is not None: self.cancel("Failed to set mtu in host") uperf_download = self.params.get("uperf_download", default="https:" "//github.com/uperf/uperf/" "archive/master.zip") tarball = self.fetch_asset("uperf.zip", locations=[uperf_download], expire='7d') archive.extract(tarball, self.teststmpdir) self.uperf_dir = os.path.join(self.teststmpdir, "uperf-master") destination = "%s:/tmp" % self.peer_ip output = self.session.copy_files(self.uperf_dir, destination, recursive=True) if not output: self.cancel("unable to copy the uperf into peer machine") cmd = "cd /tmp/uperf-master;autoreconf -fi;./configure ppc64le;make" output = self.session.cmd(cmd) if not output.exit_status == 0: self.cancel("Unable to compile Uperf into peer machine") self.uperf_run = str(self.params.get("UPERF_SERVER_RUN", default=0)) if self.uperf_run == '1': cmd = "/tmp/uperf-master/src/uperf -s &" cmd = self.session.get_raw_ssh_command(cmd) self.obj = SubProcess(cmd) self.obj.start() os.chdir(self.uperf_dir) process.system('autoreconf -fi', shell=True) process.system('./configure ppc64le', shell=True) build.make(self.uperf_dir) self.expected_tp = self.params.get("EXPECTED_THROUGHPUT", default="85") def test(self): """ Test run is a One way throughput test. In this test, we have one host transmitting (or receiving) data from a client. This transmit large messages using multiple threads or processes. """ speed = int(read_file("/sys/class/net/%s/speed" % self.iface)) cmd = "h=%s proto=tcp ./src/uperf -m manual/throughput.xml -a" \ % self.peer_ip result = process.run(cmd, shell=True, ignore_status=True) if result.exit_status: self.fail("FAIL: Uperf Run failed") for line in result.stdout.decode("utf-8").splitlines(): if self.peer_ip in line: if 'Mb/s' in line: tput = int(line.split()[3].split('.')[0]) else: # Converting the throughput calculated in Gb to Mb tput = int(line.split()[3].split('.')[0]) * 1000 if tput < (int(self.expected_tp) * speed) / 100: self.fail("FAIL: Throughput Actual - %s%%, Expected - %s%%" ", Throughput Actual value - %s " % ((tput*100)/speed, self.expected_tp, str(tput)+'Mb/sec')) if 'WARNING' in result.stdout.decode("utf-8"): self.log.warn('Test completed with warning') def tearDown(self): """ Killing Uperf process in peer machine """ self.obj.stop() cmd = "pkill uperf; rm -rf /tmp/uperf-master" output = self.session.cmd(cmd) if not output.exit_status == 0: self.fail("Either the ssh to peer machine machine\ failed or uperf process was not killed") if self.networkinterface.set_mtu('1500') is not None: self.cancel("Failed to set mtu in host") try: self.peer_networkinterface.set_mtu('1500') except Exception: self.peer_public_networkinterface.set_mtu('1500') self.networkinterface.remove_ipaddr(self.ipaddr, self.netmask) try: self.networkinterface.restore_from_backup() except Exception: self.log.info("backup file not availbale, could not restore file.") self.remotehost.remote_session.quit() self.remotehost_public.remote_session.quit() self.session.quit()
def setUp(self): """ To check and install dependencies for the test """ self.peer_ip = self.params.get("peer_ip", default="") self.peer_public_ip = self.params.get("peer_public_ip", default="") self.peer_user = self.params.get("peer_user_name", default="root") self.peer_password = self.params.get("peer_password", '*', default="None") interfaces = netifaces.interfaces() self.iface = self.params.get("interface", default="") if self.iface not in interfaces: self.cancel("%s interface is not available" % self.iface) self.ipaddr = self.params.get("host_ip", default="") self.netmask = self.params.get("netmask", default="") local = LocalHost() self.networkinterface = NetworkInterface(self.iface, local) try: self.networkinterface.add_ipaddr(self.ipaddr, self.netmask) self.networkinterface.save(self.ipaddr, self.netmask) except Exception: self.networkinterface.save(self.ipaddr, self.netmask) self.networkinterface.bring_up() self.session = Session(self.peer_ip, user=self.peer_user, password=self.peer_password) if not self.session.connect(): self.cancel("failed connecting to peer") smm = SoftwareManager() detected_distro = distro.detect() pkgs = ["gcc", "autoconf", "perl", "m4", "git-core", "automake"] if detected_distro.name == "Ubuntu": pkgs.extend(["libsctp1", "libsctp-dev", "lksctp-tools"]) else: pkgs.extend(["lksctp-tools", "lksctp-tools-devel"]) for pkg in pkgs: if not smm.check_installed(pkg) and not smm.install(pkg): self.cancel("%s package is need to test" % pkg) cmd = "%s install %s" % (smm.backend.base_command, pkg) output = self.session.cmd(cmd) if not output.exit_status == 0: self.cancel("unable to install the package %s on peer machine " % pkg) if self.peer_ip == "": self.cancel("%s peer machine is not available" % self.peer_ip) self.mtu = self.params.get("mtu", default=1500) self.remotehost = RemoteHost(self.peer_ip, self.peer_user, password=self.peer_password) self.peer_interface = self.remotehost.get_interface_by_ipaddr(self.peer_ip).name self.peer_networkinterface = NetworkInterface(self.peer_interface, self.remotehost) self.remotehost_public = RemoteHost(self.peer_public_ip, self.peer_user, password=self.peer_password) self.peer_public_networkinterface = NetworkInterface(self.peer_interface, self.remotehost_public) if self.peer_networkinterface.set_mtu(self.mtu) is not None: self.cancel("Failed to set mtu in peer") if self.networkinterface.set_mtu(self.mtu) is not None: self.cancel("Failed to set mtu in host") uperf_download = self.params.get("uperf_download", default="https:" "//github.com/uperf/uperf/" "archive/master.zip") tarball = self.fetch_asset("uperf.zip", locations=[uperf_download], expire='7d') archive.extract(tarball, self.teststmpdir) self.uperf_dir = os.path.join(self.teststmpdir, "uperf-master") destination = "%s:/tmp" % self.peer_ip output = self.session.copy_files(self.uperf_dir, destination, recursive=True) if not output: self.cancel("unable to copy the uperf into peer machine") cmd = "cd /tmp/uperf-master;autoreconf -fi;./configure ppc64le;make" output = self.session.cmd(cmd) if not output.exit_status == 0: self.cancel("Unable to compile Uperf into peer machine") self.uperf_run = str(self.params.get("UPERF_SERVER_RUN", default=0)) if self.uperf_run == '1': cmd = "/tmp/uperf-master/src/uperf -s &" cmd = self.session.get_raw_ssh_command(cmd) self.obj = SubProcess(cmd) self.obj.start() os.chdir(self.uperf_dir) process.system('autoreconf -fi', shell=True) process.system('./configure ppc64le', shell=True) build.make(self.uperf_dir) self.expected_tp = self.params.get("EXPECTED_THROUGHPUT", default="85")
def setUp(self): """ To check and install dependencies for the test """ self.peer_user = self.params.get("peer_user", default="root") self.peer_ip = self.params.get("peer_ip", default="") self.peer_public_ip = self.params.get("peer_public_ip", default="") self.peer_password = self.params.get("peer_password", '*', default=None) interfaces = netifaces.interfaces() self.iface = self.params.get("interface", default="") if self.iface not in interfaces: self.cancel("%s interface is not available" % self.iface) self.ipaddr = self.params.get("host_ip", default="") self.netmask = self.params.get("netmask", default="") self.hbond = self.params.get("hbond", default=False) localhost = LocalHost() if self.hbond: self.networkinterface = NetworkInterface(self.iface, localhost, if_type='Bond') else: self.networkinterface = NetworkInterface(self.iface, localhost) try: self.networkinterface.add_ipaddr(self.ipaddr, self.netmask) self.networkinterface.save(self.ipaddr, self.netmask) except Exception: self.networkinterface.save(self.ipaddr, self.netmask) self.networkinterface.bring_up() self.session = Session(self.peer_ip, user=self.peer_user, password=self.peer_password) if not self.session.connect(): self.cancel("failed connecting to peer") smm = SoftwareManager() for pkg in ["gcc", "autoconf", "perl", "m4", "libtool", "gcc-c++"]: if not smm.check_installed(pkg) and not smm.install(pkg): self.cancel("%s package is need to test" % pkg) cmd = "%s install %s" % (smm.backend.base_command, pkg) output = self.session.cmd(cmd) if not output.exit_status == 0: self.cancel( "unable to install the package %s on peer machine " % pkg) detected_distro = distro.detect() pkg = "nmap" if detected_distro.name == 'rhel': if not smm.check_installed(pkg) and not smm.install(pkg): self.cancel("%s package Can not install" % pkg) if detected_distro.name == "SuSE": self.nmap = os.path.join(self.teststmpdir, 'nmap') nmap_download = self.params.get("nmap_download", default="https:" "//nmap.org/dist/" "nmap-7.80.tar.bz2") tarball = self.fetch_asset(nmap_download) self.version = os.path.basename(tarball.split('.tar')[0]) self.n_map = os.path.join(self.nmap, self.version) archive.extract(tarball, self.nmap) os.chdir(self.n_map) process.system('./configure ppc64le', shell=True) build.make(self.n_map) process.system('./nping/nping -h', shell=True) if self.peer_ip == "": self.cancel("%s peer machine is not available" % self.peer_ip) self.mtu = self.params.get("mtu", default=1500) self.remotehost = RemoteHost(self.peer_ip, self.peer_user, password=self.peer_password) self.peer_interface = self.remotehost.get_interface_by_ipaddr( self.peer_ip).name self.peer_networkinterface = NetworkInterface(self.peer_interface, self.remotehost) self.remotehost_public = RemoteHost(self.peer_public_ip, self.peer_user, password=self.peer_password) self.peer_public_networkinterface = NetworkInterface( self.peer_interface, self.remotehost_public) if self.peer_networkinterface.set_mtu(self.mtu) is not None: self.cancel("Failed to set mtu in peer") if self.networkinterface.set_mtu(self.mtu) is not None: self.cancel("Failed to set mtu in host") self.iperf = os.path.join(self.teststmpdir, 'iperf') iperf_download = self.params.get("iperf_download", default="https:" "//sourceforge.net/projects/iperf2/" "files/iperf-2.0.13.tar.gz") tarball = self.fetch_asset(iperf_download, expire='7d') archive.extract(tarball, self.iperf) self.version = os.path.basename(tarball.split('.tar')[0]) self.iperf_dir = os.path.join(self.iperf, self.version) destination = "%s:/tmp" % self.peer_ip output = self.session.copy_files(self.iperf_dir, destination, recursive=True) if not output: self.cancel("unable to copy the iperf into peer machine") cmd = "cd /tmp/%s;./configure ppc64le;make" % self.version output = self.session.cmd(cmd) if not output.exit_status == 0: self.cancel("Unable to compile Iperf into peer machine") self.iperf_run = str(self.params.get("IPERF_SERVER_RUN", default=0)) if self.iperf_run == '1': cmd = "/tmp/%s/src/iperf -s" % self.version cmd = self.session.get_raw_ssh_command(cmd) self.obj = SubProcess(cmd) self.obj.start() os.chdir(self.iperf_dir) process.system('./configure', shell=True) build.make(self.iperf_dir) self.iperf = os.path.join(self.iperf_dir, 'src') self.expected_tp = self.params.get("EXPECTED_THROUGHPUT", default="85")
class Iperf(Test): """ Iperf Test """ def setUp(self): """ To check and install dependencies for the test """ self.peer_user = self.params.get("peer_user", default="root") self.peer_ip = self.params.get("peer_ip", default="") self.peer_public_ip = self.params.get("peer_public_ip", default="") self.peer_password = self.params.get("peer_password", '*', default=None) interfaces = netifaces.interfaces() self.iface = self.params.get("interface", default="") if self.iface not in interfaces: self.cancel("%s interface is not available" % self.iface) self.ipaddr = self.params.get("host_ip", default="") self.netmask = self.params.get("netmask", default="") self.hbond = self.params.get("hbond", default=False) localhost = LocalHost() if self.hbond: self.networkinterface = NetworkInterface(self.iface, localhost, if_type='Bond') else: self.networkinterface = NetworkInterface(self.iface, localhost) try: self.networkinterface.add_ipaddr(self.ipaddr, self.netmask) self.networkinterface.save(self.ipaddr, self.netmask) except Exception: self.networkinterface.save(self.ipaddr, self.netmask) self.networkinterface.bring_up() self.session = Session(self.peer_ip, user=self.peer_user, password=self.peer_password) if not self.session.connect(): self.cancel("failed connecting to peer") smm = SoftwareManager() for pkg in ["gcc", "autoconf", "perl", "m4", "libtool", "gcc-c++"]: if not smm.check_installed(pkg) and not smm.install(pkg): self.cancel("%s package is need to test" % pkg) cmd = "%s install %s" % (smm.backend.base_command, pkg) output = self.session.cmd(cmd) if not output.exit_status == 0: self.cancel( "unable to install the package %s on peer machine " % pkg) detected_distro = distro.detect() pkg = "nmap" if detected_distro.name == 'rhel': if not smm.check_installed(pkg) and not smm.install(pkg): self.cancel("%s package Can not install" % pkg) if detected_distro.name == "SuSE": self.nmap = os.path.join(self.teststmpdir, 'nmap') nmap_download = self.params.get("nmap_download", default="https:" "//nmap.org/dist/" "nmap-7.80.tar.bz2") tarball = self.fetch_asset(nmap_download) self.version = os.path.basename(tarball.split('.tar')[0]) self.n_map = os.path.join(self.nmap, self.version) archive.extract(tarball, self.nmap) os.chdir(self.n_map) process.system('./configure ppc64le', shell=True) build.make(self.n_map) process.system('./nping/nping -h', shell=True) if self.peer_ip == "": self.cancel("%s peer machine is not available" % self.peer_ip) self.mtu = self.params.get("mtu", default=1500) self.remotehost = RemoteHost(self.peer_ip, self.peer_user, password=self.peer_password) self.peer_interface = self.remotehost.get_interface_by_ipaddr( self.peer_ip).name self.peer_networkinterface = NetworkInterface(self.peer_interface, self.remotehost) self.remotehost_public = RemoteHost(self.peer_public_ip, self.peer_user, password=self.peer_password) self.peer_public_networkinterface = NetworkInterface( self.peer_interface, self.remotehost_public) if self.peer_networkinterface.set_mtu(self.mtu) is not None: self.cancel("Failed to set mtu in peer") if self.networkinterface.set_mtu(self.mtu) is not None: self.cancel("Failed to set mtu in host") self.iperf = os.path.join(self.teststmpdir, 'iperf') iperf_download = self.params.get("iperf_download", default="https:" "//sourceforge.net/projects/iperf2/" "files/iperf-2.0.13.tar.gz") tarball = self.fetch_asset(iperf_download, expire='7d') archive.extract(tarball, self.iperf) self.version = os.path.basename(tarball.split('.tar')[0]) self.iperf_dir = os.path.join(self.iperf, self.version) destination = "%s:/tmp" % self.peer_ip output = self.session.copy_files(self.iperf_dir, destination, recursive=True) if not output: self.cancel("unable to copy the iperf into peer machine") cmd = "cd /tmp/%s;./configure ppc64le;make" % self.version output = self.session.cmd(cmd) if not output.exit_status == 0: self.cancel("Unable to compile Iperf into peer machine") self.iperf_run = str(self.params.get("IPERF_SERVER_RUN", default=0)) if self.iperf_run == '1': cmd = "/tmp/%s/src/iperf -s" % self.version cmd = self.session.get_raw_ssh_command(cmd) self.obj = SubProcess(cmd) self.obj.start() os.chdir(self.iperf_dir) process.system('./configure', shell=True) build.make(self.iperf_dir) self.iperf = os.path.join(self.iperf_dir, 'src') self.expected_tp = self.params.get("EXPECTED_THROUGHPUT", default="85") def nping(self): """ Run nping test with tcp packets """ detected_distro = distro.detect() if detected_distro.name == "SuSE": os.chdir(self.n_map) cmd = "./nping/nping --tcp %s -c 10" % self.peer_ip return process.run(cmd, verbose=False, shell=True) else: cmd = "nping --tcp %s -c 10" % self.peer_ip return process.run(cmd, verbose=False, shell=True) def test(self): """ Test run is a One way throughput test. In this test, we have one host transmitting (or receiving) data from a client. This transmit large messages using multiple threads or processes. """ speed = int(read_file("/sys/class/net/%s/speed" % self.iface)) os.chdir(self.iperf) cmd = "./iperf -c %s" % self.peer_ip result = process.run(cmd, shell=True, ignore_status=True) nping_result = self.nping() if result.exit_status: self.fail("FAIL: Iperf Run failed") for line in result.stdout.decode("utf-8").splitlines(): if 'local {}'.format(self.ipaddr) in line: id = line[3] for line in result.stdout.decode("utf-8").splitlines(): if id in line and 'Mbits/sec' in line: tput = int(line.split()[6]) elif id in line and 'Gbits/sec' in line: tput = int(float(line.split()[6])) * 1000 if tput < (int(self.expected_tp) * speed) / 100: self.fail( "FAIL: Throughput Actual - %s%%, Expected - %s%%" ", Throughput Actual value - %s " % ((tput * 100) / speed, self.expected_tp, str(tput) + 'Mb/sec')) for line in nping_result.stdout.decode("utf-8").splitlines(): if 'Raw packets' in line: lost = int(line.split("|")[2].split(" ")[2]) * 10 if lost > 60: self.fail("FAIL: Ping fails after iperf test") def tearDown(self): """ Killing Iperf process in peer machine """ cmd = "pkill iperf; rm -rf /tmp/%s" % self.version output = self.session.cmd(cmd) if not output.exit_status == 0: self.fail("Either the ssh to peer machine machine\ failed or iperf process was not killed") self.obj.stop() if self.networkinterface.set_mtu('1500') is not None: self.cancel("Failed to set mtu in host") try: self.peer_networkinterface.set_mtu('1500') except Exception: self.peer_public_networkinterface.set_mtu('1500') self.networkinterface.remove_ipaddr(self.ipaddr, self.netmask) try: self.networkinterface.restore_from_backup() except Exception: self.networkinterface.remove_cfg_file() self.log.info("backup file not availbale, could not restore file.") if self.hbond: self.networkinterface.restore_slave_cfg_file() self.remotehost.remote_session.quit() self.remotehost_public.remote_session.quit() self.session.quit()
def setUp(self): """ To check and install dependencies for the test """ self.peer_user = self.params.get("peer_user_name", default="root") self.peer_ip = self.params.get("peer_ip", default="") self.peer_password = self.params.get("peer_password", '*', default=None) interfaces = netifaces.interfaces() self.iface = self.params.get("interface", default="") if self.iface not in interfaces: self.cancel("%s interface is not available" % self.iface) self.ipaddr = self.params.get("host_ip", default="") self.netmask = self.params.get("netmask", default="") localhost = LocalHost() self.networkinterface = NetworkInterface(self.iface, localhost) try: self.networkinterface.add_ipaddr(self.ipaddr, self.netmask) self.networkinterface.save(self.ipaddr, self.netmask) except Exception: self.networkinterface.save(self.ipaddr, self.netmask) self.networkinterface.bring_up() self.session = Session(self.peer_ip, user=self.peer_user, password=self.peer_password) smm = SoftwareManager() for pkg in ["gcc", "autoconf", "perl", "m4", "libtool"]: if not smm.check_installed(pkg) and not smm.install(pkg): self.cancel("%s package is need to test" % pkg) cmd = "%s install %s" % (smm.backend.base_command, pkg) output = self.session.cmd(cmd) if not output.exit_status == 0: self.cancel( "unable to install the package %s on peer machine " % pkg) if self.peer_ip == "": self.cancel("%s peer machine is not available" % self.peer_ip) self.mtu = self.params.get("mtu", default=1500) remotehost = RemoteHost(self.peer_ip, self.peer_user, password=self.peer_password) self.peer_interface = remotehost.get_interface_by_ipaddr( self.peer_ip).name self.peer_networkinterface = NetworkInterface(self.peer_interface, remotehost) if self.peer_networkinterface.set_mtu(self.mtu) is not None: self.cancel("Failed to set mtu in peer") if self.networkinterface.set_mtu(self.mtu) is not None: self.cancel("Failed to set mtu in host") self.iperf = os.path.join(self.teststmpdir, 'iperf') iperf_download = self.params.get("iperf_download", default="https:" "//excellmedia.dl.sourceforge.net/" "project/iperf2/iperf-2.0.13.tar.gz") tarball = self.fetch_asset(iperf_download, expire='7d') archive.extract(tarball, self.iperf) self.version = os.path.basename(tarball.split('.tar')[0]) self.iperf_dir = os.path.join(self.iperf, self.version) cmd = "scp -r %s %s@%s:/tmp" % (self.iperf_dir, self.peer_user, self.peer_ip) if process.system(cmd, shell=True, ignore_status=True) != 0: self.cancel("unable to copy the iperf into peer machine") cmd = "cd /tmp/%s;./configure ppc64le;make" % self.version output = self.session.cmd(cmd) if not output.exit_status == 0: self.cancel("Unable to compile Iperf into peer machine") self.iperf_run = str(self.params.get("IPERF_SERVER_RUN", default=0)) if self.iperf_run == '1': cmd = "/tmp/%s/src/iperf -s" % self.version cmd = self.session.get_raw_ssh_command(cmd) self.obj = SubProcess(cmd) self.obj.start() os.chdir(self.iperf_dir) process.system('./configure', shell=True) build.make(self.iperf_dir) self.iperf = os.path.join(self.iperf_dir, 'src') self.expected_tp = self.params.get("EXPECTED_THROUGHPUT", default="85")
class Iperf(Test): """ Iperf Test """ def setUp(self): """ To check and install dependencies for the test """ self.peer_user = self.params.get("peer_user_name", default="root") self.peer_ip = self.params.get("peer_ip", default="") self.peer_password = self.params.get("peer_password", '*', default=None) interfaces = netifaces.interfaces() self.iface = self.params.get("interface", default="") if self.iface not in interfaces: self.cancel("%s interface is not available" % self.iface) self.ipaddr = self.params.get("host_ip", default="") self.netmask = self.params.get("netmask", default="") localhost = LocalHost() self.networkinterface = NetworkInterface(self.iface, localhost) try: self.networkinterface.add_ipaddr(self.ipaddr, self.netmask) self.networkinterface.save(self.ipaddr, self.netmask) except Exception: self.networkinterface.save(self.ipaddr, self.netmask) self.networkinterface.bring_up() self.session = Session(self.peer_ip, user=self.peer_user, password=self.peer_password) smm = SoftwareManager() for pkg in ["gcc", "autoconf", "perl", "m4", "libtool"]: if not smm.check_installed(pkg) and not smm.install(pkg): self.cancel("%s package is need to test" % pkg) cmd = "%s install %s" % (smm.backend.base_command, pkg) output = self.session.cmd(cmd) if not output.exit_status == 0: self.cancel( "unable to install the package %s on peer machine " % pkg) if self.peer_ip == "": self.cancel("%s peer machine is not available" % self.peer_ip) self.mtu = self.params.get("mtu", default=1500) remotehost = RemoteHost(self.peer_ip, self.peer_user, password=self.peer_password) self.peer_interface = remotehost.get_interface_by_ipaddr( self.peer_ip).name self.peer_networkinterface = NetworkInterface(self.peer_interface, remotehost) if self.peer_networkinterface.set_mtu(self.mtu) is not None: self.cancel("Failed to set mtu in peer") if self.networkinterface.set_mtu(self.mtu) is not None: self.cancel("Failed to set mtu in host") self.iperf = os.path.join(self.teststmpdir, 'iperf') iperf_download = self.params.get("iperf_download", default="https:" "//excellmedia.dl.sourceforge.net/" "project/iperf2/iperf-2.0.13.tar.gz") tarball = self.fetch_asset(iperf_download, expire='7d') archive.extract(tarball, self.iperf) self.version = os.path.basename(tarball.split('.tar')[0]) self.iperf_dir = os.path.join(self.iperf, self.version) cmd = "scp -r %s %s@%s:/tmp" % (self.iperf_dir, self.peer_user, self.peer_ip) if process.system(cmd, shell=True, ignore_status=True) != 0: self.cancel("unable to copy the iperf into peer machine") cmd = "cd /tmp/%s;./configure ppc64le;make" % self.version output = self.session.cmd(cmd) if not output.exit_status == 0: self.cancel("Unable to compile Iperf into peer machine") self.iperf_run = str(self.params.get("IPERF_SERVER_RUN", default=0)) if self.iperf_run == '1': cmd = "/tmp/%s/src/iperf -s" % self.version cmd = self.session.get_raw_ssh_command(cmd) self.obj = SubProcess(cmd) self.obj.start() os.chdir(self.iperf_dir) process.system('./configure', shell=True) build.make(self.iperf_dir) self.iperf = os.path.join(self.iperf_dir, 'src') self.expected_tp = self.params.get("EXPECTED_THROUGHPUT", default="85") def test(self): """ Test run is a One way throughput test. In this test, we have one host transmitting (or receiving) data from a client. This transmit large messages using multiple threads or processes. """ speed = int(read_file("/sys/class/net/%s/speed" % self.iface)) os.chdir(self.iperf) cmd = "./iperf -c %s" % self.peer_ip result = process.run(cmd, shell=True, ignore_status=True) if result.exit_status: self.fail("FAIL: Iperf Run failed") for line in result.stdout.decode("utf-8").splitlines(): if 'sender' in line: tput = int(line.split()[6].split('.')[0]) if tput < (int(self.expected_tp) * speed) / 100: self.fail("FAIL: Throughput Actual - %s%%, Expected - %s%%" ", Throughput Actual value - %s " % ((tput * 100) / speed, self.expected_tp, str(tput) + 'Mb/sec')) def tearDown(self): """ Killing Iperf process in peer machine """ cmd = "pkill iperf; rm -rf /tmp/%s" % self.version output = self.session.cmd(cmd) if not output.exit_status == 0: self.fail("Either the ssh to peer machine machine\ failed or iperf process was not killed") self.obj.stop() if self.networkinterface.set_mtu('1500') is not None: self.cancel("Failed to set mtu in host") if self.peer_networkinterface.set_mtu('1500') is not None: self.cancel("Failed to set mtu in peer") self.networkinterface.remove_ipaddr(self.ipaddr, self.netmask)
from avocado.utils.ssh import Session from avocado.utils.process import SubProcess import time with Session('host', user='******', key='/path/to/key') as s: print('connected') procs = [] cmd = s.get_raw_ssh_command('sleep 5') for i in range(10): p = SubProcess(cmd) print(p.start()) procs.append(p) while True: for proc in procs: proc.poll() if all([p.result.exit_status is not None for p in procs]): print('all finished') break time.sleep(1) print('working...') print('session closed')