summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--novaclient/tests/functional/v2/test_aggregates.py64
-rw-r--r--novaclient/tests/unit/v2/test_shell.py24
-rw-r--r--novaclient/v2/shell.py14
3 files changed, 72 insertions, 30 deletions
diff --git a/novaclient/tests/functional/v2/test_aggregates.py b/novaclient/tests/functional/v2/test_aggregates.py
new file mode 100644
index 00000000..6eb30242
--- /dev/null
+++ b/novaclient/tests/functional/v2/test_aggregates.py
@@ -0,0 +1,64 @@
+# -*- coding: utf-8 -*-
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+from oslo_utils import uuidutils
+
+from novaclient.tests.functional import base
+
+
+class TestAggregatesNovaClient(base.ClientTestBase):
+ COMPUTE_API_VERSION = '2.1'
+
+ def setUp(self):
+ super(TestAggregatesNovaClient, self).setUp()
+ self.agg1 = 'agg-%s' % uuidutils.generate_uuid()
+ self.agg2 = 'agg-%s' % uuidutils.generate_uuid()
+ self.addCleanup(self._clean_aggregates)
+
+ def _clean_aggregates(self):
+ for a in (self.agg1, self.agg2):
+ try:
+ self.nova('aggregate-delete', params=a)
+ except Exception:
+ pass
+
+ def test_aggregate_update_name_legacy(self):
+ self.nova('aggregate-create', params=self.agg1)
+ self.nova('aggregate-update', params='%s %s' % (self.agg1, self.agg2))
+ output = self.nova('aggregate-show', params=self.agg2)
+ self.assertIn(self.agg2, output)
+ self.nova('aggregate-delete', params=self.agg2)
+
+ def test_aggregate_update_name(self):
+ self.nova('aggregate-create', params=self.agg1)
+ self.nova('aggregate-update',
+ params='--name=%s %s' % (self.agg2, self.agg1))
+ output = self.nova('aggregate-show', params=self.agg2)
+ self.assertIn(self.agg2, output)
+ self.nova('aggregate-delete', params=self.agg2)
+
+ def test_aggregate_update_az_legacy(self):
+ self.nova('aggregate-create', params=self.agg2)
+ self.nova('aggregate-update',
+ params='%s %s myaz' % (self.agg2, self.agg2))
+ output = self.nova('aggregate-show', params=self.agg2)
+ self.assertIn('myaz', output)
+ self.nova('aggregate-delete', params=self.agg2)
+
+ def test_aggregate_update_az(self):
+ self.nova('aggregate-create', params=self.agg2)
+ self.nova('aggregate-update',
+ params='--availability-zone=myaz %s' % self.agg2)
+ output = self.nova('aggregate-show', params=self.agg2)
+ self.assertIn('myaz', output)
+ self.nova('aggregate-delete', params=self.agg2)
diff --git a/novaclient/tests/unit/v2/test_shell.py b/novaclient/tests/unit/v2/test_shell.py
index 34eec493..6e88fc09 100644
--- a/novaclient/tests/unit/v2/test_shell.py
+++ b/novaclient/tests/unit/v2/test_shell.py
@@ -1861,30 +1861,6 @@ class ShellTest(utils.TestCase):
self.assert_called('PUT', '/os-aggregates/1', body, pos=-2)
self.assert_called('GET', '/os-aggregates/1', pos=-1)
- def test_aggregate_update_by_id_legacy(self):
- self.run_command('aggregate-update 1 new_name')
- body = {"aggregate": {"name": "new_name"}}
- self.assert_called('PUT', '/os-aggregates/1', body, pos=-2)
- self.assert_called('GET', '/os-aggregates/1', pos=-1)
-
- def test_aggregate_update_by_name_legacy(self):
- self.run_command('aggregate-update test new_name')
- body = {"aggregate": {"name": "new_name"}}
- self.assert_called('PUT', '/os-aggregates/1', body, pos=-2)
- self.assert_called('GET', '/os-aggregates/1', pos=-1)
-
- def test_aggregate_update_with_availability_zone_by_id_legacy(self):
- self.run_command('aggregate-update 1 foo new_zone')
- body = {"aggregate": {"name": "foo", "availability_zone": "new_zone"}}
- self.assert_called('PUT', '/os-aggregates/1', body, pos=-2)
- self.assert_called('GET', '/os-aggregates/1', pos=-1)
-
- def test_aggregate_update_with_availability_zone_by_name_legacy(self):
- self.run_command('aggregate-update test foo new_zone')
- body = {"aggregate": {"name": "foo", "availability_zone": "new_zone"}}
- self.assert_called('PUT', '/os-aggregates/1', body, pos=-2)
- self.assert_called('GET', '/os-aggregates/1', pos=-1)
-
def test_aggregate_set_metadata_add_by_id(self):
self.run_command('aggregate-set-metadata 3 foo=bar')
body = {"set_metadata": {"metadata": {"foo": "bar"}}}
diff --git a/novaclient/v2/shell.py b/novaclient/v2/shell.py
index 36f0080c..ad902461 100644
--- a/novaclient/v2/shell.py
+++ b/novaclient/v2/shell.py
@@ -3733,7 +3733,8 @@ def do_aggregate_delete(cs, args):
metavar='<aggregate>',
help=_('Name or ID of aggregate to update.'))
@utils.arg(
- 'name',
+ 'old_name',
+ metavar='<name>',
nargs='?',
action=shell.DeprecatedAction,
use=_('use "%s"; this option will be removed in '
@@ -3744,7 +3745,7 @@ def do_aggregate_delete(cs, args):
dest='name',
help=_('Name of aggregate.'))
@utils.arg(
- 'availability_zone',
+ 'old_availability_zone',
metavar='<availability-zone>',
nargs='?',
default=None,
@@ -3761,10 +3762,11 @@ def do_aggregate_update(cs, args):
"""Update the aggregate's name and optionally availability zone."""
aggregate = _find_aggregate(cs, args.aggregate)
updates = {}
- if args.name:
- updates["name"] = args.name
- if args.availability_zone:
- updates["availability_zone"] = args.availability_zone
+ if args.name or args.old_name:
+ updates["name"] = args.name or args.old_name
+ if args.availability_zone or args.old_availability_zone:
+ updates["availability_zone"] = (args.availability_zone or
+ args.old_availability_zone)
aggregate = cs.aggregates.update(aggregate.id, updates)
print(_("Aggregate %s has been successfully updated.") % aggregate.id)