def hasReceivedResponse(self, timeout=60.0): """ Waits to receive "response" event until the end of the timeout @param timeout: time max to wait to receive event in second (default=60s+10%) @type timeout: float @return: an event matching with the template or None otherwise @rtype: templatemessage """ TestAdapterLib.check_timeout(caller=TestAdapterLib.caller(), timeout=timeout) layer_win = templates.windows(event='response') evt = self.received(expected=self.encapsule(win_event=layer_win), timeout=self.__computeTimeout(timeout)) return evt
def getSystemInfo(self, timeout=60.0): """ Requests the host to get the complete system information @param timeout: max time to run command (default=60s) @type timeout: float """ cmd = { 'cmd': "systeminfo /S %s /FO CSV" % self.cfg['node'], 'get': GET_SYS_INFO, 'timeout': timeout } if self.logEventSent: layer_win = templates.windows(get=GET_SYS_INFO, event='request') self.logSentEvent(shortEvt="%s Request" % GET_SYS_INFO, tplEvt=self.encapsule(win_event=layer_win)) self.sendNotifyToAgent(data=cmd)
def execCommand(self, cmd, timeout=60.0): """ Execute the command passed on argument @param cmd: command to execute @type cmd: string @param timeout: max time to run command (default=60s) @type timeout: float """ cmd_ = {'cmd': cmd, 'get': EXEC_CMD, 'timeout': timeout} if self.logEventSent: layer_win = templates.windows(get=EXEC_CMD, event='request', cmd=cmd) self.logSentEvent(shortEvt="%s Request" % EXEC_CMD, tplEvt=self.encapsule(win_event=layer_win)) self.sendNotifyToAgent(data=cmd_)
def getDisks(self, timeout=60.0): """ Requests the host to get a list of all disks @param timeout: max time to run command (default=60s) @type timeout: float """ cmd = { 'cmd': "wmic /node:\"%s\" logicaldisk get Description, DeviceID, FileSystem, FreeSpace, Size /format:csv" % self.cfg['node'], 'get': GET_DISKS, 'timeout': timeout } if self.logEventSent: layer_win = templates.windows(get=GET_DISKS, event='request') self.logSentEvent(shortEvt="%s Request" % GET_DISKS, tplEvt=self.encapsule(win_event=layer_win)) self.sendNotifyToAgent(data=cmd)
def getMemUsage(self, timeout=60.0): """ Requests the host to get the memory usage @param timeout: max time to run command (default=60s) @type timeout: float """ __cmd__ = "wmic /node:%s ComputerSystem get TotalPhysicalMemory /format:csv" % self.cfg[ 'node'] __cmd__ += " && wmic /node:\"%s\" OS get FreePhysicalMemory /format:csv" % self.cfg[ 'node'] __cmd__ += " && wmic /node:\"%s\" OS get TotalVirtualMemorySize /format:csv" % self.cfg[ 'node'] __cmd__ += " && wmic /node:\"%s\" OS get FreeVirtualMemory/format:csv" % self.cfg[ 'node'] cmd = {'cmd': __cmd__, 'get': GET_MEM_USAGE, 'timeout': timeout} if self.logEventSent: layer_win = templates.windows(get=GET_MEM_USAGE, event='request') self.logSentEvent(shortEvt="%s Request" % GET_MEM_USAGE, tplEvt=self.encapsule(win_event=layer_win)) self.sendNotifyToAgent(data=cmd)
def getCpuLoad(self, timeout=60.0): """ Requests the host to get the cpu load @param timeout: max time to run command (default=60s) @type timeout: float """ cmd = { 'cmd': "wmic /node:\"%s\" cpu get DeviceID, loadpercentage /format:csv" % self.cfg['node'], 'get': GET_CPU_LOAD, 'timeout': timeout } if self.logEventSent: layer_win = templates.windows(get=GET_CPU_LOAD, event='request') self.logSentEvent(shortEvt="%s Request" % GET_CPU_LOAD, tplEvt=self.encapsule(win_event=layer_win)) self.sendNotifyToAgent(data=cmd)
def getUptime(self, timeout=60.0): """ Requests the host to get the uptime @param timeout: max time to run command (default=60s) @type timeout: float """ cmd = { 'cmd': "wmic /node:\"%s\" os get lastbootuptime /format:csv" % self.cfg['node'], 'get': GET_UPTIME, 'timeout': timeout } if self.logEventSent: layer_win = templates.windows(get=GET_UPTIME, event='request') self.logSentEvent(shortEvt="%s Request" % GET_UPTIME, tplEvt=self.encapsule(win_event=layer_win)) self.sendNotifyToAgent(data=cmd)
def getProcesses(self, timeout=60.0): """ Requests the host to get a list of all processes @param timeout: max time to run command (default=60s) @type timeout: float """ cmd = { 'cmd': "wmic /node:\"%s\" process get Processid,Caption,threadcount /format:csv" % self.cfg['node'], 'get': GET_PROCESSES, 'timeout': timeout } if self.logEventSent: layer_win = templates.windows(get=GET_PROCESSES, event='request') self.logSentEvent(shortEvt="%s Request" % GET_PROCESSES, tplEvt=self.encapsule(win_event=layer_win)) self.sendNotifyToAgent(data=cmd)
def getOs(self, timeout=60.0): """ Requests the host to get the version of the operating system @param timeout: max time to run command (default=60s) @type timeout: float """ cmd = { 'cmd': "wmic /node:\"%s\" os get buildnumber,caption /format:csv" % self.cfg['node'], 'get': GET_OS, 'timeout': timeout } if self.logEventSent: layer_win = templates.windows(get=GET_OS, event='request') self.logSentEvent(shortEvt="%s Request" % GET_OS, tplEvt=self.encapsule(win_event=layer_win)) self.sendNotifyToAgent(data=cmd)
def hasReceivedResponse(self, timeout=60.0): """ Waits to receive "response" event until the end of the timeout @param timeout: time max to wait to receive event in second (default=60s+10%) @type timeout: float @return: an event matching with the template or None otherwise @rtype: templatemessage """ if not (isinstance(timeout, int) or isinstance(timeout, float)) or isinstance(timeout, bool): raise TestAdapterLib.ValueException( TestAdapterLib.caller(), "timeout argument is not a float or integer (%s)" % type(timeout)) layer_win = templates.windows(event='response') evt = self.received(expected=self.encapsule(win_event=layer_win), timeout=self.__computeTimeout(timeout)) return evt