Improve bind coverage and fixed minor bug
Fixed a minor bug where a timeout could be passed as either a string or a int, but didn't handle the conversion properly. Change-Id: Idbe15d59299d363305dd4404080400157cf90d2c
This commit is contained in:
parent
e4e09a7c1d
commit
1b6546e137
designate
@ -53,7 +53,8 @@ class Bind9Backend(base.Backend):
|
||||
|
||||
self._rndc_call_base = self._generate_rndc_base_call()
|
||||
self._rndc_timeout = self.options.get('rndc_timeout', None)
|
||||
if self._rndc_timeout == 0:
|
||||
|
||||
if self._rndc_timeout == 0 or self._rndc_timeout == '0':
|
||||
self._rndc_timeout = None
|
||||
|
||||
def _generate_rndc_base_call(self):
|
||||
|
@ -29,6 +29,8 @@ import subprocess
|
||||
class Bind9BackendTestCase(oslotest.base.BaseTestCase):
|
||||
def setUp(self):
|
||||
super(Bind9BackendTestCase, self).setUp()
|
||||
self.stdlog = fixtures.StandardLogging()
|
||||
self.useFixture(self.stdlog)
|
||||
self.admin_context = mock.Mock()
|
||||
mock.patch.object(
|
||||
context.DesignateContext, 'get_admin_context',
|
||||
@ -54,6 +56,7 @@ class Bind9BackendTestCase(oslotest.base.BaseTestCase):
|
||||
{'key': 'rndc_bin_path', 'value': '/usr/sbin/rndc'},
|
||||
{'key': 'rndc_config_file', 'value': '/etc/rndc.conf'},
|
||||
{'key': 'rndc_key_file', 'value': '/etc/rndc.key'},
|
||||
{'key': 'rndc_timeout', 'value': '0'},
|
||||
{'key': 'clean_zonefile', 'value': 'true'}
|
||||
],
|
||||
}
|
||||
@ -86,6 +89,26 @@ class Bind9BackendTestCase(oslotest.base.BaseTestCase):
|
||||
]
|
||||
)
|
||||
|
||||
@mock.patch.object(impl_bind9.Bind9Backend, '_execute_rndc')
|
||||
@mock.patch.object(impl_bind9.Bind9Backend, 'get_zone')
|
||||
def test_update_zone_error(self, mock_get_zone, mock_execute):
|
||||
mock_get_zone.return_value = True
|
||||
mock_execute.side_effect = exceptions.Backend('error')
|
||||
|
||||
with fixtures.random_seed(0):
|
||||
self.backend.update_zone(self.admin_context, self.zone)
|
||||
|
||||
self.assertIn('Error updating zone', self.stdlog.logger.output)
|
||||
|
||||
@mock.patch.object(impl_bind9.Bind9Backend, 'create_zone')
|
||||
@mock.patch.object(impl_bind9.Bind9Backend, 'get_zone')
|
||||
def test_update_zone_does_not_exist(self, mock_get_zone, mock_create_zone):
|
||||
mock_get_zone.return_value = False
|
||||
|
||||
self.backend.update_zone(self.admin_context, self.zone)
|
||||
|
||||
mock_create_zone.assert_called()
|
||||
|
||||
@mock.patch.object(impl_bind9.Bind9Backend, '_execute_rndc')
|
||||
def test_get_zone(self, mock_execute):
|
||||
with fixtures.random_seed(0):
|
||||
@ -95,6 +118,22 @@ class Bind9BackendTestCase(oslotest.base.BaseTestCase):
|
||||
['showzone', 'example.com ']
|
||||
)
|
||||
|
||||
@mock.patch.object(impl_bind9.Bind9Backend, '_execute_rndc')
|
||||
def test_get_zone_backend_error(self, mock_execute):
|
||||
mock_execute.side_effect = exceptions.Backend('error')
|
||||
|
||||
self.assertRaisesRegex(
|
||||
exceptions.Backend,
|
||||
'error',
|
||||
self.backend.get_zone, self.admin_context, self.zone
|
||||
)
|
||||
|
||||
@mock.patch.object(impl_bind9.Bind9Backend, '_execute_rndc')
|
||||
def test_get_zone_backend_error_not_found(self, mock_execute):
|
||||
mock_execute.side_effect = exceptions.Backend('not found')
|
||||
|
||||
self.assertFalse(self.backend.get_zone(self.admin_context, self.zone))
|
||||
|
||||
@mock.patch.object(impl_bind9.Bind9Backend, '_execute_rndc')
|
||||
def test_create_zone_with_view(self, mock_execute):
|
||||
self.target['options'].append(
|
||||
|
Loading…
x
Reference in New Issue
Block a user