Deprecate --tenant option from flavor-access-list

The --tenant option in the flavor-access-list command was
never implemented and filtering by tenant is not supported
in the REST API for os-flavor-access, so to avoid confusion
this change deprecates the command line option.

It also removes the cruft that was in the python API code
so that only 'flavor' is allowed. This it not a backward
incompatible change since list() still takes kwargs and still
raises a NotImplementedError for anything in kwargs but
'flavor'.

Change-Id: I2c36376674f3a7caf5967a16ac0152f17d9fc906
Closes-Bug: #1582284
This commit is contained in:
Matt Riedemann 2016-05-16 12:08:48 -04:00
parent eea2512ec8
commit 1fd68964ea
3 changed files with 17 additions and 28 deletions

View File

@ -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'

View File

@ -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."""

View File

@ -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"))