def isDown(self, url, timeout=1.0): """ Check if the url passed as argument is down @param url: url without http(s):// @type url: string @param timeout: time to wait in second (default=1s) @type timeout: float @return: no response event @rtype: templatemessage """ TestAdapterLib.check_timeout(caller=TestAdapterLib.caller(), timeout=timeout) tpl = templates.pinger(destination=url, more=templates.ping(), type=templates.url() ) self.logSentEvent( shortEvt = "ping", tplEvt = tpl ) pa = UrlAgent(self, url, self.method, self.credentials, self.https, self.timeout) pa.start() # synchronization pa.join() if pa.rspCodeReceived is not None: tpl = templates.pinger(destination=url, more=templates.alive(), type=templates.url(code=pa.rspCodeReceived,body=pa.rspBodyReceived) ) self.logRecvEvent( shortEvt = "alive", tplEvt = tpl ) else: tpl = templates.pinger(destination=url, more=templates.no_response(), type=templates.url() ) self.logRecvEvent( shortEvt = "no response", tplEvt = tpl ) expected = templates.pinger(destination=url, more=templates.no_response(), type=templates.url() ) evt = self.received( expected = expected, timeout = timeout ) return evt
def isDown(self, host, timeout=1.0): """ Check if the host passed as argument is down. This check takes approximately 3 sec. @param host: IPv4 or hostname @type host: string @param timeout: time to wait in second (default=1s) @type timeout: float @return: no response event @rtype: templatemessage """ TestAdapterLib.check_timeout(caller=TestAdapterLib.caller(), timeout=timeout) tpl = templates.pinger(destination=host, more=templates.ping(), type=templates.tcp(destination=self.destPort) ) self.logSentEvent( shortEvt = "ping", tplEvt = tpl ) pa = TcpPingAgent(self, host, self.destPort, self.nbSyn) pa.start() # synchronization pa.join() ret= pa.isup if ret: tpl = templates.pinger(destination=host, more=templates.alive(), type=templates.tcp(destination=self.destPort) ) self.logRecvEvent( shortEvt = "alive", tplEvt = tpl ) else: tpl = templates.pinger(destination=host, more=templates.no_response(), type=templates.tcp(destination=self.destPort) ) self.logRecvEvent( shortEvt = "no response", tplEvt = tpl ) expected = templates.pinger(destination=host, more=templates.no_response(), type=templates.tcp(destination=self.destPort) ) evt = self.received( expected = expected, timeout = timeout ) return evt
def areDown(self, hosts, timeout=1.0): """ Check if all hosts passed as argument are down. This check takes approximately 10 sec. @param hosts: list of IPv4 or hostname @type hosts: list @param timeout: time to wait in second (default=1s) @type timeout: float @return: True if all hosts are down, False otherwise @rtype: boolean """ TestAdapterLib.check_timeout(caller=TestAdapterLib.caller(), timeout=timeout) th = [] # parallelize for i in xrange(len(hosts)): tpl = templates.pinger(destination=hosts[i], more=templates.ping(), type=templates.icmp()) self.logSentEvent(shortEvt="ping", tplEvt=tpl) pa = PingAgent(self, hosts[i], self.nbPing) pa.start() th.append(pa) # synchronize for pa in th: pa.join() # compute final result ret = True for pa in th: if pa.isup: tpl = templates.pinger(destination=pa.host, more=templates.alive(), type=templates.icmp()) self.logRecvEvent(shortEvt="alive", tplEvt=tpl) else: tpl = templates.pinger(destination=pa.host, more=templates.no_response(), type=templates.icmp()) self.logRecvEvent(shortEvt="no response", tplEvt=tpl) expected = templates.pinger(destination=pa.host, more=templates.no_response(), type=templates.icmp()) evt = self.received(expected=expected, timeout=timeout) if evt is None: ret = False return ret
def portsAreDown(self, host, ports, timeout=1.0): """ Check if all ports passed as argument are down for one specific host. This check takes approximately 3 sec. @param host: IPv4 or hostname @type host: string @param ports: list of port @type ports: list @param timeout: time to wait in second (default=1s) @type timeout: float @return: global status, True if all ports are down. @rtype: boolean """ TestAdapterLib.check_timeout(caller=TestAdapterLib.caller(), timeout=timeout) th = [] # parallelize for tcpPort in ports: tpl = templates.pinger(destination=host, more=templates.ping(), type=templates.tcp(destination=tcpPort) ) self.logSentEvent( shortEvt = "ping", tplEvt = tpl ) pa = TcpPingAgent(self, host, tcpPort, self.nbSyn) pa.start() th.append(pa) # synchronize for pa in th: pa.join() # compute final result ret = True for pa in th: if pa.isup: ret = False tpl = templates.pinger(destination=pa.host, more=templates.alive(), type=templates.tcp(destination=pa.destPort) ) self.logRecvEvent( shortEvt = "alive", tplEvt = tpl ) else: tpl = templates.pinger(destination=pa.host, more=templates.no_response(), type=templates.tcp(destination=pa.destPort) ) self.logRecvEvent( shortEvt = "no response", tplEvt = tpl ) expected = templates.pinger(destination=pa.host, more=templates.no_response(), type=templates.tcp(destination=pa.destPort) ) evt = self.received( expected = expected, timeout = timeout ) if evt is None: ret = False return ret
def areDown(self, urls, timeout=1.0): """ Check if the list of urls passed as argument are all down @param urls: list of url without http(s):// @type urls: list @param timeout: time to wait in second (default=1s) @type timeout: float @return: global status, True if all urls are down. @rtype: boolean """ TestAdapterLib.check_timeout(caller=TestAdapterLib.caller(), timeout=timeout) th = [] # parallelize for i in xrange(len(urls)): tpl = templates.pinger(destination=urls[i], more=templates.ping(), type=templates.url() ) self.logSentEvent( shortEvt = "ping", tplEvt = tpl ) pa = UrlAgent(self, urls[i], self.method, self.credentials, self.https, self.timeout ) pa.start() th.append(pa) # synchronize for pa in th: pa.join() # compute final result ret = True for pa in th: if pa.rspCodeReceived is not None: tpl = templates.pinger(destination=pa.url, more=templates.alive(), type=templates.url(code=pa.rspCodeReceived,body=pa.rspBodyReceived) ) self.logRecvEvent( shortEvt = "alive", tplEvt = tpl ) else: tpl = templates.pinger(destination=pa.url, more=templates.no_response(), type=templates.url() ) self.logRecvEvent( shortEvt = "no response", tplEvt = tpl ) expected = templates.pinger(destination=pa.url, more=templates.no_response(), type=templates.url() ) evt = self.received( expected = expected, timeout = timeout ) if evt is None: ret = False return ret
def isUp(self, url, timeout=1.0, codeExpected=None, bodyExpected=None): """ Check if the url passed as argument is up @param url: url without http(s):// @type url: string @param timeout: time to wait in second (default value=1s) @type timeout: float @param codeExpected: expected http response code from the remote (default=None) @type codeExpected: string/operators/none @param bodyExpected: string expected in the body (default=None) @type bodyExpected: string/operators/none @return: alive event @rtype: templatemessage """ TestAdapterLib.check_timeout(caller=TestAdapterLib.caller(), timeout=timeout) responseCode = self.responseCode responseBody = self.responseBody if codeExpected is not None: responseCode = int(codeExpected) if bodyExpected is not None: responseBody = bodyExpected tpl = templates.pinger(destination=url, more=templates.ping(), type=templates.url() ) self.logSentEvent( shortEvt = "ping", tplEvt = tpl ) pa = UrlAgent(self, url, self.method, self.credentials, self.https, self.timeout ) pa.start() # synchronization pa.join() if pa.rspCodeReceived is not None: tpl = templates.pinger(destination=url, more=templates.alive(), type=templates.url(code=pa.rspCodeReceived,body=pa.rspBodyReceived) ) self.logRecvEvent( shortEvt = "alive", tplEvt = tpl ) else: tpl = templates.pinger(destination=url, more=templates.no_response(), type=templates.url() ) self.logRecvEvent( shortEvt = "no response", tplEvt = tpl ) expected = templates.pinger(destination=url, more=templates.alive(), type=templates.url(code=str(responseCode),body=responseBody) ) evt = self.received( expected = expected, timeout = timeout ) return evt