示例#1
0
 def test_targetconfig(self):
     """
     Configures the peer NVMf.
     """
     self.session = Session(self.peer_ips[0],
                            user=self.peer_user,
                            password=self.peer_password)
     if not self.session.connect():
         self.fail("failed connecting to peer")
     self.create_cfg_file()
     destination = "%s:/tmp/" % self.peer_ips[0]
     output = self.session.copy_files(self.cfg_file, destination)
     if not output:
         self.cancel("unable to copy the NVMf cfg file into peer machine")
     for mdl in ["nvmet", "nvmet-rdma"]:
         cmd = "modprobe %s" % mdl
         output = self.session.cmd(cmd)
         if output.exit_status:
             self.cancel("%s is not loadable on the peer" % mdl)
     msg = "which nvmetcli"
     output = self.session.cmd(msg)
     if output.exit_status:
         self.cancel("nvmetcli is not installed on the peer")
     msg = "nvmetcli restore /tmp/nvmf.cfg"
     output = self.session.cmd(msg)
     if output.exit_status:
         self.fail("nvmetcli setup config fails on peer")
    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="")
        self.hbond = self.params.get("hbond", default=False)
        local = LocalHost()
        if self.hbond:
            self.networkinterface = NetworkInterface(self.iface, local,
                                                     if_type='Bond')
        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, user=self.user,
                               password=self.peer_password)
        if not self.session.connect():
            self.cancel("failed connecting to peer")
        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 setUp(self):
        '''
        set up required packages and gather necessary test inputs
        '''
        self.install_packages()
        self.rsct_service_start()
        self.hmc_ip = self.get_mcp_component("HMCIPAddr")
        if not self.hmc_ip:
            self.cancel("HMC IP not got")
        self.vioses = self.params.get("vioses", default=None)
        self.hmc_pwd = self.params.get("hmc_pwd", '*', default=None)
        self.hmc_username = self.params.get("hmc_username", '*', default=None)
        self.count = self.params.get("count", default=1)
        # TO_DO: self.skip_host parameter can be remove
        # if script is self reliable to find bootable disk
        self.skip_host = self.params.get("skip_host", default=None)
        self.vfc_id = self.params.get("vfchost_id", default=None)
        self.vfchost_count = int(self.params.get("vfc_count", default=1))
        # Since the command in each layer doesn't take same time to complete
        # there is delay observed in status reflect (like host and multipath).
        # even though we have used the wait.wait_for funtion, this is not
        # enough to handle the case. since the operation flow reflect in 3
        # stages (lpar, HMC, vios), giving a short sleep time helps the flow
        # to happen smoother. Hence adding the sleep time after each major
        # operation like unamp, map, define, undefine, create, delete.
        # we can remove this sleep time in future if the flow happens smoother
        self.opp_sleep_time = 20
        self.lpar = self.get_partition_name("Partition Name")
        if not self.lpar:
            self.cancel("LPAR Name not got from lparstat command")
        self.session = Session(self.hmc_ip,
                               user=self.hmc_username,
                               password=self.hmc_pwd)
        if not self.session.connect():
            self.cancel("failed connecting to HMC")
        cmd = 'lssyscfg -r sys  -F name'
        output = self.session.cmd(cmd).stdout_text
        self.server = ''
        for line in output.splitlines():
            if line in self.lpar:
                self.server = line
        if not self.server:
            self.cancel("Managed System not got")
        self.dic_list = []
        self.err_mesg = []
        for vios in self.vioses.split(" "):
            for vfchost in self.get_vfchost(vios):
                vfc_dic = {}
                vfc_dic["vios"] = vios
                vfc_dic["vfchost"] = vfchost
                vfc_dic["fcs"] = self.get_fcs_name(vfchost, vios)
                vfc_dic["vfc_client"] = self.get_vfc_client(vfchost, vios)
                vfc_dic["paths"] = self.get_paths(vfc_dic["vfc_client"])
                if vfc_dic["vfc_client"] != self.skip_host:
                    self.dic_list.append(vfc_dic)

        self.log.info("complete list : %s" % self.dic_list)
示例#4
0
 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.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.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.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)
     self.setup_ip()
     self.err = []
示例#5
0
 def _connect(self):
     session = Session(host=self.host,
                       port=self.port,
                       user=self.username,
                       key=self.key,
                       password=self.password)
     if session.connect():
         return session
     msg = f"Failed connecting {self.host}:{self.port}"
     raise NWException(msg)
示例#6
0
    def test_rmdev_viosfailover(self):
        '''
        using mrdev and mkdev command to check vios failover works
        '''

        self.session = Session(self.vios_ip,
                               user=self.vios_user,
                               password=self.vios_pwd)
        if not wait.wait_for(self.session.connect, timeout=30):
            self.fail("Failed connecting to VIOS")

        cmd = "ioscli lsmap -all -vnic -cpid %s" % self.lpar_id
        vnic_servers = self.session.cmd(cmd).stdout_text.splitlines()
        device = self.find_device(self.mac_id[0])
        temp_idx = vnic_servers.index("Client device name:" + device)
        vnic_server = vnic_servers[temp_idx - 5].split()[0]

        cmd = "ioscli lsmap -vnic -vadapter %s" % vnic_server
        output = self.session.cmd(cmd)

        vnic_backing_device = None
        for line in output.stdout_text.splitlines():
            if 'Backing device' in line:
                vnic_backing_device = line.split(':')[-1]

        before = self.get_active_device_logport(self.slot_num[0])
        self.log.debug("Active backing device before : %s", before)

        self.validate_vios_command('rmdev -l %s' % vnic_server, 'Defined')
        if vnic_backing_device:
            self.validate_vios_command('rmdev -l %s' % vnic_backing_device,
                                       'Defined')

        time.sleep(10)

        for backing_dev in self.backing_dev_list().splitlines():
            if backing_dev.startswith('%s,' % self.slot_num[0]):
                backing_dev = backing_dev.strip('%s,"' % self.slot_num[0])
                if 'Powered Off' not in backing_dev:
                    self.fail("Failover did not occur")

        time.sleep(60)

        if vnic_backing_device:
            self.validate_vios_command('mkdev -l %s' % vnic_backing_device,
                                       'Available')
        self.validate_vios_command('mkdev -l %s' % vnic_server, 'Available')

        networkinterface = NetworkInterface(device, self.local)
        if networkinterface.ping_check(self.peer_ip[0], count=5) is not None:
            self.fail("Ping test failed. Network virtualized \
                      vios failover has affected Network connectivity")
        self.check_dmesg_error()
示例#7
0
 def setUp(self):
     """
     test parameters
     """
     self.parameters()
     self.switch_login(self.switch_name, self.userid, self.password)
     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")
     self.get_ips()
    def test_rmdev_viosfailover(self):
        '''
        using mrdev and mkdev command to check vios failover works
        '''

        self.session = Session(self.vios_ip,
                               user=self.vios_user,
                               password=self.vios_pwd)
        if not self.session.connect():
            self.fail("Failed connecting to VIOS")

        cmd = "ioscli lsmap -all -vnic -cpid %s" % self.lpar_id
        vnic_server = self.session.cmd(
            cmd).stdout_text.splitlines()[2].split()[0]

        cmd = "ioscli lsmap -vnic -vadapter %s" % vnic_server
        output = self.session.cmd(cmd)

        vnic_backing_device = None
        for line in output.stdout_text.splitlines():
            if 'Backing device' in line:
                vnic_backing_device = line.split(':')[-1]

        before = self.get_active_device_logport(self.slot_num[0])
        self.log.debug("Active backing device before : %s", before)

        self.validate_vios_command('rmdev -l %s' % vnic_server, 'Defined')
        if vnic_backing_device:
            self.validate_vios_command('rmdev -l %s' % vnic_backing_device,
                                       'Defined')

        after = self.get_active_device_logport(self.slot_num[0])
        self.log.debug("Active backing device after: %s", after)

        if before == after:
            self.fail("failover not occour")
        time.sleep(20)

        if vnic_backing_device:
            self.validate_vios_command('mkdev -l %s' % vnic_backing_device,
                                       'Available')
        self.validate_vios_command('mkdev -l %s' % vnic_server, 'Available')

        device = self.find_device(self.mac_id[0])
        networkinterface = NetworkInterface(device, self.local)
        if networkinterface.ping_check(self.peer_ip[0], count=5) is not None:
            self.fail("Ping test failed. Network virtualized \
                      vios failover has affected Network connectivity")
        self.check_dmesg_error()
示例#9
0
 def setUp(self):
     '''
     set up required packages and gather necessary test inputs
     '''
     self.install_packages()
     self.rsct_service_start()
     self.hmc_ip = self.get_mcp_component("HMCIPAddr")
     if not self.hmc_ip:
         self.cancel("HMC IP not got")
     self.hmc_pwd = self.params.get("hmc_pwd", '*', default=None)
     self.hmc_username = self.params.get("hmc_username", '*', default=None)
     self.count = self.params.get("count", default=1)
     self.skip_drc = self.params.get("skip_drc_name", default=None)
     self.opp_sleep_time = 150
     self.lpar = self.get_partition_name("Partition Name")
     if not self.lpar:
         self.cancel("LPAR Name not got from lparstat command")
     self.session = Session(self.hmc_ip,
                            user=self.hmc_username,
                            password=self.hmc_pwd)
     if not self.session.connect():
         self.cancel("failed connecting to HMC")
     cmd = 'lssyscfg -r sys  -F name'
     output = self.session.cmd(cmd)
     self.server = ''
     for line in output.stdout_text.splitlines():
         if line in self.lpar:
             self.server = line
     if not self.server:
         self.cancel("Managed System not got")
     self.dic_list = []
     cmd = 'lshwres -r virtualio --rsubtype fc --level lpar -m %s \
            --filter "lpar_names=%s"' % (self.server, self.lpar)
     for line in self.session.cmd(cmd).stdout_text.splitlines():
         self.vfc_dic = {}
         for i in line.split(","):
             if i.split("=")[0] == "slot_num":
                 self.vfc_dic["c_slot"] = i.split("=")[-1]
             elif i.split("=")[0] == "remote_slot_num":
                 self.vfc_dic["r_slot"] = i.split("=")[-1]
             elif i.split("=")[0] == "remote_lpar_name":
                 self.vfc_dic["r_lpar"] = i.split("=")[-1]
         self.vfc_dic["wwpn"] = self.get_wwpn(self.vfc_dic["c_slot"])
         self.vfc_dic["drc"] = self.get_drc_name(self.vfc_dic["c_slot"])
         self.vfc_dic["paths"] = self.get_paths(self.vfc_dic["drc"])
         if self.vfc_dic["drc"] != self.skip_drc:
             self.dic_list.append(self.vfc_dic)
     self.log.info("complete list : %s" % self.dic_list)
示例#10
0
 def test_cleartargetconfig(self):
     """
     Clears the peer NVMf
     """
     self.session = Session(self.peer_ips[0],
                            user=self.peer_user,
                            password=self.peer_password)
     if not self.session.connect():
         self.fail("failed connecting to peer")
     msg = "nvmetcli clear"
     output = self.session.cmd(msg)
     if output.exit_status:
         self.fail("nvmetcli clear config remove on peer")
     msg = "rm -rf /tmp/nvmf.cfg"
     output = self.session.cmd(msg)
     if output.exit_status:
         self.log.warn("removing config file on peer failed")
示例#11
0
 def setUp(self):
     '''
     Gather necessary test inputs.
     '''
     self.disk = self.params.get('disk', default=None)
     self.num_of_dlpar = int(self.params.get("num_of_dlpar", default='1'))
     self.vios_ip = self.params.get('vios_ip', '*', default=None)
     self.vios_user = self.params.get('vios_username', '*', default=None)
     self.vios_pwd = self.params.get('vios_pwd', '*', default=None)
     self.session = Session(self.vios_ip,
                            user=self.vios_user,
                            password=self.vios_pwd)
     self.session.connect()
     cmd = "lscfg -l %s" % self.disk
     for line in process.system_output(cmd, shell=True).decode("utf-8") \
                                                       .splitlines():
         if self.disk in line:
             self.slot = line.split()[-1].split('-')[-2]
     cmd = "ioscli lsdev -slots"
     output = self.session.cmd(cmd)
     for line in output.stdout_text.splitlines():
         if self.slot in line:
             self.host = line.split()[-1]
     self.log.info(self.host)
     cmd = "lsscsi -vl"
     output = process.system_output(cmd, shell=True)
     for line in output.decode("utf-8").splitlines():
         if self.disk in line:
             value = line.split()[0].replace('[', '').replace(']', '')
     for line in output.decode("utf-8").splitlines():
         if value in line:
             if "dir" in line:
                 self.disk_dir = line.split()[-1].replace('[', '') \
                                                 .replace(']', '')
     cmd = r"cat %s/inquiry" % self.disk_dir
     output = process.system_output(cmd, shell=True)
     self.hdisk_name = output.split()[2].strip(b'0001').decode("utf-8")
     self.log.info(self.hdisk_name)
     cmd = "ioscli lsmap -all|grep -p %s" % self.hdisk_name
     output = self.session.cmd(cmd)
     for line in output.stdout_text.splitlines():
         if "VTD" in line:
             self.vscsi = line.split()[-1]
     if not self.vscsi:
         self.cancel("failed to get vscsi")
     self.log.info(self.vscsi)
 def setUp(self):
     '''
     set up required packages and gather necessary test inputs
     '''
     smm = SoftwareManager()
     packages = [
         'src', 'rsct.basic', 'rsct.core.utils', 'rsct.core', 'DynamicRM',
         'powerpc-utils'
     ]
     for pkg in packages:
         if not smm.check_installed(pkg) and not smm.install(pkg):
             self.cancel('%s is needed for the test to be run' % pkg)
     self.hmc_ip = self.get_mcp_component("HMCIPAddr")
     if not self.hmc_ip:
         self.cancel("HMC IP not got")
     self.hmc_pwd = self.params.get("hmc_pwd", '*', default=None)
     self.hmc_username = self.params.get("hmc_username", '*', default=None)
     self.lpar = self.get_partition_name("Partition Name")
     if not self.lpar:
         self.cancel("LPAR Name not got from lparstat command")
     self.session = Session(self.hmc_ip,
                            user=self.hmc_username,
                            password=self.hmc_pwd)
     if not self.session.connect():
         self.cancel("failed connetion to HMC")
     cmd = 'lssyscfg -r sys  -F name'
     output = self.session.cmd(cmd)
     self.server = ''
     for line in output.stdout_text.splitlines():
         if line in self.lpar:
             self.server = line
             break
     if not self.server:
         self.cancel("Managed System not got")
     self.sriov_adapter = self.params.get('sriov_adapter',
                                          '*',
                                          default=None).split(' ')
     self.sriov_port = self.params.get('sriov_port', '*',
                                       default=None).split(' ')
     self.ipaddr = self.params.get('ipaddr', '*', default="").split(' ')
     self.netmask = self.params.get('netmasks', '*', default="").split(' ')
     self.peer_ip = self.params.get('peer_ip', '*', default="").split(' ')
     self.mac_id = self.params.get('mac_id',
                                   default="02:03:03:03:03:01").split(' ')
     self.mac_id = [mac.replace(':', '') for mac in self.mac_id]
     self.local = LocalHost()
示例#13
0
 def setUp(self):
     '''
     Gather necessary test inputs.
     '''
     self.interface = self.params.get('interface', default=None)
     self.ipaddr = self.params.get("host_ip", default="")
     self.netmask = self.params.get("netmask", default="")
     self.peer_ip = self.params.get('peer_ip', default=None)
     self.num_of_dlpar = int(self.params.get("num_of_dlpar", default='1'))
     self.vios_ip = self.params.get('vios_ip', '*', default=None)
     self.vios_user = self.params.get('vios_username', '*', default=None)
     self.vios_pwd = self.params.get('vios_pwd', '*', default=None)
     self.session = Session(self.vios_ip,
                            user=self.vios_user,
                            password=self.vios_pwd)
     self.session.connect()
     local = LocalHost()
     self.networkinterface = NetworkInterface(self.interface, 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 = "lscfg -l %s" % self.interface
     for line in process.system_output(cmd, shell=True).decode("utf-8") \
                                                       .splitlines():
         if self.interface in line:
             self.slot = line.split()[-1].split('-')[-2]
     cmd = "ioscli lsmap -all -net"
     output = self.session.cmd(cmd)
     for line in output.stdout_text.splitlines():
         if self.slot in line:
             self.iface = line.split()[0]
     cmd = "ioscli lsmap -vadapter %s -net" % self.iface
     output = self.session.cmd(cmd)
     for line in output.stdout_text.splitlines():
         if "SEA" in line:
             self.sea = line.split()[-1]
     if not self.sea:
         self.cancel("failed to get SEA")
     self.log.info(self.sea)
     if self.networkinterface.ping_check(self.peer_ip, count=5) is not None:
         self.cancel("peer connection is failed")
示例#14
0
class DlparTest(Test):
    '''
    DLPAR disk script does vscsi device add,remove.
    Update the details in yaml file.
    '''
    def setUp(self):
        '''
        Gather necessary test inputs.
        '''
        self.disk = self.params.get('disk', default=None)
        self.num_of_dlpar = int(self.params.get("num_of_dlpar", default='1'))
        self.vios_ip = self.params.get('vios_ip', '*', default=None)
        self.vios_user = self.params.get('vios_username', '*', default=None)
        self.vios_pwd = self.params.get('vios_pwd', '*', default=None)
        self.session = Session(self.vios_ip,
                               user=self.vios_user,
                               password=self.vios_pwd)
        self.session.connect()
        cmd = "lscfg -l %s" % self.disk
        for line in process.system_output(cmd, shell=True).decode("utf-8") \
                                                          .splitlines():
            if self.disk in line:
                self.slot = line.split()[-1].split('-')[-2]
        cmd = "ioscli lsdev -slots"
        output = self.session.cmd(cmd)
        for line in output.stdout_text.splitlines():
            if self.slot in line:
                self.host = line.split()[-1]
        self.log.info(self.host)
        cmd = "lsscsi -vl"
        output = process.system_output(cmd, shell=True)
        for line in output.decode("utf-8").splitlines():
            if self.disk in line:
                value = line.split()[0].replace('[', '').replace(']', '')
        for line in output.decode("utf-8").splitlines():
            if value in line:
                if "dir" in line:
                    self.disk_dir = line.split()[-1].replace('[', '') \
                                                    .replace(']', '')
        cmd = r"cat %s/inquiry" % self.disk_dir
        output = process.system_output(cmd, shell=True)
        self.hdisk_name = output.split()[2].strip(b'0001').decode("utf-8")
        self.log.info(self.hdisk_name)
        cmd = "ioscli lsmap -all|grep -p %s" % self.hdisk_name
        output = self.session.cmd(cmd)
        for line in output.stdout_text.splitlines():
            if "VTD" in line:
                self.vscsi = line.split()[-1]
        if not self.vscsi:
            self.cancel("failed to get vscsi")
        self.log.info(self.vscsi)

    def dlpar_remove(self):
        '''
        dlpar remove operation
        '''
        cmd = "ioscli rmvdev -vdev %s" % self.hdisk_name
        output = self.session.cmd(cmd)
        self.log.info(output.stdout_text)
        if output.exit_status != 0:
            self.fail("failed dlpar remove operation")

    def dlpar_add(self):
        '''
        dlpar add operation
        '''
        cmd = "ioscli mkvdev -vdev %s -vadapter %s -dev %s" % (
            self.hdisk_name, self.host, self.vscsi)
        output = self.session.cmd(cmd)
        self.log.info(output.stdout_text)
        if output.exit_status != 0:
            self.fail("Failed dlpar add operation")

    def test_dlpar(self):
        '''
        vscsi dlpar remove and add operation
        '''
        for _ in range(self.num_of_dlpar):
            self.dlpar_remove()
            self.dlpar_add()

    def tearDown(self):
        self.session.quit()
示例#15
0
 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")
示例#16
0
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()
示例#17
0
class Ping6(Test):
    """
    ping6 Test.
    """

    def setUp(self):
        """
        Setup and install dependencies for the test.
        """
        self.test_name = "ping6"
        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()
        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"])
        smm = SoftwareManager()
        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_iface = self.params.get("peer_interface", default="")
        self.ipv6_peer = self.params.get("peer_ipv6", 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()
        process.system("ifup %s" % self.iface)
        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.timeout = "2m"
        self.local_ip = netifaces.ifaddresses(self.iface)[AF_INET][0]['addr']
        if 10 in netifaces.ifaddresses(self.iface):
            self.l_v6 = netifaces.ifaddresses(self.iface)[AF_INET6][0]['addr']
        else:
            self.l_v6 = ""
        self.option = self.option.replace("peer_interface", self.peer_iface)
        self.option = self.option.replace("interface", self.iface)
        self.option = self.option.replace("local_ipv6", self.l_v6)
        self.option = self.option.replace("peer_ipv6", self.ipv6_peer)
        self.option = self.option.replace("local_ip", self.local_ip)
        self.option = self.option.replace("peer_ip", self.peer_ip)
        self.option_list = self.option.split(",")
        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)

        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 ping6
        """
        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" % (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[0]))
        cmd = "timeout %s %s %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[1]))
        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")
        self.remotehost.remote_session.quit()
示例#18
0
    def setUp(self):
        '''
        check the availability of perftest package installed
        perftest package should be installed
        '''
        smm = SoftwareManager()
        detected_distro = distro.detect()
        pkgs = ["perftest"]
        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)
        interfaces = netifaces.interfaces()
        self.iface = self.params.get("interface", default="")
        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")
        self.ipaddr = self.params.get("host_ip", default="")
        self.netmask = self.params.get("netmask", default="")
        if self.iface[0:2] == 'ib':
            configure_network.set_ip(self.ipaddr,
                                     self.netmask,
                                     self.iface,
                                     interface_type='Infiniband')
        else:
            configure_network.set_ip(self.ipaddr,
                                     self.netmask,
                                     self.iface,
                                     interface_type='Ethernet')
        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.port = self.params.get("PORT_NUM", default="1")
        self.peer_ca = self.params.get("PEERCA", default="mlx4_0")
        self.peer_port = self.params.get("PEERPORT", default="1")
        self.tmo = self.params.get("TIMEOUT", default="600")
        self.tool_name = self.params.get("tool")
        if self.tool_name == "":
            self.cancel("should specify tool name")
        self.log.info("test with %s", self.tool_name)
        self.test_op = self.params.get("test_opt", default="")
        self.mtu = self.params.get("mtu", default=1500)
        self.peerinfo = PeerInfo(self.peer_ip,
                                 peer_user=self.peer_user,
                                 peer_password=self.peer_password)
        self.peer_interface = self.peerinfo.get_peer_interface(self.peer_ip)

        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")
示例#19
0
 def setUp(self):
     '''
     set up required packages and gather necessary test inputs
     '''
     smm = SoftwareManager()
     packages = [
         'src', 'rsct.basic', 'rsct.core.utils', 'NetworkManager',
         'rsct.core', 'DynamicRM', 'powerpc-utils'
     ]
     for pkg in packages:
         if not smm.check_installed(pkg) and not smm.install(pkg):
             self.cancel('%s is needed for the test to be run' % pkg)
     self.hmc_ip = self.get_mcp_component("HMCIPAddr")
     if not self.hmc_ip:
         self.cancel("HMC IP not got")
     self.hmc_pwd = self.params.get("hmc_pwd", '*', default=None)
     self.hmc_username = self.params.get("hmc_username", '*', default=None)
     self.lpar = self.get_partition_name("Partition Name")
     if not self.lpar:
         self.cancel("LPAR Name not got from lparstat command")
     self.session = Session(self.hmc_ip,
                            user=self.hmc_username,
                            password=self.hmc_pwd)
     if not self.session.connect():
         self.cancel("failed connetion to HMC")
     cmd = 'lssyscfg -r sys  -F name'
     output = self.session.cmd(cmd)
     self.server = ''
     for line in output.stdout_text.splitlines():
         if line in self.lpar:
             self.server = line
             break
     if not self.server:
         self.cancel("Managed System not got")
     self.sriov_adapter = self.params.get('sriov_adapter',
                                          '*',
                                          default=None).split(' ')
     self.sriov_port = self.params.get('sriov_port', '*',
                                       default=None).split(' ')
     self.ipaddr = self.params.get('ipaddr', '*', default="").split(' ')
     self.netmask = self.params.get('netmasks', '*', default="").split(' ')
     self.prefix = self.netmask_to_cidr(self.netmask[0])
     self.peer_ip = self.params.get('peer_ip', '*', default="").split(' ')
     self.mac_id = self.params.get('mac_id',
                                   default="02:03:03:03:03:01").split(' ')
     self.mac_id = [mac.replace(':', '') for mac in self.mac_id]
     self.migratable = self.params.get('migratable', '*', default=0)
     self.backup_device_type = self.params.get('backup_device_type',
                                               '*',
                                               default='')
     self.backup_device_slot_num = self.params.get('backup_device_slot_num',
                                                   '*',
                                                   default=None)
     self.backup_veth_vnetwork = self.params.get('backup_veth_vnetwork',
                                                 '*',
                                                 default=None)
     if 'vnic' in self.backup_device_type:
         self.vnic_sriov_adapter = self.params.get('vnic_sriov_adapter',
                                                   '*',
                                                   default=None)
         self.vnic_port_id = self.params.get('vnic_port_id',
                                             '*',
                                             default=None)
         self.vnic_adapter_id = self.get_adapter_id(self.vnic_sriov_adapter)
         self.priority = self.params.get('failover_priority',
                                         '*',
                                         default='50')
         self.max_capacity = self.params.get('max_capacity',
                                             '*',
                                             default='10')
         self.capacity = self.params.get('capacity', '*', default='2')
         self.vios_name = self.params.get('vios_name', '*', default=None)
         cmd = 'lssyscfg -m %s -r lpar --filter lpar_names=%s -F lpar_id' % (
             self.server, self.vios_name)
         self.vios_id = self.session.cmd(cmd).stdout_text.split()[0]
         self.backup_vnic_backing_device = 'sriov/%s/%s/%s/%s/%s/%s/%s' % \
             (self.vios_name, self.vios_id, self.vnic_adapter_id, self.vnic_port_id,
              self.capacity, self.priority, self.max_capacity)
     self.local = LocalHost()
示例#20
0
 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(["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)
     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.ip_config = self.params.get("ip_config", default=True)
     local = LocalHost()
     self.networkinterface = NetworkInterface(self.iface, local)
     if self.ip_config:
         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.fail("Link up of interface is taking longer than 120 seconds")
     self.peer = self.params.get("peer_ip")
     if not self.peer:
         self.cancel("No peer provided")
     self.mtu = self.params.get("mtu", default=1500)
     self.peer_public_ip = self.params.get("peer_public_ip", default="")
     self.peer_user = self.params.get("peer_user", default="root")
     self.peer_password = self.params.get("peer_password",
                                          '*',
                                          default=None)
     if 'scp' or 'ssh' in str(self.name.name):
         self.session = Session(self.peer,
                                user=self.peer_user,
                                password=self.peer_password)
         if not self.session.connect():
             self.cancel("failed connecting to peer")
     self.remotehost = RemoteHost(self.peer,
                                  self.peer_user,
                                  password=self.peer_password)
     self.peer_interface = self.remotehost.get_interface_by_ipaddr(
         self.peer).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)
     self.mtu = self.params.get("mtu", default=1500)
     self.mtu_set()
     if self.networkinterface.ping_check(self.peer, count=5) is not None:
         self.cancel("No connection to peer")
示例#21
0
 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")
示例#22
0
class VirtualFC(Test):
    '''
    Removing and Adding and Fibre Chanel Virtualized devices from the HMC
    '''
    @skipUnless("ppc" in distro.detect().arch,
                "supported only on Power platform")
    @skipIf(IS_POWER_NV or IS_KVM_GUEST,
            "This test is not supported on KVM guest or PowerNV platform")
    def setUp(self):
        '''
        set up required packages and gather necessary test inputs
        '''
        self.install_packages()
        self.rsct_service_start()
        self.hmc_ip = self.get_mcp_component("HMCIPAddr")
        if not self.hmc_ip:
            self.cancel("HMC IP not got")
        self.hmc_pwd = self.params.get("hmc_pwd", '*', default=None)
        self.hmc_username = self.params.get("hmc_username", '*', default=None)
        self.count = self.params.get("count", default=1)
        self.skip_drc = self.params.get("skip_drc_name", default=None)
        self.opp_sleep_time = 150
        self.lpar = self.get_partition_name("Partition Name")
        if not self.lpar:
            self.cancel("LPAR Name not got from lparstat command")
        self.session = Session(self.hmc_ip, user=self.hmc_username,
                               password=self.hmc_pwd)
        if not self.session.connect():
            self.cancel("failed connecting to HMC")
        cmd = 'lssyscfg -r sys  -F name'
        output = self.session.cmd(cmd)
        self.server = ''
        for line in output.stdout_text.splitlines():
            if line in self.lpar:
                self.server = line
        if not self.server:
            self.cancel("Managed System not got")
        self.dic_list = []
        cmd = 'lshwres -r virtualio --rsubtype fc --level lpar -m %s \
               --filter "lpar_names=%s"' % (self.server, self.lpar)
        for line in self.session.cmd(cmd).stdout_text.splitlines():
            self.vfc_dic = {}
            for i in line.split(","):
                if i.split("=")[0] == "slot_num":
                    self.vfc_dic["c_slot"] = i.split("=")[-1]
                elif i.split("=")[0] == "remote_slot_num":
                    self.vfc_dic["r_slot"] = i.split("=")[-1]
                elif i.split("=")[0] == "remote_lpar_name":
                    self.vfc_dic["r_lpar"] = i.split("=")[-1]
            self.vfc_dic["wwpn"] = self.get_wwpn(self.vfc_dic["c_slot"])
            self.vfc_dic["drc"] = self.get_drc_name(self.vfc_dic["c_slot"])
            self.vfc_dic["paths"] = self.get_paths(self.vfc_dic["drc"])
            if self.vfc_dic["drc"] != self.skip_drc:
                self.dic_list.append(self.vfc_dic)
        self.log.info("complete list : %s" % self.dic_list)

    @staticmethod
    def get_mcp_component(component):
        '''
        probes IBM.MCP class for mentioned component and returns it.
        '''
        for line in process.system_output('lsrsrc IBM.MCP %s' % component,
                                          ignore_status=True, shell=True,
                                          sudo=True).decode("utf-8") \
                                                    .splitlines():
            if component in line:
                return line.split()[-1].strip('{}\"')
        return ''

    @staticmethod
    def get_partition_name(component):
        '''
        get partition name from lparstat -i
        '''

        for line in process.system_output('lparstat -i', ignore_status=True,
                                          shell=True,
                                          sudo=True).decode("utf-8") \
                                                    .splitlines():
            if component in line:
                return line.split(':')[-1].strip()
        return ''

    def rsct_service_start(self):
        '''
        Running rsct services which is necessary for Network
        virtualization tests
        '''
        try:
            for svc in ["rsct", "rsct_rm"]:
                process.run('startsrc -g %s' % svc, shell=True, sudo=True)
        except CmdError as details:
            self.log.debug(str(details))
            self.fail("Starting service %s failed", svc)

        output = process.system_output("lssrc -a", ignore_status=True,
                                       shell=True, sudo=True).decode("utf-8")
        if "inoperative" in output:
            self.fail("Failed to start the rsct and rsct_rm services")

    def install_packages(self):
        '''
        Install required packages
        '''
        smm = SoftwareManager()
        detected_distro = distro.detect()
        self.log.info("Test is running on: %s", detected_distro.name)
        for pkg in ['ksh', 'src', 'rsct.basic', 'rsct.core.utils',
                    'rsct.core', 'DynamicRM']:
            if not smm.check_installed(pkg) and not smm.install(pkg):
                self.cancel('%s is needed for the test to be run' % pkg)

    def test(self):
        '''
        Remove and add vfc interfaces Dynamically from HMC
        '''
        for _ in range(self.count):
            for vfc_dic in self.dic_list:
                self.device_add_remove("remove", vfc_dic)
                time.sleep(self.opp_sleep_time)
                self.device_add_remove("add", vfc_dic)

    def get_drc_name(self, c_slot):
        '''
        Returns the drc_name i,e vfc slot name mapped to lpar
        '''
        cmd = 'lshwres -r virtualio --rsubtype slot --level slot -m %s -F \
               slot_num,lpar_name,drc_name | grep -i %s' \
               % (self.server, self.lpar)
        for line in self.session.cmd(cmd).stdout_text.splitlines():
            if c_slot in line:
                return line.split(",")[-1]
        return None

    def get_linux_name_drc(self, drc):
        '''
        returns the linux_name of corresponding drc_name
        '''
        cmd = 'lsslot -c slot'
        output = process.system_output(cmd).decode('utf-8').splitlines()
        self.log.info("output value : %s" % output)
        for line in output:
            if drc in line:
                linux_name = " ".join(line.split())
                return linux_name.split(" ")[-2]
        return None

    def get_paths(self, drc_name):
        '''
        returns the mpaths corresponding to linux name
        '''
        paths = []
        linux_name = self.get_linux_name_drc(drc_name)
        cmd = "ls -l /sys/block/"
        output = process.system_output(cmd).decode('utf-8').splitlines()
        for line in output:
            if "/%s/" % linux_name in line:
                paths.append(line.split("/")[-1])
        return paths

    def get_wwpn(self, client_slot):
        '''
        Returns the WWPNs of give client slot number
        '''
        cmd = 'lshwres -r virtualio --rsubtype fc --level lpar -m %s -F \
               lpar_name,slot_num,wwpns | grep -i %s' \
               % (self.server, self.lpar)
        output = self.session.cmd(cmd)
        for line in output.stdout_text.splitlines():
            if self.lpar and client_slot in line:
                wwpn = line.split('"')[1]
        self.log.info("wwpns of slot %s is : %s" % (client_slot, wwpn))
        return wwpn
        if output.exit_status != 0:
            self.log.debug(output.stderr)
            self.fail("Failed to get the wwpn, from give slot")

    def device_add_remove(self, operation, vfc_dic):
        '''
        Adds and removes a Network virtualized device based
        on the operation
        '''
        if operation == 'add':
            cmd = 'chhwres -r virtualio -m %s -o a -p %s --rsubtype fc -s %s \
                   -a "adapter_type=client,remote_lpar_name=%s, \
                   remote_slot_num=%s,\\"wwpns=%s\\""' \
                   % (self.server, self.lpar, vfc_dic["c_slot"],
                      vfc_dic["r_lpar"], vfc_dic["r_slot"], vfc_dic["wwpn"])
        else:
            cmd = 'chhwres -r virtualio -m %s -o r -p %s  -s %s' \
                   % (self.server, self.lpar, vfc_dic["c_slot"])

        output = self.session.cmd(cmd)
        if output.exit_status != 0:
            self.log.debug(output.stderr)
            self.fail("Network virtualization %s device operation \
                       failed" % operation)
        time.sleep(self.opp_sleep_time)
        self.drc_name_verification_hmc(operation, vfc_dic["c_slot"])
        self.linux_name_verification_host(operation, vfc_dic["drc"])
        self.mpath_verification(operation, vfc_dic["paths"],
                                vfc_dic["drc"])

    def drc_name_verification_hmc(self, operation, c_slot):
        '''
        verify the vfc slot/rdc_name exists in HMC
        '''
        err_slot = []
        drc_name = self.get_drc_name(c_slot)
        if operation == "add":
            if not drc_name:
                err_slot.append(c_slot)
        elif operation == "remove":
            if drc_name:
                err_slot.append(c_slot)

        if err_slot:
            self.fail("HMC verifction fail for %s: %s" % (drc_name, operation))
        else:
            self.log.info("HMC verfction succes %s:%s" % (drc_name, operation))

    def linux_name_verification_host(self, operation, drc_name):
        '''
        verify the linux_name or drc_name in host
        '''
        err_slot = []
        linux_name = self.get_linux_name_drc(drc_name)
        if operation == "add":
            if not linux_name:
                err_slot.append(drc_name)
        elif operation == "remove":
            if linux_name:
                err_slot.append(drc_name)

        if err_slot:
            self.fail("Host verifction fail for %s:%s" % (drc_name, operation))
        else:
            self.log.info("Host verfction suces %s:%s" % (drc_name, operation))

    def mpath_verification(self, operation, paths, drc):
        '''
        verify the paths status on add or remove operations of vfc
        '''
        err_paths = []
        curr_paths = self.get_paths(drc)
        if operation == "add":
            for path in paths:
                path_stat = multipath.get_path_status(path)
                if path_stat[0] != "active" or path_stat[2] != "ready":
                    err_paths.append(path)
        elif curr_paths:
            for path in paths:
                path_stat = multipath.get_path_status(path)
                if path_stat[0] != "failed" or path_stat[2] != "faulty":
                    err_paths.append(path)

        if err_paths:
            self.fail("path verfction failed for drc %s:%s" % (drc, err_paths))
        else:
            self.log.info("path verfction success for drc :%s" % drc)

    def tearDown(self):
        '''
        close ssh session gracefully
        '''
        self.session.quit()
示例#23
0
class Bonding(Test):
    '''
    Channel bonding enables two or more network interfaces to act as one,
    simultaneously increasing the bandwidth and providing redundancy.
    '''
    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")

    def bond_ib_conf(self, bond_name, arg1, arg2):
        '''
        configure slaves for IB cards
        '''
        cmd = 'ip link set %s up;' % (bond_name)
        if process.system(cmd, shell=True, ignore_status=True) != 0:
            self.fail("unable to bring Bond interface %s up" % bond_name)
        if arg2 == "ATTACH":
            cmd = 'ifenslave %s %s -f;' % (bond_name, arg1)
        else:
            cmd = 'ifenslave %s -d %s ;' % (bond_name, arg1)
        if process.system(cmd, shell=True, ignore_status=True) != 0:
            self.fail("unable to %s IB interface " % arg2)

    def setup_ip(self):
        '''
        set up the IP config
        '''
        if 'setup' in str(self.name):
            interface = self.host_interfaces[0]
        else:
            interface = self.bond_name
        cmd = "ip addr show  | grep %s" % self.peer_first_ipinterface
        output = self.session.cmd(cmd)
        result = ""
        result = result.join(output.stdout.decode("utf-8"))
        self.peer_first_interface = result.split()[-1]
        if self.peer_first_interface == "":
            self.fail("test failed because peer interface can not retrieved")
        self.peer_ips = [self.peer_first_ipinterface]
        self.local_ip = netifaces.ifaddresses(interface)[2][0]['addr']
        self.net_mask = []
        stf = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        for val1, val2 in zip([interface], [self.local_ip]):
            mask = ""
            if val2:
                tmp = fcntl.ioctl(stf.fileno(), 0x891b,
                                  struct.pack('256s', val1.encode()))
                mask = socket.inet_ntoa(tmp[20:24]).strip('\n')
            self.net_mask.append(mask)
        cmd = "route -n | grep %s | grep -w UG | awk "\
              "'{ print $2 }'" % interface
        self.gateway = process.system_output('%s' % cmd, shell=True)

    def bond_remove(self, arg1):
        '''
        bond_remove
        '''
        if arg1 == "local":
            self.log.info("Removing Bonding configuration on local machine")
            self.log.info("------------------------------------------------")
            for ifs in self.host_interfaces:
                cmd = "ip link set %s down" % ifs
                if process.system(cmd, shell=True, ignore_status=True) != 0:
                    self.log.info("unable to bring down the interface")
                if self.ib:
                    self.bond_ib_conf(self.bond_name, ifs, "REMOVE")
                else:
                    genio.write_file(self.bonding_slave_file, "-%s" % ifs)
            genio.write_file(self.bonding_masters_file, "-%s" % self.bond_name)
            self.log.info("Removing bonding module")
            linux_modules.unload_module("bonding")
            time.sleep(self.sleep_time)
        else:
            self.log.info("Removing Bonding configuration on Peer machine")
            self.log.info("------------------------------------------------")
            cmd = ''
            cmd += 'ip link set %s down;' % self.bond_name
            for val in self.peer_interfaces:
                cmd += 'ip link set %s down;' % val
            for val in self.peer_interfaces:
                cmd += 'ip addr flush dev %s;' % val
            for val in self.peer_interfaces:
                if self.ib:
                    self.bond_ib_conf(self.bond_name, val, "REMOVE")
                else:
                    cmd += 'echo "-%s" > %s;' % (val, self.bonding_slave_file)
            cmd += 'echo "-%s" > %s;' % (self.bond_name,
                                         self.bonding_masters_file)
            cmd += 'rmmod bonding;'
            cmd += 'ip addr add %s/%s dev %s;ip link set %s up;sleep 5;'\
                   % (self.peer_first_ipinterface, self.net_mask[0],
                      self.peer_interfaces[0], self.peer_interfaces[0])
            output = self.session.cmd(cmd)
            if not output.exit_status == 0:
                self.log.info("bond removing command failed in peer machine")

    def ping_check(self):
        '''
        ping check
        '''
        # need some time for specific interface before ping
        time.sleep(10)
        cmd = "ping -I %s %s -c 5"\
              % (self.bond_name, self.peer_first_ipinterface)
        if process.system(cmd, shell=True, ignore_status=True) != 0:
            return False
        return True

    def is_vnic(self):
        '''
        check if slave interface is vnic
        '''
        for interface in self.host_interfaces:
            cmd = "lsdevinfo -q name=%s" % interface
            if 'type="IBM,vnic"' in process.system_output(
                    cmd, shell=True).decode("utf-8"):
                return True
        return False

    def bond_fail(self, arg1):
        '''
        bond fail
        '''
        if len(self.host_interfaces) > 1:
            for interface in self.host_interfaces:
                self.log.info("Failing interface %s for mode %s", interface,
                              arg1)
                cmd = "ip link set %s down" % interface
                if process.system(cmd, shell=True, ignore_status=True) != 0:
                    self.fail("bonding not working when trying to down the\
                               interface %s " % interface)
                time.sleep(self.sleep_time)
                if self.ping_check():
                    self.log.info("Ping passed for Mode %s", arg1)
                else:
                    error_str = "Ping fail in Mode %s when interface %s down"\
                        % (arg1, interface)
                    self.log.debug(error_str)
                    self.err.append(error_str)
                self.log.info(genio.read_file(self.bond_status))
                cmd = "ip link set %s up" % interface
                time.sleep(self.sleep_time)
                if process.system(cmd, shell=True, ignore_status=True) != 0:
                    self.fail("Not able to bring up the slave\
                                    interface %s" % interface)
                time.sleep(self.sleep_time)
        else:
            self.log.debug("Need a min of 2 host interfaces to test\
                         slave failover in Bonding")

        self.log.info("\n----------------------------------------")
        self.log.info("Failing all interfaces for mode %s", arg1)
        self.log.info("----------------------------------------")
        for interface in self.host_interfaces:
            cmd = "ip link set %s down" % interface
            if process.system(cmd, shell=True, ignore_status=True) != 0:
                self.fail("Could not bring down the interface %s " % interface)
            time.sleep(self.sleep_time)
        if not self.ping_check():
            self.log.info("Ping to Bond interface failed. This is expected")
        self.log.info(genio.read_file(self.bond_status))
        for interface in self.host_interfaces:
            cmd = "ip link set %s up" % interface
            time.sleep(self.sleep_time)
            if process.system(cmd, shell=True, ignore_status=True) != 0:
                self.fail("Not able to bring up the slave\
                                interface %s" % interface)
            time.sleep(self.sleep_time)
        bond_mtu = [
            '2000', '3000', '4000', '5000', '6000', '7000', '8000', '9000'
        ]
        if self.is_vnic():
            bond_mtu = ['9000']
        for mtu in bond_mtu:
            self.bond_networkinterface = NetworkInterface(
                self.bond_name, self.localhost)
            if self.bond_networkinterface.set_mtu(mtu) is not None:
                self.cancel("Failed to set mtu in host")
            for interface in self.peer_interfaces:
                peer_networkinterface = NetworkInterface(
                    interface, self.remotehost)
                if peer_networkinterface.set_mtu(mtu) is not None:
                    self.cancel("Failed to set mtu in peer")
            if self.ping_check():
                self.log.info("Ping passed for Mode %s", self.mode, mtu)
            else:
                error_str = "Ping fail in Mode %s after MTU change to %s"\
                    % (arg1, mtu)
            if self.bond_networkinterface.set_mtu('1500'):
                self.cancel("Failed to set mtu back to 1500 in host")
            for interface in self.peer_interfaces:
                peer_networkinterface = NetworkInterface(
                    interface, self.remotehost)
                if peer_networkinterface.set_mtu('1500') is not None:
                    self.cancel("Failed to set mtu back to 1500 in peer")

    def bond_setup(self, arg1, arg2):
        '''
        bond setup
        '''
        if arg1 == "local":
            self.log.info("Configuring Bonding on Local machine")
            self.log.info("--------------------------------------")
            for ifs in self.host_interfaces:
                cmd = "ip addr flush dev %s" % ifs
                process.system(cmd, shell=True, ignore_status=True)
            for ifs in self.host_interfaces:
                cmd = "ip link set %s down" % ifs
                process.system(cmd, shell=True, ignore_status=True)
            linux_modules.load_module("bonding")
            genio.write_file(self.bonding_masters_file, "+%s" % self.bond_name)
            genio.write_file("%s/bonding/mode" % self.bond_dir, arg2)
            genio.write_file("%s/bonding/miimon" % self.bond_dir, self.miimon)
            genio.write_file("%s/bonding/fail_over_mac" % self.bond_dir,
                             self.fail_over_mac)
            genio.write_file("%s/bonding/downdelay" % self.bond_dir,
                             self.downdelay)
            dict = {
                '0': ['packets_per_slave', 'resend_igmp'],
                '1':
                ['num_unsol_na', 'primary', 'primary_reselect', 'resend_igmp'],
                '2': ['xmit_hash_policy'],
                '4': ['lacp_rate', 'xmit_hash_policy'],
                '5': [
                    'tlb_dynamic_lb', 'primary', 'primary_reselect',
                    'resend_igmp', 'xmit_hash_policy', 'lp_interval'
                ],
                '6':
                ['primary', 'primary_reselect', 'resend_igmp', 'lp_interval']
            }
            if self.mode in dict.keys():
                for param in dict[self.mode]:
                    param_value = self.params.get(param, default='')
                    if param_value:
                        genio.write_file(
                            "%s/bonding/%s" % (self.bond_dir, param),
                            param_value)
            for val in self.host_interfaces:
                if self.ib:
                    self.bond_ib_conf(self.bond_name, val, "ATTACH")
                else:
                    genio.write_file(self.bonding_slave_file, "+%s" % val)
                time.sleep(2)
            bond_name_val = ''
            for line in genio.read_file(self.bond_status).splitlines():
                if 'Bonding Mode' in line:
                    bond_name_val = line.split(':')[1]
            self.log.info("Trying bond mode %s [ %s ]", arg2, bond_name_val)
            for ifs in self.host_interfaces:
                cmd = "ip link set %s up" % ifs
                if process.system(cmd, shell=True, ignore_status=True) != 0:
                    self.fail("unable to interface up")
            cmd = "ip addr add %s/%s dev %s;ip link set %s up"\
                  % (self.local_ip, self.net_mask[0],
                     self.bond_name, self.bond_name)
            process.system(cmd, shell=True, ignore_status=True)
            for _ in range(0, 600, 60):
                if 'state UP' in process.system_output(
                        "ip link \
                     show %s" % self.bond_name,
                        shell=True).decode("utf-8"):
                    self.log.info("Bonding setup is successful on\
                                  local machine")
                    break
                time.sleep(60)
            else:
                self.fail("Bonding setup on local machine has failed")
            if self.gateway:
                cmd = 'ip route add default via %s dev %s' % \
                    (self.gateway, self.bond_name)
                process.system(cmd, shell=True, ignore_status=True)

        else:
            self.log.info("Configuring Bonding on Peer machine")
            self.log.info("------------------------------------------")
            cmd = ''
            for val in self.peer_interfaces:
                cmd += 'ip addr flush dev %s;' % val
            for val in self.peer_interfaces:
                cmd += 'ip link set %s down;' % val
            cmd += 'modprobe bonding;'
            cmd += 'echo +%s > %s;'\
                   % (self.bond_name, self.bonding_masters_file)
            cmd += 'echo 0 > %s/bonding/mode;'\
                   % self.bond_dir
            cmd += 'echo 100 > %s/bonding/miimon;'\
                   % self.bond_dir
            cmd += 'echo 2 > %s/bonding/fail_over_mac;'\
                   % self.bond_dir
            for val in self.peer_interfaces:
                if self.ib:
                    self.bond_ib_conf(self.bond_name, val, "ATTACH")
                else:
                    cmd += 'echo "+%s" > %s;' % (val, self.bonding_slave_file)
            for val in self.peer_interfaces:
                cmd += 'ip link set %s up;' % val
            cmd += 'ip addr add %s/%s dev %s;ip link set %s up;sleep 5;'\
                   % (self.peer_first_ipinterface, self.net_mask[0],
                      self.bond_name, self.bond_name)
            output = self.session.cmd(cmd)
            if not output.exit_status == 0:
                self.fail("bond setup command failed in peer machine")

    def test_setup(self):
        '''
        bonding the interfaces
        work for multiple interfaces on both host and peer
        '''
        cmd = "[ -d %s ]" % self.bond_dir
        output = self.session.cmd(cmd)
        if output.exit_status == 0:
            self.fail("bond name already exists on peer machine")
        if os.path.isdir(self.bond_dir):
            self.fail("bond name already exists on local machine")
        if self.peer_bond_needed:
            self.bond_setup("peer", "")
        self.bond_setup("local", self.mode)
        self.log.info(genio.read_file(self.bond_status))
        self.ping_check()
        self.error_check()

    def test_run(self):
        self.bond_fail(self.mode)
        self.log.info("Mode %s OK", self.mode)
        self.error_check()
        # need few sec for interface to not lost the connection to peer
        time.sleep(5)

    def test_cleanup(self):
        '''
        clean up the interface config
        '''
        self.bond_remove("local")

        if self.gateway:
            cmd = 'ip route add default via %s' % \
                (self.gateway)
            process.system(cmd, shell=True, ignore_status=True)

        if self.peer_bond_needed:
            self.bond_remove("peer")
            for val in self.peer_interfaces:
                cmd = "ifdown %s; ifup %s; sleep %s"\
                      % (val, val, self.peer_wait_time)
                output = self.session.cmd(cmd)
                if not output.exit_status == 0:
                    self.log.warn("unable to bring to original state in peer")
                time.sleep(self.sleep_time)
        self.error_check()

        for ipaddr, host_interface in zip(self.ipaddr, self.host_interfaces):
            networkinterface = NetworkInterface(host_interface, self.localhost)
            try:
                networkinterface.add_ipaddr(ipaddr, self.netmask)
                networkinterface.bring_up()
            except Exception:
                self.fail("Interface is taking long time to link up")
            if networkinterface.set_mtu("1500") is not None:
                self.cancel("Failed to set mtu in host")
            try:
                networkinterface.restore_from_backup()
            except Exception:
                self.log.info(
                    "backup file not availbale, could not restore file.")
        try:
            for interface in self.peer_interfaces:
                peer_networkinterface = NetworkInterface(
                    interface, self.remotehost)
                peer_networkinterface.set_mtu("1500")
        except Exception:
            for interface in self.peer_interfaces:
                peer_public_networkinterface = NetworkInterface(
                    interface, self.remotehost_public)
                peer_public_networkinterface.set_mtu("1500")
        self.remotehost.remote_session.quit()
        self.remotehost_public.remote_session.quit()

    def error_check(self):
        if self.err:
            self.fail("Tests failed. Details:\n%s" % "\n".join(self.err))

    def tearDown(self):
        self.session.quit()
class NetworkVirtualization(Test):
    '''
    Adding and deleting Network Virtualized devices from the vios
    Performs adding and deleting of Backing devices
    Performs HMC failover for Network Virtualized device
    Performs driver unbind and bind for Network virtualized device
    Performs Client initiated failover for Network Virtualized device
    '''
    @skipUnless("ppc" in distro.detect().arch,
                "supported only on Power platform")
    @skipIf(IS_POWER_NV or IS_KVM_GUEST,
            "This test is not supported on KVM guest or PowerNV platform")
    def setUp(self):
        '''
        set up required packages and gather necessary test inputs
        '''
        self.install_packages()
        self.hmc_ip = self.get_mcp_component("HMCIPAddr")
        if not self.hmc_ip:
            self.cancel("HMC IP not got")
        self.hmc_pwd = self.params.get("hmc_pwd", '*', default=None)
        self.hmc_username = self.params.get("hmc_username", '*', default=None)
        self.lpar = self.get_partition_name("Partition Name")
        if not self.lpar:
            self.cancel("LPAR Name not got from lparstat command")
        for root, dirct, files in os.walk("/root/.ssh"):
            for file in files:
                if file.startswith("avocado-master-root"):
                    path = os.path.join(root, file)
                    os.remove(path)
        self.session_hmc = Session(self.hmc_ip,
                                   user=self.hmc_username,
                                   password=self.hmc_pwd)
        if not self.session_hmc.connect():
            self.cancel("failed connecting to HMC")
        cmd = 'lssyscfg -r sys  -F name'
        output = self.session_hmc.cmd(cmd)
        self.server = ''
        for line in output.stdout_text.splitlines():
            if line in self.lpar:
                self.server = line
                break
        if not self.server:
            self.cancel("Managed System not got")
        self.slot_num = self.params.get("slot_num", '*', default=None)
        self.slot_num = self.slot_num.split(' ')
        for slot in self.slot_num:
            if int(slot) < 3 or int(slot) > 2999:
                self.cancel("Slot invalid. Valid range: 3 - 2999")
        self.vios_name = self.params.get("vios_names", '*',
                                         default=None).split(' ')
        self.sriov_port = self.params.get("sriov_ports", '*',
                                          default=None).split(' ')
        self.backing_adapter = self.params.get("sriov_adapters",
                                               '*',
                                               default=None).split(' ')
        if len(self.sriov_port) != len(self.backing_adapter):
            self.cancel('Backing Device counts and port counts differ')
        if len(self.vios_name) != len(self.backing_adapter):
            self.cancel('Backing Device counts and vios name counts differ')
        self.backingdev_count = len(self.backing_adapter)
        self.bandwidth = self.params.get("bandwidth", '*', default=None)
        self.vnic_priority = self.params.get("priority", '*', default=None)
        if not self.vnic_priority:
            self.vnic_priority = [50] * len(self.backing_adapter)
        else:
            self.vnic_priority = self.vnic_priority.split(' ')
        if len(self.vnic_priority) != len(self.backing_adapter):
            self.cancel('Backing Device counts and priority counts differ')
        self.auto_failover = self.params.get("auto_failover",
                                             '*',
                                             default=None)
        if self.auto_failover not in ['0', '1']:
            self.auto_failover = '1'
        self.vios_ip = self.params.get('vios_ip', '*', default=None)
        self.vios_user = self.params.get('vios_username', '*', default=None)
        self.vios_pwd = self.params.get('vios_pwd', '*', default=None)
        self.count = int(self.params.get('vnic_test_count', default="1"))
        self.num_of_dlpar = int(self.params.get("num_of_dlpar", default='1'))
        self.device_ip = self.params.get('device_ip', '*',
                                         default=None).split(' ')
        self.mac_id = self.params.get('mac_id',
                                      default="02:03:03:03:03:01").split(' ')
        self.mac_id = [mac.replace(':', '') for mac in self.mac_id]
        self.netmask = self.params.get('netmasks', '*',
                                       default=None).split(' ')
        self.peer_ip = self.params.get('peer_ip', default=None).split(' ')
        dmesg.clear_dmesg()
        self.session_hmc.cmd("uname -a")
        cmd = 'lssyscfg -m ' + self.server + \
              ' -r lpar --filter lpar_names=' + self.lpar + \
              ' -F lpar_id'
        self.lpar_id = self.session_hmc.cmd(cmd).stdout_text.split()[0]
        self.vios_id = []
        for vios_name in self.vios_name:
            cmd = 'lssyscfg -m ' + self.server + \
                  ' -r lpar --filter lpar_names=' + vios_name + \
                  ' -F lpar_id'
            self.vios_id.append(
                self.session_hmc.cmd(cmd).stdout_text.split()[0])
        cmd = 'lshwres -m %s -r sriov --rsubtype adapter -F \
              phys_loc:adapter_id' % self.server
        adapter_id_output = self.session_hmc.cmd(cmd).stdout_text
        self.backing_adapter_id = []
        for backing_adapter in self.backing_adapter:
            for line in adapter_id_output.splitlines():
                if str(backing_adapter) in line:
                    self.backing_adapter_id.append(line.split(':')[1])
        if not self.backing_adapter_id:
            self.cancel("SRIOV adapter provided was not found.")
        self.rsct_service_start()
        if len(self.slot_num) > 1:
            if 'backing' in str(self.name.name) or \
               'failover' in str(self.name.name):
                self.cancel("this test is not needed")
        self.local = LocalHost()
        cmd = "echo 'module ibmvnic +p; func send_subcrq -p' > /sys/kernel/debug/dynamic_debug/control"
        result = process.run(cmd, shell=True, ignore_status=True)
        if result.exit_status:
            self.fail("failed to enable debug mode")

    @staticmethod
    def get_mcp_component(component):
        '''
        probes IBM.MCP class for mentioned component and returns it.
        '''
        for line in process.system_output('lsrsrc IBM.MCP %s' % component,
                                          ignore_status=True, shell=True,
                                          sudo=True).decode("utf-8") \
                                                    .splitlines():
            if component in line:
                return line.split()[-1].strip('{}\"')
        return ''

    @staticmethod
    def get_partition_name(component):
        '''
        get partition name from lparstat -i
        '''

        for line in process.system_output('lparstat -i', ignore_status=True,
                                          shell=True,
                                          sudo=True).decode("utf-8") \
                                                    .splitlines():
            if component in line:
                return line.split(':')[-1].strip()
        return ''

    def check_slot_availability(self, slot_num):
        '''
        Checks if given slot is available(free) to be used.
        :return: True if slot available, False otherwise.
        '''
        cmd = 'lshwres -r virtualio -m %s --rsubtype vnic --filter \
           "lpar_names=%s" -F slot_num' % (self.server, self.lpar)
        for slot in self.session_hmc.cmd(cmd).stdout_text:
            if 'No results were found' in slot:
                return True
            if slot_num == slot:
                self.log.debug("Slot %s already exists" % slot_num)
                return False
        return True

    def rsct_service_start(self):
        '''
        Running rsct services which is necessary for Network
        virtualization tests
        '''
        try:
            for svc in ["rsct", "rsct_rm"]:
                process.run('startsrc -g %s' % svc, shell=True, sudo=True)
        except CmdError as details:
            self.log.debug(str(details))
            self.fail("Starting service %s failed", svc)

        output = process.system_output("lssrc -a",
                                       ignore_status=True,
                                       shell=True,
                                       sudo=True)
        if "inoperative" in output.decode("utf-8"):
            self.cancel("Failed to start the rsct and rsct_rm services")

    def install_packages(self):
        '''
        Install necessary packages
        '''
        smm = SoftwareManager()
        packages = [
            'ksh', 'src', 'rsct.basic', 'rsct.core.utils', 'rsct.core',
            'DynamicRM', 'powerpc-utils'
        ]
        detected_distro = distro.detect()
        if detected_distro.name == "Ubuntu":
            packages.extend(['python-paramiko'])
        self.log.info("Test is running on: %s", detected_distro.name)
        for pkg in packages:
            if not smm.check_installed(pkg) and not smm.install(pkg):
                self.cancel('%s is needed for the test to be run' % pkg)
        if detected_distro.name == "Ubuntu":
            ubuntu_url = self.params.get('ubuntu_url', default=None)
            debs = self.params.get('debs', default=None)
            for deb in debs:
                deb_url = os.path.join(ubuntu_url, deb)
                deb_install = self.fetch_asset(deb_url, expire='7d')
                shutil.copy(deb_install, self.workdir)
                process.system("dpkg -i %s/%s" % (self.workdir, deb),
                               ignore_status=True,
                               sudo=True)

    def test_add(self):
        '''
        Network virtualized device add operation
        '''
        for slot, mac, sriov_port, adapter_id, device_ip, netmask in zip(
                self.slot_num, self.mac_id, self.sriov_port,
                self.backing_adapter_id, self.device_ip, self.netmask):
            if not self.check_slot_availability(slot):
                self.fail("Slot does not exist")
            self.device_add_remove(slot, mac, sriov_port, adapter_id, 'add')
            self.interface_naming(mac, slot)
            output = self.list_device(slot)
            if 'slot_num=%s' % slot not in str(output):
                self.log.debug(output)
                self.fail("lshwres fails to list Network virtualized device \
                           after add operation")
            if mac not in str(output):
                self.log.debug(output)
                self.fail("MAC address in HMC differs")
            if not self.find_device(mac):
                self.fail("MAC address differs in linux")
            device = self.find_device(mac)
            networkinterface = NetworkInterface(device, self.local)
            try:
                networkinterface.add_ipaddr(device_ip, netmask)
                networkinterface.save(device_ip, netmask)
            except Exception:
                networkinterface.save(device_ip, netmask)
            networkinterface.bring_up()
            if not wait.wait_for(networkinterface.is_link_up, timeout=120):
                self.fail("Unable to bring up the link on the Network \
                       virtualized device")
        self.check_dmesg_error()

    def test_backingdevadd(self):
        '''
        Adding Backing device for Network virtualized device
        '''
        for slot in self.slot_num:
            if self.check_slot_availability(slot):
                self.fail("Slot does not exist")
        pre_add = self.backing_dev_count()
        for count in range(1, self.backingdev_count):
            self.backing_dev_add_remove('add', count)
        post_add = self.backing_dev_count()
        post_add_count = post_add - pre_add + 1
        if post_add_count != self.backingdev_count:
            self.log.debug("Actual backing dev count: %d", post_add_count)
            self.log.debug("Expected backing dev count: %d",
                           self.backingdev_count)
            self.fail("Failed to add backing device")
        self.check_dmesg_error()

    def test_hmcfailover(self):
        '''
        Triggers Failover for the Network virtualized
        device
        '''
        original = self.get_active_device_logport(self.slot_num[0])
        for _ in range(self.count):
            before = self.get_active_device_logport(self.slot_num[0])
            self.trigger_failover(
                self.get_backing_device_logport(self.slot_num[0]))
            time.sleep(10)
            after = self.get_active_device_logport(self.slot_num[0])
            self.log.debug("Active backing device: %s", after)
            if before == after:
                self.fail("No failover happened")
            device = self.find_device(self.mac_id[0])
            networkinterface = NetworkInterface(device, self.local)
            if networkinterface.ping_check(self.peer_ip[0],
                                           count=5) is not None:
                self.fail("Failover has affected Network connectivity")
        if original != self.get_active_device_logport(self.slot_num[0]):
            self.trigger_failover(original)
        if original != self.get_active_device_logport(self.slot_num[0]):
            self.log.warn("Fail: Activating Initial backing dev %s" % original)
        self.check_dmesg_error()

    def test_clientfailover(self):
        '''
        Performs Client initiated failover for Network virtualized
        device
        '''
        device_id = self.find_device_id(self.mac_id[0])
        try:
            for _ in range(self.count):
                for val in range(int(self.backing_dev_count())):
                    self.log.info(
                        "Performing Client initiated\
                                  failover - Attempt %s", int(val + 1))
                    genio.write_file_or_fail(
                        "/sys/devices/vio/%s/failover" % device_id, "1")
                    time.sleep(10)
                    self.log.info("Running a ping test to check if failover \
                                    affected Network connectivity")
                    device = self.find_device(self.mac_id[0])
                    networkinterface = NetworkInterface(device, self.local)
                    if networkinterface.ping_check(self.peer_ip[0],
                                                   count=5,
                                                   options="-w50") is not None:
                        self.fail("Ping test failed. Network virtualized \
                                   failover has affected Network connectivity")
        except CmdError as details:
            self.log.debug(str(details))
            self.fail("Client initiated Failover for Network virtualized \
                      device has failed")
        self.check_dmesg_error()

    def test_vnic_auto_failover(self):
        '''
        Set the priority for vNIC active and backing devices and check if autofailover works
        '''
        if len(self.backing_adapter) >= 2:
            for _ in range(self.count):
                self.update_backing_devices(self.slot_num[0])
                backing_logport = self.get_backing_device_logport(
                    self.slot_num[0])
                active_logport = self.get_active_device_logport(
                    self.slot_num[0])
                if self.enable_auto_failover():
                    if not self.change_failover_priority(backing_logport, '1'):
                        self.fail(
                            "Fail to change the priority for backing device %s",
                            backing_logport)
                    if not self.change_failover_priority(
                            active_logport, '100'):
                        self.fail(
                            "Fail to change the priority for active device %s",
                            active_logport)
                    time.sleep(10)
                    if backing_logport != self.get_active_device_logport(
                            self.slot_num[0]):
                        self.fail("Auto failover of backing device failed")
                    device = self.find_device(self.mac_id[0])
                    networkinterface = NetworkInterface(device, self.local)
                    if networkinterface.ping_check(self.peer_ip[0],
                                                   count=5) is not None:
                        self.fail("Auto failover has effected connectivity")
                else:
                    self.fail("Could not enable auto failover")
        else:
            self.cancel("Provide more backing device, only 1 given")
        self.check_dmesg_error()

    def test_rmdev_viosfailover(self):
        '''
        using mrdev and mkdev command to check vios failover works
        '''

        self.session = Session(self.vios_ip,
                               user=self.vios_user,
                               password=self.vios_pwd)
        if not self.session.connect():
            self.fail("Failed connecting to VIOS")

        cmd = "ioscli lsmap -all -vnic -cpid %s" % self.lpar_id
        vnic_server = self.session.cmd(
            cmd).stdout_text.splitlines()[2].split()[0]

        cmd = "ioscli lsmap -vnic -vadapter %s" % vnic_server
        output = self.session.cmd(cmd)

        vnic_backing_device = None
        for line in output.stdout_text.splitlines():
            if 'Backing device' in line:
                vnic_backing_device = line.split(':')[-1]

        before = self.get_active_device_logport(self.slot_num[0])
        self.log.debug("Active backing device before : %s", before)

        self.validate_vios_command('rmdev -l %s' % vnic_server, 'Defined')
        if vnic_backing_device:
            self.validate_vios_command('rmdev -l %s' % vnic_backing_device,
                                       'Defined')

        after = self.get_active_device_logport(self.slot_num[0])
        self.log.debug("Active backing device after: %s", after)

        if before == after:
            self.fail("failover not occour")
        time.sleep(20)

        if vnic_backing_device:
            self.validate_vios_command('mkdev -l %s' % vnic_backing_device,
                                       'Available')
        self.validate_vios_command('mkdev -l %s' % vnic_server, 'Available')

        device = self.find_device(self.mac_id[0])
        networkinterface = NetworkInterface(device, self.local)
        if networkinterface.ping_check(self.peer_ip[0], count=5) is not None:
            self.fail("Ping test failed. Network virtualized \
                      vios failover has affected Network connectivity")
        self.check_dmesg_error()

    def test_vnic_dlpar(self):
        '''
        Perform vNIC device hot add and hot remove using drmgr command
        '''
        for slot_no, device_ip, netmask, mac, peer_ip in zip(
                self.slot_num, self.device_ip, self.netmask, self.mac_id,
                self.peer_ip):
            self.update_backing_devices(slot_no)
            dev_id = self.find_device_id(mac)
            device_name = self.find_device(mac)
            slot = self.find_virtual_slot(dev_id)
            if slot:
                try:
                    for _ in range(self.num_of_dlpar):
                        self.drmgr_vnic_dlpar('-r', slot)
                        self.drmgr_vnic_dlpar('-a', slot)
                        self.wait_intrerface(device_name)
                except CmdError as details:
                    self.log.debug(str(details))
                    self.fail("dlpar operation did not complete")
                device = self.find_device(mac)
                networkinterface = NetworkInterface(device, self.local)
                try:
                    networkinterface.add_ipaddr(device_ip, netmask)
                except Exception:
                    networkinterface.save(device_ip, netmask)
                if not wait.wait_for(networkinterface.is_link_up, timeout=120):
                    self.fail("Unable to bring up the link on the Network \
                              virtualized device")
                if networkinterface.ping_check(peer_ip, count=5) is not None:
                    self.fail("dlpar has affected Network connectivity")
            else:
                self.fail("slot not found")
        self.check_dmesg_error()

    def test_backingdevremove(self):
        '''
        Removing Backing device for Network virtualized device
        '''
        for slot in self.slot_num:
            if self.check_slot_availability(slot):
                self.fail("Slot does not exist")
            self.update_backing_devices(slot)
            pre_remove = self.backing_dev_count()
            for count in range(1, self.backingdev_count):
                self.backing_dev_add_remove('remove', count)
            post_remove = self.backing_dev_count()
            post_remove_count = pre_remove - post_remove + 1
            if post_remove_count != self.backingdev_count:
                self.log.debug("Actual backing dev count: %d",
                               post_remove_count)
                self.log.debug("Expected backing dev count: %d",
                               self.backingdev_count)
                self.fail("Failed to remove backing device")
        self.check_dmesg_error()

    def test_remove(self):
        '''
        Network virtualized device remove operation
        '''
        for slot in self.slot_num:
            if self.check_slot_availability(slot):
                self.fail("Slot does not exist")
            self.update_backing_devices(slot)
            self.device_add_remove(slot, '', '', '', 'remove')
            output = self.list_device(slot)
            if 'slot_num=%s' % slot in str(output):
                self.log.debug(output)
                self.fail("lshwres still lists the Network virtualized device \
                           after remove operation")
        self.check_dmesg_error()

    def validate_vios_command(self, cmd, validate_string):
        '''
        checking for vnicserver and backing device
        '''
        l_cmd = "echo \"%s\" | ioscli oem_setup_env" % cmd
        output = self.session.cmd(l_cmd)
        if validate_string not in output.stdout_text:
            self.fail("command fail in vios")

    def device_add_remove(self, slot, mac, sriov_port, adapter_id, operation):
        '''
        Adds and removes a Network virtualized device based
        on the operation
        '''
        backing_device = "backing_devices=sriov/%s/%s/%s/%s/%s/%s"\
                         % (self.vios_name[0], self.vios_id[0],
                            adapter_id, sriov_port,
                            self.bandwidth, self.vnic_priority[0])
        if operation == 'add':
            cmd = 'chhwres -m %s --id %s -r virtualio --rsubtype vnic \
                   -o a -s %s -a \"auto_priority_failover=%s,mac_addr=%s,%s\" '\
                   % (self.server, self.lpar_id, slot,
                      self.auto_failover, mac, backing_device)
        else:
            cmd = 'chhwres -m %s --id %s -r virtualio --rsubtype vnic \
                   -o r -s %s'\
                   % (self.server, self.lpar_id, slot)
        output = self.session_hmc.cmd(cmd)
        if output.exit_status != 0:
            self.log.debug(output.stderr)
            self.fail("Network virtualization %s device operation \
                       failed" % operation)

    def list_device(self, slot):
        '''
        Lists the Network vritualized devices
        '''
        cmd = 'lshwres -r virtualio -m %s --rsubtype vnic --filter \
              \"lpar_names=%s,slots=%s\"' % (self.server, self.lpar, slot)
        try:
            output = self.session_hmc.cmd(cmd)
        except CmdError as details:
            self.log.debug(str(details))
            self.fail("lshwres operation failed ")
        return output.stdout_text

    def backing_dev_add_remove(self, operation, i):
        '''
        Adds and removes a backing device based on the operation
        '''
        add_backing_device = "sriov/%s/%s/%s/%s/%s/%s" \
                             % (self.vios_name[i], self.vios_id[i],
                                self.backing_adapter_id[i],
                                self.sriov_port[i],
                                self.bandwidth,
                                self.vnic_priority[i])
        if operation == 'add':
            cmd = 'chhwres -r virtualio --rsubtype vnic -o s -m %s -s %s \
                   --id %s -a \"auto_priority_failover=%s,backing_devices+=%s\"' % (
                self.server, self.slot_num[0], self.lpar_id,
                self.auto_failover, add_backing_device)
        else:
            cmd = 'chhwres -r virtualio --rsubtype vnic -o s -m %s -s %s \
                   --id %s -a backing_devices-=%s' % (
                self.server, self.slot_num[0], self.lpar_id,
                add_backing_device)
        output = self.session_hmc.cmd(cmd)
        if output.exit_status != 0:
            self.log.debug(output.stderr)
            self.fail("Network virtualization Backing device %s \
                       operation failed" % operation)

    def backing_dev_list(self):
        '''
        Lists the Backing devices for a Network virtualized
        device
        '''
        cmd = 'lshwres -r virtualio -m %s --rsubtype vnic --level lpar \
               --filter lpar_names=%s -F slot_num,backing_device_states' \
               % (self.server, self.lpar)
        try:
            output = self.session_hmc.cmd(cmd)
        except CmdError as details:
            self.log.debug(str(details))
            self.fail("lshwres operation failed ")
        return output.stdout_text

    def get_backing_devices(self):
        '''
        Lists the Backing devices for a Network virtualized
        device
        '''
        cmd = 'lshwres -r virtualio -m %s --rsubtype vnic --level lpar \
               --filter lpar_names=%s -F backing_devices' \
               % (self.server, self.lpar)
        try:
            output = self.session_hmc.cmd(cmd)
        except CmdError as details:
            self.log.debug(str(details))
            self.fail("lshwres operation failed ")
        return output.stdout_text

    def update_backing_devices(self, slot):
        '''
        Updates the lists of backing devices, ports, vioses.
        Makes sure the active device's details are on index 0.
        '''
        logport = self.get_active_device_logport(slot)
        adapter_id = ''
        for entry in self.get_backing_devices()[-1].split(','):
            if logport in entry:
                adapter_id = entry.split('/')[3]
                port = entry.split('/')[4]
        if not adapter_id:
            return
        for i in range(0, len(self.backing_adapter_id)):
            if adapter_id == self.backing_adapter_id[i]:
                if port == self.sriov_port[i]:
                    index = i
        vios_id = self.vios_id.pop(index)
        self.vios_id.insert(0, vios_id)
        self.sriov_port.pop(index)
        self.sriov_port.insert(0, port)
        self.backing_adapter_id.pop(index)
        self.backing_adapter_id.insert(0, adapter_id)

    def backing_dev_count(self):
        '''
        Lists the count of backing devices
        '''
        for slot in self.slot_num:
            output = self.backing_dev_list()
            for i in output.splitlines():
                if i.startswith('%s,' % slot):
                    count = len(i.split(',')[1:])
            return count

    @staticmethod
    def find_device(mac_addrs):
        """
        Finds out the latest added network virtualized device
        """
        mac = ':'.join(mac_addrs[i:i + 2] for i in range(0, 12, 2))
        devices = netifaces.interfaces()
        for device in devices:
            if mac in netifaces.ifaddresses(device)[17][0]['addr']:
                return device
        return ''

    def drmgr_vnic_dlpar(self, operation, slot):
        """
        Perform add / remove operation
        """
        cmd = 'drmgr %s -c slot -s %s -w 5 -d 1' % (operation, slot)
        if process.system(cmd, shell=True, sudo=True, ignore_status=True):
            self.fail("drmgr operation %s fails for vNIC device %s" %
                      (operation, slot))

    def is_auto_failover_enabled(self):
        """
        Check if auto failover is enabled for the vNIC device
        """
        cmd = 'lshwres -r virtualio -m %s --rsubtype vnic \
               --filter lpar_names=%s,slots=%s' \
               % (self.server, self.lpar, self.slot_num[0])
        output = self.session_hmc.cmd(cmd)
        if output.exit_status != 0:
            self.log.debug(output.stderr)
        if 'auto_priority_failover=1' in output.stdout_text:
            return True
        return False

    def enable_auto_failover(self):
        """
        Function to enable auto failover option
        """
        cmd = 'chhwres -r virtualio -m %s --rsubtype vnic \
               -o s --id %s -s %s -a auto_priority_failover=1' \
               % (self.server, self.lpar_id, self.slot_num[0])
        output = self.session_hmc.cmd(cmd)
        if output.exit_status != 0:
            self.log.debug(output.stderr)
        if not self.is_auto_failover_enabled():
            return False
        return True

    def get_failover_priority(self, logport):
        """
        get the priority value for the given backing device
        """
        priority = None
        cmd = 'lshwres -r virtualio -m %s --rsubtype vnic --level lpar \
               --filter lpar_names=%s -F slot_num,backing_devices' \
               % (self.server, self.lpar)
        output = self.session_hmc.cmd(cmd)
        if output.exit_status != 0:
            self.log.debug(output.stderr)
        if output.stdout_text.startswith('%s,' % self.slot_num[0]):
            backing_dev = output.stdout_text.strip('%s,"' % self.slot_num[0])
            for entry in backing_dev.split(','):
                entry = entry.split('/')
                if logport in entry:
                    priority = entry[8]
                    break
        return priority

    def change_failover_priority(self, logport, priority):
        """
        Change the fail over priroity for given backing device
        """
        cmd = 'chhwres -r virtualio --rsubtype vnicbkdev -o s -m %s \
               -s %s --id %s --logport %s -a failover_priority=%s' \
               % (self.server, self.slot_num[0], self.lpar_id, logport, priority)
        output = self.session_hmc.cmd(cmd)
        if output.exit_status != 0:
            self.log.debug(output.stderr)
        if priority != self.get_failover_priority(logport):
            return False
        return True

    def find_device_id(self, mac):
        """
        Finds the device id needed to trigger failover
        """
        device = self.find_device(mac)
        device_id = process.system_output("ls -l /sys/class/net/ | \
                                           grep %s | cut -d '/' -f \
                                           5" % device,
                                          shell=True).decode("utf-8").strip()
        return device_id

    def find_virtual_slot(self, dev_id):
        """
        finds the virtual slot for the given virtual ID
        """
        output = process.system_output("lsslot",
                                       ignore_status=True,
                                       shell=True,
                                       sudo=True)
        for slot in output.decode("utf-8").split('\n'):
            if dev_id in slot:
                return slot.split(' ')[0]
        return False

    def trigger_failover(self, logport):
        '''
        Triggers failover from HMC
        '''
        cmd = 'chhwres -r virtualio --rsubtype vnicbkdev -o act -m %s \
               -s %s --id %s \
               --logport %s' % (self.server, self.slot_num[0], self.lpar_id,
                                logport)
        output = self.session_hmc.cmd(cmd)
        if output.exit_status != 0:
            self.log.debug(output.stderr)
            self.fail("Command to set %s as Active has failed" % logport)

    def get_backing_device_logport(self, slot):
        '''
        Get the logical port id of the
        backing device
        '''
        for backing_dev in self.backing_dev_list().splitlines():
            if backing_dev.startswith('%s,' % slot):
                backing_dev = backing_dev.strip('%s,"' % slot)
                for entry in backing_dev.split(','):
                    entry = entry.split('/')
                    if '0' in entry[2] and 'Operational' in entry[3]:
                        logport = entry[1]
                        break
        return logport

    def get_active_device_logport(self, slot):
        '''
        Get the logical port id of the Network
        virtualized device
        '''
        for backing_dev in self.backing_dev_list().splitlines():
            if backing_dev.startswith('%s,' % slot):
                backing_dev = backing_dev.strip('%s,"' % slot)
                for entry in backing_dev.split(','):
                    entry = entry.split('/')
                    if '1' in entry[2]:
                        logport = entry[1]
                        break
        return logport

    def is_backing_device_active(self, slot):
        '''
        TO check the status of the backing device
        after failover
        '''
        for backing_dev in self.backing_dev_list().splitlines():
            if backing_dev.startswith('%s,' % slot):
                val = int(backing_dev.split(',')[1:][1].split('/')[2])
        if val:
            return True
        return False

    def interface_naming(self, mac, slot):
        '''
        naming to vnic interface
        '''
        mac_addrs = ':'.join(mac[i:i + 2] for i in range(0, 12, 2))
        file = "/etc/udev/rules.d/70-persistent-net.rules-%s" % slot
        with open(file, "w") as interface_conf:
            interface_conf.write("SUBSYSTEM==net \n")
            interface_conf.write("ACTION==add \n")
            interface_conf.write("DRIVERS==? \n")
            interface_conf.write("ATTR{address}==%s \n" % mac_addrs)
            interface_conf.write("ATTR{dev_id}==0x0 \n")
            interface_conf.write("ATTR{type}==1 \n")
            interface_conf.write("KERNEL==vnic \n")
            interface_conf.write("NAME=vnic%s \n" % slot)

    def wait_intrerface(self, device_name):
        """
        Wait till interface come up
        """
        for _ in range(0, 120, 10):
            for interface in netifaces.interfaces():
                if device_name == interface:
                    self.log.info("Network virtualized device %s is up",
                                  device_name)
                    return True
                time.sleep(2)
        return False

    def check_dmesg_error(self):
        """
        check for dmesg error
        """
        self.log.info("Gathering kernel errors if any")
        try:
            dmesg.collect_errors_by_level()
        except Exception as exc:
            self.log.info(exc)
            self.fail("test failed,check dmesg log in debug log")

    def tearDown(self):
        self.session_hmc.quit()
        if 'vios' in str(self.name.name):
            self.session.quit()
        cmd = "echo 'module ibmvnic -p; func send_subcrq -p' > /sys/kernel/debug/dynamic_debug/control"
        result = process.run(cmd, shell=True, ignore_status=True)
        if result.exit_status:
            self.log.debug("failed to disable debug mode")
示例#25
0
class NetworkTest(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(["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)
        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.ip_config = self.params.get("ip_config", default=True)
        local = LocalHost()
        self.networkinterface = NetworkInterface(self.iface, local)
        if self.ip_config:
            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.fail("Link up of interface is taking longer than 120 seconds")
        self.peer = self.params.get("peer_ip")
        if not self.peer:
            self.cancel("No peer provided")
        self.mtu = self.params.get("mtu", default=1500)
        self.peer_public_ip = self.params.get("peer_public_ip", default="")
        self.peer_user = self.params.get("peer_user", default="root")
        self.peer_password = self.params.get("peer_password",
                                             '*',
                                             default=None)
        if 'scp' or 'ssh' in str(self.name.name):
            self.session = Session(self.peer,
                                   user=self.peer_user,
                                   password=self.peer_password)
            if not self.session.connect():
                self.cancel("failed connecting to peer")
        self.remotehost = RemoteHost(self.peer,
                                     self.peer_user,
                                     password=self.peer_password)
        self.peer_interface = self.remotehost.get_interface_by_ipaddr(
            self.peer).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)
        self.mtu = self.params.get("mtu", default=1500)
        self.mtu_set()
        if self.networkinterface.ping_check(self.peer, count=5) is not None:
            self.cancel("No connection to peer")

    def mtu_set(self):
        '''
        set mtu size
        '''
        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")

    def test_gro(self):
        '''
        Test GRO
        '''
        ro_type = "gro"
        ro_type_full = "generic-receive-offload"
        if not self.offload_state(ro_type_full):
            self.fail("Could not get state of %s" % ro_type)
        if self.offload_state(ro_type_full) == 'fixed':
            self.fail("Can not change the state of %s" % ro_type)
        self.offload_toggle_test(ro_type, ro_type_full)

    def test_gso(self):
        '''
        Test GSO
        '''
        ro_type = "gso"
        ro_type_full = "generic-segmentation-offload"
        if not self.offload_state(ro_type_full):
            self.fail("Could not get state of %s" % ro_type)
        if self.offload_state(ro_type_full) == 'fixed':
            self.fail("Can not change the state of %s" % ro_type)
        self.offload_toggle_test(ro_type, ro_type_full)

    def test_lro(self):
        '''
        Test LRO
        '''
        ro_type = "lro"
        ro_type_full = "large-receive-offload"
        path = '/sys/class/net/%s/device/uevent' % self.iface
        if os.path.exists(path):
            output = open(path, 'r').read()
            for line in output.splitlines():
                if "OF_NAME" in line:
                    if 'vnic' in line.split('=')[-1]:
                        self.cancel("Unsupported on vNIC")
        if not self.offload_state(ro_type_full):
            self.fail("Could not get state of %s" % ro_type)
        if self.offload_state(ro_type_full) == 'fixed':
            self.fail("Can not change the state of %s" % ro_type)
        self.offload_toggle_test(ro_type, ro_type_full)

    def test_tso(self):
        '''
        Test TSO
        '''
        ro_type = "tso"
        ro_type_full = "tcp-segmentation-offload"
        if not self.offload_state(ro_type_full):
            self.fail("Could not get state of %s" % ro_type)
        if self.offload_state(ro_type_full) == 'fixed':
            self.fail("Can not change the state of %s" % ro_type)
        self.offload_toggle_test(ro_type, ro_type_full)

    def test_ping(self):
        '''
        ping to peer machine
        '''
        if self.networkinterface.ping_check(self.peer, count=10) is not None:
            self.fail("ping test failed")

    def test_floodping(self):
        '''
        Flood ping to peer machine
        '''
        if self.networkinterface.ping_check(self.peer,
                                            count=500000,
                                            options='-f') is not None:
            self.fail("flood ping test failed")

    def test_ssh(self):
        '''
        Test ssh
        '''
        cmd = "echo hi"
        output = self.session.cmd(cmd)
        if not output.exit_status == 0:
            self.fail("unable to ssh into peer machine")

    def test_scp(self):
        '''
        Test scp
        '''
        process.run("dd if=/dev/zero of=/tmp/tempfile bs=1024000000 count=1",
                    shell=True)
        md_val1 = hashlib.md5(open('/tmp/tempfile', 'rb').read()).hexdigest()
        destination = "%s:/tmp" % self.peer
        output = self.session.copy_files('/tmp/tempfile', destination)
        if not output:
            self.fail("unable to copy into peer machine")

        source = "%s:/tmp/tempfile" % self.peer
        output = self.session.copy_files(source, '/tmp')
        if not output:
            self.fail("unable to copy from peer machine")

        md_val2 = hashlib.md5(open('/tmp/tempfile', 'rb').read()).hexdigest()
        if md_val1 != md_val2:
            self.fail("Test Failed")

    def test_jumbo_frame(self):
        '''
        Test jumbo frames
        '''
        if self.networkinterface.ping_check(self.peer,
                                            count=30,
                                            options='-i 0.1 -s %d' %
                                            (int(self.mtu) - 28)) is not None:
            self.fail("jumbo frame test failed")

    def test_statistics(self):
        '''
        Test Statistics
        '''
        rx_file = "/sys/class/net/%s/statistics/rx_packets" % self.iface
        tx_file = "/sys/class/net/%s/statistics/tx_packets" % self.iface
        rx_before = genio.read_file(rx_file)
        tx_before = genio.read_file(tx_file)
        self.networkinterface.ping_check(self.peer, count=500000, options='-f')
        rx_after = genio.read_file(rx_file)
        tx_after = genio.read_file(tx_file)
        if (rx_after <= rx_before) or (tx_after <= tx_before):
            self.log.debug("Before\nrx: %s tx: %s" % (rx_before, tx_before))
            self.log.debug("After\nrx: %s tx: %s" % (rx_after, tx_after))
            self.fail("Statistics not incremented properly")

    def mtu_set_back(self):
        '''
        Test set mtu back to 1500
        '''
        try:
            self.peer_networkinterface.set_mtu('1500')
        except Exception:
            self.peer_public_networkinterface.set_mtu('1500')
        if self.networkinterface.set_mtu('1500') is not None:
            self.cancel("Failed to set mtu in host")

    def offload_toggle_test(self, ro_type, ro_type_full):
        '''
        Check to toggle the LRO / GRO / GSO / TSO
        '''
        for state in ["off", "on"]:
            if not self.offload_state_change(ro_type, ro_type_full, state):
                self.fail("%s %s failed" % (ro_type, state))
            if self.networkinterface.ping_check(self.peer,
                                                count=500000,
                                                options='-f') is not None:
                self.fail("ping failed in %s %s" % (ro_type, state))

    def offload_state_change(self, ro_type, ro_type_full, state):
        '''
        Change the state of LRO / GRO / GSO / TSO to specified state
        '''
        cmd = "ethtool -K %s %s %s" % (self.iface, ro_type, state)
        if process.system(cmd, shell=True, ignore_status=True) != 0:
            return False
        if self.offload_state(ro_type_full) != state:
            return False
        return True

    def offload_state(self, ro_type_full):
        '''
        Return the state of LRO / GRO / GSO / TSO.
        If the state can not be changed, we return 'fixed'.
        If any other error, we return ''.
        '''
        cmd = "ethtool -k %s" % self.iface
        output = process.system_output(cmd, shell=True,
                                       ignore_status=True).decode("utf-8")
        for line in output.splitlines():
            if ro_type_full in line:
                if 'fixed' in line.split()[-1]:
                    return 'fixed'
                return line.split()[-1]
        return ''

    def test_promisc(self):
        '''
        promisc mode testing
        '''
        cmd = "ip link set %s promisc on" % self.iface
        if process.system(cmd, shell=True, ignore_status=True) != 0:
            self.fail("failed to enable promisc mode")
        self.networkinterface.ping_check(self.peer, count=100000, options='-f')
        cmd = "ip link set %s promisc off" % self.iface
        if process.system(cmd, shell=True, ignore_status=True) != 0:
            self.fail("failed to disable promisc mode")
        self.networkinterface.ping_check(self.peer, count=5)

    def tearDown(self):
        '''
        Remove the files created
        '''
        self.mtu_set_back()
        if 'scp' in str(self.name.name):
            process.run("rm -rf /tmp/tempfile")
            cmd = "rm -rf /tmp/tempfile"
            self.session.cmd(cmd)
        if self.ip_config:
            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()
        if 'scp' or 'ssh' in str(self.name.name):
            self.session.quit()
 def setUp(self):
     '''
     set up required packages and gather necessary test inputs
     '''
     self.install_packages()
     self.hmc_ip = self.get_mcp_component("HMCIPAddr")
     if not self.hmc_ip:
         self.cancel("HMC IP not got")
     self.hmc_pwd = self.params.get("hmc_pwd", '*', default=None)
     self.hmc_username = self.params.get("hmc_username", '*', default=None)
     self.lpar = self.get_partition_name("Partition Name")
     if not self.lpar:
         self.cancel("LPAR Name not got from lparstat command")
     for root, dirct, files in os.walk("/root/.ssh"):
         for file in files:
             if file.startswith("avocado-master-root"):
                 path = os.path.join(root, file)
                 os.remove(path)
     self.session_hmc = Session(self.hmc_ip,
                                user=self.hmc_username,
                                password=self.hmc_pwd)
     if not self.session_hmc.connect():
         self.cancel("failed connecting to HMC")
     cmd = 'lssyscfg -r sys  -F name'
     output = self.session_hmc.cmd(cmd)
     self.server = ''
     for line in output.stdout_text.splitlines():
         if line in self.lpar:
             self.server = line
             break
     if not self.server:
         self.cancel("Managed System not got")
     self.slot_num = self.params.get("slot_num", '*', default=None)
     self.slot_num = self.slot_num.split(' ')
     for slot in self.slot_num:
         if int(slot) < 3 or int(slot) > 2999:
             self.cancel("Slot invalid. Valid range: 3 - 2999")
     self.vios_name = self.params.get("vios_names", '*',
                                      default=None).split(' ')
     self.sriov_port = self.params.get("sriov_ports", '*',
                                       default=None).split(' ')
     self.backing_adapter = self.params.get("sriov_adapters",
                                            '*',
                                            default=None).split(' ')
     if len(self.sriov_port) != len(self.backing_adapter):
         self.cancel('Backing Device counts and port counts differ')
     if len(self.vios_name) != len(self.backing_adapter):
         self.cancel('Backing Device counts and vios name counts differ')
     self.backingdev_count = len(self.backing_adapter)
     self.bandwidth = self.params.get("bandwidth", '*', default=None)
     self.vnic_priority = self.params.get("priority", '*', default=None)
     if not self.vnic_priority:
         self.vnic_priority = [50] * len(self.backing_adapter)
     else:
         self.vnic_priority = self.vnic_priority.split(' ')
     if len(self.vnic_priority) != len(self.backing_adapter):
         self.cancel('Backing Device counts and priority counts differ')
     self.auto_failover = self.params.get("auto_failover",
                                          '*',
                                          default=None)
     if self.auto_failover not in ['0', '1']:
         self.auto_failover = '1'
     self.vios_ip = self.params.get('vios_ip', '*', default=None)
     self.vios_user = self.params.get('vios_username', '*', default=None)
     self.vios_pwd = self.params.get('vios_pwd', '*', default=None)
     self.count = int(self.params.get('vnic_test_count', default="1"))
     self.num_of_dlpar = int(self.params.get("num_of_dlpar", default='1'))
     self.device_ip = self.params.get('device_ip', '*',
                                      default=None).split(' ')
     self.mac_id = self.params.get('mac_id',
                                   default="02:03:03:03:03:01").split(' ')
     self.mac_id = [mac.replace(':', '') for mac in self.mac_id]
     self.netmask = self.params.get('netmasks', '*',
                                    default=None).split(' ')
     self.peer_ip = self.params.get('peer_ip', default=None).split(' ')
     dmesg.clear_dmesg()
     self.session_hmc.cmd("uname -a")
     cmd = 'lssyscfg -m ' + self.server + \
           ' -r lpar --filter lpar_names=' + self.lpar + \
           ' -F lpar_id'
     self.lpar_id = self.session_hmc.cmd(cmd).stdout_text.split()[0]
     self.vios_id = []
     for vios_name in self.vios_name:
         cmd = 'lssyscfg -m ' + self.server + \
               ' -r lpar --filter lpar_names=' + vios_name + \
               ' -F lpar_id'
         self.vios_id.append(
             self.session_hmc.cmd(cmd).stdout_text.split()[0])
     cmd = 'lshwres -m %s -r sriov --rsubtype adapter -F \
           phys_loc:adapter_id' % self.server
     adapter_id_output = self.session_hmc.cmd(cmd).stdout_text
     self.backing_adapter_id = []
     for backing_adapter in self.backing_adapter:
         for line in adapter_id_output.splitlines():
             if str(backing_adapter) in line:
                 self.backing_adapter_id.append(line.split(':')[1])
     if not self.backing_adapter_id:
         self.cancel("SRIOV adapter provided was not found.")
     self.rsct_service_start()
     if len(self.slot_num) > 1:
         if 'backing' in str(self.name.name) or \
            'failover' in str(self.name.name):
             self.cancel("this test is not needed")
     self.local = LocalHost()
     cmd = "echo 'module ibmvnic +p; func send_subcrq -p' > /sys/kernel/debug/dynamic_debug/control"
     result = process.run(cmd, shell=True, ignore_status=True)
     if result.exit_status:
         self.fail("failed to enable debug mode")
示例#27
0
class NetworkSriovDevice(Test):
    '''
    adding and deleting logical sriov device through
    HMC.
    '''
    def setUp(self):
        '''
        set up required packages and gather necessary test inputs
        '''
        smm = SoftwareManager()
        packages = [
            'src', 'rsct.basic', 'rsct.core.utils', 'NetworkManager',
            'rsct.core', 'DynamicRM', 'powerpc-utils'
        ]
        for pkg in packages:
            if not smm.check_installed(pkg) and not smm.install(pkg):
                self.cancel('%s is needed for the test to be run' % pkg)
        self.hmc_ip = self.get_mcp_component("HMCIPAddr")
        if not self.hmc_ip:
            self.cancel("HMC IP not got")
        self.hmc_pwd = self.params.get("hmc_pwd", '*', default=None)
        self.hmc_username = self.params.get("hmc_username", '*', default=None)
        self.lpar = self.get_partition_name("Partition Name")
        if not self.lpar:
            self.cancel("LPAR Name not got from lparstat command")
        self.session = Session(self.hmc_ip,
                               user=self.hmc_username,
                               password=self.hmc_pwd)
        if not self.session.connect():
            self.cancel("failed connetion to HMC")
        cmd = 'lssyscfg -r sys  -F name'
        output = self.session.cmd(cmd)
        self.server = ''
        for line in output.stdout_text.splitlines():
            if line in self.lpar:
                self.server = line
                break
        if not self.server:
            self.cancel("Managed System not got")
        self.sriov_adapter = self.params.get('sriov_adapter',
                                             '*',
                                             default=None).split(' ')
        self.sriov_port = self.params.get('sriov_port', '*',
                                          default=None).split(' ')
        self.ipaddr = self.params.get('ipaddr', '*', default="").split(' ')
        self.netmask = self.params.get('netmasks', '*', default="").split(' ')
        self.prefix = self.netmask_to_cidr(self.netmask[0])
        self.peer_ip = self.params.get('peer_ip', '*', default="").split(' ')
        self.mac_id = self.params.get('mac_id',
                                      default="02:03:03:03:03:01").split(' ')
        self.mac_id = [mac.replace(':', '') for mac in self.mac_id]
        self.migratable = self.params.get('migratable', '*', default=0)
        self.backup_device_type = self.params.get('backup_device_type',
                                                  '*',
                                                  default='')
        self.backup_device_slot_num = self.params.get('backup_device_slot_num',
                                                      '*',
                                                      default=None)
        self.backup_veth_vnetwork = self.params.get('backup_veth_vnetwork',
                                                    '*',
                                                    default=None)
        if 'vnic' in self.backup_device_type:
            self.vnic_sriov_adapter = self.params.get('vnic_sriov_adapter',
                                                      '*',
                                                      default=None)
            self.vnic_port_id = self.params.get('vnic_port_id',
                                                '*',
                                                default=None)
            self.vnic_adapter_id = self.get_adapter_id(self.vnic_sriov_adapter)
            self.priority = self.params.get('failover_priority',
                                            '*',
                                            default='50')
            self.max_capacity = self.params.get('max_capacity',
                                                '*',
                                                default='10')
            self.capacity = self.params.get('capacity', '*', default='2')
            self.vios_name = self.params.get('vios_name', '*', default=None)
            cmd = 'lssyscfg -m %s -r lpar --filter lpar_names=%s -F lpar_id' % (
                self.server, self.vios_name)
            self.vios_id = self.session.cmd(cmd).stdout_text.split()[0]
            self.backup_vnic_backing_device = 'sriov/%s/%s/%s/%s/%s/%s/%s' % \
                (self.vios_name, self.vios_id, self.vnic_adapter_id, self.vnic_port_id,
                 self.capacity, self.priority, self.max_capacity)
        self.local = LocalHost()

    @staticmethod
    def netmask_to_cidr(netmask):
        return (sum([bin(int(bits)).count("1")
                     for bits in netmask.split(".")]))

    def get_adapter_id(self, slot):
        cmd = "lshwres -m %s -r sriov --rsubtype adapter -F phys_loc:adapter_id" \
              % (self.server)
        output = self.session.cmd(cmd)
        for line in output.stdout_text.splitlines():
            if slot in line:
                return line.split(':')[-1]
        self.cancel("adapter not found at slot %s", slot)

    @staticmethod
    def get_mcp_component(component):
        '''
        probes IBM.MCP class for mentioned component and returns it.
        '''
        for line in process.system_output('lsrsrc IBM.MCP %s' % component,
                                          ignore_status=True, shell=True,
                                          sudo=True).decode("utf-8") \
                                                    .splitlines():
            if component in line:
                return line.split()[-1].strip('{}\"')
        return ''

    @staticmethod
    def get_partition_name(component):
        '''
        get partition name from lparstat -i
        '''

        for line in process.system_output('lparstat -i', ignore_status=True,
                                          shell=True,
                                          sudo=True).decode("utf-8") \
                                                    .splitlines():
            if component in line:
                return line.split(':')[-1].strip()
        return ''

    def test_add_logical_device(self):
        '''
        test to create logical sriov device
        '''
        if self.migratable:
            self.cancel("Test unsupported")
        for slot, port, mac, ipaddr, netmask, peer_ip in zip(
                self.sriov_adapter, self.sriov_port, self.mac_id, self.ipaddr,
                self.netmask, self.peer_ip):
            self.device_add_remove(slot, port, mac, '', 'add')
            if not self.list_device(mac):
                self.fail("failed to list logical device after add operation")
            device = self.find_device(mac)
            networkinterface = NetworkInterface(device, self.local)
            networkinterface.add_ipaddr(ipaddr, netmask)
            networkinterface.bring_up()
            if networkinterface.ping_check(peer_ip, count=5) is not None:
                self.fail("ping check failed")

    def test_add_migratable_sriov(self):
        '''
        test to create Migratable sriov device
        '''
        if not self.migratable:
            self.cancel("Test unsupported")

        for slot, port, mac, ipaddr, netmask, peer_ip in zip(
                self.sriov_adapter, self.sriov_port, self.mac_id, self.ipaddr,
                self.netmask, self.peer_ip):

            self.device_add_remove(slot, port, mac, '', 'add')
            if not self.list_device(mac):
                self.fail(
                    "failed to list Migratable logical device after add operation"
                )
            bond_device = self.get_hnv_bond(mac)
            if bond_device:
                ret = process.run(
                    'nmcli c mod id %s ipv4.method manual ipv4.addres %s/%s' %
                    (bond_device, ipaddr, self.prefix),
                    ignore_status=True)
                if ret.exit_status:
                    self.fail(
                        "nmcli ip configuration for hnv bond fail with %s" %
                        (ret.exit_status))
                ret = process.run('nmcli c up %s' % bond_device,
                                  ignore_status=True)
                if ret.exit_status:
                    self.fail("hnv bond ip bring up fail with %s" %
                              (ret.exit_status))
                networkinterface = NetworkInterface(bond_device, self.local)
                if networkinterface.ping_check(peer_ip, count=5) is not None:
                    self.fail("ping check failed for hnv bond device")
            else:
                self.fail("failed to create hnv bond device")

    def test_remove_migratable_sriov(self):
        '''
        test to remove Migratable sriov device
        '''
        if not self.migratable:
            self.cancel("Test unsupported")
        for mac, slot in zip(self.mac_id, self.sriov_adapter):
            bond_device = self.get_hnv_bond(mac)
            if bond_device:
                ret = process.run('nmcli c down %s' % bond_device,
                                  ignore_status=True)
                if ret.exit_status:
                    self.fail("hnv bond ip bring down fail with %s" %
                              (ret.exit_status))
                ret = process.run('nmcli c del %s' % bond_device,
                                  ignore_status=True)
                if ret.exit_status:
                    self.fail("hnv bond delete fail with %s" %
                              (ret.exit_status))
                logical_port_id = self.get_logical_port_id(mac)
                self.device_add_remove(slot, '', '', logical_port_id, 'remove')
                if self.list_device(mac):
                    self.fail("fail to remove migratable logical device")

    def test_remove_logical_device(self):
        """
        test to remove logical device
        """
        if self.migratable:
            self.cancel("Test unsupported")
        for mac, slot in zip(self.mac_id, self.sriov_adapter):
            logical_port_id = self.get_logical_port_id(mac)
            self.device_add_remove(slot, '', '', logical_port_id, 'remove')
            if self.list_device(mac):
                self.fail("still list logical device after remove operation")

    def device_add_remove(self, slot, port, mac, logical_id, operation):
        """
        add and remove operation of logical devices
        """
        adapter_id = self.get_adapter_id(slot)
        backup_device = ''
        if self.backup_device_type:
            if 'veth' in self.backup_device_type:
                backup_device = ',backup_device_type=%s,backup_veth_vnetwork=%s' % (
                    self.backup_device_type, self.backup_veth_vnetwork)
            else:
                backup_device = ',backup_device_type=%s,backup_vnic_backing_device=%s' % (
                    self.backup_device_type, self.backup_vnic_backing_device)

        if operation == 'add':
            cmd = 'chhwres -r sriov -m %s --rsubtype logport \
                  -o a -p %s -a \"adapter_id=%s,phys_port_id=%s, \
                  logical_port_type=eth,mac_addr=%s,migratable=%s%s\" ' \
                  % (self.server, self.lpar, adapter_id,
                     port, mac, self.migratable, backup_device)
        else:
            cmd = 'chhwres -r sriov -m %s --rsubtype logport \
                  -o r -p %s -a \"adapter_id=%s,logical_port_id=%s\" ' \
                  % (self.server, self.lpar, adapter_id, logical_id)
        cmd = self.session.cmd(cmd)
        if cmd.exit_status != 0:
            self.log.debug(cmd.stderr)
            self.fail("sriov logical device %s operation \
                       failed" % operation)

    def get_logical_port_id(self, mac):
        """
        findout logical device port id
        """
        cmd = "lshwres -r sriov --rsubtype logport -m  %s \
               --level eth | grep %s | grep %s" \
               % (self.server, self.lpar, mac)
        output = self.session.cmd(cmd)
        logical_port_id = output.stdout_text.split(',')[6].split('=')[-1]
        return logical_port_id

    def get_hnv_bond(self, mac):
        """
        Get the newly created hnv bond interface name
        """
        output = genio.read_one_line("/sys/class/net/bonding_masters").split()
        for bond in output:
            if mac in netifaces.ifaddresses(bond)[17][0]['addr'].replace(
                    ':', ''):
                return bond
        self.fail("Test fail due to mac address mismatch")

    @staticmethod
    def find_device(mac_addrs):
        """
        Finds out the latest added sriov logical device
        """
        mac = ':'.join(mac_addrs[i:i + 2] for i in range(0, 12, 2))
        devices = netifaces.interfaces()
        for device in devices:
            if mac in netifaces.ifaddresses(device)[17][0]['addr']:
                return device
        return ''

    def list_device(self, mac):
        """
        list the sriov logical device
        """
        cmd = 'lshwres -r sriov --rsubtype logport -m  ltcfleet2 \
              --level eth --filter \"lpar_names=%s\" ' % self.lpar
        output = self.session.cmd(cmd)
        if mac in output.stdout_text:
            return True
        return False

    def tearDown(self):
        self.session.quit()
示例#28
0
    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_ips",
                                                      default="").split(" ")
        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.peer_bond_needed = self.params.get("peer_bond_needed",
                                                default=False)
        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.flush_ipaddr()
                    networkinterface.add_ipaddr(ipaddr, self.netmask)
                    networkinterface.save(ipaddr, self.netmask)
                except Exception:
                    networkinterface.save(ipaddr, self.netmask)
                networkinterface.bring_up()
            for ipaddr, interface in zip(self.peer_first_ipinterface,
                                         self.peer_interfaces):
                if self.peer_bond_needed:
                    self.remotehost = RemoteHost(self.peer_public_ip,
                                                 self.user,
                                                 password=self.password)
                    peer_networkinterface = NetworkInterface(
                        interface, self.remotehost)
                    try:
                        peer_networkinterface.flush_ipaddr()
                        peer_networkinterface.add_ipaddr(ipaddr, self.netmask)
                        peer_networkinterface.save(ipaddr, self.netmask)
                    except Exception:
                        peer_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=20)
        self.sleep_time = int(self.params.get("sleep_time", default=10))
        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)
        for root, dirct, files in os.walk("/root/.ssh"):
            for file in files:
                if file.startswith("avocado-master-"):
                    path = os.path.join(root, file)
                    os.remove(path)
        self.ib = False
        if self.host_interface[0:2] == 'ib':
            self.ib = True
        self.log.info("Bond Test on IB Interface? = %s", self.ib)
        '''
        An individual interface, that has a LACP PF, cannot communicate without
        being bonded. So the test uses the public ip address to create an SSH
        session instead of the private one when setting up a bonding interface.
        '''
        if self.mode == "4" and "setup" in str(self.name.name):
            self.session = Session(self.peer_public_ip,
                                   user=self.user,
                                   password=self.password)
        else:
            self.session = Session(self.peer_first_ipinterface[0],
                                   user=self.user,
                                   password=self.password)

        if not self.session.connect():
            '''
            LACP bond interface takes some time to get it to ping peer after it
            is setup. This code block tries at most 5 times to get it to connect
            to the peer.
            '''
            if self.mode == "4":
                connect = False
                for _ in range(5):
                    if self.session.connect():
                        connect = True
                        self.log.info("Was able to connect to peer.")
                        break
                    time.sleep(5)
                if not connect:
                    self.cancel("failed connecting to peer")
            else:
                self.cancel("failed connecting to peer")
        self.setup_ip()
        self.err = []
        if self.mode == "4" and "setup" in str(self.name.name):
            self.remotehost = RemoteHost(self.peer_public_ip,
                                         self.user,
                                         password=self.password)
        else:
            self.remotehost = RemoteHost(self.peer_first_ipinterface[0],
                                         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")
示例#29
0
    def setUp(self):
        """
        Setup and install dependencies for the test.
        """
        self.test_name = "udaddy"
        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")
        detected_distro = distro.detect()
        pkgs = []
        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.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.timeout = "2m"
        self.local_ip = netifaces.ifaddresses(self.iface)[AF_INET][0]['addr']
        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)

        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")
示例#30
0
class RDMA(Test):
    '''
    RDMA test for infiniband adaptors
    '''
    def setUp(self):
        '''
        check the availability of perftest package installed
        perftest package should be installed
        '''
        smm = SoftwareManager()
        detected_distro = distro.detect()
        pkgs = ["perftest"]
        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)
        interfaces = netifaces.interfaces()
        self.iface = self.params.get("interface", default="")
        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")
        self.ipaddr = self.params.get("host_ip", default="")
        self.netmask = self.params.get("netmask", default="")
        if self.iface[0:2] == 'ib':
            configure_network.set_ip(self.ipaddr,
                                     self.netmask,
                                     self.iface,
                                     interface_type='Infiniband')
        else:
            configure_network.set_ip(self.ipaddr,
                                     self.netmask,
                                     self.iface,
                                     interface_type='Ethernet')
        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.port = self.params.get("PORT_NUM", default="1")
        self.peer_ca = self.params.get("PEERCA", default="mlx4_0")
        self.peer_port = self.params.get("PEERPORT", default="1")
        self.tmo = self.params.get("TIMEOUT", default="600")
        self.tool_name = self.params.get("tool")
        if self.tool_name == "":
            self.cancel("should specify tool name")
        self.log.info("test with %s", self.tool_name)
        self.test_op = self.params.get("test_opt", default="")
        self.mtu = self.params.get("mtu", default=1500)
        self.peerinfo = PeerInfo(self.peer_ip,
                                 peer_user=self.peer_user,
                                 peer_password=self.peer_password)
        self.peer_interface = self.peerinfo.get_peer_interface(self.peer_ip)

        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 rdma_exec(self, arg1, arg2, arg3):
        '''
        bandwidth performance exec function
        '''
        flag = 0
        logs = "> /tmp/ib_log 2>&1 &"
        cmd = "timeout %s %s -d %s -i %s %s %s %s" \
            % (self.tmo, arg1, self.peer_ca, self.peer_port, arg2, arg3, logs)
        output = self.session.cmd(cmd)
        if not output.exit_status == 0:
            self.fail("ssh failed to remote machine\
                      or  faing data from remote machine failed")
        time.sleep(2)
        self.log.info("client data for %s(%s)", arg1, arg2)
        cmd = "timeout %s %s -d %s -i %s %s %s %s" \
            % (self.tmo, arg1, self.ca_name, self.port, self.peer_ip,
               arg2, arg3)
        if process.system(cmd, shell=True, ignore_status=True) != 0:
            flag = 1
        self.log.info("server data for %s(%s)", arg1, arg2)
        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("ssh failed to remote machine\
                      or fetching data from remote machine failed")
        return flag

    def test(self):
        '''
        test options are mandatory
        '''
        if not self.peerinfo.set_mtu_peer(self.peer_interface, self.mtu):
            self.fail("Failed to set mtu in peer")
        if not configure_network.set_mtu_host(self.iface, self.mtu):
            self.fail("Failed to set mtu in host")
        if self.rdma_exec(self.tool_name, self.test_op, "") != 0:
            self.fail("Client cmd: %s %s" % (self.tool_name, self.test_op))

    def tearDown(self):
        """
        unset ip
        """
        if not configure_network.set_mtu_host(self.iface, '1500'):
            self.fail("Failed to set mtu in host")
        if not self.peerinfo.set_mtu_peer(self.peer_interface, '1500'):
            self.fail("Failed to set mtu in peer")
        configure_network.unset_ip(self.iface)