Implement get endpoint operational info
Return endpoint operational info to libnetwork, return value is from Neutron port's status. Closes-Bug: #1620883 Change-Id: Ib5569cfdaa0c5934e2d24e21c27ca4164b8b8d03
This commit is contained in:
parent
70f9f46bff
commit
76e994e4de
|
@ -13,8 +13,6 @@
|
|||
|
||||
SCHEMA = {
|
||||
"PLUGIN_ACTIVATE": {"Implements": ["NetworkDriver", "IpamDriver"]},
|
||||
# TODO(tfukushima): This is mocked and should be replaced with real data.
|
||||
"ENDPOINT_OPER_INFO": {"Value": {}},
|
||||
"SUCCESS": {}
|
||||
}
|
||||
|
||||
|
|
|
@ -193,6 +193,15 @@ def _get_neutron_port_from_docker_endpoint(endpoint_id):
|
|||
return filtered_ports['ports'][0]['id']
|
||||
|
||||
|
||||
def _get_neutron_port_status_from_docker_endpoint(endpoint_id):
|
||||
response_port_status = {}
|
||||
port_name = utils.get_neutron_port_name(endpoint_id)
|
||||
filtered_ports = _get_ports_by_attrs(name=port_name)
|
||||
if filtered_ports:
|
||||
response_port_status['status'] = filtered_ports[0]['status']
|
||||
return response_port_status
|
||||
|
||||
|
||||
def _process_interface_address(port_dict, subnets_dict_by_id,
|
||||
response_interface):
|
||||
assigned_address = port_dict['ip_address']
|
||||
|
@ -853,8 +862,30 @@ def network_driver_create_endpoint():
|
|||
|
||||
@app.route('/NetworkDriver.EndpointOperInfo', methods=['POST'])
|
||||
def network_driver_endpoint_operational_info():
|
||||
app.logger.debug("Received /NetworkDriver.EndpointOperInfo")
|
||||
return flask.jsonify(const.SCHEMA['ENDPOINT_OPER_INFO'])
|
||||
"""Return Neutron Port status with the given EndpointID.
|
||||
|
||||
This function takes the following JSON data and delegates the actual
|
||||
endpoint query to the Neutron client mapping it into Port status. ::
|
||||
|
||||
{
|
||||
"NetworkID": string,
|
||||
"EndpointID": string
|
||||
}
|
||||
|
||||
See the following link for more details about the spec:
|
||||
|
||||
https://github.com/docker/libnetwork/blob/master/docs/remote.md#endpoint-operational-info # noqa
|
||||
"""
|
||||
json_data = flask.request.get_json(force=True)
|
||||
app.logger.debug("Received JSON data %s for "
|
||||
"/NetworkDriver.EndpointOperInfo", json_data)
|
||||
jsonschema.validate(json_data, schemata.ENDPOINT_INFO_SCHEMA)
|
||||
|
||||
endpoint_id = json_data['EndpointID']
|
||||
response_port_status = (
|
||||
_get_neutron_port_status_from_docker_endpoint(endpoint_id))
|
||||
|
||||
return flask.jsonify({'Value': response_port_status})
|
||||
|
||||
|
||||
@app.route('/NetworkDriver.DeleteEndpoint', methods=['POST'])
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
|
||||
from kuryr_libnetwork.schemata import endpoint_create
|
||||
from kuryr_libnetwork.schemata import endpoint_delete
|
||||
from kuryr_libnetwork.schemata import endpoint_info
|
||||
from kuryr_libnetwork.schemata import join
|
||||
from kuryr_libnetwork.schemata import leave
|
||||
from kuryr_libnetwork.schemata import network_create
|
||||
|
@ -25,6 +26,7 @@ from kuryr_libnetwork.schemata import request_pool
|
|||
# Aliases for schemata in each module
|
||||
ENDPOINT_CREATE_SCHEMA = endpoint_create.ENDPOINT_CREATE_SCHEMA
|
||||
ENDPOINT_DELETE_SCHEMA = endpoint_delete.ENDPOINT_DELETE_SCHEMA
|
||||
ENDPOINT_INFO_SCHEMA = endpoint_info.ENDPOINT_INFO_SCHEMA
|
||||
JOIN_SCHEMA = join.JOIN_SCHEMA
|
||||
LEAVE_SCHEMA = leave.LEAVE_SCHEMA
|
||||
NETWORK_CREATE_SCHEMA = network_create.NETWORK_CREATE_SCHEMA
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from kuryr_libnetwork.schemata import commons
|
||||
|
||||
ENDPOINT_INFO_SCHEMA = {
|
||||
u'links': [{
|
||||
u'method': u'POST',
|
||||
u'href': u'/NetworkDriver.EndpointOperInfo',
|
||||
u'description': u'Show an Endpoint operational info',
|
||||
u'rel': u'self',
|
||||
u'title': u'Show'
|
||||
}],
|
||||
u'title': u'Show endpoint operational info',
|
||||
u'required': [u'NetworkID', u'EndpointID'],
|
||||
u'definitions': {u'commons': {}},
|
||||
u'$schema': u'http://json-schema.org/draft-04/hyper-schema',
|
||||
u'type': u'object',
|
||||
u'properties': {
|
||||
u'NetworkID': {
|
||||
u'description': u'Network ID',
|
||||
u'$ref': u'#/definitions/commons/definitions/id'
|
||||
},
|
||||
u'EndpointID': {
|
||||
u'description': u'Endpoint ID',
|
||||
u'$ref': u'#/definitions/commons/definitions/id'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ENDPOINT_INFO_SCHEMA[u'definitions'][u'commons'] = commons.COMMONS
|
|
@ -10,6 +10,7 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import mock
|
||||
import uuid
|
||||
|
||||
import ddt
|
||||
|
@ -48,9 +49,7 @@ class TestKuryr(base.TestKuryrBase):
|
|||
('/NetworkDriver.GetCapabilities',
|
||||
{'Scope': config.CONF.capability_scope}),
|
||||
('/NetworkDriver.DiscoverNew', constants.SCHEMA['SUCCESS']),
|
||||
('/NetworkDriver.DiscoverDelete', constants.SCHEMA['SUCCESS']),
|
||||
('/NetworkDriver.EndpointOperInfo',
|
||||
constants.SCHEMA['ENDPOINT_OPER_INFO']))
|
||||
('/NetworkDriver.DiscoverDelete', constants.SCHEMA['SUCCESS']))
|
||||
@ddt.unpack
|
||||
def test_remote_driver_endpoint(self, endpoint, expected):
|
||||
response = self.app.post(endpoint)
|
||||
|
@ -743,6 +742,63 @@ class TestKuryr(base.TestKuryrBase):
|
|||
expected = {'Interface': {}}
|
||||
self.assertEqual(expected, decoded_json)
|
||||
|
||||
def test_network_driver_endpoint_operational_info_with_no_port(self):
|
||||
docker_network_id = lib_utils.get_hash()
|
||||
docker_endpoint_id = lib_utils.get_hash()
|
||||
fake_port_response = {"ports": []}
|
||||
|
||||
with mock.patch.object(app.neutron, 'list_ports') as mock_list_ports:
|
||||
data = {
|
||||
'NetworkID': docker_network_id,
|
||||
'EndpointID': docker_endpoint_id,
|
||||
}
|
||||
|
||||
mock_list_ports.return_value = fake_port_response
|
||||
response = self.app.post('/NetworkDriver.EndpointOperInfo',
|
||||
content_type='application/json',
|
||||
data=jsonutils.dumps(data))
|
||||
decoded_json = jsonutils.loads(response.data)
|
||||
self.assertEqual(200, response.status_code)
|
||||
|
||||
port_name = utils.get_neutron_port_name(docker_endpoint_id)
|
||||
mock_list_ports.assert_called_once_with(name=port_name)
|
||||
|
||||
self.assertEqual({}, decoded_json['Value'])
|
||||
|
||||
def test_network_driver_endpoint_operational_info(self):
|
||||
docker_network_id = lib_utils.get_hash()
|
||||
docker_endpoint_id = lib_utils.get_hash()
|
||||
fake_neutron_net_id = str(uuid.uuid4())
|
||||
fake_port_id = str(uuid.uuid4())
|
||||
fake_port = self._get_fake_port(
|
||||
docker_endpoint_id, fake_neutron_net_id,
|
||||
fake_port_id, constants.PORT_STATUS_ACTIVE)
|
||||
|
||||
fake_port_response = {
|
||||
"ports": [
|
||||
fake_port['port']
|
||||
]
|
||||
}
|
||||
|
||||
with mock.patch.object(app.neutron, 'list_ports') as mock_list_ports:
|
||||
data = {
|
||||
'NetworkID': docker_network_id,
|
||||
'EndpointID': docker_endpoint_id,
|
||||
}
|
||||
|
||||
mock_list_ports.return_value = fake_port_response
|
||||
response = self.app.post('/NetworkDriver.EndpointOperInfo',
|
||||
content_type='application/json',
|
||||
data=jsonutils.dumps(data))
|
||||
decoded_json = jsonutils.loads(response.data)
|
||||
self.assertEqual(200, response.status_code)
|
||||
|
||||
port_name = utils.get_neutron_port_name(docker_endpoint_id)
|
||||
mock_list_ports.assert_called_once_with(name=port_name)
|
||||
|
||||
self.assertEqual(fake_port_response['ports'][0]['status'],
|
||||
decoded_json['Value']['status'])
|
||||
|
||||
def test_network_driver_delete_endpoint(self):
|
||||
docker_network_id = lib_utils.get_hash()
|
||||
docker_endpoint_id = lib_utils.get_hash()
|
||||
|
|
Loading…
Reference in New Issue