Merge "Add timeout to rndc commands"
This commit is contained in:
commit
e49b80703f
|
@ -21,6 +21,8 @@ Bind 9 backend. Create and delete zones by executing rndc
|
|||
import random
|
||||
|
||||
import six
|
||||
import subprocess
|
||||
|
||||
from oslo_log import log as logging
|
||||
from oslo_utils import strutils
|
||||
|
||||
|
@ -51,6 +53,9 @@ class Bind9Backend(base.Backend):
|
|||
self.options.get('clean_zonefile', 'false'))
|
||||
|
||||
self._rndc_call_base = self._generate_rndc_base_call()
|
||||
self._rndc_timeout = self.options.get('rndc_timeout', None)
|
||||
if self._rndc_timeout == 0:
|
||||
self._rndc_timeout = None
|
||||
|
||||
def _generate_rndc_base_call(self):
|
||||
"""Generate argument list to execute rndc"""
|
||||
|
@ -174,7 +179,9 @@ class Bind9Backend(base.Backend):
|
|||
"""
|
||||
try:
|
||||
rndc_call = self._rndc_call_base + rndc_op
|
||||
LOG.debug('Executing RNDC call: %r', rndc_call)
|
||||
utils.execute(*rndc_call)
|
||||
except utils.processutils.ProcessExecutionError as e:
|
||||
LOG.debug('Executing RNDC call: %r with timeout %s',
|
||||
rndc_call, self._rndc_timeout)
|
||||
utils.execute(*rndc_call, timeout=self._rndc_timeout)
|
||||
except (utils.processutils.ProcessExecutionError,
|
||||
subprocess.TimeoutExpired) as e:
|
||||
raise exceptions.Backend(e)
|
||||
|
|
|
@ -26,6 +26,7 @@ BINS9_OPTS = [
|
|||
cfg.StrOpt('rndc_config_file',
|
||||
help='RNDC Config File'),
|
||||
cfg.StrOpt('rndc_key_file', help='RNDC Key File'),
|
||||
cfg.IntOpt('rndc_timeout', default=0, min=0, help='RNDC command timeout'),
|
||||
cfg.StrOpt('zone_file_path', default='$state_path/zones',
|
||||
help='Path where zone files are stored'),
|
||||
cfg.StrOpt('query_destination', default='127.0.0.1',
|
||||
|
|
|
@ -20,6 +20,8 @@ from designate import utils
|
|||
from designate.backend import impl_bind9
|
||||
from designate.tests import fixtures
|
||||
|
||||
import subprocess
|
||||
|
||||
|
||||
class Bind9BackendTestCase(designate.tests.TestCase):
|
||||
def setUp(self):
|
||||
|
@ -223,7 +225,36 @@ class Bind9BackendTestCase(designate.tests.TestCase):
|
|||
mock_execute.assert_called_with(
|
||||
'/usr/sbin/rndc', '-s', '192.168.2.4', '-p', '953',
|
||||
'-c', '/etc/rndc.conf', '-k', '/etc/rndc.key',
|
||||
'delzone', 'example.com '
|
||||
'delzone', 'example.com ', timeout=None
|
||||
)
|
||||
|
||||
@mock.patch('designate.utils.execute')
|
||||
def test_execute_rndc_timeout(self, mock_execute):
|
||||
rndc_op = ['delzone', 'example.com ']
|
||||
|
||||
self.backend._rndc_timeout = 10
|
||||
self.backend._execute_rndc(rndc_op)
|
||||
|
||||
mock_execute.assert_called_with(
|
||||
'/usr/sbin/rndc', '-s', '192.168.2.4', '-p', '953',
|
||||
'-c', '/etc/rndc.conf', '-k', '/etc/rndc.key',
|
||||
'delzone', 'example.com ', timeout=10
|
||||
)
|
||||
|
||||
@mock.patch('designate.utils.execute')
|
||||
def test_execute_rndc_timeout_exception(self, mock_execute):
|
||||
rndc_op = ['delzone', 'example.com ']
|
||||
|
||||
self.backend._rndc_timeout = 10
|
||||
|
||||
mock_execute.side_effect = subprocess.TimeoutExpired([
|
||||
'/usr/sbin/rndc', '-s', '192.168.2.4', '-p', '953',
|
||||
'-c', '/etc/rndc.conf', '-k', '/etc/rndc.key',
|
||||
'delzone', 'example.com '], 10)
|
||||
|
||||
self.assertRaises(
|
||||
exceptions.Backend,
|
||||
self.backend._execute_rndc, rndc_op
|
||||
)
|
||||
|
||||
@mock.patch('designate.utils.execute')
|
||||
|
|
|
@ -69,7 +69,7 @@ os-service-types==1.2.0
|
|||
os-win==3.0.0
|
||||
osc-lib==1.10.0
|
||||
oslo.cache==1.29.0
|
||||
oslo.concurrency==3.26.0
|
||||
oslo.concurrency==4.2.0
|
||||
oslo.config==5.2.0
|
||||
oslo.context==2.19.2
|
||||
oslo.db==8.3.0
|
||||
|
|
|
@ -11,7 +11,7 @@ keystoneauth1>=3.4.0 # Apache-2.0
|
|||
keystonemiddleware>=4.17.0 # Apache-2.0
|
||||
netaddr>=0.7.18 # BSD
|
||||
oslo.config>=5.2.0 # Apache-2.0
|
||||
oslo.concurrency>=3.26.0 # Apache-2.0
|
||||
oslo.concurrency>=4.2.0 # Apache-2.0
|
||||
oslo.messaging>=12.4.0 # Apache-2.0
|
||||
oslo.middleware>=3.31.0 # Apache-2.0
|
||||
oslo.log>=3.36.0 # Apache-2.0
|
||||
|
|
Loading…
Reference in New Issue