Merge "Adds test for Floating Ips bulk Nova V2 API"
diff --git a/etc/tempest.conf.sample b/etc/tempest.conf.sample
index 23d4ebc..9051310 100644
--- a/etc/tempest.conf.sample
+++ b/etc/tempest.conf.sample
@@ -327,6 +327,11 @@
# (integer value)
#shelved_offload_time=0
+# Unallocated floating IP range, which will be used to test
+# the floating IP bulk feature for CRUD operation. (string
+# value)
+#floating_ip_range=10.0.0.0/29
+
# Allows test cases to create/destroy tenants and users. This
# option enables isolated test cases and better parallel
# execution, but also requires that OpenStack Identity API
diff --git a/tempest/api/compute/admin/test_floating_ips_bulk.py b/tempest/api/compute/admin/test_floating_ips_bulk.py
new file mode 100644
index 0000000..8f875d2
--- /dev/null
+++ b/tempest/api/compute/admin/test_floating_ips_bulk.py
@@ -0,0 +1,82 @@
+# Copyright 2014 NEC Technologies India Ltd.
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+import netaddr
+
+from tempest.api.compute import base
+from tempest import config
+from tempest import test
+
+CONF = config.CONF
+
+
+class FloatingIPsBulkAdminTestJSON(base.BaseV2ComputeAdminTest):
+ """
+ Tests Floating IPs Bulk APIs Create, List and Delete that
+ require admin privileges.
+ API documentation - http://docs.openstack.org/api/openstack-compute/2/
+ content/ext-os-floating-ips-bulk.html
+ """
+
+ @classmethod
+ @test.safe_setup
+ def setUpClass(cls):
+ super(FloatingIPsBulkAdminTestJSON, cls).setUpClass()
+ cls.client = cls.os_adm.floating_ips_client
+ cls.ip_range = CONF.compute.floating_ip_range
+ cls.verify_unallocated_floating_ip_range(cls.ip_range)
+
+ @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()
+ 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:
+ msg = ("Configured unallocated floating IP range is already "
+ "allocated. Configure the correct unallocated range "
+ "as 'floating_ip_range'")
+ raise cls.skipException(msg)
+ return
+
+ def _delete_floating_ips_bulk(self, ip_range):
+ try:
+ self.client.delete_floating_ips_bulk(ip_range)
+ except Exception:
+ pass
+
+ @test.attr(type='gate')
+ def test_create_list_delete_floating_ips_bulk(self):
+ # Create, List and delete the Floating IPs Bulk
+ pool = 'test_pool'
+ # NOTE(GMann): Reserving the IP range but those are not attached
+ # 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)
+ 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)
+ self.assertNotEqual(0, len(body))
+ 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)
diff --git a/tempest/config.py b/tempest/config.py
index 1366361..e3f0f2a 100644
--- a/tempest/config.py
+++ b/tempest/config.py
@@ -247,7 +247,11 @@
'for removing from a host. -1 never offload, 0 offload '
'when shelved. This time should be the same as the time '
'of nova.conf, and some tests will run for as long as the '
- 'time.')
+ 'time.'),
+ cfg.StrOpt('floating_ip_range',
+ default='10.0.0.0/29',
+ help='Unallocated floating IP range, which will be used to '
+ 'test the floating IP bulk feature for CRUD operation.')
]
compute_features_group = cfg.OptGroup(name='compute-feature-enabled',
diff --git a/tempest/services/compute/json/floating_ips_client.py b/tempest/services/compute/json/floating_ips_client.py
index e2e12d5..6fc2bc2 100644
--- a/tempest/services/compute/json/floating_ips_client.py
+++ b/tempest/services/compute/json/floating_ips_client.py
@@ -112,3 +112,28 @@
body = json.loads(body)
self.validate_response(schema.floating_ip_pools, resp, body)
return resp, body['floating_ip_pools']
+
+ def create_floating_ips_bulk(self, ip_range, pool, interface):
+ """Allocate floating IPs in bulk."""
+ post_body = {
+ 'ip_range': ip_range,
+ 'pool': pool,
+ 'interface': interface
+ }
+ post_body = json.dumps({'floating_ips_bulk_create': post_body})
+ resp, body = self.post('os-floating-ips-bulk', post_body)
+ body = json.loads(body)
+ return 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)
+ return resp, body['floating_ip_info']
+
+ def delete_floating_ips_bulk(self, ip_range):
+ """Deletes the provided floating IPs bulk."""
+ post_body = json.dumps({'ip_range': ip_range})
+ resp, body = self.put('os-floating-ips-bulk/delete', post_body)
+ body = json.loads(body)
+ return resp, body['floating_ips_bulk_delete']