예제 #1
0
    def test_event_type_is_registered_on_first_call_only(self):
        protocol, connecting = self.patch_rpc_methods(side_effect=[{}, {}])
        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_detail = EVENT_DETAILS[event_name]
        event_hub = NodeEventHub()

        # On the first call, the event type is registered before the log is
        # sent to the region.
        yield event_hub.logByIP(event_name, ip_address, description)
        self.assertThat(
            protocol.RegisterEventType,
            MockCalledOnceWith(
                ANY,
                name=event_name,
                description=event_detail.description,
                level=event_detail.level,
            ),
        )
        self.assertThat(protocol.SendEventIPAddress, MockCalledOnce())

        # Reset RPC call handlers.
        protocol.RegisterEventType.reset_mock()
        protocol.SendEventIPAddress.reset_mock()

        # On the second call, the event type is known to be registered, so the
        # log is sent to the region immediately.
        yield event_hub.logByIP(event_name, ip_address, description)
        self.assertThat(protocol.RegisterEventType, MockNotCalled())
        self.assertThat(protocol.SendEventIPAddress, MockCalledOnce())
예제 #2
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))
예제 #3
0
파일: test_events.py 프로젝트: zhangrb/maas
    def test__event_is_sent_to_region(self):
        protocol, connecting = self.patch_rpc_methods()
        self.addCleanup((yield connecting))

        ip_address = factory.make_ip_address()
        description = factory.make_name('description')
        event_name = random.choice(list(map_enum(EVENT_TYPES)))

        yield NodeEventHub().logByIP(event_name, ip_address, description)

        self.assertThat(
            protocol.SendEventIPAddress, MockCalledOnceWith(
                ANY, type_name=event_name, ip_address=ip_address,
                description=description))
예제 #4
0
파일: test_events.py 프로젝트: zhangrb/maas
    def test__failure_is_suppressed_if_node_not_found(self):
        protocol, connecting = self.patch_rpc_methods(
            side_effect=[fail(NoSuchNode())])
        self.addCleanup((yield connecting))

        ip_address = factory.make_ip_address()
        description = factory.make_name('description')
        event_name = random.choice(list(map_enum(EVENT_TYPES)))

        yield NodeEventHub().logByIP(event_name, ip_address, description)

        self.assertThat(
            protocol.SendEventIPAddress, MockCalledOnceWith(
                ANY, type_name=event_name, ip_address=ip_address,
                description=description))
예제 #5
0
    def test_event_is_sent_to_region(self):
        protocol, connecting = self.patch_rpc_methods()
        self.addCleanup((yield connecting))

        system_id = factory.make_name("system_id")
        description = factory.make_name("description")
        event_name = random.choice(list(map_enum(EVENT_TYPES)))

        yield NodeEventHub().logByID(event_name, system_id, description)

        self.assertThat(
            protocol.SendEvent,
            MockCalledOnceWith(
                ANY,
                type_name=event_name,
                system_id=system_id,
                description=description,
            ),
        )