Merge "SDK for Neutron Subnetpools"

This commit is contained in:
Zuul 2024-08-30 19:32:30 +00:00 committed by Gerrit Code Review
commit 4be54ccc4b
3 changed files with 57 additions and 56 deletions

View File

@ -1753,20 +1753,18 @@ def subnet_delete(request, subnet_id):
@profiler.trace @profiler.trace
def subnetpool_list(request, **params): def subnetpool_list(request, **params):
LOG.debug("subnetpool_list(): params=%s", params) LOG.debug("subnetpool_list(): params=%s", params)
subnetpools = \ subnetpools = networkclient(request).subnet_pools(**params)
neutronclient(request).list_subnetpools(**params).get('subnetpools') if not isinstance(subnetpools, (types.GeneratorType, list)):
return [SubnetPool(s) for s in subnetpools] subnetpools = [subnetpools]
return [SubnetPool(s.to_dict()) for s in subnetpools]
@profiler.trace @profiler.trace
def subnetpool_get(request, subnetpool_id, **params): def subnetpool_get(request, subnetpool_id):
LOG.debug("subnetpool_get(): subnetpoolid=%(subnetpool_id)s, " LOG.debug("subnetpool_get(): subnetpoolid=%(subnetpool_id)s",
"params=%(params)s", {'subnetpool_id': subnetpool_id, {'subnetpool_id': subnetpool_id})
'params': params}) subnetpool = networkclient(request).get_subnet_pool(subnetpool_id)
subnetpool = \ return SubnetPool(subnetpool.to_dict())
neutronclient(request).show_subnetpool(subnetpool_id,
**params).get('subnetpool')
return SubnetPool(subnetpool)
@profiler.trace @profiler.trace
@ -1794,17 +1792,15 @@ def subnetpool_create(request, name, prefixes, **kwargs):
LOG.debug("subnetpool_create(): name=%(name)s, prefixes=%(prefixes)s, " LOG.debug("subnetpool_create(): name=%(name)s, prefixes=%(prefixes)s, "
"kwargs=%(kwargs)s", {'name': name, 'prefixes': prefixes, "kwargs=%(kwargs)s", {'name': name, 'prefixes': prefixes,
'kwargs': kwargs}) 'kwargs': kwargs})
body = {'subnetpool': body = {'name': name,
{'name': name, 'prefixes': prefixes,
'prefixes': prefixes,
}
} }
if 'tenant_id' not in kwargs: if 'tenant_id' not in kwargs:
kwargs['tenant_id'] = request.user.project_id kwargs['tenant_id'] = request.user.project_id
body['subnetpool'].update(kwargs) body.update(kwargs)
subnetpool = \ subnetpool = \
neutronclient(request).create_subnetpool(body=body).get('subnetpool') networkclient(request).create_subnet_pool(**body)
return SubnetPool(subnetpool) return SubnetPool(subnetpool.to_dict())
@profiler.trace @profiler.trace
@ -1812,17 +1808,15 @@ def subnetpool_update(request, subnetpool_id, **kwargs):
LOG.debug("subnetpool_update(): subnetpoolid=%(subnetpool_id)s, " LOG.debug("subnetpool_update(): subnetpoolid=%(subnetpool_id)s, "
"kwargs=%(kwargs)s", {'subnetpool_id': subnetpool_id, "kwargs=%(kwargs)s", {'subnetpool_id': subnetpool_id,
'kwargs': kwargs}) 'kwargs': kwargs})
body = {'subnetpool': kwargs}
subnetpool = \ subnetpool = \
neutronclient(request).update_subnetpool(subnetpool_id, networkclient(request).update_subnet_pool(subnetpool_id, **kwargs)
body=body).get('subnetpool') return SubnetPool(subnetpool.to_dict())
return SubnetPool(subnetpool)
@profiler.trace @profiler.trace
def subnetpool_delete(request, subnetpool_id): def subnetpool_delete(request, subnetpool_id):
LOG.debug("subnetpool_delete(): subnetpoolid=%s", subnetpool_id) LOG.debug("subnetpool_delete(): subnetpoolid=%s", subnetpool_id)
return neutronclient(request).delete_subnetpool(subnetpool_id) return networkclient(request).delete_subnet_pool(subnetpool_id)
@profiler.trace @profiler.trace

View File

@ -17,6 +17,7 @@ import copy
from openstack.network.v2 import network as sdk_net from openstack.network.v2 import network as sdk_net
from openstack.network.v2 import port as sdk_port from openstack.network.v2 import port as sdk_port
from openstack.network.v2 import subnet as sdk_subnet from openstack.network.v2 import subnet as sdk_subnet
from openstack.network.v2 import subnet_pool as sdk_subnet_pool
from openstack.network.v2 import trunk as sdk_trunk from openstack.network.v2 import trunk as sdk_trunk
from oslo_utils import uuidutils from oslo_utils import uuidutils
@ -93,6 +94,7 @@ def data(TEST):
TEST.api_trunks_sdk = list() TEST.api_trunks_sdk = list()
TEST.api_ports_sdk = list() TEST.api_ports_sdk = list()
TEST.api_tp_ports_sdk = list() TEST.api_tp_ports_sdk = list()
TEST.api_subnetpools_sdk = list()
# 1st network. # 1st network.
network_dict = {'is_admin_state_up': True, network_dict = {'is_admin_state_up': True,
@ -206,6 +208,7 @@ def data(TEST):
TEST.api_ports.add(port_dict) TEST.api_ports.add(port_dict)
TEST.api_ports_sdk.append(sdk_port.Port(**port_dict)) TEST.api_ports_sdk.append(sdk_port.Port(**port_dict))
TEST.ports.add(neutron.Port(port_dict)) TEST.ports.add(neutron.Port(port_dict))
assoc_port = port_dict assoc_port = port_dict
port_dict = { port_dict = {
@ -927,6 +930,8 @@ def data(TEST):
'tenant_id': '1'} 'tenant_id': '1'}
TEST.api_subnetpools.add(subnetpool_dict) TEST.api_subnetpools.add(subnetpool_dict)
TEST.api_subnetpools_sdk.append(
(sdk_subnet_pool.SubnetPool(**subnetpool_dict)))
subnetpool = neutron.SubnetPool(subnetpool_dict) subnetpool = neutron.SubnetPool(subnetpool_dict)
TEST.subnetpools.add(subnetpool) TEST.subnetpools.add(subnetpool)
@ -943,6 +948,8 @@ def data(TEST):
'tenant_id': '1'} 'tenant_id': '1'}
TEST.api_subnetpools.add(subnetpool_dict) TEST.api_subnetpools.add(subnetpool_dict)
TEST.api_subnetpools_sdk.append(
(sdk_subnet_pool.SubnetPool(**subnetpool_dict)))
subnetpool = neutron.SubnetPool(subnetpool_dict) subnetpool = neutron.SubnetPool(subnetpool_dict)
TEST.subnetpools.add(subnetpool) TEST.subnetpools.add(subnetpool)

View File

@ -18,6 +18,7 @@ import netaddr
from neutronclient.common import exceptions as neutron_exc from neutronclient.common import exceptions as neutron_exc
from openstack import exceptions as sdk_exceptions from openstack import exceptions as sdk_exceptions
from openstack.network.v2 import port as sdk_port from openstack.network.v2 import port as sdk_port
from openstack.network.v2 import subnet_pool as sdk_subnet_pool
from openstack.network.v2 import trunk as sdk_trunk from openstack.network.v2 import trunk as sdk_trunk
from oslo_utils import uuidutils from oslo_utils import uuidutils
@ -1095,77 +1096,76 @@ class NeutronApiTests(test.APIMockTestCase):
neutronclient.delete_subnet.assert_called_once_with(subnet_id) neutronclient.delete_subnet.assert_called_once_with(subnet_id)
@mock.patch.object(api.neutron, 'neutronclient') @mock.patch.object(api.neutron, 'networkclient')
def test_subnetpool_list(self, mock_neutronclient): def test_subnetpool_list(self, mock_networkclient):
subnetpools = {'subnetpools': self.api_subnetpools.list()} subnetpools = self.api_subnetpools_sdk
neutronclient = mock_neutronclient.return_value network_client = mock_networkclient.return_value
neutronclient.list_subnetpools.return_value = subnetpools network_client.subnet_pools.return_value = subnetpools
ret_val = api.neutron.subnetpool_list(self.request) ret_val = api.neutron.subnetpool_list(self.request)
for n in ret_val: for n in ret_val:
self.assertIsInstance(n, api.neutron.SubnetPool) self.assertIsInstance(n, api.neutron.SubnetPool)
neutronclient.list_subnetpools.assert_called_once_with() network_client.subnet_pools.assert_called_once_with()
@mock.patch.object(api.neutron, 'neutronclient') @mock.patch.object(api.neutron, 'networkclient')
def test_subnetpool_get(self, mock_neutronclient): def test_subnetpool_get(self, mock_networkclient):
subnetpool = {'subnetpool': self.api_subnetpools.first()} subnetpool = self.api_subnetpools_sdk[0]
subnetpool_id = self.api_subnetpools.first()['id'] subnetpool_id = self.api_subnetpools_sdk[0]['id']
neutronclient = mock_neutronclient.return_value network_client = mock_networkclient.return_value
neutronclient.show_subnetpool.return_value = subnetpool network_client.get_subnet_pool.return_value = subnetpool
ret_val = api.neutron.subnetpool_get(self.request, subnetpool_id) ret_val = api.neutron.subnetpool_get(self.request, subnetpool_id)
self.assertIsInstance(ret_val, api.neutron.SubnetPool) self.assertIsInstance(ret_val, api.neutron.SubnetPool)
neutronclient.show_subnetpool.assert_called_once_with(subnetpool_id) network_client.get_subnet_pool.assert_called_once_with(subnetpool_id)
@mock.patch.object(api.neutron, 'neutronclient') @mock.patch.object(api.neutron, 'networkclient')
def test_subnetpool_create(self, mock_neutronclient): def test_subnetpool_create(self, mock_networkclient):
subnetpool_data = self.api_subnetpools.first() subnetpool_data = self.api_subnetpools_sdk[0]
params = {'name': subnetpool_data['name'], params = {'name': subnetpool_data['name'],
'prefixes': subnetpool_data['prefixes'], 'prefixes': subnetpool_data['prefixes'],
'tenant_id': subnetpool_data['tenant_id']} 'tenant_id': subnetpool_data['tenant_id']}
neutronclient = mock_neutronclient.return_value network_client = mock_networkclient.return_value
neutronclient.create_subnetpool.return_value = {'subnetpool': network_client.create_subnet_pool.return_value = subnetpool_data
subnetpool_data}
ret_val = api.neutron.subnetpool_create(self.request, **params) ret_val = api.neutron.subnetpool_create(self.request, **params)
self.assertIsInstance(ret_val, api.neutron.SubnetPool) self.assertIsInstance(ret_val, api.neutron.SubnetPool)
neutronclient.create_subnetpool.assert_called_once_with( network_client.create_subnet_pool.assert_called_once_with(**params)
body={'subnetpool': params})
@mock.patch.object(api.neutron, 'neutronclient') @mock.patch.object(api.neutron, 'networkclient')
def test_subnetpool_update(self, mock_neutronclient): def test_subnetpool_update(self, mock_networkclient):
subnetpool_data = self.api_subnetpools.first() subnetpool_data = self.api_subnetpools.first()
subnetpool_id = subnetpool_data['id'] subnetpool_id = subnetpool_data['id']
params = {'name': subnetpool_data['name'], params = {'name': subnetpool_data['name'],
'prefixes': subnetpool_data['prefixes']} 'prefixes': subnetpool_data['prefixes']}
neutronclient = mock_neutronclient.return_value network_client = mock_networkclient.return_value
neutronclient.update_subnetpool.return_value = {'subnetpool': mock_ret = sdk_subnet_pool.SubnetPool(**subnetpool_data)
subnetpool_data} network_client.update_subnet_pool.return_value = mock_ret
ret_val = api.neutron.subnetpool_update(self.request, subnetpool_id, ret_val = api.neutron.subnetpool_update(self.request, subnetpool_id,
**params) **params)
self.assertIsInstance(ret_val, api.neutron.SubnetPool) self.assertIsInstance(ret_val, api.neutron.SubnetPool)
neutronclient.update_subnetpool.assert_called_once_with( network_client.update_subnet_pool.assert_called_once_with(
subnetpool_id, body={'subnetpool': params}) subnetpool_id, **params)
@mock.patch.object(api.neutron, 'neutronclient') @mock.patch.object(api.neutron, 'networkclient')
def test_subnetpool_delete(self, mock_neutronclient): def test_subnetpool_delete(self, mock_networkclient):
subnetpool_id = self.api_subnetpools.first()['id'] subnetpool_id = self.api_subnetpools.first()['id']
neutronclient = mock_neutronclient.return_value network_client = mock_networkclient.return_value
neutronclient.delete_subnetpool.return_value = None network_client.delete_subnet_pool.return_value = None
api.neutron.subnetpool_delete(self.request, subnetpool_id) api.neutron.subnetpool_delete(self.request, subnetpool_id)
neutronclient.delete_subnetpool.assert_called_once_with(subnetpool_id) network_client.delete_subnet_pool.assert_called_once_with(
subnetpool_id)
@mock.patch.object(api.neutron, 'networkclient') @mock.patch.object(api.neutron, 'networkclient')
def test_port_list(self, mock_networkclient): def test_port_list(self, mock_networkclient):