From c360c3e8dad8bdf9f86b8f8596a956e518d0f526 Mon Sep 17 00:00:00 2001 From: Dean Troyer Date: Thu, 11 Jul 2013 14:23:32 -0500 Subject: [PATCH] Add AgregatesManager.get() utils.find_resource() uses manager.get() as part of converting Resource names to IDs. AggregatesManager had get_details() instead of get(). Add AggregatesManager.get(), leaving .get_details() in place for backward API compatibility. Bug: 1200341 Change-Id: I7d238bbe43e1760e31f1a9ba783c668246f20844 --- novaclient/tests/v1_1/test_aggregates.py | 19 ++++++++++++++----- novaclient/tests/v1_1/test_shell.py | 18 ++++++++++++------ novaclient/v1_1/aggregates.py | 8 +++++++- novaclient/v1_1/shell.py | 2 +- 4 files changed, 34 insertions(+), 13 deletions(-) diff --git a/novaclient/tests/v1_1/test_aggregates.py b/novaclient/tests/v1_1/test_aggregates.py index f46d0871d..bbd7f2c10 100644 --- a/novaclient/tests/v1_1/test_aggregates.py +++ b/novaclient/tests/v1_1/test_aggregates.py @@ -35,6 +35,15 @@ class AggregatesTest(utils.TestCase): cs.assert_called('POST', '/os-aggregates', body) self.assertTrue(isinstance(aggregate, aggregates.Aggregate)) + def test_get(self): + aggregate = cs.aggregates.get("1") + cs.assert_called('GET', '/os-aggregates/1') + self.assertTrue(isinstance(aggregate, aggregates.Aggregate)) + + aggregate2 = cs.aggregates.get(aggregate) + cs.assert_called('GET', '/os-aggregates/1') + self.assertTrue(isinstance(aggregate2, aggregates.Aggregate)) + def test_get_details(self): aggregate = cs.aggregates.get_details("1") cs.assert_called('GET', '/os-aggregates/1') @@ -45,7 +54,7 @@ class AggregatesTest(utils.TestCase): self.assertTrue(isinstance(aggregate2, aggregates.Aggregate)) def test_update(self): - aggregate = cs.aggregates.get_details("1") + aggregate = cs.aggregates.get("1") values = {"name": "foo"} body = {"aggregate": values} @@ -58,7 +67,7 @@ class AggregatesTest(utils.TestCase): self.assertTrue(isinstance(result2, aggregates.Aggregate)) def test_update_with_availability_zone(self): - aggregate = cs.aggregates.get_details("1") + aggregate = cs.aggregates.get("1") values = {"name": "foo", "availability_zone": "new_zone"} body = {"aggregate": values} @@ -67,7 +76,7 @@ class AggregatesTest(utils.TestCase): self.assertTrue(isinstance(result3, aggregates.Aggregate)) def test_add_host(self): - aggregate = cs.aggregates.get_details("1") + aggregate = cs.aggregates.get("1") host = "host1" body = {"add_host": {"host": "host1"}} @@ -84,7 +93,7 @@ class AggregatesTest(utils.TestCase): self.assertTrue(isinstance(result3, aggregates.Aggregate)) def test_remove_host(self): - aggregate = cs.aggregates.get_details("1") + aggregate = cs.aggregates.get("1") host = "host1" body = {"remove_host": {"host": "host1"}} @@ -101,7 +110,7 @@ class AggregatesTest(utils.TestCase): self.assertTrue(isinstance(result3, aggregates.Aggregate)) def test_set_metadata(self): - aggregate = cs.aggregates.get_details("1") + aggregate = cs.aggregates.get("1") metadata = {"foo": "bar"} body = {"set_metadata": {"metadata": metadata}} diff --git a/novaclient/tests/v1_1/test_shell.py b/novaclient/tests/v1_1/test_shell.py index 0107b0284..4d9786011 100644 --- a/novaclient/tests/v1_1/test_shell.py +++ b/novaclient/tests/v1_1/test_shell.py @@ -862,7 +862,8 @@ class ShellTest(utils.TestCase): self.run_command('aggregate-create test_name nova1') body = {"aggregate": {"name": "test_name", "availability_zone": "nova1"}} - self.assert_called('POST', '/os-aggregates', body) + self.assert_called('POST', '/os-aggregates', body, pos=-2) + self.assert_called('GET', '/os-aggregates/1', pos=-1) def test_aggregate_delete(self): self.run_command('aggregate-delete 1') @@ -871,28 +872,33 @@ class ShellTest(utils.TestCase): def test_aggregate_update(self): self.run_command('aggregate-update 1 new_name') body = {"aggregate": {"name": "new_name"}} - self.assert_called('PUT', '/os-aggregates/1', body) + 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(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) + self.assert_called('PUT', '/os-aggregates/1', body, pos=-2) + self.assert_called('GET', '/os-aggregates/1', pos=-1) def test_aggregate_set_metadata(self): self.run_command('aggregate-set-metadata 1 foo=bar delete_key') body = {"set_metadata": {"metadata": {"foo": "bar", "delete_key": None}}} - self.assert_called('POST', '/os-aggregates/1/action', body) + self.assert_called('POST', '/os-aggregates/1/action', body, pos=-2) + self.assert_called('GET', '/os-aggregates/1', pos=-1) def test_aggregate_add_host(self): self.run_command('aggregate-add-host 1 host1') body = {"add_host": {"host": "host1"}} - self.assert_called('POST', '/os-aggregates/1/action', body) + self.assert_called('POST', '/os-aggregates/1/action', body, pos=-2) + self.assert_called('GET', '/os-aggregates/1', pos=-1) def test_aggregate_remove_host(self): self.run_command('aggregate-remove-host 1 host1') body = {"remove_host": {"host": "host1"}} - self.assert_called('POST', '/os-aggregates/1/action', body) + self.assert_called('POST', '/os-aggregates/1/action', body, pos=-2) + self.assert_called('GET', '/os-aggregates/1', pos=-1) def test_aggregate_details(self): self.run_command('aggregate-details 1') diff --git a/novaclient/v1_1/aggregates.py b/novaclient/v1_1/aggregates.py index 576a81a49..c2df31526 100644 --- a/novaclient/v1_1/aggregates.py +++ b/novaclient/v1_1/aggregates.py @@ -54,11 +54,17 @@ class AggregateManager(base.ManagerWithFind): 'availability_zone': availability_zone}} return self._create('/os-aggregates', body, 'aggregate') - def get_details(self, aggregate): + def get(self, aggregate): """Get details of the specified aggregate.""" return self._get('/os-aggregates/%s' % (base.getid(aggregate)), "aggregate") + # NOTE:(dtroyer): utils.find_resource() uses manager.get() but we need to + # keep the API backward compatible + def get_details(self, aggregate): + """Get details of the specified aggregate.""" + return self.get(aggregate) + def update(self, aggregate, values): """Update the name and/or availability zone.""" body = {'aggregate': values} diff --git a/novaclient/v1_1/shell.py b/novaclient/v1_1/shell.py index 5d882a646..c5d9f85b4 100644 --- a/novaclient/v1_1/shell.py +++ b/novaclient/v1_1/shell.py @@ -2486,7 +2486,7 @@ def do_aggregate_remove_host(cs, args): @utils.arg('id', metavar='', help='Aggregate id.') def do_aggregate_details(cs, args): """Show details of the specified aggregate.""" - _print_aggregate_details(cs.aggregates.get_details(args.id)) + _print_aggregate_details(cs.aggregates.get(args.id)) def _print_aggregate_details(aggregate):