From 8cb902da266f21fda00c3f9775f093b420b69b06 Mon Sep 17 00:00:00 2001 From: Vitaly Gridnev Date: Tue, 22 Sep 2015 13:22:44 +0300 Subject: [PATCH] Configurable timeouts for disk preparing Supported configurable timeouts for mounting and formatting. Also injected reasons of mounting failure inside log warning. Change-Id: Ieca0d3584726d15681376db1cc2af2114a7bc73a Partial-bug: 1493548 Closes-bug: 1498449 --- sahara/plugins/provisioning.py | 10 +++++++++- sahara/service/volumes.py | 27 +++++++++++++++++++++++---- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/sahara/plugins/provisioning.py b/sahara/plugins/provisioning.py index eb563c5c..0bae5207 100644 --- a/sahara/plugins/provisioning.py +++ b/sahara/plugins/provisioning.py @@ -213,6 +213,13 @@ class ValidationError(object): # COMMON FOR ALL PLUGINS CONFIGS +DISKS_PREPARING_TIMEOUT = Config( + "Timeout for disk preparing", 'general', 'cluster', priority=1, + default_value=300, config_type="int", is_optional=True, + description='Timeout for preparing disks, formatting and mounting' +) + + NTP_URL = Config( "URL of NTP server", 'general', 'cluster', priority=1, default_value='', is_optional=True, @@ -234,4 +241,5 @@ HEAT_WAIT_CONDITION_TIMEOUT = Config( def list_of_common_configs(): - return [NTP_ENABLED, NTP_URL, HEAT_WAIT_CONDITION_TIMEOUT] + return [DISKS_PREPARING_TIMEOUT, NTP_ENABLED, NTP_URL, + HEAT_WAIT_CONDITION_TIMEOUT] diff --git a/sahara/service/volumes.py b/sahara/service/volumes.py index cb0a4eb5..90049ac8 100644 --- a/sahara/service/volumes.py +++ b/sahara/service/volumes.py @@ -25,6 +25,7 @@ from sahara import exceptions as ex from sahara.i18n import _ from sahara.i18n import _LE from sahara.i18n import _LW +from sahara.plugins import provisioning as plugin_base from sahara.utils import cluster_progress_ops as cpo from sahara.utils.openstack import base as b from sahara.utils.openstack import cinder @@ -40,6 +41,16 @@ CONF.import_opt('api_version', 'sahara.utils.openstack.cinder', group='cinder') +def _get_timeout_for_disk_preparing(cluster): + configs = cluster.cluster_configs.to_dict() + option_name = plugin_base.DISKS_PREPARING_TIMEOUT.name + option_target = plugin_base.DISKS_PREPARING_TIMEOUT.applicable_target + try: + return int(configs[option_target][option_name]) + except Exception: + return int(plugin_base.DISKS_PREPARING_TIMEOUT.default_value) + + def _count_instances_to_attach(instances): result = 0 for instance in instances: @@ -210,24 +221,31 @@ def _mount_volume_to_node(instance, index, device): def _format_device(instance, device, formatted_devices=None, lock=None): with instance.remote() as r: try: + timeout = _get_timeout_for_disk_preparing(instance.cluster) + # Format devices with better performance options: # - reduce number of blocks reserved for root to 1% # - use 'dir_index' for faster directory listings # - use 'extents' to work faster with large files # - disable journaling + fs_opts = '-F -m 1 -O dir_index,extents,^has_journal' - r.execute_command('sudo mkfs.ext4 %s %s' % (fs_opts, device)) + r.execute_command('sudo mkfs.ext4 %s %s' % (fs_opts, device), + timeout=timeout) if lock: with lock: formatted_devices.append(device) - except Exception: + except Exception as e: LOG.warning( - _LW("Device {dev} cannot be formatted").format(dev=device)) + _LW("Device {dev} cannot be formatted: {reason}").format( + dev=device, reason=e)) def _mount_volume(instance, device_path, mount_point): with instance.remote() as r: try: + timeout = _get_timeout_for_disk_preparing(instance.cluster) + # Mount volumes with better performance options: # - enable write-back # - do not store access time @@ -235,7 +253,8 @@ def _mount_volume(instance, device_path, mount_point): r.execute_command('sudo mkdir -p %s' % mount_point) r.execute_command('sudo mount %s %s %s' % - (mount_opts, device_path, mount_point)) + (mount_opts, device_path, mount_point), + timeout=timeout) r.execute_command( 'sudo sh -c "grep %s /etc/mtab >> /etc/fstab"' % device_path)