|
37 | 37 | CONST_MANAGED_CLUSTER_SKU_NAME_AUTOMATIC, |
38 | 38 | CONST_GPU_DRIVER_NONE, |
39 | 39 | CONST_NODEPOOL_MODE_MANAGEDSYSTEM, |
| 40 | + CONST_NODEPOOL_MODE_MACHINES, |
40 | 41 | ) |
41 | 42 | from azure.cli.command_modules.acs.agentpool_decorator import AKSAgentPoolParamDict |
42 | 43 | from azure.cli.command_modules.acs.tests.latest.mocks import ( |
@@ -1724,6 +1725,41 @@ def common_set_up_managed_system_mode(self): |
1724 | 1725 | # Verify that agentpool is returned unchanged |
1725 | 1726 | self.assertEqual(dec_agentpool_3, original_agentpool_3) |
1726 | 1727 |
|
| 1728 | + def common_set_up_machines_mode(self): |
| 1729 | + dec_1 = AKSPreviewAgentPoolAddDecorator( |
| 1730 | + self.cmd, |
| 1731 | + self.client, |
| 1732 | + {"mode": CONST_NODEPOOL_MODE_MACHINES}, |
| 1733 | + self.resource_type, |
| 1734 | + self.agentpool_decorator_mode, |
| 1735 | + ) |
| 1736 | + |
| 1737 | + # fail on passing the wrong agentpool object |
| 1738 | + with self.assertRaises(CLIInternalError): |
| 1739 | + dec_1.set_up_machines_mode(None) |
| 1740 | + |
| 1741 | + # Create an agentpool with various properties set |
| 1742 | + agentpool_1 = self.create_initialized_agentpool_instance( |
| 1743 | + restore_defaults=False, |
| 1744 | + count=3, |
| 1745 | + vm_size="Standard_D2s_v3", |
| 1746 | + os_type="Linux", |
| 1747 | + enable_auto_scaling=True, |
| 1748 | + min_count=1, |
| 1749 | + max_count=5, |
| 1750 | + ) |
| 1751 | + dec_1.context.attach_agentpool(agentpool_1) |
| 1752 | + |
| 1753 | + original_name = agentpool_1.name |
| 1754 | + dec_agentpool_1 = dec_1.set_up_machines_mode(agentpool_1) |
| 1755 | + self.assertEqual(dec_agentpool_1.name, original_name) |
| 1756 | + self.assertEqual(dec_agentpool_1.mode, CONST_NODEPOOL_MODE_MACHINES) |
| 1757 | + for attr_name in vars(dec_agentpool_1): |
| 1758 | + if attr_name not in ['name', 'mode'] and not attr_name.startswith('_'): |
| 1759 | + attr_value = getattr(dec_agentpool_1, attr_name) |
| 1760 | + self.assertIsNone(attr_value, |
| 1761 | + f"Attribute '{attr_name}' should be None but was '{attr_value}'") |
| 1762 | + |
1727 | 1763 | def common_construct_agentpool_profile_preview_with_managed_system_mode(self): |
1728 | 1764 | """Test that construct_agentpool_profile_preview properly handles ManagedSystem mode""" |
1729 | 1765 |
|
@@ -1765,6 +1801,47 @@ def common_construct_agentpool_profile_preview_with_managed_system_mode(self): |
1765 | 1801 | self.assertIsNone(attr_value, |
1766 | 1802 | f"Attribute '{attr_name}' should be None but was '{attr_value}' when mode is ManagedSystem") |
1767 | 1803 |
|
| 1804 | + def common_construct_agentpool_profile_preview_with_machines_mode(self): |
| 1805 | + """Test that construct_agentpool_profile_preview properly handles Machines mode""" |
| 1806 | + |
| 1807 | + # Test that when mode is Machines, only name and mode are preserved, |
| 1808 | + # and all other property setup methods are bypassed |
| 1809 | + dec = AKSPreviewAgentPoolAddDecorator( |
| 1810 | + self.cmd, |
| 1811 | + self.client, |
| 1812 | + { |
| 1813 | + "nodepool_name": "testnp", |
| 1814 | + "mode": CONST_NODEPOOL_MODE_MACHINES, |
| 1815 | + # Add some parameters that would normally set properties |
| 1816 | + "node_count": 3, |
| 1817 | + "node_vm_size": "Standard_D2s_v3", |
| 1818 | + "crg_id": "test_crg_id", |
| 1819 | + "enable_artifact_streaming": True, |
| 1820 | + }, |
| 1821 | + self.resource_type, |
| 1822 | + self.agentpool_decorator_mode, |
| 1823 | + ) |
| 1824 | + |
| 1825 | + # Construct the agentpool profile with mocked Azure API calls |
| 1826 | + with patch( |
| 1827 | + "azext_aks_preview.agentpool_decorator.cf_agent_pools", |
| 1828 | + return_value=Mock(list=Mock(return_value=[])), |
| 1829 | + ): |
| 1830 | + agentpool = dec.construct_agentpool_profile_preview() |
| 1831 | + |
| 1832 | + # Verify that name is preserved |
| 1833 | + self.assertEqual(agentpool.name, "testnp") |
| 1834 | + |
| 1835 | + # Verify that mode is set to Machines |
| 1836 | + self.assertEqual(agentpool.mode, CONST_NODEPOOL_MODE_MACHINES) |
| 1837 | + |
| 1838 | + # Verify that all other properties are None (bypassed) |
| 1839 | + for attr_name in vars(agentpool): |
| 1840 | + if attr_name not in ['name', 'mode'] and not attr_name.startswith('_'): |
| 1841 | + attr_value = getattr(agentpool, attr_name) |
| 1842 | + self.assertIsNone(attr_value, |
| 1843 | + f"Attribute '{attr_name}' should be None but was '{attr_value}' when mode is Machines") |
| 1844 | + |
1768 | 1845 | def common_set_up_upgrade_strategy(self): |
1769 | 1846 | # Test case 1: No upgrade strategy provided |
1770 | 1847 | dec_1 = AKSPreviewAgentPoolAddDecorator( |
@@ -1946,6 +2023,9 @@ def test_set_up_virtual_machines_profile(self): |
1946 | 2023 | def test_set_up_managed_system_mode(self): |
1947 | 2024 | self.common_set_up_managed_system_mode() |
1948 | 2025 |
|
| 2026 | + def test_set_up_machines_mode(self): |
| 2027 | + self.common_set_up_machines_mode() |
| 2028 | + |
1949 | 2029 | def test_set_up_upgrade_strategy(self): |
1950 | 2030 | self.common_set_up_upgrade_strategy() |
1951 | 2031 |
|
@@ -2034,6 +2114,9 @@ def test_set_up_blue_green_upgrade_settings(self): |
2034 | 2114 | def test_construct_agentpool_profile_preview_with_managed_system_mode(self): |
2035 | 2115 | self.common_construct_agentpool_profile_preview_with_managed_system_mode() |
2036 | 2116 |
|
| 2117 | + def test_construct_agentpool_profile_preview_with_machines_mode(self): |
| 2118 | + self.common_construct_agentpool_profile_preview_with_machines_mode() |
| 2119 | + |
2037 | 2120 |
|
2038 | 2121 | class AKSPreviewAgentPoolAddDecoratorManagedClusterModeTestCase( |
2039 | 2122 | AKSPreviewAgentPoolAddDecoratorCommonTestCase |
@@ -2083,6 +2166,9 @@ def test_set_up_virtual_machines_profile(self): |
2083 | 2166 | def test_set_up_managed_system_mode(self): |
2084 | 2167 | self.common_set_up_managed_system_mode() |
2085 | 2168 |
|
| 2169 | + def test_set_up_machines_mode(self): |
| 2170 | + self.common_set_up_machines_mode() |
| 2171 | + |
2086 | 2172 | def test_set_up_upgrade_strategy(self): |
2087 | 2173 | self.common_set_up_upgrade_strategy() |
2088 | 2174 |
|
|
0 commit comments