Beispiel #1
0
    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)
Beispiel #2
0
 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)
Beispiel #3
0
    def test_find_node_by_address(self):
        node1 = create_node_by_address(self.EXAMPLE_IP[0], False)
        find_node1 = find_node_by_address(self.EXAMPLE_IP[0])
        self.assertEqual(node1, find_node1)
        node1.delete()

        node2 = create_node_by_address(self.EXAMPLE_IP[0], True)
        find_node2 = find_node_by_address(self.EXAMPLE_IP[0])
        self.assertEqual(node2, find_node2)

        find_node2 = find_node_by_address(self.EXAMPLE_REVERSE)
        self.assertEqual(node2, find_node2)
        node2.delete()

        node3 = create_node_by_address(self.EXAMPLE_HOST, False)
        find_node3 = find_node_by_address(self.EXAMPLE_HOST)
        self.assertEqual(node3, find_node3)
        node3.delete()

        node4 = create_node_by_address(self.EXAMPLE_HOST, True)
        find_node4 = find_node_by_address(self.EXAMPLE_HOST)
        self.assertEqual(node4, find_node4)

        find_node4 = find_node_by_address(self.EXAMPLE_IP[0])
        self.assertEqual(node4, find_node4)

        find_node4 = find_node_by_address(self.EXAMPLE_IP[1])
        self.assertEqual(node4, find_node4)
        node4.delete()
Beispiel #4
0
 def test_find_node_by_address(self):
     node1 = create_node_by_address(self.EXAMPLE_IP[0], False)
     find_node1 = find_node_by_address(self.EXAMPLE_IP[0])
     self.assertEqual(node1, find_node1)
     node1.delete()
     
     node2 = create_node_by_address(self.EXAMPLE_IP[0], True)
     find_node2 = find_node_by_address(self.EXAMPLE_IP[0])
     self.assertEqual(node2, find_node2)
     
     find_node2 = find_node_by_address(self.EXAMPLE_REVERSE)
     self.assertEqual(node2, find_node2)
     node2.delete()
     
     node3 = create_node_by_address(self.EXAMPLE_HOST, False)
     find_node3 = find_node_by_address(self.EXAMPLE_HOST)
     self.assertEqual(node3, find_node3)
     node3.delete()
     
     node4 = create_node_by_address(self.EXAMPLE_HOST, True)
     find_node4 = find_node_by_address(self.EXAMPLE_HOST)
     self.assertEqual(node4, find_node4)
     
     find_node4 = find_node_by_address(self.EXAMPLE_IP[0])
     self.assertEqual(node4, find_node4)
     
     find_node4 = find_node_by_address(self.EXAMPLE_IP[1])
     self.assertEqual(node4, find_node4)
     node4.delete()
Beispiel #5
0
 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)
Beispiel #6
0
def interface_to_port(interface, create_new=True):
    """
    Creates a UNIS port from L{psapi.protocol.Interface} object.

    if the a Port already exists for the Interface, it just going to
    return the port instance without creating new Port object.

    see L{port_to_interface}.

    @param interface: L{psapi.protocol.Interface} object   

    @returns: L{topology.models.Port}
    """
    if not isinstance(interface, Interface):
        raise ValueError("interface must be of type psapi.protocol.Interface, "
                        "not %s" % type(interface))

    ipaddress = interface.ipAddress
    ifaddress = interface.ifAddress
    hostname =  interface.hostName
    ifname =  interface.ifName
    # TODO read URN from interface (need updating psapi)

    if hostname is None:
        hostname = interface.ifHostName

    port = find_port(ipaddress, hostname, ifaddress, ifname)

    if not port and create_new:
        try:
            node = Node.objects.get(names__value=hostname)
        except MultipleObjectsReturned:
            raise ValueError("Hostname is not unique")
        except ObjectDoesNotExist:
            node = find_node_by_address(hostname)
            if not node:
                node = create_node_by_address(hostname)

        port = create_port(node, ifaddress=ifaddress, ifname=ifname)

    return port
Beispiel #7
0
    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)