|
11 | 11 | import com.azure.resourcemanager.authorization.models.BuiltInRole; |
12 | 12 | import com.azure.resourcemanager.authorization.models.RoleAssignment; |
13 | 13 | import com.azure.resourcemanager.compute.fluent.models.VirtualMachineScaleSetInner; |
| 14 | +import com.azure.resourcemanager.compute.models.DeleteOptions; |
| 15 | +import com.azure.resourcemanager.compute.models.DiffDiskPlacement; |
14 | 16 | import com.azure.resourcemanager.compute.models.ImageReference; |
15 | 17 | import com.azure.resourcemanager.compute.models.KnownLinuxVirtualMachineImage; |
16 | 18 | import com.azure.resourcemanager.compute.models.OperatingSystemTypes; |
|
22 | 24 | import com.azure.resourcemanager.compute.models.UpgradeMode; |
23 | 25 | import com.azure.resourcemanager.compute.models.VaultCertificate; |
24 | 26 | import com.azure.resourcemanager.compute.models.VaultSecretGroup; |
| 27 | +import com.azure.resourcemanager.compute.models.VirtualMachine; |
25 | 28 | import com.azure.resourcemanager.compute.models.VirtualMachineEvictionPolicyTypes; |
26 | 29 | import com.azure.resourcemanager.compute.models.VirtualMachineImage; |
27 | 30 | import com.azure.resourcemanager.compute.models.VirtualMachinePriorityTypes; |
|
32 | 35 | import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetVM; |
33 | 36 | import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetVMExpandType; |
34 | 37 | import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetVMs; |
| 38 | +import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes; |
35 | 39 | import com.azure.resourcemanager.keyvault.models.Secret; |
36 | 40 | import com.azure.resourcemanager.keyvault.models.Vault; |
37 | 41 | import com.azure.resourcemanager.network.models.ApplicationSecurityGroup; |
|
59 | 63 | import org.junit.jupiter.api.Test; |
60 | 64 |
|
61 | 65 | import java.io.InputStream; |
| 66 | +import java.lang.reflect.Method; |
62 | 67 | import java.nio.charset.StandardCharsets; |
63 | 68 | import java.time.Duration; |
64 | 69 | import java.util.ArrayList; |
65 | 70 | import java.util.Arrays; |
66 | 71 | import java.util.Collection; |
67 | 72 | import java.util.Collections; |
| 73 | +import java.util.HashSet; |
68 | 74 | import java.util.List; |
69 | 75 | import java.util.Map; |
| 76 | +import java.util.Set; |
70 | 77 | import java.util.stream.Collectors; |
71 | 78 |
|
72 | 79 | public class VirtualMachineScaleSetOperationsTests extends ComputeManagementTest { |
@@ -1741,53 +1748,18 @@ public void npeProtectionTest() throws Exception { |
1741 | 1748 | .withFlexibleOrchestrationMode() |
1742 | 1749 | .create(); |
1743 | 1750 |
|
1744 | | - vmss.orchestrationMode(); |
1745 | | - vmss.computerNamePrefix(); |
1746 | | - vmss.osType(); |
1747 | | - vmss.osDiskCachingType(); |
1748 | | - vmss.osDiskName(); |
1749 | | - vmss.upgradeModel(); |
1750 | | - vmss.overProvisionEnabled(); |
1751 | | - vmss.sku(); |
1752 | | - vmss.capacity(); |
1753 | | - vmss.getPrimaryNetwork(); |
1754 | | - vmss.getPrimaryInternetFacingLoadBalancer(); |
1755 | | - vmss.listPrimaryInternetFacingLoadBalancerBackends(); |
1756 | | - vmss.listPrimaryInternetFacingLoadBalancerInboundNatPools(); |
1757 | | - vmss.getPrimaryInternalLoadBalancer(); |
1758 | | - vmss.listPrimaryInternalLoadBalancerBackends(); |
1759 | | - vmss.listPrimaryInternalLoadBalancerInboundNatPools(); |
1760 | | - vmss.primaryPublicIpAddressIds(); |
1761 | | - vmss.vhdContainers(); |
1762 | | - vmss.storageProfile(); |
1763 | | - vmss.networkProfile(); |
1764 | | - vmss.extensions(); |
1765 | | - vmss.virtualMachinePriority(); |
1766 | | - vmss.billingProfile(); |
1767 | | - vmss.plan(); |
1768 | | - vmss.virtualMachineEvictionPolicy(); |
1769 | | - vmss.listNetworkInterfaces(); |
1770 | | - vmss.isManagedDiskEnabled(); |
1771 | | - vmss.isManagedServiceIdentityEnabled(); |
1772 | | - vmss.systemAssignedManagedServiceIdentityTenantId(); |
1773 | | - vmss.systemAssignedManagedServiceIdentityPrincipalId(); |
1774 | | - vmss.managedServiceIdentityType(); |
1775 | | - vmss.userAssignedManagedServiceIdentityIds(); |
1776 | | - vmss.availabilityZones(); |
1777 | | - vmss.isBootDiagnosticsEnabled(); |
1778 | | - vmss.bootDiagnosticsStorageUri(); |
1779 | | - vmss.managedOSDiskStorageAccountType(); |
1780 | | - vmss.virtualMachinePublicIpConfig(); |
1781 | | - vmss.isIpForwardingEnabled(); |
1782 | | - vmss.isAcceleratedNetworkingEnabled(); |
1783 | | - vmss.networkSecurityGroupId(); |
1784 | | - vmss.isSinglePlacementGroupEnabled(); |
1785 | | - vmss.applicationGatewayBackendAddressPoolsIds(); |
1786 | | - vmss.applicationSecurityGroupIds(); |
1787 | | - vmss.doNotRunExtensionsOnOverprovisionedVMs(); |
1788 | | - vmss.proximityPlacementGroup(); |
1789 | | - vmss.additionalCapabilities(); |
1790 | | - vmss.orchestrationMode(); |
| 1751 | + String excludeMethodsString = "start,startAsync,reimage,reimageAsync,deallocate,deallocateAsync,powerOff,powerOffAsync,restart,restartAsync"; |
| 1752 | + Set<String> excludeMethods = new HashSet<>(Arrays.asList(excludeMethodsString.split(","))); |
| 1753 | + Set<String> invoked = new HashSet<>(); |
| 1754 | + // invoke all the methods with 0 parameters except those from the exclusion set |
| 1755 | + for (Method method : VirtualMachineScaleSet.class.getDeclaredMethods()) { |
| 1756 | + if (!excludeMethods.contains(method.getName()) && method.getParameterCount() == 0) { |
| 1757 | + method.invoke(vmss); |
| 1758 | + invoked.add(method.getName()); |
| 1759 | + } |
| 1760 | + } |
| 1761 | + Assertions.assertTrue(invoked.contains("isEphemeralOSDisk")); |
| 1762 | + Assertions.assertFalse(invoked.contains("start")); |
1791 | 1763 | } |
1792 | 1764 |
|
1793 | 1765 | @Test |
@@ -1850,4 +1822,97 @@ public void canBatchOperateVMSSInstance() { |
1850 | 1822 | VirtualMachineScaleSetVM vmInstance1 = vmss.virtualMachines().getInstance("1"); |
1851 | 1823 | Assertions.assertEquals(PowerState.RUNNING, vmInstance1.powerState()); |
1852 | 1824 | } |
| 1825 | + |
| 1826 | + @Test |
| 1827 | + public void canCreateVMSSWithEphemeralOSDisk() throws Exception { |
| 1828 | + // uniform vmss with ephemeral os disk |
| 1829 | + final String vmssName = generateRandomResourceName("vmss", 10); |
| 1830 | + |
| 1831 | + Network network = this.networkManager |
| 1832 | + .networks() |
| 1833 | + .define("vmssvnet") |
| 1834 | + .withRegion(region) |
| 1835 | + .withNewResourceGroup(rgName) |
| 1836 | + .withAddressSpace("10.0.0.0/28") |
| 1837 | + .withSubnet("subnet1", "10.0.0.0/28") |
| 1838 | + .create(); |
| 1839 | + |
| 1840 | + VirtualMachineScaleSet uniformVMSS = this.computeManager |
| 1841 | + .virtualMachineScaleSets() |
| 1842 | + .define(vmssName) |
| 1843 | + .withRegion(region) |
| 1844 | + .withExistingResourceGroup(rgName) |
| 1845 | + .withSku(VirtualMachineScaleSetSkuTypes.STANDARD_DS1_V2) |
| 1846 | + .withExistingPrimaryNetworkSubnet(network, "subnet1") |
| 1847 | + .withoutPrimaryInternetFacingLoadBalancer() |
| 1848 | + .withoutPrimaryInternalLoadBalancer() |
| 1849 | + .withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_18_04_LTS) |
| 1850 | + .withRootUsername("jvuser") |
| 1851 | + .withSsh(sshPublicKey()) |
| 1852 | + .withUpgradeMode(UpgradeMode.AUTOMATIC) |
| 1853 | + .withEphemeralOSDisk() |
| 1854 | + .withPlacement(DiffDiskPlacement.CACHE_DISK) |
| 1855 | + .withCapacity(2) |
| 1856 | + .create(); |
| 1857 | + Assertions.assertTrue(uniformVMSS.isEphemeralOSDisk()); |
| 1858 | + |
| 1859 | + // flex vmss with ephemeral os disk |
| 1860 | + Network network2 = |
| 1861 | + this |
| 1862 | + .networkManager |
| 1863 | + .networks() |
| 1864 | + .define("vmssvnet2") |
| 1865 | + .withRegion(region) |
| 1866 | + .withExistingResourceGroup(rgName) |
| 1867 | + .withAddressSpace("10.1.0.0/16") |
| 1868 | + .withSubnet("subnet1", "10.1.0.0/16") |
| 1869 | + .create(); |
| 1870 | + LoadBalancer publicLoadBalancer = createHttpLoadBalancers(region, this.resourceManager.resourceGroups().getByName(rgName), "1", LoadBalancerSkuType.STANDARD, PublicIPSkuType.STANDARD, true); |
| 1871 | + |
| 1872 | + final String vmssName1 = generateRandomResourceName("vmss", 10); |
| 1873 | + VirtualMachineScaleSet flexVMSS = this.computeManager |
| 1874 | + .virtualMachineScaleSets() |
| 1875 | + .define(vmssName1) |
| 1876 | + .withRegion(region) |
| 1877 | + .withNewResourceGroup(rgName) |
| 1878 | + .withFlexibleOrchestrationMode() |
| 1879 | + .withSku(VirtualMachineScaleSetSkuTypes.STANDARD_DS1_V2) |
| 1880 | + .withExistingPrimaryNetworkSubnet(network2, "subnet1") |
| 1881 | + .withExistingPrimaryInternetFacingLoadBalancer(publicLoadBalancer) |
| 1882 | + .withoutPrimaryInternalLoadBalancer() |
| 1883 | + .withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS) |
| 1884 | + .withRootUsername("jvuser") |
| 1885 | + .withSsh(sshPublicKey()) |
| 1886 | + .withEphemeralOSDisk() |
| 1887 | + .withPlacement(DiffDiskPlacement.CACHE_DISK) |
| 1888 | + .create(); |
| 1889 | + Assertions.assertTrue(flexVMSS.isEphemeralOSDisk()); |
| 1890 | + VirtualMachine instance1 = this.computeManager |
| 1891 | + .virtualMachines() |
| 1892 | + .getById(flexVMSS.virtualMachines().list().stream().iterator().next().id()); |
| 1893 | + Assertions.assertTrue(instance1.isOSDiskEphemeral()); |
| 1894 | + |
| 1895 | + // can add vm with non-ephemeral os disk to flex vmss with ephemeral os disk vm profile |
| 1896 | + final String vmName = generateRandomResourceName("vm", 10); |
| 1897 | + VirtualMachine vm = this.computeManager |
| 1898 | + .virtualMachines() |
| 1899 | + .define(vmName) |
| 1900 | + .withRegion(region) |
| 1901 | + .withNewResourceGroup(rgName) |
| 1902 | + .withExistingPrimaryNetwork(network2) |
| 1903 | + .withSubnet("subnet1") |
| 1904 | + .withPrimaryPrivateIPAddressDynamic() |
| 1905 | + .withoutPrimaryPublicIPAddress() |
| 1906 | + .withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_18_04_LTS) |
| 1907 | + .withRootUsername("Foo12") |
| 1908 | + .withSsh(sshPublicKey()) |
| 1909 | + .withSize(VirtualMachineSizeTypes.STANDARD_DS1_V2) |
| 1910 | + .withPrimaryNetworkInterfaceDeleteOptions(DeleteOptions.DELETE) |
| 1911 | + .withExistingVirtualMachineScaleSet(flexVMSS) |
| 1912 | + .create(); |
| 1913 | + Assertions.assertEquals(vm.virtualMachineScaleSetId(), flexVMSS.id()); |
| 1914 | + // flex vmss can have a mixed set of VMs with ephemeral and non-ephemeral os disk |
| 1915 | + // which contradicts the FAQ: https://docs.microsoft.com/en-us/azure/virtual-machines/ephemeral-os-disks#frequently-asked-questions |
| 1916 | + Assertions.assertFalse(vm.isOSDiskEphemeral()); |
| 1917 | + } |
1853 | 1918 | } |
0 commit comments