VirtualBox

Changeset 72298 in vbox for trunk/src/VBox/ValidationKit


Ignore:
Timestamp:
May 23, 2018 12:24:41 PM (7 years ago)
Author:
vboxsync
Message:

valkit/vboxwrappers.py: Use common.netutils functions for getting the host IP and name.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/testdriver/vboxwrappers.py

    r71411 r72298  
    3838# Validation Kit imports.
    3939from common     import utils;
     40from common     import netutils;
    4041from testdriver import base;
    4142from testdriver import reporter;
     
    15301531        """
    15311532
    1532         # Resolve missing MAC address prefix
    1533         cchMacAddr = len(sMacAddr)
     1533        # Resolve missing MAC address prefix by feeding in the host IP address bytes.
     1534        cchMacAddr = len(sMacAddr);
    15341535        if cchMacAddr > 0 and cchMacAddr < 12:
    1535             sHostName = ''
    1536             try:
    1537                 sHostName = socket.getfqdn()
    1538                 if '.' not in sHostName and not sHostName.startswith('localhost'):
    1539                     # somewhat misconfigured system, needs expensive approach to guessing FQDN
    1540                     for aAI in socket.getaddrinfo(sHostName, None):
    1541                         sName, _ = socket.getnameinfo(aAI[4], 0)
    1542                         if '.' in sName and not set(sName).issubset(set('0123456789.')) and not sName.startswith('localhost'):
    1543                             sHostName = sName
    1544                             break
    1545 
    1546                 sHostIP = socket.gethostbyname(sHostName)
    1547                 abHostIP = socket.inet_aton(sHostIP)
    1548                 if sys.version_info[0] < 3:
    1549                     abHostIP = (ord(abHostIP[0]), ord(abHostIP[1]), ord(abHostIP[2]), ord(abHostIP[3]));
    1550             except:
    1551                 return reporter.errorXcpt('failed to determine the host IP for "%s".' % (sHostName,))
     1536            sHostIP = netutils.getPrimaryHostIp();
     1537            abHostIP = socket.inet_aton(sHostIP);
     1538            if sys.version_info[0] < 3:
     1539                abHostIP = (ord(abHostIP[0]), ord(abHostIP[1]), ord(abHostIP[2]), ord(abHostIP[3]));
     1540
    15521541            if   abHostIP[0] == 127 \
    15531542              or (abHostIP[0] == 169 and abHostIP[1] == 254) \
    15541543              or (abHostIP[0] == 192 and abHostIP[1] == 168 and abHostIP[2] == 56):
    1555                 return reporter.error('host IP for "%s" is %s, most likely not unique.' % (sHostName, sHostIP))
    1556 
    1557             sDefaultMac = '%02X%02X%02X%02X%02X%02X' \
    1558                 % (0x02, abHostIP[0], abHostIP[1], abHostIP[2], abHostIP[3], iNic)
    1559             sMacAddr = sDefaultMac[0:(12 - cchMacAddr)] + sMacAddr
     1544                return reporter.error('host IP for "%s" is %s, most likely not unique.' % (netutils.getHostnameFqdn(), sHostIP,));
     1545
     1546            sDefaultMac = '%02X%02X%02X%02X%02X%02X' % (0x02, abHostIP[0], abHostIP[1], abHostIP[2], abHostIP[3], iNic);
     1547            sMacAddr = sDefaultMac[0:(12 - cchMacAddr)] + sMacAddr;
    15601548
    15611549        # Get the NIC object and try set it address.
    15621550        try:
    1563             oNic = self.o.machine.getNetworkAdapter(iNic)
    1564         except:
    1565             return reporter.errorXcpt('getNetworkAdapter(%s) failed for "%s"' % (iNic, self.sName))
    1566 
    1567         try:
    1568             oNic.MACAddress = sMacAddr
    1569         except:
    1570             return reporter.errorXcpt('failed to set the MAC address on slot %s to "%s" for VM "%s"' \
    1571                 % (iNic, sMacAddr, self.sName))
    1572 
    1573         reporter.log('set MAC address on slot %s to %s for VM "%s"' % (iNic, sMacAddr, self.sName))
    1574         return True
     1551            oNic = self.o.machine.getNetworkAdapter(iNic);
     1552        except:
     1553            return reporter.errorXcpt('getNetworkAdapter(%s) failed for "%s"' % (iNic, self.sName,));
     1554
     1555        try:
     1556            oNic.MACAddress = sMacAddr;
     1557        except:
     1558            return reporter.errorXcpt('failed to set the MAC address on slot %s to "%s" for VM "%s"'
     1559                                      % (iNic, sMacAddr, self.sName));
     1560
     1561        reporter.log('set MAC address on slot %s to %s for VM "%s"' % (iNic, sMacAddr, self.sName,));
     1562        return True;
    15751563
    15761564    def setRamSize(self, cMB):
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette