1 | #!/usr/bin/env python
|
---|
2 | # -*- coding: utf-8 -*-
|
---|
3 | # $Id: tdCreateVMWithDefaults1.py 93115 2022-01-01 11:31:46Z vboxsync $
|
---|
4 |
|
---|
5 | """
|
---|
6 | VirtualBox Validation Kit - Create VM with IMachine::applyDefaults() Test
|
---|
7 | """
|
---|
8 |
|
---|
9 | __copyright__ = \
|
---|
10 | """
|
---|
11 | Copyright (C) 2010-2022 Oracle Corporation
|
---|
12 |
|
---|
13 | This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
14 | available from http://www.virtualbox.org. This file is free software;
|
---|
15 | you can redistribute it and/or modify it under the terms of the GNU
|
---|
16 | General Public License (GPL) as published by the Free Software
|
---|
17 | Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
18 | VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
19 | hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
20 |
|
---|
21 | The contents of this file may alternatively be used under the terms
|
---|
22 | of the Common Development and Distribution License Version 1.0
|
---|
23 | (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
24 | VirtualBox OSE distribution, in which case the provisions of the
|
---|
25 | CDDL are applicable instead of those of the GPL.
|
---|
26 |
|
---|
27 | You may elect to license modified versions of this file under the
|
---|
28 | terms and conditions of either the GPL or the CDDL or both.
|
---|
29 | """
|
---|
30 | __version__ = "$Revision: 93115 $"
|
---|
31 |
|
---|
32 |
|
---|
33 | # Standard Python imports.
|
---|
34 | import os
|
---|
35 | import sys
|
---|
36 |
|
---|
37 | # Only the main script needs to modify the path.
|
---|
38 | try: __file__
|
---|
39 | except: __file__ = sys.argv[0]
|
---|
40 | g_ksValidationKitDir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
---|
41 | sys.path.append(g_ksValidationKitDir)
|
---|
42 |
|
---|
43 | # Validation Kit imports.
|
---|
44 | from testdriver import base
|
---|
45 | from testdriver import reporter;
|
---|
46 | from testdriver import vboxcon;
|
---|
47 |
|
---|
48 |
|
---|
49 | class SubTstDrvCreateVMWithDefaults1(base.SubTestDriverBase):
|
---|
50 | """
|
---|
51 | Sub-test driver for VM Move Test #1.
|
---|
52 | """
|
---|
53 |
|
---|
54 | def __init__(self, oTstDrv):
|
---|
55 | base.SubTestDriverBase.__init__(self, oTstDrv, 'create-vm-with-defaults', 'Create VMs with defaults');
|
---|
56 |
|
---|
57 | def testIt(self):
|
---|
58 | """
|
---|
59 | Execute the sub-testcase.
|
---|
60 | """
|
---|
61 | reporter.log('ValidationKit folder is "%s"' % (g_ksValidationKitDir,))
|
---|
62 | reporter.testStart(self.sTestName);
|
---|
63 | fRc = self.testCreateVMWithDefaults();
|
---|
64 | reporter.testDone();
|
---|
65 | return fRc;
|
---|
66 |
|
---|
67 |
|
---|
68 | def createVMWithDefaults(self, sGuestType):
|
---|
69 | sName = 'testvm_%s' % (sGuestType)
|
---|
70 | # create VM manually, because the self.createTestVM() makes registration inside
|
---|
71 | # the method, but IMachine::applyDefault() must be called before machine is registered
|
---|
72 | try:
|
---|
73 | if self.oTstDrv.fpApiVer >= 4.2: # Introduces grouping (third parameter, empty for now).
|
---|
74 | oVM = self.oTstDrv.oVBox.createMachine("", sName, [],
|
---|
75 | self.oTstDrv.tryFindGuestOsId(sGuestType),
|
---|
76 | "")
|
---|
77 | elif self.oTstDrv.fpApiVer >= 4.0:
|
---|
78 | oVM = self.oTstDrv.oVBox.createMachine("", sName,
|
---|
79 | self.oTstDrv.tryFindGuestOsId(sGuestType),
|
---|
80 | "", False)
|
---|
81 | elif self.oTstDrv.fpApiVer >= 3.2:
|
---|
82 | oVM = self.oTstDrv.oVBox.createMachine(sName,
|
---|
83 | self.oTstDrv.tryFindGuestOsId(sGuestType),
|
---|
84 | "", "", False)
|
---|
85 | else:
|
---|
86 | oVM = self.oTstDrv.oVBox.createMachine(sName,
|
---|
87 | self.oTstDrv.tryFindGuestOsId(sGuestType),
|
---|
88 | "", "")
|
---|
89 | try:
|
---|
90 | oVM.saveSettings()
|
---|
91 | except:
|
---|
92 | reporter.logXcpt()
|
---|
93 | if self.oTstDrv.fpApiVer >= 4.0:
|
---|
94 | try:
|
---|
95 | if self.oTstDrv.fpApiVer >= 4.3:
|
---|
96 | oProgress = oVM.deleteConfig([])
|
---|
97 | else:
|
---|
98 | oProgress = oVM.delete(None);
|
---|
99 | self.oTstDrv.waitOnProgress(oProgress)
|
---|
100 | except:
|
---|
101 | reporter.logXcpt()
|
---|
102 | else:
|
---|
103 | try: oVM.deleteSettings()
|
---|
104 | except: reporter.logXcpt()
|
---|
105 | raise
|
---|
106 | except:
|
---|
107 | reporter.errorXcpt('failed to create vm "%s"' % (sName))
|
---|
108 | return None
|
---|
109 |
|
---|
110 | if oVM is None:
|
---|
111 | return False
|
---|
112 |
|
---|
113 | # apply settings
|
---|
114 | fRc = True
|
---|
115 | try:
|
---|
116 | if self.oTstDrv.fpApiVer >= 6.1:
|
---|
117 | oVM.applyDefaults('')
|
---|
118 | oVM.saveSettings();
|
---|
119 | self.oTstDrv.oVBox.registerMachine(oVM)
|
---|
120 | except:
|
---|
121 | reporter.logXcpt()
|
---|
122 | fRc = False
|
---|
123 |
|
---|
124 | # Some errors from applyDefaults can be observed only after further settings saving.
|
---|
125 | # Change and save the size of the VM RAM as simple setting change.
|
---|
126 | oSession = self.oTstDrv.openSession(oVM)
|
---|
127 | if oSession is None:
|
---|
128 | fRc = False
|
---|
129 |
|
---|
130 | if fRc:
|
---|
131 | try:
|
---|
132 | oSession.memorySize = 4096
|
---|
133 | oSession.saveSettings(True)
|
---|
134 | except:
|
---|
135 | reporter.logXcpt()
|
---|
136 | fRc = False
|
---|
137 |
|
---|
138 | # delete VM
|
---|
139 | try:
|
---|
140 | oVM.unregister(vboxcon.CleanupMode_DetachAllReturnNone)
|
---|
141 | except:
|
---|
142 | reporter.logXcpt()
|
---|
143 |
|
---|
144 | if self.oTstDrv.fpApiVer >= 4.0:
|
---|
145 | try:
|
---|
146 | if self.oTstDrv.fpApiVer >= 4.3:
|
---|
147 | oProgress = oVM.deleteConfig([])
|
---|
148 | else:
|
---|
149 | oProgress = oVM.delete(None)
|
---|
150 | self.oTstDrv.waitOnProgress(oProgress)
|
---|
151 |
|
---|
152 | except:
|
---|
153 | reporter.logXcpt()
|
---|
154 |
|
---|
155 | else:
|
---|
156 | try: oVM.deleteSettings()
|
---|
157 | except: reporter.logXcpt()
|
---|
158 |
|
---|
159 | return fRc
|
---|
160 |
|
---|
161 | def testCreateVMWithDefaults(self):
|
---|
162 | """
|
---|
163 | Test create VM with defaults.
|
---|
164 | """
|
---|
165 | if not self.oTstDrv.importVBoxApi():
|
---|
166 | return reporter.error('importVBoxApi');
|
---|
167 |
|
---|
168 | # Get the guest OS types.
|
---|
169 | try:
|
---|
170 | aoGuestTypes = self.oTstDrv.oVBoxMgr.getArray(self.oTstDrv.oVBox, 'guestOSTypes')
|
---|
171 | if aoGuestTypes is None or not aoGuestTypes:
|
---|
172 | return reporter.error('No guest OS types');
|
---|
173 | except:
|
---|
174 | return reporter.errorXcpt();
|
---|
175 |
|
---|
176 | # Create VMs with defaults for each of the guest types.
|
---|
177 | fRc = True
|
---|
178 | for oGuestType in aoGuestTypes:
|
---|
179 | try:
|
---|
180 | sGuestType = oGuestType.id;
|
---|
181 | except:
|
---|
182 | fRc = reporter.errorXcpt();
|
---|
183 | else:
|
---|
184 | reporter.testStart(sGuestType);
|
---|
185 | fRc = self.createVMWithDefaults(sGuestType) and fRc;
|
---|
186 | reporter.testDone();
|
---|
187 | return fRc
|
---|
188 |
|
---|
189 | if __name__ == '__main__':
|
---|
190 | sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
---|
191 | from tdApi1 import tdApi1; # pylint: disable=relative-import
|
---|
192 | sys.exit(tdApi1([SubTstDrvCreateVMWithDefaults1]).main(sys.argv))
|
---|
193 |
|
---|