VirtualBox

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

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

ValidationKit: make pylint happy

  • 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: tdMoveMedium1.py 70813 2018-01-30 17:54:48Z 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: 70813 $"
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 vboxwrappers
47
48
49class 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
162if __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
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