[microversions] share one object for shell arguments

I8d599b712b17dcfc0be940a61c537d2dfe1b715b change provides a wrong fix for
an issue with cli arguments.

_find_actions method is designed to find all action methods(do_server_list,
do_server_show and etc). Since one module can include several versions of
one action(after microversion implementation) and only the last one will
be registrated in module, _find_actions method was adopted to handle
versioned methods.
Now it checks that discovered method is related to versioning stuff and
replace it by appropriate(in terms of microversions) functions. In this case,
the substituation is used only to determine function name and that it relates
to versioning methods. That is why the change(see a change-id above) is not
help at all.

We should share list object named "arguments"(it used by all action methods to
store cli arguments) with substitution and original method(which will be used
by _find_action). It will allow to put api_versions.wraps and cliutils.arg
decorators in any order.

Change-Id: Ief316a8597555db6cb02c9f23406b9f1f09f8313
This commit is contained in:
Andrey Kurilin 2015-12-15 17:51:33 +02:00
parent aa2687b3f7
commit fd450d8c60
2 changed files with 19 additions and 22 deletions

View File

@ -22,7 +22,6 @@ 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__)
@ -372,9 +371,12 @@ def wraps(start_version, end_version=None):
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)
# Let's share "arguments" with original method and substitution to
# allow put cliutils.arg and wraps decorators in any order
if not hasattr(func, 'arguments'):
func.arguments = []
substitution.arguments = func.arguments
return substitution
return decor

View File

@ -20,6 +20,7 @@ from novaclient import api_versions
from novaclient import exceptions
from novaclient.openstack.common import cliutils
from novaclient.tests.unit import utils
from novaclient import utils as nutils
from novaclient.v2 import versions
@ -277,27 +278,21 @@ 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):
def test_arguments_property_is_copied(self):
@cliutils.arg("argument_1")
@api_versions.wraps("2.666", "2.777")
@cliutils.arg("argument_2")
def some_func():
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
versioned_method = api_versions.get_substitutions(
nutils.get_function_name(some_func),
api_versions.APIVersion("2.700"))[0]
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)
self.assertEqual(some_func.arguments,
versioned_method.func.arguments)
self.assertIn((("argument_1",), {}), versioned_method.func.arguments)
self.assertIn((("argument_2",), {}), versioned_method.func.arguments)
class DiscoverVersionTestCase(utils.TestCase):