def test_install_uni_flows(send_flow_mods_mock): """Test install uni flows method. This test will verify the flows send to the send_flow_mods method. """ uni_a = get_uni_mocked(interface_port=2, tag_value=82, switch_id="switch_uni_a", is_valid=True) uni_z = get_uni_mocked(interface_port=3, tag_value=83, switch_id="switch_uni_z", is_valid=True) attributes = { "controller": get_controller_mock(), "name": "custom_name", "uni_a": uni_a, "uni_z": uni_z, "primary_links": [ get_link_mocked(endpoint_a_port=9, endpoint_b_port=10, metadata={"s_vlan": 5}), get_link_mocked(endpoint_a_port=11, endpoint_b_port=12, metadata={"s_vlan": 6}) ] } evc = EVC(**attributes) # pylint: disable=protected-access evc._install_uni_flows(attributes['primary_links']) expected_flow_mod_a = [{ 'match': { 'in_port': uni_a.interface.port_number, 'dl_vlan': uni_a.user_tag.value }, 'cookie': evc.get_cookie(), 'actions': [{ 'action_type': 'set_vlan', 'vlan_id': uni_z.user_tag.value }, { 'action_type': 'push_vlan', 'tag_type': 's' }, { 'action_type': 'set_vlan', 'vlan_id': evc.primary_links[0].get_metadata('s_vlan').value }, { 'action_type': 'output', 'port': evc.primary_links[0].endpoint_a.port_number }] }, { 'match': { 'in_port': evc.primary_links[0].endpoint_a.port_number, 'dl_vlan': evc.primary_links[0].get_metadata('s_vlan').value }, 'cookie': evc.get_cookie(), 'actions': [{ 'action_type': 'pop_vlan' }, { 'action_type': 'output', 'port': uni_a.interface.port_number }] }] send_flow_mods_mock.assert_any_call(uni_a.interface.switch, expected_flow_mod_a) expected_flow_mod_z = [{ 'match': { 'in_port': uni_z.interface.port_number, 'dl_vlan': uni_z.user_tag.value }, 'cookie': evc.get_cookie(), 'actions': [{ 'action_type': 'set_vlan', 'vlan_id': uni_a.user_tag.value }, { 'action_type': 'push_vlan', 'tag_type': 's' }, { 'action_type': 'set_vlan', 'vlan_id': evc.primary_links[-1].get_metadata('s_vlan').value }, { 'action_type': 'output', 'port': evc.primary_links[-1].endpoint_b.port_number }] }, { 'match': { 'in_port': evc.primary_links[-1].endpoint_b.port_number, 'dl_vlan': evc.primary_links[-1].get_metadata('s_vlan').value }, 'cookie': evc.get_cookie(), 'actions': [{ 'action_type': 'pop_vlan' }, { 'action_type': 'output', 'port': uni_z.interface.port_number }] }] send_flow_mods_mock.assert_any_call(uni_z.interface.switch, expected_flow_mod_z)
def test_install_uni_flows(send_flow_mods_mock): """Test install uni flows method. This test will verify the flows send to the send_flow_mods method. """ uni_a = get_uni_mocked( interface_port=2, tag_value=82, switch_id="switch_uni_a", is_valid=True, ) uni_z = get_uni_mocked( interface_port=3, tag_value=83, switch_id="switch_uni_z", is_valid=True, ) attributes = { "controller": get_controller_mock(), "name": "custom_name", "uni_a": uni_a, "uni_z": uni_z, "primary_links": [ get_link_mocked( endpoint_a_port=9, endpoint_b_port=10, metadata={"s_vlan": 5}, ), get_link_mocked( endpoint_a_port=11, endpoint_b_port=12, metadata={"s_vlan": 6}, ), ], } evc = EVC(**attributes) # pylint: disable=protected-access evc._install_uni_flows(attributes["primary_links"]) expected_flow_mod_a = [ { "match": { "in_port": uni_a.interface.port_number, "dl_vlan": uni_a.user_tag.value, }, "cookie": evc.get_cookie(), "actions": [ { "action_type": "pop_vlan" }, { "action_type": "push_vlan", "tag_type": "s" }, { "action_type": "set_vlan", "vlan_id": evc.primary_links[0].get_metadata("s_vlan").value, }, { "action_type": "output", "port": evc.primary_links[0].endpoint_a.port_number, }, ], }, { "match": { "in_port": evc.primary_links[0].endpoint_a.port_number, "dl_vlan": evc.primary_links[0].get_metadata("s_vlan").value, }, "cookie": evc.get_cookie(), "actions": [ { "action_type": "pop_vlan" }, { "action_type": "push_vlan", "tag_type": "c" }, { "action_type": "set_vlan", "vlan_id": uni_a.user_tag.value, }, { "action_type": "output", "port": uni_a.interface.port_number, }, ], }, ] send_flow_mods_mock.assert_any_call(uni_a.interface.switch, expected_flow_mod_a) expected_flow_mod_z = [ { "match": { "in_port": uni_z.interface.port_number, "dl_vlan": uni_z.user_tag.value, }, "cookie": evc.get_cookie(), "actions": [ { "action_type": "pop_vlan" }, { "action_type": "push_vlan", "tag_type": "s" }, { "action_type": "set_vlan", "vlan_id": evc.primary_links[-1].get_metadata("s_vlan").value, }, { "action_type": "output", "port": evc.primary_links[-1].endpoint_b.port_number, }, ], }, { "match": { "in_port": evc.primary_links[-1].endpoint_b.port_number, "dl_vlan": evc.primary_links[-1].get_metadata("s_vlan").value, }, "cookie": evc.get_cookie(), "actions": [ { "action_type": "pop_vlan" }, { "action_type": "push_vlan", "tag_type": "c" }, { "action_type": "set_vlan", "vlan_id": uni_z.user_tag.value, }, { "action_type": "output", "port": uni_z.interface.port_number, }, ], }, ] send_flow_mods_mock.assert_any_call(uni_z.interface.switch, expected_flow_mod_z)