VirtualBox

Changeset 86540 in vbox


Ignore:
Timestamp:
Oct 12, 2020 11:07:32 AM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
140855
Message:

ValKit/tdAutostart1.py: Some cleanups and a couple of @todos. bugref:9341

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/tests/autostart/tdAutostart1.py

    r86062 r86540  
    3535import sys;
    3636import re;
    37 import ssl;
    38 
    39 # Python 3 hacks:
    40 if sys.version_info[0] < 3:
    41     import urllib2 as urllib; # pylint: disable=import-error,no-name-in-module
    42     from urllib2        import ProxyHandler as urllib_ProxyHandler; # pylint: disable=import-error,no-name-in-module
    43     from urllib2        import build_opener as urllib_build_opener; # pylint: disable=import-error,no-name-in-module
    44 else:
    45     import urllib; # pylint: disable=import-error,no-name-in-module
    46     from urllib.request import ProxyHandler as urllib_ProxyHandler; # pylint: disable=import-error,no-name-in-module
    47     from urllib.request import build_opener as urllib_build_opener; # pylint: disable=import-error,no-name-in-module
    48 
    4937
    5038# Only the main script needs to modify the path.
     
    6048from testdriver import vboxcon;
    6149from testdriver import vboxwrappers;
    62 from common     import utils;
    63 
    64 # Python 3 hacks:
    65 if sys.version_info[0] >= 3:
    66     long = int      # pylint: disable=redefined-builtin,invalid-name
    67     xrange = range; # pylint: disable=redefined-builtin,invalid-name
    6850
    6951
     
    11597
    11698
    117 def downloadFile(sUrlFile, sDstFile, sLocalPrefix, fnLog, fnError = None, fNoProxies=True):
    118     """
    119     Downloads the given file if an URL is given, otherwise assume it's
    120     something on the build share and copy it from there.
    121 
    122     Raises no exceptions, returns log + success indicator instead.
    123 
    124     Note! This method may use proxies configured on the system and the
    125           http_proxy, ftp_proxy, no_proxy environment variables.
    126 
    127     """
    128     if fnError is None:
    129         fnError = fnLog;
    130 
    131     if  sUrlFile.startswith('http://') \
    132      or sUrlFile.startswith('https://') \
    133      or sUrlFile.startswith('ftp://'):
    134         # Download the file.
    135         fnLog('Downloading "%s" to "%s"...' % (sUrlFile, sDstFile));
    136         try:
    137             # Disable SSL certificate verification for our servers
    138             ssl_ctx = ssl.create_default_context();
    139             ssl_ctx.check_hostname = False;
    140             ssl_ctx.verify_mode = ssl.CERT_NONE;
    141 
    142             ## @todo We get 404.html content instead of exceptions here, which is confusing and should be addressed.
    143             if not fNoProxies:
    144                 oOpener = urllib_build_opener(urllib.HTTPSHandler(context = ssl_ctx));
    145             else:
    146                 oOpener = urllib_build_opener(urllib.HTTPSHandler(context = ssl_ctx), urllib_ProxyHandler(proxies = dict()));
    147             oSrc = oOpener.open(sUrlFile);
    148             oDst = utils.openNoInherit(sDstFile, 'wb');
    149             oDst.write(oSrc.read());
    150             oDst.close();
    151             oSrc.close();
    152         except Exception as oXcpt:
    153             fnError('Error downloading "%s" to "%s": %s' % (sUrlFile, sDstFile, oXcpt));
    154             return False;
    155     else:
    156         # Assumes file from the build share.
    157         sSrcPath = os.path.join(sLocalPrefix, sUrlFile);
    158         fnLog('Copying "%s" to "%s"...' % (sSrcPath, sDstFile));
    159         try:
    160             utils.copyFileSimple(sSrcPath, sDstFile);
    161         except Exception as oXcpt:
    162             fnError('Error copying "%s" to "%s": %s' % (sSrcPath, sDstFile, oXcpt));
    163             return False;
    164 
    165     return True;
    166 
    167 
    16899class tdAutostartOs(object):
    169100    """
     
    171102    """
    172103
    173     def __init__(self, oTestDriver, fpApiVer, sGuestAdditionsIso):
    174         self.oTestDriver = oTestDriver;
     104    def __init__(self, oTstDrv, fpApiVer, sGuestAdditionsIso):
     105        self.oTstDrv = oTstDrv;
    175106        self.fpApiVer = fpApiVer;
    176107        self.sGuestAdditionsIso = sGuestAdditionsIso;
     
    236167                        break;
    237168
    238             self.oTestDriver.sleep(10);
     169            self.oTstDrv.sleep(10);
    239170            cAttempt += 1;
    240171        return fRc;
     
    481412        else:
    482413            if oCurProgress is not None:
    483                 oWrapperProgress = vboxwrappers.ProgressWrapper(oCurProgress, self.oTestDriver.oVBoxMgr,
    484                                                                 self.oTestDriver, "uploadFile");
     414                oWrapperProgress = vboxwrappers.ProgressWrapper(oCurProgress, self.oTstDrv.oVBoxMgr, self.oTstDrv, "uploadFile");
    485415                oWrapperProgress.wait();
    486416                if not oWrapperProgress.isSuccess():
     
    494424    def downloadFile(self, oGuestSession, sSrc, sDst, fIgnoreErrors = False):
    495425        """
    496         Upload the string into guest.
     426        Get a file (sSrc) from the guest storing it on the host (sDst).
    497427        """
    498428        fRc = True;
     
    510440        else:
    511441            if oCurProgress is not None:
    512                 oWrapperProgress = vboxwrappers.ProgressWrapper(oCurProgress, self.oTestDriver.oVBoxMgr,
    513                                                                 self.oTestDriver, "downloadFile");
     442                oWrapperProgress = vboxwrappers.ProgressWrapper(oCurProgress, self.oTstDrv.oVBoxMgr,
     443                                                                self.oTstDrv, "downloadFile");
    514444                oWrapperProgress.wait();
    515445                if not oWrapperProgress.isSuccess():
     
    536466        fRc = True;
    537467        for sGstFile in asFiles:
    538             sTmpFile = os.path.join(self.oTestDriver.sScratchPath, 'tmp-' + os.path.basename(sGstFile));
     468            ## @todo r=bird: You need to use the guest specific path functions here.
     469            ##       Best would be to add basenameEx to common/pathutils.py.  See how joinEx
     470            ##       is used by BaseTestVm::pathJoin and such.
     471            sTmpFile = os.path.join(self.oTstDrv.sScratchPath, 'tmp-' + os.path.basename(sGstFile));
    539472            reporter.log2('Downloading file "%s" to "%s" ...' % (sGstFile, sTmpFile));
    540473            # First try to remove (unlink) an existing temporary file, as we don't truncate the file.
     
    559492    """
    560493
    561     def __init__(self, oTestDriver, asTestBuildDirs, fpApiVer, sGuestAdditionsIso):
    562         tdAutostartOs.__init__(self, oTestDriver, fpApiVer, sGuestAdditionsIso);
     494    def __init__(self, oTstDrv, asTestBuildDirs, fpApiVer, sGuestAdditionsIso):
     495        tdAutostartOs.__init__(self, oTstDrv, fpApiVer, sGuestAdditionsIso);
    563496        self.sTestBuild = self._findFile('^VirtualBox-.*\\.run$', asTestBuildDirs);
    564497        if not self.sTestBuild:
    565498            raise base.GenError("VirtualBox install package not found");
    566499
    567     def waitVMisReady(self, oSession, fWaitTrayControl):
     500    def waitVmIsReady(self, oSession, fWaitTrayControl):
    568501        """
    569502        Waits the VM is ready after start or reboot.
     
    572505        _ = fWaitTrayControl;
    573506        # Give the VM a time to reboot
    574         self.oTestDriver.sleep(30);
     507        self.oTstDrv.sleep(30);
    575508
    576509        # Waiting the VM is ready.
     
    585518        while cAttempt < 30:
    586519            fRc, oGuestSession = self.createSession(oSession, 'Session for user: vbox',
    587                                             'vbox', 'password', 10 * 1000, False);
     520                                                    'vbox', 'password', 10 * 1000, False);
    588521            if fRc:
    589522                (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Start a guest process',
     
    596529                self.closeSession(oGuestSession, False);
    597530
    598             self.oTestDriver.sleep(10);
     531            self.oTstDrv.sleep(10);
    599532            cAttempt += 1;
    600533
     
    615548        fRc = self.closeSession(oGuestSession, True) and fRc and True; # pychecker hack.
    616549        if fRc:
    617             (fRc, oGuestSession) = self.waitVMisReady(oSession, False);
     550            (fRc, oGuestSession) = self.waitVmIsReady(oSession, False);
    618551
    619552        if not fRc:
     
    655588        fRc = False;
    656589        # Install Kernel headers, which are required for actually installing the Linux Additions.
    657         if oVM.OSTypeId.startswith('Debian') \
    658         or oVM.OSTypeId.startswith('Ubuntu'):
     590        if   oVM.OSTypeId.startswith('Debian') \
     591          or oVM.OSTypeId.startswith('Ubuntu'):
    659592            (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Installing Kernel headers',
    660593                                                  5 * 60 *1000, '/usr/bin/apt-get',
     
    673606
    674607        elif oVM.OSTypeId.startswith('OL') \
    675         or  oVM.OSTypeId.startswith('Oracle') \
    676         or  oVM.OSTypeId.startswith('RHEL') \
    677         or  oVM.OSTypeId.startswith('Redhat') \
    678         or  oVM.OSTypeId.startswith('Cent'):
     608          or oVM.OSTypeId.startswith('Oracle') \
     609          or oVM.OSTypeId.startswith('RHEL') \
     610          or oVM.OSTypeId.startswith('Redhat') \
     611          or oVM.OSTypeId.startswith('Cent'):
    679612            (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Installing Kernel headers',
    680613                                                  5 * 60 *1000, '/usr/bin/yum',
     
    711644                fRc = self.closeSession(oGuestSession);
    712645                if fRc:
    713                     (fRc, oGuestSession) = self.waitVMisReady(oSession, False);
     646                    (fRc, oGuestSession) = self.waitVmIsReady(oSession, False);
    714647
    715648                # Download log files.
     
    764697        return fRc;
    765698
    766     def configureAutostart(self, oGuestSession, sDefaultPolicy = 'allow',
    767                            asUserAllow = (), asUserDeny = ()):
     699    def configureAutostart(self, oGuestSession, sDefaultPolicy = 'allow', asUserAllow = (), asUserDeny = ()):
    768700        """
    769701        Configures the autostart feature in the guest.
     
    886818        """
    887819
    888         self.oTestDriver.sleep(30);
     820        self.oTstDrv.sleep(30);
    889821
    890822        _ = oSession;
     
    912844    """
    913845
    914     def __init__(self, oTestDriver, sTestBuildDir, fpApiVer, sGuestAdditionsIso):
     846    def __init__(self, oTstDrv, sTestBuildDir, fpApiVer, sGuestAdditionsIso):
    915847        _ = sTestBuildDir;
    916         tdAutostartOs.__init__(self, oTestDriver, fpApiVer, sGuestAdditionsIso);
     848        tdAutostartOs.__init__(self, oTstDrv, fpApiVer, sGuestAdditionsIso);
    917849        raise base.GenError('Testing the autostart functionality for Darwin is not implemented');
    918850
     
    923855    """
    924856
    925     def __init__(self, oTestDriver, sTestBuildDir, fpApiVer, sGuestAdditionsIso):
     857    def __init__(self, oTstDrv, sTestBuildDir, fpApiVer, sGuestAdditionsIso):
    926858        _ = sTestBuildDir;
    927         tdAutostartOs.__init__(self, oTestDriver, fpApiVer, sGuestAdditionsIso);
     859        tdAutostartOs.__init__(self, oTstDrv, fpApiVer, sGuestAdditionsIso);
    928860        raise base.GenError('Testing the autostart functionality for Solaris is not implemented');
    929861
     
    934866    """
    935867
    936     def __init__(self, oTestDriver, asTestBuildDirs, fpApiVer, sGuestAdditionsIso):
    937         tdAutostartOs.__init__(self, oTestDriver, fpApiVer, sGuestAdditionsIso);
     868    def __init__(self, oTstDrv, asTestBuildDirs, fpApiVer, sGuestAdditionsIso):
     869        tdAutostartOs.__init__(self, oTstDrv, fpApiVer, sGuestAdditionsIso);
    938870        self.sTestBuild = self._findFile('^VirtualBox-.*\\.(exe|msi)$', asTestBuildDirs);
    939871        if not self.sTestBuild:
     
    941873        return;
    942874
    943     def waitVMisReady(self, oSession, fWaitTrayControl, fWaitFacility = True):
     875    def waitVmIsReady(self, oSession, fWaitTrayControl, fWaitFacility = True):
    944876        """
    945877        Waits the VM is ready after start or reboot.
    946878        """
    947879        # Give the VM a time to reboot
    948         self.oTestDriver.sleep(30);
     880        self.oTstDrv.sleep(30);
    949881
    950882        # Waiting the VM is ready.
     
    957889        oGuestSession = None;
    958890        while cAttempt < 10:
    959             fRc, oGuestSession = self.createSession(oSession, 'Session for user: vbox',
    960                                             'vbox', 'password', 10 * 1000, False);
     891            fRc, oGuestSession = self.createSession(oSession, 'Session for user: vbox', 'vbox', 'password', 10 * 1000, False);
    961892            if fRc:
    962893                (fRc, _, _, _) = self.guestProcessExecute(oGuestSession, 'Start a guest process',
     
    968899                self.closeSession(oGuestSession, False);
    969900
    970             self.oTestDriver.sleep(10);
     901            self.oTstDrv.sleep(10);
    971902            cAttempt += 1;
    972903
     
    987918        fRc = self.closeSession(oGuestSession, True) and fRc and True; # pychecker hack.
    988919        if fRc:
    989             (fRc, oGuestSession) = self.waitVMisReady(oSession, True);
     920            (fRc, oGuestSession) = self.waitVmIsReady(oSession, True);
    990921        if not fRc:
    991922            reporter.error('VM is not ready after reboot');
     
    1035966        else:
    1036967            if oCurProgress is not None:
    1037                 oWrapperProgress = vboxwrappers.ProgressWrapper(oCurProgress, self.oTestDriver.oVBoxMgr,
    1038                                                                 self.oTestDriver, "installAdditions");
     968                oWrapperProgress = vboxwrappers.ProgressWrapper(oCurProgress, self.oTstDrv.oVBoxMgr,
     969                                                                self.oTstDrv, "installAdditions");
    1039970                oWrapperProgress.wait(cMsTimeout = 10 * 60 * 1000);
    1040971                if not oWrapperProgress.isSuccess():
     
    1050981        ##
    1051982        #
    1052         #self.oTestDriver.sleep(60 * 2);
     983        #self.oTstDrv.sleep(60 * 2);
    1053984        #
    1054985        #if oVM.OSTypeId not in ('WindowsNT4', 'Windows2000', 'WindowsXP', 'Windows2003'):
     
    10831014        #    fRc = self.closeSession(oGuestSession, True);
    10841015        #    if fRc:
    1085         #        (fRc, oGuestSession) = self.waitVMisReady(oSession, False, False);
     1016        #        (fRc, oGuestSession) = self.waitVmIsReady(oSession, False, False);
    10861017        #---------------------------------------
    10871018
     
    11621093        return fRc;
    11631094
    1164     def configureAutostart(self, oGuestSession, sDefaultPolicy = 'allow',
    1165                            asUserAllow = (), asUserDeny = ()):
     1095    def configureAutostart(self, oGuestSession, sDefaultPolicy = 'allow', asUserAllow = (), asUserDeny = ()):
    11661096        """
    11671097        Configures the autostart feature in the guest.
    11681098        """
    11691099        reporter.testStart('Configure autostart');
     1100
    11701101        # Create autostart database directory writeable for everyone
    11711102        (fRc, _, _, _) = \
     
    11771108                                      'C:\\ProgramData\\autostart.cfg', '/f'],
    11781109                                     False, True);
    1179         if not fRc:
    1180             reporter.error('Setting the autostart environment variable failed');
    1181 
    11821110        if fRc:
    11831111            sVBoxCfg = self._createAutostartCfg(sDefaultPolicy, asUserAllow, asUserDeny);
     
    11851113            if not fRc:
    11861114                reporter.error('Upload the autostart.cfg failed');
     1115        else:
     1116            reporter.error('Setting the autostart environment variable failed');
     1117
    11871118        reporter.testDone();
    11881119        return fRc;
     
    12421173        """
    12431174
    1244         self.oTestDriver.sleep(30);
     1175        self.oTstDrv.sleep(30);
    12451176
    12461177        _ = oGuestSession;
     
    12561187
    12571188            (fRc, _, _, aBuf) = self.guestProcessExecute(oGuestSession, 'Check for running VM',
    1258                                                        60 * 1000, 'C:\\Program Files\\Oracle\\VirtualBox\\VBoxManage.exe',
    1259                                                        ['C:\\Program Files\\Oracle\\VirtualBox\\VBoxManage.exe',
    1260                                                         'list', 'runningvms'], True, True);
     1189                                                         60 * 1000, 'C:\\Program Files\\Oracle\\VirtualBox\\VBoxManage.exe',
     1190                                                         [ 'C:\\Program Files\\Oracle\\VirtualBox\\VBoxManage.exe',
     1191                                                           'list', 'runningvms' ], True, True);
    12611192            if not fRc:
    12621193                reporter.error('Checking the VM %s is running for user %s failed' % (sVmName, sUser));
     
    13291260
    13301261WScript.Echo "Logon As A Service Right granted to user '"& strUserName &"'"
    1331                            """ % sUser;
     1262                           """ % (sUser,);
    13321263            fRc = self.uploadString(oGuestSession, sSecPolicyEditor, 'C:\\Temp\\adjustsec.vbs');
    13331264            if not fRc:
     
    13651296        self.asTestVMs          = self.asTestVMsDef;
    13661297        self.asSkipVMs          = [];
    1367         self.asTestBuildDirs      = None; #'D:/AlexD/TestBox/TestAdditionalFiles';
     1298        ## @todo r=bird: The --test-build-dirs option as primary way to get the installation files to test
     1299        ## is not an acceptable test practice as we don't know wtf you're testing.  See defect for more.
     1300        self.asTestBuildDirs    = None; #'D:/AlexD/TestBox/TestAdditionalFiles';
    13681301        self.sGuestAdditionsIso = None; #'D:/AlexD/TestBox/TestAdditionalFiles/VBoxGuestAdditions_6.1.2.iso';
    13691302
     
    15271460        if oGuestOsHlp is not None:
    15281461            #wait the VM is ready after starting
    1529             (fRc, oGuestSession) = oGuestOsHlp.waitVMisReady(oSession, True);
     1462            (fRc, oGuestSession) = oGuestOsHlp.waitVmIsReady(oSession, True);
    15301463            #install fresh guest additions
    15311464            if fRc:
Note: See TracChangeset for help on using the changeset viewer.

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