swift-ring-builder can't select id=0
Currently, it is not possible to change weight of device with id=0 by swift-ring-builder cli. Instead of change the help is shown. Example: $ swift-ring-builder object.builder set_weight --id 0 1.00 But id=0 is generated by swift for the first device if not provided. Also --weight, --zone and --region cause the same bug. There is problem to detect new command format in validate_args function if zero is as valid value for some args. Change-Id: I4ee379c242f090d116cd2504e21d0e1904cdc2fc
This commit is contained in:
parent
6a9b868ae6
commit
a5d2faab90
@ -540,10 +540,12 @@ def validate_args(argvish):
|
||||
format or not.
|
||||
"""
|
||||
opts, args = parse_args(argvish)
|
||||
new_cmd_format = opts.id or opts.region or opts.zone or \
|
||||
opts.ip or opts.port or \
|
||||
# id can be 0 (swift starts generating id from 0),
|
||||
# also zone, region and weight can be set to zero.
|
||||
new_cmd_format = opts.id is not None or opts.region is not None or \
|
||||
opts.zone is not None or opts.ip or opts.port or \
|
||||
opts.replication_ip or opts.replication_port or \
|
||||
opts.device or opts.weight or opts.meta
|
||||
opts.device or opts.weight is not None or opts.meta
|
||||
return (new_cmd_format, opts, args)
|
||||
|
||||
|
||||
|
@ -468,6 +468,7 @@ class TestUtils(unittest.TestCase):
|
||||
self.assertEqual(opts.change_device, "sdb3")
|
||||
self.assertEqual(opts.change_meta, "some meta data for change")
|
||||
|
||||
def test_validate_args_new_cmd_format(self):
|
||||
argv = \
|
||||
["--id", "0", "--region", "0", "--zone", "0",
|
||||
"--ip", "",
|
||||
@ -484,17 +485,17 @@ class TestUtils(unittest.TestCase):
|
||||
"--change-device", "",
|
||||
"--change-meta", ""]
|
||||
new_cmd_format, opts, args = validate_args(argv)
|
||||
self.assertFalse(new_cmd_format)
|
||||
self.assertTrue(new_cmd_format)
|
||||
|
||||
argv = \
|
||||
["--id", "0", "--region", "0", "--zone", "0",
|
||||
["--id", None, "--region", None, "--zone", None,
|
||||
"--ip", "",
|
||||
"--port", "0",
|
||||
"--replication-ip", "",
|
||||
"--replication-port", "0",
|
||||
"--device", "",
|
||||
"--meta", "",
|
||||
"--weight", "0",
|
||||
"--weight", None,
|
||||
"--change-ip", "change.test.test.com",
|
||||
"--change-port", "6001",
|
||||
"--change-replication-ip", "change.r.test.com",
|
||||
@ -504,6 +505,23 @@ class TestUtils(unittest.TestCase):
|
||||
new_cmd_format, opts, args = validate_args(argv)
|
||||
self.assertFalse(new_cmd_format)
|
||||
|
||||
argv = \
|
||||
["--id", "0"]
|
||||
new_cmd_format, opts, args = validate_args(argv)
|
||||
self.assertTrue(new_cmd_format)
|
||||
argv = \
|
||||
["--region", "0"]
|
||||
new_cmd_format, opts, args = validate_args(argv)
|
||||
self.assertTrue(new_cmd_format)
|
||||
argv = \
|
||||
["--zone", "0"]
|
||||
new_cmd_format, opts, args = validate_args(argv)
|
||||
self.assertTrue(new_cmd_format)
|
||||
argv = \
|
||||
["--weight", "0"]
|
||||
new_cmd_format, opts, args = validate_args(argv)
|
||||
self.assertTrue(new_cmd_format)
|
||||
|
||||
def test_parse_args(self):
|
||||
argv = \
|
||||
["--id", "1", "--region", "2", "--zone", "3",
|
||||
|
Loading…
Reference in New Issue
Block a user