1 | #!/usr/bin/env python
|
---|
2 | # -*- coding: utf-8 -*-
|
---|
3 | # $Id: tdMoveMedium.py
|
---|
4 |
|
---|
5 | """
|
---|
6 | VirtualBox Validation Kit - Medium Move Test
|
---|
7 | """
|
---|
8 |
|
---|
9 | __copyright__ = \
|
---|
10 | """
|
---|
11 | Copyright (C) 2010-2016 Oracle Corporation
|
---|
12 |
|
---|
13 | This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
14 | available from http://www.virtualbox.org. This file is free software;
|
---|
15 | you can redistribute it and/or modify it under the terms of the GNU
|
---|
16 | General Public License (GPL) as published by the Free Software
|
---|
17 | Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
18 | VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
19 | hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
20 |
|
---|
21 | The contents of this file may alternatively be used under the terms
|
---|
22 | of the Common Development and Distribution License Version 1.0
|
---|
23 | (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
24 | VirtualBox OSE distribution, in which case the provisions of the
|
---|
25 | CDDL are applicable instead of those of the GPL.
|
---|
26 |
|
---|
27 | You may elect to license modified versions of this file under the
|
---|
28 | terms and conditions of either the GPL or the CDDL or both.
|
---|
29 | """
|
---|
30 | __version__ = ""
|
---|
31 |
|
---|
32 | # Standard Python imports.
|
---|
33 | import os
|
---|
34 | import sys
|
---|
35 |
|
---|
36 | # Only the main script needs to modify the path.
|
---|
37 | try: __file__
|
---|
38 | except: __file__ = sys.argv[0]
|
---|
39 | g_ksValidationKitDir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
---|
40 | sys.path.append(g_ksValidationKitDir)
|
---|
41 |
|
---|
42 | # Validation Kit imports.
|
---|
43 | from common import utils
|
---|
44 | from testdriver import reporter
|
---|
45 | from testdriver import vbox
|
---|
46 | from testdriver import vboxwrappers;
|
---|
47 |
|
---|
48 | class 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 |
|
---|
172 | if __name__ == '__main__':
|
---|
173 | sys.exit(tdMoveMedium().main(sys.argv))
|
---|
174 |
|
---|