summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhuangtianhua <huangtianhua@huawei.com>2014-02-14 16:01:07 +0800
committerhuangtianhua <huangtianhua@huawei.com>2014-02-26 10:00:41 +0800
commita2a1ef8f36644c3487bdaf00b2e70bcc6b948fb4 (patch)
treeba335512b961af66f62a9b10eae0f3222f722f0d
parent5461af9c6ca0a56267b28b83930503a9d60214a9 (diff)
downloadpython-novaclient-a2a1ef8f36644c3487bdaf00b2e70bcc6b948fb4.tar.gz
'name' should as be optional param on aggregate-update
'name' should be an optional parameter not required on aggregate-update, so we can update 'availability_zone' only. Change-Id: I23e669a3362e0bea44adc88744eed823ec1e7ebb Closes-Bug: #1280118
-rw-r--r--novaclient/tests/v1_1/test_shell.py28
-rw-r--r--novaclient/tests/v3/test_shell.py28
-rw-r--r--novaclient/v1_1/shell.py12
-rw-r--r--novaclient/v3/shell.py12
4 files changed, 60 insertions, 20 deletions
diff --git a/novaclient/tests/v1_1/test_shell.py b/novaclient/tests/v1_1/test_shell.py
index a4c4ca19..feeba487 100644
--- a/novaclient/tests/v1_1/test_shell.py
+++ b/novaclient/tests/v1_1/test_shell.py
@@ -1149,26 +1149,42 @@ class ShellTest(utils.TestCase):
self.assert_called('DELETE', '/os-aggregates/1')
def test_aggregate_update_by_id(self):
- self.run_command('aggregate-update 1 new_name')
+ self.run_command('aggregate-update 1 --name 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(self):
- self.run_command('aggregate-update test new_name')
+ self.run_command('aggregate-update test --name 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(self):
- self.run_command('aggregate-update 1 foo new_zone')
- body = {"aggregate": {"name": "foo", "availability_zone": "new_zone"}}
+ self.run_command('aggregate-update 1 --availability_zone new_zone')
+ body = {"aggregate": {"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(self):
- self.run_command('aggregate-update test foo new_zone')
- body = {"aggregate": {"name": "foo", "availability_zone": "new_zone"}}
+ self.run_command('aggregate-update test --availability_zone new_zone')
+ body = {"aggregate": {"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_all_parameters_by_id(self):
+ self.run_command('aggregate-update 1 --name new_name '
+ '--availability_zone new_zone')
+ body = {"aggregate": {"name": "new_name",
+ "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_all_parameters_by_name(self):
+ self.run_command('aggregate-update test --name new_name '
+ '--availability_zone new_zone')
+ body = {"aggregate": {"name": "new_name",
+ "availability_zone": "new_zone"}}
self.assert_called('PUT', '/os-aggregates/1', body, pos=-2)
self.assert_called('GET', '/os-aggregates/1', pos=-1)
diff --git a/novaclient/tests/v3/test_shell.py b/novaclient/tests/v3/test_shell.py
index 85a839b4..796e73c6 100644
--- a/novaclient/tests/v3/test_shell.py
+++ b/novaclient/tests/v3/test_shell.py
@@ -104,26 +104,42 @@ class ShellTest(utils.TestCase):
self.assert_called('DELETE', '/os-aggregates/1')
def test_aggregate_update_by_id(self):
- self.run_command('aggregate-update 1 new_name')
+ self.run_command('aggregate-update 1 --name 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(self):
- self.run_command('aggregate-update test new_name')
+ self.run_command('aggregate-update test --name 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(self):
- self.run_command('aggregate-update 1 foo new_zone')
- body = {"aggregate": {"name": "foo", "availability_zone": "new_zone"}}
+ self.run_command('aggregate-update 1 --availability_zone new_zone')
+ body = {"aggregate": {"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(self):
- self.run_command('aggregate-update test foo new_zone')
- body = {"aggregate": {"name": "foo", "availability_zone": "new_zone"}}
+ self.run_command('aggregate-update test --availability_zone new_zone')
+ body = {"aggregate": {"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_all_parameters_by_id(self):
+ self.run_command('aggregate-update 1 --name new_name '
+ '--availability_zone new_zone')
+ body = {"aggregate": {"name": "new_name",
+ "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_all_parameters_by_name(self):
+ self.run_command('aggregate-update test --name new_name '
+ '--availability_zone new_zone')
+ body = {"aggregate": {"name": "new_name",
+ "availability_zone": "new_zone"}}
self.assert_called('PUT', '/os-aggregates/1', body, pos=-2)
self.assert_called('GET', '/os-aggregates/1', pos=-1)
diff --git a/novaclient/v1_1/shell.py b/novaclient/v1_1/shell.py
index c7a52098..24317642 100644
--- a/novaclient/v1_1/shell.py
+++ b/novaclient/v1_1/shell.py
@@ -2704,18 +2704,22 @@ def do_aggregate_delete(cs, args):
@utils.arg('aggregate', metavar='<aggregate>',
help=_('Name or ID of aggregate to update.'))
-@utils.arg('name', metavar='<name>', help=_('Name of aggregate.'))
-@utils.arg('availability_zone',
+@utils.arg('--name', metavar='<name>', help=_('New name of aggregate.'))
+@utils.arg('--availability_zone',
metavar='<availability-zone>',
- nargs='?',
default=None,
help=_('The availability zone of the aggregate.'))
def do_aggregate_update(cs, args):
"""Update the aggregate's name and optionally availability zone."""
aggregate = _find_aggregate(cs, args.aggregate)
- updates = {"name": args.name}
+ updates = {}
+ if args.name:
+ updates["name"] = args.name
if args.availability_zone:
updates["availability_zone"] = args.availability_zone
+ if not updates:
+ raise exceptions.CommandError(_("Must supply name "
+ "or availability_zone."))
aggregate = cs.aggregates.update(aggregate.id, updates)
print(_("Aggregate %s has been successfully updated.") % aggregate.id)
diff --git a/novaclient/v3/shell.py b/novaclient/v3/shell.py
index 10a6975d..02706c35 100644
--- a/novaclient/v3/shell.py
+++ b/novaclient/v3/shell.py
@@ -2230,18 +2230,22 @@ def do_aggregate_delete(cs, args):
@utils.arg('aggregate', metavar='<aggregate>',
help='Name or ID of aggregate to update.')
-@utils.arg('name', metavar='<name>', help='Name of aggregate.')
-@utils.arg('availability_zone',
+@utils.arg('--name', metavar='<name>', help='New name of aggregate.')
+@utils.arg('--availability_zone',
metavar='<availability-zone>',
- nargs='?',
default=None,
help='The availability zone of the aggregate.')
def do_aggregate_update(cs, args):
"""Update the aggregate's name and optionally availability zone."""
aggregate = _find_aggregate(cs, args.aggregate)
- updates = {"name": args.name}
+ updates = {}
+ if args.name:
+ updates["name"] = args.name
if args.availability_zone:
updates["availability_zone"] = args.availability_zone
+ if not updates:
+ raise exceptions.CommandError("Must supply name "
+ "or availability_zone.")
aggregate = cs.aggregates.update(aggregate.id, updates)
print("Aggregate %s has been successfully updated." % aggregate.id)