def test_handle_errors(self, mock_send_napp_event): """Test handle_errors method.""" flow = MagicMock() self.napp._flow_mods_sent[0] = (flow, 'add') switch = get_switch_mock("00:00:00:00:00:00:00:01") switch.connection = get_connection_mock( 0x04, get_switch_mock("00:00:00:00:00:00:00:02")) protocol = MagicMock() protocol.unpack.return_value = 'error_packet' switch.connection.protocol = protocol message = MagicMock() message.header.xid.value = 0 message.error_type = 2 message.code = 5 event = get_kytos_event_mock(name='.*.of_core.*.ofpt_error', content={ 'message': message, 'source': switch.connection }) self.napp.handle_errors(event) mock_send_napp_event.assert_called_with(flow.switch, flow, 'error', error_command='add', error_code=5, error_type=2)
def test_get_link_from_interface(self): """Test _get_link_from_interface.""" mock_switch_a = get_switch_mock("00:00:00:00:00:00:00:01", 0x04) mock_switch_b = get_switch_mock("00:00:00:00:00:00:00:02", 0x04) mock_interface_a = get_interface_mock('s1-eth1', 1, mock_switch_a) mock_interface_b = get_interface_mock('s2-eth1', 1, mock_switch_b) mock_interface_c = get_interface_mock('s2-eth1', 2, mock_switch_b) mock_link = get_link_mock(mock_interface_a, mock_interface_b) self.napp.links = {'0e2b5d7bc858b9f38db11b69': mock_link} response = self.napp._get_link_from_interface(mock_interface_a) self.assertEqual(response, mock_link) response = self.napp._get_link_from_interface(mock_interface_c) self.assertEqual(response, None)
def test_get_link_or_create(self): """Test _get_link_or_create.""" dpid_a = "00:00:00:00:00:00:00:01" dpid_b = "00:00:00:00:00:00:00:02" mock_switch_a = get_switch_mock(dpid_a, 0x04) mock_switch_b = get_switch_mock(dpid_b, 0x04) mock_interface_a = get_interface_mock('s1-eth1', 1, mock_switch_a) mock_interface_b = get_interface_mock('s2-eth1', 1, mock_switch_b) mock_interface_a.id = dpid_a mock_interface_b.id = dpid_b link = self.napp._get_link_or_create(mock_interface_a, mock_interface_b) self.assertEqual(link.endpoint_a.id, dpid_a) self.assertEqual(link.endpoint_b.id, dpid_b)
def test_check_storehouse_consistency(self, *args): """Test check_storehouse_consistency method. This test checks the case when a flow is missing in storehouse. """ (mock_flow_factory, mock_install_flows) = args cookie_exception_interval = [(0x2b00000000000011, 0x2b000000000000ff)] self.napp.cookie_exception_range = cookie_exception_interval dpid = "00:00:00:00:00:00:00:01" switch = get_switch_mock(dpid, 0x04) flow_1 = MagicMock() flow_1.cookie = 0x2b00000000000010 flow_1.as_dict.return_value = {'flow_1': 'data', 'cookie': 1} switch.flows = [flow_1] flow_list = [{ "command": "add", "flow": { 'flow_2': 'data', 'cookie': 1 } }] serializer = flow_1 mock_flow_factory.return_value = serializer self.napp.stored_flows = {dpid: {"flow_list": flow_list}} self.napp.check_storehouse_consistency(switch) mock_install_flows.assert_called()
def test_restore_network_status(self): """Test restore_network_status.""" dpid = '00:00:00:00:00:00:00:01' mock_switch = get_switch_mock(dpid) mock_switch.id = dpid mock_interface = get_interface_mock('s1-eth1', 1, mock_switch) mock_switch.interfaces = {1: mock_interface} self.napp.controller.switches = {dpid: mock_switch} self.napp.switches_state = {dpid: True} self.napp.interfaces_state = { '00:00:00:00:00:00:00:01:1': (True, True) } # enable self.napp.restore_network_status(mock_switch) self.assertEqual(mock_switch.enable.call_count, 1) self.assertEqual(mock_interface.enable.call_count, 1) self.assertEqual(mock_interface.lldp, True) # disable self.napp.switches_state = {dpid: False} self.napp.interfaces_state = { '00:00:00:00:00:00:00:01:1': (False, False) } self.napp.restore_network_status(mock_switch) self.assertEqual(mock_switch.disable.call_count, 1) self.assertEqual(mock_interface.disable.call_count, 1) self.assertEqual(mock_interface.lldp, False)
def test_get_interface_metadata(self): """Test get_interface_metada.""" interface_id = '00:00:00:00:00:00:00:01:1' dpid = '00:00:00:00:00:00:00:01' mock_switch = get_switch_mock(dpid) mock_interface = get_interface_mock('s1-eth1', 1, mock_switch) mock_interface.metadata = {"metada": "A"} mock_switch.interfaces = {1: mock_interface} self.napp.controller.switches = {dpid: mock_switch} api = get_test_client(self.napp.controller, self.napp) url = f'{self.server_name_url}/v3/interfaces/{interface_id}/metadata' response = api.get(url) self.assertEqual(response.status_code, 200, response.data) # fail case switch not found interface_id = '00:00:00:00:00:00:00:02:1' url = f'{self.server_name_url}/v3/interfaces/{interface_id}/metadata' response = api.get(url) self.assertEqual(response.status_code, 404, response.data) # fail case interface not found interface_id = '00:00:00:00:00:00:00:01:2' url = f'{self.server_name_url}/v3/interfaces/{interface_id}/metadata' response = api.get(url) self.assertEqual(response.status_code, 404, response.data)
def test_install_table_miss_flow(self, *args): """Test _create_flow_mod method for flow 1.3 packet.""" (mock_get_switch_by_dpid, mock_settings, mock_requests, mock_port13) = args mock_port13.OFPP_CONTROLLER = 123 flow_manager_url = 'http://localhost:8181/api/kytos/flow_manager/v2' mock_settings.FLOW_MANAGER_URL = flow_manager_url mock_settings.TABLE_ID = 0 expected_flow = {} expected_flow['priority'] = 0 expected_flow['table_id'] = 0 expected_flow['actions'] = [{'action_type': 'output', 'port': 123}] dpid = "00:00:00:00:00:00:00:01" switch = get_switch_mock(dpid, 0x04) mock_get_switch_by_dpid.return_value = switch destination = switch.id endpoint = f'{flow_manager_url}/flows/{destination}' event = get_kytos_event_mock(name='kytos/topology.switch.enabled', content={'dpid': dpid}) self.napp.install_table_miss_flow(event) data = {'flows': [expected_flow]} mock_requests.post.assert_called_with(endpoint, json=data)
def test_add_interface_metadata(self, mock_metadata_changes): """Test add_interface_metadata.""" interface_id = '00:00:00:00:00:00:00:01:1' dpid = '00:00:00:00:00:00:00:01' mock_switch = get_switch_mock(dpid) mock_interface = get_interface_mock('s1-eth1', 1, mock_switch) mock_interface.metadata = {"metada": "A"} mock_switch.interfaces = {1: mock_interface} self.napp.controller.switches = {dpid: mock_switch} api = get_test_client(self.napp.controller, self.napp) url = f'{self.server_name_url}/v3/interfaces/{interface_id}/metadata' payload = {"metada": "A"} response = api.post(url, data=json.dumps(payload), content_type='application/json') self.assertEqual(response.status_code, 201, response.data) mock_metadata_changes.assert_called() # fail case switch not found interface_id = '00:00:00:00:00:00:00:02:1' url = f'{self.server_name_url}/v3/interfaces/{interface_id}/metadata' response = api.post(url, data=json.dumps(payload), content_type='application/json') self.assertEqual(response.status_code, 404, response.data) # fail case interface not found interface_id = '00:00:00:00:00:00:00:01:2' url = f'{self.server_name_url}/v3/interfaces/{interface_id}/metadata' response = api.post(url, data=json.dumps(payload), content_type='application/json') self.assertEqual(response.status_code, 404, response.data)
def setUp(self): """Execute steps before each tests. Set the server_name_url from kytos/of_core """ self.switch_v0x01 = get_switch_mock("00:00:00:00:00:00:00:01", 0x01) self.switch_v0x04 = get_switch_mock("00:00:00:00:00:00:00:02", 0x04) self.switch_v0x01.connection = get_connection_mock( 0x01, get_switch_mock("00:00:00:00:00:00:00:03")) self.switch_v0x04.connection = get_connection_mock( 0x04, get_switch_mock("00:00:00:00:00:00:00:04")) patch('kytos.core.helpers.run_on_thread', lambda x: x).start() # pylint: disable=import-outside-toplevel from napps.kytos.of_core.main import Main self.addCleanup(patch.stopall) self.napp = Main(get_controller_mock())
def test__eq__fail(self): """Test the case where __eq__ receives objects with different types.""" mock_switch = get_switch_mock("00:00:00:00:00:00:00:01") flow_dict = { 'switch': mock_switch.id, 'table_id': 1, 'match': { 'dl_src': '11:22:33:44:55:66' }, 'priority': 2, 'idle_timeout': 3, 'hard_timeout': 4, 'cookie': 5, 'actions': [{ 'action_type': 'set_vlan', 'vlan_id': 6 }], 'stats': {} } for flow_class in Flow01, Flow04: with self.subTest(flow_class=flow_class): flow_1 = flow_class.from_dict(flow_dict, mock_switch) flow_2 = "any_string_object" with self.assertRaises(ValueError): return flow_1 == flow_2
def test__eq__success_with_equal_flows(self): """Test success case to __eq__ override with equal flows.""" mock_switch = get_switch_mock("00:00:00:00:00:00:00:01") flow_dict = { 'switch': mock_switch.id, 'table_id': 1, 'match': { 'dl_src': '11:22:33:44:55:66' }, 'priority': 2, 'idle_timeout': 3, 'hard_timeout': 4, 'cookie': 5, 'actions': [{ 'action_type': 'set_vlan', 'vlan_id': 6 }], 'stats': {} } for flow_class in Flow01, Flow04: with self.subTest(flow_class=flow_class): flow_1 = flow_class.from_dict(flow_dict, mock_switch) flow_2 = flow_class.from_dict(flow_dict, mock_switch) self.assertEqual(flow_1 == flow_2, True)
def test_consistency_cookie_ignored_range(self, *args): """Test the consistency `cookie` ignored range.""" (mock_flow_factory, mock_install_flows) = args dpid = "00:00:00:00:00:00:00:01" switch = get_switch_mock(dpid, 0x04) cookie_ignored_interval = [(0x2b00000000000011, 0x2b000000000000ff), 0x2b00000000000100] self.napp.cookie_ignored_range = cookie_ignored_interval flow = MagicMock() expected = [{ 'cookie': 0x2b00000000000010, 'called': 1 }, { 'cookie': 0x2b00000000000013, 'called': 0 }, { 'cookie': 0x2b00000000000100, 'called': 0 }, { 'cookie': 0x2b00000000000101, 'called': 1 }] # ignored flow for i in expected: mock_install_flows.call_count = 0 cookie = i['cookie'] called = i['called'] flow.cookie = cookie flow.as_dict.return_value = {'flow_1': 'data', 'cookie': cookie} switch.flows = [flow] mock_flow_factory.return_value = flow self.napp.stored_flows = {dpid: {"flow_list": flow}} self.napp.check_storehouse_consistency(switch) self.assertEqual(mock_install_flows.call_count, called)
def test_install_table_miss_flow(self, *args): """Test _create_flow_mod method for flow_mod 1.3 packet.""" (mock_flow_mod, mock_action, mock_instruction, mock_kytos_event, mock_buffer_put) = args flow_mod = MagicMock() flow_mod.instructions = [] instruction = MagicMock() instruction.actions = [] action = MagicMock() mock_flow_mod.return_value = flow_mod mock_action.return_value = action mock_instruction.return_value = instruction switch = get_switch_mock("00:00:00:00:00:00:00:01", 0x04) event = get_kytos_event_mock(name='kytos/core.switch.new', content={'switch': switch}) self.napp.install_table_miss_flow(event) self.assertEqual(flow_mod.command, 0) self.assertEqual(instruction.actions[0], action) self.assertEqual(flow_mod.instructions[0], instruction) event_call = call(name=('kytos/of_l2ls.messages.out.' 'ofpt_flow_mod'), content={ 'destination': switch.connection, 'message': flow_mod }) mock_kytos_event.assert_has_calls([event_call]) mock_buffer_put.assert_called_once()
def test_consistency_table_id_ignored_range(self, *args): """Test the consistency `table_id` ignored range.""" (mock_flow_factory, mock_install_flows) = args dpid = "00:00:00:00:00:00:00:01" switch = get_switch_mock(dpid, 0x04) table_id_ignored_interval = [(1, 2), 3] self.napp.tab_id_ignored_range = table_id_ignored_interval flow = MagicMock() expected = [{ 'table_id': 0, 'called': 1 }, { 'table_id': 3, 'called': 0 }, { 'table_id': 4, 'called': 1 }] # ignored flow for i in expected: table_id = i['table_id'] called = i['called'] mock_install_flows.call_count = 0 flow.table_id = table_id flow.as_dict.return_value = {'flow_1': 'data', 'cookie': table_id} switch.flows = [flow] mock_flow_factory.return_value = flow self.napp.stored_flows = {dpid: {"flow_list": flow}} self.napp.check_storehouse_consistency(switch) self.assertEqual(mock_install_flows.call_count, called)
def get_topology_with_metadata_mock(): """Create a topology with metadata.""" switches = {} interfaces = {} links = {} i = 0 links_to_interfaces, links_to_metadata, switches_to_interface_counts = topology_setting( ) for switch in switches_to_interface_counts: switches[switch] = get_switch_mock(switch) for key, value in switches_to_interface_counts.items(): switches[key].interfaces = {} for interface in _get_interfaces(value, switches[key]): switches[key].interfaces[interface.id] = interface interfaces[interface.id] = interface for interfaces_str in links_to_interfaces: interface_a = interfaces[interfaces_str[0]] interface_b = interfaces[interfaces_str[1]] links[str(i)] = get_link_mock(interface_a, interface_b) links[str(i)].metadata = links_to_metadata[i] i += 1 topology = MagicMock() topology.links = links topology.switches = switches return topology
def test_send_flow_mod(self, mock_buffers_put): """Test _send_flow_mod method.""" switch = get_switch_mock("00:00:00:00:00:00:00:01", 0x04) flow_mod = MagicMock() self.napp._send_flow_mod(switch, flow_mod) mock_buffers_put.assert_called()
def setUp(self): """Execute steps before each tests. Set the server_name_url from kytos/of_core """ self.switch_v0x01 = get_switch_mock("00:00:00:00:00:00:00:01") self.switch_v0x04 = get_switch_mock("00:00:00:00:00:00:00:02") self.switch_v0x01.connection = get_connection_mock( 0x01, get_switch_mock("00:00:00:00:00:00:00:03")) self.switch_v0x04.connection = get_connection_mock( 0x04, get_switch_mock("00:00:00:00:00:00:00:04")) patch('kytos.core.helpers.run_on_thread', lambda x: x).start() # pylint: disable=bad-option-value from napps.kytos.of_core.flow import FlowFactory self.addCleanup(patch.stopall) self.napp = FlowFactory()
class TestFlow(TestCase): """Test OF flow abstraction.""" mock_switch = get_switch_mock("00:00:00:00:00:00:00:01") mock_switch.id = "00:00:00:00:00:00:00:01" expected = { 'id': 'ca11e386e4bb5b0301b775c4640573e7', 'switch': mock_switch.id, 'table_id': 1, 'match': { 'dl_src': '11:22:33:44:55:66' }, 'priority': 2, 'idle_timeout': 3, 'hard_timeout': 4, 'cookie': 5, 'actions': [{ 'action_type': 'set_vlan', 'vlan_id': 6 }], 'stats': {} } def test_flow_mod(self): """Convert a dict to flow and vice-versa.""" for flow_class in Flow01, Flow04: with self.subTest(flow_class=flow_class): flow = flow_class.from_dict(self.expected, self.mock_switch) actual = flow.as_dict() self.assertDictEqual(self.expected, actual) @patch('napps.kytos.of_core.flow.FlowBase._as_of_flow_mod') def test_of_flow_mod(self, mock_flow_mod): """Test convertion from Flow to OFFlow.""" for flow_class in Flow01, Flow04: with self.subTest(flow_class=flow_class): flow = flow_class.from_dict(self.expected, self.mock_switch) flow.as_of_add_flow_mod() mock_flow_mod.assert_called() flow.as_of_delete_flow_mod() mock_flow_mod.assert_called() # pylint: disable = protected-access def test_as_of_flow_mod(self): """Test _as_of_flow_mod.""" mock_command = MagicMock() for flow_class in Flow01, Flow04: with self.subTest(flow_class=flow_class): flow_mod = flow_class.from_dict(self.expected, self.mock_switch) response = flow_mod._as_of_flow_mod(mock_command) self.assertEqual(response.cookie, self.expected['cookie']) self.assertEqual(response.idle_timeout, self.expected['idle_timeout']) self.assertEqual(response.hard_timeout, self.expected['hard_timeout'])
def test_send_napp_event(self, mock_buffers_put): """Test _send_napp_event method.""" switch = get_switch_mock("00:00:00:00:00:00:00:01", 0x04) flow = MagicMock() for command in ['add', 'delete', 'delete_strict', 'error']: self.napp._send_napp_event(switch, flow, command) self.assertEqual(mock_buffers_put.call_count, 4)
def setUp(self): patch('kytos.core.helpers.run_on_thread', lambda x: x).start() # pylint: disable=bad-option-value from napps.kytos.flow_manager.main import Main self.addCleanup(patch.stopall) controller = get_controller_mock() self.switch_01 = get_switch_mock("00:00:00:00:00:00:00:01", 0x04) self.switch_01.is_enabled.return_value = True self.switch_01.flows = [] self.switch_02 = get_switch_mock("00:00:00:00:00:00:00:02", 0x04) self.switch_02.is_enabled.return_value = False self.switch_02.flows = [] controller.switches = {"00:00:00:00:00:00:00:01": self.switch_01, "00:00:00:00:00:00:00:02": self.switch_02} self.napp = Main(controller)
def test_update_switch_flows(self): """Test update_switch_flows.""" dpid = '00:00:00:00:00:00:00:01' mock_switch = get_switch_mock(dpid) mock_switch.id = dpid self.napp._multipart_replies_flows = {dpid: mock_switch} self.napp._multipart_replies_xids = {dpid: {'flows': mock_switch}} self.napp._update_switch_flows(mock_switch) self.assertEqual(self.napp._multipart_replies_xids, {dpid: {}}) self.assertEqual(self.napp._multipart_replies_flows, {})
def test_notify_uplink_detected(self, *args): """Test notify_uplink_detected method.""" (mock_ethernet, mock_lldp, mock_dpid, mock_ubint32, mock_unpack_non_empty, mock_get_switch_by_dpid, mock_kytos_event, mock_buffer_put) = args switch = get_switch_mock("00:00:00:00:00:00:00:01", 0x04) message = MagicMock() message.in_port = 1 message.data = 'data' event = get_kytos_event_mock(name='kytos/of_core.v0x0[14].messages.in.' 'ofpt_packet_in', content={ 'source': switch.connection, 'message': message }) ethernet = MagicMock() ethernet.ether_type = 0x88CC ethernet.data = 'eth_data' lldp = MagicMock() lldp.chassis_id.sub_value = 'chassis_id' lldp.port_id.sub_value = 'port_id' dpid = MagicMock() dpid.value = "00:00:00:00:00:00:00:02" port_b = MagicMock() mock_unpack_non_empty.side_effect = [ethernet, lldp, dpid, port_b] mock_get_switch_by_dpid.return_value = get_switch_mock( dpid.value, 0x04) mock_kytos_event.return_value = 'nni' self.napp.notify_uplink_detected(event) calls = [ call(mock_ethernet, message.data), call(mock_lldp, ethernet.data), call(mock_dpid, lldp.chassis_id.sub_value), call(mock_ubint32, lldp.port_id.sub_value) ] mock_unpack_non_empty.assert_has_calls(calls) mock_buffer_put.assert_called_with('nni')
def test_switch_mock(self): """Test switch mock.""" dpid = "00:00:00:00:00:00:00:01" switch_mock = get_switch_mock(dpid, 0x04) self.assertEqual(switch_mock.dpid, dpid) self.assertEqual(switch_mock.ofp_version, '0x04') self.assertEqual(switch_mock.connection.protocol.version, 0x04) self.assertEqual(switch_mock.connection.switch, switch_mock) self.assertEqual(switch_mock.connection.address, '00:00:00:00:00:00') self.assertEqual(switch_mock.connection.state.value, 0)
def test_fail_restore_link(self): """Test fail restore_link.""" dpid = '00:00:00:00:00:00:00:01' dpid_b = '00:00:00:00:00:00:00:02' link_id = '4d42dc08522' link_id_fail = '4cd52' mock_switch_a = get_switch_mock(dpid) mock_switch_b = get_switch_mock(dpid_b) mock_interface_a_1 = get_interface_mock('s1-eth1', 1, mock_switch_a) mock_interface_b_1 = get_interface_mock('s2-eth1', 1, mock_switch_b) mock_link = get_link_mock(mock_interface_a_1, mock_interface_b_1) mock_link.id = link_id self.napp.links = {link_id: mock_link} self.napp.links_state = {link_id: {"enabled": True}} with self.assertRaises(RestoreError): self.napp._restore_link(link_id_fail) self.napp.links_state = {link_id_fail: {"enabled": True}} with self.assertRaises(RestoreError): self.napp._restore_link(link_id_fail)
def test_flow_mod_goto(self, *args): """Convert a dict to flow and vice-versa.""" (mock_json, _, _) = args dpid = "00:00:00:00:00:00:00:01" mock_json.return_value = str(self.requested_instructions) mock_switch = get_switch_mock(dpid, 0x04) mock_switch.id = dpid flow = Flow04.from_dict(self.requested_instructions, mock_switch) actual = flow.as_dict() del actual['id'] del actual['stats'] self.assertDictEqual(self.requested_instructions, actual)
def get_topology_mock(): """Create a default topology.""" switch_a = get_switch_mock("00:00:00:00:00:00:00:01", 0x04) switch_b = get_switch_mock("00:00:00:00:00:00:00:02", 0x04) switch_c = get_switch_mock("00:00:00:00:00:00:00:03", 0x01) interface_a1 = get_interface_mock("s1-eth1", 1, switch_a) interface_a2 = get_interface_mock("s1-eth2", 2, switch_a) interface_b1 = get_interface_mock("s2-eth1", 1, switch_b) interface_b2 = get_interface_mock("s2-eth2", 2, switch_b) interface_c1 = get_interface_mock("s3-eth1", 1, switch_c) interface_c2 = get_interface_mock("s3-eth2", 2, switch_c) switch_a.interfaces = { interface_a1.id: interface_a1, interface_a2.id: interface_a2 } switch_b.interfaces = { interface_b1.id: interface_b1, interface_b2.id: interface_b2 } switch_c.interfaces = { interface_c1.id: interface_c1, interface_c2.id: interface_c2 } link_1 = get_link_mock(interface_a1, interface_b1) link_2 = get_link_mock(interface_a2, interface_c1) link_3 = get_link_mock(interface_b2, interface_c2) topology = MagicMock() topology.links = {"1": link_1, "2": link_2, "3": link_3} topology.switches = { switch_a.dpid: switch_a, switch_b.dpid: switch_b, switch_c.dpid: switch_c } return topology
def test_flow_mod(self, *args): """Convert a dict to flow and vice-versa.""" (mock_json, _, _) = args dpid = "00:00:00:00:00:00:00:01" mock_json.return_value = str(self.expected) for flow_class, version in [(Flow04, 0x01), (Flow04, 0x04)]: with self.subTest(flow_class=flow_class): mock_switch = get_switch_mock(dpid, version) mock_switch.id = dpid flow = flow_class.from_dict(self.expected, mock_switch) actual = flow.as_dict() del actual['id'] self.assertDictEqual(self.expected, actual)
def test_restore_links(self): """Test restore_link.""" dpid = '00:00:00:00:00:00:00:01' dpid_b = '00:00:00:00:00:00:00:02' link_id = '4d42dc08522' mock_switch_a = get_switch_mock(dpid) mock_switch_b = get_switch_mock(dpid_b) mock_interface_a_1 = get_interface_mock('s1-eth1', 1, mock_switch_a) mock_interface_b_1 = get_interface_mock('s2-eth1', 1, mock_switch_b) mock_link = get_link_mock(mock_interface_a_1, mock_interface_b_1) mock_link.id = link_id self.napp.links = {link_id: mock_link} self.napp.links_state = {link_id: {'enabled': True}} # enable link self.napp.restore_network_status(mock_link) self.assertEqual(mock_link.enable.call_count, 1) # disable link self.napp.links_state = {link_id: {"enabled": False}} self.napp._verified_links = [] self.napp.restore_network_status(mock_link) self.assertEqual(mock_link.disable.call_count, 1)
def test_resend_stored_flows(self, mock_install_flows): """Test resend stored flows.""" dpid = "00:00:00:00:00:00:00:01" switch = get_switch_mock(dpid, 0x04) mock_event = MagicMock() flow = {"command": "add", "flow": MagicMock()} flows = {"flow_list": [flow]} mock_event.content = {"switch": switch} self.napp.controller.switches = {dpid: switch} self.napp.stored_flows = {dpid: flows} self.napp.resend_stored_flows(mock_event) mock_install_flows.assert_called()
def test_event_add_flow(self, mock_install_flows): """Test method for installing flows on the switches through events.""" dpid = "00:00:00:00:00:00:00:01" switch = get_switch_mock(dpid) self.napp.controller.switches = {dpid: switch} mock_flow_dict = MagicMock() event = get_kytos_event_mock(name='kytos.flow_manager.flows.install', content={ 'dpid': dpid, 'flow_dict': mock_flow_dict }) self.napp.event_flows_install_delete(event) mock_install_flows.assert_called_with('add', mock_flow_dict, [switch])