VirtualBox

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

Last change on this file since 86648 was 86648, checked in by vboxsync, 4 years ago

bugref:9781. Added the placeholder @@VBOX_COND_GUEST_VERSION[>(required version)]@@. Updated the templates. Removed the obsolete function getGuestOSConditional().

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