# -*- coding: utf-8 -*- # $Id: wuiadmintestbox.py 69111 2017-10-17 14:26:02Z vboxsync $ """ Test Manager WUI - TestBox. """ __copyright__ = \ """ Copyright (C) 2012-2017 Oracle Corporation This file is part of VirtualBox Open Source Edition (OSE), as available from http://www.virtualbox.org. This file is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (GPL) as published by the Free Software Foundation, in version 2 as it comes in the "COPYING" file of the VirtualBox OSE distribution. VirtualBox OSE is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. The contents of this file may alternatively be used under the terms of the Common Development and Distribution License Version 1.0 (CDDL) only, as it comes in the "COPYING.CDDL" file of the VirtualBox OSE distribution, in which case the provisions of the CDDL are applicable instead of those of the GPL. You may elect to license modified versions of this file under the terms and conditions of either the GPL or the CDDL or both. """ __version__ = "$Revision: 69111 $" # Standard python imports. import socket; # Validation Kit imports. from common import utils, webutils; from testmanager.webui.wuicontentbase import WuiContentBase, WuiListContentWithActionBase, WuiFormContentBase, WuiLinkBase, \ WuiSvnLink, WuiTmLink, WuiSpanText, WuiRawHtml; from testmanager.core.db import TMDatabaseConnection; from testmanager.core.schedgroup import SchedGroupLogic, SchedGroupData; from testmanager.core.testbox import TestBoxData, TestBoxDataEx, TestBoxLogic; from testmanager.core.testset import TestSetData; from testmanager.core.db import isDbTimestampInfinity; class WuiTestBoxDetailsLink(WuiTmLink): """ Test box details link by ID. """ def __init__(self, idTestBox, sName = WuiContentBase.ksShortDetailsLink, fBracketed = False, tsNow = None): from testmanager.webui.wuiadmin import WuiAdmin; dParams = { WuiAdmin.ksParamAction: WuiAdmin.ksActionTestBoxDetails, TestBoxData.ksParam_idTestBox: idTestBox, }; if tsNow is not None: dParams[WuiAdmin.ksParamEffectiveDate] = tsNow; ## ?? WuiTmLink.__init__(self, sName, WuiAdmin.ksScriptName, dParams, fBracketed = fBracketed); self.idTestBox = idTestBox; class WuiTestBox(WuiFormContentBase): """ WUI TestBox Form Content Generator. """ def __init__(self, oData, sMode, oDisp): if sMode == WuiFormContentBase.ksMode_Add: sTitle = 'Create TextBox'; if oData.uuidSystem is not None and len(oData.uuidSystem) > 10: sTitle += ' - ' + oData.uuidSystem; elif sMode == WuiFormContentBase.ksMode_Edit: sTitle = 'Edit TestBox - %s (#%s)' % (oData.sName, oData.idTestBox); else: assert sMode == WuiFormContentBase.ksMode_Show; sTitle = 'TestBox - %s (#%s)' % (oData.sName, oData.idTestBox); WuiFormContentBase.__init__(self, oData, sMode, 'TestBox', oDisp, sTitle); # Try enter sName as hostname (no domain) when creating the testbox. if sMode == WuiFormContentBase.ksMode_Add \ and self._oData.sName in [None, ''] \ and self._oData.ip not in [None, '']: try: (self._oData.sName, _, _) = socket.gethostbyaddr(self._oData.ip); except: pass; offDot = self._oData.sName.find('.'); if offDot > 0: self._oData.sName = self._oData.sName[:offDot]; def _populateForm(self, oForm, oData): oForm.addIntRO( TestBoxData.ksParam_idTestBox, oData.idTestBox, 'TestBox ID'); oForm.addIntRO( TestBoxData.ksParam_idGenTestBox, oData.idGenTestBox, 'TestBox generation ID'); oForm.addTimestampRO(TestBoxData.ksParam_tsEffective, oData.tsEffective, 'Last changed'); oForm.addTimestampRO(TestBoxData.ksParam_tsExpire, oData.tsExpire, 'Expires (excl)'); oForm.addIntRO( TestBoxData.ksParam_uidAuthor, oData.uidAuthor, 'Changed by UID'); oForm.addText( TestBoxData.ksParam_ip, oData.ip, 'TestBox IP Address'); ## make read only?? oForm.addUuid( TestBoxData.ksParam_uuidSystem, oData.uuidSystem, 'TestBox System/Firmware UUID'); oForm.addText( TestBoxData.ksParam_sName, oData.sName, 'TestBox Name'); oForm.addText( TestBoxData.ksParam_sDescription, oData.sDescription, 'TestBox Description'); oForm.addCheckBox( TestBoxData.ksParam_fEnabled, oData.fEnabled, 'Enabled'); oForm.addComboBox( TestBoxData.ksParam_enmLomKind, oData.enmLomKind, 'Lights-out-management', TestBoxData.kaoLomKindDescs); oForm.addText( TestBoxData.ksParam_ipLom, oData.ipLom, 'Lights-out-management IP Address'); oForm.addInt( TestBoxData.ksParam_pctScaleTimeout, oData.pctScaleTimeout, 'Timeout scale factor (%)'); oForm.addListOfSchedGroupsForTestBox(TestBoxDataEx.ksParam_aoInSchedGroups, oData.aoInSchedGroups, SchedGroupLogic(TMDatabaseConnection()).fetchOrderedByName(), 'Scheduling Group'); # Command, comment and submit button. if self._sMode == WuiFormContentBase.ksMode_Edit: oForm.addComboBox(TestBoxData.ksParam_enmPendingCmd, oData.enmPendingCmd, 'Pending command', TestBoxData.kaoTestBoxCmdDescs); else: oForm.addComboBoxRO(TestBoxData.ksParam_enmPendingCmd, oData.enmPendingCmd, 'Pending command', TestBoxData.kaoTestBoxCmdDescs); oForm.addMultilineText(TestBoxData.ksParam_sComment, oData.sComment, 'Comment'); if self._sMode != WuiFormContentBase.ksMode_Show: oForm.addSubmit('Create TestBox' if self._sMode == WuiFormContentBase.ksMode_Add else 'Change TestBox'); return True; def _generatePostFormContent(self, oData): from testmanager.webui.wuihlpform import WuiHlpForm; oForm = WuiHlpForm('testbox-machine-settable', '', fReadOnly = True); oForm.addTextRO( TestBoxData.ksParam_sOs, oData.sOs, 'TestBox OS'); oForm.addTextRO( TestBoxData.ksParam_sOsVersion, oData.sOsVersion, 'TestBox OS version'); oForm.addTextRO( TestBoxData.ksParam_sCpuArch, oData.sCpuArch, 'TestBox OS kernel architecture'); oForm.addTextRO( TestBoxData.ksParam_sCpuVendor, oData.sCpuVendor, 'TestBox CPU vendor'); oForm.addTextRO( TestBoxData.ksParam_sCpuName, oData.sCpuName, 'TestBox CPU name'); if oData.lCpuRevision: oForm.addTextRO( TestBoxData.ksParam_lCpuRevision, '%#x' % (oData.lCpuRevision,), 'TestBox CPU revision', sPostHtml = ' (family=%#x model=%#x stepping=%#x)' % (oData.getCpuFamily(), oData.getCpuModel(), oData.getCpuStepping(),), sSubClass = 'long'); else: oForm.addLongRO( TestBoxData.ksParam_lCpuRevision, oData.lCpuRevision, 'TestBox CPU revision'); oForm.addIntRO( TestBoxData.ksParam_cCpus, oData.cCpus, 'Number of CPUs, cores and threads'); oForm.addCheckBoxRO( TestBoxData.ksParam_fCpuHwVirt, oData.fCpuHwVirt, 'VT-x or AMD-V supported'); oForm.addCheckBoxRO( TestBoxData.ksParam_fCpuNestedPaging, oData.fCpuNestedPaging, 'Nested paging supported'); oForm.addCheckBoxRO( TestBoxData.ksParam_fCpu64BitGuest, oData.fCpu64BitGuest, '64-bit guest supported'); oForm.addCheckBoxRO( TestBoxData.ksParam_fChipsetIoMmu, oData.fChipsetIoMmu, 'I/O MMU supported'); oForm.addMultilineTextRO(TestBoxData.ksParam_sReport, oData.sReport, 'Hardware/software report'); oForm.addLongRO( TestBoxData.ksParam_cMbMemory, oData.cMbMemory, 'Installed RAM size (MB)'); oForm.addLongRO( TestBoxData.ksParam_cMbScratch, oData.cMbScratch, 'Available scratch space (MB)'); oForm.addIntRO( TestBoxData.ksParam_iTestBoxScriptRev, oData.iTestBoxScriptRev, 'TestBox Script SVN revision'); sHexVer = oData.formatPythonVersion(); oForm.addIntRO( TestBoxData.ksParam_iPythonHexVersion, oData.iPythonHexVersion, 'Python version (hex)', sPostHtml = webutils.escapeElem(sHexVer)); return [('Machine Only Settables', oForm.finalize()),]; class WuiTestBoxList(WuiListContentWithActionBase): """ WUI TestBox List Content Generator. """ ## Descriptors for the combo box. kasTestBoxActionDescs = \ [ \ [ 'none', 'Select an action...', '' ], [ 'enable', 'Enable', '' ], [ 'disable', 'Disable', '' ], TestBoxData.kaoTestBoxCmdDescs[1], TestBoxData.kaoTestBoxCmdDescs[2], TestBoxData.kaoTestBoxCmdDescs[3], TestBoxData.kaoTestBoxCmdDescs[4], TestBoxData.kaoTestBoxCmdDescs[5], ]; ## Boxes which doesn't report in for more than 15 min are considered dead. kcSecMaxStatusDeltaAlive = 15*60 def __init__(self, aoEntries, iPage, cItemsPerPage, tsEffective, fnDPrint, oDisp, aiSelectedSortColumns = None): # type: (list[TestBoxDataForListing], int, int, datetime.datetime, ignore, WuiAdmin) -> None WuiListContentWithActionBase.__init__(self, aoEntries, iPage, cItemsPerPage, tsEffective, sTitle = 'TestBoxes', sId = 'users', fnDPrint = fnDPrint, oDisp = oDisp, aiSelectedSortColumns = aiSelectedSortColumns); self._asColumnHeaders.extend([ 'Name', 'LOM', 'Status', 'Cmd', 'Note', 'Script', 'Python', 'Group', 'OS', 'CPU', 'Features', 'CPUs', 'RAM', 'Scratch', 'Actions' ]); self._asColumnAttribs.extend([ 'align="center"', 'align="center"', 'align="center"', 'align="center"' 'align="center"', 'align="center"', 'align="center"', 'align="center"', '', '', '', 'align="left"', 'align="right"', 'align="right"', 'align="right"', 'align="center"' ]); self._aaiColumnSorting.extend([ (TestBoxLogic.kiSortColumn_sName,), None, # LOM (-TestBoxLogic.kiSortColumn_fEnabled, TestBoxLogic.kiSortColumn_enmState, -TestBoxLogic.kiSortColumn_tsUpdated,), (TestBoxLogic.kiSortColumn_enmPendingCmd,), None, # Note (TestBoxLogic.kiSortColumn_iTestBoxScriptRev,), (TestBoxLogic.kiSortColumn_iPythonHexVersion,), None, # Group (TestBoxLogic.kiSortColumn_sOs, TestBoxLogic.kiSortColumn_sOsVersion, TestBoxLogic.kiSortColumn_sCpuArch,), (TestBoxLogic.kiSortColumn_sCpuVendor, TestBoxLogic.kiSortColumn_lCpuRevision,), (TestBoxLogic.kiSortColumn_fCpuNestedPaging,), (TestBoxLogic.kiSortColumn_cCpus,), (TestBoxLogic.kiSortColumn_cMbMemory,), (TestBoxLogic.kiSortColumn_cMbScratch,), None, # Actions ]); assert len(self._aaiColumnSorting) == len(self._asColumnHeaders); self._aoActions = list(self.kasTestBoxActionDescs); self._sAction = oDisp.ksActionTestBoxListPost; self._sCheckboxName = TestBoxData.ksParam_idTestBox; def show(self, fShowNavigation = True): """ Adds some stats at the bottom of the page """ (sTitle, sBody) = super(WuiTestBoxList, self).show(fShowNavigation); # Count boxes in interesting states. if self._aoEntries: cActive = 0; cDead = 0; for oTestBox in self._aoEntries: if oTestBox.oStatus is not None: oDelta = oTestBox.tsCurrent - oTestBox.oStatus.tsUpdated; if oDelta.days <= 0 and oDelta.seconds <= self.kcSecMaxStatusDeltaAlive: if oTestBox.fEnabled: cActive += 1; else: cDead += 1; else: cDead += 1; sBody += '
\n' \ '%s testboxes of which %s are active and %s dead' \ '