示例#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)),
        )
示例#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))
示例#3
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())
示例#4
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."))
示例#5
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."))
示例#6
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))
示例#7
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."))
示例#8
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))
示例#9
0
 def test_process_stops_processing(self):
     service = RegionControllerService(sentinel.listener)
     service.needsDNSUpdate = False
     service.startProcessing()
     yield service.processingDefer
     self.assertIsNone(service.processingDefer)