VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/tests/api/tdCloneMedium1.py@ 99568

Last change on this file since 99568 was 99235, checked in by vboxsync, 23 months ago

ValidationKit/tests/api/tdCloneMedium1.py: Solaris delivers python2 as a
32-bit binary which can't handle signed values above 0x7fffffff (MAXINT)
such as 0xdeadbeef. This causes the test suite to fail on Solaris with
the message: 'OverflowError: Python int too large to convert to C long'.
Fixed by using a smaller value when running 32-bit python2 on Solaris.

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 8.2 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3# $Id: tdCloneMedium1.py 99235 2023-03-30 14:24:55Z vboxsync $
4
5"""
6VirtualBox Validation Kit - Clone Medium Test #1
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: 99235 $"
41
42
43# Standard Python imports.
44import os
45import sys
46import platform
47
48# Only the main script needs to modify the path.
49try: __file__ # pylint: disable=used-before-assignment
50except: __file__ = sys.argv[0]
51g_ksValidationKitDir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
52sys.path.append(g_ksValidationKitDir)
53
54# Validation Kit imports.
55from common import utils
56from testdriver import base
57from testdriver import reporter
58from testdriver import vboxcon
59from testdriver import vboxwrappers
60
61
62class SubTstDrvCloneMedium1(base.SubTestDriverBase):
63 """
64 Sub-test driver for Clone Medium Test #1.
65 """
66
67 def __init__(self, oTstDrv):
68 base.SubTestDriverBase.__init__(self, oTstDrv, 'clone-medium', 'Move Medium');
69 # Solaris delivers a 32-bit version of Python 2.7 which can't handle signed values
70 # above 0x7fffffff (MAXINT) such as 0xdeadbeef. N.B. If this ever needs to be
71 # extended to other OSes the Python docs:
72 # https://docs.python.org/3/library/platform.html#platform.architecture
73 # mention that the platform.architecture() call can be wrong on macOS.
74 if utils.getHostOs() == 'solaris' and sys.version_info[0] < 3 and platform.architecture()[0] == '32bit':
75 self.iDataToWrite = 0x0badcafe;
76 else:
77 self.iDataToWrite = 0xdeadbeef;
78
79 def testIt(self):
80 """
81 Execute the sub-testcase.
82 """
83
84 return self.testAll()
85
86 #
87 # Test execution helpers.
88 #
89
90 def createTestMedium(self, oVM, sPathSuffix, sFmt = 'VDI', cbSize = 1024*1024, data = None):
91 assert oVM is not None
92
93 oSession = self.oTstDrv.openSession(oVM)
94
95 if oSession is None:
96 return False
97
98 #
99 # Create Medium Object
100 #
101
102 sBaseHdd1Path = os.path.join(self.oTstDrv.sScratchPath, sPathSuffix)
103 sBaseHdd1Fmt = sFmt
104 cbBaseHdd1Size = cbSize
105
106 try:
107 oBaseHdd1 = oSession.createBaseHd(sBaseHdd1Path, sBaseHdd1Fmt, cbBaseHdd1Size)
108 except:
109 return reporter.errorXcpt('createBaseHd failed')
110
111 oMediumIOBaseHdd1 = oBaseHdd1.openForIO(True, "")
112
113 if data:
114 cbWritten = oMediumIOBaseHdd1.write(0, data)
115
116 if cbWritten != 1:
117 return reporter.error("Failed writing to test hdd.")
118
119 oMediumIOBaseHdd1.close()
120
121 return oBaseHdd1
122
123 def cloneMedium(self, oSrcHd, oTgtHd):
124 """
125 Clones medium into target medium.
126 """
127 try:
128 oProgressCom = oSrcHd.cloneTo(oTgtHd, (vboxcon.MediumVariant_Standard, ), None);
129 except:
130 reporter.errorXcpt('failed to clone medium %s to %s' % (oSrcHd.name, oTgtHd.name));
131 return False;
132 oProgress = vboxwrappers.ProgressWrapper(oProgressCom, self.oTstDrv.oVBoxMgr, self.oTstDrv,
133 'clone base disk %s to %s' % (oSrcHd.name, oTgtHd.name));
134 oProgress.wait(cMsTimeout = 15*60*1000); # 15 min
135 oProgress.logResult();
136 return True;
137
138 def resizeAndCloneMedium(self, oSrcHd, oTgtHd, cbTgtSize):
139 """
140 Clones medium into target medium.
141 """
142
143 try:
144 oProgressCom = oSrcHd.resizeAndCloneTo(oTgtHd, cbTgtSize, (vboxcon.MediumVariant_Standard, ), None);
145 except:
146 reporter.errorXcpt('failed to resize and clone medium %s to %s and to size %d' \
147 % (oSrcHd.name, oTgtHd.name, cbTgtSize));
148 return False;
149 oProgress = vboxwrappers.ProgressWrapper(oProgressCom, self.oTstDrv.oVBoxMgr, self.oTstDrv,
150 'resize and clone base disk %s to %s and to size %d' \
151 % (oSrcHd.name, oTgtHd.name, cbTgtSize));
152 oProgress.wait(cMsTimeout = 15*60*1000); # 15 min
153 oProgress.logResult();
154 return True;
155
156 def deleteVM(self, oVM):
157 try:
158 oVM.unregister(vboxcon.CleanupMode_DetachAllReturnNone);
159 except:
160 reporter.logXcpt();
161
162 try:
163 oProgressCom = oVM.deleteConfig([]);
164 except:
165 reporter.logXcpt();
166 else:
167 oProgress = vboxwrappers.ProgressWrapper(oProgressCom, self.oTstDrv.oVBoxMgr, self.oTstDrv,
168 'Delete VM %s' % (oVM.name));
169 oProgress.wait(cMsTimeout = 15*60*1000); # 15 min
170 oProgress.logResult();
171
172 return None;
173
174 #
175 # Tests
176 #
177
178 def testCloneOnly(self):
179 """
180 Tests cloning mediums only. No resize.
181 """
182
183 reporter.testStart("testCloneOnly")
184
185 oVM = self.oTstDrv.createTestVM('test-medium-clone-only', 1, None, 4)
186
187 hd1 = self.createTestMedium(oVM, "hd1-cloneonly", data=[self.iDataToWrite])
188 hd2 = self.createTestMedium(oVM, "hd2-cloneonly")
189
190 if not self.cloneMedium(hd1, hd2):
191 return False
192
193 oMediumIOhd1 = hd1.openForIO(True, "")
194 dataHd1 = oMediumIOhd1.read(0, 4)
195 oMediumIOhd1.close()
196
197 oMediumIOhd2 = hd2.openForIO(True, "")
198 dataHd2 = oMediumIOhd2.read(0, 4)
199 oMediumIOhd2.close()
200
201 if dataHd1 != dataHd2:
202 reporter.testFailure("Data read is unexpected.")
203
204 self.deleteVM(oVM)
205
206 reporter.testDone()
207 return True
208
209 def testResizeAndClone(self):
210 """
211 Tests resizing and cloning mediums only.
212 """
213
214 reporter.testStart("testResizeAndClone")
215
216 oVM = self.oTstDrv.createTestVM('test-medium-clone-only', 1, None, 4)
217
218 hd1 = self.createTestMedium(oVM, "hd1-resizeandclone", data=[self.iDataToWrite])
219 hd2 = self.createTestMedium(oVM, "hd2-resizeandclone")
220
221 if not (hasattr(hd1, "resizeAndCloneTo") and callable(getattr(hd1, "resizeAndCloneTo"))):
222 self.deleteVM(oVM)
223 reporter.testDone()
224 return True
225
226 if not self.resizeAndCloneMedium(hd1, hd2, 1024*1024*2):
227 return False
228
229 oMediumIOhd1 = hd1.openForIO(True, "")
230 dataHd1 = oMediumIOhd1.read(0, 4)
231 oMediumIOhd1.close()
232
233 oMediumIOhd2 = hd2.openForIO(True, "")
234 dataHd2 = oMediumIOhd2.read(0, 4)
235 oMediumIOhd2.close()
236
237 if dataHd1 != dataHd2:
238 reporter.testFailure("Data read is unexpected.")
239
240 if hd2.logicalSize not in (hd1.logicalSize, 1024*1024*2):
241 reporter.testFailure("Target medium did not resize.")
242
243 self.deleteVM(oVM)
244
245 reporter.testDone()
246 return True
247
248 def testAll(self):
249 return self.testCloneOnly() & self.testResizeAndClone()
250
251if __name__ == '__main__':
252 sys.path.append(os.path.dirname(os.path.abspath(__file__)))
253 from tdApi1 import tdApi1; # pylint: disable=relative-import
254 sys.exit(tdApi1([SubTstDrvCloneMedium1]).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