VirtualBox

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

Last change on this file since 59680 was 59680, checked in by vboxsync, 9 years ago

tdAppliance1.py: Added the t5 OVAs.

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 6.9 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3# $Id: tdAppliance1.py 59680 2016-02-15 13:11:18Z vboxsync $
4
5"""
6VirtualBox Validation Kit - IAppliance Test #1
7"""
8
9__copyright__ = \
10"""
11Copyright (C) 2010-2015 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: 59680 $"
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 ):
97 reporter.testStart(sOva);
98 try:
99 fRc = self.testImportOva(os.path.join(g_ksValidationKitDir, 'tests', 'api', sOva)) and fRc;
100 fRc = self.testImportOvaAsOvf(os.path.join(g_ksValidationKitDir, 'tests', 'api', sOva)) and fRc;
101 except:
102 reporter.errorXcpt();
103 fRc = False;
104 fRc = reporter.testDone() and fRc;
105
106 ## @todo more stuff
107 return fRc;
108
109 #
110 # Test execution helpers.
111 #
112
113 def testImportOva(self, sOva):
114 """ xxx """
115 oVirtualBox = self.oVBoxMgr.getVirtualBox();
116
117 #
118 # Import it as OVA.
119 #
120 try:
121 oAppliance = oVirtualBox.createAppliance();
122 except:
123 return reporter.errorXcpt('IVirtualBox::createAppliance failed');
124 print "oAppliance=%s" % (oAppliance,)
125
126 try:
127 oProgress = vboxwrappers.ProgressWrapper(oAppliance.read(sOva), self.oVBoxMgr, self, 'read "%s"' % (sOva,));
128 except:
129 return reporter.errorXcpt('IAppliance::read("%s") failed' % (sOva,));
130 oProgress.wait();
131 if oProgress.logResult() is False:
132 return False;
133
134 try:
135 oAppliance.interpret();
136 except:
137 return reporter.errorXcpt('IAppliance::interpret() failed on "%s"' % (sOva,));
138
139 #
140 try:
141 oProgress = vboxwrappers.ProgressWrapper(oAppliance.importMachines([]),
142 self.oVBoxMgr, self, 'importMachines "%s"' % (sOva,));
143 except:
144 return reporter.errorXcpt('IAppliance::importMachines failed on "%s"' % (sOva,));
145 oProgress.wait();
146 if oProgress.logResult() is False:
147 return False;
148
149 #
150 # Export the
151 #
152 ## @todo do more with this OVA. Like untaring it and loading it as an OVF. Export it and import it again.
153
154 return True;
155
156 def testImportOvaAsOvf(self, sOva):
157 """
158 Unpacts the OVA into a subdirectory in the scratch area and imports it as an OVF.
159 """
160 oVirtualBox = self.oVBoxMgr.getVirtualBox();
161
162 sTmpDir = os.path.join(self.sScratchPath, os.path.split(sOva)[1] + '-ovf');
163 sOvf = os.path.join(sTmpDir, os.path.splitext(os.path.split(sOva)[1])[0] + '.ovf');
164
165 #
166 # Unpack
167 #
168 try:
169 os.mkdir(sTmpDir, 0755);
170 oTarFile = tarfile.open(sOva, 'r:*');
171 oTarFile.extractall(sTmpDir);
172 oTarFile.close();
173 except:
174 return reporter.errorXcpt('Unpacking "%s" to "%s" for OVF style importing failed' % (sOvf, sTmpDir,));
175
176 #
177 # Import.
178 #
179 try:
180 oAppliance2 = oVirtualBox.createAppliance();
181 except:
182 return reporter.errorXcpt('IVirtualBox::createAppliance failed (#2)');
183 print "oAppliance2=%s" % (oAppliance2,)
184
185 try:
186 oProgress = vboxwrappers.ProgressWrapper(oAppliance2.read(sOvf), self.oVBoxMgr, self, 'read "%s"' % (sOvf,));
187 except:
188 return reporter.errorXcpt('IAppliance::read("%s") failed' % (sOvf,));
189 oProgress.wait();
190 if oProgress.logResult() is False:
191 return False;
192
193 try:
194 oAppliance2.interpret();
195 except:
196 return reporter.errorXcpt('IAppliance::interpret() failed on "%s"' % (sOvf,));
197
198 try:
199 oProgress = vboxwrappers.ProgressWrapper(oAppliance2.importMachines([]),
200 self.oVBoxMgr, self, 'importMachines "%s"' % (sOvf,));
201 except:
202 return reporter.errorXcpt('IAppliance::importMachines failed on "%s"' % (sOvf,));
203 oProgress.wait();
204 if oProgress.logResult() is False:
205 return False;
206
207 return True;
208
209if __name__ == '__main__':
210 sys.exit(tdAppliance1().main(sys.argv));
211
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette