VirtualBox

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

Last change on this file was 106061, checked in by vboxsync, 3 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 8.1 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3# $Id: tdAppliance1.py 106061 2024-09-16 14:03:52Z vboxsync $
4
5"""
6VirtualBox Validation Kit - IAppliance Test #1
7"""
8
9__copyright__ = \
10"""
11Copyright (C) 2010-2024 Oracle and/or its affiliates.
12
13This file is part of VirtualBox base platform packages, as
14available from https://www.virtualbox.org.
15
16This program is free software; you can redistribute it and/or
17modify it under the terms of the GNU General Public License
18as published by the Free Software Foundation, in version 3 of the
19License.
20
21This program is distributed in the hope that it will be useful, but
22WITHOUT ANY WARRANTY; without even the implied warranty of
23MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24General Public License for more details.
25
26You should have received a copy of the GNU General Public License
27along with this program; if not, see <https://www.gnu.org/licenses>.
28
29The contents of this file may alternatively be used under the terms
30of the Common Development and Distribution License Version 1.0
31(CDDL), a copy of it is provided in the "COPYING.CDDL" file included
32in the VirtualBox distribution, in which case the provisions of the
33CDDL are applicable instead of those of the GPL.
34
35You may elect to license modified versions of this file under the
36terms and conditions of either the GPL or the CDDL or both.
37
38SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
39"""
40__version__ = "$Revision: 106061 $"
41
42
43# Standard Python imports.
44import os
45import sys
46import tarfile
47
48# Only the main script needs to modify the path.
49try: __file__ # pylint: disable=used-before-assignment
50except: __file__ = sys.argv[0]
51g_ksValidationKitDir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
52sys.path.append(g_ksValidationKitDir)
53
54# Validation Kit imports.
55from testdriver import base;
56from testdriver import reporter;
57from testdriver import vboxwrappers;
58
59
60class SubTstDrvAppliance1(base.SubTestDriverBase):
61 """
62 Sub-test driver for IAppliance Test #1.
63 """
64
65 def __init__(self, oTstDrv):
66 base.SubTestDriverBase.__init__(self, oTstDrv, 'appliance', 'Applicance');
67
68 def testIt(self):
69 """
70 Execute the sub-testcase.
71 """
72 fRc = True;
73
74 # Import a set of simple OVAs.
75 # Note! Manifests generated by ovftool 4.0.0 does not include the ovf, while the ones b 4.1.0 does.
76 for sOva in (
77 # t1 is a plain VM without any disks, ovftool 4.0 export from fusion
78 'tdAppliance1-t1.ova',
79 # t2 is a plain VM with one disk. Both 4.0 and 4.1.0 exports.
80 'tdAppliance1-t2.ova',
81 'tdAppliance1-t2-ovftool-4.1.0.ova',
82 # t3 is a VM with one gzipped disk and selecting SHA256 on the ovftool cmdline (--compress=9 --shaAlgorithm=sha256).
83 'tdAppliance1-t3.ova',
84 'tdAppliance1-t3-ovftool-4.1.0.ova',
85 # t4 is a VM with with two gzipped disk, SHA256 and a (self) signed manifest (--privateKey=./tdAppliance1-t4.pem).
86 'tdAppliance1-t4.ova',
87 'tdAppliance1-t4-ovftool-4.1.0.ova',
88 # t5 is a VM with with one gzipped disk, SHA1 and a manifest signed by a valid (2016) DigiCert code signing cert.
89 'tdAppliance1-t5.ova',
90 'tdAppliance1-t5-ovftool-4.1.0.ova',
91 # t6 is a VM with with one gzipped disk, SHA1 and a manifest signed by a certificate issued by the t4 certificate,
92 # thus it should be impossible to establish a trusted path to a root CA.
93 'tdAppliance1-t6.ova',
94 'tdAppliance1-t6-ovftool-4.1.0.ova',
95 # t7 is based on tdAppliance1-t2-ovftool-4.1.0.ova and has modified to have an invalid InstanceID as well as an
96 # extra readme file. It was tarred up using bsdtar 2.4.12 on windows, so it uses a slightly different tar format and
97 # have different file attributes.
98 'tdAppliance1-t7-bad-instance.ova',
99 ):
100 reporter.testStart(sOva);
101 try:
102 fRc = self.testImportOva(os.path.join(g_ksValidationKitDir, 'tests', 'api', sOva)) and fRc;
103 fRc = self.testImportOvaAsOvf(os.path.join(g_ksValidationKitDir, 'tests', 'api', sOva)) and fRc;
104 except:
105 reporter.errorXcpt();
106 fRc = False;
107 fRc = reporter.testDone() and fRc;
108
109 ## @todo more stuff
110 return fRc;
111
112 #
113 # Test execution helpers.
114 #
115
116 def testImportOva(self, sOva):
117 """ xxx """
118 oVirtualBox = self.oTstDrv.oVBoxMgr.getVirtualBox();
119
120 #
121 # Import it as OVA.
122 #
123 try:
124 oAppliance = oVirtualBox.createAppliance();
125 except:
126 return reporter.errorXcpt('IVirtualBox::createAppliance failed');
127
128 try:
129 oProgress = vboxwrappers.ProgressWrapper(oAppliance.read(sOva), self.oTstDrv.oVBoxMgr, self.oTstDrv,
130 'read "%s"' % (sOva,));
131 except:
132 return reporter.errorXcpt('IAppliance::read("%s") failed' % (sOva,));
133 oProgress.wait();
134 if oProgress.logResult() is False:
135 return False;
136
137 try:
138 oAppliance.interpret();
139 except:
140 return reporter.errorXcpt('IAppliance::interpret() failed on "%s"' % (sOva,));
141
142 #
143 try:
144 oProgress = vboxwrappers.ProgressWrapper(oAppliance.importMachines([]),
145 self.oTstDrv.oVBoxMgr, self.oTstDrv, 'importMachines "%s"' % (sOva,));
146 except:
147 return reporter.errorXcpt('IAppliance::importMachines failed on "%s"' % (sOva,));
148 oProgress.wait();
149 if oProgress.logResult() is False:
150 return False;
151
152 #
153 # Export the
154 #
155 ## @todo do more with this OVA. Like untaring it and loading it as an OVF. Export it and import it again.
156
157 return True;
158
159 def testImportOvaAsOvf(self, sOva):
160 """
161 Unpacks the OVA into a subdirectory in the scratch area and imports it as an OVF.
162 """
163 oVirtualBox = self.oTstDrv.oVBoxMgr.getVirtualBox();
164
165 sTmpDir = os.path.join(self.oTstDrv.sScratchPath, os.path.split(sOva)[1] + '-ovf');
166 sOvf = os.path.join(sTmpDir, os.path.splitext(os.path.split(sOva)[1])[0] + '.ovf');
167
168 #
169 # Unpack
170 #
171 try:
172 os.mkdir(sTmpDir, 0o755);
173 oTarFile = tarfile.open(sOva, 'r:*'); # No 'with' support in 2.6. pylint: disable=consider-using-with
174 if hasattr(tarfile, 'tar_filter'):
175 oTarFile.extractall(sTmpDir, filter = 'tar');
176 else:
177 oTarFile.extractall(sTmpDir);
178 oTarFile.close();
179 except:
180 return reporter.errorXcpt('Unpacking "%s" to "%s" for OVF style importing failed' % (sOvf, sTmpDir,));
181
182 #
183 # Import.
184 #
185 try:
186 oAppliance2 = oVirtualBox.createAppliance();
187 except:
188 return reporter.errorXcpt('IVirtualBox::createAppliance failed (#2)');
189
190 try:
191 oProgress = vboxwrappers.ProgressWrapper(oAppliance2.read(sOvf), self.oTstDrv.oVBoxMgr, self.oTstDrv,
192 'read "%s"' % (sOvf,));
193 except:
194 return reporter.errorXcpt('IAppliance::read("%s") failed' % (sOvf,));
195 oProgress.wait();
196 if oProgress.logResult() is False:
197 return False;
198
199 try:
200 oAppliance2.interpret();
201 except:
202 return reporter.errorXcpt('IAppliance::interpret() failed on "%s"' % (sOvf,));
203
204 try:
205 oProgress = vboxwrappers.ProgressWrapper(oAppliance2.importMachines([]),
206 self.oTstDrv.oVBoxMgr, self.oTstDrv, 'importMachines "%s"' % (sOvf,));
207 except:
208 return reporter.errorXcpt('IAppliance::importMachines failed on "%s"' % (sOvf,));
209 oProgress.wait();
210 if oProgress.logResult() is False:
211 return False;
212
213 return True;
214
215
216if __name__ == '__main__':
217 sys.path.append(os.path.dirname(os.path.abspath(__file__)))
218 from tests.api.tdApi1 import tdApi1;
219 sys.exit(tdApi1([SubTstDrvAppliance1]).main(sys.argv));
220
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