Merge "add test for creating a floating IP specifying an non-existent pool"
diff --git a/tempest/services/compute/json/floating_ips_client.py b/tempest/services/compute/json/floating_ips_client.py
index d73b8a9..27733ac 100644
--- a/tempest/services/compute/json/floating_ips_client.py
+++ b/tempest/services/compute/json/floating_ips_client.py
@@ -47,10 +47,12 @@
raise exceptions.NotFound(body)
return resp, body['floating_ip']
- def create_floating_ip(self):
+ def create_floating_ip(self, pool_name=None):
"""Allocate a floating IP to the project."""
url = 'os-floating-ips'
- resp, body = self.post(url, None, None)
+ post_body = {'pool': pool_name}
+ post_body = json.dumps(post_body)
+ resp, body = self.post(url, post_body, self.headers)
body = json.loads(body)
return resp, body['floating_ip']
diff --git a/tempest/services/compute/xml/floating_ips_client.py b/tempest/services/compute/xml/floating_ips_client.py
index 74b4be2..93f5208 100644
--- a/tempest/services/compute/xml/floating_ips_client.py
+++ b/tempest/services/compute/xml/floating_ips_client.py
@@ -22,6 +22,7 @@
from tempest import exceptions
from tempest.services.compute.xml.common import Document
from tempest.services.compute.xml.common import Element
+from tempest.services.compute.xml.common import Text
from tempest.services.compute.xml.common import xml_to_json
@@ -60,10 +61,17 @@
raise exceptions.NotFound(body)
return resp, body
- def create_floating_ip(self):
+ def create_floating_ip(self, pool_name=None):
"""Allocate a floating IP to the project."""
url = 'os-floating-ips'
- resp, body = self.post(url, None, self.headers)
+ if pool_name:
+ doc = Document()
+ pool = Element("pool")
+ pool.append(Text(pool_name))
+ doc.append(pool)
+ resp, body = self.post(url, str(doc), self.headers)
+ else:
+ resp, body = self.post(url, None, self.headers)
body = self._parse_floating_ip(etree.fromstring(body))
return resp, body
diff --git a/tempest/tests/compute/floating_ips/test_floating_ips_actions.py b/tempest/tests/compute/floating_ips/test_floating_ips_actions.py
index 888481a..2b21710 100644
--- a/tempest/tests/compute/floating_ips/test_floating_ips_actions.py
+++ b/tempest/tests/compute/floating_ips/test_floating_ips_actions.py
@@ -73,6 +73,14 @@
#Deleting the floating IP which is created in this method
self.client.delete_floating_ip(floating_ip_id_allocated)
+ @attr(type='negative')
+ def test_allocate_floating_ip_from_nonexistent_pool(self):
+ # Positive test:Allocation of a new floating IP from a nonexistent_pool
+ #to a project should fail
+ self.assertRaises(exceptions.NotFound,
+ self.client.create_floating_ip,
+ "non_exist_pool")
+
@attr(type='positive')
def test_delete_floating_ip(self):
# Positive test:Deletion of valid floating IP from project