Fix swift-ring-builder set_weight with >1 device
When iterating over the (device, weight) tuples do not carry over the device from the previous iteration. Closes-Bug: 1454433 Change-Id: Iba82519b0b2bc80e2c1abbed308b651c4da4b06a
This commit is contained in:
parent
39dc227f39
commit
747b9d9286
@ -218,7 +218,6 @@ def _parse_set_weight_values(argvish):
|
||||
# --options format,
|
||||
# but not both. If both are specified, raise an error.
|
||||
try:
|
||||
devs = []
|
||||
if not new_cmd_format:
|
||||
if len(args) % 2 != 0:
|
||||
print(Commands.set_weight.__doc__.strip())
|
||||
@ -227,7 +226,7 @@ def _parse_set_weight_values(argvish):
|
||||
devs_and_weights = izip(islice(argvish, 0, len(argvish), 2),
|
||||
islice(argvish, 1, len(argvish), 2))
|
||||
for devstr, weightstr in devs_and_weights:
|
||||
devs.extend(builder.search_devs(
|
||||
devs = (builder.search_devs(
|
||||
parse_search_value(devstr)) or [])
|
||||
weight = float(weightstr)
|
||||
_set_weight_values(devs, weight, opts)
|
||||
@ -236,7 +235,7 @@ def _parse_set_weight_values(argvish):
|
||||
print(Commands.set_weight.__doc__.strip())
|
||||
exit(EXIT_ERROR)
|
||||
|
||||
devs.extend(builder.search_devs(
|
||||
devs = (builder.search_devs(
|
||||
parse_search_values_from_opts(opts)) or [])
|
||||
weight = float(args[0])
|
||||
_set_weight_values(devs, weight, opts)
|
||||
|
@ -804,6 +804,21 @@ class TestCommands(unittest.TestCase, RunSwiftRingBuilderMixin):
|
||||
ring.rebalance()
|
||||
self.assertTrue(ring.validate())
|
||||
|
||||
def test_set_weight_old_format_two_devices(self):
|
||||
# Would block without the 'yes' argument
|
||||
self.create_sample_ring()
|
||||
argv = ["", self.tmpfile, "set_weight",
|
||||
"d2", "3.14", "d1", "6.28", "--yes"]
|
||||
self.assertSystemExit(EXIT_SUCCESS, ringbuilder.main, argv)
|
||||
|
||||
ring = RingBuilder.load(self.tmpfile)
|
||||
# Check that weight was changed
|
||||
self.assertEqual(ring.devs[2]['weight'], 3.14)
|
||||
self.assertEqual(ring.devs[1]['weight'], 6.28)
|
||||
# Check that other devices in ring are not affected
|
||||
self.assertEqual(ring.devs[0]['weight'], 100)
|
||||
self.assertEqual(ring.devs[3]['weight'], 100)
|
||||
|
||||
def test_set_weight_ipv4_old_format(self):
|
||||
self.create_sample_ring()
|
||||
# Test ipv4(old format)
|
||||
|
Loading…
x
Reference in New Issue
Block a user