Fix wrong use of list of dict in _check_driver_to_bind
From [1], the segments_to_bind should be a list of dict, so the "level.segment_id in segments_to_bind" will never work. This patch extracts a set of segment ids and uses the set in the if condition. [1] https://goo.gl/yKYSTA Change-Id: I58f1d128e6cd79546d84f7d5bfcb026affc4fc5e Closes-bug: #1524356
This commit is contained in:
parent
4c65e2ff1e
commit
9db81351ed
|
@ -764,9 +764,11 @@ class MechanismManager(stevedore.named.NamedExtensionManager):
|
|||
# level to one of the segments we are currently trying to
|
||||
# bind. Note that it is OK for the same driver to bind at
|
||||
# multiple levels using different segments.
|
||||
segment_ids_to_bind = {s[api.SEGMENTATION_ID]
|
||||
for s in segments_to_bind}
|
||||
for level in binding_levels:
|
||||
if (level.driver == driver and
|
||||
level.segment_id in segments_to_bind):
|
||||
level.segment_id in segment_ids_to_bind):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
# Copyright (c) 2016 IBM Corp.
|
||||
#
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# 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 mock
|
||||
|
||||
from neutron.plugins.ml2 import driver_api as api
|
||||
from neutron.plugins.ml2 import managers
|
||||
from neutron.tests import base
|
||||
|
||||
|
||||
class TestManagers(base.BaseTestCase):
|
||||
|
||||
def test__check_driver_to_bind(self):
|
||||
manager = managers.MechanismManager()
|
||||
bindinglevel = mock.Mock()
|
||||
bindinglevel.driver = 'fake_driver'
|
||||
bindinglevel.segment_id = 'fake_seg_id'
|
||||
binding_levels = [bindinglevel]
|
||||
segments_to_bind = [{api.SEGMENTATION_ID: 'fake_seg_id'}]
|
||||
self.assertFalse(manager._check_driver_to_bind(
|
||||
'fake_driver', segments_to_bind, binding_levels))
|
||||
|
||||
bindinglevel.segment_id = 'fake_seg_id1'
|
||||
self.assertTrue(manager._check_driver_to_bind(
|
||||
'fake_driver', segments_to_bind, binding_levels))
|
Loading…
Reference in New Issue