|
@@ 2127-2168 (lines=42) @@
|
| 2124 |
|
content={"1": "FailoverEvent1"} |
| 2125 |
|
) |
| 2126 |
|
|
| 2127 |
|
@patch("napps.kytos.mef_eline.main.emit_event") |
| 2128 |
|
@patch("napps.kytos.mef_eline.main.send_flow_mods_http") |
| 2129 |
|
def test_execute_swap_to_failover_exception( |
| 2130 |
|
self, |
| 2131 |
|
send_flow_mods_mock: MagicMock, |
| 2132 |
|
emit_main_mock: MagicMock, |
| 2133 |
|
): |
| 2134 |
|
"""Test handle_link_down method when an exception occurs.""" |
| 2135 |
|
evc1 = MagicMock(id="1") |
| 2136 |
|
good_path = MagicMock(id="GoodPath") |
| 2137 |
|
bad_path = MagicMock(id="BadPath") |
| 2138 |
|
evc1.current_path = bad_path |
| 2139 |
|
evc1.failover_path = good_path |
| 2140 |
|
evc2 = MagicMock(id="2") |
| 2141 |
|
|
| 2142 |
|
self.napp.prepare_swap_to_failover_flow = { |
| 2143 |
|
evc1: {"1": ["Flow1"]}, |
| 2144 |
|
evc2: None |
| 2145 |
|
}.get |
| 2146 |
|
|
| 2147 |
|
self.napp.prepare_swap_to_failover_event = { |
| 2148 |
|
evc1: "FailoverEvent1", |
| 2149 |
|
}.get |
| 2150 |
|
|
| 2151 |
|
send_flow_mods_mock.side_effect = FlowModException( |
| 2152 |
|
"Flowmod failed to send" |
| 2153 |
|
) |
| 2154 |
|
|
| 2155 |
|
success, failure = self.napp.execute_swap_to_failover([evc1, evc2]) |
| 2156 |
|
|
| 2157 |
|
assert success == [] |
| 2158 |
|
assert failure == [evc1, evc2] |
| 2159 |
|
|
| 2160 |
|
send_flow_mods_mock.assert_called_with( |
| 2161 |
|
{"1": ["Flow1"]}, |
| 2162 |
|
"install" |
| 2163 |
|
) |
| 2164 |
|
|
| 2165 |
|
assert evc1.current_path == bad_path |
| 2166 |
|
assert evc1.failover_path == good_path |
| 2167 |
|
|
| 2168 |
|
emit_main_mock.assert_not_called() |
| 2169 |
|
|
| 2170 |
|
@patch("napps.kytos.mef_eline.main.emit_event") |
| 2171 |
|
@patch("napps.kytos.mef_eline.main.send_flow_mods_http") |
|
@@ 2084-2124 (lines=41) @@
|
| 2081 |
|
evc6.as_dict(), |
| 2082 |
|
]) |
| 2083 |
|
|
| 2084 |
|
@patch("napps.kytos.mef_eline.main.emit_event") |
| 2085 |
|
@patch("napps.kytos.mef_eline.main.send_flow_mods_http") |
| 2086 |
|
def test_execute_swap_to_failover( |
| 2087 |
|
self, |
| 2088 |
|
send_flow_mods_mock: MagicMock, |
| 2089 |
|
emit_main_mock: MagicMock, |
| 2090 |
|
): |
| 2091 |
|
"""Test execute_swap_to_failover method.""" |
| 2092 |
|
evc1 = MagicMock(id="1") |
| 2093 |
|
good_path = MagicMock(id="GoodPath") |
| 2094 |
|
bad_path = MagicMock(id="BadPath") |
| 2095 |
|
evc1.current_path = bad_path |
| 2096 |
|
evc1.failover_path = good_path |
| 2097 |
|
evc2 = MagicMock(id="2") |
| 2098 |
|
|
| 2099 |
|
self.napp.prepare_swap_to_failover_flow = { |
| 2100 |
|
evc1: {"1": ["Flow1"]}, |
| 2101 |
|
evc2: None |
| 2102 |
|
}.get |
| 2103 |
|
|
| 2104 |
|
self.napp.prepare_swap_to_failover_event = { |
| 2105 |
|
evc1: "FailoverEvent1", |
| 2106 |
|
}.get |
| 2107 |
|
|
| 2108 |
|
success, failure = self.napp.execute_swap_to_failover([evc1, evc2]) |
| 2109 |
|
|
| 2110 |
|
assert success == [evc1] |
| 2111 |
|
assert failure == [evc2] |
| 2112 |
|
|
| 2113 |
|
send_flow_mods_mock.assert_called_with( |
| 2114 |
|
{"1": ["Flow1"]}, |
| 2115 |
|
"install" |
| 2116 |
|
) |
| 2117 |
|
|
| 2118 |
|
assert evc1.current_path == good_path |
| 2119 |
|
assert evc1.failover_path == bad_path |
| 2120 |
|
|
| 2121 |
|
emit_main_mock.assert_called_with( |
| 2122 |
|
self.napp.controller, |
| 2123 |
|
"failover_link_down", |
| 2124 |
|
content={"1": "FailoverEvent1"} |
| 2125 |
|
) |
| 2126 |
|
|
| 2127 |
|
@patch("napps.kytos.mef_eline.main.emit_event") |