| @@ 605-643 (lines=39) @@ | ||
| 602 | log_mock.info.assert_called_once_with(f"{evc} was deployed.") |
|
| 603 | self.assertTrue(deployed) |
|
| 604 | ||
| 605 | @patch('napps.kytos.mef_eline.models.log') |
|
| 606 | @patch('napps.kytos.mef_eline.models.EVC.choose_vlans') |
|
| 607 | @patch('napps.kytos.mef_eline.models.EVC.install_nni_flows') |
|
| 608 | @patch('napps.kytos.mef_eline.models.EVC.install_uni_flows') |
|
| 609 | @patch('napps.kytos.mef_eline.models.EVC.activate') |
|
| 610 | @patch('napps.kytos.mef_eline.models.EVC.should_deploy') |
|
| 611 | def test_deploy_fail(self, *args): |
|
| 612 | """Test if all methods is ignored when the should_deploy is false.""" |
|
| 613 | (should_deploy_mock, activate_mock, install_uni_flows_mock, |
|
| 614 | install_nni_flows, chose_vlans_mock, log_mock) = args |
|
| 615 | ||
| 616 | should_deploy_mock.return_value = False |
|
| 617 | uni_a = get_uni_mocked(interface_port=2, tag_value=82, |
|
| 618 | switch_id="switch_uni_a", is_valid=True) |
|
| 619 | uni_z = get_uni_mocked(interface_port=3, tag_value=83, |
|
| 620 | switch_id="switch_uni_z", is_valid=True) |
|
| 621 | ||
| 622 | attributes = { |
|
| 623 | "name": "custom_name", |
|
| 624 | "uni_a": uni_a, |
|
| 625 | "uni_z": uni_z, |
|
| 626 | "primary_links": [ |
|
| 627 | get_link_mocked(endpoint_a_port=9, endpoint_b_port=10, |
|
| 628 | metadata={"s_vlan": 5}), |
|
| 629 | get_link_mocked(endpoint_a_port=11, endpoint_b_port=12, |
|
| 630 | metadata={"s_vlan": 6}) |
|
| 631 | ] |
|
| 632 | } |
|
| 633 | ||
| 634 | evc = EVC(**attributes) |
|
| 635 | deployed = evc.deploy() |
|
| 636 | ||
| 637 | self.assertEqual(should_deploy_mock.call_count, 1) |
|
| 638 | self.assertEqual(activate_mock.call_count, 0) |
|
| 639 | self.assertEqual(install_uni_flows_mock.call_count, 0) |
|
| 640 | self.assertEqual(install_nni_flows.call_count, 0) |
|
| 641 | self.assertEqual(chose_vlans_mock.call_count, 0) |
|
| 642 | self.assertEqual(log_mock.info.call_count, 0) |
|
| 643 | self.assertFalse(deployed) |
|
| 644 | ||
| 645 | def test_is_using_backup_path(self): |
|
| 646 | """Test test is using backup path.""" |
|
| @@ 565-603 (lines=39) @@ | ||
| 562 | switch = evc.primary_links[0].endpoint_b.switch |
|
| 563 | send_flow_mods_mock.assert_called_once_with(switch, expected_flow_mods) |
|
| 564 | ||
| 565 | @patch('napps.kytos.mef_eline.models.log') |
|
| 566 | @patch('napps.kytos.mef_eline.models.EVC.choose_vlans') |
|
| 567 | @patch('napps.kytos.mef_eline.models.EVC.install_nni_flows') |
|
| 568 | @patch('napps.kytos.mef_eline.models.EVC.install_uni_flows') |
|
| 569 | @patch('napps.kytos.mef_eline.models.EVC.activate') |
|
| 570 | @patch('napps.kytos.mef_eline.models.EVC.should_deploy') |
|
| 571 | def test_deploy_successfully(self, *args): |
|
| 572 | """Test if all methods to deploy are called.""" |
|
| 573 | (should_deploy_mock, activate_mock, install_uni_flows_mock, |
|
| 574 | install_nni_flows, chose_vlans_mock, log_mock) = args |
|
| 575 | ||
| 576 | should_deploy_mock.return_value = True |
|
| 577 | uni_a = get_uni_mocked(interface_port=2, tag_value=82, |
|
| 578 | switch_id="switch_uni_a", is_valid=True) |
|
| 579 | uni_z = get_uni_mocked(interface_port=3, tag_value=83, |
|
| 580 | switch_id="switch_uni_z", is_valid=True) |
|
| 581 | ||
| 582 | attributes = { |
|
| 583 | "name": "custom_name", |
|
| 584 | "uni_a": uni_a, |
|
| 585 | "uni_z": uni_z, |
|
| 586 | "primary_links": [ |
|
| 587 | get_link_mocked(endpoint_a_port=9, endpoint_b_port=10, |
|
| 588 | metadata={"s_vlan": 5}), |
|
| 589 | get_link_mocked(endpoint_a_port=11, endpoint_b_port=12, |
|
| 590 | metadata={"s_vlan": 6}) |
|
| 591 | ] |
|
| 592 | } |
|
| 593 | ||
| 594 | evc = EVC(**attributes) |
|
| 595 | deployed = evc.deploy() |
|
| 596 | ||
| 597 | self.assertEqual(should_deploy_mock.call_count, 1) |
|
| 598 | self.assertEqual(activate_mock.call_count, 1) |
|
| 599 | self.assertEqual(install_uni_flows_mock.call_count, 1) |
|
| 600 | self.assertEqual(install_nni_flows.call_count, 1) |
|
| 601 | self.assertEqual(chose_vlans_mock.call_count, 1) |
|
| 602 | log_mock.info.assert_called_once_with(f"{evc} was deployed.") |
|
| 603 | self.assertTrue(deployed) |
|
| 604 | ||
| 605 | @patch('napps.kytos.mef_eline.models.log') |
|
| 606 | @patch('napps.kytos.mef_eline.models.EVC.choose_vlans') |
|
| @@ 334-372 (lines=39) @@ | ||
| 331 | log_mock.info.assert_called_once_with(f"{evc} was deployed.") |
|
| 332 | self.assertTrue(deployed) |
|
| 333 | ||
| 334 | @patch('napps.kytos.mef_eline.models.log') |
|
| 335 | @patch('napps.kytos.mef_eline.models.EVC.choose_vlans') |
|
| 336 | @patch('napps.kytos.mef_eline.models.EVC.install_nni_flows') |
|
| 337 | @patch('napps.kytos.mef_eline.models.EVC.install_uni_flows') |
|
| 338 | @patch('napps.kytos.mef_eline.models.EVC.activate') |
|
| 339 | @patch('napps.kytos.mef_eline.models.EVC.should_deploy') |
|
| 340 | def test_deploy_fail(self, *args): |
|
| 341 | """Test if all methods is ignored when the should_deploy is false.""" |
|
| 342 | (should_deploy_mock, activate_mock, install_uni_flows_mock, |
|
| 343 | install_nni_flows, chose_vlans_mock, log_mock) = args |
|
| 344 | ||
| 345 | should_deploy_mock.return_value = False |
|
| 346 | uni_a = get_uni_mocked(interface_port=2, tag_value=82, |
|
| 347 | switch_id="switch_uni_a", is_valid=True) |
|
| 348 | uni_z = get_uni_mocked(interface_port=3, tag_value=83, |
|
| 349 | switch_id="switch_uni_z", is_valid=True) |
|
| 350 | ||
| 351 | attributes = { |
|
| 352 | "name": "custom_name", |
|
| 353 | "uni_a": uni_a, |
|
| 354 | "uni_z": uni_z, |
|
| 355 | "primary_links": [ |
|
| 356 | get_link_mocked(endpoint_a_port=9, endpoint_b_port=10, |
|
| 357 | metadata={"s_vlan": 5}), |
|
| 358 | get_link_mocked(endpoint_a_port=11, endpoint_b_port=12, |
|
| 359 | metadata={"s_vlan": 6}) |
|
| 360 | ] |
|
| 361 | } |
|
| 362 | ||
| 363 | evc = EVC(**attributes) |
|
| 364 | deployed = evc.deploy() |
|
| 365 | ||
| 366 | self.assertEqual(should_deploy_mock.call_count, 1) |
|
| 367 | self.assertEqual(activate_mock.call_count, 0) |
|
| 368 | self.assertEqual(install_uni_flows_mock.call_count, 0) |
|
| 369 | self.assertEqual(install_nni_flows.call_count, 0) |
|
| 370 | self.assertEqual(chose_vlans_mock.call_count, 0) |
|
| 371 | self.assertEqual(log_mock.info.call_count, 0) |
|
| 372 | self.assertFalse(deployed) |
|
| 373 | ||
| @@ 294-332 (lines=39) @@ | ||
| 291 | switch = evc.primary_links[0].endpoint_b.switch |
|
| 292 | send_flow_mods_mock.assert_called_once_with(switch, expected_flow_mods) |
|
| 293 | ||
| 294 | @patch('napps.kytos.mef_eline.models.log') |
|
| 295 | @patch('napps.kytos.mef_eline.models.EVC.choose_vlans') |
|
| 296 | @patch('napps.kytos.mef_eline.models.EVC.install_nni_flows') |
|
| 297 | @patch('napps.kytos.mef_eline.models.EVC.install_uni_flows') |
|
| 298 | @patch('napps.kytos.mef_eline.models.EVC.activate') |
|
| 299 | @patch('napps.kytos.mef_eline.models.EVC.should_deploy') |
|
| 300 | def test_deploy_successfully(self, *args): |
|
| 301 | """Test if all methods to deploy are called.""" |
|
| 302 | (should_deploy_mock, activate_mock, install_uni_flows_mock, |
|
| 303 | install_nni_flows, chose_vlans_mock, log_mock) = args |
|
| 304 | ||
| 305 | should_deploy_mock.return_value = True |
|
| 306 | uni_a = get_uni_mocked(interface_port=2, tag_value=82, |
|
| 307 | switch_id="switch_uni_a", is_valid=True) |
|
| 308 | uni_z = get_uni_mocked(interface_port=3, tag_value=83, |
|
| 309 | switch_id="switch_uni_z", is_valid=True) |
|
| 310 | ||
| 311 | attributes = { |
|
| 312 | "name": "custom_name", |
|
| 313 | "uni_a": uni_a, |
|
| 314 | "uni_z": uni_z, |
|
| 315 | "primary_links": [ |
|
| 316 | get_link_mocked(endpoint_a_port=9, endpoint_b_port=10, |
|
| 317 | metadata={"s_vlan": 5}), |
|
| 318 | get_link_mocked(endpoint_a_port=11, endpoint_b_port=12, |
|
| 319 | metadata={"s_vlan": 6}) |
|
| 320 | ] |
|
| 321 | } |
|
| 322 | ||
| 323 | evc = EVC(**attributes) |
|
| 324 | deployed = evc.deploy(attributes['primary_links']) |
|
| 325 | ||
| 326 | self.assertEqual(should_deploy_mock.call_count, 1) |
|
| 327 | self.assertEqual(activate_mock.call_count, 1) |
|
| 328 | self.assertEqual(install_uni_flows_mock.call_count, 1) |
|
| 329 | self.assertEqual(install_nni_flows.call_count, 1) |
|
| 330 | self.assertEqual(chose_vlans_mock.call_count, 1) |
|
| 331 | log_mock.info.assert_called_once_with(f"{evc} was deployed.") |
|
| 332 | self.assertTrue(deployed) |
|
| 333 | ||
| 334 | @patch('napps.kytos.mef_eline.models.log') |
|
| 335 | @patch('napps.kytos.mef_eline.models.EVC.choose_vlans') |
|