Example #1
0
def createSwitchForPifs(host, bondpifs):
    # find out switch type
    
    # For each PIF, get eth/NIC number and NETPORT string

    nics = []
    netports = [] 
    
    # find interface, NIC and NETPORT string corresponding to the PIF
    # We can't rely on the device as the enumeration may change in XenServer - instead use the MAC address
    macMappings = {} # This maps a MAC address to an assumed id
    macMappings[xenrt.normaliseMAC(host.lookup("MAC_ADDRESS"))] = 0
    nicData = host.lookup("NICS")
    for n in nicData.keys():
        assumedid = int(n.replace("NIC",""))
        macMappings[xenrt.normaliseMAC(nicData[n]['MAC_ADDRESS'])] = assumedid

    for pif in bondpifs :
        mac = host.genParamGet("pif", pif, "MAC")
        i = macMappings[xenrt.normaliseMAC(mac)]
        nic = "NIC%s" % i 
        nics.append(nic)
        netport = None
        if nic == "NIC0" : 
            netport = host.lookup("NETPORT", None)
        else:
            netport = host.lookup(["NICS", nic, "NETPORT"], None)
        print "netport is %s" % netport
        if not netport: 
            raise xenrt.XRTError("Could not find NETPORT information for host %s, %s, %s.\n" 
                    % (host.getName(), nic, pif) )
        if len(netport.split("/")) != 2:
            raise xenrt.XRTError("NETPORT syntax error: %s (%s)" % (netport, host.getName()))
        netports.append(netport)

    # TODO: check that MAC addresses of PIFs match those in the config file


    hostname = host.getName()
    
    switches = []
    ports = []
    for netport in netports:
        ( switch, port) = netport.split("/")
        switch, unit = switch.rsplit('-', 1)
        ports.append((unit, port))
        switches.append(switch)
        
    # Check that we have only one switch
    if len(set(switches)) > 1: 
        raise xenrt.XRTError(
            "Ports %s are not within one switch stack. Switches found: %s" %
                (",".join(["%s/g%s" %(unit, port) for (unit, port) in ports]), switches) )
    
    switchName = switches[0]
    
    

    return switchChooser(switchName)(switchName, hostname, ports)
Example #2
0
def createSwitchForPifs(host, bondpifs):
    # find out switch type

    # For each PIF, get eth/NIC number and NETPORT string

    nics = []
    netports = []

    # find interface, NIC and NETPORT string corresponding to the PIF
    # We can't rely on the device as the enumeration may change in XenServer - instead use the MAC address
    macMappings = {}  # This maps a MAC address to an assumed id
    macMappings[xenrt.normaliseMAC(host.lookup("MAC_ADDRESS"))] = 0
    nicData = host.lookup("NICS")
    for n in nicData.keys():
        assumedid = int(n.replace("NIC", ""))
        macMappings[xenrt.normaliseMAC(nicData[n]['MAC_ADDRESS'])] = assumedid

    for pif in bondpifs:
        mac = host.genParamGet("pif", pif, "MAC")
        i = macMappings[xenrt.normaliseMAC(mac)]
        nic = "NIC%s" % i
        nics.append(nic)
        netport = None
        if nic == "NIC0":
            netport = host.lookup("NETPORT", None)
        else:
            netport = host.lookup(["NICS", nic, "NETPORT"], None)
        print "netport is %s" % netport
        if not netport:
            raise xenrt.XRTError(
                "Could not find NETPORT information for host %s, %s, %s.\n" %
                (host.getName(), nic, pif))
        if len(netport.split("/")) != 2:
            raise xenrt.XRTError("NETPORT syntax error: %s (%s)" %
                                 (netport, host.getName()))
        netports.append(netport)

    # TODO: check that MAC addresses of PIFs match those in the config file

    hostname = host.getName()

    switches = []
    ports = []
    for netport in netports:
        (switch, port) = netport.split("/")
        switch, unit = switch.rsplit('-', 1)
        ports.append((unit, port))
        switches.append(switch)

    # Check that we have only one switch
    if len(set(switches)) > 1:
        raise xenrt.XRTError(
            "Ports %s are not within one switch stack. Switches found: %s" %
            (",".join(["%s/g%s" % (unit, port)
                       for (unit, port) in ports]), switches))

    switchName = switches[0]

    return switchChooser(switchName)(switchName, hostname, ports)
Example #3
0
    def _ipAddrOfMacAddr(self, mac):
        mac = xenrt.normaliseMAC(mac)

        # Return the first IPv4 address after the MAC address is mentioned (and before another MAC address is mentioned)
        return self.host.execdom0(
            "vim-cmd vmsvc/get.guest %s | grep -e 'ipAddress = \"' -e 'macAddress = \"' | sed 's/^\s*//' | awk 'BEGIN{state=0} {if ($1 == \"macAddress\" && tolower($3) ~ /%s/) { state=1 } else if ($1 == \"macAddress\") {state=2} else if (state==1 && $1 == \"ipAddress\" && $3 ~ /[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*/) { print $3; exit};}' | awk -F\\\" '{print $2}'"
            % (self._esxGetVMID(), mac)).strip()
Example #4
0
    def testNetworkPorts(self):
        """Verify each NIC is connected to the correct switch port"""
        nics = self.host.listSecondaryNICs()
        nicMacs = dict([(assumedId, self._lookupMac(assumedId)) for assumedId in nics])
        nicDevs = dict([(assumedId, self.host.getSecondaryNIC(assumedId)) for assumedId in nics]) # getSecondaryNIC checks the MAC is on the PIF implicitly

        failures = []

        lock = xenrt.resources.CentralLock("MC_NETWORK", timeout=3600)
        powerLock = xenrt.resources.CentralLock("MC_POWER", timeout=3600, acquire=False)
        try:
            self.host.enableAllNetPorts()
            xenrt.sleep(30)
            for assumedId in nics:
                mac = nicMacs[assumedId]
                dev = nicDevs[assumedId]
                # Check link state before
                if not self._checkNIC(dev):
                    failures.append("Link for NIC %u (%s / %s) down before bringing port down" % (assumedId, mac, dev))
                    continue
                # Check link speed / duplex
                link = self._checkNICLink(dev)
                if link:
                    failures.append(link)
                    
                self.host.disableNetPort(mac)
                xenrt.sleep(20)
                if self._checkNIC(dev):
                    failures.append("Link for NIC %u (%s / %s) up after bringing port down" % (assumedId, mac, dev))
                    self.host.enableNetPort(mac) # Re-enable it in case it's a different port on this host
                    xenrt.sleep(20)

            # Now check the primary NIC
            powerLock.acquire() # We have to take this one as well to avoid confusion with a power test
            try:
                if not self.host.checkAlive():
                    raise xenrt.XRTError("Host not reachable prior to disabling primary NIC")
                self.host.disableNetPort(xenrt.normaliseMAC(self.host.lookup("MAC_ADDRESS")))
                xenrt.sleep(20)
                if self.host.checkAlive():
                    failures.append("Host reachable after disabling primary NIC")
            finally:
                powerLock.release()
        finally:
            self.host.enableAllNetPorts()
            lock.release()

        if len(failures) > 0:
            for f in failures:
                xenrt.TEC().logverbose(f)
            raise xenrt.XRTFailure("Network port failures detected")
Example #5
0
    def _ipAddrOfMacAddr(self, mac):
        mac = xenrt.normaliseMAC(mac)

        # Return the first IPv4 address after the MAC address is mentioned (and before another MAC address is mentioned)
        return self.host.execdom0("vim-cmd vmsvc/get.guest %s | grep -e 'ipAddress = \"' -e 'macAddress = \"' | sed 's/^\s*//' | awk 'BEGIN{state=0} {if ($1 == \"macAddress\" && tolower($3) ~ /%s/) { state=1 } else if ($1 == \"macAddress\") {state=2} else if (state==1 && $1 == \"ipAddress\" && $3 ~ /[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*/) { print $3; exit};}' | awk -F\\\" '{print $2}'" % (self._esxGetVMID(), mac)).strip()