Fix error in flavor set/unset command

In the "flavor set/unset" command,the "flavor" parameter
can be a name but can not be a id of a flavor.
I think we should find a flavor by using "utils.find_resource()"
in these commands.

Change-Id: I5836788f7ed18813f1ebde31bb808b7c3f932b80
Closes-Bug: #1575624
This commit is contained in:
Huanxuan Ao 2016-04-28 11:09:49 +08:00
parent 74162fa31a
commit 4524b3605f
3 changed files with 17 additions and 6 deletions

View File

@ -239,7 +239,8 @@ class SetFlavor(command.Command):
def take_action(self, parsed_args):
compute_client = self.app.client_manager.compute
flavor = compute_client.flavors.find(name=parsed_args.flavor)
flavor = utils.find_resource(compute_client.flavors,
parsed_args.flavor)
flavor.set_keys(parsed_args.property)
@ -289,5 +290,6 @@ class UnsetFlavor(command.Command):
def take_action(self, parsed_args):
compute_client = self.app.client_manager.compute
flavor = compute_client.flavors.find(name=parsed_args.flavor)
flavor = utils.find_resource(compute_client.flavors,
parsed_args.flavor)
flavor.unset_keys(parsed_args.property)

View File

@ -288,8 +288,10 @@ class TestFlavorSet(TestFlavor):
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.take_action(parsed_args)
self.flavors_mock.find.assert_called_with(name='baremetal')
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.assertIsNone(result)
@ -382,6 +384,8 @@ class TestFlavorUnset(TestFlavor):
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.take_action(parsed_args)
self.flavors_mock.find.assert_called_with(name='baremetal')
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.assertIsNone(result)

View File

@ -0,0 +1,5 @@
---
fixes:
- Fixed ``flavor set/unset`` command to properly find a
flavor to be set/unset by flavor id.
[Bug `1575624 <https://bugs.launchpad.net/bugs/1575624>`_]