VirtualBox

Ignore:
Timestamp:
Jun 7, 2019 7:41:20 PM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
131204
Message:

ValKit/tdGuestOsUnattendedInst1.py: Got basics working. bugref:9151

Location:
trunk/src/VBox/ValidationKit/tests/installation
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/tests/installation/Makefile.kmk

    r76553 r79046  
    3434ValidationKitInstallationTests_EXEC_SOURCES := \
    3535        $(PATH_SUB_CURRENT)/tdGuestOsInstTest1.py \
    36         $(PATH_SUB_CURRENT)/tdGuestOsInstOs2.py
     36        $(PATH_SUB_CURRENT)/tdGuestOsInstOs2.py \
     37        $(PATH_SUB_CURRENT)/tdGuestOsUnattendedInst1.py
    3738
    3839VBOX_VALIDATIONKIT_PYTHON_SOURCES += $(ValidationKitInstallationTests_EXEC_SOURCES)
  • trunk/src/VBox/ValidationKit/tests/installation/tdGuestOsUnattendedInst1.py

    r78830 r79046  
    3232
    3333# Standard Python imports.
    34 import os
    35 import sys
     34import copy;
     35import os;
     36import sys;
    3637
    3738
     
    5051
    5152
    52 class UnattendedVm(vboxtestvms.TestVm):
     53class UnattendedVm(vboxtestvms.BaseTestVm):
    5354    """ Unattended Installation test VM. """
    5455
     
    6768
    6869    def __init__(self, oSet, sVmName, sKind, sInstallIso, fFlags = 0):
    69         vboxtestvms.TestVm.__init__(self, sVmName, oSet = oSet, sKind = sKind,
    70                                     fRandomPvPMode = False, sFirmwareType = None, sChipsetType = None,
    71                                     sHddControllerType = None, sDvdControllerType = None);
     70        vboxtestvms.BaseTestVm.__init__(self, sVmName, oSet = oSet, sKind = sKind,
     71                                        fRandomPvPModeCrap = False if (fFlags & self.kfNoWin81Paravirt) else True);
    7272        self.sInstallIso    = sInstallIso;
    7373        self.fInstVmFlags   = fFlags;
     
    7777        self.fOptIoApic     = None;
    7878        self.fOptPae        = None;
    79         self.asExtraData    = [];
     79        self.asOptExtraData = [];
    8080        if fFlags & self.kfIdeIrqDelay:
    8181            self.asOptExtraData = self.kasIdeIrqDelay;
    8282
    83     ## @todo split TestVm.
    84     def createVmInner(self, oTestDrv, eNic0AttachType, sDvdImage):
    85         """ Overloaded from TestVm to create using defaults rather than a set complicated config properties. """
    86 
    87 
    88     def detatchAndDeleteHd(self, oTestDrv):
    89         """
    90         Detaches and deletes the HD.
    91         Returns success indicator, error info logged.
    92         """
    93         fRc = False;
    94         oVM = oTestDrv.getVmByName(self.sVmName);
    95         if oVM is not None:
    96             oSession = oTestDrv.openSession(oVM);
    97             if oSession is not None:
    98                 (fRc, oHd) = oSession.detachHd(self.sHddControllerType, iPort = 0, iDevice = 0);
    99                 if fRc is True and oHd is not None:
    100                     fRc = oSession.saveSettings();
    101                     fRc = fRc and oTestDrv.oVBox.deleteHdByMedium(oHd);
    102                     fRc = fRc and oSession.saveSettings(); # Necessary for media reg?
    103                 fRc = oSession.close() and fRc;
    104         return fRc;
     83
     84    #
     85    # Overriden methods.
     86    #
     87
     88    def _createVmPost(self, oTestDrv, oVM, eNic0AttachType, sDvdImage):
     89        #
     90        # Adjust the ram, I/O APIC and stuff.
     91        #
     92
     93        oSession = oTestDrv.openSession(oVM);
     94        if oSession is None:
     95            return None;
     96
     97        fRc = True;
     98
     99        # Set proper boot order (needed?)
     100        fRc = fRc and oSession.setBootOrder(1, vboxcon.DeviceType_HardDisk)
     101        fRc = fRc and oSession.setBootOrder(2, vboxcon.DeviceType_DVD)
     102
     103        # Adjust memory if requested.
     104        if self.iOptRamAdjust != 0:
     105            try:    cMbRam = oSession.o.machine.memorySize;
     106            except: fRc   = reporter.errorXcpt();
     107            else:
     108                fRc = fRc and oSession.setRamSize(cMbRam + self.iOptRamAdjust);
     109
     110        # I/O APIC:
     111        if self.fOptIoApic is not None:
     112            fRc = fRc and oSession.enableIoApic(self.fOptIoApic);
     113
     114        # I/O APIC:
     115        if self.fOptPae is not None:
     116            fRc = fRc and oSession.enablePae(self.fOptPae);
     117
     118        # Set extra data
     119        for sExtraData in self.asOptExtraData:
     120            try:
     121                sKey, sValue = sExtraData.split(':')
     122            except ValueError:
     123                raise base.InvalidOption('Invalid extradata specified: %s' % sExtraData)
     124            reporter.log('Set extradata: %s => %s' % (sKey, sValue))
     125            fRc = fRc and oSession.setExtraData(sKey, sValue)
     126
     127        # Save the settings.
     128        fRc = fRc and oSession.saveSettings()
     129        fRc = oSession.close() and fRc;
     130
     131        return oVM if fRc else None;
     132
     133    def _skipVmTest(self, oTestDrv, oVM):
     134        _ = oVM;
     135        #
     136        # Check for ubuntu installer vs. AMD host CPU.
     137        #
     138        if self.fInstVmFlags & self.kfUbuntuNewAmdBug:
     139            if self.isHostCpuAffectedByUbuntuNewAmdBug(oTestDrv):
     140                return True;
     141
     142        return vboxtestvms.BaseTestVm._skipVmTest(self, oTestDrv, oVM);
    105143
    106144    def getReconfiguredVm(self, oTestDrv, cCpus, sVirtMode, sParavirtMode = None):
     
    109147        # if we can run the VM as requested.
    110148        #
    111         (fRc, oVM) = vboxtestvms.TestVm.getReconfiguredVm(self, oTestDrv, cCpus, sVirtMode, sParavirtMode);
    112 
    113         #
    114         # Make sure there is no HD from the previous run attached nor taking
    115         # up storage on the host.
    116         #
     149        (fRc, oVM) = vboxtestvms.BaseTestVm.getReconfiguredVm(self, oTestDrv, cCpus, sVirtMode, sParavirtMode);
    117150        if fRc is True:
    118             fRc = self.detatchAndDeleteHd(oTestDrv);
    119 
    120         #
    121         # Check for ubuntu installer vs. AMD host CPU.
    122         #
    123         if fRc is True and (self.fInstVmFlags & self.kfUbuntuNewAmdBug):
    124             if self.isHostCpuAffectedByUbuntuNewAmdBug(oTestDrv):
    125                 return (None, None); # (skip)
    126 
    127         #
    128         # Make adjustments to the default config, and adding a fresh HD.
    129         #
    130         if fRc is True:
    131             oSession = oTestDrv.openSession(oVM);
    132             if oSession is not None:
    133                 if self.sHddControllerType == self.ksSataController:
    134                     fRc = fRc and oSession.setStorageControllerType(vboxcon.StorageControllerType_IntelAhci,
    135                                                                     self.sHddControllerType);
    136                     fRc = fRc and oSession.setStorageControllerPortCount(self.sHddControllerType, 1);
    137                 elif self.sHddControllerType == self.ksScsiController:
    138                     fRc = fRc and oSession.setStorageControllerType(vboxcon.StorageControllerType_LsiLogic,
    139                                                                     self.sHddControllerType);
     151            #
     152            # Make sure there is no HD from the previous run attached nor taking
     153            # up storage on the host.
     154            #
     155            fRc = self.recreateRecommendedHdd(oVM, oTestDrv);
     156            if fRc is True:
     157                #
     158                # Set up unattended installation.
     159                #
    140160                try:
    141                     sHddPath = os.path.join(os.path.dirname(oVM.settingsFilePath),
    142                                             '%s-%s-%s.vdi' % (self.sVmName, sVirtMode, cCpus,));
     161                    oIUnattended = oTestDrv.oVBox.createUnattendedInstaller();
    143162                except:
    144                     reporter.errorXcpt();
    145                     sHddPath = None;
    146                     fRc = False;
    147 
    148                 fRc = fRc and oSession.createAndAttachHd(sHddPath,
    149                                                          cb = self.cGbHdd * 1024*1024*1024,
    150                                                          sController = self.sHddControllerType,
    151                                                          iPort = 0,
    152                                                          fImmutable = False);
    153 
    154                 # Set proper boot order
    155                 fRc = fRc and oSession.setBootOrder(1, vboxcon.DeviceType_HardDisk)
    156                 fRc = fRc and oSession.setBootOrder(2, vboxcon.DeviceType_DVD)
    157 
    158                 # Adjust memory if requested.
    159                 if self.iOptRamAdjust != 0:
    160                     fRc = fRc and oSession.setRamSize(oSession.o.machine.memorySize + self.iOptRamAdjust);
    161 
    162                 # Set extra data
    163                 for sExtraData in self.asOptExtraData:
    164                     try:
    165                         sKey, sValue = sExtraData.split(':')
    166                     except ValueError:
    167                         raise base.InvalidOption('Invalid extradata specified: %s' % sExtraData)
    168                     reporter.log('Set extradata: %s => %s' % (sKey, sValue))
    169                     fRc = fRc and oSession.setExtraData(sKey, sValue)
    170 
    171                 # Other variations?
    172 
    173                 # Save the settings.
    174                 fRc = fRc and oSession.saveSettings()
    175                 fRc = oSession.close() and fRc;
    176             else:
    177                 fRc = False;
    178             if fRc is not True:
    179                 oVM = None;
     163                    fRc = reporter.errorXcpt();
     164                if fRc is True:
     165                    fRc = self.unattendedDetectOs(oIUnattended, oTestDrv);
     166                    if fRc is True:
     167                        fRc = self._unattendedConfigure(oIUnattended, oTestDrv);
     168                        if fRc is True:
     169                            fRc = self._unattendedDoIt(oIUnattended, oVM, oTestDrv);
    180170
    181171        # Done.
    182172        return (fRc, oVM)
    183173
    184 
     174    #
     175    # Our methods.
     176    #
     177
     178    def unattendedDetectOs(self, oIUnattended, oTestDrv): # type: (Any, vbox.TestDriver) -> bool
     179        """
     180        Does the detectIsoOS operation and checks that the detect OSTypeId matches.
     181
     182        Returns True on success, False w/ errors logged on failure.
     183        """
     184
     185        #
     186        # Point the installer at the ISO and do the detection.
     187        #
     188        try:
     189            oIUnattended.isoPath = self.sInstallIso;
     190        except:
     191            return reporter.errorXcpt('sInstallIso=%s' % (self.sInstallIso,));
     192
     193        try:
     194            oIUnattended.detectIsoOS();
     195        except:
     196            if oTestDrv.oVBoxMgr.xcptIsNotEqual(None, oTestDrv.oVBoxMgr.statuses.E_NOTIMPL):
     197                return reporter.errorXcpt('sInstallIso=%s' % (self.sInstallIso,));
     198
     199        #
     200        # Get and log the result.
     201        #
     202        # Note! Current (6.0.97) fails with E_NOTIMPL even if it does some work.
     203        #
     204        try:
     205            sDetectedOSTypeId    = oIUnattended.detectedOSTypeId;
     206            sDetectedOSVersion   = oIUnattended.detectedOSVersion;
     207            sDetectedOSFlavor    = oIUnattended.detectedOSFlavor;
     208            sDetectedOSLanguages = oIUnattended.detectedOSLanguages;
     209            sDetectedOSHints     = oIUnattended.detectedOSHints;
     210        except:
     211            return reporter.errorXcpt('sInstallIso=%s' % (self.sInstallIso,));
     212
     213        reporter.log('detectIsoOS result for "%s" (vm %s):' % (self.sInstallIso, self.sVmName));
     214        reporter.log('       DetectedOSTypeId: %s' % (sDetectedOSTypeId,));
     215        reporter.log('      DetectedOSVersion: %s' % (sDetectedOSVersion,));
     216        reporter.log('       DetectedOSFlavor: %s' % (sDetectedOSFlavor,));
     217        reporter.log('    DetectedOSLanguages: %s' % (sDetectedOSLanguages,));
     218        reporter.log('        DetectedOSHints: %s' % (sDetectedOSHints,));
     219
     220        #
     221        # Check if the OS type matches.
     222        #
     223        if self.sKind != sDetectedOSTypeId:
     224            return reporter.error('sInstallIso=%s: DetectedOSTypeId is %s, expected %s'
     225                                  % (self.sInstallIso, sDetectedOSTypeId, self.sKind));
     226
     227        return True;
     228
     229    def _unattendedConfigure(self, oIUnattended, oTestDrv): # type: (Any, vbox.TestDriver) -> bool
     230        """
     231        Configures the unattended install object.
     232
     233        The ISO attribute has been set and detectIsoOS has been done, the rest of the
     234        setup is done here.
     235
     236        Returns True on success, False w/ errors logged on failure.
     237        """
     238
     239        #
     240        # Make it install the TXS.
     241        #
     242        try:    oIUnattended.installTestExecService = True;
     243        except: return reporter.errorXcpt();
     244        try:    oIUnattended.validationKitIsoPath = oTestDrv.sVBoxValidationKitIso;
     245        except: return reporter.errorXcpt();
     246
     247        return True;
     248
     249    def _unattendedDoIt(self, oIUnattended, oVM, oTestDrv): # type: (Any, Any, vbox.TestDriver) -> bool
     250        """
     251        Does the unattended installation preparing, media construction and VM reconfiguration.
     252
     253        Returns True on success, False w/ errors logged on failure.
     254        """
     255
     256        # Associate oVM with the installer:
     257        try:
     258            oIUnattended.machine = oVM;
     259        except:
     260            return reporter.errorXcpt();
     261        oTestDrv.processPendingEvents();
     262
     263        # Prepare:
     264        try:
     265            oIUnattended.prepare();
     266        except:
     267            return reporter.errorXcpt("IUnattended.prepare failed");
     268        oTestDrv.processPendingEvents();
     269
     270        # Create media:
     271        try:
     272            oIUnattended.constructMedia();
     273        except:
     274            return reporter.errorXcpt("IUnattended.constructMedia failed");
     275        oTestDrv.processPendingEvents();
     276
     277        # Reconfigure the VM:
     278        try:
     279            oIUnattended.reconfigureVM();
     280        except:
     281            return reporter.errorXcpt("IUnattended.reconfigureVM failed");
     282        oTestDrv.processPendingEvents();
     283
     284        return True;
     285
     286    def _unattendedLogIt(self, oIUnattended):
     287        """
     288        Logs the attributes of the unattended installation object.
     289        """
     290        fRc = True;
     291        asAttribs = ( 'isoPath', 'user', 'password ', 'fullUserName', 'productKey', 'additionsIsoPath', 'installGuestAdditions',
     292                      'validationKitIsoPath', 'installTestExecService', 'timeZone', 'locale', 'language', 'country', 'proxy',
     293                      'packageSelectionAdjustments', 'hostname', 'auxiliaryBasePath', 'imageIndex', 'machine',
     294                      'scriptTemplatePath', 'postInstallScriptTemplatePath', 'postInstallCommand',
     295                      'extraInstallKernelParameters', 'detectedOSTypeId', 'detectedOSVersion', 'detectedOSLanguages',
     296                      'detectedOSFlavor', 'detectedOSHints', );
     297        for sAttrib in asAttribs:
     298            try:
     299                oValue = getattr(oIUnattended, sAttrib);
     300            except:
     301                fRc = reporter.errorXcpt('sAttrib=%s' % sAttrib);
     302            else:
     303                reporter.log('%s: %s' % (sAttrib.rjust(32), oValue,));
     304        return fRc;
    185305
    186306
     
    211331        oSet = vboxtestvms.TestVmSet(self.oTestVmManager, fIgnoreSkippedVm = True);
    212332        oSet.aoTestVms.extend([
    213             # pylint: disable=C0301
    214333            UnattendedVm(oSet, 'tst-w7-32', 'Windows7', 'en_windows_7_enterprise_x86_dvd_x15-70745.iso'),
    215             # pylint: enable=C0301
    216334        ]);
    217335        self.oTestVmSet = oSet;
     
    282400            iArg = self.requireMoreArgs(1, asArgs, iArg);
    283401            asNames = asArgs[iArg].split('=');
    284             if len(asNames) != 2 or len(asNames[0]) == 0 or len(asNames[1]) == 0:
     402            if len(asNames) != 2 or not asNames[0] or not asNames[1]:
    285403                raise base.InvalidOption('The --copy option expects value on the form "old=new": %s'  % (asArgs[iArg],));
    286404            oOldTestVm = self.oTestVmSet.findTestVmByName(asNames[0]);
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