Skip to content

Commit 41aeb89

Browse files
kk7dsmriedem
authored andcommitted
Fix aggregate_update name and availability_zone clash
The name and availability_zone arguments to aggregate update were replaced by optional parameters in change I778ab7ec54a376c60f19dcc89fe62fcab6e59e42. However, the '--name' and 'name' arguments in the parser would conflict, resulting in only the deprecated argument working. Thus, attempting to update the name on an aggregate using --name would end up doing a PUT with no new name provided. Note that there were unit tests for this, but they were not catching this problem. So, this removes those tests and adds functional tests to poke it. Change-Id: Ifef6fdc1a737dd219712a4525d4e34afd3fbd80c Closes-Bug: #1673789 (cherry picked from commit 20f0055) (cherry picked from commit 983f721)
1 parent 5620beb commit 41aeb89

File tree

3 files changed

+72
-30
lines changed

3 files changed

+72
-30
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# -*- coding: utf-8 -*-
2+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
3+
# not use this file except in compliance with the License. You may obtain
4+
# a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11+
# License for the specific language governing permissions and limitations
12+
# under the License.
13+
14+
from oslo_utils import uuidutils
15+
16+
from novaclient.tests.functional import base
17+
18+
19+
class TestAggregatesNovaClient(base.ClientTestBase):
20+
COMPUTE_API_VERSION = '2.1'
21+
22+
def setUp(self):
23+
super(TestAggregatesNovaClient, self).setUp()
24+
self.agg1 = 'agg-%s' % uuidutils.generate_uuid()
25+
self.agg2 = 'agg-%s' % uuidutils.generate_uuid()
26+
self.addCleanup(self._clean_aggregates)
27+
28+
def _clean_aggregates(self):
29+
for a in (self.agg1, self.agg2):
30+
try:
31+
self.nova('aggregate-delete', params=a)
32+
except Exception:
33+
pass
34+
35+
def test_aggregate_update_name_legacy(self):
36+
self.nova('aggregate-create', params=self.agg1)
37+
self.nova('aggregate-update', params='%s %s' % (self.agg1, self.agg2))
38+
output = self.nova('aggregate-show', params=self.agg2)
39+
self.assertIn(self.agg2, output)
40+
self.nova('aggregate-delete', params=self.agg2)
41+
42+
def test_aggregate_update_name(self):
43+
self.nova('aggregate-create', params=self.agg1)
44+
self.nova('aggregate-update',
45+
params='--name=%s %s' % (self.agg2, self.agg1))
46+
output = self.nova('aggregate-show', params=self.agg2)
47+
self.assertIn(self.agg2, output)
48+
self.nova('aggregate-delete', params=self.agg2)
49+
50+
def test_aggregate_update_az_legacy(self):
51+
self.nova('aggregate-create', params=self.agg2)
52+
self.nova('aggregate-update',
53+
params='%s %s myaz' % (self.agg2, self.agg2))
54+
output = self.nova('aggregate-show', params=self.agg2)
55+
self.assertIn('myaz', output)
56+
self.nova('aggregate-delete', params=self.agg2)
57+
58+
def test_aggregate_update_az(self):
59+
self.nova('aggregate-create', params=self.agg2)
60+
self.nova('aggregate-update',
61+
params='--availability-zone=myaz %s' % self.agg2)
62+
output = self.nova('aggregate-show', params=self.agg2)
63+
self.assertIn('myaz', output)
64+
self.nova('aggregate-delete', params=self.agg2)

novaclient/tests/unit/v2/test_shell.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,30 +1861,6 @@ def test_aggregate_update_with_availability_zone_by_name(self):
18611861
self.assert_called('PUT', '/os-aggregates/1', body, pos=-2)
18621862
self.assert_called('GET', '/os-aggregates/1', pos=-1)
18631863

1864-
def test_aggregate_update_by_id_legacy(self):
1865-
self.run_command('aggregate-update 1 new_name')
1866-
body = {"aggregate": {"name": "new_name"}}
1867-
self.assert_called('PUT', '/os-aggregates/1', body, pos=-2)
1868-
self.assert_called('GET', '/os-aggregates/1', pos=-1)
1869-
1870-
def test_aggregate_update_by_name_legacy(self):
1871-
self.run_command('aggregate-update test new_name')
1872-
body = {"aggregate": {"name": "new_name"}}
1873-
self.assert_called('PUT', '/os-aggregates/1', body, pos=-2)
1874-
self.assert_called('GET', '/os-aggregates/1', pos=-1)
1875-
1876-
def test_aggregate_update_with_availability_zone_by_id_legacy(self):
1877-
self.run_command('aggregate-update 1 foo new_zone')
1878-
body = {"aggregate": {"name": "foo", "availability_zone": "new_zone"}}
1879-
self.assert_called('PUT', '/os-aggregates/1', body, pos=-2)
1880-
self.assert_called('GET', '/os-aggregates/1', pos=-1)
1881-
1882-
def test_aggregate_update_with_availability_zone_by_name_legacy(self):
1883-
self.run_command('aggregate-update test foo new_zone')
1884-
body = {"aggregate": {"name": "foo", "availability_zone": "new_zone"}}
1885-
self.assert_called('PUT', '/os-aggregates/1', body, pos=-2)
1886-
self.assert_called('GET', '/os-aggregates/1', pos=-1)
1887-
18881864
def test_aggregate_set_metadata_add_by_id(self):
18891865
self.run_command('aggregate-set-metadata 3 foo=bar')
18901866
body = {"set_metadata": {"metadata": {"foo": "bar"}}}

novaclient/v2/shell.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3733,7 +3733,8 @@ def do_aggregate_delete(cs, args):
37333733
metavar='<aggregate>',
37343734
help=_('Name or ID of aggregate to update.'))
37353735
@utils.arg(
3736-
'name',
3736+
'old_name',
3737+
metavar='<name>',
37373738
nargs='?',
37383739
action=shell.DeprecatedAction,
37393740
use=_('use "%s"; this option will be removed in '
@@ -3744,7 +3745,7 @@ def do_aggregate_delete(cs, args):
37443745
dest='name',
37453746
help=_('Name of aggregate.'))
37463747
@utils.arg(
3747-
'availability_zone',
3748+
'old_availability_zone',
37483749
metavar='<availability-zone>',
37493750
nargs='?',
37503751
default=None,
@@ -3761,10 +3762,11 @@ def do_aggregate_update(cs, args):
37613762
"""Update the aggregate's name and optionally availability zone."""
37623763
aggregate = _find_aggregate(cs, args.aggregate)
37633764
updates = {}
3764-
if args.name:
3765-
updates["name"] = args.name
3766-
if args.availability_zone:
3767-
updates["availability_zone"] = args.availability_zone
3765+
if args.name or args.old_name:
3766+
updates["name"] = args.name or args.old_name
3767+
if args.availability_zone or args.old_availability_zone:
3768+
updates["availability_zone"] = (args.availability_zone or
3769+
args.old_availability_zone)
37683770

37693771
aggregate = cs.aggregates.update(aggregate.id, updates)
37703772
print(_("Aggregate %s has been successfully updated.") % aggregate.id)

0 commit comments

Comments
 (0)