|
12 | 12 | # under the License.
|
13 | 13 | #
|
14 | 14 |
|
| 15 | +from collections import abc |
15 | 16 | import copy
|
16 | 17 | from unittest import mock
|
17 | 18 | import uuid
|
@@ -695,6 +696,89 @@ def test_modify_static_route_external_ids(self):
|
695 | 696 |
|
696 | 697 | self.assertEqual(external_ids, lr.static_routes[0].external_ids)
|
697 | 698 |
|
| 699 | + def _cleanup_delete_hcg(self, hcg_name): |
| 700 | + if isinstance(hcg_name, str): |
| 701 | + self.nbapi.db_destroy('HA_Chassis_Group', hcg_name).execute( |
| 702 | + check_error=True) |
| 703 | + elif isinstance(hcg_name, abc.Iterable): |
| 704 | + for _hcg_name in hcg_name: |
| 705 | + self.nbapi.db_destroy('HA_Chassis_Group', _hcg_name).execute( |
| 706 | + check_error=True) |
| 707 | + |
| 708 | + def _check_hcg(self, hcg, hcg_name, chassis_priority, |
| 709 | + chassis_priority_deleted=None): |
| 710 | + self.assertEqual(hcg_name, hcg.name) |
| 711 | + self.assertEqual(len(chassis_priority), len(hcg.ha_chassis)) |
| 712 | + for hc in hcg.ha_chassis: |
| 713 | + self.assertEqual(chassis_priority[hc.chassis_name], hc.priority) |
| 714 | + |
| 715 | + if chassis_priority_deleted: |
| 716 | + for hc_name in chassis_priority_deleted: |
| 717 | + self.assertIsNone( |
| 718 | + self.nbapi.lookup('HA_Chassis', hc_name, default=None)) |
| 719 | + |
| 720 | + def test_ha_chassis_group_with_hc_add_no_existing_hcg(self): |
| 721 | + chassis_priority = {'ch1': 1, 'ch2': 2, 'ch3': 3, 'ch4': 4} |
| 722 | + hcg_name = uuidutils.generate_uuid() |
| 723 | + self.addCleanup(self._cleanup_delete_hcg, hcg_name) |
| 724 | + hcg = self.nbapi.ha_chassis_group_with_hc_add( |
| 725 | + hcg_name, chassis_priority).execute(check_error=True) |
| 726 | + self._check_hcg(hcg, hcg_name, chassis_priority) |
| 727 | + |
| 728 | + def test_ha_chassis_group_with_hc_add_existing_hcg(self): |
| 729 | + chassis_priority = {'ch1': 1, 'ch2': 2, 'ch3': 3, 'ch4': 4} |
| 730 | + hcg_name = uuidutils.generate_uuid() |
| 731 | + self.addCleanup(self._cleanup_delete_hcg, hcg_name) |
| 732 | + self.nbapi.ha_chassis_group_with_hc_add( |
| 733 | + hcg_name, chassis_priority).execute(check_error=True) |
| 734 | + cmd = self.nbapi.ha_chassis_group_with_hc_add( |
| 735 | + hcg_name, chassis_priority) |
| 736 | + self.assertRaises(RuntimeError, cmd.execute, check_error=True) |
| 737 | + |
| 738 | + def test_ha_chassis_group_with_hc_add_existing_hcg_may_exist(self): |
| 739 | + chassis_priority = {'ch1': 1, 'ch2': 2, 'ch3': 3, 'ch4': 4} |
| 740 | + hcg_name = uuidutils.generate_uuid() |
| 741 | + self.addCleanup(self._cleanup_delete_hcg, hcg_name) |
| 742 | + hcg = None |
| 743 | + for _ in range(2): |
| 744 | + hcg = self.nbapi.ha_chassis_group_with_hc_add( |
| 745 | + hcg_name, chassis_priority, may_exist=True).execute( |
| 746 | + check_error=True) |
| 747 | + self._check_hcg(hcg, hcg_name, chassis_priority) |
| 748 | + |
| 749 | + def test_ha_chassis_group_with_hc_add_existing_hcg_update_chassis(self): |
| 750 | + # This test: |
| 751 | + # - adds new chassis: ch5, ch6 |
| 752 | + # - removes others: ch3, ch4 |
| 753 | + # - changes the priority of the existing ones ch1, ch2 |
| 754 | + chassis_priority = {'ch1': 1, 'ch2': 2, 'ch3': 3, 'ch4': 4} |
| 755 | + hcg_name = uuidutils.generate_uuid() |
| 756 | + self.addCleanup(self._cleanup_delete_hcg, hcg_name) |
| 757 | + self.nbapi.ha_chassis_group_with_hc_add( |
| 758 | + hcg_name, chassis_priority).execute(check_error=True) |
| 759 | + |
| 760 | + chassis_priority = {'ch1': 2, 'ch2': 1, 'ch5': 3, 'ch6': 4} |
| 761 | + hcg = self.nbapi.ha_chassis_group_with_hc_add( |
| 762 | + hcg_name, chassis_priority, may_exist=True).execute( |
| 763 | + check_error=True) |
| 764 | + self._check_hcg(hcg, hcg_name, chassis_priority, |
| 765 | + chassis_priority_deleted=['ch3', 'ch4']) |
| 766 | + |
| 767 | + def test_ha_chassis_group_with_hc_add_two_hcg(self): |
| 768 | + # Both HCG will have the same chassis priority (the same chassis |
| 769 | + # names, that is something very common. |
| 770 | + chassis_priority1 = {'ch1': 1, 'ch2': 2, 'ch3': 3, 'ch4': 4} |
| 771 | + chassis_priority2 = {'ch1': 11, 'ch2': 12, 'ch3': 13, 'ch4': 14} |
| 772 | + hcg_name1 = uuidutils.generate_uuid() |
| 773 | + hcg_name2 = uuidutils.generate_uuid() |
| 774 | + self.addCleanup(self._cleanup_delete_hcg, [hcg_name1, hcg_name2]) |
| 775 | + hcg1 = self.nbapi.ha_chassis_group_with_hc_add( |
| 776 | + hcg_name1, chassis_priority1).execute(check_error=True) |
| 777 | + hcg2 = self.nbapi.ha_chassis_group_with_hc_add( |
| 778 | + hcg_name2, chassis_priority2).execute(check_error=True) |
| 779 | + self._check_hcg(hcg1, hcg_name1, chassis_priority1) |
| 780 | + self._check_hcg(hcg2, hcg_name2, chassis_priority2) |
| 781 | + |
698 | 782 |
|
699 | 783 | class TestIgnoreConnectionTimeout(BaseOvnIdlTest):
|
700 | 784 | @classmethod
|
|
0 commit comments