Merge "Support detach neutron port from container"

This commit is contained in:
Zuul 2018-06-13 03:24:37 +00:00 committed by Gerrit Code Review
commit 910396e000
7 changed files with 61 additions and 9 deletions

View File

@ -941,10 +941,14 @@ Response Codes
- 403 - 403
- 404 - 404
Request
-------
.. rest_parameters:: parameters.yaml .. rest_parameters:: parameters.yaml
- container_ident: container_ident - container_ident: container_ident
- network: network - network: network-query
- port: port-query
Response Response
-------- --------
@ -1023,6 +1027,9 @@ Response Codes
- 403 - 403
- 404 - 404
Request
-------
.. rest_parameters:: parameters.yaml .. rest_parameters:: parameters.yaml
- container_ident: container_ident - container_ident: container_ident

View File

@ -1013,8 +1013,13 @@ class ContainersController(base.Controller):
context = pecan.request.context context = pecan.request.context
compute_api = pecan.request.compute_api compute_api = pecan.request.compute_api
neutron_api = neutron.NeutronAPI(context) neutron_api = neutron.NeutronAPI(context)
neutron_net = neutron_api.get_neutron_network(kwargs.get('network')) if kwargs.get('port'):
compute_api.network_detach(context, container, neutron_net['id']) port = neutron_api.get_neutron_port(kwargs['port'])
net_id = port['network_id']
else:
network = neutron_api.get_neutron_network(kwargs.get('network'))
net_id = network['id']
compute_api.network_detach(context, container, net_id)
pecan.response.status = 202 pecan.response.status = 202
@base.Controller.api_version("1.8") @base.Controller.api_version("1.8")

View File

@ -177,10 +177,24 @@ network_detach = {
'type': 'object', 'type': 'object',
'properties': { 'properties': {
'network': { 'network': {
'type': 'string' 'type': 'string',
'minLength': 1,
'maxLength': 255,
},
'port': {
'type': 'string',
'minLength': 1,
'maxLength': 255,
} }
}, },
'required': ['network'], 'oneOf': [
{
'required': ['network']
},
{
'required': ['port']
}
],
'additionalProperties': False 'additionalProperties': False
} }

View File

@ -49,10 +49,11 @@ REST_API_VERSION_HISTORY = """REST API Version History:
* 1.14 - Add support to rename the container from update api * 1.14 - Add support to rename the container from update api
* 1.15 - Remove add_security_group and remove_security_group * 1.15 - Remove add_security_group and remove_security_group
* 1.16 - Modify restart_policy to capsule spec content * 1.16 - Modify restart_policy to capsule spec content
* 1.17 - Add support for detaching ports
""" """
BASE_VER = '1.1' BASE_VER = '1.1'
CURRENT_MAX_VER = '1.16' CURRENT_MAX_VER = '1.17'
class Version(object): class Version(object):

View File

@ -134,3 +134,9 @@ user documentation.
---- ----
Modify restart_policy to capsule spec content to align with Kubernetes. Modify restart_policy to capsule spec content to align with Kubernetes.
1.17
----
Add parameter ``port`` to the network_detach API. This allow users to
detach a container from a neutron port.

View File

@ -28,7 +28,7 @@ class TestRootController(api_base.FunctionalTest):
'default_version': 'default_version':
{'id': 'v1', {'id': 'v1',
'links': [{'href': 'http://localhost/v1/', 'rel': 'self'}], 'links': [{'href': 'http://localhost/v1/', 'rel': 'self'}],
'max_version': '1.16', 'max_version': '1.17',
'min_version': '1.1', 'min_version': '1.1',
'status': 'CURRENT'}, 'status': 'CURRENT'},
'description': 'Zun is an OpenStack project which ' 'description': 'Zun is an OpenStack project which '
@ -37,7 +37,7 @@ class TestRootController(api_base.FunctionalTest):
'versions': [{'id': 'v1', 'versions': [{'id': 'v1',
'links': [{'href': 'http://localhost/v1/', 'links': [{'href': 'http://localhost/v1/',
'rel': 'self'}], 'rel': 'self'}],
'max_version': '1.16', 'max_version': '1.17',
'min_version': '1.1', 'min_version': '1.1',
'status': 'CURRENT'}]} 'status': 'CURRENT'}]}

View File

@ -1902,7 +1902,26 @@ class TestContainerController(api_base.FunctionalTest):
response = self.post(url) response = self.post(url)
self.assertEqual(202, response.status_int) self.assertEqual(202, response.status_int)
mock_detach.assert_called_once_with(mock.ANY, test_container_obj, mock_detach.assert_called_once_with(mock.ANY, test_container_obj,
mock.ANY) 'private')
@patch('zun.network.neutron.NeutronAPI.get_neutron_port')
@patch('zun.compute.api.API.network_detach')
@patch('zun.objects.Container.get_by_uuid')
def test_network_detach_with_port(self, mock_by_uuid, mock_detach,
mock_get_port):
test_container = utils.get_test_container()
test_container_obj = objects.Container(self.context, **test_container)
mock_by_uuid.return_value = test_container_obj
container_uuid = test_container.get('uuid')
mock_get_port.return_value = {'network_id': 'fake-net-id'}
mock_detach.return_value = None
url = '/v1/containers/%s/%s?port=%s' % (container_uuid,
'network_detach',
'fake-port')
response = self.post(url)
self.assertEqual(202, response.status_int)
mock_detach.assert_called_once_with(mock.ANY, test_container_obj,
'fake-net-id')
@patch('zun.objects.Container.get_by_uuid') @patch('zun.objects.Container.get_by_uuid')
def test_network_list(self, mock_container_get_by_uuid): def test_network_list(self, mock_container_get_by_uuid):