def setUp(self):
     super(DjbdnsAgentBackendUnitTestCase, self).setUp()
     self.CONF.set_override('masters', ('127.0.0.1:5354', ),
                            'service:agent')
     self.useFixture(fixtures.MockPatchObject(DjbdnsBackend, '_check_dirs'))
     self.backend = DjbdnsBackend('foo')
     self.patch_ob(self.backend._resolver, 'query')
Exemple #2
0
 def setUp(self):
     super(DjbdnsAgentBackendTestCase, self).setUp()
     self.CONF.set_override('masters', ('127.0.0.1:5354', ),
                            'service:agent')
     tmp_datafiles_dir = tempfile.mkdtemp()
     os.mkdir(os.path.join(tmp_datafiles_dir, 'datafiles'))
     self.CONF.set_override(
         'tinydns_datadir', tmp_datafiles_dir,
         designate.backend.agent_backend.impl_djbdns.CFG_GROUP)
     self.useFixture(fixtures.MockPatchObject(DjbdnsBackend, '_check_dirs'))
     self.backend = DjbdnsBackend('foo')
     self.patch_ob(self.backend._resolver, 'query')
 def setUp(self):
     super(DjbdnsAgentBackendUnitTestCase, self).setUp()
     self.CONF.set_override('masters', ('127.0.0.1:5354',), 'service:agent')
     self.useFixture(fixtures.MockPatchObject(
         DjbdnsBackend, '_check_dirs'
     ))
     self.backend = DjbdnsBackend('foo')
     self.patch_ob(self.backend._resolver, 'query')
 def setUp(self):
     super(DjbdnsAgentBackendTestCase, self).setUp()
     self.CONF.set_override('masters', ('127.0.0.1:5354',), 'service:agent')
     tmp_datafiles_dir = tempfile.mkdtemp()
     os.mkdir(os.path.join(tmp_datafiles_dir, 'datafiles'))
     self.CONF.set_override(
         'tinydns_datadir',
         tmp_datafiles_dir,
         designate.backend.agent_backend.impl_djbdns.CFG_GROUP
     )
     self.useFixture(fixtures.MockPatchObject(
         DjbdnsBackend, '_check_dirs'
     ))
     self.backend = DjbdnsBackend('foo')
     self.patch_ob(self.backend._resolver, 'query')
class DjbdnsAgentBackendUnitTestCase(TestCase):
    def setUp(self):
        super(DjbdnsAgentBackendUnitTestCase, self).setUp()
        self.CONF.set_override('masters', ('127.0.0.1:5354', ),
                               'service:agent')
        self.useFixture(fixtures.MockPatchObject(DjbdnsBackend, '_check_dirs'))
        self.backend = DjbdnsBackend('foo')
        self.patch_ob(self.backend._resolver, 'query')

    def tearDown(self):
        super(DjbdnsAgentBackendUnitTestCase, self).tearDown()

    def _create_dnspy_zone(self, name):
        zone_text = (
            '$ORIGIN %(name)s\n%(name)s 3600 IN SOA %(ns)s '
            'email.email.com. 1421777854 3600 600 86400 3600\n%(name)s '
            '3600 IN NS %(ns)s\n') % {
                'name': name,
                'ns': 'ns1.designate.com'
            }

        return dns.zone.from_text(zone_text, check_origin=False)

    def patch_ob(self, *a, **kw):
        self.useFixture(fixtures.MockPatchObject(*a, **kw))

    def test_init(self):
        self.assertTrue(hasattr(self.backend, '_resolver'))
        self.assertEqual(1, self.backend._resolver.timeout)
        self.assertEqual(1, self.backend._resolver.lifetime)
        self.assertEqual(['127.0.0.1'], self.backend._resolver.nameservers)
        self.assertEqual('/var/lib/djbdns/root/data.cdb',
                         self.backend._tinydns_cdb_filename)
        self.assertEqual('/var/lib/djbdns/datafiles',
                         self.backend._datafiles_dir)
        self.assertEqual('/var/lib/djbdns/datafiles/%s.zonedata',
                         self.backend._datafiles_path_tpl)
        self.assertEqual([('127.0.0.1', 5354)], self.backend._masters)

    def test_find_zone_serial(self):
        class Data(object):
            serial = 3

        self.backend._resolver.query.return_value = [
            Data(),
        ]
        serial = self.backend.find_zone_serial('example.com')
        self.assertEqual(3, serial)

    def test_find_zone_serial_error(self):
        self.backend._resolver.query.side_effect = RuntimeError('foo')

        serial = self.backend.find_zone_serial('example.com')
        self.assertEqual(None, serial)

    @mock.patch('designate.backend.agent_backend.impl_djbdns.execute')
    def test_create_zone(self, mock_exe):
        self.patch_ob(self.backend, '_perform_axfr_from_minidns')
        self.patch_ob(self.backend, '_rebuild_data_cdb')
        zone = self._create_dnspy_zone('example.org')
        self.backend.create_zone(zone)

    def test_update_zone(self):
        self.patch_ob(self.backend, '_perform_axfr_from_minidns')
        self.patch_ob(self.backend, '_rebuild_data_cdb')
        zone = self._create_dnspy_zone('example.org')
        self.backend.update_zone(zone)

    @mock.patch('designate.backend.agent_backend.impl_djbdns.os.remove')
    def test_delete_zone(self, mock_rm):
        self.patch_ob(self.backend, '_rebuild_data_cdb')

        self.backend.delete_zone('foo')

        mock_rm.assert_called_once_with(
            '/var/lib/djbdns/datafiles/foo.zonedata')

    @mock.patch('designate.backend.agent_backend.impl_djbdns.os.remove')
    def test_exception_filter(self, *mocks):
        self.patch_ob(self.backend, '_rebuild_data_cdb')
        self.assertRaises(exceptions.Backend, self.backend.delete_zone, None)

    @mock.patch('designate.backend.agent_backend.impl_djbdns.os.remove')
    def test_exception_filter_pass_through(self, mock_rm):
        self.patch_ob(self.backend, '_rebuild_data_cdb')
        mock_rm.side_effect = exceptions.Backend
        self.assertRaises(exceptions.Backend, self.backend.delete_zone, 'foo')
Exemple #6
0
class DjbdnsAgentBackendTestCase(TestCase):
    def setUp(self):
        super(DjbdnsAgentBackendTestCase, self).setUp()
        self.CONF.set_override('masters', ('127.0.0.1:5354', ),
                               'service:agent')
        tmp_datafiles_dir = tempfile.mkdtemp()
        os.mkdir(os.path.join(tmp_datafiles_dir, 'datafiles'))
        self.CONF.set_override(
            'tinydns_datadir', tmp_datafiles_dir,
            designate.backend.agent_backend.impl_djbdns.CFG_GROUP)
        self.useFixture(fixtures.MockPatchObject(DjbdnsBackend, '_check_dirs'))
        self.backend = DjbdnsBackend('foo')
        self.patch_ob(self.backend._resolver, 'query')

    def tearDown(self):
        super(DjbdnsAgentBackendTestCase, self).tearDown()

    def patch_ob(self, *a, **kw):
        self.useFixture(fixtures.MockPatchObject(*a, **kw))

    @mock.patch('designate.backend.agent_backend.impl_djbdns.os.remove')
    @mock.patch('designate.backend.agent_backend.impl_djbdns.execute')
    def test__perform_axfr_from_minidns(self, mock_exe, mock_rm):
        mock_exe.return_value = (None, None)

        self.backend._perform_axfr_from_minidns('foo')

        mock_exe.assert_called_once_with(
            'tcpclient', '127.0.0.1', '5354', 'axfr-get', 'foo',
            os.path.join(self.backend._datafiles_dir, 'foo.zonedata'),
            os.path.join(self.backend._datafiles_dir, 'foo.ztmp'))

    def test_delete_zone_no_file(self):
        self.patch_ob(self.backend, '_rebuild_data_cdb')
        # Should not raise exceptions
        self.backend.delete_zone('non_existent_zone_file')

    @unittest.skipIf(not os.path.isfile(TINYDNSDATA_PATH),
                     "tinydns-data not installed")
    def test__rebuild_data_cdb_empty(self):
        # Check that tinydns-data can be run and the required files are
        # generated / renamed as needed
        self.CONF.set_override('root_helper', '  ')  # disable rootwrap
        self.backend._tinydns_cdb_filename = tempfile.mkstemp()[1]

        self.backend._rebuild_data_cdb()

        assert os.path.isfile(self.backend._tinydns_cdb_filename)
        os.remove(self.backend._tinydns_cdb_filename)

    @unittest.skipIf(not os.path.isfile(TINYDNSDATA_PATH),
                     "tinydns-data not installed")
    def test__rebuild_data_cdb(self):
        # Check that tinydns-data can be run and the required files are
        # generated / renamed as needed
        self.CONF.set_override('root_helper', '  ')  # disable rootwrap
        self.backend._tinydns_cdb_filename = tempfile.mkstemp()[1]

        fn = os.path.join(self.backend._datafiles_dir, 'example.org.zonedata')
        with open(fn, 'w') as f:
            f.write(""".example.org::ns1.example.org
+ns1.example.org:127.0.0.1
+www.example.org:127.0.0.1
""")

        self.backend._rebuild_data_cdb()

        assert os.path.isfile(self.backend._tinydns_cdb_filename)
        os.remove(self.backend._tinydns_cdb_filename)
Exemple #7
0
 def test__check_dirs(self):
     DjbdnsBackend._check_dirs('/tmp')
class DjbdnsAgentBackendUnitTestCase(TestCase):

    def setUp(self):
        super(DjbdnsAgentBackendUnitTestCase, self).setUp()
        self.CONF.set_override('masters', ('127.0.0.1:5354',), 'service:agent')
        self.useFixture(fixtures.MockPatchObject(
            DjbdnsBackend, '_check_dirs'
        ))
        self.backend = DjbdnsBackend('foo')
        self.patch_ob(self.backend._resolver, 'query')

    def tearDown(self):
        super(DjbdnsAgentBackendUnitTestCase, self).tearDown()

    def _create_dnspy_zone(self, name):
        zone_text = (
            '$ORIGIN %(name)s\n%(name)s 3600 IN SOA %(ns)s '
            'email.email.com. 1421777854 3600 600 86400 3600\n%(name)s '
            '3600 IN NS %(ns)s\n') % {'name': name, 'ns': 'ns1.designate.com'}

        return dns.zone.from_text(zone_text, check_origin=False)

    def patch_ob(self, *a, **kw):
        self.useFixture(fixtures.MockPatchObject(*a, **kw))

    def test_init(self):
        self.assertTrue(hasattr(self.backend, '_resolver'))
        self.assertEqual(1, self.backend._resolver.timeout)
        self.assertEqual(1, self.backend._resolver.lifetime)
        self.assertEqual(['127.0.0.1'], self.backend._resolver.nameservers)
        self.assertEqual('/var/lib/djbdns/root/data.cdb',
                         self.backend._tinydns_cdb_filename)
        self.assertEqual('/var/lib/djbdns/datafiles',
                         self.backend._datafiles_dir)
        self.assertEqual('/var/lib/djbdns/datafiles/%s.zonedata',
                         self.backend._datafiles_path_tpl)
        self.assertEqual([('127.0.0.1', 5354)], self.backend._masters)

    def test_find_zone_serial(self):
        class Data(object):
            serial = 3

        self.backend._resolver.query.return_value = [Data(), ]
        serial = self.backend.find_zone_serial('example.com')
        self.assertEqual(3, serial)

    def test_find_zone_serial_error(self):
        self.backend._resolver.query.side_effect = RuntimeError('foo')

        serial = self.backend.find_zone_serial('example.com')
        self.assertEqual(None, serial)

    @mock.patch('designate.backend.agent_backend.impl_djbdns.execute')
    def test_create_zone(self, mock_exe):
        self.patch_ob(self.backend, '_perform_axfr_from_minidns')
        self.patch_ob(self.backend, '_rebuild_data_cdb')
        zone = self._create_dnspy_zone('example.org')
        self.backend.create_zone(zone)

    def test_update_zone(self):
        self.patch_ob(self.backend, '_perform_axfr_from_minidns')
        self.patch_ob(self.backend, '_rebuild_data_cdb')
        zone = self._create_dnspy_zone('example.org')
        self.backend.update_zone(zone)

    @mock.patch('designate.backend.agent_backend.impl_djbdns.os.remove')
    def test_delete_zone(self, mock_rm):
        self.patch_ob(self.backend, '_rebuild_data_cdb')

        self.backend.delete_zone('foo')

        mock_rm.assert_called_once_with(
            '/var/lib/djbdns/datafiles/foo.zonedata'
        )

    @mock.patch('designate.backend.agent_backend.impl_djbdns.os.remove')
    def test_exception_filter(self, *mocks):
        self.patch_ob(self.backend, '_rebuild_data_cdb')
        self.assertRaises(
            exceptions.Backend,
            self.backend.delete_zone,
            None
        )

    @mock.patch('designate.backend.agent_backend.impl_djbdns.os.remove')
    def test_exception_filter_pass_through(self, mock_rm):
        self.patch_ob(self.backend, '_rebuild_data_cdb')
        mock_rm.side_effect = exceptions.Backend
        self.assertRaises(
            exceptions.Backend,
            self.backend.delete_zone,
            'foo'
        )
class DjbdnsAgentBackendTestCase(TestCase):

    def setUp(self):
        super(DjbdnsAgentBackendTestCase, self).setUp()
        self.CONF.set_override('masters', ('127.0.0.1:5354',), 'service:agent')
        tmp_datafiles_dir = tempfile.mkdtemp()
        os.mkdir(os.path.join(tmp_datafiles_dir, 'datafiles'))
        self.CONF.set_override(
            'tinydns_datadir',
            tmp_datafiles_dir,
            designate.backend.agent_backend.impl_djbdns.CFG_GROUP
        )
        self.useFixture(fixtures.MockPatchObject(
            DjbdnsBackend, '_check_dirs'
        ))
        self.backend = DjbdnsBackend('foo')
        self.patch_ob(self.backend._resolver, 'query')

    def tearDown(self):
        super(DjbdnsAgentBackendTestCase, self).tearDown()

    def patch_ob(self, *a, **kw):
        self.useFixture(fixtures.MockPatchObject(*a, **kw))

    @mock.patch('designate.backend.agent_backend.impl_djbdns.os.remove')
    @mock.patch('designate.backend.agent_backend.impl_djbdns.execute')
    def test__perform_axfr_from_minidns(self, mock_exe, mock_rm):
        mock_exe.return_value = (None, None)

        self.backend._perform_axfr_from_minidns('foo')

        mock_exe.assert_called_once_with(
            'tcpclient', '127.0.0.1', '5354', 'axfr-get', 'foo',
            os.path.join(self.backend._datafiles_dir, 'foo.zonedata'),
            os.path.join(self.backend._datafiles_dir, 'foo.ztmp')
        )

    def test_delete_zone_no_file(self):
        self.patch_ob(self.backend, '_rebuild_data_cdb')
        # Should not raise exceptions
        self.backend.delete_zone('non_existent_zone_file')

    @unittest.skipIf(not os.path.isfile(TINYDNSDATA_PATH),
                     "tinydns-data not installed")
    def test__rebuild_data_cdb_empty(self):
        # Check that tinydns-data can be run and the required files are
        # generated / renamed as needed
        self.CONF.set_override('root_helper', '  ')  # disable rootwrap
        self.backend._tinydns_cdb_filename = tempfile.mkstemp()[1]

        self.backend._rebuild_data_cdb()

        assert os.path.isfile(self.backend._tinydns_cdb_filename)
        os.remove(self.backend._tinydns_cdb_filename)

    @unittest.skipIf(not os.path.isfile(TINYDNSDATA_PATH),
                     "tinydns-data not installed")
    def test__rebuild_data_cdb(self):
        # Check that tinydns-data can be run and the required files are
        # generated / renamed as needed
        self.CONF.set_override('root_helper', '  ')  # disable rootwrap
        self.backend._tinydns_cdb_filename = tempfile.mkstemp()[1]

        fn = os.path.join(self.backend._datafiles_dir, 'example.org.zonedata')
        with open(fn, 'w') as f:
            f.write(""".example.org::ns1.example.org
+ns1.example.org:127.0.0.1
+www.example.org:127.0.0.1
""")

        self.backend._rebuild_data_cdb()

        assert os.path.isfile(self.backend._tinydns_cdb_filename)
        os.remove(self.backend._tinydns_cdb_filename)
 def test__check_dirs(self):
     DjbdnsBackend._check_dirs('/tmp')