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