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 """ 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) ) 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 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
def areUp(self, urls, timeout=1.0): """ Check if the list of urls passed as argument are all up @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 up. @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.alive(), type=templates.url()) evt = self.received(expected=expected, timeout=timeout) if evt is None: ret = False return ret