def on_complete(failed_commands): plLogger = PLLogger.GetLogger('methodology') this_cmd = get_this_cmd() ctor = CScriptableCreator() # We don't do anything if one of the hierarchy commands failed... if failed_commands is not None and len(failed_commands) > 0: err_str = 'CreateRouteMixCommand.on_complete(): ' \ 'No additional processing due to child command failure.' plLogger.LogError(err_str) this_cmd.Set("Status", err_str) return False mix_hnd = this_cmd.Get("StmTemplateMix") hnd_reg = CHandleRegistry.Instance() mix = hnd_reg.Find(mix_hnd) err_str, mix_info = json_utils.load_json(mix.Get("MixInfo")) if err_str != "": plLogger.LogError(err_str) this_cmd.Set("Status", err_str) return False if this_cmd.Get('AutoExpandTemplateMix'): cmd = ctor.CreateCommand(RPKG + ".ExpandRouteMixCommand") # Pass these through to the expand cmd.SetCollection("TargetObjectList", this_cmd.GetCollection('TargetObjectList')) cmd.SetCollection("TargetObjectTagList", this_cmd.GetCollection('TargetObjectTagList')) # New StmTemplateMix object made by our CreateTemplateConfig operations cmd.SetCollection("SrcObjectList", [mix_hnd]) # Not doing a cmd.Set("SrcObjectTagList")... It's unclear when someone would. cmd.Set("RouteCount", float(mix_info.get('routeCount', 0))) cmd.Execute() if cmd.Get("PassFailState") != "PASSED": err_str = "Failed to expand RouteMix: " + mix.Get("Name") + \ " with handle " + str(mix_hnd) + ": " + cmd.Get("Status") plLogger.LogError(err_str) this_cmd.Set("Status", err_str) cmd.MarkDelete() return False cmd.MarkDelete() err_str, tag_dict = json_utils.load_json( this_cmd.Get('GroupCommandTagInfo')) if err_str != "": plLogger.LogError(err_str) this_cmd.Set("Status", err_str) return False mix_utils.on_complete_remove_tags([tag_name for tag_name in tag_dict]) return True
def on_complete(failed_commands): plLogger = PLLogger.GetLogger("Methodology") this_cmd = get_this_cmd() ctor = CScriptableCreator() hnd_reg = CHandleRegistry.Instance() # We don't do anything if one of the hierarchy commands failed... if failed_commands is not None and len(failed_commands) > 0: err_str = "CreateTrafficMixCommand.on_complete(): " + \ "No additional processing due to child command failure." plLogger.LogError(err_str) this_cmd.Set("Status", err_str) return False mix_hnd = this_cmd.Get("StmTemplateMix") mix = hnd_reg.Find(mix_hnd) err_str, mix_info = json_utils.load_json(mix.Get("MixInfo")) if err_str != "": plLogger.LogError(err_str) this_cmd.Set("Status", err_str) return False portGroupList = this_cmd.GetCollection("PortGroupTagList") # Mix Info has list in same order as created, for Expand if (this_cmd.Get("AutoExpandTemplateMix")): cmd = ctor.CreateCommand(PKG + ".ExpandProtocolMixCommand") cmd.Set("StmTemplateMix", mix_hnd) cmd.Set("DeviceCount", int(mix_info["deviceCount"])) cmd.SetCollection("PortGroupTagList", portGroupList) cmd.Execute() if cmd.Get("PassFailState") != "PASSED": err_str = "Failed to expand ProtocolMix: " + mix.Get("Name") + \ " with handle " + str(mix_hnd) + ": " + cmd.Get("Status") plLogger.LogError(err_str) this_cmd.Set("Status", err_str) cmd.MarkDelete() return False cmd.MarkDelete() err_str, tag_dict = json_utils.load_json( this_cmd.Get('GroupCommandTagInfo')) if err_str != "": plLogger.LogError(err_str) this_cmd.Set("Status", err_str) mix_utils.on_complete_remove_tags([tag_name for tag_name in tag_dict]) return True
def on_complete(failed_commands): plLogger = PLLogger.GetLogger('Methodology') this_cmd = get_this_cmd() ctor = CScriptableCreator() # We don't do anything if one of the hierarchy commands failed... if failed_commands is not None and len(failed_commands) > 0: plLogger.LogError('CreateTrafficMixCommand.on_complete(): ' + 'No additional processing due to child command failure.') return False mix_hnd = this_cmd.Get("StmTemplateMix") hnd_reg = CHandleRegistry.Instance() mix = hnd_reg.Find(mix_hnd) err_str, mix_info = json_utils.load_json(mix.Get("MixInfo")) if err_str != "": plLogger.LogError(err_str) this_cmd.Set("Status", err_str) return False if this_cmd.Get('AutoExpandTemplateMix'): cmd = ctor.CreateCommand(TPKG + ".ExpandTrafficMixCommand") cmd.Set("StmTemplateMix", mix_hnd) cmd.Set("Load", float(mix_info["load"])) cmd.Set("LoadUnit", mix_info["loadUnits"]) cmd.Execute() if cmd.Get("PassFailState") != "PASSED": err_str = "Failed to expand TrafficMix: " + mix.Get("Name") + \ " with handle " + str(mix_hnd) + ": " + cmd.Get("Status") plLogger.LogError(err_str) this_cmd.Set("Status", err_str) cmd.MarkDelete() return False cmd.MarkDelete() err_str, tag_dict = json_utils.load_json( this_cmd.Get('GroupCommandTagInfo')) if err_str != "": plLogger.LogError(err_str) this_cmd.Set("Status", err_str) return False mix_utils.on_complete_remove_tags([tag_name for tag_name in tag_dict]) return True
def test_on_complete_remove_tags(stc): ctor = CScriptableCreator() project = CStcSystem.Instance().GetObject('project') tags = project.GetObject('Tags') # Create two tags tag1 = ctor.Create('Tag', tags) tag1.Set('Name', 'Tag1') tag2 = ctor.Create('Tag', tags) tag2.Set('Name', 'Tag2') # Check tags exist tag_list = tag_utils.get_tag_objects_from_string_names(['Tag1', 'Tag2']) assert len(tag_list) == 2 # Remove one of the tags and check only one exists mix_utils.on_complete_remove_tags('Tag2') tag_list = tag_utils.get_tag_objects_from_string_names(['Tag1', 'Tag2']) assert len(tag_list) == 1
def on_complete(failed_commands): plLogger = PLLogger.GetLogger("Methodology") this_cmd = get_this_cmd() ctor = CScriptableCreator() hnd_reg = CHandleRegistry.Instance() ''' # THINK THIS PART IS NOT NEEDED HERE AND SHOULD BE DONE ELSEWHERE # UPDATING MIX INFO WITH UPDATED INFORMATION, IE CALC DEVICE COUNT # Generate Mix Info # From table: Weight, UseBlock # From command: PortGroupTag, DeviceCount, TagPrefix mix_info = {} table_data = this_cmd.Get("TableData") dev_count = this_cmd.Get("DeviceCount") port_group_tag = this_cmd.Get("PortGroupTagList") tag_prefix = this_cmd.Get("TagPrefixList") mix_info["deviceCount"] = dev_count mix_info["templateInfo"] = [] tableData = json.loads(table_data) for row in tableData: weight = row["weight"] plLogger.LogInfo("row with new weight: " + str(weight)) static_dev_count = row["staticDeviceCount"] use_static_dev_count = row["useStaticDeviceCount"] use_block = row["useBlock"] device_tag = row["deviceTag"] template_info = {} template_info["weight"] = weight template_info["staticDeviceCount"] = static_dev_count template_info["useStaticDeviceCount"] = use_static_dev_count template_info["useBlock"] = use_block template_info["portGroupTag"] = port_group_tag template_info["deviceTag"] = tag_prefix + device_tag mix_info["templateInfo"].append(template_info) if (use_static_dev_count and (static_dev_count > dev_count)): plLogger.LogError("ERROR: staticDeviceCount (" + str(static_dev_count) + ") cannot be greater than the total device count (" + str(dev_count) + ")") return False plLogger.LogDebug("MixInfo: " + json.dumps(mix_info)) proto_mix_hnd = this_cmd.Get("StmTemplateMix") proto_mix = hnd_reg.Find(proto_mix_hnd) proto_mix.Set("MixInfo", json.dumps(mix_info)) ''' # We don't do anything if one of the hierarchy commands failed... if failed_commands is not None and len(failed_commands) > 0: plLogger.LogError('CreateTrafficMix2Command.on_complete(): ' + 'No additional processing due to child command failure.') return False mix_hnd = this_cmd.Get("StmTemplateMix") mix = hnd_reg.Find(mix_hnd) mix_info = json_utils.load_json(mix.Get("MixInfo")) # dev_count = mix_info["deviceCount"] # Mix Info has list in same order as created, for Expand if (this_cmd.Get("AutoExpandTemplateMix")): cmd = ctor.CreateCommand(PKG + ".ExpandProtocolMixCommand") cmd.Set("StmTemplateMix", mix_hnd) cmd.Set("DeviceCount", int(mix_info["deviceCount"])) cmd.Execute() if cmd.Get("PassFailState") != "PASSED": err_str = "Failed to expand ProtocolMix: " + mix.Get("Name") + \ " with handle " + str(mix_hnd) + ": " + cmd.Get("Status") plLogger.LogError(err_str) this_cmd.Set("Status", err_str) cmd.MarkDelete() return False cmd.MarkDelete() tag_dict = json_utils.load_json(this_cmd.Get('GroupCommandTagInfo')) mix_utils.on_complete_remove_tags([tag_name for tag_name in tag_dict]) return True