summaryrefslogtreecommitdiff
path: root/openstackclient
diff options
context:
space:
mode:
authorGabriel Ramirez <gabrielramirez1109@gmail.com>2020-06-04 12:46:25 -0700
committerGabriel Ramirez <gabrielramirez1109@gmail.com>2020-06-10 22:49:44 +0000
commit176907f70eb5b84d15efc03571ca772706a164a6 (patch)
treee000e91961cb19121a5a875105c6ef57880befec /openstackclient
parent26b3b30853ee92d6d26dbc1ba6312709cc309f2d (diff)
downloadpython-openstackclient-176907f70eb5b84d15efc03571ca772706a164a6.tar.gz
Allow openstack flavor set to update flavor description using name
Modified take_action() method for SetFlavor to use flavor id instead of flavor name when setting description Closes-Bug: #1844708 Story: #2007781 Task: #40019 Change-Id: If6798c89fef4c9feb4ebb460722b891f5655037d
Diffstat (limited to 'openstackclient')
-rw-r--r--openstackclient/compute/v2/flavor.py2
-rw-r--r--openstackclient/tests/unit/compute/v2/test_flavor.py36
2 files changed, 37 insertions, 1 deletions
diff --git a/openstackclient/compute/v2/flavor.py b/openstackclient/compute/v2/flavor.py
index 42649db5..805e919e 100644
--- a/openstackclient/compute/v2/flavor.py
+++ b/openstackclient/compute/v2/flavor.py
@@ -402,7 +402,7 @@ class SetFlavor(command.Command):
if compute_client.api_version < api_versions.APIVersion("2.55"):
msg = _("--os-compute-api-version 2.55 or later is required")
raise exceptions.CommandError(msg)
- compute_client.flavors.update(flavor=parsed_args.flavor,
+ compute_client.flavors.update(flavor=flavor.id,
description=parsed_args.description)
diff --git a/openstackclient/tests/unit/compute/v2/test_flavor.py b/openstackclient/tests/unit/compute/v2/test_flavor.py
index fe7ce174..4732cc82 100644
--- a/openstackclient/tests/unit/compute/v2/test_flavor.py
+++ b/openstackclient/tests/unit/compute/v2/test_flavor.py
@@ -749,6 +749,42 @@ class TestFlavorSet(TestFlavor):
self.assertRaises(exceptions.CommandError, self.cmd.take_action,
parsed_args)
+ def test_flavor_set_description_using_name_api_newer(self):
+ arglist = [
+ '--description', 'description',
+ self.flavor.name,
+ ]
+ verifylist = [
+ ('description', 'description'),
+ ('flavor', self.flavor.name),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+ self.app.client_manager.compute.api_version = 2.55
+ with mock.patch.object(novaclient.api_versions,
+ 'APIVersion',
+ return_value=2.55):
+ result = self.cmd.take_action(parsed_args)
+ self.flavors_mock.update.assert_called_with(
+ flavor=self.flavor.id, description='description')
+ self.assertIsNone(result)
+
+ def test_flavor_set_description_using_name_api_older(self):
+ arglist = [
+ '--description', 'description',
+ self.flavor.name,
+ ]
+ verifylist = [
+ ('description', 'description'),
+ ('flavor', self.flavor.name),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+ self.app.client_manager.compute.api_version = 2.54
+ with mock.patch.object(novaclient.api_versions,
+ 'APIVersion',
+ return_value=2.55):
+ self.assertRaises(exceptions.CommandError, self.cmd.take_action,
+ parsed_args)
+
class TestFlavorShow(TestFlavor):