Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. The below python script will invoke AutomaticsTapApi java class in Automatics Core to get the current execution mode if available AutomaticsTapAPI.py


    Code Block
    languagepy
    titleAutomaticsTapApi.py
    linenumberstrue
    # Boiler plate stuff to start the module
    import json
    import os
    import jpype
    import jpype.imports
    from jpype.types import *
    
    import logging
    
    logger = logging.getLogger()
    
    
    # Launch the JVM
    def launchJVM(automaticsPropsUrl,pathToExecJar):
        if jpype.isJVMStarted():
            logger.info('JVM is already running. Do not init twice!')
        else:
            logger.info('Inside else')
            logger.info(jpype.getDefaultJVMPath())
            javaClassPath = "-Djava.class.path="+pathToExecJar
            propsJavaOpts = "-Dautomatics.properties.file="+automaticsPropsUrl
            jpype.startJVM(jpype.getDefaultJVMPath(), "-ea", javaClassPath, propsJavaOpts)
    
    
    
    
    # tapApi = AutomaticsTapApi.getInstance()
    
            # import the Java modules
    from com.automatics.tap import AutomaticsTapApi
    from com.automatics.executor import PythonScriptExecutor
    from com.automatics.utils import BeanUtils
    
    
    def createDeviceObj(deviceJson):
        pyexecutor = PythonScriptExecutor()
        deviceObj = pyexecutor.convertJsonToDevice(deviceJson)
        return deviceObj
    
    
    def executeCommandUsingSsh(dut, command):
        pyexecutor = PythonScriptExecutor()
        return pyexecutor.executeCommandUsingSsh(dut, command)
    
    
    def getInstance():
        jpype.JClass("com.automatics.core.SupportedModelHandler").main([])
        BeanUtils.startContext()
        return AutomaticsTapApi.getInstance()
      
  2. Sample code for an Automatics Test Case Written in Python and which use Utils and Core APIs for different operations 

    Code Block
    languagepy
    titleSample Automatics Python Script
    linenumberstrue
    import logging
    
    from jpype.types import *
    from com.automatics.rdkb.utils import BroadBandCommonUtils
    
    from automaticsPythonLib.annotation.PythonScriptAnnotation import TestCaseId
    from automaticsPythonLib.automatics import AutomaticsTapApi
    
    logger = logging.getLogger()
    
    
    @TestCaseId('TC-RDKB-FSPYTHON-LAYOUTTEST-001')
    def nvramFileSystemLayoutcheckImageVersionInDevice(dut):
        testCaseId = "TC-RDKB-FSPYTHON-LAYOUTTEST-001";
        tapEnv = AutomaticsTapApi.getInstance()
        stepNum = "s1S1";
        errorMessage = "nvramcommand isexecution notin properly mounted after code downloaddevice failed";
        status = JBoolean(False);
        logger.info("#######################################################################################");
        logger.info("STARTING TEST CASE: TC-RDKB-FSPYTHON-LAYOUTTEST-1001001");
        logger.info("TEST DESCRIPTION: nvramValidation fileof systemdevice layout validationversion");
    
        logger.info("TEST STEPS : ");
        logger.info("1. CheckRun whethera nvramCommand isin properlythe mounteddevice andVIA itSSH hasto read-parse write permission after code download");
        logger.info("2. Verify the file access by creating a dummy file in nvramthe version.txt file");
    
        logger.info("#######################################################################################");
    
        try:
            logger.info("**********************************************************************************");
    
            logger.info("**********************************************************************************");
            logger.info(
                "STEP 1: DESCRIPTION : Check whether nvram is properly mounted and itValidate hasthe read-version writeof permissionthe afterdevice code download");
            logger.info(
                "STEP 1: ACTION : \"checkRun mounteda statuscommand usingin mountthe command(mountdevice |to grepview -w \"nvram\") and verify read-write permission in nvramthe current RDK version in device\"");
            logger.info(
                "STEP 1: EXPECTED : nvramThe shouldcurrent beversion properlyin mountedthe anddevice should havebe read-write permission(mtd:data on /nvram type jffs2 (rw,relatime)received as response");
            logger.info("**********************************************************************************");
    
            response = tapEnv.executeCommandUsingSsh(dut, JString("mount | grep -w nvramcat /version.txt"));
            logger.info(response)
        except Exception as e:
            logger.info(str(e))
        finally:
            logger.info("################### STARTING POST-CONFIGURATIONS ###################");
            logger.info("POST-CONDITION STEPS");
            logger.info("POST-CONDITION : DESCRIPTION : Remove dummy file");
            logger.info("POST-CONDITION : ACTION : Remove the dummy file permanently (rm -rf  /nvram/dummytest.sh)");
            logger.info("POST-CONDITION : EXPECTED : Created dummy file should be removed");
    
            status = BroadBandCommonUtils.removeFileAndVerifyStatus(tapEnv, dut, JString("/nvram/dummytest.sh"));
    
            if status:
                logger.info("POST-CONDITION : ACTUAL : Post condition executed successfully");
            else:
                logger.info("POST-CONDITION : ACTUAL : Post condition failed");
    
            logger.info("POST-CONFIGURATIONS : FINAL STATUS - " + str(status));
            tapEnv.updateExecutionStatus(dut, testCaseId, stepNum, JBoolean(status), errorMessage, JBoolean(False));
            logger.info("################### COMPLETED POST-CONFIGURATIONS ###################");
Code Block
languagepy
titleSample PYTEST Test case
linenumberstrue
from unittest import result

import pytest
import logging
from jpype.types import *

from automaticsPythonLib.annotation.PythonScriptAnnotation import TestCaseId
from automaticsPythonLib.automatics import AutomaticsTapApi

logger = logging.getLogger()

@TestCaseId('TC-RDKB-PYTHON-PY-TEST-001')
def test_command_execution_in_device():
    dut = pytest.Config.dut
    tapEnv = pytest.Config.tapEnv
    testCaseId = "TC-RDKB-PYTHON-PY-TEST-001";
    stepNum = "S1";
    errorMessage = "command execution in device failed";
    status = JBoolean(False);
    expected_result = False
    print(dut)
    response = tapEnv.executeCommandUsingSsh(dut, JString("pwd"));
    if not response:
        status = JBoolean(False);
    else:
        expected_result=True
        status = JBoolean(True);
    tapEnv.updateExecutionStatus(dut, testCaseId, stepNum, JBoolean(status), errorMessage, JBoolean(False));
    assert expected_result == True, f"Expected {expected_result}, but got {response}"