Skip to content

Commit 3a41cbe

Browse files
committed
relinker: Allow multiple policies to be specified
Change-Id: I6805f0466f0200a58abe79cbb8ed3e6d2fd82d62
1 parent 31e27a1 commit 3a41cbe

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

swift/cli/relinker.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -463,9 +463,10 @@ def main(args):
463463
'Path to config file with [object-relinker] section'))
464464
parser.add_argument('--swift-dir', default=None,
465465
dest='swift_dir', help='Path to swift directory')
466-
parser.add_argument('--policy', default=None, dest='policy',
467-
type=policy,
468-
help='Policy to relink (default: all)')
466+
parser.add_argument(
467+
'--policy', default=[], dest='policies',
468+
action='append', type=policy,
469+
help='Policy to relink; may specify multiple (default: all)')
469470
parser.add_argument('--devices', default=None,
470471
dest='devices', help='Path to swift device directory')
471472
parser.add_argument('--user', default=None, dest='user',
@@ -516,7 +517,7 @@ def main(args):
516517
'files_per_second': (
517518
args.files_per_second if args.files_per_second is not None
518519
else non_negative_float(conf.get('files_per_second', '0'))),
519-
'policies': POLICIES if args.policy is None else [args.policy],
520+
'policies': set(args.policies) or POLICIES,
520521
'partitions': set(args.partitions),
521522
})
522523

test/unit/cli/test_relinker.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ def test_conf_file(self):
349349
'files_per_second': 2.2,
350350
'log_level': 'DEBUG',
351351
'log_name': 'test-relinker',
352-
'policies': [POLICIES[1]],
352+
'policies': {POLICIES[1]},
353353
'partitions': {123, 456},
354354
}, mock.ANY, device='sdx')
355355

@@ -372,16 +372,23 @@ def test_conf_file(self):
372372

373373
with mock.patch('swift.cli.relinker.relink') as mock_relink, \
374374
mock.patch('logging.basicConfig') as mock_logging_config:
375-
relinker.main(['relink', '--device', 'sdx', '--debug',
376-
'--swift-dir', 'cli-dir', '--devices', 'cli-devs',
377-
'--skip-mount-check'])
375+
relinker.main([
376+
'relink', '--debug',
377+
'--swift-dir', 'cli-dir',
378+
'--devices', 'cli-devs',
379+
'--device', 'sdx',
380+
'--skip-mount-check',
381+
'--policy', '0',
382+
'--policy', '1',
383+
'--policy', '0',
384+
])
378385
mock_relink.assert_called_once_with({
379386
'swift_dir': 'cli-dir',
380387
'devices': 'cli-devs',
381388
'mount_check': False,
382389
'files_per_second': 0.0,
383390
'log_level': 'DEBUG',
384-
'policies': POLICIES,
391+
'policies': set(POLICIES),
385392
'partitions': set(),
386393
}, mock.ANY, device='sdx')
387394
# --debug is now effective

0 commit comments

Comments
 (0)