summaryrefslogtreecommitdiff
path: root/ironic_python_agent
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2016-06-22 02:29:46 +0000
committerGerrit Code Review <review@openstack.org>2016-06-22 02:29:46 +0000
commit99a053f654840fc4db4d0691883f9b4b8a5c090b (patch)
treec6db27cbd7f7a940962f0723514e7ae309b1e991 /ironic_python_agent
parente0e83347bda9519a693c9ca7aee083f2ace7e984 (diff)
parent13a8c6321ef466505e815bfad34912f371d08d77 (diff)
downloadironic-python-agent-99a053f654840fc4db4d0691883f9b4b8a5c090b.tar.gz
Merge "Add configuration options for DISK_WAIT"
Diffstat (limited to 'ironic_python_agent')
-rw-r--r--ironic_python_agent/config.py12
-rw-r--r--ironic_python_agent/hardware.py23
-rw-r--r--ironic_python_agent/tests/unit/test_hardware.py90
3 files changed, 113 insertions, 12 deletions
diff --git a/ironic_python_agent/config.py b/ironic_python_agent/config.py
index 6c7db5d1..7ee56eb3 100644
--- a/ironic_python_agent/config.py
+++ b/ironic_python_agent/config.py
@@ -129,6 +129,18 @@ cli_opts = [
default=APARAMS.get('ipa-hardware-initialization-delay', 0),
help='How much time (in seconds) to wait for hardware to '
'initialize before proceeding with any actions.'),
+
+ cfg.IntOpt('disk_wait_attempts',
+ default=APARAMS.get('ipa-disk-wait-attempts', 10),
+ help='The number of times to try and check to see if '
+ 'at least one suitable disk has appeared in inventory '
+ 'before proceeding with any actions.'),
+
+ cfg.IntOpt('disk_wait_delay',
+ default=APARAMS.get('ipa-disk-wait-delay', 3),
+ help='How much time (in seconds) to wait between attempts '
+ 'to check if at least one suitable disk has appeared '
+ 'in inventory.'),
]
CONF.register_cli_opts(cli_opts)
diff --git a/ironic_python_agent/hardware.py b/ironic_python_agent/hardware.py
index 45e0d897..fae00a64 100644
--- a/ironic_python_agent/hardware.py
+++ b/ironic_python_agent/hardware.py
@@ -20,6 +20,7 @@ import time
import netifaces
from oslo_concurrency import processutils
+from oslo_config import cfg
from oslo_log import log
from oslo_utils import units
import pint
@@ -34,14 +35,12 @@ from ironic_python_agent import utils
_global_managers = None
LOG = log.getLogger()
+CONF = cfg.CONF
UNIT_CONVERTER = pint.UnitRegistry(filename=None)
UNIT_CONVERTER.define('MB = []')
UNIT_CONVERTER.define('GB = 1024 MB')
-_DISK_WAIT_ATTEMPTS = 10
-_DISK_WAIT_DELAY = 3
-
NODE = None
@@ -420,21 +419,27 @@ class GenericHardwareManager(HardwareManager):
return HardwareSupport.GENERIC
def _wait_for_disks(self):
- # Wait for at least one suitable disk to show up, otherwise neither
- # inspection not deployment have any chances to succeed.
- for attempt in range(_DISK_WAIT_ATTEMPTS):
+ """Wait for disk to appear
+
+ Wait for at least one suitable disk to show up, otherwise neither
+ inspection not deployment have any chances to succeed.
+
+ """
+
+ for attempt in range(CONF.disk_wait_attempts):
try:
block_devices = self.list_block_devices()
utils.guess_root_disk(block_devices)
except errors.DeviceNotFound:
LOG.debug('Still waiting for at least one disk to appear, '
- 'attempt %d of %d', attempt + 1, _DISK_WAIT_ATTEMPTS)
- time.sleep(_DISK_WAIT_DELAY)
+ 'attempt %d of %d', attempt + 1,
+ CONF.disk_wait_attempts)
+ time.sleep(CONF.disk_wait_delay)
else:
break
else:
LOG.warning('No disks detected in %d seconds',
- _DISK_WAIT_DELAY * _DISK_WAIT_ATTEMPTS)
+ CONF.disk_wait_delay * CONF.disk_wait_attempts)
def _get_interface_info(self, interface_name):
addr_path = '{0}/class/net/{1}/address'.format(self.sys_path,
diff --git a/ironic_python_agent/tests/unit/test_hardware.py b/ironic_python_agent/tests/unit/test_hardware.py
index edce295a..98f898b2 100644
--- a/ironic_python_agent/tests/unit/test_hardware.py
+++ b/ironic_python_agent/tests/unit/test_hardware.py
@@ -18,6 +18,7 @@ import time
import mock
import netifaces
from oslo_concurrency import processutils
+from oslo_config import cfg
from oslo_utils import units
from oslotest import base as test_base
import pyudev
@@ -27,6 +28,11 @@ from ironic_python_agent import errors
from ironic_python_agent import hardware
from ironic_python_agent import utils
+CONF = cfg.CONF
+
+CONF.import_opt('disk_wait_attempts', 'ironic_python_agent.config')
+CONF.import_opt('disk_wait_delay', 'ironic_python_agent.config')
+
HDPARM_INFO_TEMPLATE = (
'/dev/sda:\n'
'\n'
@@ -275,6 +281,8 @@ class TestGenericHardwareManager(test_base.BaseTestCase):
self.hardware = hardware.GenericHardwareManager()
self.node = {'uuid': 'dda135fb-732d-4742-8e72-df8f3199d244',
'driver_internal_info': {}}
+ CONF.clear_override('disk_wait_attempts')
+ CONF.clear_override('disk_wait_delay')
@mock.patch('netifaces.ifaddresses')
@mock.patch('os.listdir')
@@ -1161,7 +1169,83 @@ class TestGenericHardwareManager(test_base.BaseTestCase):
self.assertEqual(hardware.HardwareSupport.GENERIC, result)
mocked_root_dev.assert_called_with(mocked_block_dev.return_value)
self.assertEqual(2, mocked_root_dev.call_count)
- mocked_sleep.assert_called_once_with(hardware._DISK_WAIT_DELAY)
+ mocked_sleep.assert_called_once_with(CONF.disk_wait_delay)
+
+ @mock.patch.object(hardware.GenericHardwareManager, 'list_block_devices',
+ autospec=True)
+ @mock.patch.object(time, 'sleep', autospec=True)
+ @mock.patch.object(utils, 'guess_root_disk', autospec=True)
+ def test_evaluate_hw_waits_for_disks_nonconfigured(self, mocked_root_dev,
+ mocked_sleep,
+ mocked_block_dev):
+ mocked_root_dev.side_effect = [
+ errors.DeviceNotFound('boom'),
+ errors.DeviceNotFound('boom'),
+ errors.DeviceNotFound('boom'),
+ errors.DeviceNotFound('boom'),
+ errors.DeviceNotFound('boom'),
+ errors.DeviceNotFound('boom'),
+ errors.DeviceNotFound('boom'),
+ errors.DeviceNotFound('boom'),
+ errors.DeviceNotFound('boom'),
+ errors.DeviceNotFound('boom'),
+ errors.DeviceNotFound('boom'),
+ None
+ ]
+
+ self.hardware.evaluate_hardware_support()
+
+ mocked_root_dev.assert_called_with(mocked_block_dev.return_value)
+ self.assertEqual(10, mocked_root_dev.call_count)
+
+ @mock.patch.object(hardware.GenericHardwareManager, 'list_block_devices',
+ autospec=True)
+ @mock.patch.object(time, 'sleep', autospec=True)
+ @mock.patch.object(utils, 'guess_root_disk', autospec=True)
+ def test_evaluate_hw_waits_for_disks_configured(self, mocked_root_dev,
+ mocked_sleep,
+ mocked_block_dev):
+ CONF.set_override('disk_wait_attempts', '2', enforce_type=True)
+
+ mocked_root_dev.side_effect = [
+ errors.DeviceNotFound('boom'),
+ errors.DeviceNotFound('boom'),
+ errors.DeviceNotFound('boom'),
+ errors.DeviceNotFound('boom'),
+ None
+ ]
+
+ self.hardware.evaluate_hardware_support()
+
+ mocked_root_dev.assert_called_with(mocked_block_dev.return_value)
+ self.assertEqual(2, mocked_root_dev.call_count)
+
+ @mock.patch.object(hardware.GenericHardwareManager, 'list_block_devices',
+ autospec=True)
+ @mock.patch.object(time, 'sleep', autospec=True)
+ @mock.patch.object(utils, 'guess_root_disk', autospec=True)
+ def test_evaluate_hw_disks_timeout_unconfigured(self, mocked_root_dev,
+ mocked_sleep,
+ mocked_block_dev):
+ mocked_root_dev.side_effect = errors.DeviceNotFound('boom')
+
+ self.hardware.evaluate_hardware_support()
+
+ mocked_sleep.assert_called_with(3)
+
+ @mock.patch.object(hardware.GenericHardwareManager, 'list_block_devices',
+ autospec=True)
+ @mock.patch.object(time, 'sleep', autospec=True)
+ @mock.patch.object(utils, 'guess_root_disk', autospec=True)
+ def test_evaluate_hw_disks_timeout_configured(self, mocked_root_dev,
+ mocked_sleep,
+ mocked_block_dev):
+ CONF.set_override('disk_wait_delay', '5', enforce_type=True)
+ mocked_root_dev.side_effect = errors.DeviceNotFound('boom')
+
+ self.hardware.evaluate_hardware_support()
+
+ mocked_sleep.assert_called_with(5)
@mock.patch.object(hardware.GenericHardwareManager, 'list_block_devices',
autospec=True)
@@ -1175,9 +1259,9 @@ class TestGenericHardwareManager(test_base.BaseTestCase):
self.assertEqual(hardware.HardwareSupport.GENERIC, result)
mocked_root_dev.assert_called_with(mocked_block_dev.return_value)
- self.assertEqual(hardware._DISK_WAIT_ATTEMPTS,
+ self.assertEqual(CONF.disk_wait_attempts,
mocked_root_dev.call_count)
- mocked_sleep.assert_called_with(hardware._DISK_WAIT_DELAY)
+ mocked_sleep.assert_called_with(CONF.disk_wait_delay)
@mock.patch.object(utils, 'get_agent_params',
lambda: {'BOOTIF': 'boot:if'})