def validate(StmMethodology, StmTestCase, InputJson, EnableTieCheck): plLogger = PLLogger.GetLogger('methodology') plLogger.LogDebug("begin.validate.LoadTestMethodologyCommand") # Check that TestMethodologyName exists stc_sys = CStcSystem.Instance() test_meth = meth_man_utils.get_stm_methodology_from_handle(StmMethodology) if test_meth is None: plLogger.LogError("ERROR: Was unable to find StmMethodology with handle " + str(StmMethodology) + " in the list of installed tests.") return "ERROR: Could not find test." test_meth_name = test_meth.Get('TestMethodologyName') plLogger.LogDebug("test_meth_name: " + test_meth_name) install_dir = meth_man_utils.get_methodology_dir(test_meth_name) os.path.join(stc_sys.GetApplicationCommonDataPath(), mgr_const.MM_TEST_METH_DIR) if not install_dir: return "ERROR: Could not find path to the test." # Check that StmTestCase is in datamodel # If NO StmTestCase is provided, then assume it's the "original" test_case_name = "" if StmTestCase == 0: plLogger.LogDebug("No StmTestCase is provided, use the methodology itself") test_case_name = "original" test_case_path = install_dir else: hnd_reg = CHandleRegistry.Instance() test_case = hnd_reg.Find(StmTestCase) if test_case is None: plLogger.LogError("ERROR: Was unable to find StmTestCase" + " in the list of installed test cases.") return "ERROR: Could not find test case." test_case_name = test_case.Get('TestCaseName') test_case_path = test_case.Get('Path') plLogger.LogDebug("test_case_name: " + test_case_name) plLogger.LogDebug("test_case_path: " + str(test_case_path)) if not os.path.exists(test_case_path): return "ERROR: Could not find path to the test case." full_txml_path = os.path.join(test_case_path, mgr_const.MM_META_FILE_NAME) plLogger.LogDebug("full_txml_path: " + str(full_txml_path)) if os.path.isfile(full_txml_path): test_instance_name = txml_utils.extract_test_case_name_from_file(full_txml_path) plLogger.LogDebug("test_instance_name: " + str(test_instance_name)) if test_instance_name == test_case_name: return "" plLogger.LogDebug("end.validate.LoadTestMethodologyCommand") return "ERROR: Could not find txml file for test case."
def run(StmMethodology, StmTestCase, InputJson, EnableTieCheck): plLogger = PLLogger.GetLogger('methodology') plLogger.LogDebug("begin.run.LoadTestMethodologyCommand") stc_sys = CStcSystem.Instance() # Keep this in to prevent PEP8 errors as the ParentConfig # of the LoadFromXmlCommand is commented out or uncommented out. plLogger.LogDebug("InputJson: " + str(InputJson)) hnd_reg = CHandleRegistry.Instance() ctor = CScriptableCreator() # validate() already checks the existence of StmMethodology and StmTestCase # No need to do the checking again here stm_meth = meth_man_utils.get_stm_methodology_from_handle(StmMethodology) plLogger.LogDebug("stm_meth: " + stm_meth.Get("TestMethodologyName")) test_meth_path = stm_meth.Get("Path") plLogger.LogDebug("test_meth_path: " + str(test_meth_path)) stm_test_case = None # If NO StmTestCase is provided, then assume it's the "original" if StmTestCase == 0: plLogger.LogDebug("stm_test_case: original") test_case_path = test_meth_path else: hnd_reg = CHandleRegistry.Instance() stm_test_case = hnd_reg.Find(StmTestCase) plLogger.LogDebug("stm_test_case: " + stm_test_case.Get("TestCaseName")) test_case_path = stm_test_case.Get("Path") if EnableTieCheck: # In the worst case, a profile test won't fit. If the test isn't # profile based, we currently have no way of determining if it will # run successfully or not. can_run = check_tie_for_profile_based_test(InputJson, stm_test_case) plLogger.LogDebug("test_case_path: " + str(test_case_path)) if not validate_command_on_disk(os.path.join(test_case_path, mgr_const. MM_SEQUENCER_FILE_NAME)): plLogger.LogError("validate_command_on_disk failed for: " + test_meth_path + "/" + mgr_const.MM_SEQUENCER_FILE_NAME) return False # Non profile-based tests can always run.... This is kind of a # strange check until we figure out how to validate non # profile-based tests. can_run = True # Load if can_run: loadCmd = ctor.CreateCommand("LoadFromXml") loadCmd.Set("FileName", os.path.join(test_case_path, mgr_const.MM_SEQUENCER_FILE_NAME)) # FIXME !!!!!! # If the ParentConfig is set to empty string (""), then the GUI works and TCL crashes. # If the ParentConfig is set to project, then the GUI crashes and TCL works # loadCmd.Set("ParentConfig", project.GetObjectHandle()) loadCmd.Execute() if StmTestCase == 0: # Can only do this if we're loading a real test case, not the original meth_man_utils.set_active_test_case(stm_test_case) else: # FIXME: # We obviously need more information here. plLogger.LogError("ERROR: Can not load Test Methodology") return False # Process the ports (now that the config is loaded) # Break the JSON into ports and params sections ports_json = None params_json = None portgroups_json = None if InputJson != "": input_json = json.loads(InputJson) if "portgroups" in input_json.keys(): portgroups_json = input_json["portgroups"] if "params" in input_json.keys(): params_json = input_json["params"] plLogger.LogDebug("calling relocate and bring ports online") # Relocate and bring ports online as necessary if portgroups_json is not None: process_portgroups(portgroups_json) else: process_ports(ports_json) if params_json is not None: plLogger.LogDebug("params_json: " + json.dumps(params_json)) # Fill in the input JSON if it exists sequencer = stc_sys.GetObject("Sequencer") cmd_list = sequencer.GetCollection("CommandList") for cmd_hnd in cmd_list: cmd = hnd_reg.Find(cmd_hnd) if cmd is None: continue if cmd.IsTypeOf("spirent.methodology.manager.MethodologyGroupCommand"): cmd.Set("InputJson", json.dumps(params_json)) break plLogger.LogDebug("end.run.LoadTestMethodologyCommand") return True