VirtualBox

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

Last change on this file since 79449 was 79067, checked in by vboxsync, 6 years ago

ValKit: Refactored sub-test driver initialization so it can have both a shortish name for --disable-sub-driver (new) and a test name for reporter.testStart. Working on extending tdGuestOsUnattendedInst1.py to do GA testings. bugref:9151

  • 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 79067 2019-06-10 22:56:46Z vboxsync $
4
5"""
6VirtualBox Validation Kit - IAppliance Test #1
7"""
8
9__copyright__ = \
10"""
11Copyright (C) 2010-2019 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: 79067 $"
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 # 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 cert.
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,
120 'read "%s"' % (sOva,));
121 except:
122 return reporter.errorXcpt('IAppliance::read("%s") failed' % (sOva,));
123 oProgress.wait();
124 if oProgress.logResult() is False:
125 return False;
126
127 try:
128 oAppliance.interpret();
129 except:
130 return reporter.errorXcpt('IAppliance::interpret() failed on "%s"' % (sOva,));
131
132 #
133 try:
134 oProgress = vboxwrappers.ProgressWrapper(oAppliance.importMachines([]),
135 self.oTstDrv.oVBoxMgr, self.oTstDrv, 'importMachines "%s"' % (sOva,));
136 except:
137 return reporter.errorXcpt('IAppliance::importMachines failed on "%s"' % (sOva,));
138 oProgress.wait();
139 if oProgress.logResult() is False:
140 return False;
141
142 #
143 # Export the
144 #
145 ## @todo do more with this OVA. Like untaring it and loading it as an OVF. Export it and import it again.
146
147 return True;
148
149 def testImportOvaAsOvf(self, sOva):
150 """
151 Unpacks the OVA into a subdirectory in the scratch area and imports it as an OVF.
152 """
153 oVirtualBox = self.oTstDrv.oVBoxMgr.getVirtualBox();
154
155 sTmpDir = os.path.join(self.oTstDrv.sScratchPath, os.path.split(sOva)[1] + '-ovf');
156 sOvf = os.path.join(sTmpDir, os.path.splitext(os.path.split(sOva)[1])[0] + '.ovf');
157
158 #
159 # Unpack
160 #
161 try:
162 os.mkdir(sTmpDir, 0o755);
163 oTarFile = tarfile.open(sOva, 'r:*');
164 oTarFile.extractall(sTmpDir);
165 oTarFile.close();
166 except:
167 return reporter.errorXcpt('Unpacking "%s" to "%s" for OVF style importing failed' % (sOvf, sTmpDir,));
168
169 #
170 # Import.
171 #
172 try:
173 oAppliance2 = oVirtualBox.createAppliance();
174 except:
175 return reporter.errorXcpt('IVirtualBox::createAppliance failed (#2)');
176
177 try:
178 oProgress = vboxwrappers.ProgressWrapper(oAppliance2.read(sOvf), self.oTstDrv.oVBoxMgr, self.oTstDrv,
179 'read "%s"' % (sOvf,));
180 except:
181 return reporter.errorXcpt('IAppliance::read("%s") failed' % (sOvf,));
182 oProgress.wait();
183 if oProgress.logResult() is False:
184 return False;
185
186 try:
187 oAppliance2.interpret();
188 except:
189 return reporter.errorXcpt('IAppliance::interpret() failed on "%s"' % (sOvf,));
190
191 try:
192 oProgress = vboxwrappers.ProgressWrapper(oAppliance2.importMachines([]),
193 self.oTstDrv.oVBoxMgr, self.oTstDrv, 'importMachines "%s"' % (sOvf,));
194 except:
195 return reporter.errorXcpt('IAppliance::importMachines failed on "%s"' % (sOvf,));
196 oProgress.wait();
197 if oProgress.logResult() is False:
198 return False;
199
200 return True;
201
202
203if __name__ == '__main__':
204 sys.path.append(os.path.dirname(os.path.abspath(__file__)))
205 from tests.api.tdApi1 import tdApi1;
206 sys.exit(tdApi1([SubTstDrvAppliance1]).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