Changeset 70812 in vbox for trunk/src/VBox/ValidationKit/tests/api/tdAppliance1.py
- Timestamp:
- Jan 30, 2018 5:46:55 PM (7 years ago)
- svn:sync-xref-src-repo-rev:
- 120609
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/tests/api/tdAppliance1.py
r70521 r70812 38 38 # Only the main script needs to modify the path. 39 39 try: __file__ 40 except: __file__ = sys.argv[0] ;41 g_ksValidationKitDir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) ;42 sys.path.append(g_ksValidationKitDir) ;40 except: __file__ = sys.argv[0] 41 g_ksValidationKitDir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) 42 sys.path.append(g_ksValidationKitDir) 43 43 44 44 # Validation Kit imports. 45 from testdriver import reporter; 46 from testdriver import base; 47 from testdriver import vbox; 48 from testdriver import vboxwrappers; 49 50 51 class tdAppliance1(vbox.TestDriver): 45 from testdriver import base 46 from testdriver import reporter 47 from testdriver import vboxwrappers 48 49 50 class SubTstDrvAppliance1(base.SubTestDriverBase): 52 51 """ 53 IAppliance Test #1.52 Sub-test driver for IAppliance Test #1. 54 53 """ 55 54 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; 55 def __init__(self, oTstDrv): 56 base.SubTestDriverBase.__init__(self, 'appliance', oTstDrv) 57 58 def testIt(self): 59 """ 60 Execute the sub-testcase. 61 """ 62 fRc = True 78 63 79 64 # Import a set of simple OVAs. … … 103 88 'tdAppliance1-t7-bad-instance.ova', 104 89 ): 105 reporter.testStart(sOva) ;90 reporter.testStart(sOva) 106 91 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 ;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 109 94 except: 110 reporter.errorXcpt() ;111 fRc = False ;112 fRc = reporter.testDone() and fRc ;95 reporter.errorXcpt() 96 fRc = False 97 fRc = reporter.testDone() and fRc 113 98 114 99 ## @todo more stuff 115 return fRc ;100 return fRc 116 101 117 102 # … … 121 106 def testImportOva(self, sOva): 122 107 """ xxx """ 123 oVirtualBox = self.o VBoxMgr.getVirtualBox();108 oVirtualBox = self.oTstDrv.oVBoxMgr.getVirtualBox() 124 109 125 110 # … … 127 112 # 128 113 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,)); 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, 'read "%s"' % (sOva,)) 120 except: 121 return reporter.errorXcpt('IAppliance::read("%s") failed' % (sOva,)) 122 oProgress.wait() 123 if oProgress.logResult() is False: 124 return False 125 126 try: 127 oAppliance.interpret() 128 except: 129 return reporter.errorXcpt('IAppliance::interpret() failed on "%s"' % (sOva,)) 146 130 147 131 # 148 132 try: 149 133 oProgress = vboxwrappers.ProgressWrapper(oAppliance.importMachines([]), 150 self.o VBoxMgr, 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 ;134 self.oTstDrv.oVBoxMgr, self.oTstDrv, 'importMachines "%s"' % (sOva,)) 135 except: 136 return reporter.errorXcpt('IAppliance::importMachines failed on "%s"' % (sOva,)) 137 oProgress.wait() 138 if oProgress.logResult() is False: 139 return False 156 140 157 141 # … … 160 144 ## @todo do more with this OVA. Like untaring it and loading it as an OVF. Export it and import it again. 161 145 162 return True ;146 return True 163 147 164 148 def testImportOvaAsOvf(self, sOva): 165 149 """ 166 Unpac ts the OVA into a subdirectory in the scratch area and imports it as an OVF.167 """ 168 oVirtualBox = self.o VBoxMgr.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') ;150 Unpacks the OVA into a subdirectory in the scratch area and imports it as an OVF. 151 """ 152 oVirtualBox = self.oTstDrv.oVBoxMgr.getVirtualBox() 153 154 sTmpDir = os.path.join(self.oTstDrv.sScratchPath, os.path.split(sOva)[1] + '-ovf') 155 sOvf = os.path.join(sTmpDir, os.path.splitext(os.path.split(sOva)[1])[0] + '.ovf') 172 156 173 157 # … … 175 159 # 176 160 try: 177 os.mkdir(sTmpDir, 0o755) ;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,)) ;161 os.mkdir(sTmpDir, 0o755) 162 oTarFile = tarfile.open(sOva, 'r:*') 163 oTarFile.extractall(sTmpDir) 164 oTarFile.close() 165 except: 166 return reporter.errorXcpt('Unpacking "%s" to "%s" for OVF style importing failed' % (sOvf, sTmpDir,)) 183 167 184 168 # … … 186 170 # 187 171 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,)); 172 oAppliance2 = oVirtualBox.createAppliance() 173 except: 174 return reporter.errorXcpt('IVirtualBox::createAppliance failed (#2)') 175 176 try: 177 oProgress = vboxwrappers.ProgressWrapper(oAppliance2.read(sOvf), self.oTstDrv.oVBoxMgr, self.oTstDrv, 'read "%s"' % (sOvf,)) 178 except: 179 return reporter.errorXcpt('IAppliance::read("%s") failed' % (sOvf,)) 180 oProgress.wait() 181 if oProgress.logResult() is False: 182 return False 183 184 try: 185 oAppliance2.interpret() 186 except: 187 return reporter.errorXcpt('IAppliance::interpret() failed on "%s"' % (sOvf,)) 205 188 206 189 try: 207 190 oProgress = vboxwrappers.ProgressWrapper(oAppliance2.importMachines([]), 208 self.o VBoxMgr, 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 ;191 self.oTstDrv.oVBoxMgr, self.oTstDrv, 'importMachines "%s"' % (sOvf,)) 192 except: 193 return reporter.errorXcpt('IAppliance::importMachines failed on "%s"' % (sOvf,)) 194 oProgress.wait() 195 if oProgress.logResult() is False: 196 return False 197 198 return True 216 199 217 200 if __name__ == '__main__': 218 sys.exit(tdAppliance1().main(sys.argv)); 219 201 sys.path.append(os.path.dirname(os.path.abspath(__file__))) 202 from tdApi1 import tdApi1 203 oTstDrv = tdApi1() 204 oTstDrv.addSubTestDriver(SubTstDrvAppliance1(oTstDrv)) 205 sys.exit(oTstDrv.main(sys.argv)) 206
Note:
See TracChangeset
for help on using the changeset viewer.