summaryrefslogtreecommitdiff
path: root/designate/tests/unit/agent/test_service.py
blob: f4d47c9f66a25f2c46ee60d6360bd28d55037435 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# Copyright 2014 Rackspace Inc.
#
# Author: Tim Simmons <tim.simmons@rackspace.com>
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import mock

import designate.tests
from designate import dnsutils
from designate import utils
from designate.agent import service
from designate.backend import agent_backend
from designate.backend.agent_backend import impl_fake
from designate.tests import fixtures


class AgentServiceTest(designate.tests.TestCase):
    def setUp(self):
        super(AgentServiceTest, self).setUp()
        self.stdlog = fixtures.StandardLogging()
        self.useFixture(self.stdlog)

        self.CONF.set_override('listen', ['0.0.0.0:0'], 'service:agent')
        self.CONF.set_override('notify_delay', 0, 'service:agent')

        self.service = service.Service()
        self.service.dns_service._start = mock.Mock()

    def test_service_start(self):
        self.service.start()

        self.assertTrue(self.service.dns_service._start.called)

    def test_service_stop(self):
        self.service.dns_service.stop = mock.Mock()
        self.service.backend.stop = mock.Mock()

        self.service.stop()

        self.assertTrue(self.service.dns_service.stop.called)
        self.assertTrue(self.service.backend.stop.called)

        self.assertIn('Stopping agent service', self.stdlog.logger.output)

    def test_service_name(self):
        self.assertEqual('agent', self.service.service_name)

    def test_get_backend(self):
        backend = agent_backend.get_backend('fake', agent_service=self.service)
        self.assertIsInstance(backend, impl_fake.FakeBackend)

    @mock.patch.object(utils, 'cache_result')
    def test_get_dns_application(self, mock_cache_result):
        self.assertIsInstance(
            self.service.dns_application, dnsutils.SerializationMiddleware
        )

    @mock.patch.object(utils, 'cache_result')
    def test_get_dns_application_with_notify_delay(self, mock_cache_result):
        self.service = service.Service()

        self.CONF.set_override('notify_delay', 1.0, 'service:agent')

        self.assertIsInstance(
            self.service.dns_application, dnsutils.SerializationMiddleware
        )