def __init__(self, testResult='', testHeader=''): """ This class describes the model of the test result document, and provides a xml <=> python encoder The following xml : <?xml version="1.0" encoding="utf-8" ?> <file> <properties"> <comments> <comment> <author>author</author> <datetime>...</datetime> <post>...</post> </comment> .... </comments> </properties> <testheader>...</testheader> <testresult>...</testresult> </file> """ today = datetime.date.today() # self.codecX2D = PyXmlDict.Xml2Dict() self.codecD2X = PyDictXml.Dict2Xml(coding=None) # self.properties = {'properties': {'comments': {'comment': []}}} self.testresult = testResult self.testheader = testHeader
def __init__ (self, userName='******', timeout="10.0", parameters=[]): """ This class describes the model of one script document, and provides a xml <=> python encoder The following xml : <?xml version="1.0" encoding="utf-8" ?> <file> <properties"> <parameters> <parameter> <name>...</name> <type>...</type> <description>...</description> <value>...</value> </parameter> </parameters> </properties> </file> """ GenericModel.GenericModel.__init__(self) # init xml encoder self.codecX2D = PyXmlDict.Xml2Dict( ) self.codecD2X = PyDictXml.Dict2Xml( coding = None ) # init file properties self.properties = { 'properties': { 'parameters': { 'parameter': [ {'type': 'bool', 'name': 'DEBUG', 'description': '', 'value' : 'False', 'color': '' }, {'type': 'float', 'name': 'TIMEOUT', 'description': '', 'value' : timeout, 'color': '' } ] } } } if len(parameters): self.properties["properties"]["parameters"]["parameter"] = parameters
def __init__(self, parent, debug=False, coding='UTF-8', name=None, shared=False): """ XML coder-decoder to object @param parent: testcase @type parent: testcase @param name: library name used with from origin/to destination (default=None) @type name: string/none @param debug: True to activate debug mode (default=False) @type debug: boolean @param coding: expected value in UTF-8, ISO, etc ... @type coding: string @param shared: shared adapter (default=False) @type shared: boolean """ TestLibraryLib.Library.__init__(self, name=__NAME__, parent=parent, debug=debug, realname=name, shared=shared) self.codecX2D = Xml2Dict.Xml2Dict() self.codecD2X = Dict2Xml.Dict2Xml(coding=coding) self.rootXML = None self.ns = {}
def __init__(self, parent, name=None, debug=False, proxyType=PROXY_SOCKS4, verbose=True): """ Socks adapter (Socket Secure) version 4 and 5 (rfc1928) https://www.ietf.org/rfc/rfc1928.txt http://tools.ietf.org/html/rfc1929 @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 """ TestAdapterLib.Adapter.__init__(self, name = __NAME__, parent = parent, debug=debug, realname=name, showEvts=verbose, showSentEvts=verbose, showRecvEvts=verbose) self.codecX2D = Xml2Dict.Xml2Dict() self.codecD2X = Dict2Xml.Dict2Xml(coding = None) self.cfg = {} self.cfg['proxy-type'] = proxyType self.__checkConfig() self.sockCodec4 = codec4.Codec(parent=self, testcase=parent, debug=debug) self.sockCodec5 = codec5.Codec(parent=self, testcase=parent, debug=debug)
def __init__(self, parent, name=None, debug=False, shared=False, agentSupport=False, agent=None, logEventSent=True, logEventReceived=True): """ Nmap wrapper @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 shared: shared adapter (default=False) @type shared: boolean @param agentSupport: agent support (default=False) @type agentSupport: boolean @param agent: agent to use (default=None) @type agent: string/none """ # check the agent if agentSupport and agent is None: raise TestAdapter.ValueException(TestAdapter.caller(), "Agent cannot be undefined!" ) if agentSupport: if not isinstance(agent, dict) : raise TestAdapter.ValueException(TestAdapter.caller(), "agent argument is not a dict (%s)" % type(agent) ) if not len(agent['name']): raise TestAdapter.ValueException(TestAdapter.caller(), "agent name cannot be empty" ) if unicode(agent['type']) != unicode(AGENT_TYPE_EXPECTED): raise TestAdapter.ValueException(TestAdapter.caller(), 'Bad agent type: %s, expected: %s' % (agent['type'], unicode(AGENT_TYPE_EXPECTED)) ) TestAdapter.Adapter.__init__(self, name = __NAME__, parent = parent, debug=debug, realname=name, agentSupport=agentSupport, agent=agent, shared=shared) self.parent = parent self.logEventSent = logEventSent self.logEventReceived = logEventReceived self.codecX2D = Xml2Dict.Xml2Dict() self.codecD2X = Dict2Xml.Dict2Xml(coding = None) self.cfg = {} if agent is not None: self.cfg['agent'] = agent self.cfg['agent-name'] = agent['name'] self.cfg['agent-support'] = agentSupport self.TIMER_ALIVE_AGT = TestAdapter.Timer(parent=self, duration=20, name="keepalive-agent", callback=self.aliveAgent, logEvent=False, enabled=True) self.__checkConfig() # initialize the agent with no data if agent is not None: if self.cfg['agent-support']: self.prepareAgent(data={'shared': shared}) if self.agentIsReady(timeout=30) is None: raise Exception("Agent %s is not ready" % self.cfg['agent-name'] ) self.TIMER_ALIVE_AGT.start()
def __init__(self, parent, agent, name=None, debug=False, shared=False): """ SoapUI adapter @param parent: parent testcase @type parent: testcase @param agent: agent to use @type agent: string @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 shared: shared adapter (default=False) @type shared: boolean """ # check the agent if not isinstance(agent, dict) : raise TestAdapter.ValueException(TestAdapter.caller(), "agent argument is not a dict (%s)" % type(agent) ) if not len(agent['name']): raise TestAdapter.ValueException(TestAdapter.caller(), "agent name cannot be empty" ) if unicode(agent['type']) != unicode(AGENT_TYPE_EXPECTED): raise TestAdapter.ValueException(TestAdapter.caller(), 'Bad agent type: %s, expected: %s' % (agent['type'], unicode(AGENT_TYPE_EXPECTED)) ) TestAdapter.Adapter.__init__(self, name = __NAME__, parent = parent, debug=debug, realname=name) self.parent = parent self.codecX2D = Xml2Dict.Xml2Dict() self.codecD2X = Dict2Xml.Dict2Xml(coding = None) self.curStepName = '' self.stepId = 0 self.currentStep = None self.threads_list = [] self.cfg = {} self.cfg['agent'] = agent self.cfg['agent-support'] = True self.cfg['agent-name'] = agent['name'] self.cfg['soapui-options'] = [ "-r", "-I" ] # -a Turns on exporting of all results # -r Prints a small summary report # -j Sets the output to include JUnit XML reports # -I Do not stop if error occurs, ignore them self.TIMER_ALIVE_AGT = TestAdapter.Timer(parent=self, duration=20, name="keepalive-agent", callback=self.aliveAgent, logEvent=False, enabled=True) self.__checkConfig() # initialize the agent with no data self.initAgent(data={}) if self.agentIsReady(timeout=10) is None: raise TestAdapter.ValueException(TestAdapter.caller(), "Agent %s is not ready" % self.cfg['agent-name'] ) self.TIMER_ALIVE_AGT.start()
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()
def __init__(self, parent, name=None, debug=False, shared=False, agentSupport=False, agent=None, logEventSent=True, logEventReceived=True): """ Curl wrapper @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 shared: shared adapter (default=False) @type shared: boolean @param agentSupport: agent support (default=False) @type agentSupport: boolean @param agent: agent to use (default=None) @type agent: string/none """ TestAdapter.Adapter.__init__(self, name = __NAME__, parent = parent, debug=debug, realname=name, agentSupport=agentSupport, agent=agent, shared=shared, caller=TestAdapter.caller(), agentType=AGENT_TYPE_EXPECTED) self.parent = parent self.logEventSent = logEventSent self.logEventReceived = logEventReceived self.codecX2D = Xml2Dict.Xml2Dict() self.codecD2X = Dict2Xml.Dict2Xml(coding = None) self.cfg = {} if agent is not None: self.cfg['agent'] = agent self.cfg['agent-name'] = agent['name'] self.cfg['agent-support'] = agentSupport self.TIMER_ALIVE_AGT = TestAdapter.Timer(parent=self, duration=20, name="keepalive-agent", callback=self.aliveAgent, logEvent=False, enabled=True) self.__checkConfig() # initialize the agent with no data if agent is not None: if self.cfg['agent-support']: self.prepareAgent(data={'shared': shared}) if self.agentIsReady(timeout=30) is None: raise Exception("Agent %s is not ready" % self.cfg['agent-name'] ) self.TIMER_ALIVE_AGT.start()
def __init__(self, parent, debug=False, name=None, shared=False, showEvts=True, showSentEvts=True, showRecvEvts=True): """ My dummy adapter. Mon adaptateur factice et avancée. @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 shared: shared adapter (default=False) @type shared: boolean """ TestAdapterLib.Adapter.__init__(self, name=__NAME__, parent=parent, debug=debug, realname=name, shared=shared, showEvts=showEvts, showSentEvts=showSentEvts, showRecvEvts=showRecvEvts) self.codecX2D = Xml2Dict.Xml2Dict() self.codecD2X = Dict2Xml.Dict2Xml(coding=None) self.cfg = {} self.__checkConfig() # try to init generic library and adapter self.XML = LibraryCodecs.XML(parent=parent, debug=False, coding='UTF-8', name=None, shared=False)
def __init__(self, parent, name=None, bindIp='', bindPort=0, destinationIp='127.0.0.1', destinationPort=80, debug=False, logEventSent=True, logEventReceived=True, xmlns0='http://schemas.xmlsoap.org/soap/envelope/', xmlns1='', xmlns2='', xmlns3='', xmlns4='', xmlns5='', xmlns6='', xmlns7='', xmlns8='', httpAgent='ExtensiveTesting', httpVersion='HTTP/1.1', httpConnection='close', agentSupport=False, agent=None, shared=False, httpAuthentication=False, proxyIp='', proxyPort=3128, proxyHost='', proxyEnabled=False, proxyType=AdapterTCP.PROXY_HTTP, verbose=True, sslSupport=False, sslVersion=AdapterSSL.SSLv23, checkCert=AdapterSSL.CHECK_CERT_NO, caCerts=None, checkHost=False, hostCn=None, certfile=None, keyfile=None): """ This class enables to send and receive SOAP data @param bindIp: bind ip (default='') @type bindIp: string @param bindPort: bind port (default=0) @type bindPort: integer @param destinationIp: destination ip (default=127.0.0.1) @type destinationIp: string @param destinationPort: destination port (default=80) @type destinationPort: integer @param xmlns0: xml namespace @type xmlns0: string @param xmlns1: xml namespace @type xmlns1: string @param xmlns2: xml namespace @type xmlns2: string @param xmlns3: xml namespace @type xmlns3: string @param xmlns4: xml namespace @type xmlns4: string @param xmlns5: xml namespace @type xmlns5: string @param xmlns6: xml namespace @type xmlns6: string @param xmlns7: xml namespace @type xmlns7: string @param xmlns8: xml namespace @type xmlns8: string @param supportAuthentication: support digest authentication (default=False) @type supportAuthentication: boolean @param httpAgent: http agent (default value=ExtensiveTesting) @type httpAgent: string @param httpConnection: SutAdapters.HTTP.CONN_CLOSE (default) | SutAdapters.HTTP.CONN_KEEPALIVE | None @type httpConnection: strconstant @param httpVersion: SutAdapters.HTTP.VERSION_10 | SutAdapters.HTTP.VERSION_11 (default) @type httpVersion: strconstant @param sslSupport: ssl support (default=False) @type sslSupport: boolean @param sslVersion: SutAdapters.SSL.SSLv2 | SutAdapters.SSL.SSLv23 (default) | SutAdapters.SSL.SSLv3 | SutAdapters.SSL.TLSv1 | SutAdapters.SSL.TLSv11 | SutAdapters.SSL.TLSv12 @type sslVersion: strconstant @param checkCert: SutAdapters.SSL.CHECK_CERT_NO (default) | SutAdapters.SSL.CHECK_CERT_OPTIONAL | SutAdapters.SSL.CHECK_CERT_REQUIRED @type checkCert: strconstant @param caCerts: path to the certificate authority (default=None) @type caCerts: string/none @param checkHost: validate the common name field (default=False) @type checkHost: boolean @param hostCn: common name to check (default=None) @type hostCn: string/none @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 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 @param proxyType: SutAdapters.TCP.PROXY_HTTP (default) | SutAdapters.TCP.PROXY_SOCKS4 | SutAdapters.TCP.PROXY_SOCKS5 @type proxyType: strconstant @param proxyIp: proxy ip @type proxyIp: string @param proxyPort: proxy port @type proxyPort: integer @param proxyHost: proxy host (automatic dns resolution) @type proxyHost: string @param proxyEnabled: True to support proxy (default=False) @type proxyEnabled: boolean @param certfile: path to the cert file (default=None) @type certfile: string/none @param keyfile: path to the key file (default=None) @type keyfile: 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, showEvts=verbose, showSentEvts=verbose, showRecvEvts=verbose) self.logEventSent = logEventSent self.logEventReceived = logEventReceived self.ADP_HTTP = AdapterHTTP.Client(parent=parent, bindIp=bindIp, bindPort=bindPort, destinationIp=destinationIp, destinationPort=destinationPort, proxyIp=proxyIp, proxyPort=proxyPort, proxyHost=proxyHost, proxyEnabled=proxyEnabled, proxyType=proxyType, destinationHost='', socketTimeout=300.0, socketFamily=4, saveContent=False, httpVersion=httpVersion, httpAgent=httpAgent, httpConnection=httpConnection, httpChunckedData=False, sslSupport=sslSupport, sslVersion=sslVersion, checkCert=checkCert, debug=debug, caCerts=caCerts, checkHost=checkHost, hostCn=hostCn, logEventSent=False, logEventReceived=False, agentSupport=agentSupport, agent=agent, shared=shared, name=name, verbose=verbose, keyfile=keyfile, certfile=certfile) self.ADP_HTTP.handleIncomingResponse = self.handleIncomingResponse self.codecX2D = Xml2Dict.Xml2Dict(coding='utf8') self.codecD2X = Dict2Xml.Dict2Xml(coding='utf8') self.cfg = {} self.cfg['xmlns0'] = xmlns0 self.cfg['xmlns1'] = xmlns1 self.cfg['xmlns2'] = xmlns2 self.cfg['xmlns3'] = xmlns3 self.cfg['xmlns4'] = xmlns4 self.cfg['xmlns5'] = xmlns5 self.cfg['xmlns6'] = xmlns6 self.cfg['xmlns7'] = xmlns7 self.cfg['xmlns8'] = xmlns8 self.cfg['http-agent'] = httpAgent self.cfg['agent-support'] = agentSupport self.cfg['http_support_authentication'] = httpAuthentication self.cfg['http_digest_timeout'] = 10.0 if agentSupport: self.cfg['agent'] = agent self.cfg['agent-name'] = agent['name'] # digest library self.rfc2617 = LibraryAuth.Digest(parent=parent, debug=debug) self.__checkConfig()
def __init__ (self, parent, name=None, bootstrap_servers=None, debug=False, agentSupport=False, agent=None, shared=False, verbose=True, logEventSent=True, logEventReceived=True): """ KAFKA Producer client Adapter. Mapping of kafka-python KafkaProducer @param parent: parent testcase @type parent: testcase @bootstrap_servers: Kafka broker used to boostrap at connect call (list of ip address port ) @type bootstrap_servers: List @param agent: agent to use when this mode is activated @type agent: string/None @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 shared: shared adapter (default=False) @type shared: boolean """ TestAdapterLib.Adapter.__init__(self, name = __NAME__, parent = parent, debug=debug, realname=name, agentSupport=agentSupport, agent=agent, shared=shared, caller=TestAdapterLib.caller(), agentType=AGENT_TYPE_EXPECTED) self.parent = parent self.codecX2D = Xml2Dict.Xml2Dict() self.codecD2X = Dict2Xml.Dict2Xml(coding = None) self.logEventSent = logEventSent self.logEventReceived = logEventReceived self.parent = parent self.cfg = {} if agent is not None: self.cfg['agent'] = agent self.cfg['agent-name'] = agent['name'] self.cfg['agent-support'] = agentSupport self.TIMER_ALIVE_AGT = TestAdapterLib.Timer(parent=self, duration=20, name="keepalive-agent", callback=self.aliveAgent, logEvent=False, enabled=True) self.__checkConfig() # initialize the agent with no data if agent is not None: if self.cfg['agent-support']: self.prepareAgent(data={'shared': shared}) if self.agentIsReady(timeout=30) is None: raise Exception("Agent %s is not ready" % self.cfg['agent-name'] ) self.TIMER_ALIVE_AGT.start() self.bootstrap_servers = bootstrap_servers if debug: self.__getKafkaClientLogger()
def __init__(self, userName='******', testData=''): """ This class describes the model of one script document, and provides a xml <=> python encoder The following xml : <?xml version="1.0" encoding="utf-8" ?> <file> <properties"> <descriptions> <description> <key>author</key> <value>...</value> </description> <description> <key>creation date</key> <value>...</value> </description> <description> <key>summary</key> <value>...</value> </description> </descriptions> <parameters> <parameter> <name>...</name> <type>...</type> <description>...</description> <value>...</value> </parameter> </parameters> </properties> <testdata>...</testdata> </file> """ GenericModel.GenericModel.__init__(self) today = datetime.datetime.today() self.dateToday = today.strftime("%d/%m/%Y %H:%M:%S") self.currentUser = userName # init xml codec self.codecX2D = PyXmlDict.Xml2Dict() self.codecD2X = PyDictXml.Dict2Xml(coding=None) # files properties self.properties = { 'properties': { 'descriptions': { 'description': [{ 'key': 'author', 'value': self.currentUser }, { 'key': 'creation date', 'value': self.dateToday }, { 'key': 'summary', 'value': 'Just a basic sample.' }, { 'key': 'data mode', 'value': DEFAULT_MODE }] }, 'inputs-parameters': { 'parameter': [{ 'type': 'str', 'name': 'PARAM1', 'description': '', 'value': 'Sample', 'color': '', 'scope': 'local' }] } } } self.testdata = testData
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 """ # 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, realname=name, shared=shared) 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()
def __init__(self, parent, name=None, bindIp='', bindPort=0, destinationIp='127.0.0.1', destinationPort=80, debug=False, logEventSent=True, logEventReceived=True, httpAgent='ExtensiveTesting', httpVersion='HTTP/1.1', httpConnection='close', sslSupport=False, sslVersion=AdapterSSL.SSLv23, checkCert=AdapterSSL.CHECK_CERT_NO, caCerts=None, checkHost=False, hostCn=None, agentSupport=False, agent=None, shared=False, proxyIp='', proxyPort=3128, proxyHost='', proxyEnabled=False, proxyType=AdapterTCP.PROXY_HTTP, certfile=None, keyfile=None): """ This class enables to send and receive REST data @param bindIp: bind ip (default='') @type bindIp: string @param bindPort: bind port (default=0) @type bindPort: integer @param destinationIp: destination ip (default=127.0.0.1) @type destinationIp: string @param destinationPort: destination port (default=80) @type destinationPort: integer @param httpAgent: http agent (default value=ExtensiveTesting) @type httpAgent: string @param httpConnection: SutAdapters.HTTP.CONN_CLOSE (default) | SutAdapters.HTTP.CONN_KEEPALIVE | None @type httpConnection: strconstant @param httpVersion: SutAdapters.HTTP.VERSION_10 | SutAdapters.HTTP.VERSION_11 (default) @type httpVersion: strconstant @param sslSupport: ssl support (default=False) @type sslSupport: boolean @param checkCert: SutAdapters.SSL.CHECK_CERT_NO (default) | SutAdapters.SSL.CHECK_CERT_OPTIONAL | SutAdapters.SSL.CHECK_CERT_REQUIRED @type checkCert: strconstant @param caCerts: path to the certificate authority (default=None) @type caCerts: string/none @param checkHost: validate the common name field (default=False) @type checkHost: boolean @param hostCn: common name to check (default=None) @type hostCn: string/none @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 agentSupport: agent support to use a remote socket (default=False) @type agentSupport: boolean @param agent: agent to use when this mode is activated, socket type expected @type agent: string/None @param shared: shared adapter (default=False) @type shared: boolean @param proxyType: SutAdapters.TCP.PROXY_HTTP (default) | SutAdapters.TCP.PROXY_SOCKS4 | SutAdapters.TCP.PROXY_SOCKS5 @type proxyType: strconstant @param proxyIp: proxy ip @type proxyIp: string @param proxyPort: proxy port @type proxyPort: integer @param proxyHost: proxy host (automatic dns resolution) @type proxyHost: string @param proxyEnabled: True to support proxy (default=False) @type proxyEnabled: boolean @param certfile: path to the cert file (default=None) @type certfile: string/none @param keyfile: path to the key file (default=None) @type keyfile: string/none """ # check agent if agentSupport and agent is None: raise TestAdapter.ValueException(TestAdapter.caller(), "Agent cannot be undefined!") if agentSupport: if not isinstance(agent, dict): raise TestAdapter.ValueException( TestAdapter.caller(), "agent argument is not a dict (%s)" % type(agent)) if not len(agent['name']): raise TestAdapter.ValueException(TestAdapter.caller(), "agent name cannot be empty") if unicode(agent['type']) != unicode(AGENT_TYPE_EXPECTED): raise TestAdapter.ValueException( TestAdapter.caller(), 'Bad agent type: %s, expected: %s' % (agent['type'], unicode(AGENT_TYPE_EXPECTED))) # init adapter TestAdapter.Adapter.__init__(self, name=__NAME__, parent=parent, debug=debug, shared=shared, realname=name, agentSupport=agentSupport, agent=agent) self.logEventSent = logEventSent self.logEventReceived = logEventReceived self.ADP_HTTP = AdapterHTTP.Client(parent=parent, bindIp=bindIp, bindPort=bindPort, destinationIp=destinationIp, destinationPort=destinationPort, proxyIp=proxyIp, proxyPort=proxyPort, proxyHost=proxyHost, proxyEnabled=proxyEnabled, proxyType=proxyType, destinationHost='', socketTimeout=300.0, socketFamily=4, saveContent=False, httpVersion=httpVersion, httpAgent=httpAgent, httpConnection=httpConnection, httpChunckedData=False, sslSupport=sslSupport, sslVersion=sslVersion, checkCert=checkCert, caCerts=caCerts, checkHost=checkHost, hostCn=hostCn, debug=debug, logEventSent=False, logEventReceived=False, agentSupport=agentSupport, agent=agent, shared=shared, name=name, keyfile=keyfile, certfile=certfile) self.ADP_HTTP.handleIncomingResponse = self.handleIncomingResponse self.LIB_JSON = LibraryCodecs.JSON(parent=parent, name=name, debug=debug, ignoreErrors=True) self.codecX2D = Xml2Dict.Xml2Dict() self.codecD2X = Dict2Xml.Dict2Xml(coding=None) self.cfg = {} self.cfg['http-agent'] = httpAgent self.cfg['agent-support'] = agentSupport if agentSupport: self.cfg['agent'] = agent self.cfg['agent-name'] = agent['name'] self.__checkConfig()
def __init__(self, parent, destIp= '127.0.0.1', destPort=22, bindIp='', bindPort=0, login='******', password='******', privateKey=None, privateKeyPath=None, name=None, debug=False, shared=False, agent=None, agentSupport=False, verbose=True): """ SFTP adapter based on SSH. Authentication by login/password or key are supported @param parent: parent testcase @type parent: testcase @param destIp: destination ip of the scp server @type destIp: string @param destPort: destination port of the scp server (default=22) @type destPort: integer @param bindIp: bind on specific ip, bind on all by default @type bindIp: string @param bindPort: bind on specific port, bind on all port by default @type bindPort: integer @param login: username to connect on it @type login: string @param password: password to connect on it @type password: string @param privateKey: string private key to use to authenticate, push your public key on the remote server @type privateKey: string/none @param privateKeyPath: path to the private key to use to authenticate, push your public key on the remote server @type privateKeyPath: string/none @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 verbose: False to disable verbose mode (default=True) @type verbose: boolean @param shared: shared adapter (default=False) @type shared: boolean @param agent: agent to use, ssh type expected @type agent: string/none @param agentSupport: agent support (default=False) @type agentSupport: boolean """ if not isinstance(bindPort, int): raise TestAdapter.ValueException(TestAdapter.caller(), "bindPort argument is not a integer (%s)" % type(bindPort) ) if not isinstance(destPort, int): raise TestAdapter.ValueException(TestAdapter.caller(), "destPort argument is not a integer (%s)" % type(destPort) ) # init adapter TestAdapter.Adapter.__init__(self, name = __NAME__, parent = parent, debug=debug, realname=name, shared=shared, showEvts=verbose, showSentEvts=verbose, showRecvEvts=verbose) self.codecX2D = Xml2Dict.Xml2Dict() self.codecD2X = Dict2Xml.Dict2Xml(coding = None) self.parent = parent self.__connected = False self.__logged = False self.ADP_SSH = AdapterSSH.Client(parent=parent, login=login, password=password, privateKey=privateKey, privateKeyPath=privateKeyPath, bindIp=bindIp, bindPort=bindPort, destIp=destIp, destPort=destPort, destHost='', socketTimeout=10.0, socketFamily=4, name=name, debug=debug, logEventSent=True, logEventReceived=True, parentName=__NAME__, shared=shared, sftpSupport=True, agent=agent, agentSupport=agentSupport, verbose=verbose ) self.cfg = {} self.cfg['dst-ip'] = destIp self.cfg['dst-port'] = destPort self.cfg['bind-ip'] = bindIp self.cfg['bind-port'] = bindPort self.cfg['user'] = login self.cfg['password'] = password self.cfg['agent-support'] = agentSupport if agentSupport: self.cfg['agent'] = agent self.cfg['agent-name'] = agent['name'] self.__logged = False self.__checkConfig() # wrap function self.ADP_SSH.onSftpOpened = self.onSftpOpened self.ADP_SSH.onSftpEvent = self.onSftpEvent
def __init__(self, parent, agent, name=None, debug=False, verbose=True, shared=False): """ Android automator throught ADB (Android debug bridge) @param parent: parent testcase @type parent: testcase @param agent: agent to use, adb type expected @type agent: string @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 verbose: False to disable verbose mode (default=True) @type verbose: boolean @param shared: shared adapter (default=False) @type shared: boolean """ # check the agent if not isinstance(agent, dict): raise TestAdapter.ValueException( TestAdapter.caller(), "agent argument is not a dict (%s)" % type(agent)) if not len(agent['name']): raise TestAdapter.ValueException(TestAdapter.caller(), "agent name cannot be empty") if unicode(agent['type']) != unicode(AGENT_TYPE_EXPECTED): raise TestAdapter.ValueException( TestAdapter.caller(), 'Bad agent type: %s, expected: %s' % (agent['type'], unicode(AGENT_TYPE_EXPECTED))) TestAdapter.Adapter.__init__(self, name=__NAME__, parent=parent, debug=debug, realname=name, agentSupport=True, agent=agent, shared=shared, showEvts=verbose, showSentEvts=verbose, showRecvEvts=verbose) self.parent = parent self.codecX2D = Xml2Dict.Xml2Dict() self.codecD2X = Dict2Xml.Dict2Xml(coding=None) self.cfg = {} self.cfg['agent'] = agent self.cfg['agent-name'] = agent['name'] self.cmdId = 0 self.__mutexCmdId__ = threading.RLock() self.TIMER_ALIVE_AGT = TestAdapter.Timer(parent=self, duration=20, name="keepalive-agent", callback=self.aliveAgent, logEvent=False, enabled=True) self.__checkConfig() # initialize the agent with no data self.prepareAgent(data={'shared': shared}) if self.agentIsReady(timeout=30) is None: raise TestAdapter.ValueException( TestAdapter.caller(), "Agent %s is not ready" % self.cfg['agent-name']) self.TIMER_ALIVE_AGT.start()
def __init__(self, parent, name=None, debug=False, shared=False, agentSupport=False, agent=None, bindIp='', bindPort=0, sslSupport=False, strictMode=False, octetStreamSupport=True, manStreamSupport=True, websocketMode=False, truncateBody=False, logEventSent=True, logEventReceived=True, checkCert=AdapterSSL.CHECK_CERT_NO, certfile="/tmp/cert.file", keyfile="/tmp/key.file"): """ HTTP server, based on TCP server 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 shared: shared adapter (default=False) @type shared: boolean @param agentSupport: agent support (default=False) @type agentSupport: boolean @param agent: agent to use (default=None) @type agent: string/none @param bindIp: bind on ip (source ip) @type bindIp: string @param bindPort: bind on port (source port) @type bindPort: integer @param sslSupport: activate SSL channel (default=False) @type sslSupport: boolean @param checkCert: SutAdapters.SSL.CHECK_CERT_NO | SutAdapters.SSL.CHECK_CERT_OPTIONAL | SutAdapters.SSL.CHECK_CERT_REQUIRED @type checkCert: strconstant @param certFile: certificate file (default=/tmp/cert.file) @type certFile: string @param keyFile: key file (default=/tmp/key.file) @type keyFile: string """ TestAdapterLib.Adapter.__init__(self, name=__NAME__, parent=parent, debug=debug, realname=name, agentSupport=agentSupport, agent=agent, shared=shared, caller=TestAdapterLib.caller(), agentType=AGENT_TYPE_EXPECTED) self.parent = parent self.codecX2D = Xml2Dict.Xml2Dict() self.codecD2X = Dict2Xml.Dict2Xml(coding=None) self.cfg = {} if agent is not None: self.cfg['agent'] = agent self.cfg['agent-name'] = agent['name'] self.cfg['agent-support'] = agentSupport self.logEventSent = logEventSent self.logEventReceived = logEventReceived self.cfg['http_truncate_body'] = truncateBody self.cfg['http_strict_mode'] = strictMode self.cfg['http_websocket_mode'] = websocketMode self.cfg['http_octet_stream_support'] = octetStreamSupport self.cfg['http_man_stream_support'] = manStreamSupport self.clients = {} self.eventsExpected = [] self.eventsQueue = Queue.Queue(0) self.ADP_TCP = AdapterTCP.Server(parent=parent, bindIp=bindIp, bindPort=bindPort, separatorDisabled=True, logEventSent=False, logEventReceived=False, agent=agent, shared=shared, agentSupport=agentSupport, sslSupport=sslSupport, checkCert=checkCert, certfile=certfile, keyfile=keyfile) self.ADP_TCP.onClientIncomingData = self.onClientIncomingData self.ADP_TCP.onClientNoMoreData = self.onClientNoMoreData self.__checkConfig()
def __init__(self, parent, agent, name=None, node='127.0.0.1', user='', password='', debug=False, shared=False, logEventSent=True, logEventReceived=True, nodes=[]): """ Windows adapter, based on the tool wmic Works with an agent only @param parent: parent testcase @type parent: testcase @param name: adapter name used with from origin/to destination (default=None) @type name: string/none @param agent: agent to use @type agent: string @param node: host to contact (default=127.0.0.1) @type node: string @param user: username (default='') @type user: string @param password: password (default='') @type password: string @param debug: active debug mode (default=False) @type debug: boolean @param shared: shared adapter (default=False) @type shared: boolean """ # init adapter TestAdapterLib.Adapter.__init__(self, name=__NAME__, parent=parent, debug=debug, realname=name, agentSupport=True, agent=agent, shared=shared, caller=TestAdapterLib.caller(), agentType=AGENT_TYPE_EXPECTED) self.codecX2D = Xml2Dict.Xml2Dict() self.codecD2X = Dict2Xml.Dict2Xml(coding=None) self.logEventSent = logEventSent self.logEventReceived = logEventReceived self.parent = parent self.cfg = {} self.cfg['agent'] = agent self.cfg['agent-name'] = agent['name'] self.cfg['agent-support'] = True self.cfg['node'] = node # todo add authen /user:"******"******" self.cfg['user'] = node self.cfg['password'] = node # nodes: call server machine at once # /node:"server-01","server-02","server-03" self.TIMER_ALIVE_AGT = TestAdapterLib.Timer(parent=self, duration=20, name="keepalive-agent", callback=self.aliveAgent, logEvent=False, enabled=True) self.__checkConfig() # initialize the agent with no data self.prepareAgent(data={'shared': shared}) if self.agentIsReady(timeout=30) is None: raise TestAdapterLib.ValueException( TestAdapterLib.caller(), "Agent %s is not ready" % self.cfg['agent-name']) self.TIMER_ALIVE_AGT.start()
def __init__(self, parent, host_group, agent, ssh_user=None, ssh_pass=None, name=None, debug=False, shared=False, constants=None, options=None, host_fqdns="None", host_py='python', agentSupport=True, logEventReceived=True, timeout=10.0): """ Ansible adapter with agent mode support @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 shared: shared adapter (default=False) @type shared: boolean @param agentSupport: agent support (default=False) @type agentSupport: boolean @param agent: agent to use (default=None) @type agent: string/none @param logEventReceived: default = True @type logEventReceived: boolean @param ssh_user: ssh user name @type ssh_user: string/dict/None @param ssh_pass: ssh user password @type ssh_pass: string/dict/None @param host_group: group for task @type host_group: string @param options: default { "connection": "local", "module_path": "~/", "forks": 100, "become": "yes", "become_method": "sudo", "become_user": "******", "check": false, "diff": false } @type options: dict/none @param constants: @type constants: dict/None @param host_fqdns: For hosts machines dict or string as json where keys should be ansible_host. For localhost playbook just "None" @type host_fqdns: dict/str @param host_py: path to python interpreter default for Linux python for Freebsd /usr/local/bin/python2 @type host_py: string """ TestAdapterLib.Adapter.__init__(self, name=self.__NAME__, parent=parent, debug=debug, realname=name, agentSupport=agentSupport, agent=agent, shared=shared, caller=TestAdapterLib.caller(), agentType=self.AGENT_TYPE_EXPECTED) self.parent = parent self.codecX2D = Xml2Dict.Xml2Dict() self.codecD2X = Dict2Xml.Dict2Xml(coding=None) self.logEventReceived = logEventReceived self.cfg = {} self.cfg['agent-support'] = True self.cfg['agent'] = agent self.cfg['agent-name'] = agent['name'] # Ansible parameters self.host_group = host_group self.ssh_user = ssh_user self.ssh_pass = ssh_pass self.host_fqdns = host_fqdns if isinstance( host_fqdns, dict) else yaml.load(host_fqdns) self.host_py = host_py self.constants = constants if constants else { "HOST_KEY_CHECKING": False } self.options = options if options else { "connection": "local", "module_path": "~/", "forks": 100, "become": "yes", "become_method": "sudo", "become_user": "******", "check": False, "diff": False } # initialize the agent with no data self.prepareAgent(data={'shared': shared}) if self.agentIsReady(timeout=timeout) is None: raise TestAdapterLib.ValueException( TestAdapterLib.caller(), "Agent %s is not ready" % self.cfg['agent-name']) self.TIMER_ALIVE_AGT = TestAdapterLib.Timer(parent=self, duration=20, name="keepalive-agent", callback=self.aliveAgent, logEvent=False, enabled=True) self.cfg['agent']['type'] = 'ansible' self.configs = {} self.services = {} self.TIMER_ALIVE_AGT.start()
def __init__(self, parent, bindIp='', bindPort=0, destinationIp='127.0.0.1', proxyIp='', proxyPort=3128, proxyHost='', proxyEnabled=False, destinationPort=80, destinationHost='', name=None, debug=False, sslSupport=False, sslVersion=AdapterSSL.SSLv23, agentSupport=False, agent=None, shared=False, logEventSent=True, logEventReceived=True): """ Adapter for the websocket protocol according to the rfc 6455 Ssl and proxy support @param parent: parent testcase @type parent: testcase @param bindIp: source ip (default='') @type bindIp: string @param bindPort: source port (default=0) @type bindPort: integer @param destinationIp: destination ip @type destinationIp: string @param destinationPort: destination port (default: port 80) @type destinationPort: integer @param destinationHost: destination host (dns resolution) @type destinationHost: string @param proxyIp: proxy ip @type proxyIp: string @param proxyPort: proxy port @type proxyPort: integer @param proxyHost: proxy host (automatic dns resolution) @type proxyHost: string @param proxyEnabled: True to support proxy (default=False) @type proxyEnabled: boolean @param sslSupport: activate SSL channel (default=False) @type sslSupport: boolean @param sslVersion: SutAdapters.SSL.SSLv2 | SutAdapters.SSL.SSLv23 (default) | SutAdapters.SSL.SSLv3 | SutAdapters.SSL.TLSv1 | SutAdapters.SSL.TLSv11 | SutAdapters.SSL.TLSv12 @type sslVersion: strconstant @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 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, agentSupport=agentSupport, agent=agent, caller=TestAdapterLib.caller(), agentType=AGENT_TYPE_EXPECTED) self.codecX2D = Xml2Dict.Xml2Dict() self.codecD2X = Dict2Xml.Dict2Xml(coding=None) self.logEventSent = logEventSent self.logEventReceived = logEventReceived self.wsKey = None self.wsHanshakeSuccess = False self.wsMaxPayloadSize = codec.WEBSOCKET_MAX_BASIC_DATA1024 self.buf = '' self.cfg = {} self.cfg['dest-ip'] = destinationIp self.cfg['dest-port'] = destinationPort self.cfg['ssl-support'] = sslSupport # agent support self.cfg['agent-support'] = agentSupport if agentSupport: self.cfg['agent'] = agent self.cfg['agent-name'] = agent['name'] self.__checkConfig() self.ADP_HTTP = AdapterHTTP.Client(parent=parent, bindIp=bindIp, bindPort=bindPort, name=name, destinationIp=destinationIp, destinationPort=destinationPort, destinationHost=destinationHost, proxyIp=proxyIp, proxyPort=proxyPort, proxyHost=proxyHost, proxyEnabled=proxyEnabled, socketTimeout=300.0, socketFamily=4, websocketMode=True, saveContent=False, httpVersion='HTTP/1.1', httpAgent='ExtensiveTesting', httpConnection='close', httpChunckedData=False, sslSupport=sslSupport, sslVersion=sslVersion, checkCert='No', debug=debug, logEventSent=False, logEventReceived=False, truncateBody=False, agentSupport=agentSupport, agent=agent, shared=shared, strictMode=False) self.ADP_HTTP.handleIncomingResponse = self.handleIncomingHttpResponse self.ADP_HTTP.onWebsocketIncomingData = self.onWebsocketIncomingData self.wsCodec = codec.Codec(parent=self)
def __init__(self, parent, bindIp='0.0.0.0', bindPort=0, destIp='127.0.0.1', destPort=23, name=None, debug=False, shared=False, prompt='>', promptEnable='#', agent=None, agentSupport=False): """ Adapter for catalyst switch cisco. Based on telnet. @param parent: parent testcase @type parent: testcase @param bindIp: bind ip (default=0.0.0.0) @type bindIp: string @param bindPort: bind port (default=0) @type bindPort: integer @param destIp: destination ip (default=127.0.0.1) @type destIp: string @param destPort: destination port (default=23) @type destPort: integer @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 shared: shared adapter (default=False) @type shared: boolean @param prompt: prompt (default=#) @type prompt: string """ if not isinstance(bindPort, int): raise TestAdapter.ValueException( TestAdapter.caller(), "bindPort argument is not a integer (%s)" % type(bindPort)) if not isinstance(destPort, int): raise TestAdapter.ValueException( TestAdapter.caller(), "destPort argument is not a integer (%s)" % type(destPort)) TestAdapter.Adapter.__init__(self, name=__NAME__, parent=parent, debug=debug, realname=name) self.codecX2D = Xml2Dict.Xml2Dict() self.codecD2X = Dict2Xml.Dict2Xml(coding=None) self.cfg = {} # agent support self.cfg['agent-support'] = agentSupport if agentSupport: self.cfg['agent'] = agent self.cfg['agent-name'] = agent['name'] self.__checkConfig() self.codec = codec_catalyst.Codec(parent=self) self.buf = '' self.prompt = '>' self.promptEnable = '#' self.ADP_TRANSPORT = AdapterTelnet.Client(parent=parent, bindIp=bindIp, bindPort=bindPort, destIp=destIp, destPort=destPort, debug=debug, logEventSent=False, logEventReceived=False, parentName=__NAME__, agent=agent, agentSupport=agentSupport) self.ADP_TRANSPORT.handleIncomingData = self.handleIncomingData
def __init__(self, userName='******', testDef='', defLibrary='', defAdapter='', timeout="10.0", inputs=[], outputs=[]): """ This class describes the model of one script document, and provides a xml <=> python encoder The following xml : <?xml version="1.0" encoding="utf-8" ?> <file> <properties"> <descriptions> <description> <key>author</key> <value>...</value> </description> <description> <key>creation date</key> <value>...</value> </description> <description> <key>summary</key> <value>...</value> </description> <description> <key>prerequisites</key> <value>...</value> </description> <description> <key>comments</key> <value> <comments> <comment> <author>author</author> <datetime>...</datetime> <post>...</post> </comment> .... </comments> </value> </description> </descriptions> <inputs-parameters> <parameter> <name>...</name> <type>...</type> <description>...</description> <value>...</value> </parameter> </inputs-parameters> <outputs-parameters> <parameter> <name>...</name> <type>...</type> <description>...</description> <value>...</value> </parameter> </outputs-parameters> <probes> <probe> <active>...</active> <args>...</args> <name>...</name> <type>...</type> </probe> </probes> <agents> <agent> <name>...</name> <type>...</type> <description>...</description> <value>...</value> </agent> </agents> </properties> <testdefinition>...</testdefinition> <testdevelopment>...</testdevelopment> <snapshots> <snapshot> <name>....</name> <timestamp>...</timestamp> <properties>...</properties> <testdef>....</testdef> </snapshot> </snapshots> </file> """ GenericModel.GenericModel.__init__(self) today = datetime.datetime.today() self.dateToday = today.strftime("%d/%m/%Y %H:%M:%S") self.currentUser = userName self.defLibrary = defLibrary self.defAdapter = defAdapter # new in v17 self.timeout = timeout self.inputs = inputs self.outputs = outputs # end of new # init xml encoder self.codecX2D = PyXmlDict.Xml2Dict() self.codecD2X = PyDictXml.Dict2Xml(coding=None) # files properties self.properties = { 'properties': { 'descriptions': { 'description': [ { 'key': 'author', 'value': self.currentUser }, { 'key': 'creation date', 'value': self.dateToday }, { 'key': 'summary', 'value': 'Just a basic sample.' }, { 'key': 'prerequisites', 'value': 'None.' }, { 'key': 'comments', 'value': { 'comments': { 'comment': [] } } }, { 'key': 'libraries', 'value': self.defLibrary }, { 'key': 'adapters', 'value': self.defAdapter }, { 'key': 'state', 'value': 'Writing' }, { 'key': 'name', 'value': 'TESTCASE' }, { 'key': 'requirement', 'value': 'REQ_01' }, ] }, 'probes': { 'probe': [{ 'active': 'False', 'args': '', 'name': 'probe01', 'type': 'default' }] }, 'inputs-parameters': { 'parameter': copy.deepcopy(DEFAULT_INPUTS) }, 'outputs-parameters': { 'parameter': copy.deepcopy(DEFAULT_OUTPUTS) }, 'agents': { 'agent': copy.deepcopy(DEFAULT_AGENTS) }, } } # new in v17 for p in self.properties["properties"]["inputs-parameters"][ "parameter"]: if p["name"] == "TIMEOUT": p["value"] = self.timeout for p in self.properties["properties"]["outputs-parameters"][ "parameter"]: if p["name"] == "TIMEOUT": p["value"] = self.timeout if len(self.inputs): self.properties["properties"]["inputs-parameters"][ "parameter"] = self.inputs if len(self.outputs): self.properties["properties"]["outputs-parameters"][ "parameter"] = self.outputs # end of new # file contents self.testdef = testDef # dev duration self.testdev = time.time()
def __init__(self, parent, name=None, debug=False, shared=False, agentSupport=False, agent=None, bindIp='', bindPort=0, sslSupport=False, strictMode=False, octetStreamSupport=True, manStreamSupport=True, websocketMode=False, truncateBody=False, logEventSent=True, logEventReceived=True, checkCert=AdapterSSL.CHECK_CERT_NO, certfile="/tmp/cert.file", keyfile="/tmp/key.file"): """ HTTP server, based on TCP server 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 shared: shared adapter (default=False) @type shared: boolean @param agentSupport: agent support (default=False) @type agentSupport: boolean @param agent: agent to use (default=None) @type agent: string/none @param bindIp: bind on ip (source ip) @type bindIp: string @param bindPort: bind on port (source port) @type bindPort: integer @param sslSupport: activate SSL channel (default=False) @type sslSupport: boolean """ # check the agent if agentSupport and agent is None: raise TestAdapter.ValueException(TestAdapter.caller(), "Agent cannot be undefined!") if agentSupport: if not isinstance(agent, dict): raise TestAdapter.ValueException( TestAdapter.caller(), "agent argument is not a dict (%s)" % type(agent)) if not len(agent['name']): raise TestAdapter.ValueException(TestAdapter.caller(), "agent name cannot be empty") if unicode(agent['type']) != unicode(AGENT_TYPE_EXPECTED): raise TestAdapter.ValueException( TestAdapter.caller(), 'Bad agent type: %s, expected: %s' % (agent['type'], unicode(AGENT_TYPE_EXPECTED))) TestAdapter.Adapter.__init__(self, name=__NAME__, parent=parent, debug=debug, realname=name, agentSupport=agentSupport, agent=agent, shared=shared) self.parent = parent self.codecX2D = Xml2Dict.Xml2Dict() self.codecD2X = Dict2Xml.Dict2Xml(coding=None) self.cfg = {} if agent is not None: self.cfg['agent'] = agent self.cfg['agent-name'] = agent['name'] self.cfg['agent-support'] = agentSupport # self.TIMER_ALIVE_AGT = TestAdapter.Timer(parent=self, duration=20, name="keepalive-agent", callback=self.aliveAgent, # logEvent=False, enabled=True) self.logEventSent = logEventSent self.logEventReceived = logEventReceived self.cfg['http_truncate_body'] = truncateBody self.cfg['http_strict_mode'] = strictMode self.cfg['http_websocket_mode'] = websocketMode self.cfg['http_octet_stream_support'] = octetStreamSupport self.cfg['http_man_stream_support'] = manStreamSupport self.clients = {} self.eventsExpected = [] self.eventsQueue = Queue.Queue(0) self.ADP_TCP = AdapterTCP.Server(parent=parent, bindIp=bindIp, bindPort=bindPort, separatorDisabled=True, logEventSent=False, logEventReceived=False, agent=agent, shared=shared, agentSupport=agentSupport, sslSupport=sslSupport, checkCert=checkCert, certfile=certfile, keyfile=keyfile) self.ADP_TCP.onClientIncomingData = self.onClientIncomingData self.ADP_TCP.onClientNoMoreData = self.onClientNoMoreData self.__checkConfig()
def __init__(self, parent, name=None, debug=False, shared=False, agentSupport=False, agent=None, sslSupport=False, bindIp='', bindPort=0, destinationIp='www.webservicex.net', destinationPort=80, xmlns0='', httpAuthentication=False, httpLogin='', httpPassword='', xmlns1='http://schemas.xmlsoap.org/soap/envelope/', xmlns2='http://www.w3.org/2003/05/soap-envelope', xmlns3='http://www.w3.org/2001/XMLSchema-instance', xmlns7='', xmlns8='', xmlns4='http://www.w3.org/2001/XMLSchema', xmlns5='http://www.w3.org/XML/1998/namespace', xmlns6='', destUri='/globalweather.asmx', proxyIp='', proxyPort=3128, proxyHost='', proxyEnabled=False, proxyType=AdapterTCP.PROXY_HTTP): """ Adapter generated automatically from wsdl @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 shared: shared adapter (default=False) @type shared: boolean @param bindIp: bind ip (default='') @type bindIp: string @param bindPort: bind port (default=0) @type bindPort: integer @param destinationIp: destination ip (default=127.0.0.1) @type destinationIp: string @param destinationPort: destination port (default=80) @type destinationPort: integer @param xmlns0: xml namespace @type xmlns0: string @param xmlns1: xml namespace (default=http://schemas.xmlsoap.org/soap/envelope/) @type xmlns1: string @param xmlns2: xml namespace (defaut=http://www.w3.org/2003/05/soap-envelope) @type xmlns2: string @param xmlns3: xml namespace (default=http://www.w3.org/2001/XMLSchema-instance) @type xmlns3: string @param xmlns4: xml namespace (default=http://www.w3.org/2001/XMLSchema) @type xmlns4: string @param xmlns5: xml namespace (default=) @type xmlns5: string @param xmlns6: xml namespace (default=) @type xmlns6: string @param xmlns7: xml namespace (default=) @type xmlns7: string @param xmlns8: xml namespace (default=) @type xmlns8: string @param sslSupport: ssl support (default=False) @type sslSupport: boolean @param destUri: destination uri @type destUri: string @param proxyType: SutAdapters.TCP.PROXY_HTTP (default) | SutAdapters.TCP.PROXY_SOCKS4 | SutAdapters.TCP.PROXY_SOCKS5 @type proxyType: strconstant @param proxyIp: proxy ip @type proxyIp: string @param proxyPort: proxy port @type proxyPort: integer @param proxyHost: proxy host (automatic dns resolution) @type proxyHost: string @param proxyEnabled: True to support proxy (default=False) @type proxyEnabled: boolean @param httpAuthentication: support http digest authentication (default=False) @type httpAuthentication: boolean @param httpLogin: login used on http digest authentication (default='') @type httpLogin: string @param httpPassword: password used on http digest authentication (default='') @type httpPassword: string @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 """ TestAdapter.Adapter.__init__(self, name=__NAME__, parent=parent, debug=debug, realname=name) self.codecX2D = Xml2Dict.Xml2Dict() self.codecD2X = Dict2Xml.Dict2Xml(coding=None) self.cfg = {} self.cfg['local-wsdl'] = '%s/%s/%s' % (TestAdapter.getMainPath(), TestAdapter.getVersion(), '/GlobalWeather/wsdl.txt') self.cfg['host'] = destinationIp self.cfg['uri'] = destUri self.cfg['http-login'] = httpLogin self.cfg['http-password'] = httpPassword self.ADP_SOAP = AdapterSOAP.Client( parent=parent, name=name, bindIp=bindIp, bindPort=bindPort, destinationIp=destinationIp, destinationPort=destinationPort, debug=debug, logEventSent=True, logEventReceived=True, xmlns0=xmlns0, xmlns1=xmlns1, xmlns2=xmlns2, xmlns7=xmlns7, xmlns8=xmlns8, xmlns3=xmlns3, xmlns4=xmlns4, xmlns5=xmlns5, xmlns6=xmlns6, httpAgent='ExtensiveTesting', sslSupport=sslSupport, agentSupport=agentSupport, httpAuthentication=httpAuthentication, proxyIp=proxyIp, proxyPort=proxyPort, proxyHost=proxyHost, proxyEnabled=proxyEnabled, proxyType=proxyType, agent=agent, shared=shared) try: self.LIB_SUDS = Client("file://%s" % self.cfg['local-wsdl'], nosend=True, cache=NoCache()) except Exception as e: raise Exception("Unable to load the wsdl file: %s" % e) # agent support self.cfg['agent-support'] = agentSupport if agentSupport: self.cfg['agent'] = agent self.cfg['agent-name'] = agent['name'] self.__checkConfig()
def __init__(self, parent, name=None, debug=False, shared=False, agent=None, agentSupport=False, gwIp='127.0.0.1', gwPort=9090, checkInterval=10): """ Adapter to receive or send SMS through a gateway @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 shared: shared adapter (default=False) @type shared: boolean @param gwIp: gateway ip (mobile device) @type gwIp: string @param gwPort: gateway port (mobile device) @type gwPort: integer @param checkInterval: interval to check the mailbox (default=10s) @type checkInterval: integer """ TestAdapter.Adapter.__init__(self, name = __NAME__, parent = parent, debug=debug, realname=name, shared=shared, agentSupport=agentSupport, agent=agent, caller=TestAdapter.caller(), agentType=AGENT_TYPE_EXPECTED) self.parent = parent self.codecX2D = Xml2Dict.Xml2Dict() self.codecD2X = Dict2Xml.Dict2Xml(coding = None) self.__mutexActionId__ = threading.RLock() self.actionId = 0 self.cfg = {} self.cfg['gw-ip'] = gwIp self.cfg['gw-port'] = gwPort self.cfg['agent-support'] = agentSupport if agentSupport: self.cfg['agent'] = agent self.cfg['agent-name'] = agent['name'] self.timer_mailbox = TestAdapter.Timer(parent=self, duration=checkInterval, name="mailbox timer", callback=self.checkMailbox, logEvent=False, enabled=True) self.TIMER_ALIVE_AGT = TestAdapter.Timer(parent=self, duration=20, name="keepalive-agent", callback=self.aliveAgent, logEvent=False, enabled=True) self.__checkConfig() # initialize the agent with no data self.prepareAgent(data={'shared': shared}) if self.agentIsReady(timeout=10) is None: raise TestAdapter.ValueException(TestAdapter.caller(), "Agent %s is not ready" % self.cfg['agent-name'] ) # raise Exception("Agent %s is not ready" % self.cfg['agent-name'] ) self.TIMER_ALIVE_AGT.start() self.timer_mailbox.start()
def __init__(self, parent, name, realname=None, debug=False, showEvts=True, showSentEvts=True, showRecvEvts=True, shared=False, agentSupport=False, agent=None, timeoutSleep=0.05, caller=None, agentType=None): """ All adapters must inherent from this class @param parent: the parent testcase @type parent: testcase @param name: adapter type name @type name: string @param realname: adapter name @type realname: string/None @param agentSupport: use agent or not (default=False) @type agentSupport: boolean @param agent: agent name (default=None) @type agent: none/dict @param debug: True to activate debug mode, default value=False @type debug: boolean @param shared: True to activate shared mode, default value=False @type shared: boolean """ if not isinstance(parent, TestExecutorLib.TestCase): raise TestAdaptersException( 'ERR_ADP_011: testcase expected but a bad type is passed for the parent: %s' % type(parent) ) self.setFailed = parent.setFailed threading.Thread.__init__(self) self.stopEvent = threading.Event() # queue for event self.queue = Queue.Queue(0) self.timeoutSleep = timeoutSleep self.__agentSupport = agentSupport self.__agentName = agent self.__agentType = agentType self.__caller = caller self.__adp_id__ = _getNewAdpId() self.__showEvts = showEvts self.__showSentEvts = showSentEvts self.__showRecvEvts = showRecvEvts self.debugMode = debug self.__timers = [] self.__states = [] # new in v19, checking the agent provided check_agent(caller=self.__caller, agent=self.__agentName, agent_support=self.__agentSupport, agent_type=self.__agentType) # end of new self.NAME = self.__class__.__name__.upper() self.timerId = -1 self.matchId = -1 self.name__ = name.upper() self.realname__ = realname self.__testcase = parent self.testcaseId = parent.getId() self.__shared = shared parent.registerComponent( self, shared=shared) self.running = False self.codecXml2Py = Xml2Dict.Xml2Dict() self.codecPy2Xml = Dict2Xml.Dict2Xml(coding = None) self.initStorageData() self.start()
def __init__ (self, userName='******', defLibrary='', defAdapter='', isGlobal=False, timeout="10.0", inputs=[], outputs=[]): """ Data model for test plan <?xml version="1.0" encoding="utf-8" ?> <file> <properties"> <descriptions> <description> <key>author</key> <value>...</value> </description> <description> <key>creation date</key> <value>...</value> </description> <description> <key>summary</key> <value>...</value> </description> <description> <key>prerequisites</key> <value>...</value> </description> <description> <key>comments</key> <value> <comments> <comment> <author>author</author> <datetime>...</datetime> <post>...</post> </comment> .... </comments> </value> </description> </descriptions> <inputs-parameters> <parameter> <name>...</name> <type>...</type> <description>...</description> <value>...</value> </parameter> </inputs-parameters> <outputs-parameters> <parameter> <name>...</name> <type>...</type> <description>...</description> <value>...</value> </parameter> </outputs-parameters> <probes> <probe> <active>...</active> <args>...</args> <name>...</name> </probe> </probes> </properties> <testplan id="0"> <testfile> <id>1</id> <parent>0</parent> <file>/../../..</file> <enable>2|0</enable> <type>local</type> <extension>tsx|tux</extension> <description></description> <alias>....</<alias> <properties"> <parameters> <parameter> <name>...</name> <type>...</type> <description>...</description> <value>...</value> </parameter> </parameters> <probes> <probe> <active>...</active> <args>...</args> <name>...</name> </probe> </probes> </properties> </testfile> <testfile> ... </testfile> </testplan> </file> """ GenericModel.GenericModel.__init__(self) today = datetime.datetime.today() self.dateToday = today.strftime("%d/%m/%Y %H:%M:%S") self.currentUser = userName self.defLibrary = defLibrary self.defAdapter = defAdapter self.isGlobal = isGlobal # new in v17 self.timeout = timeout self.inputs = inputs self.outputs = outputs # end of new self.testName = 'Scenario' if self.isGlobal: self.testName = 'Global Scenario' # init xml encoder self.codecX2D = PyXmlDict.Xml2Dict( ) self.codecD2X = PyDictXml.Dict2Xml( coding = None ) # file content and properties self.testplan = {} self.properties = {} # dev duration self.testdev = time.time() self.reset()