Skip to content

Commit 4524b36

Browse files
author
Huanxuan Ao
committed
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
1 parent 74162fa commit 4524b36

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

openstackclient/compute/v2/flavor.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,8 @@ def get_parser(self, prog_name):
239239

240240
def take_action(self, parsed_args):
241241
compute_client = self.app.client_manager.compute
242-
flavor = compute_client.flavors.find(name=parsed_args.flavor)
242+
flavor = utils.find_resource(compute_client.flavors,
243+
parsed_args.flavor)
243244
flavor.set_keys(parsed_args.property)
244245

245246

@@ -289,5 +290,6 @@ def get_parser(self, prog_name):
289290

290291
def take_action(self, parsed_args):
291292
compute_client = self.app.client_manager.compute
292-
flavor = compute_client.flavors.find(name=parsed_args.flavor)
293+
flavor = utils.find_resource(compute_client.flavors,
294+
parsed_args.flavor)
293295
flavor.unset_keys(parsed_args.property)

openstackclient/tests/compute/v2/test_flavor.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,10 @@ def test_flavor_set(self):
288288
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
289289

290290
result = self.cmd.take_action(parsed_args)
291-
292-
self.flavors_mock.find.assert_called_with(name='baremetal')
291+
try:
292+
self.flavors_mock.find.assert_called_with(name=parsed_args.flavor)
293+
except Exception:
294+
self.flavors_mock.get.assert_called_with(parsed_args.flavor)
293295
self.assertIsNone(result)
294296

295297

@@ -382,6 +384,8 @@ def test_flavor_unset(self):
382384
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
383385

384386
result = self.cmd.take_action(parsed_args)
385-
386-
self.flavors_mock.find.assert_called_with(name='baremetal')
387+
try:
388+
self.flavors_mock.find.assert_called_with(name=parsed_args.flavor)
389+
except Exception:
390+
self.flavors_mock.get.assert_called_with(parsed_args.flavor)
387391
self.assertIsNone(result)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
fixes:
3+
- Fixed ``flavor set/unset`` command to properly find a
4+
flavor to be set/unset by flavor id.
5+
[Bug `1575624 <https://bugs.launchpad.net/bugs/1575624>`_]

0 commit comments

Comments
 (0)