Merge "Fix some types in the FS and VMware drivers"

This commit is contained in:
Zuul 2019-01-28 06:14:25 +00:00 committed by Gerrit Code Review
commit db75918208
4 changed files with 10 additions and 8 deletions

View File

@ -436,7 +436,7 @@ class Store(glance_store.driver.Store):
(datadir_path, (datadir_path,
priority) = self._get_datadir_path_and_priority(datadir) priority) = self._get_datadir_path_and_priority(datadir)
priority_paths = self.priority_data_map.setdefault( priority_paths = self.priority_data_map.setdefault(
int(priority), []) priority, [])
self._check_directory_paths(datadir_path, directory_paths, self._check_directory_paths(datadir_path, directory_paths,
priority_paths) priority_paths)
directory_paths.add(datadir_path) directory_paths.add(datadir_path)
@ -490,8 +490,9 @@ class Store(glance_store.driver.Store):
parts = [part.strip() for part in datadir.rsplit(":", 1)] parts = [part.strip() for part in datadir.rsplit(":", 1)]
datadir_path = parts[0] datadir_path = parts[0]
if len(parts) == 2 and parts[1]: if len(parts) == 2 and parts[1]:
priority = parts[1] try:
if not priority.isdigit(): priority = int(parts[1])
except ValueError:
msg = (_("Invalid priority value %(priority)s in " msg = (_("Invalid priority value %(priority)s in "
"filesystem configuration") % {'priority': priority}) "filesystem configuration") % {'priority': priority})
LOG.exception(msg) LOG.exception(msg)

View File

@ -463,8 +463,9 @@ class Store(glance_store.Store):
raise exceptions.BadStoreConfiguration( raise exceptions.BadStoreConfiguration(
store_name='vmware_datastore', reason=msg) store_name='vmware_datastore', reason=msg)
if len(parts) == 3 and parts[2]: if len(parts) == 3 and parts[2]:
weight = parts[2] try:
if not weight.isdigit(): weight = int(parts[2])
except ValueError:
msg = (_('Invalid weight value %(weight)s in ' msg = (_('Invalid weight value %(weight)s in '
'vmware_datastores configuration') % 'vmware_datastores configuration') %
{'weight': weight}) {'weight': weight})
@ -501,7 +502,7 @@ class Store(glance_store.Store):
LOG.error(msg) LOG.error(msg)
raise exceptions.BadStoreConfiguration( raise exceptions.BadStoreConfiguration(
store_name='vmware_datastore', reason=msg) store_name='vmware_datastore', reason=msg)
ds_map.setdefault(int(weight), []).append(ds_obj) ds_map.setdefault(weight, []).append(ds_obj)
return ds_map return ds_map
def configure_add(self): def configure_add(self):

View File

@ -391,7 +391,7 @@ class TestMultiStore(base.MultiStoreBaseTest,
parts = self.store._parse_datastore_info_and_weight(datastore) parts = self.store._parse_datastore_info_and_weight(datastore)
self.assertEqual('a', parts[0]) self.assertEqual('a', parts[0])
self.assertEqual('b', parts[1]) self.assertEqual('b', parts[1])
self.assertEqual('100', parts[2]) self.assertEqual(100, parts[2])
def test_parse_datastore_info_and_weight_default_weight(self): def test_parse_datastore_info_and_weight_default_weight(self):
datastore = 'a:b' datastore = 'a:b'

View File

@ -396,7 +396,7 @@ class TestStore(base.StoreBaseTest,
parts = self.store._parse_datastore_info_and_weight(datastore) parts = self.store._parse_datastore_info_and_weight(datastore)
self.assertEqual('a', parts[0]) self.assertEqual('a', parts[0])
self.assertEqual('b', parts[1]) self.assertEqual('b', parts[1])
self.assertEqual('100', parts[2]) self.assertEqual(100, parts[2])
def test_parse_datastore_info_and_weight_default_weight(self): def test_parse_datastore_info_and_weight_default_weight(self):
datastore = 'a:b' datastore = 'a:b'