VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/tests/api/tdMoveMedium.py@ 64468

Last change on this file since 64468 was 62483, checked in by vboxsync, 8 years ago

tdMoveMedium.py: svn prop fixes

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Id Revision
File size: 5.5 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3# $Id: tdMoveMedium.py
4
5"""
6VirtualBox Validation Kit - Medium Move Test
7"""
8
9__copyright__ = \
10"""
11Copyright (C) 2010-2016 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__ = ""
31
32# Standard Python imports.
33import os
34import sys
35
36# Only the main script needs to modify the path.
37try: __file__
38except: __file__ = sys.argv[0]
39g_ksValidationKitDir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
40sys.path.append(g_ksValidationKitDir)
41
42# Validation Kit imports.
43from common import utils
44from testdriver import reporter
45from testdriver import vbox
46from testdriver import vboxwrappers;
47
48class tdMoveMedium(vbox.TestDriver):
49 """
50 Medium moving Test.
51 """
52
53 # Suffix exclude list.
54 suffixes = [
55 '.vdi',
56 ];
57
58 def __init__(self):
59 vbox.TestDriver.__init__(self)
60 self.asRsrcs = None
61
62 #
63 # Overridden methods.
64 #
65
66 def actionConfig(self):
67 """
68 Import the API.
69 """
70 if not self.importVBoxApi():
71 return False
72 return True
73
74 def actionExecute(self):
75 """
76 Execute the testcase.
77 """
78 return self.testMediumMove()
79
80 #
81 # Test execution helpers.
82 #
83 def setLocation(self, sLocation, aListOfAttach):
84 for attachment in aListOfAttach:
85 try:
86 oMedium = attachment.medium;
87 reporter.log('Move medium ' + oMedium.name + ' to the ' + sLocation)
88 except:
89 reporter.errorXcpt('failed to get the medium from the IMediumAttachment "%s"' % (attachment));
90
91 try:
92 oProgress = vboxwrappers.ProgressWrapper(oMedium.setLocation(sLocation), self.oVBoxMgr, self, 'move "%s"' % (oMedium.name,));
93 except:
94 return reporter.errorXcpt('Medium::setLocation("%s") for medium "%s" failed' % (sLocation, oMedium.name,));
95
96 oProgress.wait();
97 if oProgress.logResult() is False:
98 return False;
99
100 # Test with VDI image
101 # move medium to a new location.
102 # case 1. Only path without file name
103 # case 2. Only path without file name without '\' or '/' at the end
104 # case 3. Path with file name
105 # case 4. Only file name
106 # case 5. Move snapshot
107
108 def testMediumMove(self):
109 """
110 Test medium moving.
111 """
112 reporter.testStart('medium moving')
113
114 try:
115 oVM = self.createTestVM('test-medium-move', 1, None, 4)
116 assert oVM is not None
117
118 # create virtual disk image vdi
119 fRc = True
120 c = 0
121 oSession = self.openSession(oVM)
122 for i in self.suffixes:
123 sHddPath = os.path.join(self.sScratchPath, 'Test' + str(c) + i)
124 oHd = oSession.createBaseHd(sHddPath, cb=1024*1024)
125 if oHd is None:
126 fRc = False
127 break
128
129 # attach HDD, IDE controller exists by default, but we use SATA just in case
130 sController='SATA Controller'
131 fRc = fRc and oSession.attachHd(sHddPath, sController, iPort = c, iDevice = 0, fImmutable=False, fForceResource=False)
132 fRc = fRc and oSession.saveSettings()
133
134 #create temporary subdirectory in the current working directory
135 sOrigLoc = self.sScratchPath
136 sNewLoc = os.path.join(sOrigLoc, 'newLocation/')
137
138 os.makedirs(sNewLoc, 0775);
139
140 aListOfAttach = oVM.getMediumAttachmentsOfController(sController)
141 #case 1. Only path without file name
142 sLocation = sNewLoc
143 self.setLocation(sLocation, aListOfAttach)
144
145 #case 2. Only path without file name without '\' or '/' at the end
146 sLocation = sOrigLoc
147 self.setLocation(sLocation, aListOfAttach)
148
149 #case 3. Path with file name
150 sLocation = sNewLoc + 'newName.vdi'
151 self.setLocation(sLocation, aListOfAttach)
152
153 #case 4. Only file name
154 sLocation = 'onlyMediumName'
155 self.setLocation(sLocation, aListOfAttach)
156
157 #case 5. Move snapshot
158 fRc = fRc and oSession.takeSnapshot('Snapshot1')
159 sLocation = sOrigLoc
160 #get fresh attachments after snapshot
161 aListOfAttach = oVM.getMediumAttachmentsOfController(sController)
162 self.setLocation(sLocation, aListOfAttach)
163
164 fRc = oSession.close() and fRc
165
166 assert fRc is True
167 except:
168 reporter.errorXcpt()
169
170 return reporter.testDone()[1] == 0
171
172if __name__ == '__main__':
173 sys.exit(tdMoveMedium().main(sys.argv))
174
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