Merge "Port floating_ip_pools extention to v2.1"

This commit is contained in:
Jenkins 2014-10-13 16:22:25 +00:00 committed by Gerrit Code Review
commit b722bb7884
8 changed files with 146 additions and 8 deletions

View File

@ -0,0 +1,10 @@
{
"floating_ip_pools": [
{
"name": "pool1"
},
{
"name": "pool2"
}
]
}

View File

@ -152,6 +152,8 @@
"compute_extension:v3:flavor-manage": "rule:admin_api",
"compute_extension:floating_ip_dns": "",
"compute_extension:floating_ip_pools": "",
"compute_extension:v3:os-floating-ip-pools": "",
"compute_extension:v3:os-floating-ip-pools:discoverable": "",
"compute_extension:floating_ips": "",
"compute_extension:floating_ips_bulk": "rule:admin_api",
"compute_extension:fping": "",

View File

@ -0,0 +1,68 @@
# Copyright (c) 2011 X.commerce, a business unit of eBay Inc.
#
# 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.
from nova.api.openstack import extensions
from nova import network
ALIAS = 'os-floating-ip-pools'
authorize = extensions.extension_authorizer('compute', 'v3:' + ALIAS)
def _translate_floating_ip_view(pool_name):
return {
'name': pool_name,
}
def _translate_floating_ip_pools_view(pools):
return {
'floating_ip_pools': [_translate_floating_ip_view(pool_name)
for pool_name in pools]
}
class FloatingIPPoolsController(object):
"""The Floating IP Pool API controller for the OpenStack API."""
def __init__(self):
self.network_api = network.API()
super(FloatingIPPoolsController, self).__init__()
@extensions.expected_errors(())
def index(self, req):
"""Return a list of pools."""
context = req.environ['nova.context']
authorize(context)
pools = self.network_api.get_floating_ip_pools(context)
return _translate_floating_ip_pools_view(pools)
class FloatingIpPools(extensions.V3APIExtensionBase):
"""Floating IPs support."""
name = "FloatingIpPools"
alias = ALIAS
version = 1
def get_resources(self):
resource = [extensions.ResourceExtension(ALIAS,
FloatingIPPoolsController())]
return resource
def get_controller_extensions(self):
"""It's an abstract function V3APIExtensionBase and the extension
will not be loaded without it.
"""
return []

View File

@ -15,7 +15,9 @@
from lxml import etree
from nova.api.openstack.compute.contrib import floating_ip_pools
from nova.api.openstack.compute.contrib import floating_ip_pools as fipp_v2
from nova.api.openstack.compute.plugins.v3 import floating_ip_pools as\
fipp_v21
from nova import context
from nova import network
from nova import test
@ -26,18 +28,21 @@ def fake_get_floating_ip_pools(self, context):
return ['nova', 'other']
class FloatingIpPoolTest(test.NoDBTestCase):
class FloatingIpPoolTestV21(test.NoDBTestCase):
floating_ip_pools = fipp_v21
url = '/v2/fake/os-floating-ip-pools'
def setUp(self):
super(FloatingIpPoolTest, self).setUp()
super(FloatingIpPoolTestV21, self).setUp()
self.stubs.Set(network.api.API, "get_floating_ip_pools",
fake_get_floating_ip_pools)
self.context = context.RequestContext('fake', 'fake')
self.controller = floating_ip_pools.FloatingIPPoolsController()
self.controller = self.floating_ip_pools.FloatingIPPoolsController()
def test_translate_floating_ip_pools_view(self):
pools = fake_get_floating_ip_pools(None, self.context)
view = floating_ip_pools._translate_floating_ip_pools_view(pools)
view = self.floating_ip_pools._translate_floating_ip_pools_view(pools)
self.assertIn('floating_ip_pools', view)
self.assertEqual(view['floating_ip_pools'][0]['name'],
pools[0])
@ -45,7 +50,7 @@ class FloatingIpPoolTest(test.NoDBTestCase):
pools[1])
def test_floating_ips_pools_list(self):
req = fakes.HTTPRequest.blank('/v2/fake/os-floating-ip-pools')
req = fakes.HTTPRequest.blank(self.url)
res_dict = self.controller.index(req)
pools = fake_get_floating_ip_pools(None, self.context)
@ -53,9 +58,15 @@ class FloatingIpPoolTest(test.NoDBTestCase):
self.assertEqual(res_dict, response)
class FloatingIpPoolSerializerTest(test.NoDBTestCase):
class FloatingIpPoolTestV2(FloatingIpPoolTestV21):
floating_ip_pools = fipp_v2
class FloatingIpPoolSerializerTestV2(test.NoDBTestCase):
floating_ip_pools = fipp_v2
def test_index_serializer(self):
serializer = floating_ip_pools.FloatingIPPoolsTemplate()
serializer = self.floating_ip_pools.FloatingIPPoolsTemplate()
text = serializer.serialize(dict(
floating_ip_pools=[
dict(name='nova'),

View File

@ -212,6 +212,7 @@ policy_data = """
"compute_extension:v3:flavors:discoverable": "",
"compute_extension:floating_ip_dns": "",
"compute_extension:floating_ip_pools": "",
"compute_extension:v3:os-floating-ip-pools": "",
"compute_extension:floating_ips": "",
"compute_extension:floating_ips_bulk": "",
"compute_extension:fping": "",

View File

@ -0,0 +1,10 @@
{
"floating_ip_pools": [
{
"name": "%(pool1)s"
},
{
"name": "%(pool2)s"
}
]
}

View File

@ -0,0 +1,35 @@
# Copyright 2014 IBM Corp.
#
# 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.
from nova.network import api as network_api
from nova.tests.integrated.v3 import api_sample_base
class FloatingIPPoolsSampleTests(api_sample_base.ApiSampleTestBaseV3):
extension_name = "os-floating-ip-pools"
def test_list_floatingippools(self):
pool_list = ["pool1", "pool2"]
def fake_get_floating_ip_pools(self, context):
return pool_list
self.stubs.Set(network_api.API, "get_floating_ip_pools",
fake_get_floating_ip_pools)
response = self._do_get('os-floating-ip-pools')
subs = {
'pool1': pool_list[0],
'pool2': pool_list[1]
}
self._verify_response('floatingippools-list-resp', subs, response, 200)

View File

@ -84,6 +84,7 @@ nova.api.v3.extensions =
flavor_access = nova.api.openstack.compute.plugins.v3.flavor_access:FlavorAccess
flavor_rxtx = nova.api.openstack.compute.plugins.v3.flavor_rxtx:FlavorRxtx
flavor_manage = nova.api.openstack.compute.plugins.v3.flavor_manage:FlavorManage
floating_ip_pools = nova.api.openstack.compute.plugins.v3.floating_ip_pools:FloatingIpPools
fping = nova.api.openstack.compute.plugins.v3.fping:Fping
hide_server_addresses = nova.api.openstack.compute.plugins.v3.hide_server_addresses:HideServerAddresses
hosts = nova.api.openstack.compute.plugins.v3.hosts:Hosts