From 3bb7fcb64301cec5fc9435d37deaa0617d207a7a Mon Sep 17 00:00:00 2001 From: Eric Brown Date: Sat, 15 Aug 2015 11:36:33 -0700 Subject: [PATCH] Use min and max on IntOpt option types Latest version of oslo.config support the ability to set valid range on IntOpt option values. This path makes use of that feature for a number of options with well known minimum and maximum values. Change-Id: Ie4b081bdaa373c9dedf7dd0c9884553ffb42b61c --- cinder/common/config.py | 1 + cinder/service.py | 1 + cinder/tests/unit/test_storwize_svc.py | 15 --------------- cinder/volume/driver.py | 3 +++ .../drivers/dell/dell_storagecenter_common.py | 1 + .../volume/drivers/ibm/storwize_svc/__init__.py | 14 ++++---------- cinder/volume/drivers/ibm/storwize_svc/helpers.py | 13 ------------- cinder/volume/drivers/prophetstor/options.py | 1 + cinder/volume/drivers/remotefs.py | 1 + cinder/volume/drivers/san/san.py | 1 + cinder/volume/drivers/solidfire.py | 1 + .../drivers/brocade/brcd_fabric_opts.py | 1 + .../drivers/cisco/cisco_fabric_opts.py | 1 + 13 files changed, 16 insertions(+), 38 deletions(-) diff --git a/cinder/common/config.py b/cinder/common/config.py index 161d6368bc1..594fefb078c 100644 --- a/cinder/common/config.py +++ b/cinder/common/config.py @@ -61,6 +61,7 @@ global_opts = [ help='Default glance host name or IP'), cfg.IntOpt('glance_port', default=9292, + min=1, max=65535, help='Default glance port'), cfg.ListOpt('glance_api_servers', default=['$glance_host:$glance_port'], diff --git a/cinder/service.py b/cinder/service.py index 01f929edee9..54eadb66ce4 100644 --- a/cinder/service.py +++ b/cinder/service.py @@ -64,6 +64,7 @@ service_opts = [ help='IP address on which OpenStack Volume API listens'), cfg.IntOpt('osapi_volume_listen_port', default=8776, + min=1, max=65535, help='Port on which OpenStack Volume API listens'), cfg.IntOpt('osapi_volume_workers', help='Number of workers for OpenStack Volume API service. ' diff --git a/cinder/tests/unit/test_storwize_svc.py b/cinder/tests/unit/test_storwize_svc.py index b812bcd287f..fd25fdaa2b9 100644 --- a/cinder/tests/unit/test_storwize_svc.py +++ b/cinder/tests/unit/test_storwize_svc.py @@ -1787,26 +1787,11 @@ class StorwizeSVCDriverTestCase(test.TestCase): self.driver.check_for_setup_error) self._reset_flags() - self._set_flag('storwize_svc_vol_rsize', 101) - self.assertRaises(exception.InvalidInput, - self.driver.check_for_setup_error) - self._reset_flags() - - self._set_flag('storwize_svc_vol_warning', 101) - self.assertRaises(exception.InvalidInput, - self.driver.check_for_setup_error) - self._reset_flags() - self._set_flag('storwize_svc_vol_grainsize', 42) self.assertRaises(exception.InvalidInput, self.driver.check_for_setup_error) self._reset_flags() - self._set_flag('storwize_svc_flashcopy_timeout', 601) - self.assertRaises(exception.InvalidInput, - self.driver.check_for_setup_error) - self._reset_flags() - self._set_flag('storwize_svc_vol_compression', True) self._set_flag('storwize_svc_vol_rsize', -1) self.assertRaises(exception.InvalidInput, diff --git a/cinder/volume/driver.py b/cinder/volume/driver.py index 9d9a91663c7..ba2fe056390 100644 --- a/cinder/volume/driver.py +++ b/cinder/volume/driver.py @@ -47,6 +47,7 @@ volume_opts = [ help='Number of times to attempt to run flakey shell commands'), cfg.IntOpt('reserved_percentage', default=0, + min=0, max=100, help='The percentage of backend capacity is reserved'), cfg.IntOpt('iscsi_num_targets', default=None, @@ -63,6 +64,7 @@ volume_opts = [ help='The list of secondary IP addresses of the iSCSI daemon'), cfg.IntOpt('iscsi_port', default=3260, + min=1, max=65535, help='The port that the iSCSI daemon is listening on'), cfg.IntOpt('num_volume_device_scan_tries', default=3, @@ -240,6 +242,7 @@ iser_opts = [ help='The IP address that the iSER daemon is listening on'), cfg.IntOpt('iser_port', default=3260, + min=1, max=65535, help='The port that the iSER daemon is listening on'), cfg.StrOpt('iser_helper', default='tgtadm', diff --git a/cinder/volume/drivers/dell/dell_storagecenter_common.py b/cinder/volume/drivers/dell/dell_storagecenter_common.py index c8741cab531..c937ff5d2be 100644 --- a/cinder/volume/drivers/dell/dell_storagecenter_common.py +++ b/cinder/volume/drivers/dell/dell_storagecenter_common.py @@ -31,6 +31,7 @@ common_opts = [ help='Storage Center System Serial Number'), cfg.IntOpt('dell_sc_api_port', default=3033, + min=1, max=65535, help='Dell API port'), cfg.StrOpt('dell_sc_server_folder', default='openstack', diff --git a/cinder/volume/drivers/ibm/storwize_svc/__init__.py b/cinder/volume/drivers/ibm/storwize_svc/__init__.py index a1a8620fae7..805af3f6c5f 100644 --- a/cinder/volume/drivers/ibm/storwize_svc/__init__.py +++ b/cinder/volume/drivers/ibm/storwize_svc/__init__.py @@ -63,10 +63,12 @@ storwize_svc_opts = [ help='Storage system storage pool for volumes'), cfg.IntOpt('storwize_svc_vol_rsize', default=2, + min=-1, max=100, help='Storage system space-efficiency parameter for volumes ' '(percentage)'), cfg.IntOpt('storwize_svc_vol_warning', default=0, + min=-1, max=100, help='Storage system threshold for volume capacity warnings ' '(percentage)'), cfg.BoolOpt('storwize_svc_vol_autoexpand', @@ -88,8 +90,9 @@ storwize_svc_opts = [ help='The I/O group in which to allocate volumes'), cfg.IntOpt('storwize_svc_flashcopy_timeout', default=120, + min=1, max=600, help='Maximum number of seconds to wait for FlashCopy to be ' - 'prepared. Maximum value is 600 seconds (10 minutes)'), + 'prepared.'), cfg.StrOpt('storwize_svc_connection_protocol', default='iSCSI', help='Connection protocol (iSCSI/FC)'), @@ -289,15 +292,6 @@ class StorwizeSVCDriver(san.SanDriver, 'authentication: set either san_password or ' 'san_private_key option.')) - # Check that flashcopy_timeout is not more than 10 minutes - flashcopy_timeout = self.configuration.storwize_svc_flashcopy_timeout - if not (flashcopy_timeout > 0 and flashcopy_timeout <= 600): - raise exception.InvalidInput( - reason=_('Illegal value %d specified for ' - 'storwize_svc_flashcopy_timeout: ' - 'valid values are between 0 and 600.') - % flashcopy_timeout) - opts = self._helpers.build_default_opts(self.configuration) self._helpers.check_vdisk_opts(self._state, opts) diff --git a/cinder/volume/drivers/ibm/storwize_svc/helpers.py b/cinder/volume/drivers/ibm/storwize_svc/helpers.py index 109790d0c08..762229457db 100644 --- a/cinder/volume/drivers/ibm/storwize_svc/helpers.py +++ b/cinder/volume/drivers/ibm/storwize_svc/helpers.py @@ -403,19 +403,6 @@ class StorwizeHelpers(object): @staticmethod def check_vdisk_opts(state, opts): - # Check that rsize is either -1 or between 0 and 100 - if not (opts['rsize'] >= -1 and opts['rsize'] <= 100): - raise exception.InvalidInput( - reason=_('Illegal value specified for storwize_svc_vol_rsize: ' - 'set to either a percentage (0-100) or -1.')) - - # Check that warning is either -1 or between 0 and 100 - if not (opts['warning'] >= -1 and opts['warning'] <= 100): - raise exception.InvalidInput( - reason=_('Illegal value specified for ' - 'storwize_svc_vol_warning: ' - 'set to a percentage (0-100).')) - # Check that grainsize is 32/64/128/256 if opts['grainsize'] not in [32, 64, 128, 256]: raise exception.InvalidInput( diff --git a/cinder/volume/drivers/prophetstor/options.py b/cinder/volume/drivers/prophetstor/options.py index c9cc3e99260..ff9768f7fe2 100644 --- a/cinder/volume/drivers/prophetstor/options.py +++ b/cinder/volume/drivers/prophetstor/options.py @@ -23,6 +23,7 @@ DPL_OPTS = [ help='DPL pool uuid in which DPL volumes are stored.'), cfg.IntOpt('dpl_port', default=8357, + min=1, max=65535, help='DPL port number.'), ] diff --git a/cinder/volume/drivers/remotefs.py b/cinder/volume/drivers/remotefs.py index c3da55d6263..a357ded8dbc 100644 --- a/cinder/volume/drivers/remotefs.py +++ b/cinder/volume/drivers/remotefs.py @@ -51,6 +51,7 @@ nas_opts = [ secret=True), cfg.IntOpt('nas_ssh_port', default=22, + min=1, max=65535, help='SSH port to use to connect to NAS system.'), cfg.StrOpt('nas_private_key', default='', diff --git a/cinder/volume/drivers/san/san.py b/cinder/volume/drivers/san/san.py index 6707a0f5416..6c6df1cc45c 100644 --- a/cinder/volume/drivers/san/san.py +++ b/cinder/volume/drivers/san/san.py @@ -57,6 +57,7 @@ san_opts = [ help='Cluster name to use for creating volumes'), cfg.IntOpt('san_ssh_port', default=22, + min=1, max=65535, help='SSH port to use with SAN'), cfg.BoolOpt('san_is_local', default=False, diff --git a/cinder/volume/drivers/solidfire.py b/cinder/volume/drivers/solidfire.py index 26d68070a3a..c209c088b62 100644 --- a/cinder/volume/drivers/solidfire.py +++ b/cinder/volume/drivers/solidfire.py @@ -70,6 +70,7 @@ sf_opts = [ cfg.IntOpt('sf_api_port', default=443, + min=1, max=65535, help='SolidFire API port. Useful if the device api is behind ' 'a proxy on a different port.')] diff --git a/cinder/zonemanager/drivers/brocade/brcd_fabric_opts.py b/cinder/zonemanager/drivers/brocade/brcd_fabric_opts.py index d9792d5dbd4..6c1276ab025 100644 --- a/cinder/zonemanager/drivers/brocade/brcd_fabric_opts.py +++ b/cinder/zonemanager/drivers/brocade/brcd_fabric_opts.py @@ -33,6 +33,7 @@ brcd_zone_opts = [ secret=True), cfg.IntOpt('fc_fabric_port', default=22, + min=1, max=65535, help='Connecting port'), cfg.StrOpt('zoning_policy', default='initiator-target', diff --git a/cinder/zonemanager/drivers/cisco/cisco_fabric_opts.py b/cinder/zonemanager/drivers/cisco/cisco_fabric_opts.py index ae777ed6850..c105b314158 100644 --- a/cinder/zonemanager/drivers/cisco/cisco_fabric_opts.py +++ b/cinder/zonemanager/drivers/cisco/cisco_fabric_opts.py @@ -30,6 +30,7 @@ cisco_zone_opts = [ secret=True), cfg.IntOpt('cisco_fc_fabric_port', default=22, + min=1, max=65535, help='Connecting port'), cfg.StrOpt('cisco_zoning_policy', default='initiator-target',