Merge "Make "flavor show" command to show a private flavor properly"
This commit is contained in:
commit
467ed54d6d
@ -18,10 +18,29 @@
|
||||
import six
|
||||
|
||||
from openstackclient.common import command
|
||||
from openstackclient.common import exceptions
|
||||
from openstackclient.common import parseractions
|
||||
from openstackclient.common import utils
|
||||
|
||||
|
||||
def _find_flavor(compute_client, flavor):
|
||||
try:
|
||||
return compute_client.flavors.get(flavor)
|
||||
except Exception as ex:
|
||||
if type(ex).__name__ == 'NotFound':
|
||||
pass
|
||||
else:
|
||||
raise
|
||||
try:
|
||||
return compute_client.flavors.find(name=flavor, is_public=None)
|
||||
except Exception as ex:
|
||||
if type(ex).__name__ == 'NotFound':
|
||||
msg = "No flavor with a name or ID of '%s' exists." % flavor
|
||||
raise exceptions.CommandError(msg)
|
||||
else:
|
||||
raise
|
||||
|
||||
|
||||
class CreateFlavor(command.ShowOne):
|
||||
"""Create new flavor"""
|
||||
|
||||
@ -132,8 +151,7 @@ class DeleteFlavor(command.Command):
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
compute_client = self.app.client_manager.compute
|
||||
flavor = utils.find_resource(compute_client.flavors,
|
||||
parsed_args.flavor)
|
||||
flavor = _find_flavor(compute_client, parsed_args.flavor)
|
||||
compute_client.flavors.delete(flavor.id)
|
||||
|
||||
|
||||
@ -239,8 +257,7 @@ class SetFlavor(command.Command):
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
compute_client = self.app.client_manager.compute
|
||||
flavor = utils.find_resource(compute_client.flavors,
|
||||
parsed_args.flavor)
|
||||
flavor = _find_flavor(compute_client, parsed_args.flavor)
|
||||
flavor.set_keys(parsed_args.property)
|
||||
|
||||
|
||||
@ -258,8 +275,7 @@ class ShowFlavor(command.ShowOne):
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
compute_client = self.app.client_manager.compute
|
||||
resource_flavor = utils.find_resource(compute_client.flavors,
|
||||
parsed_args.flavor)
|
||||
resource_flavor = _find_flavor(compute_client, parsed_args.flavor)
|
||||
flavor = resource_flavor._info.copy()
|
||||
flavor.pop("links", None)
|
||||
|
||||
@ -290,6 +306,5 @@ class UnsetFlavor(command.Command):
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
compute_client = self.app.client_manager.compute
|
||||
flavor = utils.find_resource(compute_client.flavors,
|
||||
parsed_args.flavor)
|
||||
flavor = _find_flavor(compute_client, parsed_args.flavor)
|
||||
flavor.unset_keys(parsed_args.property)
|
||||
|
@ -433,7 +433,7 @@ class TestFlavorSet(TestFlavor):
|
||||
super(TestFlavorSet, self).setUp()
|
||||
|
||||
self.flavors_mock.find.return_value = self.flavor
|
||||
|
||||
self.flavors_mock.get.side_effect = exceptions.NotFound(None)
|
||||
self.cmd = flavor.SetFlavor(self.app, None)
|
||||
|
||||
def test_flavor_set(self):
|
||||
@ -448,10 +448,8 @@ class TestFlavorSet(TestFlavor):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
try:
|
||||
self.flavors_mock.find.assert_called_with(name=parsed_args.flavor)
|
||||
except Exception:
|
||||
self.flavors_mock.get.assert_called_with(parsed_args.flavor)
|
||||
self.flavors_mock.find.assert_called_with(name=parsed_args.flavor,
|
||||
is_public=None)
|
||||
self.assertIsNone(result)
|
||||
|
||||
|
||||
@ -491,9 +489,9 @@ class TestFlavorShow(TestFlavor):
|
||||
def setUp(self):
|
||||
super(TestFlavorShow, self).setUp()
|
||||
|
||||
# Return value of utils.find_resource()
|
||||
self.flavors_mock.get.return_value = self.flavor
|
||||
|
||||
# Return value of _find_resource()
|
||||
self.flavors_mock.find.return_value = self.flavor
|
||||
self.flavors_mock.get.side_effect = exceptions.NotFound(None)
|
||||
self.cmd = flavor.ShowFlavor(self.app, None)
|
||||
|
||||
def test_show_no_options(self):
|
||||
@ -529,7 +527,7 @@ class TestFlavorUnset(TestFlavor):
|
||||
super(TestFlavorUnset, self).setUp()
|
||||
|
||||
self.flavors_mock.find.return_value = self.flavor
|
||||
|
||||
self.flavors_mock.get.side_effect = exceptions.NotFound(None)
|
||||
self.cmd = flavor.UnsetFlavor(self.app, None)
|
||||
|
||||
def test_flavor_unset(self):
|
||||
@ -544,8 +542,6 @@ class TestFlavorUnset(TestFlavor):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
try:
|
||||
self.flavors_mock.find.assert_called_with(name=parsed_args.flavor)
|
||||
except Exception:
|
||||
self.flavors_mock.get.assert_called_with(parsed_args.flavor)
|
||||
self.flavors_mock.find.assert_called_with(name=parsed_args.flavor,
|
||||
is_public=None)
|
||||
self.assertIsNone(result)
|
||||
|
5
releasenotes/notes/bug-1575478-5a0a923c3a32f96a.yaml
Normal file
5
releasenotes/notes/bug-1575478-5a0a923c3a32f96a.yaml
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
fixes:
|
||||
- Fixed ``flavor show/delete/set/unset`` command to properly
|
||||
find a private flavor by flavor name.
|
||||
[Bug `1575478 <https://bugs.launchpad.net/bugs/1575478>`_]
|
Loading…
x
Reference in New Issue
Block a user