Merge "Deprecate --tenant option from flavor-access-list"

This commit is contained in:
Jenkins 2016-05-23 14:17:43 +00:00 committed by Gerrit Code Review
commit f510d8fd6f
3 changed files with 17 additions and 28 deletions
novaclient

@ -845,14 +845,11 @@ class ShellTest(utils.TestCase):
self.run_command('flavor-access-list --flavor 2')
self.assert_called('GET', '/flavors/2/os-flavor-access')
# FIXME: flavor-access-list is not implemented yet
# def test_flavor_access_list_tenant(self):
# self.run_command('flavor-access-list --tenant proj2')
# self.assert_called('GET', '/flavors/2/os-flavor-access')
def test_flavor_access_list_bad_filter(self):
cmd = 'flavor-access-list --flavor 2 --tenant proj2'
self.assertRaises(exceptions.CommandError, self.run_command, cmd)
_, err = self.run_command(cmd)
# assert the deprecation warning for using --tenant
self.assertIn('WARNING: Option "--tenant" is deprecated', err)
def test_flavor_access_list_no_filter(self):
cmd = 'flavor-access-list'

@ -30,22 +30,15 @@ class FlavorAccessManager(base.ManagerWithFind):
resource_class = FlavorAccess
def list(self, **kwargs):
# NOTE(mriedem): This looks a bit weird, you would normally expect this
# method to just take a flavor arg, but it used to erroneously accept
# flavor or tenant, but never actually implemented support for listing
# flavor access by tenant. We leave the interface unchanged though for
# backward compatibility.
if kwargs.get('flavor'):
return self._list_by_flavor(kwargs['flavor'])
elif kwargs.get('tenant'):
return self._list_by_tenant(kwargs['tenant'])
else:
raise NotImplementedError(_('Unknown list options.'))
def _list_by_flavor(self, flavor):
return self._list('/flavors/%s/os-flavor-access' % base.getid(flavor),
'flavor_access')
def _list_by_tenant(self, tenant):
"""Print flavor list shared with the given tenant."""
# TODO(uni): need to figure out a proper URI for list_by_tenant
# since current API already provided current tenant_id information
raise NotImplementedError(_('Sorry, query by tenant not supported.'))
return self._list('/flavors/%s/os-flavor-access' %
base.getid(kwargs['flavor']), 'flavor_access')
raise NotImplementedError(_('Unknown list options.'))
def add_tenant_access(self, flavor, tenant):
"""Add a tenant to the given flavor access list."""

@ -878,20 +878,19 @@ def do_flavor_key(cs, args):
help=_("Filter results by flavor name or ID."))
@utils.arg(
'--tenant', metavar='<tenant_id>',
help=_('Filter results by tenant ID.'))
help=_('Filter results by tenant ID.'),
action=shell.DeprecatedAction,
real_action='nothing',
use=_('this option is not supported, and will be '
'removed in version 5.0.0.'))
def do_flavor_access_list(cs, args):
"""Print access information about the given flavor."""
if args.flavor and args.tenant:
raise exceptions.CommandError(_("Unable to filter results by "
"both --flavor and --tenant."))
elif args.flavor:
if args.flavor:
flavor = _find_flavor(cs, args.flavor)
if flavor.is_public:
raise exceptions.CommandError(_("Access list not available "
"for public flavors."))
kwargs = {'flavor': flavor}
elif args.tenant:
kwargs = {'tenant': args.tenant}
else:
raise exceptions.CommandError(_("Unable to get all access lists. "
"Specify --flavor"))