Пример #1
0
 def make_startable_RackDNSService(self, *args, **kwargs):
     service = dns.RackDNSService(*args, **kwargs)
     service._orig_tryUpdate = service._tryUpdate
     self.patch(service,
                "_tryUpdate").return_value = (always_succeed_with(None))
     service.call = (service._tryUpdate, tuple(), {})
     return service
Пример #2
0
    def test__getConfiguration_updates_interval_to_high(self):
        rpc_service, protocol = yield prepareRegion(self)
        service = dns.RackDNSService(rpc_service, reactor)
        yield service.startService()
        self.addCleanup((yield service.stopService))
        yield service._getConfiguration()

        self.assertThat(service.step, Equals(service.INTERVAL_HIGH))
        self.assertThat(service._loop.interval, Equals(service.INTERVAL_HIGH))
Пример #3
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())
        service = dns.RackDNSService(StubClusterClientService(), reactor)
        self.patch_autospec(service, "_maybeApplyConfiguration")

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

        self.assertThat(logger.output, Equals(""))
        self.assertThat(service._maybeApplyConfiguration, MockNotCalled())
Пример #4
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
        service = dns.RackDNSService(rpc_service, reactor)
        self.patch_autospec(service, "_maybeApplyConfiguration")

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

        self.assertThat(logger.output, Equals(""))
        self.assertThat(service._maybeApplyConfiguration, MockNotCalled())
Пример #5
0
    def test__genRegionIps_groups_by_region(self):
        mock_rpc = Mock()
        mock_rpc.connections = {}
        for _ in range(3):
            region_name = factory.make_name('region')
            for _ in range(3):
                pid = random.randint(0, 10000)
                eventloop = '%s:pid=%s' % (region_name, pid)
                ip = factory.make_ip_address()
                mock_conn = Mock()
                mock_conn.address = (ip, random.randint(5240, 5250))
                mock_rpc.connections[eventloop] = mock_conn

        service = dns.RackDNSService(mock_rpc, reactor)
        region_ips = list(service._genRegionIps())
        self.assertEquals(3, len(region_ips))
Пример #6
0
    def test__genRegionIps_always_returns_same_result(self):
        mock_rpc = Mock()
        mock_rpc.connections = {}
        for _ in range(3):
            region_name = factory.make_name('region')
            for _ in range(3):
                pid = random.randint(0, 10000)
                eventloop = '%s:pid=%s' % (region_name, pid)
                ip = factory.make_ip_address()
                mock_conn = Mock()
                mock_conn.address = (ip, random.randint(5240, 5250))
                mock_rpc.connections[eventloop] = mock_conn

        service = dns.RackDNSService(mock_rpc, reactor)
        region_ips = frozenset(service._genRegionIps())
        for _ in range(3):
            self.assertEquals(region_ips, frozenset(service._genRegionIps()))
Пример #7
0
 def _makeDNSService(self, rpc_service):
     from provisioningserver.rackdservices import dns
     dns_service = dns.RackDNSService(rpc_service, reactor)
     dns_service.setName("dns")
     return dns_service
Пример #8
0
 def test_service_iterates_on_low_interval(self):
     service = dns.RackDNSService(StubClusterClientService(), reactor)
     self.assertThat(service.step, Equals(service.INTERVAL_LOW))
Пример #9
0
 def test_service_uses__tryUpdate_as_periodic_function(self):
     service = dns.RackDNSService(StubClusterClientService(), reactor)
     self.assertThat(service.call, Equals((service._tryUpdate, (), {})))