fix usage of need_default in parse_storage_policies
The need_default varible in parse_storage_policies seems to mark the case that there no policy is set to default. If True, the function trys to use first policy as default. If False, that means there is a policy is set yes for default option, not false values. So set need_default False only if a policy says he is the default one. Change-Id: Idc293366e6c529423e75900783570ffb6925533b
This commit is contained in:
parent
49c39e1b81
commit
e38fcd25d9
|
@ -129,7 +129,8 @@ def parse_storage_policies(conf):
|
|||
raise ValueError("Malformed storage policy %s" % section)
|
||||
try:
|
||||
is_default = conf.get(section, 'default')
|
||||
need_default = False
|
||||
if config_true_value(is_default):
|
||||
need_default = False
|
||||
except NoOptionError:
|
||||
is_default = False
|
||||
try:
|
||||
|
|
|
@ -120,6 +120,24 @@ class TestStoragePolicies(unittest.TestCase):
|
|||
self.assertRaises(
|
||||
ValueError, storage_policy.parse_storage_policies, conf)
|
||||
|
||||
conf = self._conf("""
|
||||
[storage-policy:0]
|
||||
default = no
|
||||
[storage-policy:1]
|
||||
default = no
|
||||
""")
|
||||
stor_pols = storage_policy.parse_storage_policies(conf)
|
||||
self.assertEquals(stor_pols.get_by_index(0).idx, 0)
|
||||
|
||||
conf = self._conf("""
|
||||
[storage-policy:1]
|
||||
default = no
|
||||
[storage-policy:2]
|
||||
default = no
|
||||
""")
|
||||
stor_pols = storage_policy.parse_storage_policies(conf)
|
||||
self.assertEquals(stor_pols.get_by_index(0).idx, 0)
|
||||
|
||||
def test_no_default_specified(self):
|
||||
conf = self._conf("""
|
||||
[storage-policy:1]
|
||||
|
@ -136,5 +154,22 @@ class TestStoragePolicies(unittest.TestCase):
|
|||
stor_pols = storage_policy.parse_storage_policies(conf1)
|
||||
self.assertEqual(stor_pols.default.name, 'thisOne')
|
||||
|
||||
def test_false_default(self):
|
||||
conf = self._conf("""
|
||||
[storage-policy:0]
|
||||
default = no
|
||||
[storage-policy:1]
|
||||
""")
|
||||
stor_pols = storage_policy.parse_storage_policies(conf)
|
||||
self.assertEquals(stor_pols.get_by_index(0).idx, 0)
|
||||
|
||||
conf = self._conf("""
|
||||
[storage-policy:0]
|
||||
[storage-policy:1]
|
||||
default = no
|
||||
""")
|
||||
stor_pols = storage_policy.parse_storage_policies(conf)
|
||||
self.assertEquals(stor_pols.get_by_index(0).idx, 0)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
Loading…
Reference in New Issue