summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark McClain <mark.mcclain@dreamhost.com>2012-10-22 18:15:24 -0400
committerMark McClain <mark.mcclain@dreamhost.com>2012-10-22 18:25:29 -0400
commit83a84182cd5dbd4571291f176f421d3fec572f5f (patch)
tree6373812a7a9d949b937fe3282d8afed2aa8c7543
parent16d653a3067332dc06f5138d2b842a79d65803a6 (diff)
downloadnova-83a84182cd5dbd4571291f176f421d3fec572f5f.tar.gz
nova-83a84182cd5dbd4571291f176f421d3fec572f5f.tar.xz
nova-83a84182cd5dbd4571291f176f421d3fec572f5f.zip
add port support when QuantumV2 subclass is used
fixes bug 1070045 Fix the current implementation by checking if FLAGS.network_api_class is a subclass of nova.network.quantumv2.api.API. Previously, the API would not accept port references unless the network_api_class string was anything other than the QuantumV2 class. This limitation prevented subclassing. This changeset includes additional API unit tests focused on QuantumV2 and requested networks. Change-Id: I6b7b7389e127ff8b084ac379cb9aebccc102620c
-rw-r--r--nova/api/openstack/compute/servers.py8
-rw-r--r--nova/tests/api/openstack/compute/test_servers.py52
2 files changed, 58 insertions, 2 deletions
diff --git a/nova/api/openstack/compute/servers.py b/nova/api/openstack/compute/servers.py
index 89eac8bfd..c5e829d52 100644
--- a/nova/api/openstack/compute/servers.py
+++ b/nova/api/openstack/compute/servers.py
@@ -32,6 +32,8 @@ from nova import compute
from nova.compute import instance_types
from nova import exception
from nova import flags
+from nova.network.quantumv2 import api as quantum_api
+from nova.openstack.common import importutils
from nova.openstack.common import log as logging
from nova.openstack.common.rpc import common as rpc_common
from nova.openstack.common import timeutils
@@ -597,8 +599,10 @@ class Controller(wsgi.Controller):
return injected_files
def _is_quantum_v2(self):
- return FLAGS.network_api_class ==\
- "nova.network.quantumv2.api.API"
+ return issubclass(
+ importutils.import_class(FLAGS.network_api_class),
+ quantum_api.API
+ )
def _get_requested_networks(self, requested_networks):
"""Create a list of requested networks from the networks attribute."""
diff --git a/nova/tests/api/openstack/compute/test_servers.py b/nova/tests/api/openstack/compute/test_servers.py
index e8162fda6..117ff26a4 100644
--- a/nova/tests/api/openstack/compute/test_servers.py
+++ b/nova/tests/api/openstack/compute/test_servers.py
@@ -40,6 +40,7 @@ from nova.db.sqlalchemy import models
from nova import exception
from nova import flags
from nova.network import manager
+from nova.network import quantumv2
from nova.openstack.common import jsonutils
from nova.openstack.common import rpc
from nova import test
@@ -135,6 +136,11 @@ class Base64ValidationTest(test.TestCase):
self.assertEqual(result, None)
+class QuantumV2Subclass(quantumv2.api.API):
+ """Used to ensure that API handles subclasses properly."""
+ pass
+
+
class ServersControllerTest(test.TestCase):
def setUp(self):
@@ -175,6 +181,52 @@ class ServersControllerTest(test.TestCase):
res = self.controller._get_requested_networks(requested_networks)
self.assertTrue((uuid, None) in res)
+ def test_requested_networks_quantumv2_enabled_with_port(self):
+ self.flags(network_api_class='nova.network.quantumv2.api.API')
+ port = 'eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee'
+ requested_networks = [{'port': port}]
+ res = self.controller._get_requested_networks(requested_networks)
+ self.assertEquals(res, [(None, None, port)])
+
+ def test_requested_networks_quantumv2_enabled_with_network(self):
+ self.flags(network_api_class='nova.network.quantumv2.api.API')
+ network = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'
+ requested_networks = [{'uuid': network}]
+ res = self.controller._get_requested_networks(requested_networks)
+ self.assertEquals(res, [(network, None, None)])
+
+ def test_requested_networks_quantumv2_enabled_with_network_and_port(self):
+ self.flags(network_api_class='nova.network.quantumv2.api.API')
+ network = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'
+ port = 'eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee'
+ requested_networks = [{'uuid': network, 'port': port}]
+ res = self.controller._get_requested_networks(requested_networks)
+ self.assertEquals(res, [(None, None, port)])
+
+ def test_requested_networks_quantumv2_disabled_with_port(self):
+ port = 'eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee'
+ requested_networks = [{'port': port}]
+ self.assertRaises(
+ webob.exc.HTTPBadRequest,
+ self.controller._get_requested_networks,
+ requested_networks)
+
+ def test_requested_networks_api_enabled_with_v2_subclass(self):
+ self.flags(network_api_class='nova.network.quantumv2.api.API')
+ network = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'
+ port = 'eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee'
+ requested_networks = [{'uuid': network, 'port': port}]
+ res = self.controller._get_requested_networks(requested_networks)
+ self.assertEquals(res, [(None, None, port)])
+
+ def test_requested_networks_quantumv2_subclass_with_port(self):
+ cls = 'nova.tests.api.openstack.compute.test_servers.QuantumV2Subclass'
+ self.flags(network_api_class=cls)
+ port = 'eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee'
+ requested_networks = [{'port': port}]
+ res = self.controller._get_requested_networks(requested_networks)
+ self.assertEquals(res, [(None, None, port)])
+
def test_get_server_by_uuid(self):
req = fakes.HTTPRequest.blank('/v2/fake/servers/%s' % FAKE_UUID)
res_dict = self.controller.show(req, FAKE_UUID)