Skip to content

Commit f37eda3

Browse files
author
Tang Chen
committed
Make SetFlavor and UnsetFlavor inherit from cliff.Command
set/unset comamnd classes should inherit from cliff.Command class. Change-Id: I54e5608ac0768d7d94b7f7d516ea1948daefdc1b Partial-Bug: 1546065
1 parent b5b5fdd commit f37eda3

5 files changed

Lines changed: 39 additions & 32 deletions

File tree

doc/source/backwards-incompatible.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,18 @@ List of Backwards Incompatible Changes
114114
* Bug: https://launchpad.net/bugs/1506841
115115
* Commit: https://review.openstack.org/#/c/236736/
116116

117+
9. `flavor set/unset` commands will no longer return the modified resource
118+
119+
Previously, modifying a flavor would result in the new flavor being displayed
120+
to the user. To keep things consistent with other `set/unset` commands, we
121+
will no longer be showing the modified resource.
122+
123+
* In favor of: Use `set/unset` then `show`
124+
* As of: NA
125+
* Removed in: NA
126+
* Bug: https://bugs.launchpad.net/python-openstackclient/+bug/1546065
127+
* Commit: https://review.openstack.org/#/c/280663/
128+
117129
For Developers
118130
==============
119131

functional/tests/compute/v2/test_flavor.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,20 @@ def test_flavor_show(self):
4646
self.assertEqual(self.NAME + "\n", raw_output)
4747

4848
def test_flavor_properties(self):
49-
opts = self.get_show_opts(["properties"])
49+
opts = self.get_show_opts(['properties'])
50+
5051
raw_output = self.openstack(
51-
'flavor set --property a=b --property c=d ' + self.NAME + opts)
52+
'flavor set --property a=b --property c=d ' + self.NAME
53+
)
54+
self.assertEqual('', raw_output)
55+
56+
raw_output = self.openstack('flavor show ' + self.NAME + opts)
5257
self.assertEqual("a='b', c='d'\n", raw_output)
5358

54-
raw_output = self.openstack('flavor unset --property a ' +
55-
self.NAME + opts)
59+
raw_output = self.openstack(
60+
'flavor unset --property a ' + self.NAME
61+
)
62+
self.assertEqual('', raw_output)
63+
64+
raw_output = self.openstack('flavor show ' + self.NAME + opts)
5665
self.assertEqual("c='d'\n", raw_output)

openstackclient/compute/v2/flavor.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ def take_action(self, parsed_args):
242242
return zip(*sorted(six.iteritems(flavor)))
243243

244244

245-
class SetFlavor(command.ShowOne):
245+
class SetFlavor(command.Command):
246246
"""Set flavor properties"""
247247

248248
def get_parser(self, prog_name):
@@ -263,17 +263,11 @@ def get_parser(self, prog_name):
263263

264264
def take_action(self, parsed_args):
265265
compute_client = self.app.client_manager.compute
266-
resource_flavor = compute_client.flavors.find(name=parsed_args.flavor)
266+
flavor = compute_client.flavors.find(name=parsed_args.flavor)
267+
flavor.set_keys(parsed_args.property)
267268

268-
resource_flavor.set_keys(parsed_args.property)
269269

270-
flavor = resource_flavor._info.copy()
271-
flavor['properties'] = utils.format_dict(resource_flavor.get_keys())
272-
flavor.pop("links", None)
273-
return zip(*sorted(six.iteritems(flavor)))
274-
275-
276-
class UnsetFlavor(command.ShowOne):
270+
class UnsetFlavor(command.Command):
277271
"""Unset flavor properties"""
278272

279273
def get_parser(self, prog_name):
@@ -295,11 +289,5 @@ def get_parser(self, prog_name):
295289

296290
def take_action(self, parsed_args):
297291
compute_client = self.app.client_manager.compute
298-
resource_flavor = compute_client.flavors.find(name=parsed_args.flavor)
299-
300-
resource_flavor.unset_keys(parsed_args.property)
301-
302-
flavor = resource_flavor._info.copy()
303-
flavor['properties'] = utils.format_dict(resource_flavor.get_keys())
304-
flavor.pop("links", None)
305-
return zip(*sorted(six.iteritems(flavor)))
292+
flavor = compute_client.flavors.find(name=parsed_args.flavor)
293+
flavor.unset_keys(parsed_args.property)

openstackclient/tests/compute/v2/test_flavor.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -285,15 +285,12 @@ def test_flavor_set(self):
285285
('property', {'FOO': '"B A R"'}),
286286
('flavor', 'baremetal')
287287
]
288-
289288
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
290289

291-
columns, data = self.cmd.take_action(parsed_args)
290+
result = self.cmd.take_action(parsed_args)
292291

293292
self.flavors_mock.find.assert_called_with(name='baremetal')
294-
295-
self.assertEqual('properties', columns[6])
296-
self.assertIn('FOO=\'"B A R"\'', data[6])
293+
self.assertIsNone(result)
297294

298295

299296
class TestFlavorShow(TestFlavor):
@@ -382,12 +379,9 @@ def test_flavor_unset(self):
382379
('property', ['property']),
383380
('flavor', 'baremetal'),
384381
]
385-
386382
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
387383

388-
columns, data = self.cmd.take_action(parsed_args)
384+
result = self.cmd.take_action(parsed_args)
389385

390386
self.flavors_mock.find.assert_called_with(name='baremetal')
391-
392-
self.assertEqual('properties', columns[6])
393-
self.assertNotIn('property', data[6])
387+
self.assertIsNone(result)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
fixes:
3+
- Command ``flavor set/unset`` now outputs nothing.
4+
[Bug `1546065 <https://bugs.launchpad.net/python-openstackclient/+bug/1546065>`_]

0 commit comments

Comments
 (0)