def _isProcessPresent(self, sName): """ Checks whether the named process is present or not. """ for oProcess in utils.processListAll(): sBase = oProcess.getBaseImageNameNoExeSuff(); if sBase is not None and sBase.lower() == sName: return True; return False;
def _isProcessPresent(self, sName): """ Checks whether the named process is present or not. """ for oProcess in utils.processListAll(): sBase = oProcess.getBaseImageNameNoExeSuff() if sBase is not None and sBase.lower() == sName: return True return False
def _uninstallVBoxOnWindows(self): """ Uninstalls VBox on Windows, all installations we find to be on the safe side... """ import win32com.client; # pylint: disable=F0401 win32com.client.gencache.EnsureModule('{000C1092-0000-0000-C000-000000000046}', 1033, 1, 0); oInstaller = win32com.client.Dispatch('WindowsInstaller.Installer', resultCLSID = '{000C1090-0000-0000-C000-000000000046}') # Search installed products for VirtualBox. asProdCodes = []; for sProdCode in oInstaller.Products: try: sProdName = oInstaller.ProductInfo(sProdCode, "ProductName"); except: reporter.logXcpt(); continue; #reporter.log('Info: %s=%s' % (sProdCode, sProdName)); if sProdName.startswith('Oracle VM VirtualBox') \ or sProdName.startswith('Sun VirtualBox'): asProdCodes.append([sProdCode, sProdName]); # Before we start uninstalling anything, just ruthlessly kill any # msiexec process we might find hanging around. cKilled = 0; for oProcess in utils.processListAll(): sBase = oProcess.getBaseImageNameNoExeSuff(); if sBase is not None and sBase.lower() in [ 'msiexec', ]: reporter.log('Killing MSI process: %s (%s)' % (oProcess.iPid, sBase)); utils.processKill(oProcess.iPid); cKilled += 1; if cKilled > 0: time.sleep(16); # fudge. # Do the uninstalling. fRc = True; sLogFile = os.path.join(self.sScratchPath, 'VBoxUninstallLog.txt'); for sProdCode, sProdName in asProdCodes: reporter.log('Uninstalling %s (%s)...' % (sProdName, sProdCode)); fRc2, iRc = self._sudoExecuteSync(['msiexec', '/uninstall', sProdCode, '/quiet', '/passive', '/norestart', '/L*v', '%s' % (sLogFile), ]); if fRc2 is False: if iRc == 3010: # ERROR_SUCCESS_REBOOT_REQUIRED reporter.log('Note: Uninstaller required a reboot to complete uninstallation'); # Optional, don't fail. else: fRc = False; reporter.addLogFile(sLogFile, 'log/uninstaller', "Verbose MSI uninstallation log file"); self._waitForTestManagerConnectivity(30); if fRc is False and os.path.isfile(sLogFile): reporter.addLogFile(sLogFile, 'log/uninstaller'); return fRc;
def _terminateProcessesByNameAndArgSubstr(self, sName, sArg, sDesc): """ Terminates the named process using taskkill.exe, if any of its args contains the passed string. """ cKilled = 0; aoProcesses = utils.processListAll(); for oProcess in aoProcesses: sBase = oProcess.getBaseImageNameNoExeSuff(); if sBase is not None and sBase.lower() == sName and any(sArg in s for s in oProcess.asArgs): reporter.log('Killing %s process: %s (%s)' % (sDesc, oProcess.iPid, sBase)); self._executeSync(['taskkill.exe', '/pid', '%u' % (oProcess.iPid,)]); cKilled += 1; return cKilled;
def _killProcessesByName(self, sName, sDesc, fChildren = False): """ Kills the named process, optionally including children. """ cKilled = 0; aoProcesses = utils.processListAll(); for oProcess in aoProcesses: sBase = oProcess.getBaseImageNameNoExeSuff(); if sBase is not None and sBase.lower() == sName: reporter.log('Killing %s process: %s (%s)' % (sDesc, oProcess.iPid, sBase)); utils.processKill(oProcess.iPid); cKilled += 1; if fChildren: for oChild in aoProcesses: if oChild.iParentPid == oProcess.iPid and oChild.iParentPid is not None: reporter.log('Killing %s child process: %s (%s)' % (sDesc, oChild.iPid, sBase)); utils.processKill(oChild.iPid); cKilled += 1; return cKilled;
def _killProcessesByName(self, sName, sDesc, fChildren=False): """ Checks whether the named process is present or not. """ cKilled = 0 aoProcesses = utils.processListAll() for oProcess in aoProcesses: sBase = oProcess.getBaseImageNameNoExeSuff() if sBase is not None and sBase.lower() == sName: reporter.log('Killing %s process: %s (%s)' % (sDesc, oProcess.iPid, sBase)) utils.processKill(oProcess.iPid) cKilled += 1 if fChildren: for oChild in aoProcesses: if oChild.iParentPid == oProcess.iPid and oChild.iParentPid is not None: reporter.log('Killing %s child process: %s (%s)' % (sDesc, oChild.iPid, sBase)) utils.processKill(oChild.iPid) cKilled += 1 return cKilled
def _killAllVBoxProcesses(self): """ Kills all virtual box related processes we find in the system. """ for iIteration in range(22): # Gather processes to kill. aoTodo = []; for oProcess in utils.processListAll(): sBase = oProcess.getBaseImageNameNoExeSuff(); if sBase is None: continue; sBase = sBase.lower(); if sBase in [ 'vboxsvc', 'virtualbox', 'virtualboxvm', 'vboxheadless', 'vboxmanage', 'vboxsdl', 'vboxwebsrv', 'vboxautostart', 'vboxballoonctrl', 'vboxbfe', 'vboxextpackhelperapp', 'vboxnetdhcp', 'vboxnetadpctl', 'vboxtestogl', 'vboxtunctl', 'vboxvmmpreload', 'vboxxpcomipcd', 'vmCreator', ]: aoTodo.append(oProcess); if sBase.startswith('virtualbox-') and sBase.endswith('-multiarch.exe'): aoTodo.append(oProcess); if iIteration in [0, 21] and sBase in [ 'windbg', 'gdb', 'gdb-i386-apple-darwin', ]: reporter.log('Warning: debugger running: %s (%s)' % (oProcess.iPid, sBase,)); if not aoTodo: return True; # Kill. for oProcess in aoTodo: reporter.log('Loop #%d - Killing %s (%s, uid=%s)' % ( iIteration, oProcess.iPid, oProcess.sImage if oProcess.sName is None else oProcess.sName, oProcess.iUid, )); utils.processKill(oProcess.iPid); # No mercy. # Check if they're all dead like they should be. time.sleep(0.1); for oProcess in aoTodo: if utils.processExists(oProcess.iPid): time.sleep(2); break; return False;
def _uninstallVBoxOnWindows(self): """ Uninstalls VBox on Windows, all installations we find to be on the safe side... """ import win32com.client # pylint: disable=F0401 win32com.client.gencache.EnsureModule( '{000C1092-0000-0000-C000-000000000046}', 1033, 1, 0) oInstaller = win32com.client.Dispatch( 'WindowsInstaller.Installer', resultCLSID='{000C1090-0000-0000-C000-000000000046}') # Search installed products for VirtualBox. asProdCodes = [] for sProdCode in oInstaller.Products: try: sProdName = oInstaller.ProductInfo(sProdCode, "ProductName") except: reporter.logXcpt() continue #reporter.log('Info: %s=%s' % (sProdCode, sProdName)); if sProdName.startswith('Oracle VM VirtualBox') \ or sProdName.startswith('Sun VirtualBox'): asProdCodes.append([sProdCode, sProdName]) # Before we start uninstalling anything, just ruthlessly kill any # msiexec process we might find hanging around. cKilled = 0 for oProcess in utils.processListAll(): sBase = oProcess.getBaseImageNameNoExeSuff() if sBase is not None and sBase.lower() in [ 'msiexec', ]: reporter.log('Killing MSI process: %s (%s)' % (oProcess.iPid, sBase)) utils.processKill(oProcess.iPid) cKilled += 1 if cKilled > 0: time.sleep(16) # fudge. # Do the uninstalling. fRc = True sLogFile = os.path.join(self.sScratchPath, 'VBoxUninstallLog.txt') for sProdCode, sProdName in asProdCodes: reporter.log('Uninstalling %s (%s)...' % (sProdName, sProdCode)) fRc2, iRc = self._sudoExecuteSync([ 'msiexec', '/uninstall', sProdCode, '/quiet', '/passive', '/norestart', '/L*v', '%s' % (sLogFile), ]) if fRc2 is False: if iRc == 3010: # ERROR_SUCCESS_REBOOT_REQUIRED reporter.log( 'Note: Uninstaller required a reboot to complete uninstallation' ) # Optional, don't fail. else: fRc = False reporter.addLogFile(sLogFile, 'log/uninstaller', "Verbose MSI uninstallation log file") self._waitForTestManagerConnectivity(30) if fRc is False and os.path.isfile(sLogFile): reporter.addLogFile(sLogFile, 'log/uninstaller') return fRc
def _killAllVBoxProcesses(self): """ Kills all virtual box related processes we find in the system. """ sHostOs = utils.getHostOs() asDebuggers = [ 'cdb', 'windbg', ] if sHostOs == 'windows' else [ 'gdb', 'gdb-i386-apple-darwin', 'lldb' ] for iIteration in range(22): # Gather processes to kill. aoTodo = [] aoDebuggers = [] for oProcess in utils.processListAll(): sBase = oProcess.getBaseImageNameNoExeSuff() if sBase is None: continue sBase = sBase.lower() if sBase in [ 'vboxsvc', 'vboxsds', 'virtualbox', 'virtualboxvm', 'vboxheadless', 'vboxmanage', 'vboxsdl', 'vboxwebsrv', 'vboxautostart', 'vboxballoonctrl', 'vboxbfe', 'vboxextpackhelperapp', 'vboxnetdhcp', 'vboxnetnat', 'vboxnetadpctl', 'vboxtestogl', 'vboxtunctl', 'vboxvmmpreload', 'vboxxpcomipcd', ]: aoTodo.append(oProcess) if sBase.startswith('virtualbox-') and sBase.endswith( '-multiarch.exe'): aoTodo.append(oProcess) if sBase in asDebuggers: aoDebuggers.append(oProcess) if iIteration in [0, 21]: reporter.log('Warning: debugger running: %s (%s %s)' % (oProcess.iPid, sBase, oProcess.asArgs)) if not aoTodo: return True # Are any of the debugger processes hooked up to a VBox process? if sHostOs == 'windows': # On demand debugging windows: windbg -p <decimal-pid> -e <decimal-event> -g for oDebugger in aoDebuggers: for oProcess in aoTodo: # The whole command line is asArgs[0] here. Fix if that changes. if oDebugger.asArgs and oDebugger.asArgs[0].find( '-p %s ' % (oProcess.iPid, )) >= 0: aoTodo.append(oDebugger) break else: for oDebugger in aoDebuggers: for oProcess in aoTodo: # Simplistic approach: Just check for argument equaling our pid. if oDebugger.asArgs and ( '%s' % oProcess.iPid) in oDebugger.asArgs: aoTodo.append(oDebugger) break # Kill. for oProcess in aoTodo: reporter.log('Loop #%d - Killing %s (%s, uid=%s)' % ( iIteration, oProcess.iPid, oProcess.sImage if oProcess.sName is None else oProcess.sName, oProcess.iUid, )) if not utils.processKill(oProcess.iPid) \ and sHostOs != 'windows' \ and utils.processExists(oProcess.iPid): # Many of the vbox processes are initially set-uid-to-root and associated debuggers are running # via sudo, so we might not be able to kill them unless we sudo and use /bin/kill. try: utils.sudoProcessCall( ['/bin/kill', '-9', '%s' % (oProcess.iPid, )]) except: reporter.logXcpt() # Check if they're all dead like they should be. time.sleep(0.1) for oProcess in aoTodo: if utils.processExists(oProcess.iPid): time.sleep(2) break return False