def run(ObjectList, TrafficMixTagList): plLogger = PLLogger.GetLogger('methodology') plLogger.LogInfo("ResetRotateTrafficMixWeightsCommand.run()") tml = dm_utils.process_inputs_for_objects(ObjectList, TrafficMixTagList, "StmTrafficMix") for tm in tml: e = etree.fromstring(tm.Get('MixInfo')) # Pull the information we need for this MIX group... load = float(e.get('Load')) load_unit = e.get('LoadUnit') # If the weights have not been rotated yet, then nothing to do... original_weights = e.get('OriginalWeightList') if original_weights is None: continue # Set back to the original weight list... e.set('WeightList', e.get('OriginalWeightList')) tm.Set('MixInfo', etree.tostring(e)) # Reallocate the load based upon the new weights... with AutoCommand('spirent.methodology.traffic.AllocateTrafficMixLoad1Command') as alloc: alloc.Set('StmTrafficMix', tm.GetObjectHandle()) alloc.Set('TagName', '') alloc.Set('Load', load) alloc.Set('LoadUnit', load_unit) alloc.Execute() return True
def run(ObjectList, CurrVal, Iteration, TagList, IgnoreEmptyTags): plLogger = PLLogger.GetLogger('methodology') plLogger.LogInfo("IteratorConfigRotateTrafficMixWeightsCommand.run()") count = int(CurrVal) tml = dm_utils.process_inputs_for_objects(ObjectList, TagList, "StmTrafficMix") for tm in tml: e = etree.fromstring(tm.Get('MixInfo')) # Pull the information we need for this MIX group... load = float(e.get('Load')) load_unit = e.get('LoadUnit') original_weights = e.get('OriginalWeightList') if original_weights is None: e.set('OriginalWeightList', e.get('WeightList')) e.set('WeightList', e.get('OriginalWeightList')) tm.Set('MixInfo', etree.tostring(e)) # The default rotation is to the right, so we need to negate the count to rotate left... rotate_weights(-count, tm) # Reallocate the load based upon the new weights... with AutoCommand('spirent.methodology.traffic.AllocateTrafficMixLoad1Command') as alloc: alloc.Set('StmTrafficMix', tm.GetObjectHandle()) alloc.Set('TagName', '') alloc.Set('Load', load) alloc.Set('LoadUnit', load_unit) alloc.Execute() # The configurator must keep the results framework in sync with the iteration framework. # What we want to do is pass information to the results framework to let it know that # a new iteration is taking place and a meaningful value that it can display. this_cmd = get_this_cmd() update_results_with_current_value('Non-conformant Streams', count, Iteration, this_cmd) return True
def test_process_inputs_for_objects(stc): stc_sys = CStcSystem.Instance() project = stc_sys.GetObject("Project") ctor = CScriptableCreator() dev1 = ctor.Create("EmulatedDevice", project) dev2 = ctor.Create("EmulatedDevice", project) dev3 = ctor.Create("EmulatedDevice", project) dev4 = ctor.Create("EmulatedDevice", project) port = ctor.Create("Port", project) tags = project.GetObject("Tags") assert tags tag1 = ctor.Create("Tag", tags) tag1.Set("Name", "Tag 1") tag2 = ctor.Create("Tag", tags) tag2.Set("Name", "Tag 2") tag1.AddObject(tags, RelationType("UserTag")) tag2.AddObject(tags, RelationType("UserTag")) dev1.AddObject(tag1, RelationType("UserTag")) dev2.AddObject(tag2, RelationType("UserTag")) port.AddObject(tag2, RelationType("UserTag")) # Test normal ProcessInputHandleVec obj_list = dm_utils.process_inputs_for_objects( [dev1.GetObjectHandle(), dev3.GetObjectHandle()], [], "EmulatedDevice" ) assert len(obj_list) == 2 found_dev1 = False found_dev3 = False for obj in obj_list: if obj.GetObjectHandle() == dev1.GetObjectHandle(): found_dev1 = True elif obj.GetObjectHandle() == dev3.GetObjectHandle(): found_dev3 = True assert found_dev1 assert found_dev3 # This one is a bit ugly due to the default host # (might be wrong) host = port.GetObject("Host") assert host obj_list = dm_utils.process_inputs_for_objects([project.GetObjectHandle()], [], "EmulatedDevice") assert len(obj_list) == 5 found_dev1 = True found_dev2 = True found_dev3 = True found_dev4 = True found_default_host = True for obj in obj_list: if obj.GetObjectHandle() == dev1.GetObjectHandle(): found_dev1 = True elif obj.GetObjectHandle() == dev3.GetObjectHandle(): found_dev3 = True elif obj.GetObjectHandle() == dev2.GetObjectHandle(): found_dev2 = True elif obj.GetObjectHandle() == dev4.GetObjectHandle(): found_dev4 = True elif obj.GetObjectHandle() == host.GetObjectHandle(): found_default_host = True assert found_dev1 assert found_dev2 assert found_dev3 assert found_dev4 assert found_default_host obj_list = dm_utils.process_inputs_for_objects([dev3.GetObjectHandle()], ["Tag 1", "Tag 2"], "EmulatedDevice") assert len(obj_list) == 3 found_dev1 = False found_dev2 = False found_dev3 = False for obj in obj_list: if obj.GetObjectHandle() == dev1.GetObjectHandle(): found_dev1 = True elif obj.GetObjectHandle() == dev3.GetObjectHandle(): found_dev3 = True elif obj.GetObjectHandle() == dev2.GetObjectHandle(): found_dev2 = True assert found_dev1 assert found_dev2 assert found_dev3 obj_list = dm_utils.process_inputs_for_objects([dev3.GetObjectHandle()], ["Tag 1", "Tag 2"], "Port") assert len(obj_list) == 1 assert obj_list[0].GetObjectHandle() == port.GetObjectHandle() # Test duplicate removal obj_list = dm_utils.process_inputs_for_objects([dev1.GetObjectHandle()], ["Tag 1"], "EmulatedDevice") assert len(obj_list) == 1 assert obj_list[0].GetObjectHandle() == dev1.GetObjectHandle()
def run(ObjectList, TagList, IgnoreEmptyTags, CurrVal, Iteration, ClassName, PropertyName): plLogger = PLLogger.GetLogger('methodology') plLogger.LogInfo("IteratorConfigPropertyValueCommand.run") # Validate ClassName valid_class, ret_name = dm_utils.validate_classname(ClassName) if not valid_class: plLogger.LogError("Invalid ClassName: " + str(ClassName)) return False # Validate PropertyName prop_list = [p.lower() for p in CMeta.GetProperties(ClassName)] if PropertyName.lower() not in prop_list: plLogger.LogError("Invalid PropertyName: " + str(PropertyName) + " given for class: " + str(ClassName)) return False if not IgnoreEmptyTags: if tag_utils.is_any_empty_tags_given_string_names(TagList, ClassName): plLogger.LogError("No tagged objects for TagList: " + str(TagList)) return False # Find the objects obj_list = dm_utils.process_inputs_for_objects(ObjectList, TagList, ClassName) if len(obj_list) == 0: plLogger.LogInfo("No objects of type " + ClassName + " to configure.") return True plLogger.LogDebug("obj_list contains: " + str(len(obj_list))) # Set the new value prop_meta = CMeta.GetPropertyMeta(ClassName, PropertyName) for obj in obj_list: plLogger.LogDebug("setting obj " + obj.Get("Name") + "'s " + PropertyName + " to " + CurrVal) if prop_meta["isCollection"]: plLogger.LogDebug(PropertyName + " is a collection") try: val_list = ast.literal_eval(CurrVal) if isinstance(val_list, list): obj.SetCollection(PropertyName, [str(val) for val in val_list]) else: obj.SetCollection(PropertyName, [str(val_list)]) except ValueError: plLogger.LogError("Was not able to to set collection " + "property: " + PropertyName + " of " + ClassName + " to " + CurrVal) return False else: # Scalar obj.Set(PropertyName, CurrVal) # Update the results hnd_reg = CHandleRegistry.Instance() this_cmd = hnd_reg.Find(__commandHandle__) res_name = ClassName + "." + PropertyName update_results_with_current_value(res_name, CurrVal, Iteration, this_cmd) return True