VirtualBox

Changeset 83415 in vbox


Ignore:
Timestamp:
Mar 25, 2020 4:27:11 PM (5 years ago)
Author:
vboxsync
Message:

TestManager/webui: Hooked up the partial database dumper to the WUI so it isn't necessary to have SSH access to the server to get at the data.

Location:
trunk/src/VBox/ValidationKit/testmanager
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/testmanager/config.py

    r83381 r83415  
    9090## File on the build binary share that can be used to check that it's mounted.
    9191g_ksBuildBinRootFile    = 'builds.txt'
     92## Template for paratial database dump files.  One argument: UID
     93g_ksTmDbDumpFileTemplate = '/var/tmp/tm-partial-db-dump-for-%u.zip'
    9294## @}
    9395
     
    142144g_kcMaxUploads          = 256;
    143145## @}
     146
     147
     148## @name Partial Database Dump
     149## @{
     150
     151## Minimum number of day.  Set higher than g_kcTmDbDumpMaxDays to disable.
     152g_kcTmDbDumpMinDays     = 1;
     153## Maximum number of day.  Keep low - consider space and runtime.
     154g_kcTmDbDumpMaxDays     = 31;
     155## The default number of days.
     156g_kcTmDbDumpDefaultDays = 14;
     157## @}
     158
    144159
    145160## @name Debug Features
  • trunk/src/VBox/ValidationKit/testmanager/webui/wuiadmin.py

    r83360 r83415  
    3535
    3636# Validation Kit imports.
    37 from common                                    import webutils
     37from common                                    import utils, webutils;
    3838from testmanager                               import config;
    3939from testmanager.webui.wuibase                 import WuiDispatcherBase, WuiException
     
    5555    ksActionSystemLogList           = 'SystemLogList'
    5656    ksActionSystemChangelogList     = 'SystemChangelogList'
     57    ksActionSystemDbDump            = 'SystemDbDump'
     58    ksActionSystemDbDumpDownload    = 'SystemDbDumpDownload'
    5759
    5860    ksActionUserList                = 'UserList'
     
    167169
    168170        #
    169         # System Log actions.
     171        # System actions.
    170172        #
    171173        self._dDispatch[self.ksActionSystemChangelogList]       = self._actionSystemChangelogList;
    172174        self._dDispatch[self.ksActionSystemLogList]             = self._actionSystemLogList;
     175        self._dDispatch[self.ksActionSystemDbDump]              = self._actionSystemDbDump;
     176        self._dDispatch[self.ksActionSystemDbDumpDownload]      = self._actionSystemDbDumpDownload;
    173177
    174178        #
     
    345349                    [ 'Changelog',              self._sActionUrlBase + self.ksActionSystemChangelogList,    False ],
    346350                    [ 'System log',             self._sActionUrlBase + self.ksActionSystemLogList,          False ],
     351                    [ 'Partial DB Dump',        self._sActionUrlBase + self.ksActionSystemDbDump,           False ],
    347352                    [ 'User accounts',          self._sActionUrlBase + self.ksActionUserList,               False ],
    348353                    [ 'New user',               self._sActionUrlBase + self.ksActionUserAdd,                True  ],
     
    423428
    424429    def _actionSystemChangelogList(self):
    425         """ Action wrapper. """
     430        """ Action handler. """
    426431        from testmanager.core.systemchangelog          import SystemChangelogLogic;
    427432        from testmanager.webui.wuiadminsystemchangelog import WuiAdminSystemChangelogList;
     
    447452        from testmanager.webui.wuiadminsystemlog       import WuiAdminSystemLogList;
    448453        return self._actionGenericListing(SystemLogLogic, WuiAdminSystemLogList)
     454
     455    def _actionSystemDbDump(self):
     456        """ Action handler. """
     457        from testmanager.webui.wuiadminsystemdbdump    import WuiAdminSystemDbDumpForm;
     458
     459        cDaysBack = self.getIntParam(self.ksParamDaysBack, iMin = config.g_kcTmDbDumpMinDays,
     460                                     iMax = config.g_kcTmDbDumpMaxDays, iDefault = config.g_kcTmDbDumpDefaultDays);
     461        self._checkForUnknownParameters();
     462
     463        oContent = WuiAdminSystemDbDumpForm(cDaysBack, oDisp = self);
     464        (self._sPageTitle, self._sPageBody) = oContent.showForm();
     465        return True;
     466
     467    def _actionSystemDbDumpDownload(self):
     468        """ Action handler. """
     469        import datetime;
     470        import os;
     471
     472        cDaysBack = self.getIntParam(self.ksParamDaysBack, iMin = config.g_kcTmDbDumpMinDays,
     473                                     iMax = config.g_kcTmDbDumpMaxDays, iDefault = config.g_kcTmDbDumpDefaultDays);
     474        self._checkForUnknownParameters();
     475
     476        #
     477        # Generate the dump.
     478        #
     479        # We generate a file name that's unique to a user is smart enough to only
     480        # issue one of these requests at the time.  This also makes sure we  won't
     481        #  waste too much space should this code get interrupted and rerun.
     482        #
     483        oFile    = None;
     484        oNow     = datetime.datetime.utcnow();
     485        sTmpFile = config.g_ksTmDbDumpFileTemplate % (self._oCurUser.uid,);
     486        sScript  = os.path.join(config.g_ksTestManagerDir, 'db', 'partial-db-dump.py');
     487        try:
     488            (iExitCode, sStdOut, sStdErr) = utils.processOutputUnchecked([sScript, '--days-to-dump', str(cDaysBack),
     489                                                                          '-f', sTmpFile,]);
     490            if iExitCode != 0:
     491                raise Exception('iExitCode=%s\n--- stderr ---\n%s\n--- stdout ---\n%s' % (iExitCode, sStdOut, sStdErr,));
     492
     493            #
     494            # Open and send the dump.
     495            #
     496            oFile = open(sTmpFile, 'rb');
     497            cbFile = os.fstat(oFile.fileno()).st_size;
     498
     499            self._oSrvGlue.setHeaderField('Content-Type', 'application/zip');
     500            self._oSrvGlue.setHeaderField('Content-Disposition',
     501                                          oNow.strftime('attachment; filename="partial-db-dump-%Y-%m-%dT%H-%M-%S.zip"'));
     502            self._oSrvGlue.setHeaderField('Content-Length', str(cbFile));
     503
     504            while True:
     505                abChunk = oFile.read(262144);
     506                if not abChunk:
     507                    break;
     508                self._oSrvGlue.writeRaw(abChunk);
     509
     510        finally:
     511            # Delete the file to save space.
     512            if oFile:
     513                try:    oFile.close();
     514                except: pass;
     515            utils.noxcptDeleteFile(sTmpFile);
     516        return self.ksDispatchRcAllDone;
     517
    449518
    450519    # User Account actions.
Note: See TracChangeset for help on using the changeset viewer.

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