def __init__(self, ifid, proc=None): """ Initialize a class instance network interface corresponding to 'ifid' on the host associated with the 'proc' object. The 'ifid' argumen can be either the network interface name or its hardware address (e.g., the PCI address of the network card corresponding to the network interface). By default this class is intialized for the local host, but 'proc' can be used to pass a connected 'SSH' object, in which case all operation will be done on the remote host. This object will keep a 'proc' reference and use it in various methods. """ if not proc: proc = Procs.Proc() self._ifid = ifid self._proc = proc self.ifname = None self.hwaddr = None self._sysfsbase = None self._saved_ip_info = {} self._ip_tool_present = None sysfsbase = _SYSFSBASE.joinpath(ifid) if FSHelpers.isdir(sysfsbase, proc=proc): # 'ifid' is a network interface name. self.ifname = ifid self._sysfsbase = sysfsbase self.hwaddr = self._get_hw_addr() else: # 'ifid' is probably a HW address (e.g., PCI address). self.ifname = self._hw_addr_to_ifname() if not self.ifname: self._raise_iface_not_found() self.hwaddr = ifid self._sysfsbase = _SYSFSBASE.joinpath(self.ifname)
def _deploy_drivers(args, proc): """Deploy drivers to the SUT represented by 'proc'.""" drvsrc = find_app_data("wult", _DRV_SRC_SUBPATH/f"{args.toolname}", descr=f"{args.toolname} drivers sources") if not drvsrc.is_dir(): raise Error(f"path '{drvsrc}' does not exist or it is not a directory") kver = None if not args.ksrc: kver = KernelVersion.get_kver(proc=proc) if not args.ksrc: args.ksrc = Path(f"/lib/modules/{kver}/build") else: args.ksrc = FSHelpers.abspath(args.ksrc, proc=proc) if not FSHelpers.isdir(args.ksrc, proc=proc): raise Error(f"kernel sources directory '{args.ksrc}' does not exist{proc.hostmsg}") if not kver: kver = KernelVersion.get_kver_ktree(args.ksrc, proc=proc) _LOG.info("Kernel sources path: %s", args.ksrc) _LOG.info("Kernel version: %s", kver) if KernelVersion.kver_lt(kver, args.minkver): raise Error(f"version of the kernel{proc.hostmsg} is {kver}, and it is not new enough.\n" f"Please, use kernel version {args.minkver} or newer.") _LOG.debug("copying the drivers to %s:\n '%s' -> '%s'", proc.hostname, drvsrc, args.stmpdir) proc.rsync(f"{drvsrc}/", args.stmpdir / "drivers", remotesrc=False, remotedst=True) drvsrc = args.stmpdir / "drivers" kmodpath = Path(f"/lib/modules/{kver}") if not FSHelpers.isdir(kmodpath, proc=proc): raise Error(f"kernel modules directory '{kmodpath}' does not exist{proc.hostmsg}") # Build the drivers on the SUT. _LOG.info("Compiling the drivers%s", proc.hostmsg) cmd = f"make -C '{drvsrc}' KSRC='{args.ksrc}'" if args.debug: cmd += " V=1" stdout, stderr, exitcode = proc.run(cmd) if exitcode != 0: msg = proc.cmd_failed_msg(cmd, stdout, stderr, exitcode) if "synth_event_" in stderr: msg += "\n\nLooks like synthetic events support is disabled in your kernel, enable " \ "the 'CONFIG_SYNTH_EVENTS' kernel configuration option." raise Error(msg) _log_cmd_output(args, stdout, stderr) # Deploy the drivers. dstdir = kmodpath / _DRV_SRC_SUBPATH FSHelpers.mkdir(dstdir, parents=True, exist_ok=True, proc=proc) for name in _get_deployables(drvsrc, proc): installed_module = _get_module_path(proc, name) srcpath = drvsrc / f"{name}.ko" dstpath = dstdir / f"{name}.ko" _LOG.info("Deploying driver '%s' to '%s'%s", name, dstpath, proc.hostmsg) proc.rsync(srcpath, dstpath, remotesrc=True, remotedst=True) if installed_module and installed_module.resolve() != dstpath.resolve(): _LOG.debug("removing old module '%s'%s", installed_module, proc.hostmsg) proc.run_verify(f"rm -f '{installed_module}'") stdout, stderr = proc.run_verify(f"depmod -a -- '{kver}'") _log_cmd_output(args, stdout, stderr) # Potentially the deployed driver may crash the system before it gets to write-back data # to the file-system (e.g., what 'depmod' modified). This may lead to subsequent boot # problems. So sync the file-system now. proc.run_verify("sync")