From 16250e932c27c089693ab48ec3a0b782104e7a57 Mon Sep 17 00:00:00 2001 From: Pengfei Ni Date: Thu, 8 Oct 2015 18:56:44 +0800 Subject: [PATCH] Add device_owner while creating neutron port. 1. Set device_id to endpoint id 2. Set device_owner to kuryr:container Change-Id: Ib080ee59f6428732f341167088a99f726ef74891 Closes-Bug: 1504001 Signed-off-by: Pengfei Ni --- kuryr/common/constants.py | 2 ++ kuryr/controllers.py | 3 ++- kuryr/tests/test_kuryr.py | 12 +++++++++--- kuryr/tests/test_kuryr_endpoint.py | 11 ++++++++--- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/kuryr/common/constants.py b/kuryr/common/constants.py index a81d216b..11efe135 100644 --- a/kuryr/common/constants.py +++ b/kuryr/common/constants.py @@ -49,3 +49,5 @@ SCHEMA = { }, "SUCCESS": {} } + +DEVICE_OWNER = 'kuryr:container' diff --git a/kuryr/controllers.py b/kuryr/controllers.py index c00d0f1c..2b5b716f 100644 --- a/kuryr/controllers.py +++ b/kuryr/controllers.py @@ -24,7 +24,6 @@ from kuryr.common import exceptions from kuryr import schemata from kuryr import utils - cfg.CONF.import_group('neutron_client', 'kuryr.common.config') cfg.CONF.import_group('keystone_client', 'kuryr.common.config') @@ -233,6 +232,8 @@ def _create_subnets_and_or_port(interface, neutron_network_id, endpoint_id): 'name': '-'.join([endpoint_id, 'port']), 'admin_state_up': True, 'network_id': neutron_network_id, + 'device_owner': constants.DEVICE_OWNER, + 'device_id': endpoint_id, } if interface_mac: port['mac_address'] = interface_mac diff --git a/kuryr/tests/test_kuryr.py b/kuryr/tests/test_kuryr.py index 93d7be0e..bb3e179f 100644 --- a/kuryr/tests/test_kuryr.py +++ b/kuryr/tests/test_kuryr.py @@ -42,9 +42,9 @@ class TestKuryr(base.TestKuryrBase): - POST /NetworkDriver.Leave """ @ddt.data(('/Plugin.Activate', constants.SCHEMA['PLUGIN_ACTIVATE']), - ('/NetworkDriver.EndpointOperInfo', - constants.SCHEMA['ENDPOINT_OPER_INFO']), - ('/NetworkDriver.Leave', constants.SCHEMA['SUCCESS'])) + ('/NetworkDriver.EndpointOperInfo', + constants.SCHEMA['ENDPOINT_OPER_INFO']), + ('/NetworkDriver.Leave', constants.SCHEMA['SUCCESS'])) @ddt.unpack def test_remote_driver_endpoint(self, endpoint, expected): response = self.app.post(endpoint) @@ -165,6 +165,8 @@ class TestKuryr(base.TestKuryrBase): 'admin_state_up': True, 'mac_address': fake_mac_address, 'network_id': fake_neutron_network_id, + 'device_owner': constants.DEVICE_OWNER, + 'device_id': docker_endpoint_id, 'fixed_ips': [{'subnet_id': subnet_v4_id}] } } @@ -270,6 +272,8 @@ class TestKuryr(base.TestKuryrBase): 'admin_state_up': True, 'mac_address': fake_mac_address, 'network_id': fake_neutron_network_id, + 'device_owner': constants.DEVICE_OWNER, + 'device_id': docker_endpoint_id, 'fixed_ips': [ {'subnet_id': subnet_v4_id}, {'subnet_id': subnet_v6_id}, @@ -374,6 +378,8 @@ class TestKuryr(base.TestKuryrBase): 'port': { 'name': '-'.join([docker_endpoint_id, 'port']), 'admin_state_up': True, + 'device_owner': constants.DEVICE_OWNER, + 'device_id': docker_endpoint_id, 'mac_address': "fa:16:3e:20:57:c3", 'network_id': fake_neutron_network_id, 'fixed_ips': [{ diff --git a/kuryr/tests/test_kuryr_endpoint.py b/kuryr/tests/test_kuryr_endpoint.py index 1a6d6773..6c9a41aa 100644 --- a/kuryr/tests/test_kuryr_endpoint.py +++ b/kuryr/tests/test_kuryr_endpoint.py @@ -85,6 +85,8 @@ class TestKuryrEndpointFailures(base.TestKuryrFailures): 'port': { 'name': '-'.join([docker_endpoint_id, 'port']), 'admin_state_up': True, + 'device_owner': constants.DEVICE_OWNER, + 'device_id': docker_endpoint_id, 'fixed_ips': [{ 'subnet_id': neutron_subnetv4_id, 'ip_address': '192.168.1.2' @@ -106,7 +108,8 @@ class TestKuryrEndpointFailures(base.TestKuryrFailures): "admin_state_up": True, "network_id": neutron_network_id, "tenant_id": "d6700c0c9ffa4f1cb322cd4a1f3906fa", - "device_owner": "", + "device_owner": constants.DEVICE_OWNER, + 'device_id': docker_endpoint_id, "mac_address": "fa:16:3e:20:57:c3", 'fixed_ips': [{ 'subnet_id': neutron_subnetv4_id, @@ -209,8 +212,10 @@ class TestKuryrEndpointCreateFailures(TestKuryrEndpointFailures): fake_neutron_subnet_v6_id) = self._create_subnet_with_exception( fake_neutron_network_id, fake_docker_endpoint_id, None) self._create_port_with_exception(fake_neutron_network_id, - fake_docker_endpoint_id, fake_neutron_subnet_v4_id, - fake_neutron_subnet_v6_id, GivenException()) + fake_docker_endpoint_id, + fake_neutron_subnet_v4_id, + fake_neutron_subnet_v6_id, + GivenException()) self._mock_out_network(fake_neutron_network_id, fake_docker_network_id) # The port creation is failed and Kuryr rolles the created subnet back.