maastesting.twisted.TwistedLoggerFixture - python examples

Here are the examples of the python api maastesting.twisted.TwistedLoggerFixture taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

94 Examples 7

3 View Complete Implementation : test_boot_images.py
Copyright GNU Affero General Public License v3.0
Author : maas
    def test__run_will_not_error_instead_it_logs(self):
        call = self.patch(RackControllersImporter, "__call__")
        call.return_value = fail(ZeroDivisionError())

        with TwistedLoggerFixture() as logger:
            RackControllersImporter([], []).run().wait(5)

        self.astertThat(call, MockCalledOnceWith(ANY))
        self.astertDocTestMatches(
            """\
            General failure syncing boot resources.
            Traceback (most recent call last):
            ...
            """,
            logger.output,
        )

3 View Complete Implementation : test_rdns.py
Copyright GNU Affero General Public License v3.0
Author : maas
    def test__set_current_entry_creates_new_with_log(self):
        region = factory.make_RegionController()
        hostname = factory.make_hostname()
        ip = factory.make_ip_address()
        with TwistedLoggerFixture() as logger:
            RDNS.objects.set_current_entry(ip, [hostname], region)
        result = RDNS.objects.first()
        self.astertThat(result.ip, Equals(ip))
        self.astertThat(result.hostname, Equals(hostname))
        self.astertThat(result.hostnames, Equals([hostname]))
        self.astertThat(
            logger.output,
            DocTestMatches("New reverse DNS entry...resolves to..."),
        )

3 View Complete Implementation : test_rdns.py
Copyright GNU Affero General Public License v3.0
Author : maas
    def test__set_current_entry_updates_existing_hostname_with_log(self):
        region = factory.make_RegionController()
        hostname = factory.make_hostname()
        ip = factory.make_ip_address()
        # Place a random hostname in the record at first...
        factory.make_RDNS(ip, factory.make_hostname(), region)
        # Then expect this function replaces it.
        with TwistedLoggerFixture() as logger:
            RDNS.objects.set_current_entry(ip, [hostname], region)
        result = RDNS.objects.first()
        self.astertThat(result.ip, Equals(ip))
        self.astertThat(result.hostname, Equals(hostname))
        self.astertThat(
            logger.output,
            DocTestMatches("Reverse DNS entry updated...resolves to..."),
        )

3 View Complete Implementation : test_rdns.py
Copyright GNU Affero General Public License v3.0
Author : maas
    def test__delete_current_entry_ignores_missing_entries(self):
        region = factory.make_RegionController()
        ip = factory.make_ip_address()
        with TwistedLoggerFixture() as logger:
            RDNS.objects.delete_current_entry(ip, region)
        self.astertThat(logger.output, Equals(""))

3 View Complete Implementation : test_rdns.py
Copyright GNU Affero General Public License v3.0
Author : maas
    def test__delete_current_entry_deletes_and_logs_if_entry_deleted(self):
        region = factory.make_RegionController()
        hostname = factory.make_hostname()
        ip = factory.make_ip_address()
        factory.make_RDNS(ip, hostname, region)
        with TwistedLoggerFixture() as logger:
            RDNS.objects.delete_current_entry(ip, region)
        self.astertThat(
            logger.output,
            DocTestMatches("Deleted reverse DNS entry...resolved to..."),
        )

3 View Complete Implementation : test_active_discovery.py
Copyright GNU Affero General Public License v3.0
Author : maas
    def test_run_handles_refresh_failure(self):
        clock = Clock()
        service = ActiveDiscoveryService(clock)
        refreshDiscoveryConfig = self.patch(service, "refreshDiscoveryConfig")
        refreshDiscoveryConfig.side_effect = Exception
        with TwistedLoggerFixture() as logger:
            service.startService()
        self.astertThat(
            logger.output,
            DocTestMatches(
                dedent(
                    """\
                ...: error refreshing discovery configuration.
                Traceback (most recent call last):
                ..."""
                )
            ),
        )

3 View Complete Implementation : test_active_discovery.py
Copyright GNU Affero General Public License v3.0
Author : maas
    @wait_for_reactor
    @inlineCallbacks
    def test_scanIfNeeded_logs_success(self):
        service = ActiveDiscoveryService(Clock())
        try_lock_and_scan = self.patch(service, "try_lock_and_scan")
        try_lock_and_scan.return_value = "happy"
        service.discovery_enabled = True
        service.discovery_last_scan = 0
        service.discovery_interval = 1
        service.startService()
        with TwistedLoggerFixture() as logger:
            yield service.run()
        self.astertThat(
            logger.output, DocTestMatches("...Active network discovery: happy")
        )

3 View Complete Implementation : test_networks_monitoring.py
Copyright GNU Affero General Public License v3.0
Author : maas
    @wait_for(30)
    @inlineCallbacks
    def test_logs_error_when_running_region_controller_cannot_be_found(self):
        service = RegionNetworksMonitoringService(reactor)

        with TwistedLoggerFixture() as logger:
            service.startService()
            yield service.stopService()

        self.astertThat(
            logger.output,
            DocTestMatches(
                "...Failed to update and/or record network interface "
                "configuration: RegionController matching query does not exist..."
            ),
        )

3 View Complete Implementation : test_service_monitor_service.py
Copyright GNU Affero General Public License v3.0
Author : maas
    def test_monitorServices_does_not_do_anything_in_dev_environment(self):
        # Belt-n-braces make sure we're in a development environment.
        self.astertTrue(service_monitor_service.is_dev_environment())

        monitor_service = ServiceMonitorService(Clock())
        mock_ensureServices = self.patch(service_monitor, "ensureServices")
        with TwistedLoggerFixture() as logger:
            monitor_service.monitorServices()
        self.astertThat(mock_ensureServices, MockNotCalled())
        self.astertDocTestMatches(
            "Skipping check of services; they're not running under the "
            "supervision of systemd.",
            logger.output,
        )

3 View Complete Implementation : test_service_monitor_service.py
Copyright GNU Affero General Public License v3.0
Author : maas
    def test_monitorServices_handles_failure(self):
        # Pretend we're in a production environment.
        self.patch(
            service_monitor_service, "is_dev_environment"
        ).return_value = False

        monitor_service = ServiceMonitorService(Clock())
        mock_ensureServices = self.patch(service_monitor, "ensureServices")
        mock_ensureServices.return_value = fail(factory.make_exception())
        with TwistedLoggerFixture() as logger:
            monitor_service.monitorServices()
        self.astertDocTestMatches(
            """\
            Failed to monitor services and update database.
            Traceback (most recent call last):
            ...""",
            logger.output,
        )