Beispiel #1
0
	def isPartitions_for(self, timeout=2,partitions=None):
		"""
		Wait to receive response from "partitions_for" request and match returned Topics until the end of the timeout.
		@param timeout: time max to wait to receive event in second (default=2s)
		@type timeout: float		
		@param offset: Optional list that we expect to be view by producer 
		@type offset: list of of Topics
		"""
		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) )
		if partitions == None:
			partitions= { "partitions":TestOperatorsLib.Any()}
		expected = templates.kafka_ops(method=PARTITIONS_FOR,more=partitions)
		# try to match the template 
		evt = self.received( expected=self.encapsule( self.producerTpl ,expected), timeout=timeout )
		return evt		
Beispiel #2
0
	def isConnected(self, timeout=1.0):
		"""
		Waits to receive "connected" event until the end of the timeout
		
		@param timeout: time max to wait to receive event in second (default=1s)
		@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) )
		
		expected = templates.ssh(host=self.host, port=self.port, more=templates.connected() )
		evt = self.received( expected = expected, timeout = timeout )
		return evt
Beispiel #3
0
    def login(self, username, password, timeout=1.0):
        """
		Login to the catalyst
		
		@param username: telnet username
		@type username: string		
		
		@param password: telnet password
		@type password: string		
		
		@param timeout: time max to wait to receive event in second (default=1s)
		@type timeout: float		
		
		@return: True on success, False otherwise
		@rtype: boolean
		"""
        if not (isinstance(timeout, int)
                or isinstance(timeout, float)) or isinstance(timeout, bool):
            raise TestAdapter.ValueException(
                TestAdapter.caller(),
                "timeout argument is not a float or integer (%s)" %
                type(timeout))

        ret = None
        # username
        if not self.hasReceivedUsername(timeout=timeout):
            self.error('prompt login not detected')
            ret = False
        else:
            tpl = templates_catalyst.catalyst_username(data=username)
            self.sendCommand(tpl=tpl)

            # password
            if not self.hasReceivedPassword(timeout=timeout):
                self.error('prompt password not detected')
                ret = False
            else:
                tpl = templates_catalyst.catalyst_password(data=password)
                self.sendCommand(tpl=tpl)

                # prompt
                if not self.hasReceivedPrompt(timeout=timeout):
                    self.error('prompt not detected')
                    ret = False
                else:
                    ret = True
        return ret
Beispiel #4
0
	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
		"""
		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) )
		
		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
Beispiel #5
0
	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
		"""
		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) )
		
		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
Beispiel #6
0
    def doAreDown(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)

        return self.areDown(urls=urls, timeout=timeout)
Beispiel #7
0
    def hasReceivedResponse(self, timeout=1.0):
        """
		Waits to receive "response" event until the end of the timeout
		
		@param timeout: time max to wait to receive event in second (default=1s)
		@type timeout: float	

		@return: an event matching with the template or None otherwise
		@rtype: templatemessage		
		"""
        TestAdapterLib.check_timeout(caller=TestAdapterLib.caller(),
                                     timeout=timeout)

        layer_linux = templates.linux(event='response')
        evt = self.received(expected=self.encapsule(linux_event=layer_linux),
                            timeout=timeout)
        return evt
Beispiel #8
0
	def doAreDown(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 up.
		@rtype: boolean
		"""
		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) )
		
		return self.areDown(hosts=hosts, timeout=timeout)
Beispiel #9
0
    def isStopped(self,
                  timeout=1.0,
                  versionIp=None,
                  sourceIp=None,
                  destinationIp=None,
                  sourcePort=None,
                  destinationPort=None):
        """
		Wait to receive "stopped" event until the end of the timeout
		
		@param timeout: time max to wait to receive event in second (default=1s)
		@type timeout: float		

		@param versionIp: version ip expected
		@type versionIp: string/operators/none	

		@param sourceIp: source ip expected
		@type sourceIp:	string/operators/none	
		
		@param destinationIp: destination ip expected
		@type destinationIp: string/operators/none	
		
		@param sourcePort: source port expected
		@type sourcePort:	string/operators/none
		
		@param destinationPort: destination port expected
		@type destinationPort: string/operators/none	
		
		@return: an event matching with the template or None otherwise
		@rtype: templatemessage		
		"""
        TestAdapterLib.check_timeout(caller=TestAdapterLib.caller(),
                                     timeout=timeout)

        # construct the expected template
        tpl = templates.stopped()
        expected = self.getExpectedTemplate(tpl=tpl,
                                            versionIp=versionIp,
                                            sourceIp=sourceIp,
                                            destinationIp=destinationIp,
                                            sourcePort=sourcePort,
                                            destinationPort=destinationPort)

        # try to match the template
        evt = self.received(expected=expected, timeout=timeout)
        return evt
	def doDisconnect(self, timeout=1.0):
		"""
		Do disconnect

		@param timeout: time max to wait to receive event in second (default=1s)
		@type timeout: float			
		
		@return: True is successfully disconnected, false otherwise
		@rtype: boolean			
		"""
		TestAdapterLib.check_timeout(caller=TestAdapterLib.caller(), timeout=timeout)
		
		ret = True
		self.disconnect()
		if self.isDisconnected(timeout=timeout) is None:
			ret = False
		return ret
Beispiel #11
0
	def doAreDown(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
		"""
		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) )
		
		return self.areDown(urls=urls, timeout=timeout)
Beispiel #12
0
    def doAreDown(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 up.
		@rtype: boolean
		"""
        TestAdapterLib.check_timeout(caller=TestAdapterLib.caller(),
                                     timeout=timeout)

        return self.areDown(hosts=hosts, timeout=timeout)
Beispiel #13
0
    def hasReceivedHttpResponse(self,
                                httpCode=None,
                                httpPhrase=None,
                                httpVersion=None,
                                httpHeaders=None,
                                httpBody=None,
                                timeout=1.0):
        """
		Wait to receive "http response" until the end of the timeout.

		@param httpCode: http code (default=200)
		@type httpCode: string

		@param httpPhrase: http phrase (default=OK)
		@type httpPhrase: string

		@param httpVersion: http version (default=HTTP/1.1)
		@type httpVersion: string

		@param httpHeaders: expected http headers
		@type httpHeaders: dict

		@param httpBody: expected body (default=None)
		@type httpBody: string/none
		
		@param timeout: time to wait in seconds (default=1s)
		@type timeout: float
		
		@return: http response
		@rtype:	   template	  
		"""
        TestAdapterLib.check_timeout(caller=TestAdapterLib.caller(),
                                     timeout=timeout)

        tpl_expected = TestTemplates.TemplateMessage()
        layer_curl = curl_templates.response(version=httpVersion,
                                             code=httpCode,
                                             phrase=httpPhrase,
                                             headers=httpHeaders,
                                             body=httpBody)
        tpl_expected.addLayer(layer_curl)

        evt = self.received(expected=tpl_expected, timeout=timeout)
        if evt is None:
            return None
        return evt
Beispiel #14
0
	def isSend(self, timeout=2, record=None):
		"""
		Wait to receive response from "send" request and match returned RecordMetadata  until the end of the timeout.
		@param timeout: time max to wait to receive event in second (default=2s)
		@type timeout: float		
		@param offset: Optional RecordMetadata that we expect to be assigned to consumer 
		@type offset:  RecordMetadata
		"""
		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) )
		
		if record == None:
			record = { "Topic":TestOperatorsLib.Any(), "Partition": TestOperatorsLib.Any(), "Offset":TestOperatorsLib.Any() , "Timestamp":TestOperatorsLib.Any() ,"Checksum": TestOperatorsLib.Any(), "Serialized_key_size":TestOperatorsLib.Any(), "Serialized_value_size": TestOperatorsLib.Any()}
		expected = templates.kafka_ops(method=SEND, more=record)
		# try to match the template 
		evt = self.received( expected=self.encapsule( self.producerTpl ,expected ), timeout=timeout )
		return evt
Beispiel #15
0
	def hasReceivedPacket(self, timeout=1.0, dstIp=None, srcIp=None, srcPort=None, dstPort=None, data=None, 
												controlBits=None):
		"""
		Waits to receive "data" event until the end of the timeout
		
		@param timeout: time max to wait to receive event in second (default=1s)
		@type timeout: float
		
		@param dstIp: destination ip
		@type dstIp: none/string/operators
		
		@param srcIp: source ip
		@type srcIp: none/string/operators
		
		@param srcPort: source port
		@type srcPort: none/integer/operators

		@param dstPort: destination port
		@type dstPort: none/integer/operators
		
		@param data: upper data
		@type data: none/string/operators
		
		@param controlBits: control bits
		@type controlBits: none/string/operators

		@return: an event matching with the template or None otherwise
		@rtype: templatemessage
		"""
		TestAdapterLib.check_timeout(caller=TestAdapterLib.caller(), timeout=timeout)
		
		# prepare the expected template
		ether_tpl = AdapterEthernet.ethernet()
		expected = self.encapsule(layer=ether_tpl)
		
		ip_tpl = AdapterIP.ip(source=srcIp, destination=dstIp)
		expected.addLayer(ip_tpl)
		
		tcp_tpl = templates.tcp(source=srcPort, destination=dstPort, control_bits=controlBits)
		expected.addLayer(tcp_tpl)
		# wait 
		evt = self.received( expected = expected, timeout = timeout )
		if evt is None:
			return None
		return evt
Beispiel #16
0
	def sendData(self, tpl, dataRaw=None, optionsRaw=None):
		"""
		Send telnet data

		@param tpl: telnet
		@type tpl: templatelayer

		@param dataRaw: telnet data (default=None)
		@type dataRaw: string/none
		
		@param optionsRaw: telnet options (default=None)
		@type optionsRaw: string/none

		@return: telnet layer encapsulate in ip
		@rtype: templatemessage		
		"""
		if not self.tcp.connected:
			#raise Exception( 'tcp not connected' )
			raise TestAdapterLib.AdapterException(TestAdapterLib.caller(),  "tcp not connected" )
				
		try:
			if dataRaw is not None or optionsRaw is not None:
				tpl = templates.telnet(data=dataRaw, cmds=optionsRaw)
			# encode template
			try:
				(encodedData, summary) = self.telnetCodec.encode(telnet_tpl=tpl)
			except Exception as e:
				raise Exception("Cannot encode Telnet message: %s" % str(e))	
					
			try:
				lower = self.tcp.sendData( data=encodedData )
			except Exception as e:
				raise Exception("telnet failed: %s" % str(e))	
			
			# add sip layer to the lower layer
			tpl.addRaw( encodedData )
			lower.addLayer( tpl )
			
			# Log event
			if self.logEventSent:
				self.logSentEvent( shortEvt = summary, tplEvt = lower ) 
		except Exception as e:
			raise Exception('Unable to send telnet data: %s' % str(e))
			
		return lower	
Beispiel #17
0
    def hasReceivedHttpResponse(self,
                                httpCode="200",
                                httpPhrase="OK",
                                headers=None,
                                timeout=1.0):
        """
		Wait to receive "http response" until the end of the timeout.
		
		@param httpCode: http code (default=200)
		@type httpCode: string
		
		@param httpPhrase: http phrase (default=OK)
		@type httpPhrase: string
		
		@param timeout: time to wait in seconds (default=1s)
		@type timeout: float
	
		@return: http response
		@rtype:	template	
		"""
        if not (isinstance(timeout, int) or isinstance(timeout, float)):
            raise TestAdapterLib.ValueException(
                TestAdapterLib.caller(),
                "timeout argument is not a float or integer (%s)" %
                type(timeout))

        tpl = TestTemplatesLib.TemplateMessage()

        if self.cfg['agent-support']:
            layer_agent = TestTemplatesLib.TemplateLayer('AGENT')
            layer_agent.addKey(name='name', data=self.cfg['agent']['name'])
            layer_agent.addKey(name='type', data=self.cfg['agent']['type'])
            tpl.addLayer(layer_agent)

        tpl.addLayer(AdapterIP.ip(more=AdapterIP.received()))
        tpl.addLayer(AdapterTCP.tcp(more=AdapterTCP.received()))
        if self.ADP_HTTP.tcp().cfg['ssl-support']:
            tpl.addLayer(AdapterSSL.ssl(more=AdapterSSL.received()))
        tpl.addLayer(
            AdapterHTTP.response(version="HTTP/1.1",
                                 code=httpCode,
                                 phrase=httpPhrase,
                                 headers=headers))

        return self.hasReceivedResponse(expected=tpl, timeout=timeout)
Beispiel #18
0
    def sendBinary(self, data):
        """
		Send binary data
		
		@param data: data to send
		@type data: string
		"""
        if not self.wsHanshakeSuccess:
            return

        # make chunk
        chunks = [
            data[x:x + self.wsMaxPayloadSize]
            for x in xrange(0, len(data), self.wsMaxPayloadSize)
        ]

        # encode data in the websocket packet and enqueue it
        for chunk in chunks:
            ws_tpl = templates.ws(fin=1,
                                  mask=0,
                                  rsv1=0,
                                  rsv2=0,
                                  rsv3=0,
                                  opcode=codec.WEBSOCKET_OPCODE_BINARY,
                                  data=chunk,
                                  data_length=len(chunk),
                                  more=templates.sent())
            wsdata = self.wsCodec.encodeWsData(tpl=ws_tpl)

            # Send websocket data
            try:
                lower = self.ADP_HTTP.tcp().sendData(data=wsdata)
            except Exception as e:
                #raise Exception("send request: tcp failed: %s" % str(e))
                raise TestAdapterLib.AdapterException(
                    TestAdapterLib.caller(),
                    "send request: tcp failed: %s" % str(e))

            lower.addLayer(ws_tpl)

            # Log event
            if self.logEventSent:
                lower.addRaw(raw=wsdata)
                self.logSentEvent(shortEvt=codec.WEBSOCKET_OPCODE_BINARY_STR,
                                  tplEvt=lower)
Beispiel #19
0
    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
Beispiel #20
0
	def isPartitions_for(self, timeout=2,partitions=None):
		"""
		Wait to receive response from "partitions_for" request and match returned Topics until the end of the timeout.

		@param timeout: time max to wait to receive event in second (default=2s)
		@type timeout: float		

		@param offset: Optional list that we expect to be view by producer 
		@type offset: list of of Topics
		"""
		TestAdapterLib.check_timeout(caller=TestAdapterLib.caller(), timeout=timeout)

		if partitions == None:
			partitions= { "partitions":TestOperatorsLib.Any()}
		expected = templates.kafka_ops(method=PARTITIONS_FOR,more=partitions)
		# try to match the template 
		evt = self.received( expected=self.encapsule( self.producerTpl ,expected), timeout=timeout )
		return evt	
	def isTerminated(self, timeout=1.0, nbRow=None):
		"""
		Waits to receive "terminated" event until the end of the timeout
		
		@param timeout: time max to wait to receive event in second (default=1s)
		@type timeout: float		
		
		@param nbRow: number of row received
		@type nbRow: string/none			
		
		@return: an event matching with the template or None otherwise
		@rtype: templatemessage
		"""
		TestAdapterLib.check_timeout(caller=TestAdapterLib.caller(), timeout=timeout)
		
		expected = templates.db(host=self.cfg['host'], port=self.cfg['port'], more=templates.terminated(nbRow=nbRow) )
		evt = self.received( expected = self.encapsule(db_event=expected), timeout = timeout )
		return evt
    def isStopped(self, timeout=1.0):
        """
		Wait to receive "stopped" event until the end of the timeout
		
		@param timeout: time max to wait to receive event in second (default=1s)
		@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))

        return self.ADP_UDP.isStopped(timeout=timeout)
Beispiel #23
0
    def doCommand(self, cmd, timeout=1.0):
        """
		Execute the command passed on argument and wait the reponse until the end of the timeout
		
		@param cmd: command to execute
		@type cmd: string		
		
		@param timeout: time max to wait to receive event in second (default=1s)
		@type timeout: float	

		@return: an event matching with the template or None otherwise
		@rtype: templatemessage	
		"""
        TestAdapterLib.check_timeout(caller=TestAdapterLib.caller(),
                                     timeout=timeout)

        self.execCommand(cmd=cmd)
        return self.hasReceivedResponse(timeout=timeout)
Beispiel #24
0
    def isClosed(self, timeout=10.0):
        """
		Waits to receive "closed" event until the end of the timeout

		@param timeout: time max to wait to receive event in second (default=10s)
		@type timeout: float			

		@return: an event matching with the template or None otherwise
		@rtype: templatemessage	
		"""
        TestAdapter.check_timeout(caller=TestAdapter.caller(), timeout=timeout)

        # construct the expected template
        expected = self.getExpectedTemplate(event=templates_term.term_closed())

        # try to match the template
        evt = self.received(expected=expected, timeout=timeout)
        return evt
    def isDisconnected(self, timeout=1.0):
        """
		is disconnected from the soap service

		@param timeout: time to wait in seconds (default=1s)
		@type timeout: float

		@return: event if disconnected
		@rtype:	template	
		"""
        if not (isinstance(timeout, int)
                or isinstance(timeout, float)) or isinstance(timeout, bool):
            raise TestAdapter.ValueException(
                TestAdapter.caller(),
                "timeout argument is not a float or integer (%s)" %
                type(timeout))

        return self.ADP_SOAP.isDisconnected(timeout=timeout)
Beispiel #26
0
	def doDisconnect(self, timeout=1.0):
		"""
		Do disconnect

		@param timeout: time max to wait to receive event in second (default=1s)
		@type timeout: float			
		
		@return: True is successfully disconnected, false otherwise
		@rtype: boolean	
		"""
		if not ( isinstance(timeout, int) or isinstance(timeout, float) ) or isinstance(timeout,bool): 
			raise TestAdapter.ValueException(TestAdapter.caller(), "timeout argument is not a float or integer (%s)" % type(timeout) )
		
		ret = True
		self.disconnect()
		if self.isDisconnected(timeout=timeout) is None:
			ret = False
		return ret
Beispiel #27
0
    def isDisconnected(self, timeout=1.0):
        """
		Is Disconnected

		@param timeout: time max to wait to receive event in second (default=1s)
		@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 TestAdapter.ValueException(
                TestAdapter.caller(),
                "timeout argument is not a float or integer (%s)" %
                type(timeout))

        return self.ADP_TRANSPORT.isDisconnected(timeout=timeout)
	def __init__(self, parent, name=None, debug=False, bindIp = '', bindPort=0,
								logEventReceived=True, agentSupport=False, agent=None, shared=False,
								):
		"""
		SNMP trap receiver v1 and v2c

		@param parent: parent testcase
		@type parent: testcase

		@param name: adapter name used with from origin/to destination (default=None)
		@type name: string/none

		@param debug: active debug mode (default=False)
		@type debug:	boolean

		@param bindIp: bind on ip (source ip)
		@type bindIp: string

		@param bindPort: bind on port (source port)
		@type bindPort: integer
		
		@param agentSupport: agent support to use a remote socket (default=False)
		@type agentSupport: boolean

		@param agent: agent to use when this mode is activated
		@type agent: string/none
		
		@param shared: shared adapter (default=False)
		@type shared:	boolean
		"""
		# init adapter
		TestAdapterLib.Adapter.__init__(self, name = __NAME__, parent = parent, debug=debug, 
																									realname=name, shared=shared,
																									agentSupport=agentSupport, agent=agent,
																									caller=TestAdapterLib.caller(),
																									agentType=AGENT_TYPE_EXPECTED)
		self.codecX2D = Xml2Dict.Xml2Dict()
		self.codecD2X = Dict2Xml.Dict2Xml(coding = None)
		self.logEventReceived = logEventReceived

		# init udp layer
		self.ADP_UDP = AdapterUDP.Client(parent=parent, debug=debug, name=name, 
											bindIp = bindIp, bindPort=bindPort, 
											destinationIp='', destinationPort=0,  destinationHost='', 
											socketFamily=AdapterIP.IPv4, separatorDisabled=True, inactivityTimeout=0,
											logEventSent=False, logEventReceived=False, parentName=__NAME__, agentSupport=agentSupport,
											agent=agent, shared=shared)
		
		# callback udp
		self.ADP_UDP.handleIncomingData = self.onIncomingData

		self.cfg = {}
		self.cfg['agent-support'] = agentSupport
		if agentSupport:
			self.cfg['agent'] = agent
			self.cfg['agent-name'] = agent['name']
		self.__checkConfig()
Beispiel #29
0
    def isLoginFailed(self, timeout=1.0):
        """
		Waits to receive "login failed" event until the end of the timeout
		
		@param timeout: time max to wait to receive event in second (default=1s)
		@type timeout: float			
		
		@return: an event matching with the template or None otherwise
		@rtype: templatemessage
		"""
        TestAdapterLib.check_timeout(caller=TestAdapterLib.caller(),
                                     timeout=timeout)

        expected = templates.ssh(host=self.host,
                                 port=self.port,
                                 more=templates.login_failed())
        evt = self.received(expected=expected, timeout=timeout)
        return evt
Beispiel #30
0
	def __init__(self, parent, debug=False, name=None, ipVersion=AdapterIP.IPv4, version=sniffer.ICMPv4, shared=False, 
											agentSupport=False, agent=None ):
		"""
		This class enables to send ping request
		The lower layer is based on the ICMP adapter.
	
		@param parent: parent testcase
		@type parent: testcase

		@param name: adapter name used with from origin/to destination (default=None)
		@type name: string/none
		
		@param debug: active debug mode (default=False)
		@type debug:	boolean
		
		@param ipVersion: SutAdapters.IP.IPv4 (default) | SutAdapters.IP.IPv6
		@type ipVersion: intconstant	
		
		@param version: SutAdapters.ICMP.ICMPv4 (default) | SutAdapters.ICMP.ICMPv6
		@type version: intconstant	
		
		@param shared: shared adapter (default=False)
		@type shared:	boolean		

		@param agentSupport: agent support to use a remote socket (default=False)
		@type agentSupport: boolean

		@param agent: agent to use when this mode is activated
		@type agent: string/None
		"""	
		# check agent
		if agentSupport and agent is None:
			raise TestAdapterLib.ValueException(TestAdapterLib.caller(), "Agent cannot be undefined!" )	
			
		if agentSupport:
			if not isinstance(agent, dict) : 
				raise TestAdapterLib.ValueException(TestAdapterLib.caller(), "agent argument is not a dict (%s)" % type(agent) )
			if not len(agent['name']): 
				raise TestAdapterLib.ValueException(TestAdapterLib.caller(), "agent name cannot be empty" )
			if  unicode(agent['type']) != unicode(AGENT_TYPE_EXPECTED): 
				raise TestAdapterLib.ValueException(TestAdapterLib.caller(), 'Bad agent type: %s, expected: %s' % (agent['type'], unicode(AGENT_TYPE_EXPECTED))  )
				
		# init adapter
		TestAdapterLib.Adapter.__init__(self, name = __NAME__, parent = parent, debug=debug, shared=shared, 
																			realname=name, agentSupport=agentSupport, agent=agent)
		self.icmp = sniffer.SnifferV4(parent=parent, debug=debug, logEventSent=True, logEventReceived=True,
																				shared=shared, agentSupport=agentSupport, agent=agent )
		
		self.cfg = {}
		self.cfg['agent-support'] = agentSupport
		if agentSupport:
			self.cfg['agent'] = agent
			self.cfg['agent-name'] = agent['name']
		self.__checkConfig()