Merge "Copy cli arguments in api_versions.wraps decorator"

This commit is contained in:
Jenkins 2015-08-17 16:18:58 +00:00 committed by Gerrit Code Review
commit 17a37e5760
2 changed files with 33 additions and 3 deletions

View File

@ -22,6 +22,7 @@ from oslo_utils import strutils
import novaclient
from novaclient import exceptions
from novaclient.i18n import _, _LW
from novaclient.openstack.common import cliutils
from novaclient import utils
LOG = logging.getLogger(__name__)
@ -342,8 +343,14 @@ def wraps(start_version, end_version=None):
if not methods:
raise exceptions.VersionNotFoundForAPIMethod(
obj.api_version.get_string(), name)
else:
return max(methods, key=lambda f: f.start_version).func(
obj, *args, **kwargs)
method = max(methods, key=lambda f: f.start_version)
return method.func(obj, *args, **kwargs)
if hasattr(func, 'arguments'):
for cli_args, cli_kwargs in func.arguments:
cliutils.add_arg(substitution, *cli_args, **cli_kwargs)
return substitution
return decor

View File

@ -18,6 +18,7 @@ import mock
import novaclient
from novaclient import api_versions
from novaclient import exceptions
from novaclient.openstack.common import cliutils
from novaclient.tests.unit import utils
from novaclient.v2 import versions
@ -250,6 +251,28 @@ class WrapsTestCase(utils.TestCase):
checker.assert_called_once_with(*((obj,) + some_args), **some_kwargs)
def test_cli_args_are_copied(self):
@api_versions.wraps("2.2", "2.6")
@cliutils.arg("name_1", help="Name of the something")
@cliutils.arg("action_1", help="Some action")
def some_func_1(cs, args):
pass
@cliutils.arg("name_2", help="Name of the something")
@cliutils.arg("action_2", help="Some action")
@api_versions.wraps("2.2", "2.6")
def some_func_2(cs, args):
pass
args_1 = [(('name_1',), {'help': 'Name of the something'}),
(('action_1',), {'help': 'Some action'})]
self.assertEqual(args_1, some_func_1.arguments)
args_2 = [(('name_2',), {'help': 'Name of the something'}),
(('action_2',), {'help': 'Some action'})]
self.assertEqual(args_2, some_func_2.arguments)
class DiscoverVersionTestCase(utils.TestCase):
def setUp(self):