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.flush_ipaddr()
                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")
            self.remotehost.remote_session.quit()
        except Exception:
            self.log.debug("Could not revert peer interface MTU to 1500")
예제 #2
0
    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)

        for ipaddr, host_interface in zip(self.ipaddr, self.host_interfaces):
            networkinterface = NetworkInterface(host_interface, self.localhost)
            try:
                networkinterface.flush_ipaddr()
                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.")

        if self.peer_bond_needed:
            self.bond_remove("peer")
            for ipaddr, interface in zip(self.peer_first_ipinterface,
                                         self.peer_interfaces):
                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.bring_up()
                except Exception:
                    peer_networkinterface.save(ipaddr, self.netmask)
                time.sleep(self.sleep_time)
        self.error_check()

        detected_distro = distro.detect()
        if detected_distro.name == "rhel":
            cmd = "systemctl restart NetworkManager.service"
        elif detected_distro.name == "Ubuntu":
            cmd = "systemctl restart networking"
        else:
            cmd = "systemctl restart network"
        if process.system(cmd, shell=True, ignore_status=True) != 0:
            self.fail("Failed to restart the network service on host")

        try:
            for interface in self.peer_interfaces:
                peer_networkinterface = NetworkInterface(
                    interface, self.remotehost)
                peer_networkinterface.set_mtu("1500")
            self.remotehost.remote_session.quit()
        except Exception:
            self.log.debug("Could not revert peer interface MTU to 1500")
예제 #3
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")