|
@@ 156-202 (lines=47) @@
|
| 153 |
|
deployed = evc.deploy_to('primary_path', evc.primary_path) |
| 154 |
|
self.assertFalse(deployed) |
| 155 |
|
|
| 156 |
|
@patch('napps.kytos.mef_eline.models.log') |
| 157 |
|
@patch('napps.kytos.mef_eline.models.EVCDeploy._send_flow_mods') |
| 158 |
|
@patch('napps.kytos.mef_eline.models.LinkProtection.deploy_to_backup_path') |
| 159 |
|
@patch('napps.kytos.mef_eline.models.EVCDeploy.deploy') |
| 160 |
|
@patch('napps.kytos.mef_eline.models.Path.status') |
| 161 |
|
def test_handle_link_down_case_1(self, path_status_mocked, |
| 162 |
|
deploy_mocked, deploy_to_mocked, |
| 163 |
|
_send_flow_mods_mocked, log_mocked): |
| 164 |
|
"""Test if deploy_to backup path is called.""" |
| 165 |
|
deploy_mocked.return_value = True |
| 166 |
|
path_status_mocked.side_effect = [EntityStatus.DOWN, EntityStatus.UP] |
| 167 |
|
|
| 168 |
|
primary_path = [ |
| 169 |
|
get_link_mocked(endpoint_a_port=9, endpoint_b_port=10, |
| 170 |
|
metadata={"s_vlan": 5}, |
| 171 |
|
status=EntityStatus.DOWN), |
| 172 |
|
get_link_mocked(endpoint_a_port=11, endpoint_b_port=12, |
| 173 |
|
metadata={"s_vlan": 6}, |
| 174 |
|
status=EntityStatus.UP), |
| 175 |
|
] |
| 176 |
|
backup_path = [ |
| 177 |
|
get_link_mocked(endpoint_a_port=9, endpoint_b_port=10, |
| 178 |
|
metadata={"s_vlan": 5}, |
| 179 |
|
status=EntityStatus.UP), |
| 180 |
|
get_link_mocked(endpoint_a_port=11, endpoint_b_port=12, |
| 181 |
|
metadata={"s_vlan": 6}, |
| 182 |
|
status=EntityStatus.UP), |
| 183 |
|
] |
| 184 |
|
attributes = { |
| 185 |
|
"controller": get_controller_mock(), |
| 186 |
|
"name": "circuit_name", |
| 187 |
|
"uni_a": get_uni_mocked(is_valid=True), |
| 188 |
|
"uni_z": get_uni_mocked(is_valid=True), |
| 189 |
|
"primary_path": primary_path, |
| 190 |
|
"backup_path": backup_path, |
| 191 |
|
"enabled": True |
| 192 |
|
} |
| 193 |
|
evc = EVC(**attributes) |
| 194 |
|
|
| 195 |
|
evc.current_path = evc.primary_path |
| 196 |
|
current_handle_link_down = evc.handle_link_down() |
| 197 |
|
self.assertEqual(deploy_mocked.call_count, 0) |
| 198 |
|
deploy_to_mocked.assert_called_once() |
| 199 |
|
|
| 200 |
|
self.assertTrue(current_handle_link_down) |
| 201 |
|
msg = f"{evc} deployed after link down." |
| 202 |
|
log_mocked.debug.assert_called_once_with(msg) |
| 203 |
|
|
| 204 |
|
@patch('napps.kytos.mef_eline.models.log') |
| 205 |
|
@patch('napps.kytos.mef_eline.models.EVCDeploy.deploy') |
|
@@ 204-248 (lines=45) @@
|
| 201 |
|
msg = f"{evc} deployed after link down." |
| 202 |
|
log_mocked.debug.assert_called_once_with(msg) |
| 203 |
|
|
| 204 |
|
@patch('napps.kytos.mef_eline.models.log') |
| 205 |
|
@patch('napps.kytos.mef_eline.models.EVCDeploy.deploy') |
| 206 |
|
@patch(DEPLOY_TO_PRIMARY_PATH) |
| 207 |
|
@patch('napps.kytos.mef_eline.models.Path.status') |
| 208 |
|
def test_handle_link_down_case_2(self, path_status_mocked, |
| 209 |
|
deploy_to_mocked, deploy_mocked, |
| 210 |
|
log_mocked): |
| 211 |
|
"""Test if deploy_to backup path is called.""" |
| 212 |
|
deploy_mocked.return_value = True |
| 213 |
|
deploy_to_mocked.return_value = True |
| 214 |
|
path_status_mocked.side_effect = [EntityStatus.UP, EntityStatus.DOWN] |
| 215 |
|
primary_path = [ |
| 216 |
|
get_link_mocked(endpoint_a_port=7, endpoint_b_port=8, |
| 217 |
|
metadata={"s_vlan": 5}, |
| 218 |
|
status=EntityStatus.UP), |
| 219 |
|
get_link_mocked(endpoint_a_port=11, endpoint_b_port=12, |
| 220 |
|
metadata={"s_vlan": 6}, |
| 221 |
|
status=EntityStatus.UP), |
| 222 |
|
] |
| 223 |
|
backup_path = [ |
| 224 |
|
get_link_mocked(endpoint_a_port=9, endpoint_b_port=10, |
| 225 |
|
metadata={"s_vlan": 5}, |
| 226 |
|
status=EntityStatus.DOWN), |
| 227 |
|
get_link_mocked(endpoint_a_port=11, endpoint_b_port=12, |
| 228 |
|
metadata={"s_vlan": 6}, |
| 229 |
|
status=EntityStatus.UP), |
| 230 |
|
] |
| 231 |
|
attributes = { |
| 232 |
|
"controller": get_controller_mock(), |
| 233 |
|
"name": "circuit_name", |
| 234 |
|
"uni_a": get_uni_mocked(is_valid=True), |
| 235 |
|
"uni_z": get_uni_mocked(is_valid=True), |
| 236 |
|
"primary_path": primary_path, |
| 237 |
|
"backup_path": backup_path, |
| 238 |
|
"enabled": True |
| 239 |
|
} |
| 240 |
|
|
| 241 |
|
evc = EVC(**attributes) |
| 242 |
|
evc.current_path = evc.backup_path |
| 243 |
|
current_handle_link_down = evc.handle_link_down() |
| 244 |
|
self.assertEqual(deploy_mocked.call_count, 0) |
| 245 |
|
deploy_to_mocked.assert_called_once() |
| 246 |
|
self.assertTrue(current_handle_link_down) |
| 247 |
|
msg = f"{evc} deployed after link down." |
| 248 |
|
log_mocked.debug.assert_called_once_with(msg) |
| 249 |
|
|
| 250 |
|
@patch('napps.kytos.mef_eline.models.log') |
| 251 |
|
@patch('napps.kytos.mef_eline.models.EVCDeploy.deploy') |