Пример #1
0
    def command_json(self, cmd, params=[]):
        """
		"""
        # prepare agent request
        cmdId = self.getCommandId()
        agentData = {
            'command-id': cmdId,
            'command-name': cmd,
            "command-params": json.dumps(params)
        }

        # send command to agent
        self.debug("request: %s" % agentData)
        self.sendNotifyToAgent(data=agentData)

        # log event
        layerParams = TestTemplates.TemplateLayer(name='')
        i = 1
        for v in params:
            layerParams.addKey("arg%s" % i, "%s" % v)
            i += 1

        tpl = self.encapsule(layer_gui=templates.gui(
            action=cmd, actionId=cmdId, parameters=layerParams))
        self.logSentEvent(shortEvt=cmd, tplEvt=tpl)

        return cmdId
Пример #2
0
    def isActionAccepted(self, timeout=10.0, actionName=None, actionId=None):
        """
		Waits to receive "action accepted" event until the end of the timeout
		
		@param timeout: time max to wait to receive event in second (default=10s)
		@type timeout: float		

		@param actionName:  name action
		@type actionName: string/none

		@param actionId: action id
		@type actionId: string/none
		
		@return: an event matching with the template or none otherwise
		@rtype: templatemessage
		"""
        if not (isinstance(timeout, int) or isinstance(timeout, float)):
            raise TestAdapter.ValueException(
                TestAdapter.caller(),
                "timeout argument is not a float or integer (%s)" %
                type(timeout))

        # construct the expected template
        expected = self.encapsule(layer_gui=templates.gui(
            action=actionName, actionId=actionId, result=ADB_ACTION_OK))

        # try to match the template
        evt = self.received(expected=expected, timeout=timeout)
        return evt
Пример #3
0
    def isActionAccepted(self, timeout=10.0, actionName=None, actionId=None):
        """
		Waits to receive "action accepted" event until the end of the timeout
		
		@param timeout: time max to wait to receive event in second (default=10s)
		@type timeout: float		

		@param actionName:  name action
		@type actionName: string/none

		@param actionId: action id
		@type actionId: string/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
        expected = self.encapsule(layer_gui=templates.gui(
            action=actionName, actionId=actionId, result=ADB_ACTION_OK))

        # try to match the template
        evt = self.received(expected=expected, timeout=timeout)
        return evt
Пример #4
0
    def command_adb(self, params, adb='adb'):
        """
		"""
        # prepare agent request
        cmdId = self.getCommandId()
        agentData = {
            'command-id': cmdId,
            'command-name': ADB_ACTION,
            'sub-command': adb,
            "command-params": params
        }

        # send command to agent
        self.debug("request: %s" % agentData)
        self.sendNotifyToAgent(data=agentData)

        # log event
        layerParams = TestTemplates.TemplateLayer(name=params)

        tpl = self.encapsule(layer_gui=templates.gui(
            action=adb, actionId=cmdId, parameters=layerParams))
        self.logSentEvent(shortEvt="adb %s" % adb, tplEvt=tpl)

        return cmdId
Пример #5
0
    def receivedNotifyFromAgent(self, data):
        """
		Function to reimplement
		"""
        if 'cmd' in data:
            if data['cmd'] == AGENT_EVENT_INITIALIZED:
                tpl = TestTemplates.TemplateMessage()
                layer = TestTemplates.TemplateLayer('AGENT')
                layer.addKey("ready", True)
                layer.addKey(name='name', data=self.cfg['agent']['name'])
                layer.addKey(name='type', data=self.cfg['agent']['type'])
                tpl.addLayer(layer=layer)
                self.logRecvEvent(shortEvt="Agent Is Ready", tplEvt=tpl)
        else:
            try:
                commandId = data['command-id']
                commandName = data['command-name']
                commandResult = data['command-result']
                commandValue = data['command-value']

                result = ADB_ACTION_OK
                if commandResult:
                    result = ADB_ACTION_FAILED

                if isinstance(data['command-value'], dict):
                    if "result" in data['command-value']:
                        commandValue = data['command-value']['result']

                    if "error" in data['command-value']:
                        commandValue = data['command-value']['error']
                        if isinstance(commandValue, dict):
                            error_tpl = TestTemplates.TemplateLayer(name='')
                            for k, v in commandValue.items():
                                error_tpl.addKey("%s" % k, "%s" % v)
                            commandValue = error_tpl

                        result = ADB_ACTION_FAILED

                if commandName == ADB_DEVICEINFO_ACTION:
                    deviceInfo = TestTemplates.TemplateLayer(name='')

                    for k in commandValue.keys():
                        deviceInfo.addKey(k, commandValue[k])
                    tpl = self.encapsule(
                        layer_gui=templates.gui(action=commandName,
                                                actionId=commandId,
                                                result=result,
                                                value=deviceInfo))
                    self.logRecvEvent(shortEvt="%s [result=%s]" %
                                      (commandName, result),
                                      tplEvt=tpl)

                elif commandName == JSON_EXIST_ACTION:
                    if not commandValue: result = ADB_ACTION_FAILED
                    tpl = self.encapsule(
                        layer_gui=templates.gui(action=commandName,
                                                actionId=commandId,
                                                result=result,
                                                value=commandValue))
                    self.logRecvEvent(shortEvt="%s [result=%s]" %
                                      (commandName, result),
                                      tplEvt=tpl)

                elif commandName == JSON_WAITELEMENT_ACTION:
                    if not commandValue: result = ADB_ACTION_FAILED
                    tpl = self.encapsule(
                        layer_gui=templates.gui(action=commandName,
                                                actionId=commandId,
                                                result=result,
                                                value=commandValue))
                    self.logRecvEvent(shortEvt="%s [result=%s]" %
                                      (commandName, result),
                                      tplEvt=tpl)

                else:
                    tpl = self.encapsule(
                        layer_gui=templates.gui(action=commandName,
                                                actionId=commandId,
                                                result=result,
                                                value=commandValue))
                    self.logRecvEvent(shortEvt="%s [result=%s]" %
                                      (commandName, result),
                                      tplEvt=tpl)

            except Exception as e:
                self.error('received notify: %s' % e)