VirtualBox

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

Last change on this file since 79067 was 79067, checked in by vboxsync, 5 years ago

ValKit: Refactored sub-test driver initialization so it can have both a shortish name for --disable-sub-driver (new) and a test name for reporter.testStart. Working on extending tdGuestOsUnattendedInst1.py to do GA testings. bugref:9151

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.7 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3# $Id: tdCreateVMWithDefaults1.py 79067 2019-06-10 22:56:46Z vboxsync $
4
5"""
6VirtualBox Validation Kit - Create VM with IMachine::applyDefaults() Test
7"""
8
9__copyright__ = \
10"""
11Copyright (C) 2010-2019 Oracle Corporation
12
13This file is part of VirtualBox Open Source Edition (OSE), as
14available from http://www.virtualbox.org. This file is free software;
15you can redistribute it and/or modify it under the terms of the GNU
16General Public License (GPL) as published by the Free Software
17Foundation, in version 2 as it comes in the "COPYING" file of the
18VirtualBox OSE distribution. VirtualBox OSE is distributed in the
19hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
20
21The contents of this file may alternatively be used under the terms
22of the Common Development and Distribution License Version 1.0
23(CDDL) only, as it comes in the "COPYING.CDDL" file of the
24VirtualBox OSE distribution, in which case the provisions of the
25CDDL are applicable instead of those of the GPL.
26
27You may elect to license modified versions of this file under the
28terms and conditions of either the GPL or the CDDL or both.
29"""
30__version__ = "$Revision: 79067 $"
31
32
33# Standard Python imports.
34import os
35import sys
36
37# Only the main script needs to modify the path.
38try: __file__
39except: __file__ = sys.argv[0]
40g_ksValidationKitDir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
41sys.path.append(g_ksValidationKitDir)
42
43# Validation Kit imports.
44from testdriver import base
45from testdriver import reporter;
46from testdriver import vboxcon;
47
48
49class 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 len(aoGuestTypes) < 1:
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
189if __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
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