VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/tests/api/tdCreateVMWithDefaults1.py@ 101470

Last change on this file since 101470 was 98651, checked in by vboxsync, 22 months ago

ValKit: pylint 2.16.2: checks for file

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.1 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3# $Id: tdCreateVMWithDefaults1.py 98651 2023-02-20 13:10:54Z vboxsync $
4
5"""
6VirtualBox Validation Kit - Create VM with IMachine::applyDefaults() Test
7"""
8
9__copyright__ = \
10"""
11Copyright (C) 2010-2023 Oracle and/or its affiliates.
12
13This file is part of VirtualBox base platform packages, as
14available from https://www.virtualbox.org.
15
16This program is free software; you can redistribute it and/or
17modify it under the terms of the GNU General Public License
18as published by the Free Software Foundation, in version 3 of the
19License.
20
21This program is distributed in the hope that it will be useful, but
22WITHOUT ANY WARRANTY; without even the implied warranty of
23MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24General Public License for more details.
25
26You should have received a copy of the GNU General Public License
27along with this program; if not, see <https://www.gnu.org/licenses>.
28
29The contents of this file may alternatively be used under the terms
30of the Common Development and Distribution License Version 1.0
31(CDDL), a copy of it is provided in the "COPYING.CDDL" file included
32in the VirtualBox distribution, in which case the provisions of the
33CDDL are applicable instead of those of the GPL.
34
35You may elect to license modified versions of this file under the
36terms and conditions of either the GPL or the CDDL or both.
37
38SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
39"""
40__version__ = "$Revision: 98651 $"
41
42
43# Standard Python imports.
44import os
45import sys
46
47# Only the main script needs to modify the path.
48try: __file__ # pylint: disable=used-before-assignment
49except: __file__ = sys.argv[0]
50g_ksValidationKitDir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
51sys.path.append(g_ksValidationKitDir)
52
53# Validation Kit imports.
54from testdriver import base
55from testdriver import reporter;
56from testdriver import vboxcon;
57
58
59class 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
199if __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
Note: See TracBrowser for help on using the repository browser.

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