VirtualBox

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

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

ValidationKit: address pylint issues

  • 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 70855 2018-02-02 13:52:40Z 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: 70855 $"
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),
138 fImmutable=False, fForceResource=False)
139 if fRc:
140 asFiles.append(sFile)
141
142 fRc = fRc and oSession.saveSettings()
143
144 #create temporary subdirectory in the current working directory
145 sOrigLoc = self.oTstDrv.sScratchPath
146 sNewLoc = os.path.join(sOrigLoc, 'newLocation')
147 os.mkdir(sNewLoc, 0o775)
148
149 aoMediumAttachments = oVM.getMediumAttachmentsOfController(sController)
150 #case 1. Only path without file name, with trailing separator
151 fRc = self.setLocation(sNewLoc + os.sep, aoMediumAttachments) and fRc
152 fRc = self.checkLocation(sNewLoc, aoMediumAttachments, asFiles) and fRc
153
154 #case 2. Only path without file name, without trailing separator
155 fRc = self.setLocation(sOrigLoc, aoMediumAttachments) and fRc
156 fRc = self.checkLocation(sOrigLoc, aoMediumAttachments, asFiles) and fRc
157
158 #case 3. Path with file name
159 fRc = self.setLocation(os.path.join(sNewLoc, 'newName'), aoMediumAttachments) and fRc
160 asNewFiles = ['newName' + os.path.splitext(s)[1] for s in asFiles]
161 fRc = self.checkLocation(os.path.join(sNewLoc, 'newName'), aoMediumAttachments, asFiles) and fRc
162 # BUG! the check above succeeds, but it actually should be the one below which does
163 #fRc = self.checkLocation(sNewLoc, aoMediumAttachments, asNewFiles) and fRc
164
165 #case 4. Only file name
166 fRc = self.setLocation('onlyMediumName', aoMediumAttachments) and fRc
167 asNewFiles = ['onlyMediumName' + os.path.splitext(s)[1] for s in asFiles]
168 fRc = self.checkLocation(os.path.join(sNewLoc, 'newName'), aoMediumAttachments,
169 [s.replace('.hdd', '.parallels') for s in asNewFiles]) and fRc
170 # BUG! due to the above path mishandling the check above succeeds, the directory issue is
171 # a consequence of the bug in case 3, but the extension is also picked incorrectly, it is
172 # not correct to just pick the backend id as the extension, it needs looking at the ext list.
173 #fRc = self.checkLocation(sNewLoc, aoMediumAttachments, asNewFiles) and fRc
174
175 #case 5. Move all files from a snapshot
176 fRc = fRc and oSession.takeSnapshot('Snapshot1')
177 if fRc:
178 aoMediumAttachments = oVM.getMediumAttachmentsOfController(sController)
179 asSnapFiles = [os.path.basename(o.medium.name) for o in aoMediumAttachments]
180 fRc = self.setLocation(sOrigLoc, aoMediumAttachments) and fRc
181 fRc = self.checkLocation(sOrigLoc, aoMediumAttachments, asSnapFiles) and fRc
182
183 fRc = oSession.close() and fRc
184
185 assert fRc is True
186 except:
187 reporter.errorXcpt()
188
189 return reporter.testDone()[1] == 0
190
191
192if __name__ == '__main__':
193 sys.path.append(os.path.dirname(os.path.abspath(__file__)))
194 from tdApi1 import tdApi1
195 sys.exit(tdApi1([SubTstDrvMoveMedium1]).main(sys.argv))
196
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