Beispiel #1
0
    def test__tryUpdate_logs_errors_from_broken_method(self):
        # Patch the logger in the clusterservice so no log messages are printed
        # because the tests run in debug mode.
        self.patch(common.log, "debug")

        rpc_service, _ = yield prepareRegion(self)
        self.patch_autospec(external, "configure_rack")  # No-op configuration.

        ntp = external.RackNTP()
        service = make_startable_RackExternalService(self, rpc_service,
                                                     reactor, [("NTP", ntp)])
        broken_method = self.patch_autospec(ntp, self.method)
        broken_method.side_effect = factory.make_exception()

        # Ensure that we never actually execute against systemd.
        self.patch_autospec(service_monitor, "restartService")

        yield service.startService()
        self.addCleanup((yield service.stopService))

        self.useFixture(MAASRootFixture())
        with TwistedLoggerFixture() as logger:
            yield service._orig_tryUpdate()

        self.assertThat(
            logger.output,
            DocTestMatches("""
                Failed to update NTP configuration.
                Traceback (most recent call last):
                ...
                maastesting.factory.TestException#...
                """),
        )
Beispiel #2
0
    def test_is_silent_and_does_nothing_when_region_is_not_available(self):
        # Patch the logger in the clusterservice so no log messages are printed
        # because the tests run in debug mode.
        self.patch(common.log, "debug")
        self.useFixture(MAASRootFixture())
        ntp = external.RackNTP()
        service = make_startable_RackExternalService(
            self, StubClusterClientService(), reactor, [("NTP", ntp)])
        self.patch_autospec(ntp, "_tryUpdate")

        yield service.startService()
        self.addCleanup((yield service.stopService))

        with TwistedLoggerFixture() as logger:
            yield service._tryUpdate()

        self.assertThat(logger.output, Equals(""))
        self.assertThat(ntp._tryUpdate, MockNotCalled())
Beispiel #3
0
    def test_is_silent_and_does_nothing_when_rack_is_not_recognised(self):
        # Patch the logger in the clusterservice so no log messages are printed
        # because the tests run in debug mode.
        self.patch(common.log, "debug")
        self.useFixture(MAASRootFixture())
        rpc_service, protocol = yield prepareRegion(self)
        protocol.GetControllerType.side_effect = exceptions.NoSuchNode
        ntp = external.RackNTP()
        service = make_startable_RackExternalService(
            self, StubClusterClientService(), reactor, [("NTP", ntp)])
        self.patch_autospec(ntp, "_tryUpdate")

        yield service.startService()
        self.addCleanup((yield service.stopService))

        with TwistedLoggerFixture() as logger:
            yield service._tryUpdate()

        self.assertThat(logger.output, Equals(""))
        self.assertThat(ntp._tryUpdate, MockNotCalled())
Beispiel #4
0
 def make_RackNTP_ExternalService(self, rpc_service, reactor):
     ntp = external.RackNTP()
     service = make_startable_RackExternalService(
         self, rpc_service, reactor, [("NTP", ntp)]
     )
     return service, ntp