def test_create_psservice(self): service_name = 'test service' service_type = 'test' service_description = 'this is a test service' event_types = [events.SUMMARY, events.ECHO] service_accesspoint = "http://%s:9995/test" % self.EXAMPLE_IP[0] service = create_psservice(service_name, service_accesspoint, service_type, service_description, event_types) node = find_node_by_address(self.EXAMPLE_IP[0]) self.assertEqual(service.parent, node) self.assertEqual( service.names.get(value=service_name).value, service_name) props = service.properties_bag.all()[0].psserviceproperties self.assertEqual(props.serviceName, service_name) self.assertEqual(props.accessPoint, service_accesspoint) self.assertEqual(props.serviceType, service_type) self.assertEqual(props.serviceDescription, service_description) for event in event_types: self.assertEqual(props.eventTypes.filter(value=event).count(), 1) service.delete() service2 = create_psservice(service_name, service_accesspoint, service_type, service_description, event_types) # should be the same node self.assertEqual(service2.parent, node)
def test_create_psservice(self): service_name = 'test service' service_type = 'test' service_description = 'this is a test service' event_types = [events.SUMMARY, events.ECHO ] service_accesspoint = "http://%s:9995/test" % self.EXAMPLE_IP[0] service = create_psservice(service_name, service_accesspoint, service_type, service_description, event_types) node = find_node_by_address(self.EXAMPLE_IP[0]) self.assertEqual(service.parent, node) self.assertEqual(service.names.get(value=service_name).value, service_name) props = service.properties_bag.all()[0].psserviceproperties self.assertEqual(props.serviceName, service_name) self.assertEqual(props.accessPoint, service_accesspoint) self.assertEqual(props.serviceType, service_type) self.assertEqual(props.serviceDescription, service_description) for event in event_types: self.assertEqual(props.eventTypes.filter(value=event).count(), 1) service.delete() service2 = create_psservice(service_name, service_accesspoint, service_type, service_description, event_types) # should be the same node self.assertEqual(service2.parent, node)
def add_gls(gls_url): """ Adds new gLS service to the periscope services database. @param gls_url: The URL for the gLS. @type gls_url: URL string @return: L{periscope.topology.models.Service} """ logger.info("Adding root hint: %s" % gls_url) gls = create_psservice(gls_url, gls_url, 'gLS', 'Root Hint', [events.SUMMARY]) return gls
def test_find_service_watch(self): service_name = 'test service' service_type = 'test' service_description = 'this is a test service' service_accesspoint = "http://%s:9995/test" % self.EXAMPLE_IP[0] event = EventType.objects.create(value=events.NET_UTILIZATION) service = create_psservice(service_name, service_accesspoint, service_type, service_description) node = find_node_by_address(self.EXAMPLE_IP[0]) self.assertIsNone(find_service_watch(node, events.NET_UTILIZATION)) watch = psServiceWatchList.objects.create(service=service, event_type=event, network_object=node) services_find = find_service_watch(node, events.NET_UTILIZATION) self.assertEqual(len(services_find), 1) self.assertEqual(services_find[0], service)
def save_lookup_service_result(result_set, print_services=False): """ Saves the services and their assoicated data to L{periscope.topology.models.psServiceWatchList}. @param result_set: Lookup (gLS/hLS) service result. @type result_set: L{psapi.client.ResultSet}, or raw XML @param print_services: if True the service names will be printed to stdout. @type print_services: boolean @returns: None """ # first parsed the results services = parse_lookup_service_result(result_set) # Register perfSONAR services registered with the lookup service for psservice in services: # perfSONAR services if isinstance(psservice['service'], PsService): service_name = psservice['service'].serviceName access_point = psservice['service'].accessPoint service_type = psservice['service'].serviceType service_description = psservice['service'].serviceDescription #Network topology service elif isinstance(psservice['service'], NMBService): service_name = psservice['service'].name access_point = psservice['service'].address service_type = psservice['service'].type service_description = psservice['service'].description address_type = get_address_type(access_point) if address_type != 'url': access_point = address_type + "://" + access_point else: raise ValueError("undefined service: %s" % type(psservice['service'])) if isinstance(psservice['service'], PsService): # Create UNIS service instance try: service = create_psservice(service_name, access_point, service_type, service_description, psservice['event_types']) except Exception as exp: logger.warn(exp) continue if print_services: print "Adding: %s, %s, %s, %s" % (service_name, access_point, service_type, service_description) # Register meta data assoicated with the service for i in range(len(psservice['data'])): try: net_obj = register_metadata(service, psservice['data'][i].data) except Exception as exp: logger.warn(exp) continue if net_obj and print_services: print "Registered:", net_obj