Make aggregates_client use **kwargs
As we discussed on
http://lists.openstack.org/pipermail/openstack-dev/2015-July/068864.html
All http POST/PUT methods need to contain **kwargs as their arguments.
This patch makes aggregates_client use **kwargs.
Partially implements blueprint consistent-service-method-names
Change-Id: If155980d6381083d110b5749ba3203d7883c5cbc
diff --git a/tempest/api/compute/admin/test_aggregates.py b/tempest/api/compute/admin/test_aggregates.py
index 91e55d6..9334fb6 100644
--- a/tempest/api/compute/admin/test_aggregates.py
+++ b/tempest/api/compute/admin/test_aggregates.py
@@ -106,7 +106,7 @@
# set the metadata of the aggregate
meta = {"key": "value"}
- body = self.client.set_metadata(aggregate['id'], meta)
+ body = self.client.set_metadata(aggregate['id'], metadata=meta)
self.assertEqual(meta, body["metadata"])
# verify the metadata has been set
@@ -130,9 +130,10 @@
new_aggregate_name = aggregate_name + '_new'
new_az_name = az_name + '_new'
- resp_aggregate = self.client.update_aggregate(aggregate_id,
- new_aggregate_name,
- new_az_name)
+ resp_aggregate = self.client.update_aggregate(
+ aggregate_id,
+ name=new_aggregate_name,
+ availability_zone=new_az_name)
self.assertEqual(new_aggregate_name, resp_aggregate['name'])
self.assertEqual(new_az_name, resp_aggregate['availability_zone'])
@@ -150,13 +151,13 @@
aggregate = self.client.create_aggregate(name=aggregate_name)
self.addCleanup(self.client.delete_aggregate, aggregate['id'])
- body = self.client.add_host(aggregate['id'], self.host)
+ body = self.client.add_host(aggregate['id'], host=self.host)
self.assertEqual(aggregate_name, body['name'])
self.assertEqual(aggregate['availability_zone'],
body['availability_zone'])
self.assertIn(self.host, body['hosts'])
- body = self.client.remove_host(aggregate['id'], self.host)
+ body = self.client.remove_host(aggregate['id'], host=self.host)
self.assertEqual(aggregate_name, body['name'])
self.assertEqual(aggregate['availability_zone'],
body['availability_zone'])
@@ -169,8 +170,9 @@
aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
aggregate = self.client.create_aggregate(name=aggregate_name)
self.addCleanup(self.client.delete_aggregate, aggregate['id'])
- self.client.add_host(aggregate['id'], self.host)
- self.addCleanup(self.client.remove_host, aggregate['id'], self.host)
+ self.client.add_host(aggregate['id'], host=self.host)
+ self.addCleanup(self.client.remove_host, aggregate['id'],
+ host=self.host)
aggregates = self.client.list_aggregates()
aggs = filter(lambda x: x['id'] == aggregate['id'], aggregates)
@@ -187,8 +189,9 @@
aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
aggregate = self.client.create_aggregate(name=aggregate_name)
self.addCleanup(self.client.delete_aggregate, aggregate['id'])
- self.client.add_host(aggregate['id'], self.host)
- self.addCleanup(self.client.remove_host, aggregate['id'], self.host)
+ self.client.add_host(aggregate['id'], host=self.host)
+ self.addCleanup(self.client.remove_host, aggregate['id'],
+ host=self.host)
body = self.client.show_aggregate(aggregate['id'])
self.assertEqual(aggregate_name, body['name'])
@@ -204,8 +207,9 @@
aggregate = self.client.create_aggregate(
name=aggregate_name, availability_zone=az_name)
self.addCleanup(self.client.delete_aggregate, aggregate['id'])
- self.client.add_host(aggregate['id'], self.host)
- self.addCleanup(self.client.remove_host, aggregate['id'], self.host)
+ self.client.add_host(aggregate['id'], host=self.host)
+ self.addCleanup(self.client.remove_host, aggregate['id'],
+ host=self.host)
server_name = data_utils.rand_name('test_server')
admin_servers_client = self.os_adm.servers_client
server = self.create_test_server(name=server_name,
diff --git a/tempest/api/compute/admin/test_aggregates_negative.py b/tempest/api/compute/admin/test_aggregates_negative.py
index 74a8547..231c88f 100644
--- a/tempest/api/compute/admin/test_aggregates_negative.py
+++ b/tempest/api/compute/admin/test_aggregates_negative.py
@@ -143,7 +143,7 @@
self.addCleanup(self.client.delete_aggregate, aggregate['id'])
self.assertRaises(lib_exc.NotFound, self.client.add_host,
- aggregate['id'], non_exist_host)
+ aggregate['id'], host=non_exist_host)
@test.attr(type=['negative'])
@test.idempotent_id('7324c334-bd13-4c93-8521-5877322c3d51')
@@ -155,7 +155,7 @@
self.assertRaises(lib_exc.Forbidden,
self.user_client.add_host,
- aggregate['id'], self.host)
+ aggregate['id'], host=self.host)
@test.attr(type=['negative'])
@test.idempotent_id('19dd44e1-c435-4ee1-a402-88c4f90b5950')
@@ -165,11 +165,12 @@
aggregate = self.client.create_aggregate(name=aggregate_name)
self.addCleanup(self.client.delete_aggregate, aggregate['id'])
- self.client.add_host(aggregate['id'], self.host)
- self.addCleanup(self.client.remove_host, aggregate['id'], self.host)
+ self.client.add_host(aggregate['id'], host=self.host)
+ self.addCleanup(self.client.remove_host, aggregate['id'],
+ host=self.host)
self.assertRaises(lib_exc.Conflict, self.client.add_host,
- aggregate['id'], self.host)
+ aggregate['id'], host=self.host)
@test.attr(type=['negative'])
@test.idempotent_id('7a53af20-137a-4e44-a4ae-e19260e626d9')
@@ -179,12 +180,13 @@
aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
aggregate = self.client.create_aggregate(name=aggregate_name)
self.addCleanup(self.client.delete_aggregate, aggregate['id'])
- self.client.add_host(aggregate['id'], self.host)
- self.addCleanup(self.client.remove_host, aggregate['id'], self.host)
+ self.client.add_host(aggregate['id'], host=self.host)
+ self.addCleanup(self.client.remove_host, aggregate['id'],
+ host=self.host)
self.assertRaises(lib_exc.Forbidden,
self.user_client.remove_host,
- aggregate['id'], self.host)
+ aggregate['id'], host=self.host)
@test.attr(type=['negative'])
@test.idempotent_id('95d6a6fa-8da9-4426-84d0-eec0329f2e4d')
@@ -195,4 +197,4 @@
self.addCleanup(self.client.delete_aggregate, aggregate['id'])
self.assertRaises(lib_exc.NotFound, self.client.remove_host,
- aggregate['id'], non_exist_host)
+ aggregate['id'], host=non_exist_host)
diff --git a/tempest/scenario/test_aggregates_basic_ops.py b/tempest/scenario/test_aggregates_basic_ops.py
index 02d1171..f5f4a61 100644
--- a/tempest/scenario/test_aggregates_basic_ops.py
+++ b/tempest/scenario/test_aggregates_basic_ops.py
@@ -64,12 +64,12 @@
return computes[0]['host_name']
def _add_host(self, aggregate_id, host):
- aggregate = self.aggregates_client.add_host(aggregate_id, host)
+ aggregate = self.aggregates_client.add_host(aggregate_id, host=host)
self.addCleanup(self._remove_host, aggregate['id'], host)
self.assertIn(host, aggregate['hosts'])
def _remove_host(self, aggregate_id, host):
- aggregate = self.aggregates_client.remove_host(aggregate_id, host)
+ aggregate = self.aggregates_client.remove_host(aggregate_id, host=host)
self.assertNotIn(host, aggregate['hosts'])
def _check_aggregate_details(self, aggregate, aggregate_name, azone,
@@ -85,7 +85,7 @@
def _set_aggregate_metadata(self, aggregate, meta):
aggregate = self.aggregates_client.set_metadata(aggregate['id'],
- meta)
+ metadata=meta)
for key, value in meta.items():
self.assertEqual(meta[key], aggregate['metadata'][key])
diff --git a/tempest/services/compute/json/aggregates_client.py b/tempest/services/compute/json/aggregates_client.py
index e275895..eeeceb7 100644
--- a/tempest/services/compute/json/aggregates_client.py
+++ b/tempest/services/compute/json/aggregates_client.py
@@ -46,13 +46,9 @@
self.validate_response(schema.create_aggregate, resp, body)
return service_client.ResponseBody(resp, body['aggregate'])
- def update_aggregate(self, aggregate_id, name, availability_zone=None):
+ def update_aggregate(self, aggregate_id, **kwargs):
"""Update a aggregate."""
- put_body = {
- 'name': name,
- 'availability_zone': availability_zone
- }
- put_body = json.dumps({'aggregate': put_body})
+ put_body = json.dumps({'aggregate': kwargs})
resp, body = self.put('os-aggregates/%s' % aggregate_id, put_body)
body = json.loads(body)
@@ -77,36 +73,27 @@
"""Returns the primary type of resource this client works with."""
return 'aggregate'
- def add_host(self, aggregate_id, host):
+ def add_host(self, aggregate_id, **kwargs):
"""Adds a host to the given aggregate."""
- post_body = {
- 'host': host,
- }
- post_body = json.dumps({'add_host': post_body})
+ post_body = json.dumps({'add_host': kwargs})
resp, body = self.post('os-aggregates/%s/action' % aggregate_id,
post_body)
body = json.loads(body)
self.validate_response(schema.aggregate_add_remove_host, resp, body)
return service_client.ResponseBody(resp, body['aggregate'])
- def remove_host(self, aggregate_id, host):
+ def remove_host(self, aggregate_id, **kwargs):
"""Removes a host from the given aggregate."""
- post_body = {
- 'host': host,
- }
- post_body = json.dumps({'remove_host': post_body})
+ post_body = json.dumps({'remove_host': kwargs})
resp, body = self.post('os-aggregates/%s/action' % aggregate_id,
post_body)
body = json.loads(body)
self.validate_response(schema.aggregate_add_remove_host, resp, body)
return service_client.ResponseBody(resp, body['aggregate'])
- def set_metadata(self, aggregate_id, meta):
+ def set_metadata(self, aggregate_id, **kwargs):
"""Replaces the aggregate's existing metadata with new metadata."""
- post_body = {
- 'metadata': meta,
- }
- post_body = json.dumps({'set_metadata': post_body})
+ post_body = json.dumps({'set_metadata': kwargs})
resp, body = self.post('os-aggregates/%s/action' % aggregate_id,
post_body)
body = json.loads(body)