VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/tests/api/tdMoveMedium1.py@ 70854

Last change on this file since 70854 was 70854, checked in by vboxsync, 7 years ago

ValidationKit: Improve API testcase, doing checks if the moved images actually are in the correct place.

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Id Revision
File size: 8.2 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3# $Id: tdMoveMedium1.py 70854 2018-02-02 12:20:34Z vboxsync $
4
5"""
6VirtualBox Validation Kit - Medium Move Test #1
7"""
8
9__copyright__ = \
10"""
11Copyright (C) 2010-2017 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: 70854 $"
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
47from testdriver import vboxwrappers
48
49
50class SubTstDrvMoveMedium1(base.SubTestDriverBase):
51 """
52 Sub-test driver for Medium Move Test #1.
53 """
54
55 def __init__(self, oTstDrv):
56 base.SubTestDriverBase.__init__(self, 'move-medium', oTstDrv)
57
58 def testIt(self):
59 """
60 Execute the sub-testcase.
61 """
62 return self.testMediumMove()
63
64 #
65 # Test execution helpers.
66 #
67
68 def setLocation(self, sLocation, aoMediumAttachments):
69 for oAttachment in aoMediumAttachments:
70 try:
71 oMedium = oAttachment.medium
72 reporter.log('Move medium "%s" to "%s"' % (oMedium.name, sLocation,))
73 except:
74 reporter.errorXcpt('failed to get the medium from the IMediumAttachment "%s"' % (oAttachment))
75
76 try:
77 oProgress = vboxwrappers.ProgressWrapper(oMedium.setLocation(sLocation), self.oTstDrv.oVBoxMgr, self.oTstDrv,
78 'move "%s"' % (oMedium.name,))
79 except:
80 return reporter.errorXcpt('Medium::setLocation("%s") for medium "%s" failed' % (sLocation, oMedium.name,))
81
82 oProgress.wait()
83 if oProgress.logResult() is False:
84 return False
85 return True
86
87 def checkLocation(self, sLocation, aoMediumAttachments, asFiles):
88 fRc = True
89 for oAttachment in aoMediumAttachments:
90 sFilePath = os.path.join(sLocation, asFiles[oAttachment.port])
91 sActualFilePath = oAttachment.medium.location
92 if not os.path.samefile(sFilePath, sActualFilePath):
93 reporter.log('medium location expected to be "%s" but is "%s"', (sFilePath, sActualFilePath))
94 fRc = False;
95 if not os.path.exists(sFilePath):
96 reporter.log('medium file does not exist at "%s"', (sFilePath))
97 fRc = False;
98 return fRc
99
100 def testMediumMove(self):
101 """
102 Test medium moving.
103 """
104 reporter.testStart('medium moving')
105
106 try:
107 oVM = self.oTstDrv.createTestVM('test-medium-move', 1, None, 4)
108 assert oVM is not None
109
110 # create hard disk images, one for each file-based backend, using the first applicable extension
111 fRc = True
112 oSession = self.oTstDrv.openSession(oVM)
113 aoDskFmts = self.oTstDrv.oVBoxMgr.getArray(self.oTstDrv.oVBox.systemProperties, 'mediumFormats')
114 asFiles = []
115 for oDskFmt in aoDskFmts:
116 aoDskFmtCaps = self.oTstDrv.oVBoxMgr.getArray(oDskFmt, 'capabilities')
117 if vboxcon.MediumFormatCapabilities_File not in aoDskFmtCaps \
118 or vboxcon.MediumFormatCapabilities_CreateDynamic not in aoDskFmtCaps:
119 continue
120 (asExts, aTypes) = oDskFmt.describeFileExtensions()
121 for i in range(0, len(asExts)):
122 if aTypes[i] is vboxcon.DeviceType_HardDisk:
123 sExt = '.' + asExts[i]
124 break
125 if sExt is None:
126 fRc = False
127 break
128 sFile = 'Test' + str(len(asFiles)) + sExt
129 sHddPath = os.path.join(self.oTstDrv.sScratchPath, sFile)
130 oHd = oSession.createBaseHd(sHddPath, sFmt=oDskFmt.id, cb=1024*1024)
131 if oHd is None:
132 fRc = False
133 break
134
135 # attach HDD, IDE controller exists by default, but we use SATA just in case
136 sController='SATA Controller'
137 fRc = fRc and oSession.attachHd(sHddPath, sController, iPort = len(asFiles), fImmutable=False, fForceResource=False)
138 if fRc:
139 asFiles.append(sFile)
140
141 fRc = fRc and oSession.saveSettings()
142
143 #create temporary subdirectory in the current working directory
144 sOrigLoc = self.oTstDrv.sScratchPath
145 sNewLoc = os.path.join(sOrigLoc, 'newLocation')
146 os.mkdir(sNewLoc, 0o775)
147
148 aoMediumAttachments = oVM.getMediumAttachmentsOfController(sController)
149 #case 1. Only path without file name, with trailing separator
150 fRc = self.setLocation(sNewLoc + os.sep, aoMediumAttachments) and fRc
151 fRc = self.checkLocation(sNewLoc, aoMediumAttachments, asFiles) and fRc
152
153 #case 2. Only path without file name, without trailing separator
154 fRc = self.setLocation(sOrigLoc, aoMediumAttachments) and fRc
155 fRc = self.checkLocation(sOrigLoc, aoMediumAttachments, asFiles) and fRc
156
157 #case 3. Path with file name
158 fRc = self.setLocation(os.path.join(sNewLoc, 'newName'), aoMediumAttachments) and fRc
159 asNewFiles = list(map(lambda s: 'newName' + os.path.splitext(s)[1], asFiles))
160 fRc = self.checkLocation(os.path.join(sNewLoc, 'newName'), aoMediumAttachments, asFiles) and fRc
161 # BUG! the check above succeeds, but it actually should be the one below which does
162 #fRc = self.checkLocation(sNewLoc, aoMediumAttachments, asNewFiles) and fRc
163
164 #case 4. Only file name
165 fRc = self.setLocation('onlyMediumName', aoMediumAttachments) and fRc
166 asNewFiles = list(map(lambda s: 'onlyMediumName' + os.path.splitext(s)[1], asFiles))
167 fRc = self.checkLocation(os.path.join(sNewLoc, 'newName'), aoMediumAttachments,
168 list(map(lambda s: s.replace('.hdd', '.parallels'), asNewFiles))) and fRc
169 # BUG! due to the above path mishandling the check above succeeds, the directory issue is
170 # a consequence of the bug in case 3, but the extension is also picked incorrectly, it is
171 # not correct to just pick the backend id as the extension, it needs looking at the ext list.
172 #fRc = self.checkLocation(sNewLoc, aoMediumAttachments, asNewFiles) and fRc
173
174 #case 5. Move all files from a snapshot
175 fRc = fRc and oSession.takeSnapshot('Snapshot1')
176 if fRc:
177 aoMediumAttachments = oVM.getMediumAttachmentsOfController(sController)
178 asSnapFiles = list(map(lambda o: os.path.basename(o.medium.name), aoMediumAttachments))
179 fRc = self.setLocation(sOrigLoc, aoMediumAttachments) and fRc
180 fRc = self.checkLocation(sOrigLoc, aoMediumAttachments, asSnapFiles) and fRc
181
182 fRc = oSession.close() and fRc
183
184 assert fRc is True
185 except:
186 reporter.errorXcpt()
187
188 return reporter.testDone()[1] == 0
189
190
191if __name__ == '__main__':
192 sys.path.append(os.path.dirname(os.path.abspath(__file__)))
193 from tdApi1 import tdApi1
194 sys.exit(tdApi1([SubTstDrvMoveMedium1]).main(sys.argv))
195
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