]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Updating cmd/manage.py get_arg_string() argument parser and adding unit test
authorDaniel Allegood <daniel.allegood@hp.com>
Wed, 27 May 2015 17:27:06 +0000 (10:27 -0700)
committerDaniel Allegood <daniel.allegood@hp.com>
Thu, 28 May 2015 18:10:22 +0000 (18:10 +0000)
Looks like get_arg_string() would improperly chop off the first two characters
of an argument that was passed in with one dash.  For example,
passing '-option foo' would return 'tion foo' instead of 'option foo'.

Change-Id: Ib9aee601711b22c5243aca35f5c6196f494d23a9
Closes-Bug: #1459453

cinder/cmd/manage.py
cinder/tests/unit/test_cmd.py

index 57b5683a71f7bb87ea050f7d1a8cccd1617d542f..76f9d7cf623ae19624dd80f39de53a227480145d 100644 (file)
@@ -514,7 +514,7 @@ def get_arg_string(args):
             # This is long optional arg
             arg = args[2:]
         else:
-            arg = args[3:]
+            arg = args[1:]
     else:
         arg = args
 
index 8b2a031bc440ad96c168fdf70d186744b927cd4e..384d07de8313945af20d4392954364c1c0b89b79 100644 (file)
@@ -641,6 +641,15 @@ class TestCinderManageCmd(test.TestCase):
             service_get_all.assert_called_with(ctxt)
             service_is_up.assert_called_with(service)
 
+    def test_get_arg_string(self):
+        args1 = "foobar"
+        args2 = "-foo bar"
+        args3 = "--foo bar"
+
+        self.assertEqual("foobar", cinder_manage.get_arg_string(args1))
+        self.assertEqual("foo bar", cinder_manage.get_arg_string(args2))
+        self.assertEqual("foo bar", cinder_manage.get_arg_string(args3))
+
     @mock.patch('oslo_config.cfg.ConfigOpts.register_cli_opt')
     def test_main_argv_lt_2(self, register_cli_opt):
         script_name = 'cinder-manage'