summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
authorPhil Day <philip.day@hp.com>2013-04-04 18:00:49 +0100
committerPhil Day <philip.day@hp.com>2013-05-10 01:29:27 +0100
commit1b2c121f133b15d0fe3f6ebdb131ac9998bc4b83 (patch)
treedb349fc2ed3deabc5d5c380c49a6c82ce0fbafae /nova/tests
parentb17715174e8cdd98fe336ee79660860890cf6dce (diff)
Allow a floating IP to be associated to a specific fixed IP
The current floating IP API extension only accepts the instance ID and the floating address to be assigned. Where the instance is connected to more than one network the behaviour is to associated the floating IP with the first fixed IP of the instances (and to log a warning) This change introduces a new extension which wehn loaded adds a fixed IP address as an optional parameter, allowing the floating IP to be associated with a specific fixed IP. Without this extension, or without the optional parameters, the API behaviour is unchanged. If specified the fixed IP must be associated with the instance. DocImpact Implements blueprint multi-nic-floating-ip-assignment Change-Id: I9241137ad794cdf7f452ed84e9445f0e11fdd44e
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/api/openstack/compute/contrib/test_floating_ips.py129
-rw-r--r--nova/tests/api/openstack/compute/test_extensions.py1
-rw-r--r--nova/tests/integrated/api_samples/all_extensions/extensions-get-resp.json.tpl8
-rw-r--r--nova/tests/integrated/api_samples/all_extensions/extensions-get-resp.xml.tpl3
-rw-r--r--nova/tests/integrated/api_samples/os-extended-floating-ips/floating-ips-create-nopool-req.json.tpl0
-rw-r--r--nova/tests/integrated/api_samples/os-extended-floating-ips/floating-ips-create-nopool-req.xml.tpl0
-rw-r--r--nova/tests/integrated/api_samples/os-extended-floating-ips/floating-ips-create-req.json.tpl3
-rw-r--r--nova/tests/integrated/api_samples/os-extended-floating-ips/floating-ips-create-req.xml.tpl2
-rw-r--r--nova/tests/integrated/api_samples/os-extended-floating-ips/floating-ips-create-resp.json.tpl9
-rw-r--r--nova/tests/integrated/api_samples/os-extended-floating-ips/floating-ips-create-resp.xml.tpl2
-rw-r--r--nova/tests/integrated/api_samples/os-extended-floating-ips/floating-ips-get-resp.json.tpl9
-rw-r--r--nova/tests/integrated/api_samples/os-extended-floating-ips/floating-ips-get-resp.xml.tpl2
-rw-r--r--nova/tests/integrated/api_samples/os-extended-floating-ips/floating-ips-list-empty-resp.json.tpl3
-rw-r--r--nova/tests/integrated/api_samples/os-extended-floating-ips/floating-ips-list-empty-resp.xml.tpl2
-rw-r--r--nova/tests/integrated/api_samples/os-extended-floating-ips/floating-ips-list-resp.json.tpl19
-rw-r--r--nova/tests/integrated/api_samples/os-extended-floating-ips/floating-ips-list-resp.xml.tpl5
-rw-r--r--nova/tests/integrated/test_api_samples.py16
17 files changed, 209 insertions, 4 deletions
diff --git a/nova/tests/api/openstack/compute/contrib/test_floating_ips.py b/nova/tests/api/openstack/compute/contrib/test_floating_ips.py
index 00759a7ef..2dc6f2956 100644
--- a/nova/tests/api/openstack/compute/contrib/test_floating_ips.py
+++ b/nova/tests/api/openstack/compute/contrib/test_floating_ips.py
@@ -20,6 +20,7 @@ from lxml import etree
import webob
from nova.api.openstack.compute.contrib import floating_ips
+from nova.api.openstack import extensions
from nova import compute
from nova.compute import utils as compute_utils
from nova import context
@@ -154,8 +155,10 @@ class FloatingIpTest(test.TestCase):
self.context = context.get_admin_context()
self._create_floating_ips()
+ self.ext_mgr = extensions.ExtensionManager()
+ self.ext_mgr.extensions = {}
self.controller = floating_ips.FloatingIPController()
- self.manager = floating_ips.FloatingIPActionController()
+ self.manager = floating_ips.FloatingIPActionController(self.ext_mgr)
def tearDown(self):
self._delete_floating_ip()
@@ -315,8 +318,10 @@ class FloatingIpTest(test.TestCase):
self.controller.delete(req, 1)
def test_floating_ip_associate(self):
+ fixed_address = '192.168.1.100'
+
def fake_associate_floating_ip(*args, **kwargs):
- pass
+ self.assertEqual(fixed_address, kwargs['fixed_address'])
self.stubs.Set(network.api.API, "associate_floating_ip",
fake_associate_floating_ip)
@@ -326,8 +331,26 @@ class FloatingIpTest(test.TestCase):
rsp = self.manager._add_floating_ip(req, 'test_inst', body)
self.assertTrue(rsp.status_int == 202)
- def test_associate_not_allocated_floating_ip_to_instance(self):
+ def test_not_extended_floating_ip_associate_fixed(self):
+ # Check that fixed_address is ignored if os-extended-floating-ips
+ # is not loaded
+ fixed_address_requested = '192.168.1.101'
+ fixed_address_allocated = '192.168.1.100'
+
+ def fake_associate_floating_ip(*args, **kwargs):
+ self.assertEqual(fixed_address_allocated,
+ kwargs['fixed_address'])
+
+ self.stubs.Set(network.api.API, "associate_floating_ip",
+ fake_associate_floating_ip)
+ body = dict(addFloatingIp=dict(address=self.floating_ip,
+ fixed_address=fixed_address_requested))
+
+ req = fakes.HTTPRequest.blank('/v2/fake/servers/test_inst/action')
+ rsp = self.manager._add_floating_ip(req, 'test_inst', body)
+ self.assertTrue(rsp.status_int == 202)
+ def test_associate_not_allocated_floating_ip_to_instance(self):
def fake_associate_floating_ip(self, context, instance,
floating_address, fixed_address,
affect_auto_assigned=False):
@@ -510,6 +533,106 @@ class FloatingIpTest(test.TestCase):
body)
+class ExtendedFloatingIpTest(test.TestCase):
+ floating_ip = "10.10.10.10"
+ floating_ip_2 = "10.10.10.11"
+
+ def _create_floating_ips(self, floating_ips=None):
+ """Create a floating ip object."""
+ if floating_ips is None:
+ floating_ips = [self.floating_ip]
+ elif not isinstance(floating_ips, (list, tuple)):
+ floating_ips = [floating_ips]
+
+ def make_ip_dict(ip):
+ """Shortcut for creating floating ip dict."""
+ return
+
+ dict_ = {'pool': 'nova', 'host': 'fake_host'}
+ return db.floating_ip_bulk_create(
+ self.context, [dict(address=ip, **dict_) for ip in floating_ips],
+ )
+
+ def _delete_floating_ip(self):
+ db.floating_ip_destroy(self.context, self.floating_ip)
+
+ def setUp(self):
+ super(ExtendedFloatingIpTest, self).setUp()
+ self.stubs.Set(compute.api.API, "get",
+ compute_api_get)
+ self.stubs.Set(network.api.API, "get_floating_ip",
+ network_api_get_floating_ip)
+ self.stubs.Set(network.api.API, "get_floating_ip_by_address",
+ network_api_get_floating_ip_by_address)
+ self.stubs.Set(network.api.API, "get_floating_ips_by_project",
+ network_api_get_floating_ips_by_project)
+ self.stubs.Set(network.api.API, "release_floating_ip",
+ network_api_release)
+ self.stubs.Set(network.api.API, "disassociate_floating_ip",
+ network_api_disassociate)
+ self.stubs.Set(network.api.API, "get_instance_id_by_floating_address",
+ get_instance_by_floating_ip_addr)
+ self.stubs.Set(compute_utils, "get_nw_info_for_instance",
+ stub_nw_info(self.stubs))
+ self.flags(
+ osapi_compute_extension=[
+ 'nova.api.openstack.compute.contrib.select_extensions'],
+ osapi_compute_ext_list=['Floating_ips', 'Extended_floating_ips'])
+
+ fake_network.stub_out_nw_api_get_instance_nw_info(self.stubs,
+ spectacular=True)
+ self.stubs.Set(db, 'instance_get',
+ fake_instance_get)
+
+ self.context = context.get_admin_context()
+ self._create_floating_ips()
+
+ self.ext_mgr = extensions.ExtensionManager()
+ self.ext_mgr.extensions = {}
+ self.ext_mgr.extensions['os-floating-ips'] = True
+ self.ext_mgr.extensions['os-extended-floating-ips'] = True
+ self.controller = floating_ips.FloatingIPController()
+ self.manager = floating_ips.FloatingIPActionController(self.ext_mgr)
+
+ def tearDown(self):
+ self._delete_floating_ip()
+ super(ExtendedFloatingIpTest, self).tearDown()
+
+ def test_extended_floating_ip_associate_fixed(self):
+ fixed_address = '192.168.1.101'
+
+ def fake_associate_floating_ip(*args, **kwargs):
+ self.assertEqual(fixed_address, kwargs['fixed_address'])
+
+ self.stubs.Set(network.api.API, "associate_floating_ip",
+ fake_associate_floating_ip)
+ body = dict(addFloatingIp=dict(address=self.floating_ip,
+ fixed_address=fixed_address))
+
+ req = fakes.HTTPRequest.blank('/v2/fake/servers/test_inst/action')
+ rsp = self.manager._add_floating_ip(req, 'test_inst', body)
+ self.assertTrue(rsp.status_int == 202)
+
+ def test_extended_floating_ip_associate_fixed_not_allocated(self):
+ def fake_associate_floating_ip(*args, **kwargs):
+ pass
+
+ self.stubs.Set(network.api.API, "associate_floating_ip",
+ fake_associate_floating_ip)
+ body = dict(addFloatingIp=dict(address=self.floating_ip,
+ fixed_address='11.11.11.11'))
+
+ req = webob.Request.blank('/v2/fake/servers/test_inst/action')
+ req.method = "POST"
+ req.body = jsonutils.dumps(body)
+ req.headers["content-type"] = "application/json"
+ resp = req.get_response(fakes.wsgi_app(init_only=('servers',)))
+ res_dict = jsonutils.loads(resp.body)
+ self.assertEqual(resp.status_int, 400)
+ self.assertEqual(res_dict['badRequest']['message'],
+ "Specified fixed address not assigned to instance")
+
+
class FloatingIpSerializerTest(test.TestCase):
def test_default_serializer(self):
serializer = floating_ips.FloatingIPTemplate()
diff --git a/nova/tests/api/openstack/compute/test_extensions.py b/nova/tests/api/openstack/compute/test_extensions.py
index 658d0c474..6e400a075 100644
--- a/nova/tests/api/openstack/compute/test_extensions.py
+++ b/nova/tests/api/openstack/compute/test_extensions.py
@@ -167,6 +167,7 @@ class ExtensionControllerTest(ExtensionTestCase):
"DeferredDelete",
"DiskConfig",
"ExtendedAvailabilityZone",
+ "ExtendedFloatingIps",
"ExtendedIps",
"ExtendedIpsMac",
"ExtendedVIFNet",
diff --git a/nova/tests/integrated/api_samples/all_extensions/extensions-get-resp.json.tpl b/nova/tests/integrated/api_samples/all_extensions/extensions-get-resp.json.tpl
index 1d3d2ea90..d559b4890 100644
--- a/nova/tests/integrated/api_samples/all_extensions/extensions-get-resp.json.tpl
+++ b/nova/tests/integrated/api_samples/all_extensions/extensions-get-resp.json.tpl
@@ -233,6 +233,14 @@
"updated": "%(timestamp)s"
},
{
+ "alias": "os-extended-floating-ips",
+ "description": "%(text)s",
+ "links": [],
+ "name": "ExtendedFloatingIps",
+ "namespace": "http://docs.openstack.org/compute/ext/extended_floating_ips/api/v2",
+ "updated": "%(timestamp)s"
+ },
+ {
"alias": "os-fixed-ips",
"description": "Fixed IPs support.",
"links": [],
diff --git a/nova/tests/integrated/api_samples/all_extensions/extensions-get-resp.xml.tpl b/nova/tests/integrated/api_samples/all_extensions/extensions-get-resp.xml.tpl
index 440996966..cc9ae4c02 100644
--- a/nova/tests/integrated/api_samples/all_extensions/extensions-get-resp.xml.tpl
+++ b/nova/tests/integrated/api_samples/all_extensions/extensions-get-resp.xml.tpl
@@ -87,6 +87,9 @@
<extension alias="os-evacuate" updated="%(timestamp)s" namespace="http://docs.openstack.org/compute/ext/evacuate/api/v2" name="Evacuate">
<description>%(text)s</description>
</extension>
+ <extension alias="os-extended-floating-ips" updated="%(timestamp)s" namespace="http://docs.openstack.org/compute/ext/extended_floating_ips/api/v2" name="ExtendedFloatingIps">
+ <description>%(text)s</description>
+ </extension>
<extension alias="os-fixed-ips" name="FixedIPs" namespace="http://docs.openstack.org/compute/ext/fixed_ips/api/v2" updated="2012-10-18T13:25:27-06:00">
<description>Fixed IPs support.</description>
</extension>
diff --git a/nova/tests/integrated/api_samples/os-extended-floating-ips/floating-ips-create-nopool-req.json.tpl b/nova/tests/integrated/api_samples/os-extended-floating-ips/floating-ips-create-nopool-req.json.tpl
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/nova/tests/integrated/api_samples/os-extended-floating-ips/floating-ips-create-nopool-req.json.tpl
diff --git a/nova/tests/integrated/api_samples/os-extended-floating-ips/floating-ips-create-nopool-req.xml.tpl b/nova/tests/integrated/api_samples/os-extended-floating-ips/floating-ips-create-nopool-req.xml.tpl
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/nova/tests/integrated/api_samples/os-extended-floating-ips/floating-ips-create-nopool-req.xml.tpl
diff --git a/nova/tests/integrated/api_samples/os-extended-floating-ips/floating-ips-create-req.json.tpl b/nova/tests/integrated/api_samples/os-extended-floating-ips/floating-ips-create-req.json.tpl
new file mode 100644
index 000000000..24129f495
--- /dev/null
+++ b/nova/tests/integrated/api_samples/os-extended-floating-ips/floating-ips-create-req.json.tpl
@@ -0,0 +1,3 @@
+{
+ "pool": "%(pool)s"
+} \ No newline at end of file
diff --git a/nova/tests/integrated/api_samples/os-extended-floating-ips/floating-ips-create-req.xml.tpl b/nova/tests/integrated/api_samples/os-extended-floating-ips/floating-ips-create-req.xml.tpl
new file mode 100644
index 000000000..a80147389
--- /dev/null
+++ b/nova/tests/integrated/api_samples/os-extended-floating-ips/floating-ips-create-req.xml.tpl
@@ -0,0 +1,2 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<pool>%(pool)s</pool> \ No newline at end of file
diff --git a/nova/tests/integrated/api_samples/os-extended-floating-ips/floating-ips-create-resp.json.tpl b/nova/tests/integrated/api_samples/os-extended-floating-ips/floating-ips-create-resp.json.tpl
new file mode 100644
index 000000000..10ee8d9bd
--- /dev/null
+++ b/nova/tests/integrated/api_samples/os-extended-floating-ips/floating-ips-create-resp.json.tpl
@@ -0,0 +1,9 @@
+{
+ "floating_ip": {
+ "fixed_ip": null,
+ "id": 1,
+ "instance_id": null,
+ "ip": "10.10.10.1",
+ "pool": "nova"
+ }
+}
diff --git a/nova/tests/integrated/api_samples/os-extended-floating-ips/floating-ips-create-resp.xml.tpl b/nova/tests/integrated/api_samples/os-extended-floating-ips/floating-ips-create-resp.xml.tpl
new file mode 100644
index 000000000..e0f68ef50
--- /dev/null
+++ b/nova/tests/integrated/api_samples/os-extended-floating-ips/floating-ips-create-resp.xml.tpl
@@ -0,0 +1,2 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<floating_ip instance_id="None" ip="10.10.10.1" fixed_ip="None" id="1" pool="nova"/> \ No newline at end of file
diff --git a/nova/tests/integrated/api_samples/os-extended-floating-ips/floating-ips-get-resp.json.tpl b/nova/tests/integrated/api_samples/os-extended-floating-ips/floating-ips-get-resp.json.tpl
new file mode 100644
index 000000000..10ee8d9bd
--- /dev/null
+++ b/nova/tests/integrated/api_samples/os-extended-floating-ips/floating-ips-get-resp.json.tpl
@@ -0,0 +1,9 @@
+{
+ "floating_ip": {
+ "fixed_ip": null,
+ "id": 1,
+ "instance_id": null,
+ "ip": "10.10.10.1",
+ "pool": "nova"
+ }
+}
diff --git a/nova/tests/integrated/api_samples/os-extended-floating-ips/floating-ips-get-resp.xml.tpl b/nova/tests/integrated/api_samples/os-extended-floating-ips/floating-ips-get-resp.xml.tpl
new file mode 100644
index 000000000..e0f68ef50
--- /dev/null
+++ b/nova/tests/integrated/api_samples/os-extended-floating-ips/floating-ips-get-resp.xml.tpl
@@ -0,0 +1,2 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<floating_ip instance_id="None" ip="10.10.10.1" fixed_ip="None" id="1" pool="nova"/> \ No newline at end of file
diff --git a/nova/tests/integrated/api_samples/os-extended-floating-ips/floating-ips-list-empty-resp.json.tpl b/nova/tests/integrated/api_samples/os-extended-floating-ips/floating-ips-list-empty-resp.json.tpl
new file mode 100644
index 000000000..12f118da5
--- /dev/null
+++ b/nova/tests/integrated/api_samples/os-extended-floating-ips/floating-ips-list-empty-resp.json.tpl
@@ -0,0 +1,3 @@
+{
+ "floating_ips": []
+}
diff --git a/nova/tests/integrated/api_samples/os-extended-floating-ips/floating-ips-list-empty-resp.xml.tpl b/nova/tests/integrated/api_samples/os-extended-floating-ips/floating-ips-list-empty-resp.xml.tpl
new file mode 100644
index 000000000..da6f0d4ce
--- /dev/null
+++ b/nova/tests/integrated/api_samples/os-extended-floating-ips/floating-ips-list-empty-resp.xml.tpl
@@ -0,0 +1,2 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<floating_ips/> \ No newline at end of file
diff --git a/nova/tests/integrated/api_samples/os-extended-floating-ips/floating-ips-list-resp.json.tpl b/nova/tests/integrated/api_samples/os-extended-floating-ips/floating-ips-list-resp.json.tpl
new file mode 100644
index 000000000..06f57451c
--- /dev/null
+++ b/nova/tests/integrated/api_samples/os-extended-floating-ips/floating-ips-list-resp.json.tpl
@@ -0,0 +1,19 @@
+{
+ "floating_ips": [
+ {
+ "fixed_ip": null,
+ "id": 1,
+ "instance_id": null,
+ "ip": "10.10.10.1",
+ "pool": "nova"
+ },
+ {
+ "fixed_ip": null,
+ "id": 2,
+ "instance_id": null,
+ "ip": "10.10.10.2",
+ "pool": "nova"
+ }
+ ]
+}
+
diff --git a/nova/tests/integrated/api_samples/os-extended-floating-ips/floating-ips-list-resp.xml.tpl b/nova/tests/integrated/api_samples/os-extended-floating-ips/floating-ips-list-resp.xml.tpl
new file mode 100644
index 000000000..bbd0b117e
--- /dev/null
+++ b/nova/tests/integrated/api_samples/os-extended-floating-ips/floating-ips-list-resp.xml.tpl
@@ -0,0 +1,5 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<floating_ips>
+ <floating_ip instance_id="None" ip="10.10.10.1" fixed_ip="None" id="1" pool="nova"/>
+ <floating_ip instance_id="None" ip="10.10.10.2" fixed_ip="None" id="2" pool="nova"/>
+</floating_ips>
diff --git a/nova/tests/integrated/test_api_samples.py b/nova/tests/integrated/test_api_samples.py
index 188f96055..32ee8816e 100644
--- a/nova/tests/integrated/test_api_samples.py
+++ b/nova/tests/integrated/test_api_samples.py
@@ -83,12 +83,15 @@ class ApiSampleTestBase(integrated_helpers._IntegratedTestBase):
extension_name = None
def setUp(self):
+ extends = []
self.flags(use_ipv6=False,
osapi_compute_link_prefix=self._get_host(),
osapi_glance_link_prefix=self._get_glance_host())
if not self.all_extensions:
+ if hasattr(self, 'extends_name'):
+ extends = [self.extends_name]
ext = [self.extension_name] if self.extension_name else []
- self.flags(osapi_compute_extension=ext)
+ self.flags(osapi_compute_extension=ext + extends)
super(ApiSampleTestBase, self).setUp()
fake_network.stub_compute_with_ips(self.stubs)
self.generate_samples = os.getenv('GENERATE_SAMPLES') is not None
@@ -1351,10 +1354,21 @@ class FloatingIpsJsonTest(ApiSampleTestBase):
self.assertEqual(response.status, 202)
+class ExtendedFloatingIpsJsonTest(FloatingIpsJsonTest):
+ extends_name = ("nova.api.openstack.compute.contrib."
+ "floating_ips.Floating_ips")
+ extension_name = ("nova.api.openstack.compute.contrib."
+ "extended_floating_ips.Extended_floating_ips")
+
+
class FloatingIpsXmlTest(FloatingIpsJsonTest):
ctype = 'xml'
+class ExtendedFloatingIpsXmlTest(ExtendedFloatingIpsJsonTest):
+ ctype = 'xml'
+
+
class FloatingIpsBulkJsonTest(ApiSampleTestBase):
extension_name = "nova.api.openstack.compute.contrib." \
"floating_ips_bulk.Floating_ips_bulk"