class Ethtool(Test): ''' To test different types of pings ''' def setUp(self): ''' To check and install dependencies for the test ''' smm = SoftwareManager() pkgs = ["ethtool", "net-tools"] detected_distro = distro.detect() if detected_distro.name == "Ubuntu": pkgs.extend(["iputils-ping"]) elif detected_distro.name == "SuSE": pkgs.extend(["iputils"]) else: pkgs.extend(["iputils"]) for pkg in pkgs: if not smm.check_installed(pkg) and not smm.install(pkg): self.cancel("%s package is need to test" % pkg) interfaces = netifaces.interfaces() interface = self.params.get("interface") if interface not in interfaces: self.cancel("%s interface is not available" % interface) self.iface = interface self.ipaddr = self.params.get("host_ip", default="") self.netmask = self.params.get("netmask", default="") self.peer = self.params.get("peer_ip") if not self.peer: self.cancel("No peer provided") local = LocalHost() if self.iface[0:2] == 'ib': self.networkinterface = NetworkInterface(self.iface, local, if_type='Infiniband') 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) else: 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() if not wait.wait_for(self.networkinterface.is_link_up, timeout=120): self.cancel("Link up of interface is taking longer than 120s") if self.networkinterface.ping_check(self.peer, count=5) is not None: self.cancel("No connection to peer") self.args = self.params.get("arg", default='') self.elapse = self.params.get("action_elapse", default='') self.priv_test = self.params.get("privflag_test", default=False) if self.priv_test: cmd = "ethtool --show-priv-flags %s" % (self.iface) self.ret_val = process.run(cmd, shell=True, verbose=True, ignore_status=True) if self.ret_val.exit_status: self.cancel("Device Doesn't support Private flags") def interface_state_change(self, interface, state, status): ''' Set the interface state specified, and return True if done. Returns False otherwise. ''' cmd = "ip link set dev %s %s" % (interface, state) if state == "up": if process.system(cmd, shell=True, ignore_status=True) != 0: return False if not wait.wait_for(self.networkinterface.is_link_up, timeout=120): self.fail("Link up of interface is taking longer than 120s") else: if process.system(cmd, shell=True, ignore_status=True) != 0: return False if status != self.interface_link_status(interface): return False return True def interface_link_status(self, interface): ''' Return the status of the interface link from ethtool. ''' cmd = "ethtool %s" % interface for line in process.system_output(cmd, shell=True, ignore_status=True).decode("utf-8") \ .splitlines(): if 'Link detected' in line: return line.split()[-1] return '' def test_ethtool(self): ''' Test the ethtool args provided ''' for state, status in zip(["down", "up"], ["no", "yes"]): if not self.interface_state_change(self.iface, state, status): self.fail("interface %s failed" % state) cmd = "ethtool %s %s %s" % (self.args, self.iface, self.elapse) ret = process.run(cmd, shell=True, verbose=True, ignore_status=True) if ret.exit_status != 0: self.fail("failed") if self.networkinterface.ping_check(self.peer, count=10000, options='-f') is not None: self.fail("flood ping test failed") if self.priv_test: self.ethtool_toggle_priv_flags() def ethtool_toggle_priv_flags(self): ''' Toggle the priv flag settings of the driver. ''' priv_pass = [] priv_fail = [] for oper in ('toggle', 'setback'): for line in self.ret_val.stdout_text.splitlines(): if "off" in line: val = "on" else: val = "off" if "flags" not in line: priv_flag = line.split(':')[0] cmd = "ethtool --set-priv-flags %s \"%s\" %s" % \ (self.iface, priv_flag.rstrip(), val) ret1 = process.run(cmd, shell=True, verbose=True, ignore_status=True) if ret1.exit_status == 0 or 'supported' in \ ret1.stderr_text: priv_pass.append(priv_flag.rstrip()) else: priv_fail.append(priv_flag.rstrip()) if self.networkinterface.ping_check(self.peer, count=500000, options='-f') is not None: self.fail("Ping failed oper = %s" % oper) if priv_fail: self.fail("Private flags could not be toggled: %s" % ",".join(list(set(priv_fail)))) def tearDown(self): ''' Set the interface up at the end of test. ''' self.interface_state_change(self.iface, "up", "yes") self.networkinterface.remove_ipaddr(self.ipaddr, self.netmask)
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_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) 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) 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") 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") cmd = "scp -r %s %s@%s:/tmp" % (self.uperf_dir, self.peer_user, self.peer_ip) if process.system(cmd, shell=True, ignore_status=True) != 0: 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") 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)
def setUp(self): ''' To check and install dependencies for the test ''' detected_distro = distro.detect() smm = SoftwareManager() depends = [] # FIXME: "redhat" as the distro name for RHEL is deprecated # on Avocado versions >= 50.0. This is a temporary compatibility # enabler for older runners, but should be removed soon if detected_distro.name == "Ubuntu": depends.extend(["openssh-client", "iputils-ping"]) elif detected_distro.name in ["rhel", "fedora", "centos", "redhat"]: depends.extend(["openssh-clients", "iputils"]) else: depends.extend(["openssh", "iputils"]) for pkg in depends: if not smm.check_installed(pkg) and not smm.install(pkg): self.cancel("%s package is need to test" % pkg) self.mode = self.params.get("bonding_mode", default="") if 'setup' in str(self.name) or 'run' in str(self.name): if not self.mode: self.cancel("test skipped because mode not specified") interfaces = netifaces.interfaces() self.peer_public_ip = self.params.get("peer_public_ip", default="") self.user = self.params.get("user_name", default="root") self.password = self.params.get("peer_password", '*', default="None") self.host_interfaces = self.params.get("bond_interfaces", default="").split(" ") if not self.host_interfaces: self.cancel("user should specify host interfaces") self.peer_interfaces = self.params.get("peer_interfaces", default="").split(" ") for self.host_interface in self.host_interfaces: if self.host_interface not in interfaces: self.cancel("interface is not available") self.peer_first_ipinterface = self.params.get("peer_ip", default="") if not self.peer_interfaces or self.peer_first_ipinterface == "": self.cancel("peer machine should available") self.ipaddr = self.params.get("host_ips", default="").split(" ") self.netmask = self.params.get("netmask", default="") self.localhost = LocalHost() if 'setup' in str(self.name.name): for ipaddr, interface in zip(self.ipaddr, self.host_interfaces): networkinterface = NetworkInterface(interface, self.localhost) try: networkinterface.add_ipaddr(ipaddr, self.netmask) networkinterface.save(ipaddr, self.netmask) except Exception: networkinterface.save(ipaddr, self.netmask) networkinterface.bring_up() self.miimon = self.params.get("miimon", default="100") self.fail_over_mac = self.params.get("fail_over_mac", default="2") self.downdelay = self.params.get("downdelay", default="0") self.bond_name = self.params.get("bond_name", default="tempbond") self.net_path = "/sys/class/net/" self.bond_status = "/proc/net/bonding/%s" % self.bond_name self.bond_dir = os.path.join(self.net_path, self.bond_name) self.bonding_slave_file = "%s/bonding/slaves" % self.bond_dir self.bonding_masters_file = "%s/bonding_masters" % self.net_path self.peer_bond_needed = self.params.get("peer_bond_needed", default=False) self.peer_wait_time = self.params.get("peer_wait_time", default=5) self.sleep_time = int(self.params.get("sleep_time", default=5)) self.mtu = self.params.get("mtu", default=1500) self.ib = False if self.host_interface[0:2] == 'ib': self.ib = True self.log.info("Bond Test on IB Interface? = %s", self.ib) self.session = Session(self.peer_first_ipinterface, user=self.user, password=self.password) if not self.session.connect(): self.cancel("failed connecting to peer") self.setup_ip() self.err = [] self.remotehost = RemoteHost(self.peer_first_ipinterface, self.user, password=self.password) self.remotehost_public = RemoteHost(self.peer_public_ip, self.user, password=self.password) if 'setup' in str(self.name.name): for interface in self.peer_interfaces: peer_networkinterface = NetworkInterface( interface, self.remotehost) if peer_networkinterface.set_mtu(self.mtu) is not None: self.cancel("Failed to set mtu in peer") for host_interface in self.host_interfaces: self.networkinterface = NetworkInterface( host_interface, self.localhost) if self.networkinterface.set_mtu(self.mtu) is not None: self.cancel("Failed to set mtu in host")
class Rping(Test): """ rping Test. """ def setUp(self): """ Setup and install dependencies for the test. """ self.test_name = "rping" self.basic = self.params.get("basic_option", default="None") self.ext = self.params.get("ext_option", default="None") self.flag = self.params.get("ext_flag", default="0") if self.basic == "None" and self.ext == "None": self.cancel("No option given") if self.flag == "1" and self.ext != "None": self.option = self.ext else: self.option = self.basic if process.system("ibstat", shell=True, ignore_status=True) != 0: self.cancel("MOFED is not installed. Skipping") pkgs = [] detected_distro = distro.detect() smm = SoftwareManager() if detected_distro.name == "Ubuntu": pkgs.extend(["openssh-client", "iputils-ping"]) elif detected_distro.name == "SuSE": pkgs.extend(["openssh", "iputils"]) else: pkgs.extend(["openssh-clients", "iputils"]) for pkg in pkgs: if not smm.check_installed(pkg) and not smm.install(pkg): self.cancel("Not able to install %s" % pkg) interfaces = netifaces.interfaces() self.iface = self.params.get("interface", default="") self.peer_ip = self.params.get("peer_ip", default="") self.ipv6_peer = self.params.get("peer_ipv6", default="") if self.iface not in interfaces: self.cancel("%s interface is not available" % self.iface) if self.peer_ip == "": self.cancel("%s peer machine is not available" % self.peer_ip) self.ipaddr = self.params.get("host_ip", default="") self.netmask = self.params.get("netmask", default="") local = LocalHost() if self.iface[0:2] == 'ib': self.networkinterface = NetworkInterface(self.iface, local, if_type='Infiniband') 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) else: 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() process.system("ifup %s" % self.iface) self.timeout = "2m" self.local_ip = netifaces.ifaddresses(self.iface)[AF_INET][0]['addr'] self.option = self.option.replace("peer_ipv6", self.ipv6_peer) self.option = self.option.replace("peer_ip", self.peer_ip) self.peer_user = self.params.get("peer_user_name", default="root") self.peer_password = self.params.get("peer_password", '*', default="None") self.session = Session(self.peer_ip, user=self.peer_user, password=self.peer_password) self.option = self.option.replace("interface", self.iface) self.option_list = self.option.split(",") 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 detected_distro.name == "Ubuntu": cmd = "service ufw stop" # FIXME: "redhat" as the distro name for RHEL is deprecated # on Avocado versions >= 50.0. This is a temporary compatibility # enabler for older runners, but should be removed soon elif detected_distro.name in ['rhel', 'fedora', 'redhat']: cmd = "systemctl stop firewalld" elif detected_distro.name == "SuSE": if detected_distro.version == 15: cmd = "systemctl stop firewalld" else: cmd = "rcSuSEfirewall2 stop" elif detected_distro.name == "centos": cmd = "service iptables stop" else: self.cancel("Distro not supported") if process.system(cmd, ignore_status=True, shell=True) != 0: self.cancel("Unable to disable firewall") output = self.session.cmd(cmd) if not output.exit_status == 0: self.cancel("Unable to disable firewall on peer") def test(self): """ Test rping """ if self.peer_networkinterface.set_mtu(self.mtu) is not None: self.fail("Failed to set mtu in peer") if self.networkinterface.set_mtu(self.mtu) is not None: self.fail("Failed to set mtu in host") self.log.info(self.test_name) logs = "> /tmp/ib_log 2>&1 &" cmd = "timeout %s %s -s %s %s" % (self.timeout, self.test_name, self.option_list[0], logs) output = self.session.cmd(cmd) if not output.exit_status == 0: self.fail("SSH connection (or) Server command failed") time.sleep(5) self.log.info("Client data - %s(%s)" % (self.test_name, self.option_list[1])) cmd = "timeout %s %s -c %s" \ % (self.timeout, self.test_name, self.option_list[1]) if process.system(cmd, shell=True, ignore_status=True) != 0: self.fail("Client command failed") time.sleep(5) self.log.info("Server data - %s(%s)" % (self.test_name, self.option_list[0])) cmd = "timeout %s cat /tmp/ib_log && rm -rf /tmp/ib_log" \ % (self.timeout) output = self.session.cmd(cmd) if not output.exit_status == 0: self.fail("Server output retrieval failed") def tearDown(self): """ unset ip """ if self.networkinterface.set_mtu('1500') is not None: self.fail("Failed to set mtu in host") if self.peer_networkinterface.set_mtu('1500') is not None: self.fail("Failed to set mtu in peer")
class VirtualizationDriverBindTest(Test): """ virtualized devices can be bound and unbound to drivers. This test verifies that for a given virtualized device. :param device: Name of the virtualized device """ def setUp(self): """ Identify the virtualized device. """ smm = SoftwareManager() for pkg in ["net-tools"]: if not smm.check_installed(pkg) and not smm.install(pkg): self.cancel("%s package is need to test" % pkg) interfaces = netifaces.interfaces() self.virtual_device = self.params.get('virtual_device') self.virtual_slot = self.params.get('virtual_slot') if "T" in self.virtual_slot: self.virtual_slot = self.virtual_slot.split("-T")[0] output = process.system_output("lsslot", shell=True) for line in output.decode("utf-8").splitlines(): if self.virtual_slot in line: self.device_type = line.split()[-1] self.device = line.split()[-2] self.count = int(self.params.get('count', default="1")) self.peer_ip = self.params.get('peer_ip', default=None) self.ipaddr = self.params.get("host_ip", default="") self.netmask = self.params.get("netmask", default="") local = LocalHost() if self.device_type in ["l-lan", "vnic"]: if self.virtual_device not in interfaces: self.cancel("%s interface is not available" % self.virtual_device) self.networkinterface = NetworkInterface(self.virtual_device, local) if self.virtual_device in local.get_default_route_interface(): self.cancel("Test could not run on default interface") 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() else: if disk.is_root_device(self.virtual_device): self.cancel("Test could not run on root disk") def is_exists_device(self, device): ''' Check whether the scsi_device is present in lsscsi output ''' devices = [] output = process.system_output("lsscsi").decode('utf-8') for line in output.splitlines(): devices.append(line.split('/')[-1].strip(' ')) if device in devices: return True return False def test(self): """ Performs driver unbind and bind for the Network virtualized device """ if self.device_type in ["l-lan", "vnic"]: if self.networkinterface.ping_check(self.peer_ip, count=5) is not None: self.cancel( "Please make sure the network peer is configured ?") else: if self.is_exists_device(self.virtual_device) is False: self.cancel("failed to detect the test disk") try: for _ in range(self.count): for operation in ["unbind", "bind"]: self.log.info( "Running %s operation for Network virtualized \ device" % operation) dict = { "vnic": "ibmvnic", "l-lan": "ibmveth", "v-scsi": "ibmvscsi", "vfc-client": "ibmvfc" } if self.device_type in dict.keys(): param = dict[self.device_type] genio.write_file( os.path.join("/sys/bus/vio/drivers/%s" % param, operation), "%s" % self.device) time.sleep(5) if self.device_type in ["l-lan", "vnic"]: self.log.info( "Running a ping test to check if unbind/bind \ affected newtwork connectivity") if self.networkinterface.ping_check(self.peer_ip, count=5) is not None: self.fail("Ping test failed. Network virtualized \ unbind/bind has affected Network connectivity" ) else: self.log.info("checking for disk available if unbind/bind \ affected to disk") if self.is_exists_device(self.virtual_device) is False: self.fail("exists device test failed.unbind/bind has \ affected disk") except CmdError as details: self.log.debug(str(details)) self.fail("Driver %s operation failed for Network virtualized \ device %s" % (operation, self.interface)) def tearDown(self): """ remove ip from interface """ if self.device_type in ["l-lan", "vnic"]: self.networkinterface.remove_ipaddr(self.ipaddr, self.netmask) self.networkinterface.restore_from_backup()
class PingPong(Test): ''' ibv_ud_pingpong test ibv_ud_pingpong tool should be installed ''' def setUp(self): ''' To check and install dependencies for the test ''' interfaces = netifaces.interfaces() self.flag = self.params.get("ext_flag", default="0") self.iface = self.params.get("interface", default="") self.peer_ip = self.params.get("peer_ip", default="") self.peer_user = self.params.get("peer_user", default="root") self.peer_password = self.params.get("peer_password", '*', default="None") self.ipaddr = self.params.get("host_ip", default="") self.netmask = self.params.get("netmask", default="") local = LocalHost() if self.iface[0:2] == 'ib': self.networkinterface = NetworkInterface(self.iface, local, if_type='Infiniband') 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) else: 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 self.iface not in interfaces: self.cancel("%s interface is not available" % self.iface) if self.peer_ip == "": self.cancel("%s peer machine is not available" % self.peer_ip) self.ca_name = self.params.get("CA_NAME", default="mlx4_0") self.gid = int(self.params.get("GID_NUM", default="0")) self.port = int(self.params.get("PORT_NUM", default="1")) self.peer_ca = self.params.get("PEERCA", default="mlx4_0") self.peer_gid = int(self.params.get("PEERGID", default="0")) self.peer_port = int(self.params.get("PEERPORT", default="1")) self.tmo = self.params.get("TIMEOUT", default="120") 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) smm = SoftwareManager() detected_distro = distro.detect() pkgs = [] if detected_distro.name == "Ubuntu": pkgs.extend(["ibverbs-utils", 'openssh-client']) cmd = "service ufw stop" # FIXME: "redhat" as the distro name for RHEL is deprecated # on Avocado versions >= 50.0. This is a temporary compatibility # enabler for older runners, but should be removed soon elif detected_distro.name in ['rhel', 'fedora', 'redhat']: pkgs.extend(["libibverbs", 'openssh-clients']) cmd = "systemctl stop firewalld" elif detected_distro.name == "SuSE": pkgs.append('openssh') if detected_distro.version == 15: cmd = "systemctl stop firewalld" else: cmd = "rcSuSEfirewall2 stop" elif detected_distro.name == "centos": pkgs.extend(['libibverbs', 'openssh-clients']) cmd = "service iptables stop" else: self.cancel("Distro not supported") if process.system(cmd, ignore_status=True, shell=True) != 0: self.cancel("Unable to disable firewall") output = self.session.cmd(cmd) if not output.exit_status == 0: self.cancel("Unable to disable firewall on peer") for pkg in pkgs: if not smm.check_installed(pkg) and not smm.install(pkg): self.cancel("%s package is need to test" % pkg) if process.system("ibstat", shell=True, ignore_status=True) != 0: self.cancel("infiniband adaptors not available") self.tool_name = self.params.get("tool") self.log.info("test with %s", self.tool_name) self.peer_iface = '' cmd = "ip addr show" output = self.session.cmd(cmd) for line in output.stdout.decode("utf-8").splitlines(): if self.peer_ip in line: self.peer_iface = line.split()[-1] break def pingpong_exec(self, arg1, arg2, arg3): ''' ping pong exec function ''' test = arg2 logs = "> /tmp/ib_log 2>&1 &" if test == "basic": test = "" cmd = "timeout %s %s -d %s -g %d -i %d %s %s %s" \ % (self.tmo, arg1, self.peer_ca, self.peer_gid, self.peer_port, test, arg3, logs) output = self.session.cmd(cmd) if not output.exit_status == 0: self.fail("ssh failed to remote machine") time.sleep(2) self.log.info("client data for %s(%s)", arg1, arg2) self.log.info("%s -d %s -g %d %s -i %d %s %s", arg1, self.ca_name, self.gid, self.peer_ip, self.port, test, arg3) tmp = "timeout %s %s -d %s -g %d -i %d %s %s %s" \ % (self.tmo, arg1, self.ca_name, self.gid, self.port, self.peer_ip, test, arg3) if process.system(tmp, shell=True, ignore_status=True) != 0: self.fail("test failed") self.log.info("server data for %s(%s)", arg1, arg2) self.log.info("%s -d %s -g %d -i %d %s %s", arg1, self.peer_ca, self.peer_gid, self.peer_port, test, arg3) cmd = "timeout %s cat /tmp/ib_log && rm -rf /tmp/ib_log" \ % self.tmo output = self.session.cmd(cmd) if not output.exit_status == 0: self.fail("test failed") def test_ib_pingpong(self): ''' test options are mandatory ext test options are depends upon user ''' # change MTU to 9000 for non-IB tests if "ib" not in self.iface and self.tool_name == "ibv_ud_pingpong": self.mtu = "9000" if self.peer_networkinterface.set_mtu(self.mtu) is not None: self.fail("Failed to set mtu in peer") if self.networkinterface.set_mtu(self.mtu) is not None: self.fail("Failed to set mtu in host") time.sleep(10) val1 = "" val2 = "" test_op = self.params.get("test_opt", default="").split(",") for val in test_op: try: val1, val2 = val.split() except ValueError: pass self.pingpong_exec(self.tool_name, val1, val2) ext_test_op = self.params.get("ext_test_opt", default="").split(",") if self.flag == "1": for val in ext_test_op: self.pingpong_exec(self.tool_name, val, "") else: self.log.info("Extended test option skipped") def tearDown(self): if self.networkinterface.set_mtu('1500') is not None: self.fail("Failed to set mtu in host") if self.peer_networkinterface.set_mtu('1500') is not None: self.fail("Failed to set mtu in peer") self.remotehost.remote_session.quit()
class Netperf(Test): """ Netperf Test """ def setUp(self): """ To check and install dependencies for the test """ self.peer_user = self.params.get("peer_user", default="root") self.peer_public_ip = self.params.get("peer_public_ip", default="") 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="") 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'] if detected_distro.name == "Ubuntu": pkgs.append('openssh-client') elif detected_distro.name == "SuSE": pkgs.append('openssh') else: pkgs.append('openssh-clients') 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.timeout = self.params.get("TIMEOUT", default="600") 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.netperf_run = str(self.params.get("NETSERVER_RUN", default=0)) self.netperf = os.path.join(self.teststmpdir, 'netperf') netperf_download = self.params.get("netperf_download", default="https:" "//github.com/HewlettPackard/" "netperf/archive/netperf-2.7.0.zip") tarball = self.fetch_asset(netperf_download, expire='7d') archive.extract(tarball, self.netperf) self.version = "%s-%s" % ("netperf", os.path.basename(tarball.split('.zip')[0])) self.neperf = os.path.join(self.netperf, self.version) destination = "%s:/tmp" % self.peer_ip output = self.session.copy_files(self.neperf, destination, recursive=True) if not output: self.cancel("unable to copy the netperf into peer machine") cmd = "cd /tmp/%s;./configure ppc64le;make" % self.version output = self.session.cmd(cmd) if not output.exit_status == 0: self.fail("test failed because command failed in peer machine") os.chdir(self.neperf) process.system('./configure ppc64le', shell=True) build.make(self.neperf) self.perf = os.path.join(self.neperf, 'src', 'netperf') self.expected_tp = self.params.get("EXPECTED_THROUGHPUT", default="90") self.duration = self.params.get("duration", default="300") self.min = self.params.get("minimum_iterations", default="1") self.max = self.params.get("maximum_iterations", default="15") self.option = self.params.get("option", default='') def test(self): """ netperf test """ if self.netperf_run == '1': cmd = "chmod 777 /tmp/%s/src" % self.version output = self.session.cmd(cmd) if not output.exit_status == 0: self.fail("test failed because netserver not available") cmd = "/tmp/%s/src/netserver" % self.version output = self.session.cmd(cmd) if not output.exit_status == 0: self.fail("test failed because netserver not available") speed = int(read_file("/sys/class/net/%s/speed" % self.iface)) cmd = "timeout %s %s -H %s" % (self.timeout, self.perf, self.peer_ip) if self.option != "": if "TCP_STREAM" in self.option: socket_size = process.run("cat /proc/sys/net/ipv4/tcp_rmem", shell=True, ignore_status=True) cmd = "%s %s -m %s" % (cmd, self.option, socket_size.stdout.decode("utf-8").split('\t')[1]) elif "UDP_STREAM" in self.option: socket_size = process.run("cat /proc/sys/net/ipv4/udp_mem", shell=True, ignore_status=True) cmd = "%s %s -m %s" % (cmd, self.option, socket_size.stdout.decode("utf-8").split('\t')[1]) else: cmd = "%s -t %s" % (cmd, self.option) cmd = "%s -l %s -i %s,%s" % (cmd, self.duration, self.max, self.min) result = process.run(cmd, shell=True, ignore_status=True) if result.exit_status != 0: self.fail("FAIL: Run failed") for line in result.stdout.decode("utf-8").splitlines(): if line and 'Throughput' in line.split()[-1]: tput = int(result.stdout.decode("utf-8").split()[-1]. 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')) if 'WARNING' in result.stdout.decode("utf-8"): self.log.warn('Test completed with warning') def tearDown(self): """ removing the data in peer machine """ cmd = "pkill netserver; rm -rf /tmp/%s" % self.version output = self.session.cmd(cmd) if not output.exit_status == 0: self.fail("test failed because peer sys not connected") 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()
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_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="") 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) remotehost_public = RemoteHost(self.peer_public_ip, self.peer_user, password=self.peer_password) self.peer_public_networkinterface = NetworkInterface( self.peer_interface, 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) 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") try: self.peer_networkinterface.set_mtu('1500') except Exception: self.peer_public_networkinterface.set_mtu('1500') self.networkinterface.remove_ipaddr(self.ipaddr, self.netmask) self.networkinterface.restore_from_backup()
class ReceiveMulticastTest(Test): ''' check multicast receive using ping tool ''' def setUp(self): ''' To check and install dependencies for the test ''' self.peer = self.params.get("peer_ip", default="") self.user = self.params.get("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, user=self.user, password=self.peer_password) self.count = self.params.get("count", default="500000") smm = SoftwareManager() pkgs = ["net-tools"] detected_distro = distro.detect() if detected_distro.name == "Ubuntu": pkgs.extend(["openssh-client", "iputils-ping"]) elif detected_distro.name == "SuSE": pkgs.extend(["openssh", "iputils"]) else: pkgs.extend(["openssh-clients", "iputils"]) for pkg in pkgs: if not smm.check_installed(pkg) and not smm.install(pkg): self.cancel("%s package is need to test" % pkg) if self.peer == "": self.cancel("peer ip should specify in input") cmd = "ip addr show | grep %s" % self.peer output = self.session.cmd(cmd) result = "" result = result.join(output.stdout.decode("utf-8")) self.peerif = result.split()[-1] if self.peerif == "": self.cancel("unable to get peer interface") cmd = "ip -f inet -o addr show %s | awk '{print $4}' | cut -d / -f1"\ % self.iface self.local_ip = process.system_output(cmd, shell=True).strip() if self.local_ip == "": self.cancel("unable to get local ip") def test_multicast(self): ''' ping to peer machine ''' cmd = "echo 0 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts" if process.system(cmd, shell=True, verbose=True, ignore_status=True) != 0: self.fail("unable to set value to icmp_echo_ignore_broadcasts") cmd = "ip link set %s allmulticast on" % self.iface if process.system(cmd, shell=True, verbose=True, ignore_status=True) != 0: self.fail("unable to set all mulicast option to test interface") cmd = "ip route add 224.0.0.0/4 dev %s" % self.peerif output = self.session.cmd(cmd) if not output.exit_status == 0: self.fail("Unable to add route for Peer interafce") cmd = "timeout 600 ping -I %s 224.0.0.1 -c %s -f" % (self.peerif, self.count) output = self.session.cmd(cmd) if not output.exit_status == 0: self.fail("multicast test failed") def tearDown(self): ''' delete multicast route and turn off multicast option ''' cmd = "ip route del 224.0.0.0/4" output = self.session.cmd(cmd) if not output.exit_status == 0: self.log.info("Unable to delete multicast route added for peer") cmd = "echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts" if process.system(cmd, shell=True, verbose=True, ignore_status=True) != 0: self.log.info("unable to unset all mulicast option") cmd = "ip link set %s allmulticast off" % self.iface if process.system(cmd, shell=True, verbose=True, ignore_status=True) != 0: self.log.info("unable to unset all mulicast option") self.networkinterface.remove_ipaddr(self.ipaddr, self.netmask) self.networkinterface.restore_from_backup()
class NetworkconfigTest(Test): ''' check Network_configuration using ethtool and lspci ''' def setUp(self): ''' To check and install dependencies for the test ''' sm = SoftwareManager() for pkg in ["ethtool", "net-tools"]: if not sm.check_installed(pkg) and not sm.install(pkg): self.cancel("%s package is need to test" % pkg) interfaces = netifaces.interfaces() self.iface = self.params.get("interface") 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() cmd = "basename -a /sys/class/net/%s/device/driver/module/drivers/*" % self.iface output = process.system_output(cmd, shell=True).decode("utf-8") for line in output.splitlines(): if line.split(':')[0] in ['pci', 'vio']: self.iface_type, self.driver = line.split(':') break self.businfo = self.get_bus_info(self.iface, self.iface_type) @staticmethod def get_bus_info(iface, iface_type): if iface_type == 'vio': cmd = "lscfg -vl %s" % iface for line in process.system_output(cmd, shell=True).decode("utf-8") \ .splitlines(): if iface in line: if "T" in line: loc_id = line.split()[-1].split("-T")[0] else: loc_id = line.split()[-1] for line in process.system_output("lsslot", shell=True).decode("utf-8") \ .splitlines(): if loc_id in line: return line.split()[-2] else: cmd = "ethtool -i %s" % iface for line in process.system_output(cmd, shell=True).decode("utf-8") \ .splitlines(): if 'bus-info' in line: return line.split()[-1] def test_driver_check(self): ''' driver match check using lspci and ethtool ''' cmd = "ethtool -i %s" % self.iface for line in process.system_output(cmd, shell=True).decode("utf-8") \ .splitlines(): if 'driver' in line: driver = line.split()[-1] self.log.info(driver) if self.driver != driver: self.fail("mismatch in driver information") def get_network_sysfs_param(self, param): ''' To finding the value for all parameters ''' cmd = r"cat /sys/module/%s/drivers/%s:%s/%s/net/%s/%s" % \ (self.driver, self.iface_type, self.driver, self.businfo, self.iface, param) return process.system_output(cmd, shell=True).decode("utf-8").strip() def test_mtu_check(self): ''' comparing mtu value ''' mtu = self.get_network_sysfs_param("mtu") self.log.info("mtu value is %s" % mtu) mtuval = process.system_output("ip link show %s" % self.iface, shell=True).decode("utf-8").split()[4] self.log.info("through ip link show, mtu value is %s" % mtuval) if mtu != mtuval: self.fail("mismatch in mtu") def test_speed_check(self): ''' Comparing speed ''' speed = self.get_network_sysfs_param("speed") cmd = "ethtool %s" % self.iface for line in process.system_output(cmd, shell=True).decode("utf-8") \ .splitlines(): if 'Speed' in line: eth_speed = line.split()[-1].strip('Mb/s') if speed != eth_speed: self.fail("mis match in speed") def test_mac_aadr_check(self): ''' comparing mac address ''' address = self.get_network_sysfs_param("address") self.log.info("mac address is %s" % address) hw_addr = netifaces.ifaddresses(self.iface)[netifaces.AF_LINK] hw_addr = hw_addr[0]['addr'] if hw_addr != address: self.fail("mismatch in hardware address") def test_duplex_check(self): ''' comparing duplex ''' duplex = self.get_network_sysfs_param("duplex") self.log.info("transmission mode is %s" % duplex) cmd = "ethtool %s" % self.iface for line in process.system_output(cmd, shell=True).decode("utf-8") \ .splitlines(): if 'Duplex' in line: eth_duplex = line.split()[-1] if str(duplex).capitalize() != eth_duplex: self.fail("mismatch in duplex") def tearDown(self): ''' unset ip for host interface ''' 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.")
class SwitchTest(Test): ''' switch port test ''' def setUp(self): ''' To get all the parameter for the test ''' interfaces = netifaces.interfaces() interface = self.params.get("interface") if interface not in interfaces: self.cancel("%s interface is not available" % interface) self.iface = interface 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.peer = self.params.get("peer_ip") if not self.peer: self.cancel("No peer provided") if self.networkinterface.ping_check(self.peer, count=2) is not None: self.cancel("No connection to peer") self.switch_name = self.params.get("switch_name", '*', default="") self.userid = self.params.get("userid", '*', default="") self.password = self.params.get("password", '*', default="") self.port_id = self.params.get("port_id", default="") if not self.port_id: self.cancel("user should specify port id") self.switch_login(self.switch_name, self.userid, self.password) def switch_login(self, ip, username, password): ''' Login method for remote fc switch ''' self.tnc = paramiko.SSHClient() self.tnc.set_missing_host_key_policy(paramiko.AutoAddPolicy()) self.tnc.connect(ip, username=username, password=password, look_for_keys=False, allow_agent=False) self.log.info("SSH connection established to " + ip) self.remote_conn = self.tnc.invoke_shell() self.log.info("Interactive SSH session established") assert self.remote_conn self.remote_conn.send("iscli" + '\n') def _send_only_result(self, command, response): output = response.decode("utf-8").splitlines() if command in output[0]: output.pop(0) output.pop() output = [element.lstrip() + '\n' for element in output] response = ''.join(output) response = response.strip() self.log.info(''.join(response)) return ''.join(response) def run_switch_command(self, command, timeout=300): ''' Run command method for running commands on fc switch ''' self.prompt = "#" self.log.info("Running the %s command on fc/nic switch", command) if not hasattr(self, 'tnc'): self.fail("telnet connection to the fc/nic switch not yet done") self.remote_conn.send(command + '\n') response = self.remote_conn.recv(1000) return self._send_only_result(command, response) def test(self): ''' switch port enable and disable test ''' self.log.info("Enabling the privilege mode") self.run_switch_command("enable") self.log.info("Entering configuration mode") self.run_switch_command("conf t") cmd = "interface port %s" % self.port_id self.run_switch_command(cmd) self.run_switch_command("shutdown") time.sleep(5) if self.networkinterface.ping_check(self.peer, count=5) is None: self.fail("pinging after disable port") self.run_switch_command("no shutdown") time.sleep(5) if self.networkinterface.ping_check(self.peer, count=5) is not None: self.fail("ping test failed") self.run_switch_command("end") def tearDown(self): ''' unset ip address ''' 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.")
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 detected_distro.name == "Ubuntu": cmd_fw = "service ufw stop" elif detected_distro.name in ['rhel', 'fedora', 'redhat']: cmd_fw = "systemctl stop firewalld" elif detected_distro.name == "SuSE": if detected_distro.version == 15: cmd_fw = "systemctl stop firewalld" else: cmd_fw = "rcSuSEfirewall2 stop" elif detected_distro.name == "centos": cmd_fw = "service iptables stop" else: self.cancel("Distro not supported") if process.system(cmd_fw, ignore_status=True, shell=True) != 0: self.cancel("Unable to disable firewall on host") output = self.session.cmd(cmd_fw) if output.exit_status != 0: self.cancel("Unable to disable firewall service on peer") 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()