def parse_addresses(self, test_spec, src_field, dst_field, ip_version, lead_participant, measurement_agent): #determine source since its optional input_source = lead_participant if src_field and src_field in test_spec: input_source = test_spec[src_field] #get dest if this is point-to-point dest_ip = None if dst_field: self.metadata['subject-type'] = 'point-to-point' self.metadata['input-destination'] = test_spec[dst_field] src_ip, dest_ip = pscheduler.ip_normalize_version(input_source, self.metadata['input-destination'], ip_version=ip_version) else: self.metadata['subject-type'] = 'network-element' src_ip, tmp_ip = pscheduler.ip_normalize_version(input_source, input_source, ip_version=ip_version) #set fields self.metadata['source'] = src_ip if dest_ip: self.metadata['destination'] = dest_ip self.metadata['input-source'] = input_source #Make measurement-agent the created_by_address if we have it, otherwise the lead participant, with same ip type as source if measurement_agent: src_ip, self.metadata['measurement-agent'] = pscheduler.ip_normalize_version(src_ip, measurement_agent) else: src_ip, self.metadata['measurement-agent'] = pscheduler.ip_normalize_version(src_ip, lead_participant)
def parse_addresses(self, test_spec, src_field, dst_field, ip_version, lead_participant, measurement_agent): src_ip = None dest_ip = None input_source = lead_participant input_dest = lead_participant self.metadata['subject-type'] = 'point-to-point' #get source field from URL, then try measurement agent, then fallback to lead if src_field and src_field in test_spec: source_url = test_spec[src_field] source_url_host = urllib.parse.urlparse( test_spec[src_field]).hostname if source_url_host: input_source = source_url_host elif measurement_agent: input_source = measurement_agent #do same thingv we did for source but for dest if dst_field and dst_field in test_spec: dest_url = test_spec[dst_field] dest_url_host = urllib.parse.urlparse( test_spec[dst_field]).hostname if dest_url_host: input_dest = dest_url_host elif measurement_agent: input_dest = measurement_agent #normalize ips src_ip, dest_ip = pscheduler.ip_normalize_version( input_source, input_dest, ip_version=ip_version) # set fields self.metadata['source'] = src_ip self.metadata['destination'] = dest_ip self.metadata['input-source'] = input_source self.metadata['input-destination'] = input_dest #Normalize the measurement agent IP and fallback to lead if not set if measurement_agent: src_ip, self.metadata[ 'measurement-agent'] = pscheduler.ip_normalize_version( src_ip, measurement_agent) else: src_ip, self.metadata[ 'measurement-agent'] = pscheduler.ip_normalize_version( src_ip, lead_participant)
def check_endpoint_limits(limit, spec, spec_source="source", spec_dest="dest", spec_ip_version='ip-version', limit_source="source", limit_dest="dest", limit_endpoint="endpoint"): """ Checks source, dest and endpoint limits given a spec. Args: limit: The limit definition to uses as the evaluation criteria spec: The spec to be evaulated spec_source: optional. The name of the source field in the spec. Defaults to "source". spec_dest: optional. The name of the dest field in the spec. Defaults to "dest". spec_ip_version: optional. The name of the ip-version field in the spec. Defaults to "ip-version". limit_source: optional. The name of the source field in the limit. Defaults to "source". limit_dest: optional. The name of the dest field in the limit. Defaults to "dest". limit_endpoint: optional. The name of the endpoint field in the limit. Defaults to "endpoint". Returns: List of error strings if limit is not passed. Empty list otherwise. """ errors = [] #if no source, dest or endpoint limit then exit immediately has_endpoint_limit = False for ep_limit in [limit_source, limit_dest, limit_endpoint]: if limit.has_key(ep_limit): has_endpoint_limit = True break if not has_endpoint_limit: return errors #init source, dest and ip version ip_version = spec.get(spec_ip_version, None) possible_ip_versions = [4, 6] source = spec.get(spec_source, None) dest = spec[spec_dest] #required source_ip = None dest_ip = None if source is not None: source_ip, dest_ip = pscheduler.ip_normalize_version(source, dest, ip_version=ip_version) if source_ip is None or dest_ip is None: #no use in proceeding if can't be resolved errors.append("{0} {1} and {2} {3} cannot be resolved to IP addresses of the same type".format(spec_source, source, spec_dest, dest)) return errors if ip_version is None: ip_version = pscheduler.ip_addr_version(dest_ip)[0] if ip_version is not None: possible_ip_versions = [ip_version] #check source limit if any if limit.has_key(limit_source): if source_ip is None: errors.append("This test has a limit on the {0} field but the {0} was not specifed. You must specify a {0} to run this test".format(spec_source)) else: errors += check_ip_limit(limit[limit_source], source, ip=source_ip, possible_ip_versions=possible_ip_versions) #check dest limit if any if limit.has_key(limit_dest): errors += check_ip_limit(limit[limit_dest], dest, ip=dest_ip, possible_ip_versions=possible_ip_versions, ) #check endpoint limit if any if limit.has_key(limit_endpoint): if source is None or check_ip_limit(limit[limit_endpoint], source, ip=source_ip, possible_ip_versions=possible_ip_versions): #source does not match if check_ip_limit(limit[limit_endpoint], dest, ip=dest_ip, possible_ip_versions=possible_ip_versions): #dest does not match errors.append("{0} nor {1} matches the IP range set by {2} limit".format(spec_source, spec_dest, limit_endpoint)) return errors
def __init__(self, test_type=None, test_spec=None, lead_participant=None, measurement_agent=None, tool_name=None, run_href=None, summaries=None, duration=None, ts=None, test_result={}, src_field="source", dst_field="dest", ipv_field="ip-version", succeeded_field="succeeded", error_field="error", fast_mode=False ): #init self.metadata = { 'event-types': [] } self.data = [] if not fast_mode: #determine source since its optional input_source = lead_participant if src_field and src_field in test_spec: input_source = test_spec[src_field] #determine if we are forcing an ip-version ip_version = None if ipv_field in test_spec: ip_version = test_spec[ipv_field] #get dest if this is point-to-point src_ip = None dest_ip = None input_dest = None if dst_field: self.metadata['subject-type'] = 'point-to-point' input_dest = test_spec[dst_field] src_ip, dest_ip = pscheduler.ip_normalize_version(input_source, input_dest, ip_version=ip_version) else: self.metadata['subject-type'] = 'network-element' src_ip, tmp_ip = pscheduler.ip_normalize_version(input_source, input_source, ip_version=ip_version) #set fields self.metadata['source'] = src_ip if dest_ip: self.metadata['destination'] = dest_ip self.metadata['input-source'] = input_source if input_dest: self.metadata['input-destination'] = input_dest self.metadata['tool-name'] = tool_name self.metadata['time-duration'] = duration #Make measurement-agent the created_by_address if we have it, otherwise the lead participant, with same ip type as source if measurement_agent: src_ip, self.metadata['measurement-agent'] = pscheduler.ip_normalize_version(src_ip, measurement_agent) else: src_ip, self.metadata['measurement-agent'] = pscheduler.ip_normalize_version(src_ip, lead_participant) #set test type to new value if provided if test_type: self.test_type = test_type #may be overridden by subclass, so use value even if not in constructor params if self.test_type: self.metadata['pscheduler-test-type'] = self.test_type #Handle event types summary_map = DEFAULT_SUMMARIES if summaries: summary_map = summaries for et in self.get_event_types(test_spec=test_spec): self.add_event_type(et, summary_map) if run_href: self.add_event_type('pscheduler-run-href', summary_map) #add extra metadata fields self.add_metadata_fields(test_spec=test_spec) self.add_additional_metadata(test_spec=test_spec) #handle data data_point = { 'ts': ts, 'val': [] } if succeeded_field in test_result and test_result[succeeded_field]: data_field_map = self.get_data_field_map() for field in data_field_map: if field in test_result: if isinstance(test_result[field], dict) and not test_result[field]: #esmond doesn't like empty dicts so skip pass else: data_point['val'].append({ 'event-type': data_field_map[field], 'val': test_result[field]}) self.add_additional_data(data_point=data_point, test_spec=test_spec, test_result=test_result) else: #run failed, record the results msg = "" if error_field in test_result and test_result[error_field]: msg = test_result[error_field] else: msg = "The test failed for an unspecified reason. See the server logs of the testing host(s)." data_point['val'].append({ 'event-type': 'failures', 'val': { 'error': msg }}) #add run-href if run_href: data_point['val'].append({ 'event-type': 'pscheduler-run-href', 'val': { 'href': run_href }}) self.data.append(data_point)