relinker: Allow multiple policies to be specified

Change-Id: I6805f0466f0200a58abe79cbb8ed3e6d2fd82d62
This commit is contained in:
Tim Burke 2021-03-19 10:33:12 -07:00
parent 31e27a168a
commit 3a41cbe670
2 changed files with 17 additions and 9 deletions

View File

@ -463,9 +463,10 @@ def main(args):
'Path to config file with [object-relinker] section')) 'Path to config file with [object-relinker] section'))
parser.add_argument('--swift-dir', default=None, parser.add_argument('--swift-dir', default=None,
dest='swift_dir', help='Path to swift directory') dest='swift_dir', help='Path to swift directory')
parser.add_argument('--policy', default=None, dest='policy', parser.add_argument(
type=policy, '--policy', default=[], dest='policies',
help='Policy to relink (default: all)') action='append', type=policy,
help='Policy to relink; may specify multiple (default: all)')
parser.add_argument('--devices', default=None, parser.add_argument('--devices', default=None,
dest='devices', help='Path to swift device directory') dest='devices', help='Path to swift device directory')
parser.add_argument('--user', default=None, dest='user', parser.add_argument('--user', default=None, dest='user',
@ -516,7 +517,7 @@ def main(args):
'files_per_second': ( 'files_per_second': (
args.files_per_second if args.files_per_second is not None args.files_per_second if args.files_per_second is not None
else non_negative_float(conf.get('files_per_second', '0'))), else non_negative_float(conf.get('files_per_second', '0'))),
'policies': POLICIES if args.policy is None else [args.policy], 'policies': set(args.policies) or POLICIES,
'partitions': set(args.partitions), 'partitions': set(args.partitions),
}) })

View File

@ -349,7 +349,7 @@ class TestRelinker(unittest.TestCase):
'files_per_second': 2.2, 'files_per_second': 2.2,
'log_level': 'DEBUG', 'log_level': 'DEBUG',
'log_name': 'test-relinker', 'log_name': 'test-relinker',
'policies': [POLICIES[1]], 'policies': {POLICIES[1]},
'partitions': {123, 456}, 'partitions': {123, 456},
}, mock.ANY, device='sdx') }, mock.ANY, device='sdx')
@ -372,16 +372,23 @@ class TestRelinker(unittest.TestCase):
with mock.patch('swift.cli.relinker.relink') as mock_relink, \ with mock.patch('swift.cli.relinker.relink') as mock_relink, \
mock.patch('logging.basicConfig') as mock_logging_config: mock.patch('logging.basicConfig') as mock_logging_config:
relinker.main(['relink', '--device', 'sdx', '--debug', relinker.main([
'--swift-dir', 'cli-dir', '--devices', 'cli-devs', 'relink', '--debug',
'--skip-mount-check']) '--swift-dir', 'cli-dir',
'--devices', 'cli-devs',
'--device', 'sdx',
'--skip-mount-check',
'--policy', '0',
'--policy', '1',
'--policy', '0',
])
mock_relink.assert_called_once_with({ mock_relink.assert_called_once_with({
'swift_dir': 'cli-dir', 'swift_dir': 'cli-dir',
'devices': 'cli-devs', 'devices': 'cli-devs',
'mount_check': False, 'mount_check': False,
'files_per_second': 0.0, 'files_per_second': 0.0,
'log_level': 'DEBUG', 'log_level': 'DEBUG',
'policies': POLICIES, 'policies': set(POLICIES),
'partitions': set(), 'partitions': set(),
}, mock.ANY, device='sdx') }, mock.ANY, device='sdx')
# --debug is now effective # --debug is now effective