VirtualBox

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

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

Main: bugref:8612: Made the testcase as sub-test for tdApi1.py

  • 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 78671 2019-05-22 17:06:36Z 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: 78671 $"
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
48class SubTstDrvCreateVMWithDefaults1(base.SubTestDriverBase):
49 """
50 Sub-test driver for VM Move Test #1.
51 """
52
53 def __init__(self, oTstDrv):
54 base.SubTestDriverBase.__init__(self, 'move-vm', oTstDrv)
55 self.asRsrcs = []
56
57 def testIt(self):
58 """
59 Execute the sub-testcase.
60 """
61 reporter.log('ValidationKit folder is "%s"' % (g_ksValidationKitDir,))
62 return self.testCreateVMWithDefaults()
63
64 def createVMWithDefaults(self, sGuestType):
65 sName = 'testvm_%s' % (sGuestType)
66 # create VM manually, because the self.createTestVM() makes registration inside
67 # the method, but IMachine::applyDefault() must be called before machine is registered
68 try:
69 if self.oTstDrv.fpApiVer >= 4.2: # Introduces grouping (third parameter, empty for now).
70 oVM = self.oTstDrv.oVBox.createMachine("", sName, [],
71 self.oTstDrv.tryFindGuestOsId(sGuestType),
72 "")
73 elif self.oTstDrv.fpApiVer >= 4.0:
74 oVM = self.oTstDrv.oVBox.createMachine("", sName,
75 self.oTstDrv.tryFindGuestOsId(sGuestType),
76 "", False)
77 elif self.oTstDrv.fpApiVer >= 3.2:
78 oVM = self.oTstDrv.oVBox.createMachine(sName,
79 self.oTstDrv.tryFindGuestOsId(sGuestType),
80 "", "", False)
81 else:
82 oVM = self.oTstDrv.oVBox.createMachine(sName,
83 self.oTstDrv.tryFindGuestOsId(sGuestType),
84 "", "")
85 try:
86 oVM.saveSettings()
87 except:
88 reporter.logXcpt()
89 if self.oTstDrv.fpApiVer >= 4.0:
90 try:
91 if self.oTstDrv.fpApiVer >= 4.3:
92 oProgress = oVM.deleteConfig([])
93 else:
94 oProgress = oVM.delete(None);
95 self.oTstDrv.waitOnProgress(oProgress)
96 except:
97 reporter.logXcpt()
98 else:
99 try: oVM.deleteSettings()
100 except: reporter.logXcpt()
101 raise
102 except:
103 reporter.errorXcpt('failed to create vm "%s"' % (sName))
104 return None
105
106 if oVM is None:
107 return False
108
109 # apply settings
110 fRc = True
111 try:
112 if self.oTstDrv.fpApiVer >= 6.1:
113 oVM.applyDefaults('')
114 oVM.saveSettings();
115 self.oTstDrv.oVBox.registerMachine(oVM)
116 except:
117 reporter.logXcpt()
118 fRc = False
119
120 # Some errors from applyDefaults can be observed only after further settings saving.
121 # Change and save the size of the VM RAM as simple setting change.
122 oSession = self.oTstDrv.openSession(oVM)
123 if oSession is None:
124 fRc = False
125
126 if fRc:
127 try:
128 oSession.memorySize = 4096
129 oSession.saveSettings(True)
130 except:
131 reporter.logXcpt()
132 fRc = False
133
134 # delete VM
135 try:
136 oVM.unregister(vboxcon.CleanupMode_DetachAllReturnNone)
137 except:
138 reporter.logXcpt()
139
140 if self.oTstDrv.fpApiVer >= 4.0:
141 try:
142 if self.oTstDrv.fpApiVer >= 4.3:
143 oProgress = oVM.deleteConfig([])
144 else:
145 oProgress = oVM.delete(None)
146 self.oTstDrv.waitOnProgress(oProgress)
147
148 except:
149 reporter.logXcpt()
150
151 else:
152 try: oVM.deleteSettings()
153 except: reporter.logXcpt()
154
155 return fRc
156
157 def testCreateVMWithDefaults(self):
158 """
159 Test create VM with defaults.
160 """
161 if not self.oTstDrv.importVBoxApi():
162 return reporter.error('importVBoxApi');
163
164 # Get the guest OS types.
165 try:
166 aoGuestTypes = self.oTstDrv.oVBoxMgr.getArray(self.oTstDrv.oVBox, 'guestOSTypes')
167 if aoGuestTypes is None or len(aoGuestTypes) < 1:
168 return reporter.error('No guest OS types');
169 except:
170 return reporter.errorXcpt();
171
172 # Create VMs with defaults for each of the guest types.
173 reporter.testStart('Create VMs with defaults');
174 fRc = True
175 for oGuestType in aoGuestTypes:
176 try:
177 sGuestType = oGuestType.id;
178 except:
179 fRc = reporter.errorXcpt();
180 else:
181 reporter.testStart(sGuestType);
182 fRc = self.createVMWithDefaults(sGuestType) & fRc;
183 reporter.testDone();
184 reporter.testDone();
185
186 return fRc
187
188if __name__ == '__main__':
189 sys.path.append(os.path.dirname(os.path.abspath(__file__)))
190 from tdApi1 import tdApi1; # pylint: disable=relative-import
191 sys.exit(tdApi1([SubTstDrvCreateVMWithDefaults1]).main(sys.argv))
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