Fix integer/float conversions for py34 compatibility

In py34 we have more strict approach to type conversions.
So, fix conversions for integers and floats.

Change-Id: I237c8972c3449f2a0b6e925d747c63dc5d479e18
Partially-Implements: bp py3-compatibility
This commit is contained in:
Valeriy Ponomaryov 2015-08-03 12:12:12 +03:00
parent 83107dd849
commit a72f889458
5 changed files with 8 additions and 8 deletions

View File

@ -277,7 +277,7 @@ class WSGIService(service.ServiceBase):
self.host = getattr(CONF, '%s_listen' % name, "0.0.0.0")
self.port = getattr(CONF, '%s_listen_port' % name, 0)
self.workers = getattr(CONF, '%s_workers' % name, None)
if self.workers < 1:
if self.workers is not None and self.workers < 1:
LOG.warn(
_LW("Value of config option %(name)s_workers must be integer "
"greater than 1. Input value ignored.") % {'name': name})

View File

@ -299,7 +299,7 @@ class ShareDriver(object):
def check_for_setup_error(self):
"""Check for setup error."""
max_ratio = self.configuration.safe_get('max_over_subscription_ratio')
if max_ratio < 1.0:
if not max_ratio or float(max_ratio) < 1.0:
msg = (_("Invalid max_over_subscription_ratio '%s'. "
"Valid value should be >= 1.0.") % max_ratio)
raise exception.InvalidParameterValue(err=msg)

View File

@ -1072,7 +1072,7 @@ class NetAppCmodeClient(client_base.NetAppBaseClient):
# Do the unmount, handling split-related errors with retries.
retry_interval = 3 # seconds
for retry in range(wait_seconds / retry_interval):
for retry in range(int(wait_seconds / retry_interval)):
try:
self._unmount_volume(volume_name, force=force)
LOG.debug('Volume %s unmounted.', volume_name)

View File

@ -845,7 +845,7 @@ class ShareManager(manager.SchedulerDependentManager):
elif (network_info['network_type'] == 'vlan'
and (network_info['segmentation_id'] is None
or int(network_info['segmentation_id']) > 4094
or int(network_info['segmentation_id'] < 1))):
or int(network_info['segmentation_id']) < 1)):
msg = _('A segmentation ID %s was specified but is not valid for '
'a VLAN network type; the segmentation ID must be an '
'integer value in the range of [1,4094]')
@ -854,7 +854,7 @@ class ShareManager(manager.SchedulerDependentManager):
elif (network_info['network_type'] == 'vxlan'
and (network_info['segmentation_id'] is None
or int(network_info['segmentation_id']) > 16777215
or int(network_info['segmentation_id'] < 1))):
or int(network_info['segmentation_id']) < 1)):
msg = _('A segmentation ID %s was specified but is not valid for '
'a VXLAN network type; the segmentation ID must be an '
'integer value in the range of [1,16777215]')
@ -863,7 +863,7 @@ class ShareManager(manager.SchedulerDependentManager):
elif (network_info['network_type'] == 'gre'
and (network_info['segmentation_id'] is None
or int(network_info['segmentation_id']) > 4294967295
or int(network_info['segmentation_id'] < 1))):
or int(network_info['segmentation_id']) < 1)):
msg = _('A segmentation ID %s was specified but is not valid for '
'a GRE network type; the segmentation ID must be an '
'integer value in the range of [1, 4294967295]')

View File

@ -207,14 +207,14 @@ class ShareDriverTestCase(test.TestCase):
self.assertEqual([],
share_driver.get_share_server_pools('fake_server'))
@ddt.data(0.8, 1.0, 10.5, 20.0, None)
@ddt.data(0.8, 1.0, 10.5, 20.0, None, '1', '1.1')
def test_check_for_setup_error(self, value):
driver.CONF.set_default('driver_handles_share_servers', False)
share_driver = driver.ShareDriver(False)
share_driver.configuration = configuration.Configuration(None)
self.mock_object(share_driver.configuration, 'safe_get',
mock.Mock(return_value=value))
if value >= 1.0:
if value and float(value) >= 1.0:
share_driver.check_for_setup_error()
else:
self.assertRaises(exception.InvalidParameterValue,