Ejemplo n.º 1
0
    def ps_show_thread(self, pid, affect_children, ps, has_ctxt_switch_info,
                       sock_inodes, sock_inode_re, cgroups):
        try:
            affinity = self.format_affinity(schedutils.get_affinity(pid))
        except (
                SystemError, OSError
        ) as e:  # (3, 'No such process') old python-schedutils incorrectly raised SystemError
            if e[0] == 3:
                return
            raise e

        sched = schedutils.schedstr(schedutils.get_scheduler(pid))[6:]
        rtprio = int(ps[pid]["stat"]["rt_priority"])
        cgout = ps[pid]["cgroups"]
        cmd = ps[pid]["stat"]["comm"]
        users = ""
        if tuna.is_irq_thread(cmd):
            try:
                if not self.irqs:
                    self.irqs = procfs.interrupts()
                if cmd[:4] == "IRQ-":
                    users = self.irqs[tuna.irq_thread_number(cmd)]["users"]
                    for u in users:
                        if u in self.get_nics():
                            users[users.index(
                                u)] = "%s(%s)" % (u, ethtool.get_module(u))
                    users = ",".join(users)
                else:
                    u = cmd[cmd.find('-') + 1:]
                    if u in self.get_nics():
                        users = ethtool.get_module(u)
            except:
                users = "Not found in /proc/interrupts!"

        ctxt_switch_info = ""
        if has_ctxt_switch_info:
            voluntary_ctxt_switches = int(
                ps[pid]["status"]["voluntary_ctxt_switches"])
            nonvoluntary_ctxt_switches = int(
                ps[pid]["status"]["nonvoluntary_ctxt_switches"])
            ctxt_switch_info = " %9d %12s" % (voluntary_ctxt_switches,
                                              nonvoluntary_ctxt_switches)

        if affect_children:
            print " %-5d " % pid,
        else:
            print "  %-5d" % pid,
        print "%6s %5d %8s%s %15s %s" % (sched, rtprio, affinity,
                                         ctxt_switch_info, cmd, users),
        if cgroups:
            print " %9s" % cgout,
        print ""
        if sock_inodes:
            self.ps_show_sockets(pid, ps, sock_inodes, sock_inode_re,
                                 affect_children and 3 or 4)
        if affect_children and ps[pid].has_key("threads"):
            for tid in ps[pid]["threads"].keys():
                self.ps_show_thread(tid, False, ps[pid]["threads"],
                                    has_ctxt_switch_info, sock_inodes,
                                    sock_inode_re)
Ejemplo n.º 2
0
def ps_show_thread(pid, affect_children, ps,
		   has_ctxt_switch_info, sock_inodes, sock_inode_re, cgroups):
	global irqs
	try:
		affinity = format_affinity(schedutils.get_affinity(pid))
	except (SystemError, OSError) as e: # (3, 'No such process') old python-schedutils incorrectly raised SystemError
		if e[0] == 3:
			return
		raise e

	sched = schedutils.schedstr(schedutils.get_scheduler(pid))[6:]
	rtprio = int(ps[pid]["stat"]["rt_priority"])
	cgout = ps[pid]["cgroups"]
	cmd = ps[pid]["stat"]["comm"]
	users = ""
	if tuna.is_irq_thread(cmd):
		try:
			if not irqs:
				irqs = procfs.interrupts()
			if cmd[:4] == "IRQ-":
				users = irqs[tuna.irq_thread_number(cmd)]["users"]
				for u in users:
					if u in get_nics():
						users[users.index(u)] = "%s(%s)" % (u, ethtool.get_module(u))
				users = ",".join(users)
			else:
				u = cmd[cmd.find('-') + 1:]
				if u in get_nics():
					users = ethtool.get_module(u)
		except:
			users = "Not found in /proc/interrupts!"

	ctxt_switch_info = ""
	if has_ctxt_switch_info:
		voluntary_ctxt_switches = int(ps[pid]["status"]["voluntary_ctxt_switches"])
		nonvoluntary_ctxt_switches = int(ps[pid]["status"]["nonvoluntary_ctxt_switches"])
		ctxt_switch_info = " %9d %12s" % (voluntary_ctxt_switches,
						  nonvoluntary_ctxt_switches)
	
	if affect_children:
		print " %-5d " % pid,
	else:
		print "  %-5d" % pid,
	print "%6s %5d %8s%s %15s %s" % (sched, rtprio, affinity,
					 ctxt_switch_info, cmd, users),
	if cgroups:
		print " %9s" % cgout,
	print ""
	if sock_inodes:
		ps_show_sockets(pid, ps, sock_inodes, sock_inode_re,
				affect_children and 3 or 4)
	if affect_children and ps[pid].has_key("threads"):
		for tid in ps[pid]["threads"].keys():
			ps_show_thread(tid, False, ps[pid]["threads"],
				       has_ctxt_switch_info,
				       sock_inodes, sock_inode_re, cgroups)
Ejemplo n.º 3
0
    def lookup(self, name):
        if encode_value(name) not in map(encode_value, ethtool.get_devices()):
            raise NotFoundError("KCHIFACE0001E", {'name': name})

        ipaddr = ''
        netmask = ''
        module = 'unknown'
        status = 'down'
        try:
            ipaddr = ethtool.get_ipaddr(encode_value(name))
            netmask = ethtool.get_netmask(encode_value(name))
            module = ethtool.get_module(encode_value(name))

            flags = ethtool.get_flags(encode_value(name))
            status = 'up' if flags & (ethtool.IFF_RUNNING | ethtool.IFF_UP) \
                     else 'down'
        except IOError:
            pass

        iface_type = netinfo.get_interface_type(name)

        return {'name': name,
                'type': iface_type,
                'status': status,
                'ipaddr': ipaddr,
                'netmask': netmask,
                'module': module}
Ejemplo n.º 4
0
def show_driver(devname):
    """
    Queries the specified network device for associated driver information

    CLI Example:

    .. code-block:: bash

        salt '*' ethtool.show_driver <devname>
    """

    try:
        module = ethtool.get_module(devname)
    except IOError:
        log.error("Driver information not implemented on %s", devname)
        return "Not implemented"

    try:
        businfo = ethtool.get_businfo(devname)
    except IOError:
        log.error("Bus information no available on %s", devname)
        return "Not available"

    ret = {
        "driver": module,
        "bus_info": businfo,
    }

    return ret
Ejemplo n.º 5
0
    def lookup(self, name):
        if encode_value(name) not in map(encode_value, ethtool.get_devices()):
            raise NotFoundError('KCHIFACE0001E', {'name': name})

        ipaddr = ''
        netmask = ''
        module = 'unknown'
        status = 'down'
        try:
            ipaddr = ethtool.get_ipaddr(encode_value(name))
            netmask = ethtool.get_netmask(encode_value(name))
            module = ethtool.get_module(encode_value(name))

            flags = ethtool.get_flags(encode_value(name))
            status = 'up' if flags & (ethtool.IFF_RUNNING
                                      | ethtool.IFF_UP) else 'down'
        except IOError:
            pass

        iface_type = netinfo.get_interface_type(name)

        return {
            'name': name,
            'type': iface_type,
            'status': status,
            'ipaddr': ipaddr,
            'netmask': netmask,
            'module': module,
        }
Ejemplo n.º 6
0
 def setUpClass(cls):
     cls.interface = interface
     cls.phy_int = get_phy_int(cls.interface)
     if cls.phy_int == None:
         raise Exception("There is no interface {0}".format(interface))
     cls.driver = ethtool.get_module(cls.phy_int)
     cls.bus = ethtool.get_businfo(cls.phy_int)
Ejemplo n.º 7
0
def show_driver(devname):
    '''
    Queries the specified network device for associated driver information

    CLI Example:

    .. code-block:: bash

        salt '*' ethtool.show_driver <devname>
    '''

    try:
        module = ethtool.get_module(devname)
    except IOError:
        log.error('Driver information not implemented on {0}'.format(devname))
        return 'Not implemented'

    try:
        businfo = ethtool.get_businfo(devname)
    except IOError:
        log.error('Bus information no available on {0}'.format(devname))
        return 'Not available'

    ret = {
        'driver': module,
        'bus_info': businfo,
    }

    return ret
Ejemplo n.º 8
0
 def __init__(self, testname, interface):
     super(TuningTest, self).__init__(testname)
     self.interface = interface
     self.phy_int = get_phy_int(self.interface)
     if self.phy_int == None:
         raise Exception("There is no interface {0}".format(interface))
     self.driver = ethtool.get_module(self.phy_int)
     self.bus = ethtool.get_businfo(self.phy_int)
Ejemplo n.º 9
0
def get_irq_users(irqs, irq, nics = None):
	if not nics:
		nics = ethtool.get_active_devices()
	users = irqs[irq]["users"]
	for u in users:
		if u in nics:
			try:
				users[users.index(u)] = "%s(%s)" % (u, ethtool.get_module(u))
			except IOError:
				# Old kernel, doesn't implement ETHTOOL_GDRVINFO
				pass
	return users
Ejemplo n.º 10
0
def show_driver(interface, args = None):
        try:
                driver = ethtool.get_module(interface)
        except IOError:
                driver = "not implemented"

        try:
                bus = ethtool.get_businfo(interface)
        except IOError:
                bus = "not available"

        printtab("driver: %s" % driver)
        printtab("bus-info: %s" % bus)
Ejemplo n.º 11
0
def show_driver(interface, args=None):
    try:
        driver = ethtool.get_module(interface)
    except IOError:
        driver = "not implemented"

    try:
        bus = ethtool.get_businfo(interface)
    except IOError:
        bus = "not available"

    printtab("driver: %s" % driver)
    printtab("bus-info: %s" % bus)
Ejemplo n.º 12
0
def find_drivers_by_users(users):
    nics = get_nics()
    drivers = []
    for u in users:
        try:
            idx = u.index("-")
            u = u[:idx]
        except:
            pass
        if u in nics:
            driver = ethtool.get_module(u)
            if driver not in drivers:
                drivers.append(driver)

    return drivers
Ejemplo n.º 13
0
def find_drivers_by_users(users):
	nics = get_nics()
	drivers = []
	for u in users:
		try:
			idx = u.index('-')
			u = u[:idx]
		except:
			pass
		if u in nics:
			driver = ethtool.get_module(u)
			if driver not in drivers:
				drivers.append(driver)
		
	return drivers
Ejemplo n.º 14
0
Archivo: rtpirq.py Proyecto: acmel/ait
def show(irqs, ps):
	irq_list = []
	for sirq in irqs.keys():
		try:
			irq_list.append(int(sirq))
		except:
			continue

	irq_list.sort()

	nics = ethtool.get_active_devices()

	for irq in irq_list:
		info = irqs[irq]
		pids = ps.find_by_name("IRQ-%d" % irq)
		if pids:
			pid = pids[0]
			thread_affinity_list = schedutils.get_affinity(pid)
			if len(thread_affinity_list) <= 4:
				thread_affinity = ",".join("%s" % a for a in thread_affinity_list)
			else:
				thread_affinity = ",".join("0x%x" % a for a in procfs.hexbitmask(schedutils.get_affinity(pid), irqs.nr_cpus))
			rtprio = int(ps[pid]["stat"]["rt_priority"])
		else:
			pid = -1
			rtprio = -1
			thread_affinity = ""

		try:
			irq_affinity_list = info["affinity"]
			if len(irq_affinity_list) <= 4:
				irq_affinity = ",".join("%s" % a for a in irq_affinity_list)
			else:
				irq_affinity = ",".join("0x%x" % a for a in procfs.hexbitmask(irq_affinity_list, irqs.nr_cpus))
		except:
			irq_affinity = ""
		events = reduce(lambda a, b: a + b, info["cpu"])
		users = info["users"]
		for u in users:
			if u in nics:
				users[users.index(u)] = "%s(%s)" % (u, ethtool.get_module(u))
		print "%5d: %5d %5d %11d %8s %8s %s" % (irq, pid, rtprio,
							events, thread_affinity,
						        irq_affinity,
						        ",".join(users))
Ejemplo n.º 15
0
Archivo: rtps.py Proyecto: cz172638/ait
def show(ps, cpuinfo, irqs):
    ps_list = []
    for pid in ps.keys():
        if schedutils.get_scheduler(pid) == 0:
            continue
        ps_list.append(pid)

    ps_list.sort()

    nics = ethtool.get_active_devices()

    for pid in ps_list:
        thread_affinity_list = schedutils.get_affinity(pid)
        if len(thread_affinity_list) <= 4:
            thread_affinity = ",".join(str(a) for a in thread_affinity_list)
        else:
            thread_affinity = ",".join(
                str(hex(a)) for a in procfs.hexbitmask(
                    schedutils.get_affinity(pid), cpuinfo.nr_cpus))
        sched = schedutils.schedstr(schedutils.get_scheduler(pid))[6:]
        rtprio = int(ps[pid]["stat"]["rt_priority"])
        cmd = ps[pid]["stat"]["comm"]
        users = ""
        if cmd[:4] == "IRQ-":
            try:
                users = irqs[cmd[4:]]["users"]
                for u in users:
                    if u in nics:
                        users[users.index(
                            u)] = "%s(%s)" % (u, ethtool.get_module(u))
                users = ",".join(users)
            except:
                users = "Not found in /proc/interrupts!"
        try:
            voluntary_ctxt_switches = int(
                ps[pid]["status"]["voluntary_ctxt_switches"])
            nonvoluntary_ctxt_switches = int(
                ps[pid]["status"]["nonvoluntary_ctxt_switches"])
        except:
            voluntary_ctxt_switches = -1
            nonvoluntary_ctxt_switches = -1
        print "%5d %6s %5d %8s %9d %12s %15s %s" % (
            pid, sched, rtprio, thread_affinity, voluntary_ctxt_switches,
            nonvoluntary_ctxt_switches, cmd, users)
Ejemplo n.º 16
0
    def driver(self):
        """driver attribute

        Returns string name of the device driver as reported by the kernel.
        Tries several methods to obtain the name.
        """
        if self.link_header_type == 772:  # loopback header type
            return 'loopback'
        linkinfo = self._nl_msg.get_attr("IFLA_LINKINFO")
        if linkinfo:
            result = linkinfo.get_attr("IFLA_INFO_KIND")
            if result and result != "unknown":
                # pyroute2 tries to be too clever and second guesses the
                # driver; when it fails, it fills in "unknown". We need to
                # ignore it.
                return result
        try:
            return ethtool.get_module(self.name)
        except IOError:
            return None
Ejemplo n.º 17
0
Archivo: rtps.py Proyecto: acmel/ait
def show(ps, cpuinfo, irqs):
	ps_list = []
	for pid in ps.keys():
		if schedutils.get_scheduler(pid) == 0:
			continue
		ps_list.append(pid)

	ps_list.sort()

	nics = ethtool.get_active_devices()

	for pid in ps_list:
		thread_affinity_list = schedutils.get_affinity(pid)
		if len(thread_affinity_list) <= 4:
			thread_affinity = ",".join(str(a) for a in thread_affinity_list)
		else:
			thread_affinity = ",".join(str(hex(a)) for a in procfs.hexbitmask(schedutils.get_affinity(pid), cpuinfo.nr_cpus))
		sched = schedutils.schedstr(schedutils.get_scheduler(pid))[6:]
		rtprio = int(ps[pid]["stat"]["rt_priority"])
		cmd = ps[pid]["stat"]["comm"]
		users = ""
		if cmd[:4] == "IRQ-":
			try:
				users = irqs[cmd[4:]]["users"]
				for u in users:
					if u in nics:
						users[users.index(u)] = "%s(%s)" % (u, ethtool.get_module(u))
				users = ",".join(users)
			except:
				users = "Not found in /proc/interrupts!"
		try:
			voluntary_ctxt_switches = int(ps[pid]["status"]["voluntary_ctxt_switches"])
			nonvoluntary_ctxt_switches = int(ps[pid]["status"]["nonvoluntary_ctxt_switches"])
		except:
			voluntary_ctxt_switches = -1
			nonvoluntary_ctxt_switches = -1
		print "%5d %6s %5d %8s %9d %12s %15s %s" % (pid, sched, rtprio,
							    thread_affinity,
							    voluntary_ctxt_switches,
							    nonvoluntary_ctxt_switches,
							    cmd, users)
Ejemplo n.º 18
0
def show_driver(devname):
    '''
    Queries the specified network device for associated driver information

    CLI Example:

    .. code-block:: bash

        salt '*' ethtool.show_driver <devname>
    '''

    try:
        module = ethtool.get_module(devname)
    except IOError:
        log.error(
            'Driver information not implemented on {0}'.format(
                devname
            )
        )
        return 'Not implemented'

    try:
        businfo = ethtool.get_businfo(devname)
    except IOError:
        log.error(
            'Bus information no available on {0}'.format(
                devname
            )
        )
        return 'Not available'

    ret = {
        'driver': module,
        'bus_info': businfo,
    }

    return ret
Ejemplo n.º 19
0
def enable_dpdk(nic1_mac, nic2_mac):
    nic1_name = get_nic_name_from_mac(nic1_mac)
    nic2_name = get_nic_name_from_mac(nic2_mac)
    nic1_businfo = my_tool.get_bus_from_name(nic1_name)
    nic2_businfo = my_tool.get_bus_from_name(nic2_name)
    cmd = """
    modprobe -r vfio-pci
    modprobe -r vfio
    modprobe vfio-pci
    modprobe vfio
    """
    log_and_run(cmd, "0,1")
    import ethtool
    driver_name = ethtool.get_module(nic1_name)
    if driver_name == "mlx5_core":
        log("This Driver is Mallenox , So just return 0")
        return 0
    if os.path.exists("/usr/share/dpdk/usertools/dpdk-devbind.py"):
        log("using dpdk-devbind.py set the vfio-pci driver to nic")
        cmd = f"""
        /usr/share/dpdk/usertools/dpdk-devbind.py -b vfio-pci {nic1_businfo}
        /usr/share/dpdk/usertools/dpdk-devbind.py -b vfio-pci {nic2_businfo}
        /usr/share/dpdk/usertools/dpdk-devbind.py --status
        """
        log_and_run(cmd)
    else:
        log("using driverctl set the vfio-pci driver to nic")
        cmd = f"""
        driverctl -v set-override {nic1_businfo} vfio-pci
        sleep 3
        driverctl -v set-override {nic2_businfo} vfio-pci
        sleep 3
        driverctl -v list-devices | grep vfio-pci
        """
        log_and_run(cmd)
    return 0
Ejemplo n.º 20
0
def read_network_interfaces():
    intDict = {}
    intDict['class'] = "NETINTERFACES"
    
    interfaces = ethtool.get_devices()
    for interface in interfaces:
        try:
            hwaddr = ethtool.get_hwaddr(interface)
        except:
            hwaddr = ""
            
        # slave devices can have their hwaddr changed
        try:
            master = os.readlink('/sys/class/net/%s/master' % interface)
        except:
            master = None

        if master:
            master_interface = os.path.basename(master)
            hwaddr = get_slave_hwaddr(master_interface, interface)

        try:
            module = ethtool.get_module(interface)
        except:
            if interface == 'lo':
                module = "loopback"
            else:
                module = "Unknown"
        try:
            ipaddr = ethtool.get_ipaddr(interface)
        except:
            ipaddr = ""

        try:
            netmask = ethtool.get_netmask(interface)
        except:
            netmask = ""

        try:
            broadcast = ethtool.get_broadcast(interface)
        except:
            broadcast = ""
            
        ip6_list = []
        try:
            # one interface may have more IPv6 addresses
            for ip6 in dev.get_ipv6_addresses():
                ip6_list.append({
                    'scope':   ip6.scope,
                    'addr':    ip6.address, 
                    'netmask': ip6.netmask
                })
        except:
            pass
        intDict[interface] = {'hwaddr':hwaddr,
                              'ipaddr':ipaddr,
                              'netmask':netmask,
                              'broadcast':broadcast,
                              'module': module,
                              'ipv6': ip6_list}

    return intDict
Ejemplo n.º 21
0
 def __init__(self, testname, interface):
     super(CxTest, self).__init__(testname)
     self.interface = interface
     self.phy_int = get_phy_int(self.interface) 
     self.driver = ethtool.get_module(self.phy_int)
     self.bus = ethtool.get_businfo(self.phy_int)
Ejemplo n.º 22
0
data = f.read()
f.close()

r = re.compile("[:\s]+")

lines = re.split("[\r\n]+", data)
active_devices = ethtool.get_active_devices()
for line in lines[2:]:
    columns = r.split(line.lstrip())

    if len(columns) < 10:
        continue
    iface_name = columns[0]
    # loopback devices has no driver and gives IOError, skip them
    try:
        driver = ethtool.get_module(iface_name)
    except IOError:
        continue

    if driver in SKIP_DRIVERS:
        continue

    if iface_name not in active_devices:
        continue

    print '{}\t{}\t{}'.format(
        host_name + '.interface.' + iface_name + '.rx_bytes', columns[1],
        time_now)
    print '{}\t{}\t{}'.format(
        host_name + '.interface.' + iface_name + '.rx_errors', columns[3],
        time_now)
Ejemplo n.º 23
0
 def _customization(self):
     nics = ethtool.get_devices()
     validValues = []
     enslaved = set()
     interfaces = set()
     for nic in nics:
         try:
             flags = ethtool.get_flags(nic)
             if flags & ethtool.IFF_LOOPBACK:
                 self.logger.debug('Detected loopback device %s' % nic)
             elif ethtool.get_module(nic) == 'bridge':
                 self.logger.debug('Detected bridge device %s' % nic)
                 if os.path.exists('/sys/class/net/%s/brif' % nic):
                     slaves = os.listdir('/sys/class/net/%s/brif' % nic)
                     self.logger.debug(
                         'Detected slaves for device %s: %s' % (
                             nic,
                             ','.join(slaves)
                         )
                     )
                     for iface in slaves:
                         if iface in nics:
                             enslaved.update([iface])
             elif netinfo.isbonding(nic):
                 slaves = netinfo.slaves(nic)
                 if not slaves:
                     self.logger.debug(
                         'Detected bond device %s without slaves' % nic
                     )
                 else:
                     self.logger.debug(
                         'Detected slaves for device %s: %s' % (
                             nic,
                             ','.join(slaves)
                         )
                     )
                     enslaved.update(slaves)
                     interfaces.update([nic])
             else:
                 interfaces.update([nic])
         except IOError as ioe:
             if ioe.errno in (None, errno.EOPNOTSUPP):
                 self.logger.debug('Detected unsupported device %s' % nic)
             else:
                 raise ioe
     validValues = list(interfaces - enslaved)
     self.logger.debug('Nics detected: %s' % ','.join(nics))
     self.logger.debug('Nics enslaved: %s' % ','.join(enslaved))
     self.logger.debug('Nics valid: %s' % ','.join(validValues))
     if not validValues:
         if enslaved:
             raise RuntimeError(
                 _(
                     'The following existing interfaces are not suitable '
                     'for vdsm: {enslaved}. You might want to pull out an '
                     'interface out of a bridge to be able to use it'
                 ).format(
                     enslaved=','.join(enslaved)
                 )
             )
         else:
             raise RuntimeError(_('A Network interface is required'))
     interactive = self.environment[
         ohostedcons.NetworkEnv.BRIDGE_IF
     ] is None
     if interactive:
         default = ohostedcons.Defaults.DEFAULT_BRIDGE_IF
         if default not in validValues:
             default = validValues[0]
         self.environment[
             ohostedcons.NetworkEnv.BRIDGE_IF
         ] = self.dialog.queryString(
             name='ovehosted_bridge_if',
             note=_(
                 'Please indicate a nic to set '
                 '{bridge} bridge on: (@VALUES@) [@DEFAULT@]: '
             ).format(
                 bridge=self.environment[
                     ohostedcons.NetworkEnv.BRIDGE_NAME
                 ]
             ),
             prompt=True,
             caseSensitive=True,
             default=default,
             validValues=validValues,
         )
Ejemplo n.º 24
0
def main(interfaces, checkOnly):    
    tuned_int = []
    cpu = get_cpu_name()

    tune_irqbalance()

    for interface in interfaces:
        phy_int = get_phy_int(interface)
        numa = get_numa(phy_int)
        local_cores = get_local_cores(numa)

        if phy_int is None:
            print("Cannot find interface {0}. Ignoring {0}..".format(interface))
            continue
        else:
            print('Starting Test for {}'.format(interface))
        if phy_int not in tuned_int:
            tune_irq_affinity(phy_int)
            tuned_int.append(phy_int)

        #load generic tests
        test_loader = unittest.TestLoader()
        generic_test_names = test_loader.getTestCaseNames(TuningTest)
        generic_suite = unittest.TestSuite()
        for test_name in generic_test_names:
            generic_suite.addTest(TuningTest(test_name, interface))
        
        print('\n----------------------Starting Generic test---------------------------')
        #generic test
        test_result = unittest.TextTestRunner(verbosity=2).run(generic_suite)
        if not checkOnly:
            for failure in test_result.failures:
                testname = failure[0].id().split(".")[-1]
                if testname == 'test_sysctl_value':
                    tune_sysctl()
                elif testname == 'test_fq':
                    tune_fq(phy_int)
                elif testname == 'test_mtu':
                    tune_mtu(interface)
                elif testname == 'test_cpu_governor':
                    tune_cpu_governer()
                elif testname == 'test_pci_speed':
                    print('Please check the PCI slot for {}'.format(interface))
                elif testname == 'test_flow_control':
                    tune_flow_control(phy_int)
                elif testname == 'test_iommu':
                    print('Please add iommu=pt to the kernel parameter')     

        print('\n---------------Starting Mellanox specific test------------------------')
        #load mellanox connectx-4 and 5 specific test
        if ethtool.get_module(phy_int) == 'mlx5_core':
            test_names = test_loader.getTestCaseNames(CxTest)
            testsuite = unittest.TestSuite()
            for test_name in test_names:
                testsuite.addTest(CxTest(test_name, interface))
        
            test_result = unittest.TextTestRunner(verbosity=2).run(testsuite)
            if not checkOnly:
                for failure in test_result.failures:
                    testname = failure[0].id().split(".")[-1]
                    if testname == 'test_maxreadreq':
                        tune_mellanox(phy_int)
                    elif testname == 'test_ring_size':
                        tune_ring_size(phy_int)
                    elif testname == 'test_dropless_rq':
                        tune_dropless_rq(interface)
        
        print('\n------------------Starting AMD specific test--------------------------')        
        if "AMD EPYC 7" in cpu:
            test_names = test_loader.getTestCaseNames(AMDTest)
            testsuite = unittest.TestSuite()
            for test_name in test_names:
                testsuite.addTest(AMDTest(test_name, interface))
        
            test_result = unittest.TextTestRunner(verbosity=2).run(testsuite)

            if not checkOnly:
                for failure in test_result.failures:
                    testname = failure[0].id().split(".")[-1]
                    if testname == 'test_irq_size':
                        tune_irq_size(phy_int,local_cores)
                    elif testname == 'test_iommu':
                        print('Please add iommu=pt to the kernel parameter')

        print('Done')
Ejemplo n.º 25
0
def read_network_interfaces():
    intDict = {}
    intDict['class'] = "NETINTERFACES"

    if not ethtool_present and not netifaces_present:
        # ethtool is not available on non-linux platforms (as kfreebsd), skip it
        sys.stderr.write(
            "Warning: information about network interfaces could not be retrieved on this platform.\n"
        )
        return intDict

    if ethtool_present:
        interfaces = list(
            set(ethtool.get_devices() + ethtool.get_active_devices()))
    else:
        interfaces = netifaces.interfaces()

    for interface in interfaces:
        try:
            if ethtool_present:
                hwaddr = ethtool.get_hwaddr(interface)
            else:
                hwaddr = netifaces.ifaddresses(interface)[
                    netifaces.AF_LINK][0]['addr']
        except:
            hwaddr = ""

        # slave devices can have their hwaddr changed
        try:
            master = os.readlink('/sys/class/net/%s/master' % interface)
        except:
            master = None

        if master:
            master_interface = os.path.basename(master)
            hwaddr = get_slave_hwaddr(master_interface, interface)

        try:
            if ethtool_present:
                module = ethtool.get_module(interface)
            else:
                driver_file = open(
                    '/sys/class/net/%s/device/uevent' % interface, 'r')
                module = driver_file.readline().split('=')[1].strip()
                driver_file.close()
        except:
            if interface == 'lo':
                module = "loopback"
            else:
                module = "Unknown"

        try:
            if ethtool_present:
                ipaddr = ethtool.get_ipaddr(interface)
            else:
                ipaddr = netifaces.ifaddresses(interface)[
                    netifaces.AF_INET][0]['addr']
        except:
            ipaddr = ""

        try:
            if ethtool_present:
                netmask = ethtool.get_netmask(interface)
            else:
                netmask = netifaces.ifaddresses(interface)[
                    netifaces.AF_INET][0]['netmask']
        except:
            netmask = ""

        try:
            if ethtool_present:
                broadcast = ethtool.get_broadcast(interface)
            else:
                broadcast = netifaces.ifaddresses(interface)[
                    netifaces.AF_INET][0]['broadcast']
        except:
            broadcast = ""

        ip6_list = []
        if ethtool_present:
            dev_info = ethtool.get_interfaces_info(interface)
            for info in dev_info:
                # one interface may have more IPv6 addresses
                for ip6 in info.get_ipv6_addresses():
                    scope = ip6.scope
                    if scope == 'global':
                        scope = 'universe'
                    ip6_list.append({
                        'scope': scope,
                        'addr': ip6.address,
                        'netmask': ip6.netmask
                    })

        else:
            try:
                for dev_info in netifaces.ifaddresses(interface)[
                        netifaces.AF_INET6]:
                    ip6_addr = dev_info['addr'].split('%')[0]

                    scope_info = ipaddress.IPv6Address(ip6_addr)
                    if scope_info.is_global:
                        scope = 'universe'
                    elif scope_info.is_link_local:
                        scope = 'link'
                    elif scope_info.is_loopback:
                        scope = 'host'
                    elif scope_info.is_site_local:
                        scope = 'site'

                    # count number of '1' bits in netmask returned by netifaces
                    ip6_netmask = dev_info['netmask']
                    netmask_bits = 0
                    for two_octets in ip6_netmask.split(':'):
                        if not two_octets:
                            break
                        elif two_octets.lower() == 'ffff':
                            netmask_bits += 16
                        else:
                            # remove '0b' from begin and find last '1' in the string
                            netmask_bits += 1 + bin(
                                int(two_octets.split('/')[0],
                                    16))[2:].rindex('1')

                    ip6_list.append({
                        'scope': scope,
                        'addr': ip6_addr,
                        'netmask': netmask_bits
                    })
            except KeyError:
                pass  # no ipv6 for this interface

        intDict[interface] = {
            'hwaddr': hwaddr,
            'ipaddr': ipaddr,
            'netmask': netmask,
            'broadcast': broadcast,
            'module': module,
            'ipv6': ip6_list
        }

    return intDict
Ejemplo n.º 26
0
 def is_ifc_module(self, ifc, fabric_type):
     modules = {'eth': 'mlx4_en', 'ib': 'ipoib'}
     if modules[fabric_type] in ethtool.get_module(ifc):
         return True
Ejemplo n.º 27
0
 def _customization(self):
     nics = ethtool.get_devices()
     validValues = []
     enslaved = set()
     interfaces = set()
     for nic in nics:
         try:
             flags = ethtool.get_flags(nic)
             if flags & ethtool.IFF_LOOPBACK:
                 self.logger.debug('Detected loopback device %s' % nic)
             elif ethtool.get_module(nic) == 'bridge':
                 self.logger.debug('Detected bridge device %s' % nic)
                 if os.path.exists('/sys/class/net/%s/brif' % nic):
                     slaves = os.listdir('/sys/class/net/%s/brif' % nic)
                     self.logger.debug('Detected slaves for device %s: %s' %
                                       (nic, ','.join(slaves)))
                     for iface in slaves:
                         if iface in nics:
                             enslaved.update([iface])
             elif netinfo.isbonding(nic):
                 slaves = netinfo.slaves(nic)
                 if not slaves:
                     self.logger.debug(
                         'Detected bond device %s without slaves' % nic)
                 else:
                     self.logger.debug('Detected slaves for device %s: %s' %
                                       (nic, ','.join(slaves)))
                     enslaved.update(slaves)
                     interfaces.update([nic])
             else:
                 interfaces.update([nic])
         except IOError as ioe:
             if ioe.errno in (None, errno.EOPNOTSUPP):
                 self.logger.debug('Detected unsupported device %s' % nic)
             else:
                 raise ioe
     validValues = list(interfaces - enslaved)
     self.logger.debug('Nics detected: %s' % ','.join(nics))
     self.logger.debug('Nics enslaved: %s' % ','.join(enslaved))
     self.logger.debug('Nics valid: %s' % ','.join(validValues))
     if not validValues:
         if enslaved:
             raise RuntimeError(
                 _('The following existing interfaces are not suitable '
                   'for vdsm: {enslaved}. You might want to pull out an '
                   'interface out of a bridge to be able to use it').format(
                       enslaved=','.join(enslaved)))
         else:
             raise RuntimeError(_('A Network interface is required'))
     interactive = self.environment[
         ohostedcons.NetworkEnv.BRIDGE_IF] is None
     if interactive:
         default = ohostedcons.Defaults.DEFAULT_BRIDGE_IF
         if default not in validValues:
             default = validValues[0]
         self.environment[
             ohostedcons.NetworkEnv.BRIDGE_IF] = self.dialog.queryString(
                 name='ovehosted_bridge_if',
                 note=_(
                     'Please indicate a nic to set '
                     '{bridge} bridge on: (@VALUES@) [@DEFAULT@]: ').format(
                         bridge=self.environment[
                             ohostedcons.NetworkEnv.BRIDGE_NAME]),
                 prompt=True,
                 caseSensitive=True,
                 default=default,
                 validValues=validValues,
             )
Ejemplo n.º 28
0
data = f.read()
f.close()
 
r = re.compile("[:\s]+")
 
lines = re.split("[\r\n]+", data)
active_devices = ethtool.get_active_devices()
for line in lines[2:]:
	columns = r.split(line.lstrip())

	if len(columns) < 10:
            continue
	iface_name = columns[0]	
	# loopback devices has no driver and gives IOError, skip them
	try:	
		driver = ethtool.get_module(iface_name)
	except IOError: continue


	if driver in SKIP_DRIVERS:
		continue	

	if iface_name not in active_devices:
		continue


 	print '{}\t{}\t{}'.format(host_name + '.interface.' + iface_name + '.rx_bytes', columns[1], time_now)
 	print '{}\t{}\t{}'.format(host_name + '.interface.' + iface_name + '.rx_errors', columns[3], time_now)
 	print '{}\t{}\t{}'.format(host_name + '.interface.' + iface_name + '.tx_bytes', columns[9], time_now)
 	print '{}\t{}\t{}'.format(host_name + '.interface.' + iface_name + '.tx_errors', columns[11], time_now)
Ejemplo n.º 29
0
ignored = {}
excluded = {}
debug = []

if debug_out:
    debug.append("EXCLUDES: '%s', '%s', '%s'" %
                 (exclude_names, exclude_module_types, exclude_bus_types))
    debug.append("INCLUDE: '%s', '%s', '%s'" %
                 (include_names, include_module_types, include_bus_types))
    debug.append("IGNORE: '%s', '%s', '%s'" %
                 (ignore_names, ignore_module_types, ignore_bus_types))

for i in ethtool.get_devices():
    o = {"name": i}
    try:
        module = ethtool.get_module(i)
        businfo = ethtool.get_businfo(i)

        # If it matches an ignore pattern then just ignore it.
        if has_match(i, module, businfo, ignore_names, ignore_module_types,
                     ignore_bus_types):
            if debug_out: debug.append("IGNORE '%s' on ignore match" % i)
            ignored[i] = {
                "name": i,
                "module": module,
            }
            continue

        # If no include specifications have been set and the interface is not ignored
        # it needs to be considered for inclusion
        if len(include_names) + len(include_module_types) + len(
Ejemplo n.º 30
0
def read_network_interfaces():
    intDict = {}
    intDict['class'] = "NETINTERFACES"

    if not ethtool_present:
        # ethtool is not available on non-linux platforms (as kfreebsd), skip it
        return intDict

    interfaces = list(set(ethtool.get_devices() + ethtool.get_active_devices()))
    for interface in interfaces:
        try:
            hwaddr = ethtool.get_hwaddr(interface)
        except:
            hwaddr = ""

        # slave devices can have their hwaddr changed
        try:
            master = os.readlink('/sys/class/net/%s/master' % interface)
        except:
            master = None

        if master:
            master_interface = os.path.basename(master)
            hwaddr = get_slave_hwaddr(master_interface, interface)

        try:
            module = ethtool.get_module(interface)
        except:
            if interface == 'lo':
                module = "loopback"
            else:
                module = "Unknown"
        try:
            ipaddr = ethtool.get_ipaddr(interface)
        except:
            ipaddr = ""

        try:
            netmask = ethtool.get_netmask(interface)
        except:
            netmask = ""

        try:
            broadcast = ethtool.get_broadcast(interface)
        except:
            broadcast = ""

        ip6_list = []
        dev_info = ethtool.get_interfaces_info(interface)
        for info in dev_info:
            # one interface may have more IPv6 addresses
            for ip6 in info.get_ipv6_addresses():
                scope = ip6.scope
                if scope == 'global':
                    scope = 'universe'
                ip6_list.append({
                    'scope':   scope,
                    'addr':    ip6.address,
                    'netmask': ip6.netmask
                })
        intDict[interface] = {'hwaddr':hwaddr,
                              'ipaddr':ipaddr,
                              'netmask':netmask,
                              'broadcast':broadcast,
                              'module': module,
                              'ipv6': ip6_list}

    return intDict
Ejemplo n.º 31
0
def read_network_interfaces():
    intDict = {}
    intDict['class'] = "NETINTERFACES"

    if not ethtool_present:
        # ethtool is not available on non-linux platforms (as kfreebsd), skip it
        return intDict

    interfaces = list(set(ethtool.get_devices() +
                          ethtool.get_active_devices()))
    for interface in interfaces:
        try:
            hwaddr = ethtool.get_hwaddr(interface)
        except:
            hwaddr = ""

        # slave devices can have their hwaddr changed
        try:
            master = os.readlink('/sys/class/net/%s/master' % interface)
        except:
            master = None

        if master:
            master_interface = os.path.basename(master)
            hwaddr = get_slave_hwaddr(master_interface, interface)

        try:
            module = ethtool.get_module(interface)
        except:
            if interface == 'lo':
                module = "loopback"
            else:
                module = "Unknown"
        try:
            ipaddr = ethtool.get_ipaddr(interface)
        except:
            ipaddr = ""

        try:
            netmask = ethtool.get_netmask(interface)
        except:
            netmask = ""

        try:
            broadcast = ethtool.get_broadcast(interface)
        except:
            broadcast = ""

        ip6_list = []
        dev_info = ethtool.get_interfaces_info(interface)
        for info in dev_info:
            # one interface may have more IPv6 addresses
            for ip6 in info.get_ipv6_addresses():
                scope = ip6.scope
                if scope == 'global':
                    scope = 'universe'
                ip6_list.append({
                    'scope': scope,
                    'addr': ip6.address,
                    'netmask': ip6.netmask
                })
        intDict[interface] = {
            'hwaddr': hwaddr,
            'ipaddr': ipaddr,
            'netmask': netmask,
            'broadcast': broadcast,
            'module': module,
            'ipv6': ip6_list
        }

    return intDict
Ejemplo n.º 32
0
def read_network_interfaces():
    intDict = {}
    intDict['class'] = "NETINTERFACES"

    if not ethtool_present and not netifaces_present:
        # ethtool is not available on non-linux platforms (as kfreebsd), skip it
        sys.stderr.write("Warning: information about network interfaces could not be retrieved on this platform.\n")
        return intDict

    if ethtool_present:
        interfaces = list(set(ethtool.get_devices() + ethtool.get_active_devices()))
    else:
        interfaces = netifaces.interfaces()

    for interface in interfaces:
        try:
            if ethtool_present:
                hwaddr = ethtool.get_hwaddr(interface)
            else:
                hwaddr = netifaces.ifaddresses(interface)[netifaces.AF_LINK][0]['addr']
        except:
            hwaddr = ""

        # slave devices can have their hwaddr changed
        try:
            master = os.readlink('/sys/class/net/%s/master' % interface)
        except:
            master = None

        if master:
            master_interface = os.path.basename(master)
            hwaddr = get_slave_hwaddr(master_interface, interface)

        try:
            if ethtool_present:
                module = ethtool.get_module(interface)
            else:
                driver_file = open('/sys/class/net/%s/device/uevent' % interface, 'r')
                module = driver_file.readline().split('=')[1].strip()
                driver_file.close()
        except:
            if interface == 'lo':
                module = "loopback"
            else:
                module = "Unknown"

        try:
            if ethtool_present:
                ipaddr = ethtool.get_ipaddr(interface)
            else:
                ipaddr = netifaces.ifaddresses(interface)[netifaces.AF_INET][0]['addr']
        except:
            ipaddr = ""

        try:
            if ethtool_present:
                netmask = ethtool.get_netmask(interface)
            else:
                netmask = netifaces.ifaddresses(interface)[netifaces.AF_INET][0]['netmask']
        except:
            netmask = ""

        try:
            if ethtool_present:
                broadcast = ethtool.get_broadcast(interface)
            else:
                broadcast = netifaces.ifaddresses(interface)[netifaces.AF_INET][0]['broadcast']
        except:
            broadcast = ""

        ip6_list = []
        if ethtool_present:
            dev_info = ethtool.get_interfaces_info(interface)
            for info in dev_info:
                # one interface may have more IPv6 addresses
                for ip6 in info.get_ipv6_addresses():
                    scope = ip6.scope
                    if scope == 'global':
                        scope = 'universe'
                    ip6_list.append({
                        'scope':   scope,
                        'addr':    ip6.address,
                        'netmask': ip6.netmask
                    })

        else:
            try:
                for dev_info in netifaces.ifaddresses(interface)[netifaces.AF_INET6]:
                    ip6_addr = dev_info['addr'].split('%')[0]

                    scope_info = ipaddress.IPv6Address(ip6_addr)
                    if scope_info.is_global:
                        scope = 'universe'
                    elif scope_info.is_link_local:
                        scope = 'link'
                    elif scope_info.is_loopback:
                        scope = 'host'
                    elif scope_info.is_site_local:
                        scope = 'site'

                    # count number of '1' bits in netmask returned by netifaces
                    ip6_netmask = dev_info['netmask']
                    netmask_bits = 0
                    for two_octets in ip6_netmask.split(':'):
                        if not two_octets:
                            break
                        elif two_octets.lower() == 'ffff':
                            netmask_bits += 16
                        else:
                            # remove '0b' from begin and find last '1' in the string
                            netmask_bits += 1 + bin(int(two_octets.split('/')[0], 16))[2:].rindex('1')

                    ip6_list.append({
                            'scope':   scope,
                            'addr':    ip6_addr,
                            'netmask': netmask_bits
                    })
            except KeyError:
                pass  # no ipv6 for this interface

        intDict[interface] = {'hwaddr': hwaddr,
                              'ipaddr': ipaddr,
                              'netmask': netmask,
                              'broadcast': broadcast,
                              'module': module,
                              'ipv6': ip6_list}

    return intDict
Ejemplo n.º 33
0
 def get_nic_driver_from_name(self, name):
     if name:
         return ethtool.get_module(name)
     else:
         return ""
Ejemplo n.º 34
0
 def is_ifc_module(self, ifc, fabric_type):
     modules = {'eth':'mlx4_en', 'ib':'ipoib'}
     if modules[fabric_type] in ethtool.get_module(ifc):
         return True
Ejemplo n.º 35
0
        raise ValueError('Unknown option to task "%s"' % key)

included = {}
ignored = {}
excluded = {}
debug = []

if debug_out:
    debug.append("EXCLUDES: '%s', '%s', '%s'" % (exclude_names, exclude_module_types, exclude_bus_types))
    debug.append("INCLUDE: '%s', '%s', '%s'" % (include_names, include_module_types, include_bus_types))
    debug.append("IGNORE: '%s', '%s', '%s'" % (ignore_names, ignore_module_types, ignore_bus_types))

for i in ethtool.get_devices():
    o = { "name": i }
    try:
        module = ethtool.get_module(i)
        businfo = ethtool.get_businfo(i)

        # If it matches an ignore pattern then just ignore it.
        if has_match(i, module, businfo, ignore_names, ignore_module_types, ignore_bus_types):
            if debug_out: debug.append("IGNORE '%s' on ignore match" % i)
            ignored[i] = {
                "name": i,
                "module": module,
            }
            continue

        # If no include specifications have been set and the interface is not ignored
        # it needs to be considered for inclusion
        if len(include_names) + len(include_module_types) + len(include_bus_types) == 0:
            # If it matches exclude list then exclude it, else include it