VirtualBox

Ignore:
Timestamp:
Jan 30, 2018 5:46:55 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
120609
Message:

ValidationKit: Turn all API tests into sub-tests which can still be run separately. tdApi1.py runs them all in one go.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/tests/api/tdAppliance1.py

    r70521 r70812  
    3838# Only the main script needs to modify the path.
    3939try:    __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);
     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)
    4343
    4444# 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):
     45from testdriver import base
     46from testdriver import reporter
     47from testdriver import vboxwrappers
     48
     49
     50class SubTstDrvAppliance1(base.SubTestDriverBase):
    5251    """
    53     IAppliance Test #1.
     52    Sub-test driver for IAppliance Test #1.
    5453    """
    5554
    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
    7863
    7964        # Import a set of simple OVAs.
     
    10388            'tdAppliance1-t7-bad-instance.ova',
    10489            ):
    105             reporter.testStart(sOva);
     90            reporter.testStart(sOva)
    10691            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
    10994            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
    11398
    11499        ## @todo more stuff
    115         return fRc;
     100        return fRc
    116101
    117102    #
     
    121106    def testImportOva(self, sOva):
    122107        """ xxx """
    123         oVirtualBox = self.oVBoxMgr.getVirtualBox();
     108        oVirtualBox = self.oTstDrv.oVBoxMgr.getVirtualBox()
    124109
    125110        #
     
    127112        #
    128113        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,))
    146130
    147131        #
    148132        try:
    149133            oProgress = vboxwrappers.ProgressWrapper(oAppliance.importMachines([]),
    150                                                      self.oVBoxMgr, 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
    156140
    157141        #
     
    160144        ## @todo do more with this OVA. Like untaring it and loading it as an OVF.  Export it and import it again.
    161145
    162         return True;
     146        return True
    163147
    164148    def testImportOvaAsOvf(self, sOva):
    165149        """
    166         Unpacts the OVA into a subdirectory in the scratch area and imports it as an OVF.
    167         """
    168         oVirtualBox = self.oVBoxMgr.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')
    172156
    173157        #
     
    175159        #
    176160        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,))
    183167
    184168        #
     
    186170        #
    187171        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,))
    205188
    206189        try:
    207190            oProgress = vboxwrappers.ProgressWrapper(oAppliance2.importMachines([]),
    208                                                      self.oVBoxMgr, 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
    216199
    217200if __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.

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