|
@@ 760-812 (lines=53) @@
|
| 757 |
|
assert mock_interface_1.enable.call_count == 0 |
| 758 |
|
assert mock_interface_2.enable.call_count == 0 |
| 759 |
|
|
| 760 |
|
@patch('napps.kytos.topology.main.Main.notify_topology_update') |
| 761 |
|
async def test_disable_interfaces(self, mock_notify_topo): |
| 762 |
|
"""Test disable_interfaces.""" |
| 763 |
|
interface_id = '00:00:00:00:00:00:00:01:1' |
| 764 |
|
dpid = '00:00:00:00:00:00:00:01' |
| 765 |
|
mock_switch = get_switch_mock(dpid) |
| 766 |
|
mock_interface_1 = get_interface_mock('s1-eth1', 1, mock_switch) |
| 767 |
|
mock_interface_2 = get_interface_mock('s1-eth2', 2, mock_switch) |
| 768 |
|
mock_switch.interfaces = {1: mock_interface_1, 2: mock_interface_2} |
| 769 |
|
self.napp.controller.switches = {dpid: mock_switch} |
| 770 |
|
|
| 771 |
|
endpoint = f"{self.base_endpoint}/interfaces/{interface_id}/disable" |
| 772 |
|
response = await self.api_client.post(endpoint) |
| 773 |
|
assert response.status_code == 200 |
| 774 |
|
|
| 775 |
|
self.napp.topo_controller.disable_interface.assert_called_with( |
| 776 |
|
interface_id |
| 777 |
|
) |
| 778 |
|
assert mock_interface_1.disable.call_count == 1 |
| 779 |
|
assert mock_interface_2.disable.call_count == 0 |
| 780 |
|
mock_notify_topo.assert_called() |
| 781 |
|
|
| 782 |
|
mock_interface_1.disable.call_count = 0 |
| 783 |
|
mock_interface_2.disable.call_count = 0 |
| 784 |
|
|
| 785 |
|
endpoint = f"{self.base_endpoint}/interfaces/switch/{dpid}/disable" |
| 786 |
|
response = await self.api_client.post(endpoint) |
| 787 |
|
assert response.status_code == 200 |
| 788 |
|
|
| 789 |
|
self.napp.topo_controller.upsert_switch.assert_called_with( |
| 790 |
|
mock_switch.id, mock_switch.as_dict() |
| 791 |
|
) |
| 792 |
|
assert mock_interface_1.disable.call_count == 1 |
| 793 |
|
assert mock_interface_2.disable.call_count == 1 |
| 794 |
|
|
| 795 |
|
# test interface not found |
| 796 |
|
interface_id = '00:00:00:00:00:00:00:01:3' |
| 797 |
|
mock_interface_1.disable.call_count = 0 |
| 798 |
|
mock_interface_2.disable.call_count = 0 |
| 799 |
|
endpoint = f"{self.base_endpoint}/interfaces/{interface_id}/disable" |
| 800 |
|
response = await self.api_client.post(endpoint) |
| 801 |
|
|
| 802 |
|
assert response.status_code == 404 |
| 803 |
|
assert mock_interface_1.disable.call_count == 0 |
| 804 |
|
assert mock_interface_2.disable.call_count == 0 |
| 805 |
|
|
| 806 |
|
# test switch not found |
| 807 |
|
dpid = '00:00:00:00:00:00:00:02' |
| 808 |
|
endpoint = f"{self.base_endpoint}/interfaces/switch/{dpid}/disable" |
| 809 |
|
response = await self.api_client.post(endpoint) |
| 810 |
|
assert response.status_code == 404 |
| 811 |
|
assert mock_interface_1.disable.call_count == 0 |
| 812 |
|
assert mock_interface_2.disable.call_count == 0 |
| 813 |
|
|
| 814 |
|
async def test_get_interface_metadata(self): |
| 815 |
|
"""Test get_interface_metada.""" |
|
@@ 709-758 (lines=50) @@
|
| 706 |
|
assert mock_metadata_changes.call_count == 1 |
| 707 |
|
assert response.status_code == 404 |
| 708 |
|
|
| 709 |
|
@patch('napps.kytos.topology.main.Main.notify_topology_update') |
| 710 |
|
async def test_enable_interfaces(self, mock_notify_topo): |
| 711 |
|
"""Test enable_interfaces.""" |
| 712 |
|
dpid = '00:00:00:00:00:00:00:01' |
| 713 |
|
mock_switch = get_switch_mock(dpid) |
| 714 |
|
mock_interface_1 = get_interface_mock('s1-eth1', 1, mock_switch) |
| 715 |
|
mock_interface_2 = get_interface_mock('s1-eth2', 2, mock_switch) |
| 716 |
|
mock_switch.interfaces = {1: mock_interface_1, 2: mock_interface_2} |
| 717 |
|
self.napp.controller.switches = {dpid: mock_switch} |
| 718 |
|
|
| 719 |
|
interface_id = '00:00:00:00:00:00:00:01:1' |
| 720 |
|
|
| 721 |
|
endpoint = f"{self.base_endpoint}/interfaces/{interface_id}/enable" |
| 722 |
|
response = await self.api_client.post(endpoint) |
| 723 |
|
assert response.status_code == 200 |
| 724 |
|
assert mock_interface_1.enable.call_count == 1 |
| 725 |
|
assert mock_interface_2.enable.call_count == 0 |
| 726 |
|
self.napp.topo_controller.enable_interface.assert_called_with( |
| 727 |
|
interface_id |
| 728 |
|
) |
| 729 |
|
mock_notify_topo.assert_called() |
| 730 |
|
|
| 731 |
|
mock_interface_1.enable.call_count = 0 |
| 732 |
|
mock_interface_2.enable.call_count = 0 |
| 733 |
|
endpoint = f"{self.base_endpoint}/interfaces/switch/{dpid}/enable" |
| 734 |
|
response = await self.api_client.post(endpoint) |
| 735 |
|
assert response.status_code == 200 |
| 736 |
|
self.napp.topo_controller.upsert_switch.assert_called_with( |
| 737 |
|
mock_switch.id, mock_switch.as_dict() |
| 738 |
|
) |
| 739 |
|
assert mock_interface_1.enable.call_count == 1 |
| 740 |
|
assert mock_interface_2.enable.call_count == 1 |
| 741 |
|
|
| 742 |
|
# test interface not found |
| 743 |
|
interface_id = '00:00:00:00:00:00:00:01:3' |
| 744 |
|
mock_interface_1.enable.call_count = 0 |
| 745 |
|
mock_interface_2.enable.call_count = 0 |
| 746 |
|
endpoint = f"{self.base_endpoint}/interfaces/{interface_id}/enable" |
| 747 |
|
response = await self.api_client.post(endpoint) |
| 748 |
|
assert response.status_code == 404 |
| 749 |
|
assert mock_interface_1.enable.call_count == 0 |
| 750 |
|
assert mock_interface_2.enable.call_count == 0 |
| 751 |
|
|
| 752 |
|
# test switch not found |
| 753 |
|
dpid = '00:00:00:00:00:00:00:02' |
| 754 |
|
endpoint = f"{self.base_endpoint}/interfaces/{interface_id}/enable" |
| 755 |
|
response = await self.api_client.post(endpoint) |
| 756 |
|
assert response.status_code == 404 |
| 757 |
|
assert mock_interface_1.enable.call_count == 0 |
| 758 |
|
assert mock_interface_2.enable.call_count == 0 |
| 759 |
|
|
| 760 |
|
@patch('napps.kytos.topology.main.Main.notify_topology_update') |
| 761 |
|
async def test_disable_interfaces(self, mock_notify_topo): |