Skip to content

Commit

Permalink
Merge "Port floating_ip_pools extention to v2.1"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Oct 13, 2014
2 parents df57d44 + 2773fed commit b722bb7
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 8 deletions.
@@ -0,0 +1,10 @@
{
"floating_ip_pools": [
{
"name": "pool1"
},
{
"name": "pool2"
}
]
}
2 changes: 2 additions & 0 deletions etc/nova/policy.json
Expand Up @@ -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": "",
Expand Down
68 changes: 68 additions & 0 deletions nova/api/openstack/compute/plugins/v3/floating_ip_pools.py
@@ -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 []
27 changes: 19 additions & 8 deletions nova/tests/api/openstack/compute/contrib/test_floating_ip_pools.py
Expand Up @@ -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
Expand All @@ -26,36 +28,45 @@ 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])
self.assertEqual(view['floating_ip_pools'][1]['name'],
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)
response = {'floating_ip_pools': [{'name': name} for name in pools]}
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'),
Expand Down
1 change: 1 addition & 0 deletions nova/tests/fake_policy.py
Expand Up @@ -212,6 +212,7 @@
"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": "",
Expand Down
@@ -0,0 +1,10 @@
{
"floating_ip_pools": [
{
"name": "%(pool1)s"
},
{
"name": "%(pool2)s"
}
]
}
35 changes: 35 additions & 0 deletions nova/tests/integrated/v3/test_floating_ip_pools.py
@@ -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)
1 change: 1 addition & 0 deletions setup.cfg
Expand Up @@ -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
Expand Down

0 comments on commit b722bb7

Please sign in to comment.