Low-level Compute v2 API: floating ip pool
api.compute.APIv2 floating ip pool function. novaclient 8.0 is now released without support for the previously deprecated nova-net functions, so include a new low-level REST implementation of the removed APIs. Also includes a handful of cleanups that the previous security group and floating IP reviews missed. Change-Id: I20116ec4fc1113857d8d917bfb30fa3170d05b9f
This commit is contained in:
parent
7e1350815e
commit
107cad200a
@ -168,13 +168,30 @@ class APIv2(api.BaseAPI):
|
||||
https://developer.openstack.org/api-ref/compute/#show-floating-ip-address-details
|
||||
|
||||
:returns:
|
||||
list of security groups names
|
||||
list of floating IPs
|
||||
"""
|
||||
|
||||
url = "/os-floating-ips"
|
||||
|
||||
return self.list(url)["floating_ips"]
|
||||
|
||||
# Floating IP Pools
|
||||
|
||||
def floating_ip_pool_list(
|
||||
self,
|
||||
):
|
||||
"""Get floating IP pools
|
||||
|
||||
https://developer.openstack.org/api-ref/compute/?expanded=#list-floating-ip-pools
|
||||
|
||||
:returns:
|
||||
list of floating IP pools
|
||||
"""
|
||||
|
||||
url = "/os-floating-ip-pools"
|
||||
|
||||
return self.list(url)["floating_ip_pools"]
|
||||
|
||||
# Networks
|
||||
|
||||
def network_create(
|
||||
|
@ -34,10 +34,10 @@ class ListFloatingIPPool(common.NetworkAndComputeLister):
|
||||
columns = (
|
||||
'Name',
|
||||
)
|
||||
data = client.floating_ip_pools.list()
|
||||
data = client.api.floating_ip_pool_list()
|
||||
|
||||
return (columns,
|
||||
(utils.get_item_properties(
|
||||
(utils.get_dict_properties(
|
||||
s, columns,
|
||||
) for s in data))
|
||||
|
||||
|
@ -145,6 +145,24 @@ class TestFloatingIP(TestComputeAPIv2):
|
||||
self.assertEqual(self.LIST_FLOATING_IP_RESP, ret)
|
||||
|
||||
|
||||
class TestFloatingIPPool(TestComputeAPIv2):
|
||||
|
||||
LIST_FLOATING_IP_POOL_RESP = [
|
||||
{"name": "tide"},
|
||||
{"name": "press"},
|
||||
]
|
||||
|
||||
def test_floating_ip_pool_list(self):
|
||||
self.requests_mock.register_uri(
|
||||
'GET',
|
||||
FAKE_URL + '/os-floating-ip-pools',
|
||||
json={'floating_ip_pools': self.LIST_FLOATING_IP_POOL_RESP},
|
||||
status_code=200,
|
||||
)
|
||||
ret = self.api.floating_ip_pool_list()
|
||||
self.assertEqual(self.LIST_FLOATING_IP_POOL_RESP, ret)
|
||||
|
||||
|
||||
class TestNetwork(TestComputeAPIv2):
|
||||
|
||||
FAKE_NETWORK_RESP = {
|
||||
|
@ -181,15 +181,6 @@ class FakeComputev2Client(object):
|
||||
self.hypervisors_stats = mock.Mock()
|
||||
self.hypervisors_stats.resource_class = fakes.FakeResource(None, {})
|
||||
|
||||
self.security_group_rules = mock.Mock()
|
||||
self.security_group_rules.resource_class = fakes.FakeResource(None, {})
|
||||
|
||||
self.floating_ips = mock.Mock()
|
||||
self.floating_ips.resource_class = fakes.FakeResource(None, {})
|
||||
|
||||
self.floating_ip_pools = mock.Mock()
|
||||
self.floating_ip_pools.resource_class = fakes.FakeResource(None, {})
|
||||
|
||||
self.keypairs = mock.Mock()
|
||||
self.keypairs.resource_class = fakes.FakeResource(None, {})
|
||||
|
||||
@ -1074,11 +1065,7 @@ class FakeFloatingIPPool(object):
|
||||
# Overwrite default attributes.
|
||||
floating_ip_pool_attrs.update(attrs)
|
||||
|
||||
floating_ip_pool = fakes.FakeResource(
|
||||
info=copy.deepcopy(floating_ip_pool_attrs),
|
||||
loaded=True)
|
||||
|
||||
return floating_ip_pool
|
||||
return floating_ip_pool_attrs
|
||||
|
||||
@staticmethod
|
||||
def create_floating_ip_pools(attrs=None, count=2):
|
||||
|
@ -103,10 +103,6 @@ class TestDeleteFloatingIPCompute(TestFloatingIPCompute):
|
||||
|
||||
self.app.client_manager.network_endpoint_enabled = False
|
||||
|
||||
# Return value of utils.find_resource()
|
||||
self.compute.floating_ips.get = (
|
||||
compute_fakes.FakeFloatingIP.get_floating_ips(self._floating_ips))
|
||||
|
||||
# Get the command object to test
|
||||
self.cmd = fip.DeleteFloatingIP(self.app, None)
|
||||
|
||||
|
@ -11,6 +11,8 @@
|
||||
# under the License.
|
||||
#
|
||||
|
||||
import mock
|
||||
|
||||
from openstackclient.network.v2 import floating_ip_pool
|
||||
from openstackclient.tests.unit.compute.v2 import fakes as compute_fakes
|
||||
|
||||
@ -26,10 +28,13 @@ class TestFloatingIPPoolCompute(compute_fakes.TestComputev2):
|
||||
self.compute = self.app.client_manager.compute
|
||||
|
||||
|
||||
@mock.patch(
|
||||
'openstackclient.api.compute_v2.APIv2.floating_ip_pool_list'
|
||||
)
|
||||
class TestListFloatingIPPoolCompute(TestFloatingIPPoolCompute):
|
||||
|
||||
# The floating ip pools to list up
|
||||
floating_ip_pools = \
|
||||
_floating_ip_pools = \
|
||||
compute_fakes.FakeFloatingIPPool.create_floating_ip_pools(count=3)
|
||||
|
||||
columns = (
|
||||
@ -37,9 +42,9 @@ class TestListFloatingIPPoolCompute(TestFloatingIPPoolCompute):
|
||||
)
|
||||
|
||||
data = []
|
||||
for pool in floating_ip_pools:
|
||||
for pool in _floating_ip_pools:
|
||||
data.append((
|
||||
pool.name,
|
||||
pool['name'],
|
||||
))
|
||||
|
||||
def setUp(self):
|
||||
@ -47,19 +52,17 @@ class TestListFloatingIPPoolCompute(TestFloatingIPPoolCompute):
|
||||
|
||||
self.app.client_manager.network_endpoint_enabled = False
|
||||
|
||||
self.compute.floating_ip_pools.list.return_value = \
|
||||
self.floating_ip_pools
|
||||
|
||||
# Get the command object to test
|
||||
self.cmd = floating_ip_pool.ListFloatingIPPool(self.app, None)
|
||||
|
||||
def test_floating_ip_list(self):
|
||||
def test_floating_ip_list(self, fipp_mock):
|
||||
fipp_mock.return_value = self._floating_ip_pools
|
||||
arglist = []
|
||||
verifylist = []
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.compute.floating_ip_pools.list.assert_called_once_with()
|
||||
fipp_mock.assert_called_once_with()
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(self.data, list(data))
|
||||
|
Loading…
Reference in New Issue
Block a user