Skip to content

Commit 9949a2b

Browse files
authored
Merge pull request #911 from kush1093/ocata-dev-lbaasv2-driver-issue
Ocata Development LBaaSv2 driver issue with ML2 portbinding extension
2 parents eb8ab86 + a18c63a commit 9949a2b

2 files changed

Lines changed: 105 additions & 7 deletions

File tree

f5lbaasdriver/v2/bigip/plugin_rpc.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -540,10 +540,6 @@ def create_port_on_subnet(self, context, subnet_id=None,
540540
port_data[portbindings.VNIC_TYPE] = vnic_type
541541
port_data[portbindings.PROFILE] = binding_profile
542542

543-
if ('binding:capabilities' in
544-
portbindings.EXTENDED_ATTRIBUTES_2_0['ports']):
545-
port_data['binding:capabilities'] = {
546-
'port_filter': False}
547543
port = self.driver.plugin.db._core_plugin.create_port(
548544
context, {'port': port_data})
549545
# Because ML2 marks ports DOWN by default on creation
@@ -704,9 +700,6 @@ def create_port_on_network(self, context, network_id=None,
704700
port_data[portbindings.VNIC_TYPE] = vnic_type
705701
port_data[portbindings.PROFILE] = binding_profile
706702

707-
extended_attrs = portbindings.EXTENDED_ATTRIBUTES_2_0['ports']
708-
if 'binding:capabilities' in extended_attrs:
709-
port_data['binding:capabilities'] = {'port_filter': False}
710703
port = self.driver.plugin.db._core_plugin.create_port(
711704
context, {'port': port_data})
712705
# Because ML2 marks ports DOWN by default on creation
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# Copyright 2016 F5 Networks Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import mock
16+
import pytest
17+
18+
import neutron.api.v2.attributes
19+
from neutron_lib import constants as neutron_const
20+
21+
import f5lbaasdriver.v2.bigip.plugin_rpc
22+
23+
24+
@pytest.fixture
25+
@mock.patch("f5lbaasdriver.v2.bigip.plugin_rpc.LBaaSv2PluginCallbacksRPC."
26+
"__init__")
27+
def fully_mocked_target(init):
28+
init.return_value = None
29+
target = f5lbaasdriver.v2.bigip.plugin_rpc.LBaaSv2PluginCallbacksRPC()
30+
return target
31+
32+
33+
@pytest.fixture
34+
def neutron_attributes(request):
35+
hold_attributes = neutron.api.v2.attributes
36+
37+
def finalizer():
38+
neutron.api.v2.attributes = hold_attributes
39+
request.addfinalizer(finalizer)
40+
neutron.api.v2.attributes = mock.Mock()
41+
return neutron.api.v2.attributes
42+
43+
44+
@pytest.fixture
45+
def neutron_extensions(request):
46+
hold_extensions = neutron.extensions
47+
48+
def finalizer():
49+
neutron.extensions = hold_extensions
50+
request.addfinalizer(finalizer)
51+
neutron.extensions = mock.Mock()
52+
return neutron.extensions
53+
54+
55+
def test_create_port_on_subnet(fully_mocked_target, neutron_attributes,
56+
neutron_extensions):
57+
portbindings = neutron_extensions.portbindings
58+
target = fully_mocked_target
59+
context = mock.Mock()
60+
# fake data manipulations....
61+
# args...
62+
fake_args = ['subnet_id', 'mac_address', 'name', 'host', 'device_id',
63+
'vnic_type', 'binding_profile']
64+
portbindings_attrs = ['VNIC_NORMAL', 'HOST_ID', 'VNIC_TYPE', 'PROFILE']
65+
fake_args = {x: x for x in fake_args}
66+
fake_args['binding_profile'] = {}
67+
# port bindings...
68+
for attr in portbindings_attrs:
69+
setattr(portbindings, attr, attr)
70+
fake_args['vnic_type'] = portbindings.VNIC_NORMAL
71+
# fake validation data...
72+
subnet = {'id': 'subnet_id', 'tenant_id': 'tenant_id',
73+
'network_id': 'network_id'}
74+
port = {'id': 'id'}
75+
device_ips = [{'subnet_id': subnet['id']}]
76+
port_data = {
77+
'tenant_id': subnet['tenant_id'],
78+
'name': fake_args['name'],
79+
'network_id': subnet['network_id'],
80+
'mac_address': fake_args['mac_address'],
81+
'admin_state_up': True,
82+
'device_owner': 'network:f5lbaasv2',
83+
'status': neutron_const.PORT_STATUS_ACTIVE,
84+
'fixed_ips': device_ips,
85+
'device_id': fake_args['device_id'],
86+
'binding:host_id': fake_args['host'],
87+
'binding:vnic_type': portbindings.VNIC_NORMAL,
88+
'binding:profile': {}}
89+
update_data = {'status': neutron_const.PORT_STATUS_ACTIVE}
90+
expected_create_port_args = (context, {'port': port_data})
91+
expected_update_port_args = \
92+
(context, port['id'], {'port': update_data})
93+
# attach our mock interactions...
94+
target.driver = mock.Mock()
95+
target.driver.plugin.db._core_plugin.get_subnet.return_value = subnet
96+
target.driver.plugin.db._core_plugin.create_port.return_value = port
97+
# test...
98+
assert port == target.create_port_on_subnet(context, **fake_args)
99+
# validate...
100+
assert target.driver.plugin.db._core_plugin.get_subnet.call_count
101+
assert target.driver.plugin.db._core_plugin.create_port.call_count
102+
assert target.driver.plugin.db._core_plugin.create_port.\
103+
call_args_list[0][0] == expected_create_port_args
104+
assert target.driver.plugin.db._core_plugin.update_port.\
105+
call_args_list[0][0] == expected_update_port_args

0 commit comments

Comments
 (0)