diff --git a/openstackclient/api/compute_v2.py b/openstackclient/api/compute_v2.py index 3141728acf..650226713c 100644 --- a/openstackclient/api/compute_v2.py +++ b/openstackclient/api/compute_v2.py @@ -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( diff --git a/openstackclient/network/v2/floating_ip_pool.py b/openstackclient/network/v2/floating_ip_pool.py index 73e94ead8b..ebb15da8d7 100644 --- a/openstackclient/network/v2/floating_ip_pool.py +++ b/openstackclient/network/v2/floating_ip_pool.py @@ -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)) diff --git a/openstackclient/tests/unit/api/test_compute_v2.py b/openstackclient/tests/unit/api/test_compute_v2.py index 7a30223c5a..22ee489967 100644 --- a/openstackclient/tests/unit/api/test_compute_v2.py +++ b/openstackclient/tests/unit/api/test_compute_v2.py @@ -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 = { diff --git a/openstackclient/tests/unit/compute/v2/fakes.py b/openstackclient/tests/unit/compute/v2/fakes.py index ff50f4fe88..e6af947684 100644 --- a/openstackclient/tests/unit/compute/v2/fakes.py +++ b/openstackclient/tests/unit/compute/v2/fakes.py @@ -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): diff --git a/openstackclient/tests/unit/network/v2/test_floating_ip_compute.py b/openstackclient/tests/unit/network/v2/test_floating_ip_compute.py index 0d58c158b2..df47e63e91 100644 --- a/openstackclient/tests/unit/network/v2/test_floating_ip_compute.py +++ b/openstackclient/tests/unit/network/v2/test_floating_ip_compute.py @@ -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) diff --git a/openstackclient/tests/unit/network/v2/test_floating_ip_pool_compute.py b/openstackclient/tests/unit/network/v2/test_floating_ip_pool_compute.py index 8db2143035..591f58ca4e 100644 --- a/openstackclient/tests/unit/network/v2/test_floating_ip_pool_compute.py +++ b/openstackclient/tests/unit/network/v2/test_floating_ip_pool_compute.py @@ -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))