Exemplo n.º 1
0
    def test_process_updates_zones_logs_reason_for_single_update(self):
        # Create some fake serial updates with sources for the update.
        def _create_publications():
            return [
                DNSPublication.objects.create(
                    source=factory.make_name("reason")) for _ in range(2)
            ]

        publications = yield deferToDatabase(_create_publications)
        service = RegionControllerService(sentinel.listener)
        service.needsDNSUpdate = True
        service.previousSerial = publications[0].serial
        dns_result = (
            publications[-1].serial,
            True,
            [factory.make_name("domain") for _ in range(3)],
        )
        mock_dns_update_all_zones = self.patch(region_controller,
                                               "dns_update_all_zones")
        mock_dns_update_all_zones.return_value = dns_result
        mock_check_serial = self.patch(service, "_checkSerial")
        mock_check_serial.return_value = succeed(dns_result)
        mock_msg = self.patch(region_controller.log, "msg")
        service.startProcessing()
        yield service.processingDefer
        self.assertThat(mock_dns_update_all_zones, MockCalledOnceWith())
        self.assertThat(mock_check_serial, MockCalledOnceWith(dns_result))
        self.assertThat(
            mock_msg,
            MockCalledOnceWith("Reloaded DNS configuration; %s" %
                               (publications[-1].source)),
        )
Exemplo n.º 2
0
    def test_process_updates_zones_logs_reason_for_multiple_updates(self):
        # Create some fake serial updates with sources for the update.
        def _create_publications():
            return [
                DNSPublication.objects.create(
                    source=factory.make_name('reason')) for _ in range(3)
            ]

        publications = yield deferToDatabase(_create_publications)
        service = RegionControllerService(sentinel.listener)
        service.needsDNSUpdate = True
        service.previousSerial = publications[0].serial
        dns_result = (publications[-1].serial,
                      [factory.make_name('domain') for _ in range(3)])
        mock_dns_update_all_zones = self.patch(region_controller,
                                               "dns_update_all_zones")
        mock_dns_update_all_zones.return_value = dns_result
        mock_check_serial = self.patch(service, "_checkSerial")
        mock_check_serial.return_value = succeed(dns_result)
        mock_msg = self.patch(region_controller.log, "msg")
        service.startProcessing()
        yield service.processingDefer
        expected_msg = "Reloaded DNS configuration: \n"
        expected_msg += '\n'.join(
            ' * %s' % publication.source
            for publication in reversed(publications[1:]))
        self.assertThat(mock_dns_update_all_zones, MockCalledOnceWith())
        self.assertThat(mock_check_serial, MockCalledOnceWith(dns_result))
        self.assertThat(mock_msg, MockCalledOnceWith(expected_msg))
Exemplo n.º 3
0
 def test_startProcessing_calls_start_when_looping_call_not_running(self):
     service = RegionControllerService(sentinel.listener)
     mock_start = self.patch(service.processing, "start")
     service.startProcessing()
     self.assertThat(
         mock_start,
         MockCalledOnceWith(0.1, now=False))
Exemplo n.º 4
0
 def test_process_doesnt_proxy_update_config_when_nothing_to_process(self):
     service = RegionControllerService(sentinel.listener)
     service.needsProxyUpdate = False
     mock_proxy_update_config = self.patch(region_controller,
                                           "proxy_update_config")
     service.startProcessing()
     yield service.processingDefer
     self.assertThat(mock_proxy_update_config, MockNotCalled())
Exemplo n.º 5
0
 def test_process_doesnt_update_zones_when_nothing_to_process(self):
     service = RegionControllerService(sentinel.listener)
     service.needsDNSUpdate = False
     mock_dns_update_all_zones = self.patch(region_controller,
                                            "dns_update_all_zones")
     service.startProcessing()
     yield service.processingDefer
     self.assertThat(mock_dns_update_all_zones, MockNotCalled())
Exemplo n.º 6
0
 def test_process_updates_zones_logs_failure(self):
     service = RegionControllerService(sentinel.listener)
     service.needsDNSUpdate = True
     mock_dns_update_all_zones = self.patch(region_controller,
                                            "dns_update_all_zones")
     mock_dns_update_all_zones.side_effect = factory.make_exception()
     mock_err = self.patch(region_controller.log, "err")
     service.startProcessing()
     yield service.processingDefer
     self.assertThat(mock_dns_update_all_zones, MockCalledOnceWith())
     self.assertThat(mock_err,
                     MockCalledOnceWith(ANY, "Failed configuring DNS."))
Exemplo n.º 7
0
 def test_process_updates_proxy_logs_failure(self):
     service = RegionControllerService(sentinel.listener)
     service.needsProxyUpdate = True
     mock_proxy_update_config = self.patch(region_controller,
                                           "proxy_update_config")
     mock_proxy_update_config.return_value = fail(factory.make_exception())
     mock_err = self.patch(region_controller.log, "err")
     service.startProcessing()
     yield service.processingDefer
     self.assertThat(mock_proxy_update_config,
                     MockCalledOnceWith(reload_proxy=True))
     self.assertThat(mock_err,
                     MockCalledOnceWith(ANY, "Failed configuring proxy."))
Exemplo n.º 8
0
 def test_process_updates_proxy(self):
     service = RegionControllerService(sentinel.listener)
     service.needsProxyUpdate = True
     mock_proxy_update_config = self.patch(region_controller,
                                           "proxy_update_config")
     mock_proxy_update_config.return_value = succeed(None)
     mock_msg = self.patch(region_controller.log, "msg")
     service.startProcessing()
     yield service.processingDefer
     self.assertThat(mock_proxy_update_config,
                     MockCalledOnceWith(reload_proxy=True))
     self.assertThat(mock_msg,
                     MockCalledOnceWith("Successfully configured proxy."))
Exemplo n.º 9
0
 def test_process_updates_zones(self):
     service = RegionControllerService(sentinel.listener)
     service.needsDNSUpdate = True
     mock_dns_update_all_zones = self.patch(
         region_controller, "dns_update_all_zones")
     mock_msg = self.patch(
         region_controller.log, "msg")
     service.startProcessing()
     yield service.processingDefer
     self.assertThat(mock_dns_update_all_zones, MockCalledOnceWith())
     self.assertThat(
         mock_msg,
         MockCalledOnceWith("Successfully configured DNS."))
Exemplo n.º 10
0
 def test_process_updates_bind_and_proxy(self):
     service = RegionControllerService(sentinel.listener)
     service.needsDNSUpdate = True
     service.needsProxyUpdate = True
     mock_dns_update_all_zones = self.patch(
         region_controller, "dns_update_all_zones")
     mock_proxy_update_config = self.patch(
         region_controller, "proxy_update_config")
     mock_proxy_update_config.return_value = succeed(None)
     service.startProcessing()
     yield service.processingDefer
     self.assertThat(
         mock_dns_update_all_zones, MockCalledOnceWith())
     self.assertThat(
         mock_proxy_update_config, MockCalledOnceWith(reload_proxy=True))
Exemplo n.º 11
0
 def test_process_updates_zones(self):
     service = RegionControllerService(sentinel.listener)
     service.needsDNSUpdate = True
     dns_result = (random.randint(1, 1000),
                   [factory.make_name('domain') for _ in range(3)])
     mock_dns_update_all_zones = self.patch(region_controller,
                                            "dns_update_all_zones")
     mock_dns_update_all_zones.return_value = dns_result
     mock_check_serial = self.patch(service, "_checkSerial")
     mock_check_serial.return_value = succeed(dns_result)
     mock_msg = self.patch(region_controller.log, "msg")
     service.startProcessing()
     yield service.processingDefer
     self.assertThat(mock_dns_update_all_zones, MockCalledOnceWith())
     self.assertThat(mock_check_serial, MockCalledOnceWith(dns_result))
     self.assertThat(
         mock_msg,
         MockCalledOnceWith("Reloaded DNS configuration; regiond started."))
Exemplo n.º 12
0
 def test_process_updates_bind_and_proxy(self):
     service = RegionControllerService(sentinel.listener)
     service.needsDNSUpdate = True
     service.needsProxyUpdate = True
     dns_result = (random.randint(1, 1000),
                   [factory.make_name('domain') for _ in range(3)])
     mock_dns_update_all_zones = self.patch(region_controller,
                                            "dns_update_all_zones")
     mock_dns_update_all_zones.return_value = dns_result
     mock_check_serial = self.patch(service, "_checkSerial")
     mock_check_serial.return_value = succeed(dns_result)
     mock_proxy_update_config = self.patch(region_controller,
                                           "proxy_update_config")
     mock_proxy_update_config.return_value = succeed(None)
     service.startProcessing()
     yield service.processingDefer
     self.assertThat(mock_dns_update_all_zones, MockCalledOnceWith())
     self.assertThat(mock_check_serial, MockCalledOnceWith(dns_result))
     self.assertThat(mock_proxy_update_config,
                     MockCalledOnceWith(reload_proxy=True))
Exemplo n.º 13
0
 def test_process_stops_processing(self):
     service = RegionControllerService(sentinel.listener)
     service.needsDNSUpdate = False
     service.startProcessing()
     yield service.processingDefer
     self.assertIsNone(service.processingDefer)
Exemplo n.º 14
0
 def test_startProcessing_doesnt_call_start_when_looping_call_running(self):
     service = RegionControllerService(sentinel.listener)
     mock_start = self.patch(service.processing, "start")
     service.processing.running = True
     service.startProcessing()
     self.assertThat(mock_start, MockNotCalled())
Exemplo n.º 15
0
 def test_stopService_handles_canceling_processing(self):
     listener = MagicMock()
     service = RegionControllerService(listener)
     service.startProcessing()
     yield service.stopService()
     self.assertIsNone(service.processingDefer)