diff --git a/glance_store/_drivers/filesystem.py b/glance_store/_drivers/filesystem.py index 8e8481c4..f9c3e476 100644 --- a/glance_store/_drivers/filesystem.py +++ b/glance_store/_drivers/filesystem.py @@ -436,7 +436,7 @@ class Store(glance_store.driver.Store): (datadir_path, priority) = self._get_datadir_path_and_priority(datadir) priority_paths = self.priority_data_map.setdefault( - int(priority), []) + priority, []) self._check_directory_paths(datadir_path, directory_paths, priority_paths) directory_paths.add(datadir_path) @@ -490,8 +490,9 @@ class Store(glance_store.driver.Store): parts = [part.strip() for part in datadir.rsplit(":", 1)] datadir_path = parts[0] if len(parts) == 2 and parts[1]: - priority = parts[1] - if not priority.isdigit(): + try: + priority = int(parts[1]) + except ValueError: msg = (_("Invalid priority value %(priority)s in " "filesystem configuration") % {'priority': priority}) LOG.exception(msg) diff --git a/glance_store/_drivers/vmware_datastore.py b/glance_store/_drivers/vmware_datastore.py index ef6f1c06..76a9edda 100644 --- a/glance_store/_drivers/vmware_datastore.py +++ b/glance_store/_drivers/vmware_datastore.py @@ -463,8 +463,9 @@ class Store(glance_store.Store): raise exceptions.BadStoreConfiguration( store_name='vmware_datastore', reason=msg) if len(parts) == 3 and parts[2]: - weight = parts[2] - if not weight.isdigit(): + try: + weight = int(parts[2]) + except ValueError: msg = (_('Invalid weight value %(weight)s in ' 'vmware_datastores configuration') % {'weight': weight}) @@ -501,7 +502,7 @@ class Store(glance_store.Store): LOG.error(msg) raise exceptions.BadStoreConfiguration( store_name='vmware_datastore', reason=msg) - ds_map.setdefault(int(weight), []).append(ds_obj) + ds_map.setdefault(weight, []).append(ds_obj) return ds_map def configure_add(self): diff --git a/glance_store/tests/unit/test_multistore_vmware.py b/glance_store/tests/unit/test_multistore_vmware.py index e5c95d7e..e88b53a7 100644 --- a/glance_store/tests/unit/test_multistore_vmware.py +++ b/glance_store/tests/unit/test_multistore_vmware.py @@ -391,7 +391,7 @@ class TestMultiStore(base.MultiStoreBaseTest, parts = self.store._parse_datastore_info_and_weight(datastore) self.assertEqual('a', parts[0]) 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): datastore = 'a:b' diff --git a/glance_store/tests/unit/test_vmware_store.py b/glance_store/tests/unit/test_vmware_store.py index 93d1a282..661a25c6 100644 --- a/glance_store/tests/unit/test_vmware_store.py +++ b/glance_store/tests/unit/test_vmware_store.py @@ -396,7 +396,7 @@ class TestStore(base.StoreBaseTest, parts = self.store._parse_datastore_info_and_weight(datastore) self.assertEqual('a', parts[0]) 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): datastore = 'a:b'