Exemplo n.º 1
0
def send_event_mac_address(mac_address, type_name, description, timestamp):
    """Send an event.

    for :py:class:`~provisioningserver.rpc.region.SendEventMACAddress`.
    """
    try:
        event_type = EventType.objects.get(name=type_name)
    except EventType.DoesNotExist:
        raise NoSuchEventType.from_name(type_name)

    try:
        interface = Interface.objects.get(type=INTERFACE_TYPE.PHYSICAL,
                                          mac_address=mac_address)
    except Interface.DoesNotExist:
        # The node doesn't exist, but we don't raise an exception - it's
        # entirely possible the cluster has started sending events for a node
        # that we don't know about yet. This is most likely to happen when a
        # new node is trying to enlist.
        log.debug(
            "Event '{type}: {description}' sent for non-existent "
            "node with MAC address '{mac}'.",
            type=type_name,
            description=description,
            mac=mac_address,
        )
    else:
        Event.objects.create(
            node=interface.node,
            type=event_type,
            description=description,
            created=timestamp,
        )
Exemplo n.º 2
0
def send_event_ip_address(ip_address, type_name, description, timestamp):
    """Send an event using IP address.

    for :py:class:`~provisioningserver.rpc.region.SendEventIPAddress`.
    """
    try:
        event_type = EventType.objects.get(name=type_name)
    except EventType.DoesNotExist:
        raise NoSuchEventType.from_name(type_name)

    node = Node.objects.filter(interface__ip_addresses__ip=ip_address).first()
    if node is None:
        # The node doesn't exist, but we don't raise an exception - it's
        # entirely possible the cluster has started sending events for a node
        # that we don't know about yet. This is most likely to happen when a
        # new node is trying to enlist.
        log.debug(
            "Event '{type}: {description}' sent for non-existent "
            "node with IP address '{ip_address}'.",
            type=type_name,
            description=description,
            ip_address=ip_address,
        )
    else:
        Event.objects.create(
            node=node,
            type=event_type,
            description=description,
            created=timestamp,
        )
Exemplo n.º 3
0
def send_event(system_id, type_name, description, timestamp):
    """Send an event.

    for :py:class:`~provisioningserver.rpc.region.SendEvent`.
    """
    try:
        event_type = EventType.objects.get(name=type_name)
    except EventType.DoesNotExist:
        raise NoSuchEventType.from_name(type_name)

    try:
        node = Node.objects.get(system_id=system_id)
    except Node.DoesNotExist:
        # The node doesn't exist, but we don't raise an exception - it's
        # entirely possible the cluster has started sending events for a node
        # that we don't know about yet. This is most likely to happen when a
        # new node is trying to enlist.
        log.debug(
            "Event '{type}: {description}' sent for non-existent "
            "node '{node_id}'.",
            type=type_name,
            description=description,
            node_id=system_id,
        )
    else:
        Event.objects.create(
            node=node,
            type=event_type,
            description=description,
            created=timestamp,
        )
Exemplo n.º 4
0
    def test_updates_cache_if_event_type_not_found(self):
        protocol, connecting = self.patch_rpc_methods(
            side_effect=[succeed({}), fail(NoSuchEventType())])
        self.addCleanup((yield connecting))

        ip_address = factory.make_ip_address()
        description = factory.make_name("description")
        event_name = random.choice(list(map_enum(EVENT_TYPES)))
        event_hub = NodeEventHub()

        # Fine the first time.
        yield event_hub.logByIP(event_name, ip_address, description)
        # The cache has been populated with the event name.
        self.assertThat(event_hub._types_registered, Equals({event_name}))
        # Second time it crashes.
        with ExpectedException(NoSuchEventType):
            yield event_hub.logByIP(event_name, ip_address, description)
        # The event has been removed from the cache.
        self.assertThat(event_hub._types_registered, HasLength(0))