VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/tests/api/tdAppliance1.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 Author Date Id Revision
File size: 7.4 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3# $Id: tdAppliance1.py 70813 2018-01-30 17:54:48Z vboxsync $
4
5"""
6VirtualBox Validation Kit - IAppliance 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
36import tarfile
37
38# Only the main script needs to modify the path.
39try: __file__
40except: __file__ = sys.argv[0]
41g_ksValidationKitDir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
42sys.path.append(g_ksValidationKitDir)
43
44# Validation Kit imports.
45from testdriver import base
46from testdriver import reporter
47from testdriver import vboxwrappers
48
49
50class SubTstDrvAppliance1(base.SubTestDriverBase):
51 """
52 Sub-test driver for IAppliance Test #1.
53 """
54
55 def __init__(self, oTstDrv):
56 base.SubTestDriverBase.__init__(self, 'appliance', oTstDrv)
57
58 def testIt(self):
59 """
60 Execute the sub-testcase.
61 """
62 fRc = True
63
64 # Import a set of simple OVAs.
65 # Note! Manifests generated by ovftool 4.0.0 does not include the ovf, while the ones b 4.1.0 does.
66 for sOva in (
67 # t1 is a plain VM without any disks, ovftool 4.0 export from fusion
68 'tdAppliance1-t1.ova',
69 # t2 is a plain VM with one disk. Both 4.0 and 4.1.0 exports.
70 'tdAppliance1-t2.ova',
71 'tdAppliance1-t2-ovftool-4.1.0.ova',
72 # t3 is a VM with one gzipped disk and selecting SHA256 on the ovftool cmdline (--compress=9 --shaAlgorithm=sha256).
73 'tdAppliance1-t3.ova',
74 'tdAppliance1-t3-ovftool-4.1.0.ova',
75 # t4 is a VM with with two gzipped disk, SHA256 and a (self) signed manifest (--privateKey=./tdAppliance1-t4.pem).
76 'tdAppliance1-t4.ova',
77 'tdAppliance1-t4-ovftool-4.1.0.ova',
78 # t5 is a VM with with one gzipped disk, SHA1 and a manifest signed by a valid (2016) DigiCert code signing certificate.
79 'tdAppliance1-t5.ova',
80 'tdAppliance1-t5-ovftool-4.1.0.ova',
81 # t6 is a VM with with one gzipped disk, SHA1 and a manifest signed by a certificate issued by the t4 certificate,
82 # thus it should be impossible to establish a trusted path to a root CA.
83 'tdAppliance1-t6.ova',
84 'tdAppliance1-t6-ovftool-4.1.0.ova',
85 # t7 is based on tdAppliance1-t2-ovftool-4.1.0.ova and has modified to have an invalid InstanceID as well as an
86 # extra readme file. It was tarred up using bsdtar 2.4.12 on windows, so it uses a slightly different tar format and
87 # have different file attributes.
88 'tdAppliance1-t7-bad-instance.ova',
89 ):
90 reporter.testStart(sOva)
91 try:
92 fRc = self.testImportOva(os.path.join(g_ksValidationKitDir, 'tests', 'api', sOva)) and fRc
93 fRc = self.testImportOvaAsOvf(os.path.join(g_ksValidationKitDir, 'tests', 'api', sOva)) and fRc
94 except:
95 reporter.errorXcpt()
96 fRc = False
97 fRc = reporter.testDone() and fRc
98
99 ## @todo more stuff
100 return fRc
101
102 #
103 # Test execution helpers.
104 #
105
106 def testImportOva(self, sOva):
107 """ xxx """
108 oVirtualBox = self.oTstDrv.oVBoxMgr.getVirtualBox()
109
110 #
111 # Import it as OVA.
112 #
113 try:
114 oAppliance = oVirtualBox.createAppliance()
115 except:
116 return reporter.errorXcpt('IVirtualBox::createAppliance failed')
117
118 try:
119 oProgress = vboxwrappers.ProgressWrapper(oAppliance.read(sOva), self.oTstDrv.oVBoxMgr, self.oTstDrv, 'read "%s"' % (sOva,))
120 except:
121 return reporter.errorXcpt('IAppliance::read("%s") failed' % (sOva,))
122 oProgress.wait()
123 if oProgress.logResult() is False:
124 return False
125
126 try:
127 oAppliance.interpret()
128 except:
129 return reporter.errorXcpt('IAppliance::interpret() failed on "%s"' % (sOva,))
130
131 #
132 try:
133 oProgress = vboxwrappers.ProgressWrapper(oAppliance.importMachines([]),
134 self.oTstDrv.oVBoxMgr, self.oTstDrv, 'importMachines "%s"' % (sOva,))
135 except:
136 return reporter.errorXcpt('IAppliance::importMachines failed on "%s"' % (sOva,))
137 oProgress.wait()
138 if oProgress.logResult() is False:
139 return False
140
141 #
142 # Export the
143 #
144 ## @todo do more with this OVA. Like untaring it and loading it as an OVF. Export it and import it again.
145
146 return True
147
148 def testImportOvaAsOvf(self, sOva):
149 """
150 Unpacks the OVA into a subdirectory in the scratch area and imports it as an OVF.
151 """
152 oVirtualBox = self.oTstDrv.oVBoxMgr.getVirtualBox()
153
154 sTmpDir = os.path.join(self.oTstDrv.sScratchPath, os.path.split(sOva)[1] + '-ovf')
155 sOvf = os.path.join(sTmpDir, os.path.splitext(os.path.split(sOva)[1])[0] + '.ovf')
156
157 #
158 # Unpack
159 #
160 try:
161 os.mkdir(sTmpDir, 0o755)
162 oTarFile = tarfile.open(sOva, 'r:*')
163 oTarFile.extractall(sTmpDir)
164 oTarFile.close()
165 except:
166 return reporter.errorXcpt('Unpacking "%s" to "%s" for OVF style importing failed' % (sOvf, sTmpDir,))
167
168 #
169 # Import.
170 #
171 try:
172 oAppliance2 = oVirtualBox.createAppliance()
173 except:
174 return reporter.errorXcpt('IVirtualBox::createAppliance failed (#2)')
175
176 try:
177 oProgress = vboxwrappers.ProgressWrapper(oAppliance2.read(sOvf), self.oTstDrv.oVBoxMgr, self.oTstDrv, 'read "%s"' % (sOvf,))
178 except:
179 return reporter.errorXcpt('IAppliance::read("%s") failed' % (sOvf,))
180 oProgress.wait()
181 if oProgress.logResult() is False:
182 return False
183
184 try:
185 oAppliance2.interpret()
186 except:
187 return reporter.errorXcpt('IAppliance::interpret() failed on "%s"' % (sOvf,))
188
189 try:
190 oProgress = vboxwrappers.ProgressWrapper(oAppliance2.importMachines([]),
191 self.oTstDrv.oVBoxMgr, self.oTstDrv, 'importMachines "%s"' % (sOvf,))
192 except:
193 return reporter.errorXcpt('IAppliance::importMachines failed on "%s"' % (sOvf,))
194 oProgress.wait()
195 if oProgress.logResult() is False:
196 return False
197
198 return True
199
200
201if __name__ == '__main__':
202 sys.path.append(os.path.dirname(os.path.abspath(__file__)))
203 from tdApi1 import tdApi1
204 oTD = tdApi1()
205 oTD.addSubTestDriver(SubTstDrvAppliance1(oTD))
206 sys.exit(oTD.main(sys.argv))
207
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