diff --git a/swift/cli/ringbuilder.py b/swift/cli/ringbuilder.py index a3a3570cbd..1b9cb05577 100644 --- a/swift/cli/ringbuilder.py +++ b/swift/cli/ringbuilder.py @@ -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) diff --git a/test/unit/cli/test_ringbuilder.py b/test/unit/cli/test_ringbuilder.py index cc485ee3a5..5cb6c0ec7c 100644 --- a/test/unit/cli/test_ringbuilder.py +++ b/test/unit/cli/test_ringbuilder.py @@ -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)