Make SetFlavor and UnsetFlavor inherit from cliff.Command

set/unset comamnd classes should inherit from cliff.Command class.

Change-Id: I54e5608ac0768d7d94b7f7d516ea1948daefdc1b
Partial-Bug: 1546065
This commit is contained in:
Tang Chen 2016-02-17 10:07:50 +08:00
parent b5b5fdd78a
commit f37eda3a27
5 changed files with 39 additions and 32 deletions

View File

@ -114,6 +114,18 @@ List of Backwards Incompatible Changes
* Bug: https://launchpad.net/bugs/1506841
* Commit: https://review.openstack.org/#/c/236736/
9. `flavor set/unset` commands will no longer return the modified resource
Previously, modifying a flavor would result in the new flavor being displayed
to the user. To keep things consistent with other `set/unset` commands, we
will no longer be showing the modified resource.
* In favor of: Use `set/unset` then `show`
* As of: NA
* Removed in: NA
* Bug: https://bugs.launchpad.net/python-openstackclient/+bug/1546065
* Commit: https://review.openstack.org/#/c/280663/
For Developers
==============

View File

@ -46,11 +46,20 @@ class FlavorTests(test.TestCase):
self.assertEqual(self.NAME + "\n", raw_output)
def test_flavor_properties(self):
opts = self.get_show_opts(["properties"])
opts = self.get_show_opts(['properties'])
raw_output = self.openstack(
'flavor set --property a=b --property c=d ' + self.NAME + opts)
'flavor set --property a=b --property c=d ' + self.NAME
)
self.assertEqual('', raw_output)
raw_output = self.openstack('flavor show ' + self.NAME + opts)
self.assertEqual("a='b', c='d'\n", raw_output)
raw_output = self.openstack('flavor unset --property a ' +
self.NAME + opts)
raw_output = self.openstack(
'flavor unset --property a ' + self.NAME
)
self.assertEqual('', raw_output)
raw_output = self.openstack('flavor show ' + self.NAME + opts)
self.assertEqual("c='d'\n", raw_output)

View File

@ -242,7 +242,7 @@ class ShowFlavor(command.ShowOne):
return zip(*sorted(six.iteritems(flavor)))
class SetFlavor(command.ShowOne):
class SetFlavor(command.Command):
"""Set flavor properties"""
def get_parser(self, prog_name):
@ -263,17 +263,11 @@ class SetFlavor(command.ShowOne):
def take_action(self, parsed_args):
compute_client = self.app.client_manager.compute
resource_flavor = compute_client.flavors.find(name=parsed_args.flavor)
resource_flavor.set_keys(parsed_args.property)
flavor = resource_flavor._info.copy()
flavor['properties'] = utils.format_dict(resource_flavor.get_keys())
flavor.pop("links", None)
return zip(*sorted(six.iteritems(flavor)))
flavor = compute_client.flavors.find(name=parsed_args.flavor)
flavor.set_keys(parsed_args.property)
class UnsetFlavor(command.ShowOne):
class UnsetFlavor(command.Command):
"""Unset flavor properties"""
def get_parser(self, prog_name):
@ -295,11 +289,5 @@ class UnsetFlavor(command.ShowOne):
def take_action(self, parsed_args):
compute_client = self.app.client_manager.compute
resource_flavor = compute_client.flavors.find(name=parsed_args.flavor)
resource_flavor.unset_keys(parsed_args.property)
flavor = resource_flavor._info.copy()
flavor['properties'] = utils.format_dict(resource_flavor.get_keys())
flavor.pop("links", None)
return zip(*sorted(six.iteritems(flavor)))
flavor = compute_client.flavors.find(name=parsed_args.flavor)
flavor.unset_keys(parsed_args.property)

View File

@ -285,15 +285,12 @@ class TestFlavorSet(TestFlavor):
('property', {'FOO': '"B A R"'}),
('flavor', 'baremetal')
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
result = self.cmd.take_action(parsed_args)
self.flavors_mock.find.assert_called_with(name='baremetal')
self.assertEqual('properties', columns[6])
self.assertIn('FOO=\'"B A R"\'', data[6])
self.assertIsNone(result)
class TestFlavorShow(TestFlavor):
@ -382,12 +379,9 @@ class TestFlavorUnset(TestFlavor):
('property', ['property']),
('flavor', 'baremetal'),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
result = self.cmd.take_action(parsed_args)
self.flavors_mock.find.assert_called_with(name='baremetal')
self.assertEqual('properties', columns[6])
self.assertNotIn('property', data[6])
self.assertIsNone(result)

View File

@ -0,0 +1,4 @@
---
fixes:
- Command ``flavor set/unset`` now outputs nothing.
[Bug `1546065 <https://bugs.launchpad.net/python-openstackclient/+bug/1546065>`_]