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
This commit is contained in:
Dean Troyer 2013-07-11 14:23:32 -05:00
parent a45c49bafc
commit c360c3e8da
4 changed files with 34 additions and 13 deletions

View File

@ -35,6 +35,15 @@ class AggregatesTest(utils.TestCase):
cs.assert_called('POST', '/os-aggregates', body) cs.assert_called('POST', '/os-aggregates', body)
self.assertTrue(isinstance(aggregate, aggregates.Aggregate)) 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): def test_get_details(self):
aggregate = cs.aggregates.get_details("1") aggregate = cs.aggregates.get_details("1")
cs.assert_called('GET', '/os-aggregates/1') cs.assert_called('GET', '/os-aggregates/1')
@ -45,7 +54,7 @@ class AggregatesTest(utils.TestCase):
self.assertTrue(isinstance(aggregate2, aggregates.Aggregate)) self.assertTrue(isinstance(aggregate2, aggregates.Aggregate))
def test_update(self): def test_update(self):
aggregate = cs.aggregates.get_details("1") aggregate = cs.aggregates.get("1")
values = {"name": "foo"} values = {"name": "foo"}
body = {"aggregate": values} body = {"aggregate": values}
@ -58,7 +67,7 @@ class AggregatesTest(utils.TestCase):
self.assertTrue(isinstance(result2, aggregates.Aggregate)) self.assertTrue(isinstance(result2, aggregates.Aggregate))
def test_update_with_availability_zone(self): 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"} values = {"name": "foo", "availability_zone": "new_zone"}
body = {"aggregate": values} body = {"aggregate": values}
@ -67,7 +76,7 @@ class AggregatesTest(utils.TestCase):
self.assertTrue(isinstance(result3, aggregates.Aggregate)) self.assertTrue(isinstance(result3, aggregates.Aggregate))
def test_add_host(self): def test_add_host(self):
aggregate = cs.aggregates.get_details("1") aggregate = cs.aggregates.get("1")
host = "host1" host = "host1"
body = {"add_host": {"host": "host1"}} body = {"add_host": {"host": "host1"}}
@ -84,7 +93,7 @@ class AggregatesTest(utils.TestCase):
self.assertTrue(isinstance(result3, aggregates.Aggregate)) self.assertTrue(isinstance(result3, aggregates.Aggregate))
def test_remove_host(self): def test_remove_host(self):
aggregate = cs.aggregates.get_details("1") aggregate = cs.aggregates.get("1")
host = "host1" host = "host1"
body = {"remove_host": {"host": "host1"}} body = {"remove_host": {"host": "host1"}}
@ -101,7 +110,7 @@ class AggregatesTest(utils.TestCase):
self.assertTrue(isinstance(result3, aggregates.Aggregate)) self.assertTrue(isinstance(result3, aggregates.Aggregate))
def test_set_metadata(self): def test_set_metadata(self):
aggregate = cs.aggregates.get_details("1") aggregate = cs.aggregates.get("1")
metadata = {"foo": "bar"} metadata = {"foo": "bar"}
body = {"set_metadata": {"metadata": metadata}} body = {"set_metadata": {"metadata": metadata}}

View File

@ -862,7 +862,8 @@ class ShellTest(utils.TestCase):
self.run_command('aggregate-create test_name nova1') self.run_command('aggregate-create test_name nova1')
body = {"aggregate": {"name": "test_name", body = {"aggregate": {"name": "test_name",
"availability_zone": "nova1"}} "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): def test_aggregate_delete(self):
self.run_command('aggregate-delete 1') self.run_command('aggregate-delete 1')
@ -871,28 +872,33 @@ class ShellTest(utils.TestCase):
def test_aggregate_update(self): def test_aggregate_update(self):
self.run_command('aggregate-update 1 new_name') self.run_command('aggregate-update 1 new_name')
body = {"aggregate": {"name": "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): def test_aggregate_update_with_availability_zone(self):
self.run_command('aggregate-update 1 foo new_zone') self.run_command('aggregate-update 1 foo new_zone')
body = {"aggregate": {"name": "foo", "availability_zone": "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): def test_aggregate_set_metadata(self):
self.run_command('aggregate-set-metadata 1 foo=bar delete_key') self.run_command('aggregate-set-metadata 1 foo=bar delete_key')
body = {"set_metadata": {"metadata": {"foo": "bar", body = {"set_metadata": {"metadata": {"foo": "bar",
"delete_key": None}}} "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): def test_aggregate_add_host(self):
self.run_command('aggregate-add-host 1 host1') self.run_command('aggregate-add-host 1 host1')
body = {"add_host": {"host": "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): def test_aggregate_remove_host(self):
self.run_command('aggregate-remove-host 1 host1') self.run_command('aggregate-remove-host 1 host1')
body = {"remove_host": {"host": "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): def test_aggregate_details(self):
self.run_command('aggregate-details 1') self.run_command('aggregate-details 1')

View File

@ -54,11 +54,17 @@ class AggregateManager(base.ManagerWithFind):
'availability_zone': availability_zone}} 'availability_zone': availability_zone}}
return self._create('/os-aggregates', body, 'aggregate') return self._create('/os-aggregates', body, 'aggregate')
def get_details(self, aggregate): def get(self, aggregate):
"""Get details of the specified aggregate.""" """Get details of the specified aggregate."""
return self._get('/os-aggregates/%s' % (base.getid(aggregate)), return self._get('/os-aggregates/%s' % (base.getid(aggregate)),
"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): def update(self, aggregate, values):
"""Update the name and/or availability zone.""" """Update the name and/or availability zone."""
body = {'aggregate': values} body = {'aggregate': values}

View File

@ -2486,7 +2486,7 @@ def do_aggregate_remove_host(cs, args):
@utils.arg('id', metavar='<id>', help='Aggregate id.') @utils.arg('id', metavar='<id>', help='Aggregate id.')
def do_aggregate_details(cs, args): def do_aggregate_details(cs, args):
"""Show details of the specified aggregate.""" """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): def _print_aggregate_details(aggregate):