VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/tests/api/tdAppliance1.py@ 68925

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

tdAppliance1.py: Added tescase for the harmless invalid InstanceID and extra file. bugref:8997

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