|
@@ 710-812 (lines=103) @@
|
| 707 |
|
# verify add circuit in sched |
| 708 |
|
sched_add_mock.assert_called_once() |
| 709 |
|
|
| 710 |
|
@patch("napps.kytos.mef_eline.main.Main._check_no_tag_duplication") |
| 711 |
|
@patch("napps.kytos.mef_eline.models.evc.EVC._tag_lists_equal") |
| 712 |
|
@patch("napps.kytos.mef_eline.main.Main._use_uni_tags") |
| 713 |
|
@patch("napps.kytos.mef_eline.models.evc.EVC.deploy") |
| 714 |
|
@patch("napps.kytos.mef_eline.scheduler.Scheduler.add") |
| 715 |
|
@patch("napps.kytos.mef_eline.main.Main._uni_from_dict") |
| 716 |
|
@patch("napps.kytos.mef_eline.controllers.ELineController.upsert_evc") |
| 717 |
|
@patch("napps.kytos.mef_eline.main.EVC.as_dict") |
| 718 |
|
@patch("napps.kytos.mef_eline.models.evc.EVC._validate") |
| 719 |
|
async def test_create_a_circuit_case_6( |
| 720 |
|
self, |
| 721 |
|
validate_mock, |
| 722 |
|
evc_as_dict_mock, |
| 723 |
|
mongo_controller_upsert_mock, |
| 724 |
|
uni_from_dict_mock, |
| 725 |
|
sched_add_mock, |
| 726 |
|
evc_deploy_mock, |
| 727 |
|
mock_use_uni_tags, |
| 728 |
|
mock_tags_equal, |
| 729 |
|
mock_check_duplicate |
| 730 |
|
): |
| 731 |
|
"""Test create a new intra circuit with a disabled interface""" |
| 732 |
|
# pylint: disable=too-many-locals |
| 733 |
|
self.napp.controller.loop = asyncio.get_running_loop() |
| 734 |
|
validate_mock.return_value = True |
| 735 |
|
mongo_controller_upsert_mock.return_value = True |
| 736 |
|
evc_deploy_mock.return_value = True |
| 737 |
|
mock_use_uni_tags.return_value = True |
| 738 |
|
mock_tags_equal.return_value = True |
| 739 |
|
mock_check_duplicate.return_value = True |
| 740 |
|
uni1 = create_autospec(UNI) |
| 741 |
|
uni2 = create_autospec(UNI) |
| 742 |
|
uni1.interface = create_autospec(Interface) |
| 743 |
|
uni2.interface = create_autospec(Interface) |
| 744 |
|
switch = MagicMock() |
| 745 |
|
switch.status = EntityStatus.UP |
| 746 |
|
switch.return_value = "00:00:00:00:00:00:00:01" |
| 747 |
|
uni1.interface.switch = switch |
| 748 |
|
uni1.interface.status = EntityStatus.DISABLED |
| 749 |
|
uni2.interface.switch = switch |
| 750 |
|
uni_from_dict_mock.side_effect = [uni1, uni2] |
| 751 |
|
evc_as_dict_mock.return_value = {} |
| 752 |
|
sched_add_mock.return_value = True |
| 753 |
|
self.napp.mongo_controller.get_circuits.return_value = {} |
| 754 |
|
|
| 755 |
|
url = f"{self.base_endpoint}/v2/evc/" |
| 756 |
|
payload = { |
| 757 |
|
"name": "my evc1", |
| 758 |
|
"frequency": "* * * * *", |
| 759 |
|
"uni_a": { |
| 760 |
|
"interface_id": "00:00:00:00:00:00:00:01:1", |
| 761 |
|
"tag": {"tag_type": 'vlan', "value": 80}, |
| 762 |
|
}, |
| 763 |
|
"uni_z": { |
| 764 |
|
"interface_id": "00:00:00:00:00:00:00:01:2", |
| 765 |
|
"tag": {"tag_type": 'vlan', "value": 1}, |
| 766 |
|
}, |
| 767 |
|
"dynamic_backup_path": True, |
| 768 |
|
"primary_constraints": { |
| 769 |
|
"spf_max_path_cost": 8, |
| 770 |
|
"mandatory_metrics": { |
| 771 |
|
"ownership": "red" |
| 772 |
|
} |
| 773 |
|
}, |
| 774 |
|
"secondary_constraints": { |
| 775 |
|
"spf_attribute": "priority", |
| 776 |
|
"mandatory_metrics": { |
| 777 |
|
"ownership": "blue" |
| 778 |
|
} |
| 779 |
|
} |
| 780 |
|
} |
| 781 |
|
|
| 782 |
|
response = await self.api_client.post(url, json=payload) |
| 783 |
|
current_data = response.json() |
| 784 |
|
|
| 785 |
|
# verify expected result from request |
| 786 |
|
assert 201 == response.status_code |
| 787 |
|
assert "circuit_id" in current_data |
| 788 |
|
|
| 789 |
|
# verify uni called |
| 790 |
|
uni_from_dict_mock.called_twice() |
| 791 |
|
uni_from_dict_mock.assert_any_call(payload["uni_z"]) |
| 792 |
|
uni_from_dict_mock.assert_any_call(payload["uni_a"]) |
| 793 |
|
|
| 794 |
|
# verify validation called |
| 795 |
|
validate_mock.assert_called_once() |
| 796 |
|
validate_mock.assert_called_with( |
| 797 |
|
table_group={'evpl': 0, 'epl': 0}, |
| 798 |
|
frequency="* * * * *", |
| 799 |
|
name="my evc1", |
| 800 |
|
uni_a=uni1, |
| 801 |
|
uni_z=uni2, |
| 802 |
|
dynamic_backup_path=True, |
| 803 |
|
primary_constraints=payload["primary_constraints"], |
| 804 |
|
secondary_constraints=payload["secondary_constraints"], |
| 805 |
|
) |
| 806 |
|
# verify save method is called |
| 807 |
|
mongo_controller_upsert_mock.assert_called_once() |
| 808 |
|
|
| 809 |
|
# verify evc as dict is called to save in the box |
| 810 |
|
evc_as_dict_mock.assert_called() |
| 811 |
|
# verify add circuit in sched |
| 812 |
|
sched_add_mock.assert_called_once() |
| 813 |
|
|
| 814 |
|
async def test_create_a_circuit_invalid_queue_id(self): |
| 815 |
|
"""Test create a new circuit with invalid queue_id.""" |
|
@@ 607-708 (lines=102) @@
|
| 604 |
|
response = await self.api_client.post(url, json=payload) |
| 605 |
|
assert 400 == response.status_code, response.data |
| 606 |
|
|
| 607 |
|
@patch("napps.kytos.mef_eline.main.Main._check_no_tag_duplication") |
| 608 |
|
@patch("napps.kytos.mef_eline.models.evc.EVC._tag_lists_equal") |
| 609 |
|
@patch("napps.kytos.mef_eline.main.Main._use_uni_tags") |
| 610 |
|
@patch("napps.kytos.mef_eline.models.evc.EVC.deploy") |
| 611 |
|
@patch("napps.kytos.mef_eline.scheduler.Scheduler.add") |
| 612 |
|
@patch("napps.kytos.mef_eline.main.Main._uni_from_dict") |
| 613 |
|
@patch("napps.kytos.mef_eline.controllers.ELineController.upsert_evc") |
| 614 |
|
@patch("napps.kytos.mef_eline.main.EVC.as_dict") |
| 615 |
|
@patch("napps.kytos.mef_eline.models.evc.EVC._validate") |
| 616 |
|
async def test_create_a_circuit_case_5( |
| 617 |
|
self, |
| 618 |
|
validate_mock, |
| 619 |
|
evc_as_dict_mock, |
| 620 |
|
mongo_controller_upsert_mock, |
| 621 |
|
uni_from_dict_mock, |
| 622 |
|
sched_add_mock, |
| 623 |
|
evc_deploy_mock, |
| 624 |
|
mock_use_uni_tags, |
| 625 |
|
mock_tags_equal, |
| 626 |
|
mock_check_duplicate |
| 627 |
|
): |
| 628 |
|
"""Test create a new intra circuit with a disabled switch""" |
| 629 |
|
# pylint: disable=too-many-locals |
| 630 |
|
self.napp.controller.loop = asyncio.get_running_loop() |
| 631 |
|
validate_mock.return_value = True |
| 632 |
|
mongo_controller_upsert_mock.return_value = True |
| 633 |
|
evc_deploy_mock.return_value = True |
| 634 |
|
mock_use_uni_tags.return_value = True |
| 635 |
|
mock_tags_equal.return_value = True |
| 636 |
|
mock_check_duplicate.return_value = True |
| 637 |
|
uni1 = create_autospec(UNI) |
| 638 |
|
uni2 = create_autospec(UNI) |
| 639 |
|
uni1.interface = create_autospec(Interface) |
| 640 |
|
uni2.interface = create_autospec(Interface) |
| 641 |
|
switch = MagicMock() |
| 642 |
|
switch.status = EntityStatus.DISABLED |
| 643 |
|
switch.return_value = "00:00:00:00:00:00:00:01" |
| 644 |
|
uni1.interface.switch = switch |
| 645 |
|
uni2.interface.switch = switch |
| 646 |
|
uni_from_dict_mock.side_effect = [uni1, uni2] |
| 647 |
|
evc_as_dict_mock.return_value = {} |
| 648 |
|
sched_add_mock.return_value = True |
| 649 |
|
self.napp.mongo_controller.get_circuits.return_value = {} |
| 650 |
|
|
| 651 |
|
url = f"{self.base_endpoint}/v2/evc/" |
| 652 |
|
payload = { |
| 653 |
|
"name": "my evc1", |
| 654 |
|
"frequency": "* * * * *", |
| 655 |
|
"uni_a": { |
| 656 |
|
"interface_id": "00:00:00:00:00:00:00:01:1", |
| 657 |
|
"tag": {"tag_type": 'vlan', "value": 80}, |
| 658 |
|
}, |
| 659 |
|
"uni_z": { |
| 660 |
|
"interface_id": "00:00:00:00:00:00:00:01:2", |
| 661 |
|
"tag": {"tag_type": 'vlan', "value": 1}, |
| 662 |
|
}, |
| 663 |
|
"dynamic_backup_path": True, |
| 664 |
|
"primary_constraints": { |
| 665 |
|
"spf_max_path_cost": 8, |
| 666 |
|
"mandatory_metrics": { |
| 667 |
|
"ownership": "red" |
| 668 |
|
} |
| 669 |
|
}, |
| 670 |
|
"secondary_constraints": { |
| 671 |
|
"spf_attribute": "priority", |
| 672 |
|
"mandatory_metrics": { |
| 673 |
|
"ownership": "blue" |
| 674 |
|
} |
| 675 |
|
} |
| 676 |
|
} |
| 677 |
|
|
| 678 |
|
response = await self.api_client.post(url, json=payload) |
| 679 |
|
current_data = response.json() |
| 680 |
|
|
| 681 |
|
# verify expected result from request |
| 682 |
|
assert 201 == response.status_code |
| 683 |
|
assert "circuit_id" in current_data |
| 684 |
|
|
| 685 |
|
# verify uni called |
| 686 |
|
uni_from_dict_mock.called_twice() |
| 687 |
|
uni_from_dict_mock.assert_any_call(payload["uni_z"]) |
| 688 |
|
uni_from_dict_mock.assert_any_call(payload["uni_a"]) |
| 689 |
|
|
| 690 |
|
# verify validation called |
| 691 |
|
validate_mock.assert_called_once() |
| 692 |
|
validate_mock.assert_called_with( |
| 693 |
|
table_group={'evpl': 0, 'epl': 0}, |
| 694 |
|
frequency="* * * * *", |
| 695 |
|
name="my evc1", |
| 696 |
|
uni_a=uni1, |
| 697 |
|
uni_z=uni2, |
| 698 |
|
dynamic_backup_path=True, |
| 699 |
|
primary_constraints=payload["primary_constraints"], |
| 700 |
|
secondary_constraints=payload["secondary_constraints"], |
| 701 |
|
) |
| 702 |
|
# verify save method is called |
| 703 |
|
mongo_controller_upsert_mock.assert_called_once() |
| 704 |
|
|
| 705 |
|
# verify evc as dict is called to save in the box |
| 706 |
|
evc_as_dict_mock.assert_called() |
| 707 |
|
# verify add circuit in sched |
| 708 |
|
sched_add_mock.assert_called_once() |
| 709 |
|
|
| 710 |
|
@patch("napps.kytos.mef_eline.main.Main._check_no_tag_duplication") |
| 711 |
|
@patch("napps.kytos.mef_eline.models.evc.EVC._tag_lists_equal") |