Merge "SDK for Neutron Subnetpools"
This commit is contained in:
commit
4be54ccc4b
@ -1753,20 +1753,18 @@ def subnet_delete(request, subnet_id):
|
||||
@profiler.trace
|
||||
def subnetpool_list(request, **params):
|
||||
LOG.debug("subnetpool_list(): params=%s", params)
|
||||
subnetpools = \
|
||||
neutronclient(request).list_subnetpools(**params).get('subnetpools')
|
||||
return [SubnetPool(s) for s in subnetpools]
|
||||
subnetpools = networkclient(request).subnet_pools(**params)
|
||||
if not isinstance(subnetpools, (types.GeneratorType, list)):
|
||||
subnetpools = [subnetpools]
|
||||
return [SubnetPool(s.to_dict()) for s in subnetpools]
|
||||
|
||||
|
||||
@profiler.trace
|
||||
def subnetpool_get(request, subnetpool_id, **params):
|
||||
LOG.debug("subnetpool_get(): subnetpoolid=%(subnetpool_id)s, "
|
||||
"params=%(params)s", {'subnetpool_id': subnetpool_id,
|
||||
'params': params})
|
||||
subnetpool = \
|
||||
neutronclient(request).show_subnetpool(subnetpool_id,
|
||||
**params).get('subnetpool')
|
||||
return SubnetPool(subnetpool)
|
||||
def subnetpool_get(request, subnetpool_id):
|
||||
LOG.debug("subnetpool_get(): subnetpoolid=%(subnetpool_id)s",
|
||||
{'subnetpool_id': subnetpool_id})
|
||||
subnetpool = networkclient(request).get_subnet_pool(subnetpool_id)
|
||||
return SubnetPool(subnetpool.to_dict())
|
||||
|
||||
|
||||
@profiler.trace
|
||||
@ -1794,17 +1792,15 @@ def subnetpool_create(request, name, prefixes, **kwargs):
|
||||
LOG.debug("subnetpool_create(): name=%(name)s, prefixes=%(prefixes)s, "
|
||||
"kwargs=%(kwargs)s", {'name': name, 'prefixes': prefixes,
|
||||
'kwargs': kwargs})
|
||||
body = {'subnetpool':
|
||||
{'name': name,
|
||||
'prefixes': prefixes,
|
||||
}
|
||||
body = {'name': name,
|
||||
'prefixes': prefixes,
|
||||
}
|
||||
if 'tenant_id' not in kwargs:
|
||||
kwargs['tenant_id'] = request.user.project_id
|
||||
body['subnetpool'].update(kwargs)
|
||||
body.update(kwargs)
|
||||
subnetpool = \
|
||||
neutronclient(request).create_subnetpool(body=body).get('subnetpool')
|
||||
return SubnetPool(subnetpool)
|
||||
networkclient(request).create_subnet_pool(**body)
|
||||
return SubnetPool(subnetpool.to_dict())
|
||||
|
||||
|
||||
@profiler.trace
|
||||
@ -1812,17 +1808,15 @@ def subnetpool_update(request, subnetpool_id, **kwargs):
|
||||
LOG.debug("subnetpool_update(): subnetpoolid=%(subnetpool_id)s, "
|
||||
"kwargs=%(kwargs)s", {'subnetpool_id': subnetpool_id,
|
||||
'kwargs': kwargs})
|
||||
body = {'subnetpool': kwargs}
|
||||
subnetpool = \
|
||||
neutronclient(request).update_subnetpool(subnetpool_id,
|
||||
body=body).get('subnetpool')
|
||||
return SubnetPool(subnetpool)
|
||||
networkclient(request).update_subnet_pool(subnetpool_id, **kwargs)
|
||||
return SubnetPool(subnetpool.to_dict())
|
||||
|
||||
|
||||
@profiler.trace
|
||||
def subnetpool_delete(request, 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
|
||||
|
@ -17,6 +17,7 @@ import copy
|
||||
from openstack.network.v2 import network as sdk_net
|
||||
from openstack.network.v2 import port as sdk_port
|
||||
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 oslo_utils import uuidutils
|
||||
|
||||
@ -93,6 +94,7 @@ def data(TEST):
|
||||
TEST.api_trunks_sdk = list()
|
||||
TEST.api_ports_sdk = list()
|
||||
TEST.api_tp_ports_sdk = list()
|
||||
TEST.api_subnetpools_sdk = list()
|
||||
|
||||
# 1st network.
|
||||
network_dict = {'is_admin_state_up': True,
|
||||
@ -206,6 +208,7 @@ def data(TEST):
|
||||
TEST.api_ports.add(port_dict)
|
||||
TEST.api_ports_sdk.append(sdk_port.Port(**port_dict))
|
||||
TEST.ports.add(neutron.Port(port_dict))
|
||||
|
||||
assoc_port = port_dict
|
||||
|
||||
port_dict = {
|
||||
@ -927,6 +930,8 @@ def data(TEST):
|
||||
'tenant_id': '1'}
|
||||
|
||||
TEST.api_subnetpools.add(subnetpool_dict)
|
||||
TEST.api_subnetpools_sdk.append(
|
||||
(sdk_subnet_pool.SubnetPool(**subnetpool_dict)))
|
||||
subnetpool = neutron.SubnetPool(subnetpool_dict)
|
||||
TEST.subnetpools.add(subnetpool)
|
||||
|
||||
@ -943,6 +948,8 @@ def data(TEST):
|
||||
'tenant_id': '1'}
|
||||
|
||||
TEST.api_subnetpools.add(subnetpool_dict)
|
||||
TEST.api_subnetpools_sdk.append(
|
||||
(sdk_subnet_pool.SubnetPool(**subnetpool_dict)))
|
||||
subnetpool = neutron.SubnetPool(subnetpool_dict)
|
||||
TEST.subnetpools.add(subnetpool)
|
||||
|
||||
|
@ -18,6 +18,7 @@ import netaddr
|
||||
from neutronclient.common import exceptions as neutron_exc
|
||||
from openstack import exceptions as sdk_exceptions
|
||||
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 oslo_utils import uuidutils
|
||||
|
||||
@ -1095,77 +1096,76 @@ class NeutronApiTests(test.APIMockTestCase):
|
||||
|
||||
neutronclient.delete_subnet.assert_called_once_with(subnet_id)
|
||||
|
||||
@mock.patch.object(api.neutron, 'neutronclient')
|
||||
def test_subnetpool_list(self, mock_neutronclient):
|
||||
subnetpools = {'subnetpools': self.api_subnetpools.list()}
|
||||
@mock.patch.object(api.neutron, 'networkclient')
|
||||
def test_subnetpool_list(self, mock_networkclient):
|
||||
subnetpools = self.api_subnetpools_sdk
|
||||
|
||||
neutronclient = mock_neutronclient.return_value
|
||||
neutronclient.list_subnetpools.return_value = subnetpools
|
||||
network_client = mock_networkclient.return_value
|
||||
network_client.subnet_pools.return_value = subnetpools
|
||||
|
||||
ret_val = api.neutron.subnetpool_list(self.request)
|
||||
|
||||
for n in ret_val:
|
||||
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')
|
||||
def test_subnetpool_get(self, mock_neutronclient):
|
||||
subnetpool = {'subnetpool': self.api_subnetpools.first()}
|
||||
subnetpool_id = self.api_subnetpools.first()['id']
|
||||
@mock.patch.object(api.neutron, 'networkclient')
|
||||
def test_subnetpool_get(self, mock_networkclient):
|
||||
subnetpool = self.api_subnetpools_sdk[0]
|
||||
subnetpool_id = self.api_subnetpools_sdk[0]['id']
|
||||
|
||||
neutronclient = mock_neutronclient.return_value
|
||||
neutronclient.show_subnetpool.return_value = subnetpool
|
||||
network_client = mock_networkclient.return_value
|
||||
network_client.get_subnet_pool.return_value = subnetpool
|
||||
|
||||
ret_val = api.neutron.subnetpool_get(self.request, subnetpool_id)
|
||||
|
||||
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')
|
||||
def test_subnetpool_create(self, mock_neutronclient):
|
||||
subnetpool_data = self.api_subnetpools.first()
|
||||
@mock.patch.object(api.neutron, 'networkclient')
|
||||
def test_subnetpool_create(self, mock_networkclient):
|
||||
subnetpool_data = self.api_subnetpools_sdk[0]
|
||||
params = {'name': subnetpool_data['name'],
|
||||
'prefixes': subnetpool_data['prefixes'],
|
||||
'tenant_id': subnetpool_data['tenant_id']}
|
||||
|
||||
neutronclient = mock_neutronclient.return_value
|
||||
neutronclient.create_subnetpool.return_value = {'subnetpool':
|
||||
subnetpool_data}
|
||||
network_client = mock_networkclient.return_value
|
||||
network_client.create_subnet_pool.return_value = subnetpool_data
|
||||
|
||||
ret_val = api.neutron.subnetpool_create(self.request, **params)
|
||||
|
||||
self.assertIsInstance(ret_val, api.neutron.SubnetPool)
|
||||
neutronclient.create_subnetpool.assert_called_once_with(
|
||||
body={'subnetpool': params})
|
||||
network_client.create_subnet_pool.assert_called_once_with(**params)
|
||||
|
||||
@mock.patch.object(api.neutron, 'neutronclient')
|
||||
def test_subnetpool_update(self, mock_neutronclient):
|
||||
@mock.patch.object(api.neutron, 'networkclient')
|
||||
def test_subnetpool_update(self, mock_networkclient):
|
||||
subnetpool_data = self.api_subnetpools.first()
|
||||
subnetpool_id = subnetpool_data['id']
|
||||
params = {'name': subnetpool_data['name'],
|
||||
'prefixes': subnetpool_data['prefixes']}
|
||||
|
||||
neutronclient = mock_neutronclient.return_value
|
||||
neutronclient.update_subnetpool.return_value = {'subnetpool':
|
||||
subnetpool_data}
|
||||
network_client = mock_networkclient.return_value
|
||||
mock_ret = sdk_subnet_pool.SubnetPool(**subnetpool_data)
|
||||
network_client.update_subnet_pool.return_value = mock_ret
|
||||
|
||||
ret_val = api.neutron.subnetpool_update(self.request, subnetpool_id,
|
||||
**params)
|
||||
|
||||
self.assertIsInstance(ret_val, api.neutron.SubnetPool)
|
||||
neutronclient.update_subnetpool.assert_called_once_with(
|
||||
subnetpool_id, body={'subnetpool': params})
|
||||
network_client.update_subnet_pool.assert_called_once_with(
|
||||
subnetpool_id, **params)
|
||||
|
||||
@mock.patch.object(api.neutron, 'neutronclient')
|
||||
def test_subnetpool_delete(self, mock_neutronclient):
|
||||
@mock.patch.object(api.neutron, 'networkclient')
|
||||
def test_subnetpool_delete(self, mock_networkclient):
|
||||
subnetpool_id = self.api_subnetpools.first()['id']
|
||||
|
||||
neutronclient = mock_neutronclient.return_value
|
||||
neutronclient.delete_subnetpool.return_value = None
|
||||
network_client = mock_networkclient.return_value
|
||||
network_client.delete_subnet_pool.return_value = None
|
||||
|
||||
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')
|
||||
def test_port_list(self, mock_networkclient):
|
||||
|
Loading…
Reference in New Issue
Block a user