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
This commit is contained in:
Eric Brown 2015-08-15 11:36:33 -07:00
parent cae8244206
commit 3bb7fcb643
13 changed files with 16 additions and 38 deletions

View File

@ -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'],

View File

@ -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. '

View File

@ -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,

View File

@ -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',

View File

@ -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',

View File

@ -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)

View File

@ -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(

View File

@ -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.'),
]

View File

@ -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='',

View File

@ -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,

View File

@ -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.')]

View File

@ -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',

View File

@ -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',