Exemple #1
0
    def __init__(self, params):
        self.mount_dir = params.get("nfs_mount_dir")
        self.mount_options = params.get("nfs_mount_options")
        self.mount_src = params.get("nfs_mount_src")
        self.nfs_setup = False
        path.find_command("mount")
        self.rm_mount_dir = False
        self.rm_export_dir = False
        self.unexportfs_in_clean = False
        distro_details = distro.detect().name
        self.session = None
        self.setup_nfs_ip = params.get("nfs_server_ip", "127.0.0.1")
        self.export_dir = (params.get("export_dir")
                           or self.mount_src.split(":")[-1])
        self.export_ip = params.get("export_ip", "*")
        self.export_options = params.get("export_options", "").strip()

        if params.get("setup_remote_nfs") == "yes":
            self.nfs_setup = True
            self.setup_nfs_ip = params["nfs_server_ip"]
            nfs_server_params = {
                'server_ip': self.setup_nfs_ip,
                'server_pwd': params["nfs_server_pwd"],
                'server_user': params.get("nfs_server_user", "root")
            }
            self.session = test_setup.remote_session(nfs_server_params)
            distro_details = utils_misc.get_distro(self.session)
            if self.session.cmd_status("exportfs -h") != 0:
                logging.error("exportfs cmd not available in remote host")

        elif params.get("setup_local_nfs") == "yes":
            self.nfs_setup = True
            self.setup_nfs_ip = "127.0.0.1"
            path.find_command("service")
            path.find_command("exportfs")

        if (params.get("setup_remote_nfs") == "yes"
                or params.get("setup_local_nfs") == "yes"):
            if 'Ubuntu' in distro_details or 'rhel' in distro_details:
                self.nfs_service = service.Service("nfs-server",
                                                   session=self.session)
            else:
                self.nfs_service = service.Service("nfs", session=self.session)

            self.rpcbind_service = service.Service("rpcbind",
                                                   session=self.session)
            self.exportfs = Exportfs(self.export_dir,
                                     self.export_ip,
                                     self.export_options,
                                     session=self.session)
        self.mount_src = "%s:%s" % (self.setup_nfs_ip, self.export_dir)
Exemple #2
0
    def ping_vm(self, vm, params, uri=None, ping_count=10, ping_timeout=60):
        """
        Method used to ping the VM before and after migration

        :param vm: VM object
        :param params: Test dict params
        :param uri: connect uri
        :param ping_count: count of icmp packet
        :param ping_timeout: Timeout for the ping command
        """
        vm_ip = params.get("vm_ip_dict", {})
        server_session = None
        func = exceptions.TestError
        if uri and uri != "qemu:///system":
            func = exceptions.TestFail
            src_uri = "qemu:///system"
            vm.connect_uri = uri
            server_session = test_setup.remote_session(params)
            # after migration VM would take some time to respond and to
            # avoid the race of framework querying IP address before VM
            # starts responding, provide timeout for 240 seconds to retry
            # and raise if VM fails to respond
            vm_ip[vm.name] = vm.get_address(session=server_session,
                                            timeout=240)
            logging.info("Check VM network connectivity after migrating")
        else:
            logging.info("Check VM network connectivity before migration")
            if not vm.is_alive():
                vm.start()
            vm.wait_for_login()
            vm_ip[vm.name] = vm.get_address()
            params["vm_ip_dict"] = vm_ip
        s_ping, o_ping = utils_net.ping(vm_ip[vm.name],
                                        count=ping_count,
                                        timeout=ping_timeout,
                                        output_func=logging.debug,
                                        session=server_session)
        logging.info(o_ping)
        if uri:
            vm.connect_uri = src_uri
            if server_session:
                server_session.close()
        if s_ping != 0:
            if uri:
                if "offline" in params.get("migrate_options"):
                    logging.info(
                        "Offline Migration: %s will not responded to "
                        "ping as expected", vm.name)
                    return
            func("%s did not respond after %d sec." % (vm.name, ping_timeout))