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