[OVS] Shut down the port on changing the admin-state to false

On changing the port-admin-state to false, the port goes down.

Change-Id: Ica46e39d8858f4235a8a1b9caeb696346a86f38b
Closes-bug: #1672629
This commit is contained in:
OmarM 2017-12-03 09:42:50 -05:00 committed by Omar Muhtaseb
parent 639b83264c
commit ce01b70ef8
4 changed files with 140 additions and 0 deletions

View File

@ -1433,6 +1433,9 @@ class OVSNeutronAgent(l2population_rpc.L2populationRpcCallBackTunnelMixin,
"putting on the dead VLAN", vif_port.vif_id)
self.port_dead(vif_port)
self.plugin_rpc.update_device_down(
self.context, port_id, self.agent_id,
self.conf.host)
port_needs_binding = False
else:
LOG.debug("No VIF port for port %s defined on agent.", port_id)

View File

@ -123,6 +123,9 @@ class ClientFixture(fixtures.Fixture):
spec['security_groups'] = security_groups
return self._create_resource('port', spec)
def update_port(self, port_id, **kwargs):
return self._update_resource('port', port_id, kwargs)
def create_floatingip(self, tenant_id, floating_network_id,
fixed_ip_address, port_id):
spec = {

View File

@ -0,0 +1,105 @@
# Copyright 2017 - Nokia
#
# 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.
import functools
from neutron.common import utils
from neutron.tests.fullstack import base
from neutron.tests.fullstack.resources import environment
from neutron.tests.unit import testlib_api
from neutron_lib import constants
from oslo_utils import uuidutils
load_tests = testlib_api.module_load_tests
class PortShutDownTest(base.BaseFullStackTestCase):
# This is a test to confirm the port status
# on shutting down the port administratively.
# The port status should no longer be ACTIVE
# and go to DOWN
use_dhcp = True
l2_pop = False
arp_responder = False
num_hosts = 1
scenarios = [
(constants.AGENT_TYPE_LINUXBRIDGE,
{'l2_agent_type': constants.AGENT_TYPE_LINUXBRIDGE}),
(constants.AGENT_TYPE_OVS,
{'l2_agent_type': constants.AGENT_TYPE_OVS})
]
def setUp(self):
host_descriptions = [
environment.HostDescription(
l2_agent_type=self.l2_agent_type,
dhcp_agent=self.use_dhcp,
)
for _ in range(self.num_hosts)]
env = environment.Environment(
environment.EnvironmentDescription(
l2_pop=self.l2_pop,
arp_responder=self.arp_responder),
host_descriptions)
super(PortShutDownTest, self).setUp(env)
def _create_external_network_and_subnet(self, tenant_id):
# This test is not exclusive for the external networks.
# It is only used here to implicitly create a dhcp port
# on the network creation.
network = self.safe_client.create_network(
tenant_id, name='test-public', external=True, network_type='local')
self.safe_client.create_subnet(tenant_id, network['id'],
'240.0.0.0/8', gateway_ip='240.0.0.2')
return network
def _get_network_dhcp_ports(self, network_id):
return self.client.list_ports(network_id=network_id,
device_owner=constants.DEVICE_OWNER_DHCP)['ports']
def _is_port_active(self, port_id):
port = self.client.show_port(port_id)['port']
return port['status'] == constants.PORT_STATUS_ACTIVE
def _is_port_down(self, port_id):
port = self.client.show_port(port_id)['port']
return port['status'] == constants.PORT_STATUS_DOWN
def test_port_shut_down(self):
tenant_id = uuidutils.generate_uuid()
# Create an external network
network = self._create_external_network_and_subnet(tenant_id)
# Check if the DHCP port is created
port_created = functools.partial(self._get_network_dhcp_ports,
network['id'])
utils.wait_until_true(port_created)
# Get the DHCP port
port = self._get_network_dhcp_ports(network['id'])[0]
# Wait till the changes are reflected to DB
port_status_active_predicate = functools.partial(
self._is_port_active, port['id'])
utils.wait_until_true(port_status_active_predicate)
# Shut down the port
self.safe_client.update_port(port['id'], admin_state_up=False)
port_status_down_predicate = functools.partial(
self._is_port_down, port['id'])
utils.wait_until_true(port_status_down_predicate)

View File

@ -968,6 +968,35 @@ class TestOvsNeutronAgent(object):
self.agent.treat_devices_removed([port_id])
delete.assert_called_with(mock.ANY, {'port_id': port_id})
def test_treat_vif_port_shut_down_port(self):
details = mock.MagicMock()
vif_port = type('vif_port', (object,), {
"vif_id": "12",
"iface-id": "407a79e0-e0be-4b7d-92a6-513b2161011b",
"vif_mac": "fa:16:3e:68:46:7b",
"port_name": "qr-407a79e0-e0",
"ofport": -1,
"bridge_name": "br-int"})
with mock.patch.object(
self.agent.plugin_rpc, 'update_device_down'
) as update_device_down, mock.patch.object(
self.agent, "port_dead"
) as port_dead:
port_needs_binding = self.agent.treat_vif_port(
vif_port, details['port_id'],
details['network_id'],
details['network_type'],
details['physical_network'],
details['segmentation_id'],
False,
details['fixed_ips'],
details['device_owner'], False)
self.assertFalse(port_needs_binding)
port_dead.assert_called_once_with(vif_port)
update_device_down.assert_called_once_with(
self.agent.context, details['port_id'], self.agent.agent_id,
self.agent.conf.host)
def test_bind_port_with_missing_network(self):
vif_port = mock.Mock()
vif_port.name.return_value = 'port'