Change fixed/floating ip clients to return one value and update tests
Add ResponseBodyData for cases like delete_floating_ips_bulk where a
string is returned as the body. The client has to dereference the data
but I think this is a bit cleaner than having some methods return two values.
Partially implements: blueprint clients-return-one-value
Change-Id: I87b092b2dd2a231049fc39312038f2a2d5101028
diff --git a/tempest/api/compute/admin/test_fixed_ips.py b/tempest/api/compute/admin/test_fixed_ips.py
index d1d13a0..dd666d2 100644
--- a/tempest/api/compute/admin/test_fixed_ips.py
+++ b/tempest/api/compute/admin/test_fixed_ips.py
@@ -42,19 +42,17 @@
@test.attr(type='gate')
@test.services('network')
def test_list_fixed_ip_details(self):
- resp, fixed_ip = self.client.get_fixed_ip_details(self.ip)
+ fixed_ip = self.client.get_fixed_ip_details(self.ip)
self.assertEqual(fixed_ip['address'], self.ip)
@test.attr(type='gate')
@test.services('network')
def test_set_reserve(self):
body = {"reserve": "None"}
- resp, body = self.client.reserve_fixed_ip(self.ip, body)
- self.assertEqual(resp.status, 202)
+ self.client.reserve_fixed_ip(self.ip, body)
@test.attr(type='gate')
@test.services('network')
def test_set_unreserve(self):
body = {"unreserve": "None"}
- resp, body = self.client.reserve_fixed_ip(self.ip, body)
- self.assertEqual(resp.status, 202)
+ self.client.reserve_fixed_ip(self.ip, body)
diff --git a/tempest/api/compute/admin/test_floating_ips_bulk.py b/tempest/api/compute/admin/test_floating_ips_bulk.py
index c1263ea..e01245e 100644
--- a/tempest/api/compute/admin/test_floating_ips_bulk.py
+++ b/tempest/api/compute/admin/test_floating_ips_bulk.py
@@ -40,7 +40,7 @@
@classmethod
def verify_unallocated_floating_ip_range(cls, ip_range):
# Verify whether configure floating IP range is not already allocated.
- _, body = cls.client.list_floating_ips_bulk()
+ body = cls.client.list_floating_ips_bulk()
allocated_ips_list = map(lambda x: x['address'], body)
for ip_addr in netaddr.IPNetwork(ip_range).iter_hosts():
if str(ip_addr) in allocated_ips_list:
@@ -65,18 +65,14 @@
# anywhere. Using the below mentioned interface which is not ever
# expected to be used. Clean Up has been done for created IP range
interface = 'eth0'
- resp, body = self.client.create_floating_ips_bulk(self.ip_range,
- pool,
- interface)
-
- self.assertEqual(200, resp.status)
+ body = self.client.create_floating_ips_bulk(self.ip_range,
+ pool,
+ interface)
self.addCleanup(self._delete_floating_ips_bulk, self.ip_range)
self.assertEqual(self.ip_range, body['ip_range'])
- resp, ips_list = self.client.list_floating_ips_bulk()
- self.assertEqual(200, resp.status)
+ ips_list = self.client.list_floating_ips_bulk()
self.assertNotEqual(0, len(ips_list))
for ip in netaddr.IPNetwork(self.ip_range).iter_hosts():
self.assertIn(str(ip), map(lambda x: x['address'], ips_list))
- resp, body = self.client.delete_floating_ips_bulk(self.ip_range)
- self.assertEqual(200, resp.status)
- self.assertEqual(self.ip_range, body)
+ body = self.client.delete_floating_ips_bulk(self.ip_range)
+ self.assertEqual(self.ip_range, body.data)
diff --git a/tempest/api/compute/floating_ips/test_floating_ips_actions.py b/tempest/api/compute/floating_ips/test_floating_ips_actions.py
index e6f4fb0..7aa5d12 100644
--- a/tempest/api/compute/floating_ips/test_floating_ips_actions.py
+++ b/tempest/api/compute/floating_ips/test_floating_ips_actions.py
@@ -35,7 +35,7 @@
resp, server = cls.create_test_server(wait_until='ACTIVE')
cls.server_id = server['id']
# Floating IP creation
- resp, body = cls.client.create_floating_ip()
+ body = cls.client.create_floating_ip()
cls.floating_ip_id = body['id']
cls.floating_ip = body['ip']
@@ -43,7 +43,7 @@
def resource_cleanup(cls):
# Deleting the floating IP which is created in this method
if cls.floating_ip_id:
- resp, body = cls.client.delete_floating_ip(cls.floating_ip_id)
+ cls.client.delete_floating_ip(cls.floating_ip_id)
super(FloatingIPsTestJSON, cls).resource_cleanup()
def _try_delete_floating_ip(self, floating_ip_id):
@@ -59,15 +59,14 @@
def test_allocate_floating_ip(self):
# Positive test:Allocation of a new floating IP to a project
# should be successful
- resp, body = self.client.create_floating_ip()
+ body = self.client.create_floating_ip()
floating_ip_id_allocated = body['id']
self.addCleanup(self.client.delete_floating_ip,
floating_ip_id_allocated)
- self.assertEqual(200, resp.status)
- resp, floating_ip_details = \
+ floating_ip_details = \
self.client.get_floating_ip_details(floating_ip_id_allocated)
# Checking if the details of allocated IP is in list of floating IP
- resp, body = self.client.list_floating_ips()
+ body = self.client.list_floating_ips()
self.assertIn(floating_ip_details, body)
@test.attr(type='gate')
@@ -76,14 +75,10 @@
# Positive test:Deletion of valid floating IP from project
# should be successful
# Creating the floating IP that is to be deleted in this method
- resp, floating_ip_body = self.client.create_floating_ip()
+ floating_ip_body = self.client.create_floating_ip()
self.addCleanup(self._try_delete_floating_ip, floating_ip_body['id'])
- # Storing the details of floating IP before deleting it
- cli_resp = self.client.get_floating_ip_details(floating_ip_body['id'])
- resp, floating_ip_details = cli_resp
# Deleting the floating IP from the project
- resp, body = self.client.delete_floating_ip(floating_ip_body['id'])
- self.assertEqual(202, resp.status)
+ self.client.delete_floating_ip(floating_ip_body['id'])
# Check it was really deleted.
self.client.wait_for_resource_deletion(floating_ip_body['id'])
@@ -94,20 +89,18 @@
# to a specific server should be successful
# Association of floating IP to fixed IP address
- resp, body = self.client.associate_floating_ip_to_server(
+ self.client.associate_floating_ip_to_server(
self.floating_ip,
self.server_id)
- self.assertEqual(202, resp.status)
# Check instance_id in the floating_ip body
- resp, body = self.client.get_floating_ip_details(self.floating_ip_id)
+ body = self.client.get_floating_ip_details(self.floating_ip_id)
self.assertEqual(self.server_id, body['instance_id'])
# Disassociation of floating IP that was associated in this method
- resp, body = self.client.disassociate_floating_ip_from_server(
+ self.client.disassociate_floating_ip_from_server(
self.floating_ip,
self.server_id)
- self.assertEqual(202, resp.status)
@test.attr(type='gate')
@test.services('network')
@@ -119,21 +112,20 @@
resp, body = self.create_test_server(name=new_name)
self.servers_client.wait_for_server_status(body['id'], 'ACTIVE')
self.new_server_id = body['id']
+ self.addCleanup(self.servers_client.delete_server, self.new_server_id)
# Associating floating IP for the first time
- resp, _ = self.client.associate_floating_ip_to_server(
+ self.client.associate_floating_ip_to_server(
self.floating_ip,
self.server_id)
# Associating floating IP for the second time
- resp, body = self.client.associate_floating_ip_to_server(
+ self.client.associate_floating_ip_to_server(
self.floating_ip,
self.new_server_id)
- self.addCleanup(self.servers_client.delete_server, self.new_server_id)
- if (resp['status'] is not None):
- self.addCleanup(self.client.disassociate_floating_ip_from_server,
- self.floating_ip,
- self.new_server_id)
+ self.addCleanup(self.client.disassociate_floating_ip_from_server,
+ self.floating_ip,
+ self.new_server_id)
# Make sure no longer associated with old server
self.assertRaises((exceptions.NotFound,
diff --git a/tempest/api/compute/floating_ips/test_floating_ips_actions_negative.py b/tempest/api/compute/floating_ips/test_floating_ips_actions_negative.py
index b08df97..a78476c 100644
--- a/tempest/api/compute/floating_ips/test_floating_ips_actions_negative.py
+++ b/tempest/api/compute/floating_ips/test_floating_ips_actions_negative.py
@@ -37,7 +37,7 @@
cls.server_id = server['id']
# Generating a nonexistent floatingIP id
cls.floating_ip_ids = []
- resp, body = cls.client.list_floating_ips()
+ body = cls.client.list_floating_ips()
for i in range(len(body)):
cls.floating_ip_ids.append(body[i]['id'])
while True:
diff --git a/tempest/api/compute/floating_ips/test_list_floating_ips.py b/tempest/api/compute/floating_ips/test_list_floating_ips.py
index 7af9ca7..ca46918 100644
--- a/tempest/api/compute/floating_ips/test_list_floating_ips.py
+++ b/tempest/api/compute/floating_ips/test_list_floating_ips.py
@@ -26,7 +26,7 @@
cls.floating_ip = []
cls.floating_ip_id = []
for i in range(3):
- resp, body = cls.client.create_floating_ip()
+ body = cls.client.create_floating_ip()
cls.floating_ip.append(body)
cls.floating_ip_id.append(body['id'])
@@ -40,8 +40,7 @@
@test.services('network')
def test_list_floating_ips(self):
# Positive test:Should return the list of floating IPs
- resp, body = self.client.list_floating_ips()
- self.assertEqual(200, resp.status)
+ body = self.client.list_floating_ips()
floating_ips = body
self.assertNotEqual(0, len(floating_ips),
"Expected floating IPs. Got zero.")
@@ -53,16 +52,14 @@
def test_get_floating_ip_details(self):
# Positive test:Should be able to GET the details of floatingIP
# Creating a floating IP for which details are to be checked
- resp, body = self.client.create_floating_ip()
+ body = self.client.create_floating_ip()
floating_ip_id = body['id']
self.addCleanup(self.client.delete_floating_ip,
floating_ip_id)
floating_ip_instance_id = body['instance_id']
floating_ip_ip = body['ip']
floating_ip_fixed_ip = body['fixed_ip']
- resp, body = \
- self.client.get_floating_ip_details(floating_ip_id)
- self.assertEqual(200, resp.status)
+ body = self.client.get_floating_ip_details(floating_ip_id)
# Comparing the details of floating IP
self.assertEqual(floating_ip_instance_id,
body['instance_id'])
@@ -75,7 +72,6 @@
@test.services('network')
def test_list_floating_ip_pools(self):
# Positive test:Should return the list of floating IP Pools
- resp, floating_ip_pools = self.client.list_floating_ip_pools()
- self.assertEqual(200, resp.status)
+ floating_ip_pools = self.client.list_floating_ip_pools()
self.assertNotEqual(0, len(floating_ip_pools),
"Expected floating IP Pools. Got zero.")
diff --git a/tempest/api/compute/servers/test_server_rescue.py b/tempest/api/compute/servers/test_server_rescue.py
index b04fe69..c4e5f7b 100644
--- a/tempest/api/compute/servers/test_server_rescue.py
+++ b/tempest/api/compute/servers/test_server_rescue.py
@@ -33,7 +33,7 @@
super(ServerRescueTestJSON, cls).resource_setup()
# Floating IP creation
- resp, body = cls.floating_ips_client.create_floating_ip()
+ body = cls.floating_ips_client.create_floating_ip()
cls.floating_ip_id = str(body['id']).strip()
cls.floating_ip = str(body['ip']).strip()
@@ -90,15 +90,12 @@
# Association of floating IP to a rescued vm
client = self.floating_ips_client
- resp, body = client.associate_floating_ip_to_server(self.floating_ip,
- self.server_id)
- self.assertEqual(202, resp.status)
+ client.associate_floating_ip_to_server(self.floating_ip,
+ self.server_id)
# Disassociation of floating IP that was associated in this method
- resp, body = \
- client.disassociate_floating_ip_from_server(self.floating_ip,
- self.server_id)
- self.assertEqual(202, resp.status)
+ client.disassociate_floating_ip_from_server(self.floating_ip,
+ self.server_id)
@test.attr(type='gate')
def test_rescued_vm_add_remove_security_group(self):
diff --git a/tempest/cmd/cleanup_service.py b/tempest/cmd/cleanup_service.py
index 9c4a5dc..67eb182 100644
--- a/tempest/cmd/cleanup_service.py
+++ b/tempest/cmd/cleanup_service.py
@@ -297,7 +297,7 @@
def list(self):
client = self.client
- _, floating_ips = client.list_floating_ips()
+ floating_ips = client.list_floating_ips()
LOG.debug("List count, %s Floating IPs" % len(floating_ips))
return floating_ips
diff --git a/tempest/common/service_client.py b/tempest/common/service_client.py
index 69e25e2..12f9414 100644
--- a/tempest/common/service_client.py
+++ b/tempest/common/service_client.py
@@ -94,6 +94,18 @@
return "response: %s\nBody: %s" % (self.response, body)
+class ResponseBodyData(object):
+ """Class that wraps an http response and string data into a single value.
+ """
+
+ def __init__(self, response, data):
+ self.response = response
+ self.data = data
+
+ def __str__(self):
+ return "response: %s\nBody: %s" % (self.response, self.data)
+
+
class ResponseBodyList(list):
"""Class that wraps an http response and list body into a single value.
diff --git a/tempest/scenario/manager.py b/tempest/scenario/manager.py
index b1f5cce..07c06df 100644
--- a/tempest/scenario/manager.py
+++ b/tempest/scenario/manager.py
@@ -512,7 +512,7 @@
Nova clients
"""
- _, floating_ip = self.floating_ips_client.create_floating_ip(pool_name)
+ floating_ip = self.floating_ips_client.create_floating_ip(pool_name)
self.addCleanup(self.delete_wrapper,
self.floating_ips_client.delete_floating_ip,
floating_ip['id'])
diff --git a/tempest/scenario/test_baremetal_basic_ops.py b/tempest/scenario/test_baremetal_basic_ops.py
index fd4449a..fe49dc1 100644
--- a/tempest/scenario/test_baremetal_basic_ops.py
+++ b/tempest/scenario/test_baremetal_basic_ops.py
@@ -104,7 +104,7 @@
return int(ephemeral)
def add_floating_ip(self):
- _, floating_ip = self.floating_ips_client.create_floating_ip()
+ floating_ip = self.floating_ips_client.create_floating_ip()
self.floating_ips_client.associate_floating_ip_to_server(
floating_ip['ip'], self.instance['id'])
return floating_ip['ip']
diff --git a/tempest/scenario/test_server_basic_ops.py b/tempest/scenario/test_server_basic_ops.py
index 23743c5..509ce60 100644
--- a/tempest/scenario/test_server_basic_ops.py
+++ b/tempest/scenario/test_server_basic_ops.py
@@ -80,7 +80,7 @@
def verify_ssh(self):
if self.run_ssh:
# Obtain a floating IP
- _, floating_ip = self.floating_ips_client.create_floating_ip()
+ floating_ip = self.floating_ips_client.create_floating_ip()
self.addCleanup(self.delete_wrapper,
self.floating_ips_client.delete_floating_ip,
floating_ip['id'])
diff --git a/tempest/scenario/test_shelve_instance.py b/tempest/scenario/test_shelve_instance.py
index 8882177..5ba650d 100644
--- a/tempest/scenario/test_shelve_instance.py
+++ b/tempest/scenario/test_shelve_instance.py
@@ -77,7 +77,7 @@
create_kwargs=create_kwargs)
if CONF.compute.use_floatingip_for_ssh:
- _, floating_ip = self.floating_ips_client.create_floating_ip()
+ floating_ip = self.floating_ips_client.create_floating_ip()
self.addCleanup(self.delete_wrapper,
self.floating_ips_client.delete_floating_ip,
floating_ip['id'])
diff --git a/tempest/scenario/test_volume_boot_pattern.py b/tempest/scenario/test_volume_boot_pattern.py
index 910fd79..3a73fae 100644
--- a/tempest/scenario/test_volume_boot_pattern.py
+++ b/tempest/scenario/test_volume_boot_pattern.py
@@ -99,7 +99,7 @@
def _ssh_to_server(self, server, keypair):
if CONF.compute.use_floatingip_for_ssh:
- _, floating_ip = self.floating_ips_client.create_floating_ip()
+ floating_ip = self.floating_ips_client.create_floating_ip()
self.addCleanup(self.delete_wrapper,
self.floating_ips_client.delete_floating_ip,
floating_ip['id'])
diff --git a/tempest/services/compute/json/fixed_ips_client.py b/tempest/services/compute/json/fixed_ips_client.py
index 5797c16..31cf5b2 100644
--- a/tempest/services/compute/json/fixed_ips_client.py
+++ b/tempest/services/compute/json/fixed_ips_client.py
@@ -26,11 +26,11 @@
resp, body = self.get(url)
body = json.loads(body)
self.validate_response(schema.fixed_ips, resp, body)
- return resp, body['fixed_ip']
+ return service_client.ResponseBody(resp, body['fixed_ip'])
def reserve_fixed_ip(self, ip, body):
"""This reserves and unreserves fixed ips."""
url = "os-fixed-ips/%s/action" % (ip)
resp, body = self.post(url, json.dumps(body))
self.validate_response(schema.fixed_ip_action, resp, body)
- return resp, body
+ return service_client.ResponseBody(resp)
diff --git a/tempest/services/compute/json/floating_ips_client.py b/tempest/services/compute/json/floating_ips_client.py
index 9c586e3..441f185 100644
--- a/tempest/services/compute/json/floating_ips_client.py
+++ b/tempest/services/compute/json/floating_ips_client.py
@@ -32,7 +32,7 @@
resp, body = self.get(url)
body = json.loads(body)
self.validate_response(schema.list_floating_ips, resp, body)
- return resp, body['floating_ips']
+ return service_client.ResponseBodyList(resp, body['floating_ips'])
def get_floating_ip_details(self, floating_ip_id):
"""Get the details of a floating IP."""
@@ -42,7 +42,7 @@
if resp.status == 404:
raise exceptions.NotFound(body)
self.validate_response(schema.floating_ip, resp, body)
- return resp, body['floating_ip']
+ return service_client.ResponseBody(resp, body['floating_ip'])
def create_floating_ip(self, pool_name=None):
"""Allocate a floating IP to the project."""
@@ -52,14 +52,14 @@
resp, body = self.post(url, post_body)
body = json.loads(body)
self.validate_response(schema.floating_ip, resp, body)
- return resp, body['floating_ip']
+ return service_client.ResponseBody(resp, body['floating_ip'])
def delete_floating_ip(self, floating_ip_id):
"""Deletes the provided floating IP from the project."""
url = "os-floating-ips/%s" % str(floating_ip_id)
resp, body = self.delete(url)
self.validate_response(schema.add_remove_floating_ip, resp, body)
- return resp, body
+ return service_client.ResponseBody(resp, body)
def associate_floating_ip_to_server(self, floating_ip, server_id):
"""Associate the provided floating IP to a specific server."""
@@ -73,7 +73,7 @@
post_body = json.dumps(post_body)
resp, body = self.post(url, post_body)
self.validate_response(schema.add_remove_floating_ip, resp, body)
- return resp, body
+ return service_client.ResponseBody(resp, body)
def disassociate_floating_ip_from_server(self, floating_ip, server_id):
"""Disassociate the provided floating IP from a specific server."""
@@ -87,7 +87,7 @@
post_body = json.dumps(post_body)
resp, body = self.post(url, post_body)
self.validate_response(schema.add_remove_floating_ip, resp, body)
- return resp, body
+ return service_client.ResponseBody(resp, body)
def is_resource_deleted(self, id):
try:
@@ -110,7 +110,7 @@
resp, body = self.get(url)
body = json.loads(body)
self.validate_response(schema.floating_ip_pools, resp, body)
- return resp, body['floating_ip_pools']
+ return service_client.ResponseBodyList(resp, body['floating_ip_pools'])
def create_floating_ips_bulk(self, ip_range, pool, interface):
"""Allocate floating IPs in bulk."""
@@ -123,14 +123,15 @@
resp, body = self.post('os-floating-ips-bulk', post_body)
body = json.loads(body)
self.validate_response(schema.create_floating_ips_bulk, resp, body)
- return resp, body['floating_ips_bulk_create']
+ return service_client.ResponseBody(resp,
+ body['floating_ips_bulk_create'])
def list_floating_ips_bulk(self):
"""Returns a list of all floating IPs bulk."""
resp, body = self.get('os-floating-ips-bulk')
body = json.loads(body)
self.validate_response(schema.list_floating_ips_bulk, resp, body)
- return resp, body['floating_ip_info']
+ return service_client.ResponseBodyList(resp, body['floating_ip_info'])
def delete_floating_ips_bulk(self, ip_range):
"""Deletes the provided floating IPs bulk."""
@@ -138,4 +139,5 @@
resp, body = self.put('os-floating-ips-bulk/delete', post_body)
body = json.loads(body)
self.validate_response(schema.delete_floating_ips_bulk, resp, body)
- return resp, body['floating_ips_bulk_delete']
+ data = body['floating_ips_bulk_delete']
+ return service_client.ResponseBodyData(resp, data)
diff --git a/tempest/stress/cleanup.py b/tempest/stress/cleanup.py
index b52eca9..c2e33a1 100644
--- a/tempest/stress/cleanup.py
+++ b/tempest/stress/cleanup.py
@@ -55,7 +55,7 @@
except Exception:
pass
- _, floating_ips = admin_manager.floating_ips_client.list_floating_ips()
+ floating_ips = admin_manager.floating_ips_client.list_floating_ips()
LOG.info("Cleanup::remove %s floating ips" % len(floating_ips))
for f in floating_ips:
try: