1 | #!/usr/bin/env python
|
---|
2 | # -*- coding: utf-8 -*-
|
---|
3 | # $Id: tdCloneMedium1.py 98090 2023-01-16 09:39:04Z vboxsync $
|
---|
4 |
|
---|
5 | """
|
---|
6 | VirtualBox Validation Kit - Clone Medium Test #1
|
---|
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: 98090 $"
|
---|
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 | from testdriver import vboxwrappers
|
---|
58 |
|
---|
59 |
|
---|
60 | class SubTstDrvCloneMedium1(base.SubTestDriverBase):
|
---|
61 | """
|
---|
62 | Sub-test driver for Clone Medium Test #1.
|
---|
63 | """
|
---|
64 |
|
---|
65 | def __init__(self, oTstDrv):
|
---|
66 | base.SubTestDriverBase.__init__(self, oTstDrv, 'clone-medium', 'Move Medium');
|
---|
67 |
|
---|
68 | def testIt(self):
|
---|
69 | """
|
---|
70 | Execute the sub-testcase.
|
---|
71 | """
|
---|
72 |
|
---|
73 | return self.testAll()
|
---|
74 |
|
---|
75 | #
|
---|
76 | # Test execution helpers.
|
---|
77 | #
|
---|
78 |
|
---|
79 | def createTestMedium(self, oVM, sPathSuffix, sFmt = 'VDI', cbSize = 1024*1024, data = None):
|
---|
80 | assert oVM is not None
|
---|
81 |
|
---|
82 | oSession = self.oTstDrv.openSession(oVM)
|
---|
83 |
|
---|
84 | if oSession is None:
|
---|
85 | return False
|
---|
86 |
|
---|
87 | #
|
---|
88 | # Create Medium Object
|
---|
89 | #
|
---|
90 |
|
---|
91 | sBaseHdd1Path = os.path.join(self.oTstDrv.sScratchPath, sPathSuffix)
|
---|
92 | sBaseHdd1Fmt = sFmt
|
---|
93 | cbBaseHdd1Size = cbSize
|
---|
94 |
|
---|
95 | try:
|
---|
96 | oBaseHdd1 = oSession.createBaseHd(sBaseHdd1Path, sBaseHdd1Fmt, cbBaseHdd1Size)
|
---|
97 | except:
|
---|
98 | return reporter.errorXcpt('createBaseHd failed')
|
---|
99 |
|
---|
100 | oMediumIOBaseHdd1 = oBaseHdd1.openForIO(True, "")
|
---|
101 |
|
---|
102 | if data:
|
---|
103 | cbWritten = oMediumIOBaseHdd1.write(0, data)
|
---|
104 |
|
---|
105 | if cbWritten != 1:
|
---|
106 | return reporter.error("Failed writing to test hdd.")
|
---|
107 |
|
---|
108 | oMediumIOBaseHdd1.close()
|
---|
109 |
|
---|
110 | return oBaseHdd1
|
---|
111 |
|
---|
112 | def cloneMedium(self, oSrcHd, oTgtHd):
|
---|
113 | """
|
---|
114 | Clones medium into target medium.
|
---|
115 | """
|
---|
116 | try:
|
---|
117 | oProgressCom = oSrcHd.cloneTo(oTgtHd, (vboxcon.MediumVariant_Standard, ), None);
|
---|
118 | except:
|
---|
119 | reporter.errorXcpt('failed to clone medium %s to %s' % (oSrcHd.name, oTgtHd.name));
|
---|
120 | return False;
|
---|
121 | oProgress = vboxwrappers.ProgressWrapper(oProgressCom, self.oTstDrv.oVBoxMgr, self.oTstDrv,
|
---|
122 | 'clone base disk %s to %s' % (oSrcHd.name, oTgtHd.name));
|
---|
123 | oProgress.wait(cMsTimeout = 15*60*1000); # 15 min
|
---|
124 | oProgress.logResult();
|
---|
125 | return True;
|
---|
126 |
|
---|
127 | def resizeAndCloneMedium(self, oSrcHd, oTgtHd, cbTgtSize):
|
---|
128 | """
|
---|
129 | Clones medium into target medium.
|
---|
130 | """
|
---|
131 |
|
---|
132 | try:
|
---|
133 | oProgressCom = oSrcHd.resizeAndCloneTo(oTgtHd, cbTgtSize, (vboxcon.MediumVariant_Standard, ), None);
|
---|
134 | except:
|
---|
135 | reporter.errorXcpt('failed to resize and clone medium %s to %s and to size %d' \
|
---|
136 | % (oSrcHd.name, oTgtHd.name, cbTgtSize));
|
---|
137 | return False;
|
---|
138 | oProgress = vboxwrappers.ProgressWrapper(oProgressCom, self.oTstDrv.oVBoxMgr, self.oTstDrv,
|
---|
139 | 'resize and clone base disk %s to %s and to size %d' \
|
---|
140 | % (oSrcHd.name, oTgtHd.name, cbTgtSize));
|
---|
141 | oProgress.wait(cMsTimeout = 15*60*1000); # 15 min
|
---|
142 | oProgress.logResult();
|
---|
143 | return True;
|
---|
144 |
|
---|
145 | def deleteVM(self, oVM):
|
---|
146 | try:
|
---|
147 | oVM.unregister(vboxcon.CleanupMode_DetachAllReturnNone);
|
---|
148 | except:
|
---|
149 | reporter.logXcpt();
|
---|
150 |
|
---|
151 | try:
|
---|
152 | oProgressCom = oVM.deleteConfig([]);
|
---|
153 | except:
|
---|
154 | reporter.logXcpt();
|
---|
155 | else:
|
---|
156 | oProgress = vboxwrappers.ProgressWrapper(oProgressCom, self.oTstDrv.oVBoxMgr, self.oTstDrv,
|
---|
157 | 'Delete VM %s' % (oVM.name));
|
---|
158 | oProgress.wait(cMsTimeout = 15*60*1000); # 15 min
|
---|
159 | oProgress.logResult();
|
---|
160 |
|
---|
161 | return None;
|
---|
162 |
|
---|
163 | #
|
---|
164 | # Tests
|
---|
165 | #
|
---|
166 |
|
---|
167 | def testCloneOnly(self):
|
---|
168 | """
|
---|
169 | Tests cloning mediums only. No resize.
|
---|
170 | """
|
---|
171 |
|
---|
172 | reporter.testStart("testCloneOnly")
|
---|
173 |
|
---|
174 | oVM = self.oTstDrv.createTestVM('test-medium-clone-only', 1, None, 4)
|
---|
175 |
|
---|
176 | hd1 = self.createTestMedium(oVM, "hd1-cloneonly", data=[0xdeadbeef])
|
---|
177 | hd2 = self.createTestMedium(oVM, "hd2-cloneonly")
|
---|
178 |
|
---|
179 | if not self.cloneMedium(hd1, hd2):
|
---|
180 | return False
|
---|
181 |
|
---|
182 | oMediumIOhd1 = hd1.openForIO(True, "")
|
---|
183 | dataHd1 = oMediumIOhd1.read(0, 4)
|
---|
184 | oMediumIOhd1.close()
|
---|
185 |
|
---|
186 | oMediumIOhd2 = hd2.openForIO(True, "")
|
---|
187 | dataHd2 = oMediumIOhd2.read(0, 4)
|
---|
188 | oMediumIOhd2.close()
|
---|
189 |
|
---|
190 | if dataHd1 != dataHd2:
|
---|
191 | reporter.testFailure("Data read is unexpected.")
|
---|
192 |
|
---|
193 | self.deleteVM(oVM)
|
---|
194 |
|
---|
195 | reporter.testDone()
|
---|
196 | return True
|
---|
197 |
|
---|
198 | def testResizeAndClone(self):
|
---|
199 | """
|
---|
200 | Tests resizing and cloning mediums only.
|
---|
201 | """
|
---|
202 |
|
---|
203 | reporter.testStart("testResizeAndClone")
|
---|
204 |
|
---|
205 | oVM = self.oTstDrv.createTestVM('test-medium-clone-only', 1, None, 4)
|
---|
206 |
|
---|
207 | hd1 = self.createTestMedium(oVM, "hd1-resizeandclone", data=[0xdeadbeef])
|
---|
208 | hd2 = self.createTestMedium(oVM, "hd2-resizeandclone")
|
---|
209 |
|
---|
210 | if not (hasattr(hd1, "resizeAndCloneTo") and callable(getattr(hd1, "resizeAndCloneTo"))):
|
---|
211 | self.deleteVM(oVM)
|
---|
212 | reporter.testDone()
|
---|
213 | return True
|
---|
214 |
|
---|
215 | if not self.resizeAndCloneMedium(hd1, hd2, 1024*1024*2):
|
---|
216 | return False
|
---|
217 |
|
---|
218 | oMediumIOhd1 = hd1.openForIO(True, "")
|
---|
219 | dataHd1 = oMediumIOhd1.read(0, 4)
|
---|
220 | oMediumIOhd1.close()
|
---|
221 |
|
---|
222 | oMediumIOhd2 = hd2.openForIO(True, "")
|
---|
223 | dataHd2 = oMediumIOhd2.read(0, 4)
|
---|
224 | oMediumIOhd2.close()
|
---|
225 |
|
---|
226 | if dataHd1 != dataHd2:
|
---|
227 | reporter.testFailure("Data read is unexpected.")
|
---|
228 |
|
---|
229 | if hd2.logicalSize not in (hd1.logicalSize, 1024*1024*2):
|
---|
230 | reporter.testFailure("Target medium did not resize.")
|
---|
231 |
|
---|
232 | self.deleteVM(oVM)
|
---|
233 |
|
---|
234 | reporter.testDone()
|
---|
235 | return True
|
---|
236 |
|
---|
237 | def testAll(self):
|
---|
238 | return self.testCloneOnly() & self.testResizeAndClone()
|
---|
239 |
|
---|
240 | if __name__ == '__main__':
|
---|
241 | sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
---|
242 | from tdApi1 import tdApi1; # pylint: disable=relative-import
|
---|
243 | sys.exit(tdApi1([SubTstDrvCloneMedium1]).main(sys.argv))
|
---|