| 1 |
# Copyright (c) 2015 OpenStack Foundation |
| 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 |
| 12 |
# implied. |
| 13 |
# See the License for the specific language governing permissions and |
| 14 |
# limitations under the License. |
| 15 |
|
| 16 |
from unittest import mock |
| 17 |
|
| 18 |
from neutron import manager |
| 19 |
from neutron.plugins.ml2 import managers |
| 20 |
from neutron.tests import base |
| 21 |
|
| 22 |
from neutron_lib import context |
| 23 |
from neutron_lib.plugins import directory |
| 24 |
|
| 25 |
from networking_l2gw.db.l2gateway import l2gateway_db |
| 26 |
from networking_l2gw.db.l2gateway.ovsdb import lib |
| 27 |
from networking_l2gw.services.l2gateway.common import constants as n_const |
| 28 |
from networking_l2gw.services.l2gateway.common import ovsdb_schema |
| 29 |
from networking_l2gw.services.l2gateway.common import tunnel_calls |
| 30 |
from networking_l2gw.services.l2gateway.ovsdb import data |
| 31 |
from networking_l2gw.services.l2gateway.service_drivers import agent_api |
| 32 |
|
| 33 |
|
| 34 |
class TestL2GatewayOVSDBCallbacks: |
| 35 |
|
| 36 |
def setUp(self): |
| 37 |
super().setUp() |
| 38 |
self.context = context.get_admin_context() |
| 39 |
|
| 40 |
def test_update_ovsdb_changes(self): |
| 41 |
fake_activity = 1 |
| 42 |
fake_ovsdb_data = {n_const.OVSDB_IDENTIFIER: 'fake_id'} |
| 43 |
with mock.patch.object(data, 'OVSDBData') as ovs_data: |
| 44 |
self.l2gw_callbacks.update_ovsdb_changes(self.context, |
| 45 |
fake_activity, |
| 46 |
fake_ovsdb_data) |
| 47 |
ovsdb_return_value = ovs_data.return_value |
| 48 |
ovsdb_return_value.update_ovsdb_changes.assert_called_with( |
| 49 |
self.context, fake_activity, fake_ovsdb_data) |
| 50 |
|
| 51 |
def test_notify_ovsdb_states(self): |
| 52 |
fake_ovsdb_states = {'ovsdb1': 'connected'} |
| 53 |
with mock.patch.object(data, 'OVSDBData') as ovs_data: |
| 54 |
self.l2gw_callbacks.notify_ovsdb_states(self.context, |
| 55 |
fake_ovsdb_states) |
| 56 |
ovsdb_return_value = ovs_data.return_value |
| 57 |
ovsdb_return_value.notify_ovsdb_states.assert_called_with( |
| 58 |
self.context, fake_ovsdb_states) |
| 59 |
|
| 60 |
def test_get_ovsdbdata_object(self): |
| 61 |
fake_ovsdb_id = 'fake_ovsdb_id' |
| 62 |
with mock.patch.object(data, 'OVSDBData') as ovs_data: |
| 63 |
ret_value = self.l2gw_callbacks.get_ovsdbdata_object( |
| 64 |
fake_ovsdb_id) |
| 65 |
ret_value1 = ovs_data.assert_called_with(fake_ovsdb_id) |
| 66 |
self.assertEqual(ret_value, ret_value1) |
| 67 |
|
| 68 |
|
| 69 |
class TestOVSDBData(base.BaseTestCase): |
| 70 |
|
| 71 |
def setUp(self): |
| 72 |
super().setUp() |
| 73 |
self.context = context.get_admin_context() |
| 74 |
self.ovsdb_identifier = 'fake_ovsdb_id' |
| 75 |
mock.patch.object(directory, 'get_plugin').start() |
| 76 |
mock.patch.object(managers, 'TypeManager').start() |
| 77 |
self.ovsdb_data = data.OVSDBData(self.ovsdb_identifier) |
| 78 |
|
| 79 |
def test_init(self): |
| 80 |
with mock.patch.object(data.OVSDBData, |
| 81 |
'_setup_entry_table') as setup_entry_table: |
| 82 |
self.ovsdb_data.__init__(self.ovsdb_identifier) |
| 83 |
self.assertEqual('fake_ovsdb_id', |
| 84 |
self.ovsdb_data.ovsdb_identifier) |
| 85 |
self.assertTrue(setup_entry_table.called) |
| 86 |
|
| 87 |
def test_update_ovsdb_changes(self): |
| 88 |
fake_dict = {} |
| 89 |
fake_activity = 1 |
| 90 |
fake_remote_mac = {'uuid': '123456', |
| 91 |
'mac': 'mac123', |
| 92 |
'ovsdb_identifier': 'host1', |
| 93 |
'logical_switch_id': 'ls123'} |
| 94 |
fake_new_logical_switches = [fake_dict] |
| 95 |
fake_new_physical_port = [fake_dict] |
| 96 |
fake_new_physical_switches = [fake_dict] |
| 97 |
fake_new_physical_locators = [fake_dict] |
| 98 |
fake_new_local_macs = [fake_dict] |
| 99 |
fake_new_remote_macs = [fake_remote_mac] |
| 100 |
fake_modified_remote_macs = [fake_dict] |
| 101 |
fake_modified_physical_ports = [fake_dict] |
| 102 |
fake_modified_local_macs = [fake_dict] |
| 103 |
fake_deleted_logical_switches = [fake_dict] |
| 104 |
fake_deleted_physical_ports = [fake_dict] |
| 105 |
fake_deleted_physical_switches = [fake_dict] |
| 106 |
fake_deleted_physical_locators = [fake_dict] |
| 107 |
fake_deleted_local_macs = [fake_dict] |
| 108 |
fake_deleted_remote_macs = [fake_dict] |
| 109 |
|
| 110 |
fake_ovsdb_data = { |
| 111 |
n_const.OVSDB_IDENTIFIER: 'fake_ovsdb_id', |
| 112 |
'new_logical_switches': fake_new_logical_switches, |
| 113 |
'new_physical_ports': fake_new_physical_port, |
| 114 |
'new_physical_switches': fake_new_physical_switches, |
| 115 |
'new_physical_locators': fake_new_physical_locators, |
| 116 |
'new_local_macs': fake_new_local_macs, |
| 117 |
'new_remote_macs': fake_new_remote_macs, |
| 118 |
'modified_remote_macs': fake_modified_remote_macs, |
| 119 |
'modified_physical_ports': fake_modified_physical_ports, |
| 120 |
'modified_local_macs': fake_modified_local_macs, |
| 121 |
'deleted_logical_switches': fake_deleted_logical_switches, |
| 122 |
'deleted_physical_switches': fake_deleted_physical_switches, |
| 123 |
'deleted_physical_ports': fake_deleted_physical_ports, |
| 124 |
'deleted_physical_locators': fake_deleted_physical_locators, |
| 125 |
'deleted_local_macs': fake_deleted_local_macs, |
| 126 |
'deleted_remote_macs': fake_deleted_remote_macs} |
| 127 |
with mock.patch.object( |
| 128 |
self.ovsdb_data, |
| 129 |
'_process_new_logical_switches' |
| 130 |
) as process_new_logical_switches, \ |
| 131 |
mock.patch.object( |
| 132 |
self.ovsdb_data, |
| 133 |
'_process_new_physical_ports' |
| 134 |
) as process_new_physical_ports, \ |
| 135 |
mock.patch.object( |
| 136 |
self.ovsdb_data, |
| 137 |
'_process_new_physical_switches' |
| 138 |
) as process_new_physical_switches, \ |
| 139 |
mock.patch.object( |
| 140 |
self.ovsdb_data, |
| 141 |
'_process_new_physical_locators' |
| 142 |
) as process_new_physical_locators, \ |
| 143 |
mock.patch.object( |
| 144 |
self.ovsdb_data, |
| 145 |
'_process_new_local_macs' |
| 146 |
) as process_new_local_macs, \ |
| 147 |
mock.patch.object( |
| 148 |
self.ovsdb_data, |
| 149 |
'_process_new_remote_macs' |
| 150 |
) as process_new_remote_macs, \ |
| 151 |
mock.patch.object( |
| 152 |
self.ovsdb_data, |
| 153 |
'_process_modified_remote_macs' |
| 154 |
) as process_modified_remote_macs, \ |
| 155 |
mock.patch.object( |
| 156 |
self.ovsdb_data, |
| 157 |
'_process_modified_physical_ports' |
| 158 |
) as process_modified_physical_ports, \ |
| 159 |
mock.patch.object( |
| 160 |
self.ovsdb_data, |
| 161 |
'_process_deleted_logical_switches' |
| 162 |
) as process_deleted_logical_switches, \ |
| 163 |
mock.patch.object( |
| 164 |
self.ovsdb_data, |
| 165 |
'_process_deleted_physical_switches' |
| 166 |
) as process_deleted_physical_switches, \ |
| 167 |
mock.patch.object( |
| 168 |
self.ovsdb_data, |
| 169 |
'_process_deleted_physical_ports' |
| 170 |
) as process_deleted_physical_ports, \ |
| 171 |
mock.patch.object( |
| 172 |
self.ovsdb_data, |
| 173 |
'_process_deleted_physical_locators' |
| 174 |
) as process_deleted_physical_locators, \ |
| 175 |
mock.patch.object( |
| 176 |
self.ovsdb_data, |
| 177 |
'_process_deleted_local_macs' |
| 178 |
) as process_deleted_local_macs, \ |
| 179 |
mock.patch.object( |
| 180 |
self.ovsdb_data, |
| 181 |
'_process_deleted_remote_macs' |
| 182 |
) as process_deleted_remote_macs, \ |
| 183 |
mock.patch.object( |
| 184 |
self.ovsdb_data, |
| 185 |
'_handle_l2pop') as mock_handle_l2pop: |
| 186 |
self.ovsdb_data.entry_table = { |
| 187 |
'new_logical_switches': process_new_logical_switches, |
| 188 |
'new_physical_ports': process_new_physical_ports, |
| 189 |
'new_physical_switches': process_new_physical_switches, |
| 190 |
'new_physical_locators': process_new_physical_locators, |
| 191 |
'new_local_macs': process_new_local_macs, |
| 192 |
'new_remote_macs': process_new_remote_macs, |
| 193 |
'modified_remote_macs': process_modified_remote_macs, |
| 194 |
'modified_physical_ports': process_modified_physical_ports, |
| 195 |
'deleted_logical_switches': process_deleted_logical_switches, |
| 196 |
'deleted_physical_switches': process_deleted_physical_switches, |
| 197 |
'deleted_physical_ports': process_deleted_physical_ports, |
| 198 |
'deleted_physical_locators': process_deleted_physical_locators, |
| 199 |
'deleted_local_macs': process_deleted_local_macs, |
| 200 |
'deleted_remote_macs': process_deleted_remote_macs} |
| 201 |
self.ovsdb_data.update_ovsdb_changes( |
| 202 |
self.context, fake_activity, fake_ovsdb_data) |
| 203 |
|
| 204 |
process_new_logical_switches.assert_called_with( |
| 205 |
self.context, fake_new_logical_switches) |
| 206 |
process_new_physical_ports.assert_called_with( |
| 207 |
self.context, fake_new_physical_port) |
| 208 |
process_new_physical_switches.assert_called_with( |
| 209 |
self.context, fake_new_physical_switches) |
| 210 |
process_new_physical_locators.assert_called_with( |
| 211 |
self.context, fake_new_physical_locators) |
| 212 |
process_new_local_macs.assert_called_with( |
| 213 |
self.context, fake_new_local_macs) |
| 214 |
process_new_remote_macs.assert_called_with( |
| 215 |
self.context, fake_new_remote_macs) |
| 216 |
process_modified_remote_macs.assert_called_with( |
| 217 |
self.context, fake_modified_remote_macs) |
| 218 |
process_modified_physical_ports.assert_called_with( |
| 219 |
self.context, fake_modified_physical_ports) |
| 220 |
process_deleted_logical_switches.assert_called_with( |
| 221 |
self.context, fake_deleted_logical_switches) |
| 222 |
process_deleted_physical_switches.assert_called_with( |
| 223 |
self.context, fake_deleted_physical_switches) |
| 224 |
process_deleted_physical_ports.assert_called_with( |
| 225 |
self.context, fake_deleted_physical_ports) |
| 226 |
process_deleted_physical_locators.assert_called_with( |
| 227 |
self.context, fake_deleted_physical_locators) |
| 228 |
process_deleted_local_macs.assert_called_with( |
| 229 |
self.context, fake_deleted_local_macs) |
| 230 |
process_deleted_remote_macs.assert_called_with( |
| 231 |
self.context, fake_deleted_remote_macs) |
| 232 |
self.assertTrue(mock_handle_l2pop.called) |
| 233 |
|
| 234 |
@mock.patch.object(lib, 'get_all_pending_remote_macs_in_asc_order') |
| 235 |
@mock.patch.object(lib, 'delete_pending_ucast_mac_remote') |
| 236 |
@mock.patch.object(ovsdb_schema, 'LogicalSwitch') |
| 237 |
@mock.patch.object(ovsdb_schema, 'PhysicalLocator') |
| 238 |
@mock.patch.object(ovsdb_schema, 'UcastMacsRemote') |
| 239 |
@mock.patch.object(agent_api.L2gatewayAgentApi, 'add_vif_to_gateway') |
| 240 |
@mock.patch.object(agent_api.L2gatewayAgentApi, 'update_vif_to_gateway') |
| 241 |
@mock.patch.object(agent_api.L2gatewayAgentApi, 'delete_vif_from_gateway') |
| 242 |
def test_notify_ovsdb_states(self, mock_del_vif, mock_upd_vif, |
| 243 |
mock_add_vif, mock_ucmr, mock_pl, |
| 244 |
mock_ls, mock_del_pend_recs, |
| 245 |
mock_get_pend_recs): |
| 246 |
fake_ovsdb_states = {'ovsdb1': 'connected'} |
| 247 |
fake_dict = {'logical_switch_uuid': 'fake_ls_id', |
| 248 |
'mac': 'fake_mac', |
| 249 |
'locator_uuid': 'fake_loc_id', |
| 250 |
'dst_ip': 'fake_dst_ip', |
| 251 |
'vm_ip': 'fake_vm_ip'} |
| 252 |
fake_insert_dict = {'operation': 'insert'} |
| 253 |
fake_insert_dict.update(fake_dict) |
| 254 |
fake_update_dict = {'operation': 'update'} |
| 255 |
fake_update_dict.update(fake_dict) |
| 256 |
fake_delete_dict = {'operation': 'delete'} |
| 257 |
fake_delete_dict.update(fake_dict) |
| 258 |
mock_get_pend_recs.return_value = [fake_insert_dict] |
| 259 |
self.ovsdb_data.notify_ovsdb_states( |
| 260 |
self.context, fake_ovsdb_states) |
| 261 |
self.assertTrue(mock_add_vif.called) |
| 262 |
mock_get_pend_recs.return_value = [fake_update_dict] |
| 263 |
self.ovsdb_data.notify_ovsdb_states( |
| 264 |
self.context, fake_ovsdb_states) |
| 265 |
self.assertTrue(mock_upd_vif.called) |
| 266 |
mock_get_pend_recs.return_value = [fake_delete_dict] |
| 267 |
self.ovsdb_data.notify_ovsdb_states( |
| 268 |
self.context, fake_ovsdb_states) |
| 269 |
self.assertTrue(mock_del_vif.called) |
| 270 |
|
| 271 |
def test_process_new_logical_switches(self): |
| 272 |
fake_dict = {} |
| 273 |
fake_new_logical_switches = [fake_dict] |
| 274 |
with mock.patch.object(lib, 'get_logical_switch', |
| 275 |
return_value=None) as get_ls: |
| 276 |
with mock.patch.object(lib, |
| 277 |
'add_logical_switch') as add_ls: |
| 278 |
self.ovsdb_data._process_new_logical_switches( |
| 279 |
self.context, fake_new_logical_switches) |
| 280 |
self.assertIn(n_const.OVSDB_IDENTIFIER, fake_dict) |
| 281 |
self.assertEqual('fake_ovsdb_id', |
| 282 |
fake_dict[n_const.OVSDB_IDENTIFIER]) |
| 283 |
get_ls.assert_called_with(self.context, fake_dict) |
| 284 |
add_ls.assert_called_with(self.context, fake_dict) |
| 285 |
|
| 286 |
def test_process_new_physical_switches(self): |
| 287 |
fake_dict = {'tunnel_ip': ['set']} |
| 288 |
fake_new_physical_switches = [fake_dict] |
| 289 |
with mock.patch.object(lib, 'get_physical_switch', |
| 290 |
return_value=None) as get_ps: |
| 291 |
with mock.patch.object(lib, |
| 292 |
'add_physical_switch') as add_ps: |
| 293 |
self.ovsdb_data._process_new_physical_switches( |
| 294 |
self.context, fake_new_physical_switches) |
| 295 |
self.assertIn(n_const.OVSDB_IDENTIFIER, fake_dict) |
| 296 |
self.assertIsNone(fake_dict['tunnel_ip']) |
| 297 |
self.assertEqual('fake_ovsdb_id', |
| 298 |
fake_dict[n_const.OVSDB_IDENTIFIER]) |
| 299 |
get_ps.assert_called_with(self.context, fake_dict) |
| 300 |
add_ps.assert_called_with(self.context, fake_dict) |
| 301 |
|
| 302 |
@mock.patch.object(lib, 'get_physical_port', return_value=None) |
| 303 |
@mock.patch.object(lib, 'add_physical_port') |
| 304 |
@mock.patch.object(lib, 'get_vlan_binding', return_value=None) |
| 305 |
@mock.patch.object(lib, 'add_vlan_binding') |
| 306 |
def test_process_new_physical_ports(self, add_vlan, get_vlan, |
| 307 |
add_pp, get_pp): |
| 308 |
fake_dict1 = {} |
| 309 |
fake_dict2 = {'vlan_bindings': [fake_dict1]} |
| 310 |
fake_new_physical_ports = [fake_dict2] |
| 311 |
self.ovsdb_data._process_new_physical_ports( |
| 312 |
self.context, fake_new_physical_ports) |
| 313 |
self.assertIn(n_const.OVSDB_IDENTIFIER, fake_dict2) |
| 314 |
self.assertEqual('fake_ovsdb_id', |
| 315 |
fake_dict2[n_const.OVSDB_IDENTIFIER]) |
| 316 |
get_pp.assert_called_with(self.context, fake_dict2) |
| 317 |
add_pp.assert_called_with(self.context, fake_dict2) |
| 318 |
self.assertIn(n_const.OVSDB_IDENTIFIER, fake_dict1) |
| 319 |
self.assertIn('port_uuid', fake_dict1) |
| 320 |
get_vlan.assert_called_with(self.context, fake_dict1) |
| 321 |
add_vlan.assert_called_with(self.context, fake_dict1) |
| 322 |
|
| 323 |
def test_process_new_physical_locators(self): |
| 324 |
fake_dict = {} |
| 325 |
fake_new_physical_locators = [fake_dict] |
| 326 |
with mock.patch.object(lib, 'get_physical_locator', |
| 327 |
return_value=None) as get_pl: |
| 328 |
with mock.patch.object(lib, |
| 329 |
'add_physical_locator') as add_pl: |
| 330 |
self.ovsdb_data._process_new_physical_locators( |
| 331 |
self.context, fake_new_physical_locators) |
| 332 |
self.assertIn(n_const.OVSDB_IDENTIFIER, fake_dict) |
| 333 |
self.assertEqual('fake_ovsdb_id', |
| 334 |
fake_dict[n_const.OVSDB_IDENTIFIER]) |
| 335 |
get_pl.assert_called_with(self.context, fake_dict) |
| 336 |
add_pl.assert_called_with(self.context, fake_dict) |
| 337 |
|
| 338 |
@mock.patch.object(lib, 'get_ucast_mac_local', return_value=None) |
| 339 |
@mock.patch.object(lib, 'add_ucast_mac_local') |
| 340 |
def test_process_new_local_macs(self, add_lm, get_lm): |
| 341 |
fake_dict = {'uuid': '123456', |
| 342 |
'mac': 'mac123', |
| 343 |
'ovsdb_identifier': 'host1', |
| 344 |
'logical_switch_id': 'ls123'} |
| 345 |
fake_new_local_macs = [fake_dict] |
| 346 |
self.ovsdb_data._process_new_local_macs( |
| 347 |
self.context, fake_new_local_macs) |
| 348 |
self.assertIn(n_const.OVSDB_IDENTIFIER, fake_dict) |
| 349 |
self.assertEqual('fake_ovsdb_id', |
| 350 |
fake_dict[n_const.OVSDB_IDENTIFIER]) |
| 351 |
get_lm.assert_called_with(self.context, fake_dict) |
| 352 |
add_lm.assert_called_with(self.context, fake_dict) |
| 353 |
|
| 354 |
def test_process_new_remote_macs(self): |
| 355 |
fake_dict = {'logical_switch_id': 'ls123'} |
| 356 |
fake_new_remote_macs = [fake_dict] |
| 357 |
with mock.patch.object(lib, 'get_ucast_mac_remote', |
| 358 |
return_value=None) as get_mr: |
| 359 |
with mock.patch.object(lib, |
| 360 |
'add_ucast_mac_remote') as add_mr: |
| 361 |
self.ovsdb_data._process_new_remote_macs( |
| 362 |
self.context, fake_new_remote_macs) |
| 363 |
self.assertIn(n_const.OVSDB_IDENTIFIER, fake_dict) |
| 364 |
self.assertEqual('fake_ovsdb_id', |
| 365 |
fake_dict[n_const.OVSDB_IDENTIFIER]) |
| 366 |
get_mr.assert_called_with(self.context, fake_dict) |
| 367 |
add_mr.assert_called_with(self.context, fake_dict) |
| 368 |
|
| 369 |
def test_process_modified_remote_macs(self): |
| 370 |
fake_dict = {'logical_switch_id': 'ls123'} |
| 371 |
fake_modified_remote_macs = [fake_dict] |
| 372 |
with mock.patch.object(lib, |
| 373 |
'update_ucast_mac_remote') as update_mr: |
| 374 |
self.ovsdb_data._process_modified_remote_macs( |
| 375 |
self.context, fake_modified_remote_macs) |
| 376 |
self.assertIn(n_const.OVSDB_IDENTIFIER, fake_dict) |
| 377 |
self.assertEqual('fake_ovsdb_id', |
| 378 |
fake_dict[n_const.OVSDB_IDENTIFIER]) |
| 379 |
update_mr.assert_called_with(self.context, fake_dict) |
| 380 |
|
| 381 |
def test_process_deleted_logical_switches(self): |
| 382 |
fake_dict = {} |
| 383 |
fake_deleted_logical_switches = [fake_dict] |
| 384 |
with mock.patch.object(lib, 'delete_logical_switch') as delete_ls: |
| 385 |
self.ovsdb_data._process_deleted_logical_switches( |
| 386 |
self.context, fake_deleted_logical_switches) |
| 387 |
self.assertIn(n_const.OVSDB_IDENTIFIER, fake_dict) |
| 388 |
self.assertEqual('fake_ovsdb_id', |
| 389 |
fake_dict[n_const.OVSDB_IDENTIFIER]) |
| 390 |
delete_ls.assert_called_with(self.context, fake_dict) |
| 391 |
|
| 392 |
def test_get_agent_by_mac(self): |
| 393 |
fake_mac = {'mac': 'fake_mac_1'} |
| 394 |
fake_port = [{'binding:host_id': 'fake_host'}] |
| 395 |
with mock.patch.object(self.ovsdb_data, '_get_port_by_mac', |
| 396 |
return_value=fake_port) as mock_get_port_mac, \ |
| 397 |
mock.patch.object( |
| 398 |
self.ovsdb_data, |
| 399 |
'_get_agent_details_by_host') as mock_get_agent_detail: |
| 400 |
self.ovsdb_data._get_agent_by_mac(self.context, fake_mac) |
| 401 |
mock_get_port_mac.assert_called_with(self.context, 'fake_mac_1') |
| 402 |
mock_get_agent_detail.assert_called_with(self.context, 'fake_host') |
| 403 |
|
| 404 |
def test_get_agent_details_by_host(self): |
| 405 |
fake_agent = {'configurations': {'tunnel_types': ["vxlan"], |
| 406 |
'l2_population': True}} |
| 407 |
fake_agents = [fake_agent] |
| 408 |
with mock.patch.object(self.ovsdb_data.core_plugin, |
| 409 |
'get_agents', |
| 410 |
return_value=fake_agents): |
| 411 |
l2pop_enabled = self.ovsdb_data._get_agent_details_by_host( |
| 412 |
self.context, 'fake_host') |
| 413 |
self.assertTrue(l2pop_enabled) |
| 414 |
|
| 415 |
def test_process_deleted_physical_switches(self): |
| 416 |
fake_dict = {} |
| 417 |
fake_deleted_physical_switches = [fake_dict] |
| 418 |
fake_ls_dict = {'uuid': 'ls-uuid'} |
| 419 |
fake_ls_list = [fake_ls_dict] |
| 420 |
with mock.patch.object(lib, 'delete_physical_switch') as delete_ps, \ |
| 421 |
mock.patch.object(lib, 'get_all_physical_switches_by_ovsdb_id', |
| 422 |
return_value=False) as get_ps, \ |
| 423 |
mock.patch.object(lib, 'get_all_logical_switches_by_ovsdb_id', |
| 424 |
return_value=fake_ls_list) as get_ls, \ |
| 425 |
mock.patch.object(agent_api.L2gatewayAgentApi, |
| 426 |
'delete_network') as del_network: |
| 427 |
self.ovsdb_data._process_deleted_physical_switches( |
| 428 |
self.context, fake_deleted_physical_switches) |
| 429 |
self.assertIn(n_const.OVSDB_IDENTIFIER, fake_dict) |
| 430 |
self.assertEqual('fake_ovsdb_id', |
| 431 |
fake_dict[n_const.OVSDB_IDENTIFIER]) |
| 432 |
delete_ps.assert_called_with(self.context, fake_dict) |
| 433 |
get_ps.assert_called_with(self.context, 'fake_ovsdb_id') |
| 434 |
get_ls.assert_called_with(self.context, 'fake_ovsdb_id') |
| 435 |
del_network.assert_called_with(self.context, 'fake_ovsdb_id', |
| 436 |
'ls-uuid') |
| 437 |
|
| 438 |
def test_process_deleted_physical_ports(self): |
| 439 |
fake_dict = {'name': 'fake_uuid', 'uuid': 'fake_name'} |
| 440 |
fake_deleted_physical_ports = [fake_dict] |
| 441 |
fake_physical_port = {'uuid': 'fake_uuid', |
| 442 |
'name': 'fake_name'} |
| 443 |
fake_physical_switch = {'uuid': 'fake_uuid', |
| 444 |
'ovsdb_identifier': 'fake_ovsdb_id', |
| 445 |
'name': 'fake_switch'}, |
| 446 |
fake_vlan_binding = {'port_uuid:': 'fake_port_uuid', |
| 447 |
'vlan': 'fake_vlan', |
| 448 |
'logical_switch_uuid': 'fake_switch_uuid', |
| 449 |
'ovsdb_identifier': 'fake_ovsdb_id'} |
| 450 |
with mock.patch.object(lib, |
| 451 |
'delete_physical_port'), \ |
| 452 |
mock.patch.object(lib, |
| 453 |
'get_physical_port', |
| 454 |
return_value=fake_physical_port), \ |
| 455 |
mock.patch.object(lib, 'get_physical_switch', |
| 456 |
return_vaue=fake_physical_switch), \ |
| 457 |
mock.patch.object(lib, |
| 458 |
'get_all_vlan_bindings_by_physical_port', |
| 459 |
return_vaue=fake_vlan_binding), \ |
| 460 |
mock.patch.object(l2gateway_db.L2GatewayMixin, |
| 461 |
'_get_l2gw_ids_by_interface_switch', |
| 462 |
return_value=['fake_uuid']), \ |
| 463 |
mock.patch.object( |
| 464 |
l2gateway_db.L2GatewayMixin, |
| 465 |
'_delete_connection_by_l2gw_id') as l2gw_conn_del: |
| 466 |
self.ovsdb_data._process_deleted_physical_ports( |
| 467 |
self.context, fake_deleted_physical_ports) |
| 468 |
self.assertIn(n_const.OVSDB_IDENTIFIER, fake_dict) |
| 469 |
self.assertEqual('fake_ovsdb_id', |
| 470 |
fake_dict[n_const.OVSDB_IDENTIFIER]) |
| 471 |
l2gw_conn_del.assert_called_with(self.context, 'fake_uuid') |
| 472 |
|
| 473 |
@mock.patch.object(lib, 'delete_physical_port') |
| 474 |
@mock.patch.object(lib, 'get_physical_port') |
| 475 |
@mock.patch.object(lib, 'get_physical_switch') |
| 476 |
@mock.patch.object(l2gateway_db.L2GatewayMixin, |
| 477 |
'_get_l2gw_ids_by_interface_switch', |
| 478 |
return_value=['fake_uuid']) |
| 479 |
@mock.patch.object(l2gateway_db.L2GatewayMixin, |
| 480 |
'_delete_connection_by_l2gw_id') |
| 481 |
@mock.patch.object(lib, |
| 482 |
'get_all_vlan_bindings_by_physical_port') |
| 483 |
@mock.patch.object(lib, |
| 484 |
'get_all_vlan_bindings_by_logical_switch') |
| 485 |
@mock.patch.object(data.OVSDBData, '_delete_macs_from_ovsdb') |
| 486 |
@mock.patch.object(lib, 'delete_vlan_binding') |
| 487 |
def test_process_deleted_physical_ports_with_delete_macs( |
| 488 |
self, del_vlan, del_macs, get_vlan_by_ls, get_vlan_by_pp, |
| 489 |
l2gw_conn_del, get_l2gw, get_ps, get_pp, delete_pp): |
| 490 |
fake_dict = {'uuid': 'fake_uuid', 'name': 'fake_name', |
| 491 |
'logical_switch_id': 'fake_ls_id', |
| 492 |
'ovsdb_identifier': 'fake_ovsdb_id'} |
| 493 |
fake_deleted_physical_ports = [fake_dict] |
| 494 |
fake_physical_port = {'uuid': 'fake_uuid', |
| 495 |
'name': 'fake_name', |
| 496 |
'ovsdb_identifier': 'fake_ovsdb_id'} |
| 497 |
fake_physical_switch = {'uuid': 'fake_uuid', |
| 498 |
'ovsdb_identifier': 'fake_ovsdb_id', |
| 499 |
'name': 'fake_switch'} |
| 500 |
vlan_binding_dict = {'logical_switch_uuid': 'fake_ls_id', |
| 501 |
'ovsdb_identifier': 'fake_ovsdb_id', |
| 502 |
'port_uuid': 'fake_uuid', |
| 503 |
'vlan': 'fake_vlan', |
| 504 |
'logical_switch_id': 'fake_ls_id'} |
| 505 |
fake_vlan_binding_list = [vlan_binding_dict] |
| 506 |
fake_binding_list = [vlan_binding_dict] |
| 507 |
get_pp.return_value = fake_physical_port |
| 508 |
get_ps.return_vaue = fake_physical_switch |
| 509 |
get_vlan_by_pp.return_value = fake_vlan_binding_list |
| 510 |
get_vlan_by_ls.return_value = fake_binding_list |
| 511 |
self.ovsdb_data._process_deleted_physical_ports( |
| 512 |
self.context, fake_deleted_physical_ports) |
| 513 |
self.assertIn(n_const.OVSDB_IDENTIFIER, fake_dict) |
| 514 |
self.assertEqual('fake_ovsdb_id', |
| 515 |
fake_dict[n_const.OVSDB_IDENTIFIER]) |
| 516 |
l2gw_conn_del.assert_called_with(self.context, 'fake_uuid') |
| 517 |
get_vlan_by_pp.assert_called_with(self.context, fake_dict) |
| 518 |
del_vlan.assert_called_with(self.context, vlan_binding_dict) |
| 519 |
get_vlan_by_ls.assert_called_with(self.context, vlan_binding_dict) |
| 520 |
del_macs.assert_called_with(self.context, |
| 521 |
'fake_ls_id', 'fake_ovsdb_id') |
| 522 |
del_vlan.assert_called_with(self.context, vlan_binding_dict) |
| 523 |
delete_pp.assert_called_with(self.context, fake_dict) |
| 524 |
|
| 525 |
@mock.patch.object(data.OVSDBData, |
| 526 |
'_get_logical_switch_ids', |
| 527 |
return_value=['1']) |
| 528 |
@mock.patch.object(lib, |
| 529 |
'get_all_physical_switches_by_ovsdb_id', |
| 530 |
return_value=[{'tunnel_ip': '3.3.3.3'}]) |
| 531 |
@mock.patch.object(data.OVSDBData, |
| 532 |
'_get_fdb_entries') |
| 533 |
@mock.patch.object(lib, |
| 534 |
'delete_physical_locator') |
| 535 |
@mock.patch.object(data.OVSDBData, '_get_agent_ips', |
| 536 |
return_value={'1.1.1.1': 'hostname'}) |
| 537 |
@mock.patch.object(tunnel_calls.Tunnel_Calls, |
| 538 |
'trigger_l2pop_delete') |
| 539 |
def test_process_deleted_physical_locators( |
| 540 |
self, trig_l2pop, get_agent_ips, delete_pl, get_fdb, get_all_ps, |
| 541 |
get_ls): |
| 542 |
"""Test case to test _process_deleted_physical_locators. |
| 543 |
|
| 544 |
for unicast rpc to the L2 agent |
| 545 |
""" |
| 546 |
fake_dict1 = {'dst_ip': '1.1.1.1'} |
| 547 |
fake_dict2 = {'dst_ip': '2.2.2.2'} |
| 548 |
fake_deleted_physical_locators = [fake_dict2, fake_dict1] |
| 549 |
mock.patch.object(manager, 'NeutronManager').start() |
| 550 |
self.ovsdb_data._process_deleted_physical_locators( |
| 551 |
self.context, fake_deleted_physical_locators) |
| 552 |
self.assertIn(n_const.OVSDB_IDENTIFIER, fake_dict1) |
| 553 |
self.assertTrue(get_ls.called) |
| 554 |
self.assertTrue(get_all_ps.called) |
| 555 |
self.assertTrue(get_fdb.called) |
| 556 |
self.assertEqual('fake_ovsdb_id', |
| 557 |
fake_dict1[n_const.OVSDB_IDENTIFIER]) |
| 558 |
delete_pl.assert_called_with(self.context, fake_dict1) |
| 559 |
self.assertTrue(get_agent_ips.called) |
| 560 |
trig_l2pop.assert_called_with(self.context, |
| 561 |
mock.ANY, |
| 562 |
'hostname') |
| 563 |
|
| 564 |
@mock.patch.object(data.OVSDBData, |
| 565 |
'_get_logical_switch_ids', |
| 566 |
return_value=['1']) |
| 567 |
@mock.patch.object(lib, |
| 568 |
'get_all_physical_switches_by_ovsdb_id', |
| 569 |
return_value=[{'tunnel_ip': '3.3.3.3'}]) |
| 570 |
@mock.patch.object(data.OVSDBData, |
| 571 |
'_get_fdb_entries') |
| 572 |
@mock.patch.object(lib, |
| 573 |
'delete_physical_locator') |
| 574 |
@mock.patch.object(data.OVSDBData, '_get_agent_ips', |
| 575 |
return_value={'2.2.2.2': 'hostname'}) |
| 576 |
@mock.patch.object(tunnel_calls.Tunnel_Calls, |
| 577 |
'trigger_l2pop_delete') |
| 578 |
def test_process_deleted_physical_locators1( |
| 579 |
self, trig_l2pop, get_agent_ips, delete_pl, get_fdb, |
| 580 |
get_all_ps, get_ls): |
| 581 |
"""Test case to test _process_deleted_physical_locators. |
| 582 |
|
| 583 |
for broadcast rpc to the L2 agents |
| 584 |
""" |
| 585 |
fake_dict1 = {'dst_ip': '1.1.1.1'} |
| 586 |
fake_deleted_physical_locators = [fake_dict1] |
| 587 |
mock.patch.object(manager, 'NeutronManager').start() |
| 588 |
self.ovsdb_data._process_deleted_physical_locators( |
| 589 |
self.context, fake_deleted_physical_locators) |
| 590 |
self.assertIn(n_const.OVSDB_IDENTIFIER, fake_dict1) |
| 591 |
self.assertTrue(get_ls.called) |
| 592 |
self.assertTrue(get_all_ps.called) |
| 593 |
self.assertTrue(get_fdb.called) |
| 594 |
self.assertEqual('fake_ovsdb_id', |
| 595 |
fake_dict1[n_const.OVSDB_IDENTIFIER]) |
| 596 |
delete_pl.assert_called_once_with(self.context, fake_dict1) |
| 597 |
self.assertTrue(get_agent_ips.called) |
| 598 |
trig_l2pop.assert_called_with(self.context, |
| 599 |
mock.ANY) |
| 600 |
|
| 601 |
def test_process_deleted_local_macs(self): |
| 602 |
fake_dict = {'uuid': '123456', |
| 603 |
'mac': 'mac123', |
| 604 |
'ovsdb_identifier': 'host1', |
| 605 |
'logical_switch_id': 'ls123'} |
| 606 |
fake_deleted_local_macs = [fake_dict] |
| 607 |
with mock.patch.object(lib, 'delete_ucast_mac_local') as delete_ml: |
| 608 |
with mock.patch.object(lib, |
| 609 |
'get_ucast_mac_remote_by_mac_and_ls', |
| 610 |
return_value=True): |
| 611 |
self.ovsdb_data._process_deleted_local_macs( |
| 612 |
self.context, fake_deleted_local_macs) |
| 613 |
self.assertIn(n_const.OVSDB_IDENTIFIER, fake_dict) |
| 614 |
self.assertEqual('fake_ovsdb_id', |
| 615 |
fake_dict[n_const.OVSDB_IDENTIFIER]) |
| 616 |
delete_ml.assert_called_with(self.context, fake_dict) |
| 617 |
|
| 618 |
def test_process_deleted_remote_macs(self): |
| 619 |
fake_dict = {} |
| 620 |
fake_deleted_remote_macs = [fake_dict] |
| 621 |
with mock.patch.object(lib, 'delete_ucast_mac_remote') as delete_mr: |
| 622 |
self.ovsdb_data._process_deleted_remote_macs( |
| 623 |
self.context, fake_deleted_remote_macs) |
| 624 |
self.assertIn(n_const.OVSDB_IDENTIFIER, fake_dict) |
| 625 |
self.assertEqual('fake_ovsdb_id', |
| 626 |
fake_dict[n_const.OVSDB_IDENTIFIER]) |
| 627 |
delete_mr.assert_called_with(self.context, fake_dict) |
| 628 |
|
| 629 |
@mock.patch.object(lib, 'get_physical_port') |
| 630 |
@mock.patch.object(lib, 'add_physical_port') |
| 631 |
@mock.patch.object(lib, 'get_all_vlan_bindings_by_physical_port') |
| 632 |
@mock.patch.object(lib, 'add_vlan_binding') |
| 633 |
@mock.patch.object(lib, 'update_physical_ports_status') |
| 634 |
def test_process_modified_physical_ports(self, update_pp_status, add_vlan, |
| 635 |
get_vlan, add_pp, get_pp): |
| 636 |
fake_dict1 = {} |
| 637 |
fake_dict2 = {'vlan_bindings': [fake_dict1], |
| 638 |
'uuid': 'fake_uuid'} |
| 639 |
fake_modified_physical_ports = [fake_dict2] |
| 640 |
self.ovsdb_data._process_modified_physical_ports( |
| 641 |
self.context, fake_modified_physical_ports) |
| 642 |
self.assertIn(n_const.OVSDB_IDENTIFIER, fake_dict2) |
| 643 |
self.assertEqual('fake_ovsdb_id', |
| 644 |
fake_dict2[n_const.OVSDB_IDENTIFIER]) |
| 645 |
get_pp.assert_called_with(self.context, fake_dict2) |
| 646 |
update_pp_status.assert_called_with(self.context, fake_dict2) |
| 647 |
self.assertFalse(add_pp.called) |
| 648 |
get_vlan.assert_called_with(self.context, fake_dict2) |
| 649 |
self.assertIn(n_const.OVSDB_IDENTIFIER, fake_dict1) |
| 650 |
self.assertIn('port_uuid', fake_dict1) |
| 651 |
add_vlan.assert_called_with(self.context, fake_dict1) |