def run(StmMethodology):
    plLogger = PLLogger.GetLogger('methodology')
    plLogger.LogDebug("DeleteMethodologyCommand.run.begin")

    meth_list = CCommandEx.ProcessInputHandleVec("StmMethodology",
                                                 [StmMethodology])
    if len(meth_list) != 1:
        plLogger.LogError("Invalid StmMethodology object")
        return False

    test_meth = meth_list[0]
    if test_meth is None:
        plLogger.LogError("Was unable to find StmMethodology with " +
                          "handle " + StmMethodology +
                          " in the set of installed test cases.")
        return False

    # Do not allow the methodology to be deleted if one of its test
    # cases is currently active (and running)
    active_tc = meth_man_utils.get_active_test_case()
    if active_tc is not None:
        tc_list = test_meth.GetObjects("StmTestCase")
        for tc in tc_list:
            if tc.GetObjectHandle() == active_tc.GetObjectHandle():
                plLogger.LogDebug("Test Methodology " + test_meth.Get("Name") +
                                  " has a current active test case " +
                                  tc.Get("Name") + ".  Checking to see if it" +
                                  " can be deleted.")
                # Check the results to see if the test is still running
                if meth_man_utils.is_test_case_running(tc):
                    plLogger.LogError("Can not delete a methodology with " +
                                      "an actively running test case.")
                    return False
                # Remove the active test case
                meth_man_utils.remove_active_test_relation()
                break

    # Delete the methodology and all configured test cases from
    # the file system
    if meth_man_utils.methodology_rmdir(test_meth.Get("MethodologyKey")):
        plLogger.LogDebug("Successfully deleted " + test_meth.Get("Name") +
                          " from disk")
    else:
        plLogger.LogError("Failed to delete " + test_meth.Get("Name") +
                          " from disk")
        return False

    # Delete the methodology object
    test_meth.MarkDelete()

    plLogger.LogDebug("DeleteMethodologyCommand.run.end")
    return True
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(MethodologyKey, TestCaseKey):
    plLogger = PLLogger.GetLogger('methodology')
    test_meth = meth_man_utils.get_stm_methodology_from_key(MethodologyKey)
    if not test_meth:
        plLogger.LogError("No methodology with key " + MethodologyKey +
                          " exists")
        return False
    this_cmd = get_this_cmd()
    this_cmd.Set('StmMethodology', test_meth.GetObjectHandle())
    if not TestCaseKey:
        return True
    testcase = meth_man_utils.get_stm_testcase_from_key(test_meth,
                                                        TestCaseKey)
    if testcase:
        this_cmd.Set('StmTestCase', testcase.GetObjectHandle())
    else:
        plLogger.LogError("No test case with key " + TestCaseKey +
                          " exists for " + MethodologyKey)
        return False
    return True
def run():
    plLogger = PLLogger.GetLogger('methodology')
    plLogger.LogDebug("begin.run.GetAllTestMethodologiesCommand")
    hnd_reg = CHandleRegistry.Instance()

    installed_meths = []
    install_dir = meth_man_utils.get_methodology_home_dir()

    meth_man = meth_man_utils.get_meth_manager()
    test_meth_list = meth_man.GetObjects("StmMethodology")
    for test_meth in test_meth_list:
        installed_meths.append(test_meth.GetObjectHandle())

    plLogger.LogDebug("installed_meths: " + str(installed_meths))

    this_cmd = hnd_reg.Find(__commandHandle__)
    this_cmd.SetCollection("StmMethodologyList", installed_meths)
    this_cmd.Set("TestMethodologyDir", str(install_dir))

    plLogger.LogDebug("end.run.GetAllTestMethodologiesCommand")
    return True
Esempio n. 5
0
def run(FileName):
    plLogger = PLLogger.GetLogger('methodology')
    plLogger.LogDebug("begin.run.ImportTestCommand")
    plLogger.LogDebug(" FileName: " + FileName)

    stc_sys = CStcSystem.Instance()
    common_data_path = stc_sys.GetApplicationCommonDataPath()
    test_meth_dir = os.path.join(common_data_path,
                                 mgr_const.MM_TEST_METH_DIR)
    if not os.path.exists(test_meth_dir):
        plLogger.LogDebug("Adding testMeth directory: " + str(test_meth_dir))
        os.mkdir(test_meth_dir)

    # Unzip to temp directory
    nice_ts = txml_utils.get_timestamp_ymd_hms()
    temp_dir = os.path.join(test_meth_dir,
                            "temp_" + str(nice_ts))

    if not os.path.exists(temp_dir):
        os.makedirs(temp_dir)

    with zipfile.ZipFile(FileName, "r") as z:
        z.extractall(temp_dir)

    meta_file = os.path.join(temp_dir, mgr_const.MM_TEST_CASE_SUBDIR,
                             mgr_const.MM_META_FILE_NAME)
    seq_file = os.path.join(temp_dir,
                            mgr_const.MM_SEQUENCER_FILE_NAME)

    if not os.path.isfile(meta_file):
        plLogger.LogError("Unable to extract TXML file!")
        return False
    if not os.path.isfile(seq_file):
        plLogger.LogError("Unable to extract sequencer file!")
        return False

    # Read the TXML file for the test name
    test_name = txml_utils.extract_methodology_name_from_file(meta_file)
    if not test_name:
        plLogger.LogError("ERROR: Could not extract test methodology name from the TXML file!")
        return False
    plLogger.LogDebug("test_name: " + test_name)

    if not validate_command_on_disk(seq_file):
        return False

    test_meth_test_dir = os.path.join(test_meth_dir, test_name)
    test_meth_test_case_dir = os.path.join(test_meth_test_dir,
                                           mgr_const.MM_TEST_CASE_SUBDIR)
    plLogger.LogDebug(" test_meth_test_dir: " + str(test_meth_test_dir))
    plLogger.LogDebug(" test_meth_test_case_dir: " + str(test_meth_test_case_dir))

    if not os.path.exists(test_meth_test_dir):
        os.makedirs(test_meth_test_dir)
    if not os.path.exists(test_meth_test_case_dir):
        os.makedirs(test_meth_test_case_dir)

    # FIXME:
    # Need to handle multiple copies of the TXML file
    shutil.copy(seq_file, test_meth_test_dir)
    shutil.copy(meta_file, test_meth_test_case_dir)

    # Add BLL objects
    meth_man_utils.build_test_methodology(test_meth_test_dir, use_txml=True)

    # Clean up
    # Delete the temporary directory and its contents
    os.remove(meta_file)
    os.rmdir(os.path.join(temp_dir, mgr_const.MM_TEST_CASE_SUBDIR))
    os.remove(seq_file)
    os.rmdir(temp_dir)

    plLogger.LogDebug("end.run.ImportTestCommand")
    return True
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
def run(MethodologyJson):
    plLogger = PLLogger.GetLogger("methodology")
    plLogger.LogDebug("CreateMethodologyTestCaseCommand.run")
    this_cmd = get_this_cmd()

    err_str, meta = json_utils.load_json(MethodologyJson)
    if err_str != "":
        plLogger.LogError(err_str)
        this_cmd.Set("Status", err_str)
        return False

    meth_key = meta["methodology_key"]
    meth_obj = meth_man_utils.get_stm_methodology_from_key(meth_key)

    if meth_obj is None:
        plLogger.LogDebug("Invalid methodology key: " + str(meth_key))
        return False
    if not meth_obj.IsTypeOf("StmMethodology"):
        plLogger.LogError("Invalid methodology object: " + meth_obj.Get("Name"))
        return False

    # Get a new test case key
    tc_key = meth_man_utils.get_new_testcase_key(meth_obj)

    # Create a directory for the test case
    plLogger.LogDebug("create a directory under " + meth_obj.Get("Path"))
    target_dir = meth_man_utils.methodology_test_case_mkdir(meth_key, tc_key)
    if not target_dir:
        plLogger.LogError("Failed to create test case directory")
        return False

    source_dir = meth_obj.Get("Path")
    plLogger.LogDebug("Source directory is " + source_dir)
    plLogger.LogDebug("Target directory is " + target_dir)

    # Copy the files from the source directory to the new target directory
    src_files = os.listdir(source_dir)
    for file_name in src_files:
        full_file_name = os.path.join(source_dir, file_name)
        if os.path.isfile(full_file_name):
            shutil.copy(full_file_name, target_dir)

    # Now that the target files are in place, generate the meta file

    meta["test_case_key"] = tc_key
    MethodologyJson = json.dumps(meta)
    plLogger.LogDebug("meta = " + MethodologyJson)
    meta_json_file = os.path.join(target_dir, mgr_const.MM_META_JSON_FILE_NAME)

    # Make sure we can write to the file
    changed_permissions = False
    if os.path.exists(meta_json_file):
        mode = os.stat(meta_json_file)[stat.ST_MODE]
        os.chmod(meta_json_file, mode | stat.S_IWRITE)
        changed_permissions = True

    # Open or create the json file and write to it
    f = open(meta_json_file, "w")
    f.write(MethodologyJson)
    f.close()

    # Put permissions back the way they were
    if changed_permissions:
        os.chmod(meta_json_file, mode)

    # Now create the data model portion that corresponds to the test case
    ctor = CScriptableCreator()
    test_case = ctor.Create("StmTestCase", meth_obj)
    # The meth display_name may not be correct, but it is more informative than nothing...
    test_case.Set("Name", meta["display_name"])
    test_case.Set("TestCaseKey", tc_key)
    test_case.Set("Path", target_dir)

    this_cmd.Set("TestCaseKey", tc_key)

    plLogger.LogDebug("CreateMethodologyTestCaseCommand.run.exit")
    return True
def run(TestCaseSrc, TestCaseName, TestCaseDescription):
    plLogger = PLLogger.GetLogger('methodology')
    plLogger.LogDebug("begin.run.CreateTestCaseCommand")
    hnd_reg = CHandleRegistry.Instance()
    meth_src_obj = hnd_reg.Find(TestCaseSrc)
    meth_obj = None
    if meth_src_obj is None:
        plLogger.LogDebug("Invalid TestCaseSrc handle: " + str(TestCaseSrc))
    if meth_src_obj.IsTypeOf("StmMethodology"):
        meth_obj = meth_src_obj
    elif meth_obj.IsTypeOf("StmTestCase"):
        # TODO: Support creation from another test case
        plLogger.LogError("Test Case creation from existing test cases is not " +
                          "currently supported.")
        meth_obj = meth_src_obj.GetParent()
        return False
    else:
        plLogger.LogError("Invalid source object: " + meth_src_obj.Get("Name"))
        return False

    # Get a new test case key
    tc_key = meth_man_utils.get_new_testcase_key(meth_obj)

    # Create a directory for the test case
    plLogger.LogDebug("create a directory under " + meth_obj.Get("Path"))
    meth_key = meth_obj.Get("MethodologyKey")
    target_dir = meth_man_utils.methodology_test_case_mkdir(meth_key, tc_key)
    if not target_dir:
        plLogger.LogError("Failed to create test case directory")
        return False

    source_dir = meth_obj.Get("Path")
    plLogger.LogDebug("Source directory is " + source_dir)
    plLogger.LogDebug("Target directory is " + target_dir)

    # Copy the files from the source directory to the new target directory
    src_files = os.listdir(source_dir)
    for file_name in src_files:
        full_file_name = os.path.join(source_dir, file_name)
        if (os.path.isfile(full_file_name)):
            shutil.copy(full_file_name, target_dir)

    # Now that the target files are in place, update the metadata file

    # Open the TXML file
    txml_file = os.path.join(target_dir,
                             mgr_const.MM_META_FILE_NAME)
    if not os.path.exists(txml_file):
        plLogger.LogError("ERROR: Can't find " + str(txml_file))
        return False

    # Read the TXML
    txml_tree = etree.parse(txml_file)
    if txml_tree is None:
        plLogger.LogError("ERROR: Could not parse TXML located in " + str(txml_file))
        return False
    txml_root = txml_tree.getroot()
    if txml_root is None:
        plLogger.LogError("ERROR: Could not parse TXML located in " + str(txml_file))
        return False

    # Update the testInfo section with the name of the test case
    child = txml_root.find(meta_man.TEST_INFO)
    if child is not None:
        child.set(meta_man.TI_TEST_CASE_NAME, TestCaseName)
        child.set(meta_man.TI_DESCRIPTION, TestCaseDescription)
        child.set(meta_man.TI_TEST_CASE_KEY, tc_key)

    # Make sure we can write to the file
    mode = os.stat(txml_file)[stat.ST_MODE]
    os.chmod(txml_file, mode | stat.S_IWRITE)

    # Write the txml out to the file
    txml_str = etree.tostring(txml_root)
    f = open(txml_file, "w")
    f.write("<?xml version=\"1.0\" ?>\n")
    f.write(txml_str)
    f.close()

    # Put permissions back the way they were
    os.chmod(txml_file, mode)

    # Now create the data model portion that corresponds to the test case
    ctor = CScriptableCreator()
    test_case = ctor.Create("StmTestCase", meth_obj)
    test_case.Set("Name", TestCaseName)
    test_case.Set("TestCaseKey", tc_key)
    test_case.Set("Path", target_dir)

    this_cmd = get_this_cmd()
    this_cmd.Set("StmTestCase", test_case.GetObjectHandle())

    plLogger.LogDebug("end.run.CreateTestCaseCommand")
    return True
Esempio n. 9
0
def run(TestMethodologyName, InputJson, TestCaseName, FileName):
    plLogger = PLLogger.GetLogger('methodology')
    plLogger.LogDebug("begin.run.SaveTestCaseCommand")

    stc_sys = CStcSystem.Instance()
    project = stc_sys.GetObject("Project")
    ctor = CScriptableCreator()

    # If TestCaseName is "" then overwrite the "original" TXML file
    # Otherwise, create a new TXML file
    is_overwrite = False
    test_case_name = TestCaseName
    if test_case_name == "":
        plLogger.LogDebug("This is an overwrite operation")
        test_case_name = meta_man.TEST_INSTANCE_ORIGINAL
        is_overwrite = True

    plLogger.LogDebug("TestCaseName: " + TestCaseName)
    plLogger.LogDebug("test_case_name: " + test_case_name)
    plLogger.LogDebug("is_overwrite: " + str(is_overwrite))

    if project is None:
        plLogger.LogError("Invalid Project object")
        return False

    # Find the TXML file (source)
    test_meth_path = os.path.join(stc_sys.GetApplicationCommonDataPath(),
                                  mgr_const.MM_TEST_METH_DIR,
                                  TestMethodologyName)
    txml_file = os.path.join(test_meth_path,
                             mgr_const.MM_TEST_CASE_SUBDIR,
                             mgr_const.MM_META_FILE_NAME)
    if not os.path.exists(txml_file):
        plLogger.LogError("ERROR: Can't find " + str(txml_file))
        return False

    # Read the TXML
    txml_tree = etree.parse(txml_file)
    txml_root = txml_tree.getroot()
    plLogger.LogDebug("Processing TXML: " + etree.tostring(txml_root))
    if txml_root is None:
        plLogger.LogError("ERROR: Could not parse TXML located in " + str(txml_file))
        return False

    # Parse the JSON into ports/params
    input_json = json.loads(InputJson)
    new_params_dict = ast.literal_eval(json.dumps(input_json["params"]))
    new_ports_dict = ast.literal_eval(json.dumps(input_json["ports"]))

    plLogger.LogDebug(" new_params_dict: " + str(new_params_dict))
    plLogger.LogDebug(" new_ports_dict: " + str(new_ports_dict))

    for child in txml_root:
        plLogger.LogDebug("Found tag: " + child.tag)
        if child.tag == meta_man.TEST_INFO:
            plLogger.LogDebug("process test info section")
            if not is_overwrite:
                plLogger.LogDebug("Setting new test case name to: " + test_case_name)
                # Change the name of the testCase
                child.set(meta_man.TI_TEST_CASE_NAME, test_case_name)
            else:
                plLogger.LogDebug("Using existing test case name: " +
                                  child.get(meta_man.TI_TEST_CASE_NAME))
        elif child.tag == meta_man.TEST_RESOURCES:
            plLogger.LogDebug("process test resources section")
            PORT_STR = ".//" + meta_man.TR_RESOURCE_GROUPS + \
                       "/" + meta_man.TR_RESOURCE_GROUP + \
                       "/" + meta_man.TR_PORT_GROUPS + \
                       "/" + meta_man.TR_PORT_GROUP + \
                       "/" + meta_man.TR_PORTS + \
                       "/" + meta_man.TR_PORT
            port_list = child.findall(PORT_STR)
            for port in port_list:
                if port.tag == meta_man.TR_PORT:
                    plLogger.LogDebug("Process port: " +
                                      port.get(meta_man.TR_NAME))
                    update_port_tag(port, new_ports_dict)
        elif (child.tag == meta_man.EDITABLE_PARAMS):
            plLogger.LogDebug("process test params section")
            PARAM_STR = ".//" + meta_man.EP_PARAM_GROUPS + \
                        "/" + meta_man.EP_PARAM_GROUP + \
                        "/" + meta_man.EP_PARAMS + \
                        "/" + meta_man.EP_PARAM
            param_list = child.findall(PARAM_STR)
            for param in param_list:
                plLogger.LogDebug("Found param)")
                prop_val = None
                prop_id = None
                # Process attributes
                for attr in param:
                    if attr.tag == meta_man.EP_ATTR:
                        attr_name = attr.get(meta_man.EP_NAME)
                        if attr_name == meta_man.EP_PROP_ID:
                            prop_id = attr.get(meta_man.EP_VALUE)
                        elif attr_name == meta_man.EP_DEFAULT:
                            prop_val = attr.get(meta_man.EP_VALUE)
                            default_val_elem = attr
                plLogger.LogDebug(" prop_val: " + str(prop_val))
                plLogger.LogDebug(" prop_id: " + str(prop_id))
                if prop_id is not None and prop_val is not None:
                    if prop_id in new_params_dict.keys():
                        if default_val_elem is None:
                            plLogger.LogError("ERROR: Could not find XML element for " +
                                              str(prop_id))
                        else:
                            default_val_elem.set(meta_man.EP_VALUE, new_params_dict[prop_id])
                else:
                    plLogger.LogWarn(" prop_id and or prop_val was none - no value to set")

    # Test case path
    tc_path = os.path.join(test_meth_path, mgr_const.MM_TEST_CASE_SUBDIR)
    if not os.path.exists(tc_path):
        os.makedirs(tc_path)

    if is_overwrite is False:
        plLogger.LogDebug(" create a new testcase...")
        # Create new TXML filename (original filename + timestamp)
        if FileName == "":
            nice_ts = txml_utils.get_timestamp_ymd_hms()
            file_prefix = str(os.path.splitext(mgr_const.MM_META_FILE_NAME)[0])
            new_tc_file = file_prefix + "_" + nice_ts + ".txml"
        else:
            new_tc_file = FileName
        plLogger.LogDebug("Writing new Test Case: " + str(new_tc_file))

        full_path = os.path.join(tc_path, new_tc_file)

        # Add a new test case
        meth_man = meth_man_utils.get_meth_manager()
        meth_list = meth_man.GetObjects("StmMethodology")
        for test_meth in meth_list:
            if test_meth.Get("TestMethodologyName") == TestMethodologyName:
                test_case = ctor.Create("StmTestCase", test_meth)
                test_case.Set("TestCaseName", TestCaseName)
                test_case.Set("Path", full_path)

    else:
        plLogger.LogDebug("Overwriting values in existing " +
                          str(mgr_const.MM_META_FILE_NAME))
        full_path = os.path.join(tc_path, mgr_const.MM_META_FILE_NAME)

    txml_str = etree.tostring(txml_root)
    plLogger.LogDebug(" txml_str: " + str(txml_str))
    plLogger.LogDebug(" writing file to " + str(full_path))
    f = open(full_path, "w")
    f.write("<?xml version=\"1.0\" ?>\n")
    f.write(txml_str)
    f.close()

    hnd_reg = CHandleRegistry.Instance()
    this_cmd = hnd_reg.Find(__commandHandle__)
    this_cmd.Set("TxmlFileName", full_path)

    plLogger.LogDebug("end.run.SaveTestCaseCommand")
    return True