diff --git a/swiftbench/cli/__init__.py b/swiftbench/cli/__init__.py index 2941071..7bc41d5 100644 --- a/swiftbench/cli/__init__.py +++ b/swiftbench/cli/__init__.py @@ -119,6 +119,8 @@ def main(argv): parser.add_argument('-C', '--num-containers', type=int, help='Number of containers to distribute objects ' 'among') + parser.add_argument('--container-name', + help='Set the base container_name') parser.add_argument('-x', '--no-delete', dest='delete', action='store_false', help='If set, will not delete the objects created') @@ -157,8 +159,11 @@ def main(argv): options.put_concurrency = options.concurrency options.get_concurrency = options.concurrency options.del_concurrency = options.concurrency - options.containers = ['%s_%d' % (options.container_name, i) - for i in range(int(options.num_containers))] + if options.num_containers == 1: + options.containers = [options.container_name] + else: + options.containers = ['%s_%d' % (options.container_name, i) + for i in range(int(options.num_containers))] # Turn "yes"/"no"/etc. strings to booleans options.use_proxy = config_true_value(options.use_proxy) diff --git a/tests/test_cli.py b/tests/test_cli.py index 4c5b99a..de820fe 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -123,6 +123,7 @@ class TestCli(unittest.TestCase): '--num-objects', '5000', '--num-gets', '4000', '--num-containers', '4', + '--container-name', 'foo', '-x', '--auth_version', '2.0', '--delay', '10', @@ -143,6 +144,9 @@ class TestCli(unittest.TestCase): self.assertEqual(controller_opts.num_gets, 4000) self.assertEqual(controller_opts.num_containers, 4) self.assertEqual(len(controller_opts.containers), 4) + self.assertEqual([ + c.startswith('foo_') for c in controller_opts.containers + ], [True] * 4) self.assertFalse(controller_opts.delete) self.assertEqual(controller_opts.auth_version, '2.0') self.assertEqual(controller_opts.delay, 10) @@ -156,6 +160,12 @@ class TestCli(unittest.TestCase): self.assertEqual(controller_opts.timeout, 10) self.assertTrue(controller_opts.containers) + def test_single_container(self): + controller_opts, container_opts, del_opts = self.run_main([ + '--container-name', 'bar', '--num-containers', '1']) + self.assertEqual(controller_opts.num_containers, 1) + self.assertEqual(controller_opts.containers, ['bar']) + def test_concurrency_overrides_get_put_delete(self): controller_opts, container_opts, del_opts = self.run_main( [