From 831e16408cf3e28c804535e54f4cfa8cce3d58c7 Mon Sep 17 00:00:00 2001 From: hongli750210 Date: Mon, 14 Oct 2024 10:58:09 +0800 Subject: [PATCH 1/8] mgmt, computefleet, add live tests --- .../pom.xml | 12 + .../ComputeFleetManagerTests.java | 284 ++++++++++++++++++ sdk/computefleet/test-resources.bicep | 22 ++ sdk/computefleet/tests.mgmt.yml | 17 ++ 4 files changed, 335 insertions(+) create mode 100644 sdk/computefleet/azure-resourcemanager-computefleet/src/test/java/com/azure/resourcemanager/computefleet/ComputeFleetManagerTests.java create mode 100644 sdk/computefleet/test-resources.bicep create mode 100644 sdk/computefleet/tests.mgmt.yml diff --git a/sdk/computefleet/azure-resourcemanager-computefleet/pom.xml b/sdk/computefleet/azure-resourcemanager-computefleet/pom.xml index 77c4280e28a1a..04bd3cea2d7b4 100644 --- a/sdk/computefleet/azure-resourcemanager-computefleet/pom.xml +++ b/sdk/computefleet/azure-resourcemanager-computefleet/pom.xml @@ -81,5 +81,17 @@ 1.14.0 test + + com.azure.resourcemanager + azure-resourcemanager-resources + 2.43.0 + test + + + com.azure.resourcemanager + azure-resourcemanager-network + 2.43.0 + test + diff --git a/sdk/computefleet/azure-resourcemanager-computefleet/src/test/java/com/azure/resourcemanager/computefleet/ComputeFleetManagerTests.java b/sdk/computefleet/azure-resourcemanager-computefleet/src/test/java/com/azure/resourcemanager/computefleet/ComputeFleetManagerTests.java new file mode 100644 index 0000000000000..9291900f1f4d6 --- /dev/null +++ b/sdk/computefleet/azure-resourcemanager-computefleet/src/test/java/com/azure/resourcemanager/computefleet/ComputeFleetManagerTests.java @@ -0,0 +1,284 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.resourcemanager.computefleet; + +import com.azure.core.credential.TokenCredential; +import com.azure.core.http.policy.HttpLogDetailLevel; +import com.azure.core.http.policy.HttpLogOptions; +import com.azure.core.management.AzureEnvironment; +import com.azure.core.management.Region; +import com.azure.core.management.SubResource; +import com.azure.core.management.profile.AzureProfile; +import com.azure.core.test.TestProxyTestBase; +import com.azure.core.test.annotation.LiveOnly; +import com.azure.core.util.Configuration; +import com.azure.core.util.CoreUtils; +import com.azure.identity.AzurePowerShellCredentialBuilder; +import com.azure.resourcemanager.computefleet.models.ApiEntityReference; +import com.azure.resourcemanager.computefleet.models.BaseVirtualMachineProfile; +import com.azure.resourcemanager.computefleet.models.CachingTypes; +import com.azure.resourcemanager.computefleet.models.ComputeProfile; +import com.azure.resourcemanager.computefleet.models.DeleteOptions; +import com.azure.resourcemanager.computefleet.models.DiskControllerTypes; +import com.azure.resourcemanager.computefleet.models.DiskCreateOptionTypes; +import com.azure.resourcemanager.computefleet.models.DiskDeleteOptionTypes; +import com.azure.resourcemanager.computefleet.models.EvictionPolicy; +import com.azure.resourcemanager.computefleet.models.Fleet; +import com.azure.resourcemanager.computefleet.models.FleetProperties; +import com.azure.resourcemanager.computefleet.models.IPVersion; +import com.azure.resourcemanager.computefleet.models.ImageReference; +import com.azure.resourcemanager.computefleet.models.LinuxConfiguration; +import com.azure.resourcemanager.computefleet.models.NetworkApiVersion; +import com.azure.resourcemanager.computefleet.models.OperatingSystemTypes; +import com.azure.resourcemanager.computefleet.models.PublicIPAddressSku; +import com.azure.resourcemanager.computefleet.models.PublicIPAddressSkuName; +import com.azure.resourcemanager.computefleet.models.PublicIPAddressSkuTier; +import com.azure.resourcemanager.computefleet.models.RegularPriorityAllocationStrategy; +import com.azure.resourcemanager.computefleet.models.RegularPriorityProfile; +import com.azure.resourcemanager.computefleet.models.SpotAllocationStrategy; +import com.azure.resourcemanager.computefleet.models.SpotPriorityProfile; +import com.azure.resourcemanager.computefleet.models.StorageAccountTypes; +import com.azure.resourcemanager.computefleet.models.VirtualMachineScaleSetIPConfiguration; +import com.azure.resourcemanager.computefleet.models.VirtualMachineScaleSetIPConfigurationProperties; +import com.azure.resourcemanager.computefleet.models.VirtualMachineScaleSetManagedDiskParameters; +import com.azure.resourcemanager.computefleet.models.VirtualMachineScaleSetNetworkConfiguration; +import com.azure.resourcemanager.computefleet.models.VirtualMachineScaleSetNetworkConfigurationProperties; +import com.azure.resourcemanager.computefleet.models.VirtualMachineScaleSetNetworkProfile; +import com.azure.resourcemanager.computefleet.models.VirtualMachineScaleSetOSDisk; +import com.azure.resourcemanager.computefleet.models.VirtualMachineScaleSetOSProfile; +import com.azure.resourcemanager.computefleet.models.VirtualMachineScaleSetPublicIPAddressConfiguration; +import com.azure.resourcemanager.computefleet.models.VirtualMachineScaleSetPublicIPAddressConfigurationProperties; +import com.azure.resourcemanager.computefleet.models.VirtualMachineScaleSetStorageProfile; +import com.azure.resourcemanager.computefleet.models.VmSizeProfile; +import com.azure.resourcemanager.network.NetworkManager; +import com.azure.resourcemanager.network.models.IpVersion; +import com.azure.resourcemanager.network.models.Network; +import com.azure.resourcemanager.network.models.PublicIpPrefix; +import com.azure.resourcemanager.network.models.PublicIpPrefixSku; +import com.azure.resourcemanager.network.models.PublicIpPrefixSkuName; +import com.azure.resourcemanager.network.models.PublicIpPrefixSkuTier; +import com.azure.resourcemanager.resources.ResourceManager; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.util.Arrays; +import java.util.Random; +import java.util.UUID; + +public class ComputeFleetManagerTests extends TestProxyTestBase { + private static final Random RANDOM = new Random(); + private static final Region REGION = Region.US_WEST2; + private String resourceGroupName = "rg" + randomPadding(); + private ComputeFleetManager computeFleetManager = null; + private NetworkManager networkManager = null; + private ResourceManager resourceManager; + private boolean testEnv; + + @Override + public void beforeTest() { + final TokenCredential credential = new AzurePowerShellCredentialBuilder().build(); + final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); + + computeFleetManager = ComputeFleetManager + .configure() + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) + .authenticate(credential, profile); + + networkManager = NetworkManager + .configure() + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) + .authenticate(credential, profile); + + resourceManager = ResourceManager + .configure() + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) + .authenticate(credential, profile) + .withDefaultSubscription(); + + // use AZURE_RESOURCE_GROUP_NAME if run in LIVE CI + String testResourceGroup = Configuration.getGlobalConfiguration().get("AZURE_RESOURCE_GROUP_NAME"); + testEnv = !CoreUtils.isNullOrEmpty(testResourceGroup); + if (testEnv) { + resourceGroupName = testResourceGroup; + } else { + resourceManager.resourceGroups() + .define(resourceGroupName) + .withRegion(REGION) + .create(); + } + } + + @Override + protected void afterTest() { + if (!testEnv) { + resourceManager.resourceGroups().beginDeleteByName(resourceGroupName); + } + } + + @Test + @LiveOnly + public void testCreateComputeFleet() { + Fleet fleet = null; + try { + String fleetName = "fleet" + randomPadding(); + String vmName = "vm" + randomPadding(); + String vnetName = "vnet" + randomPadding(); + String publicIpName = "publicIp" + randomPadding(); + String publicIpPrefixName = "publicIpPrefix" + randomPadding(); + String adminUser = "adminUser" + randomPadding(); + String adminPwd = UUID.randomUUID().toString().replace("-", "@").substring(0, 13); + // @embedStart + Network network = networkManager.networks() + .define(vnetName) + .withRegion(REGION) + .withExistingResourceGroup(resourceGroupName) + .withAddressSpace("10.0.0.0/16") + .withSubnet("default", "10.0.0.0/24") + .create(); + + PublicIpPrefix publicIpPrefix = networkManager.publicIpPrefixes() + .define(publicIpPrefixName) + .withRegion(REGION) + .withExistingResourceGroup(resourceGroupName) + .withSku( + new PublicIpPrefixSku() + .withName(PublicIpPrefixSkuName.STANDARD) + .withTier(PublicIpPrefixSkuTier.REGIONAL) + ) + .withPrefixLength(28) + .withPublicIpAddressVersion(IpVersion.IPV4) + .create(); + + fleet = computeFleetManager.fleets() + .define(fleetName) + .withRegion(REGION) + .withExistingResourceGroup(resourceGroupName) + .withProperties( + new FleetProperties() + .withSpotPriorityProfile( + new SpotPriorityProfile() + .withMaintain(true) + .withCapacity(1) + .withEvictionPolicy(EvictionPolicy.DELETE) + .withAllocationStrategy(SpotAllocationStrategy.LOWEST_PRICE) + ) + .withVmSizesProfile( + Arrays.asList( + new VmSizeProfile().withName("Standard_D4s_v3"), + new VmSizeProfile().withName("Standard_D2s_v3"), + new VmSizeProfile().withName("Standard_E2s_v3") + ) + ) + .withComputeProfile( + new ComputeProfile() + .withBaseVirtualMachineProfile( + new BaseVirtualMachineProfile() + .withStorageProfile( + new VirtualMachineScaleSetStorageProfile() + .withImageReference( + new ImageReference() + .withPublisher("canonical") + .withOffer("ubuntu-24_04-lts") + .withSku("server") + .withVersion("latest") + ) + .withOsDisk( + new VirtualMachineScaleSetOSDisk() + .withManagedDisk( + new VirtualMachineScaleSetManagedDiskParameters() + .withStorageAccountType(StorageAccountTypes.PREMIUM_LRS) + ) + .withOsType(OperatingSystemTypes.LINUX) + .withDiskSizeGB(30) + .withCreateOption(DiskCreateOptionTypes.FROM_IMAGE) + .withDeleteOption(DiskDeleteOptionTypes.DELETE) + .withCaching(CachingTypes.READ_WRITE) + ) + .withDiskControllerType(DiskControllerTypes.SCSI) + ) + .withOsProfile( + new VirtualMachineScaleSetOSProfile() + .withComputerNamePrefix(randomPadding()) + .withAdminUsername(adminUser) + .withAdminPassword(adminPwd) + .withLinuxConfiguration( + new LinuxConfiguration().withDisablePasswordAuthentication(false) + ) + ) + .withNetworkProfile( + new VirtualMachineScaleSetNetworkProfile() + .withNetworkInterfaceConfigurations( + Arrays.asList( + new VirtualMachineScaleSetNetworkConfiguration() + .withName(vmName) + .withProperties( + new VirtualMachineScaleSetNetworkConfigurationProperties() + .withPrimary(true) + .withEnableAcceleratedNetworking(false) + .withDeleteOption(DeleteOptions.DELETE) + .withIpConfigurations( + Arrays.asList( + new VirtualMachineScaleSetIPConfiguration() + .withName(vmName) + .withProperties( + new VirtualMachineScaleSetIPConfigurationProperties() + .withPrimary(true) + .withSubnet( + new ApiEntityReference() + .withId(network.subnets().get("default").id()) + ) + .withPublicIPAddressConfiguration( + new VirtualMachineScaleSetPublicIPAddressConfiguration() + .withName(publicIpName) + .withSku( + new PublicIPAddressSku() + .withName(PublicIPAddressSkuName.STANDARD) + .withTier(PublicIPAddressSkuTier.REGIONAL) + ) + .withProperties( + new VirtualMachineScaleSetPublicIPAddressConfigurationProperties() + .withDeleteOption(DeleteOptions.DELETE) + .withPublicIPAddressVersion(IPVersion.IPV4) + .withIdleTimeoutInMinutes(9) + .withPublicIPPrefix( + new SubResource() + .withId(publicIpPrefix.id()) + ) + ) + ) + ) + ) + ) + ) + ) + ) + .withNetworkApiVersion(NetworkApiVersion.TWO_ZERO_TWO_ZERO_ONE_ONE_ZERO_ONE) + ) + ) + .withComputeApiVersion("2024-03-01") + .withPlatformFaultDomainCount(1) + ) + .withRegularPriorityProfile(new RegularPriorityProfile() + .withAllocationStrategy(RegularPriorityAllocationStrategy.LOWEST_PRICE) + .withMinCapacity(1) + .withCapacity(2) + ) + ) + .create(); + // @embedStart + fleet.refresh(); + Assertions.assertEquals(fleetName, fleet.name()); + Assertions.assertEquals(fleetName, computeFleetManager.fleets().getById(fleet.id()).name()); + Assertions.assertTrue(computeFleetManager.fleets().listByResourceGroup(resourceGroupName).stream().findAny().isPresent()); + } finally { + if (fleet != null) { + computeFleetManager.fleets().deleteById(fleet.id()); + } + } + } + + private static String randomPadding() { + return String.format("%05d", Math.abs(RANDOM.nextInt() % 100000)); + } +} diff --git a/sdk/computefleet/test-resources.bicep b/sdk/computefleet/test-resources.bicep new file mode 100644 index 0000000000000..3ff2bac58becc --- /dev/null +++ b/sdk/computefleet/test-resources.bicep @@ -0,0 +1,22 @@ +@description('The tenant id to which the application and resources belong.') +param tenantId string = '72f988bf-86f1-41af-91ab-2d7cd011db47' + +@description('The client id of the service principal used to run tests.') +param testApplicationId string + +@description('This is the object id of the service principal used to run tests.') +param testApplicationOid string + +var contributorRoleId = '/subscriptions/${subscription().subscriptionId}/providers/Microsoft.Authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c' + +resource contributorRoleId_name 'Microsoft.Authorization/roleAssignments@2022-04-01' = { + name: guid('contributorRoleId${resourceGroup().name}') + properties: { + roleDefinitionId: contributorRoleId + principalId: testApplicationOid + } +} + +output AZURE_TENANT_ID string = tenantId +output AZURE_SUBSCRIPTION_ID string = subscription().subscriptionId +output AZURE_RESOURCE_GROUP_NAME string = resourceGroup().name diff --git a/sdk/computefleet/tests.mgmt.yml b/sdk/computefleet/tests.mgmt.yml new file mode 100644 index 0000000000000..c01b98ae1b3ba --- /dev/null +++ b/sdk/computefleet/tests.mgmt.yml @@ -0,0 +1,17 @@ +trigger: none + +pr: none + +extends: + template: /eng/pipelines/templates/stages/archetype-sdk-tests.yml + parameters: + ServiceDirectory: computefleet + Artifacts: + - name: azure-resourcemanager-computefleet + groupId: com.azure.resourcemanager + safeName: azureresourcemanagercomputefleet + Clouds: 'Public' + UseFederatedAuth: true + # Only run tests on Windows to save cost. + MatrixFilters: + - pool=.*(win).* From 628306a7ef65154f3ea4d69fef3f0cbac00940f0 Mon Sep 17 00:00:00 2001 From: hongli750210 Date: Tue, 15 Oct 2024 12:26:10 +0800 Subject: [PATCH 2/8] Fixed comments for pr#42311 --- .../ComputeFleetManagerTests.java | 80 +++++++++---------- 1 file changed, 36 insertions(+), 44 deletions(-) diff --git a/sdk/computefleet/azure-resourcemanager-computefleet/src/test/java/com/azure/resourcemanager/computefleet/ComputeFleetManagerTests.java b/sdk/computefleet/azure-resourcemanager-computefleet/src/test/java/com/azure/resourcemanager/computefleet/ComputeFleetManagerTests.java index 9291900f1f4d6..d317b5a518b33 100644 --- a/sdk/computefleet/azure-resourcemanager-computefleet/src/test/java/com/azure/resourcemanager/computefleet/ComputeFleetManagerTests.java +++ b/sdk/computefleet/azure-resourcemanager-computefleet/src/test/java/com/azure/resourcemanager/computefleet/ComputeFleetManagerTests.java @@ -8,13 +8,12 @@ import com.azure.core.http.policy.HttpLogOptions; import com.azure.core.management.AzureEnvironment; import com.azure.core.management.Region; -import com.azure.core.management.SubResource; import com.azure.core.management.profile.AzureProfile; import com.azure.core.test.TestProxyTestBase; import com.azure.core.test.annotation.LiveOnly; import com.azure.core.util.Configuration; import com.azure.core.util.CoreUtils; -import com.azure.identity.AzurePowerShellCredentialBuilder; +import com.azure.identity.DefaultAzureCredentialBuilder; import com.azure.resourcemanager.computefleet.models.ApiEntityReference; import com.azure.resourcemanager.computefleet.models.BaseVirtualMachineProfile; import com.azure.resourcemanager.computefleet.models.CachingTypes; @@ -26,14 +25,10 @@ import com.azure.resourcemanager.computefleet.models.EvictionPolicy; import com.azure.resourcemanager.computefleet.models.Fleet; import com.azure.resourcemanager.computefleet.models.FleetProperties; -import com.azure.resourcemanager.computefleet.models.IPVersion; import com.azure.resourcemanager.computefleet.models.ImageReference; import com.azure.resourcemanager.computefleet.models.LinuxConfiguration; import com.azure.resourcemanager.computefleet.models.NetworkApiVersion; import com.azure.resourcemanager.computefleet.models.OperatingSystemTypes; -import com.azure.resourcemanager.computefleet.models.PublicIPAddressSku; -import com.azure.resourcemanager.computefleet.models.PublicIPAddressSkuName; -import com.azure.resourcemanager.computefleet.models.PublicIPAddressSkuTier; import com.azure.resourcemanager.computefleet.models.RegularPriorityAllocationStrategy; import com.azure.resourcemanager.computefleet.models.RegularPriorityProfile; import com.azure.resourcemanager.computefleet.models.SpotAllocationStrategy; @@ -47,17 +42,16 @@ import com.azure.resourcemanager.computefleet.models.VirtualMachineScaleSetNetworkProfile; import com.azure.resourcemanager.computefleet.models.VirtualMachineScaleSetOSDisk; import com.azure.resourcemanager.computefleet.models.VirtualMachineScaleSetOSProfile; -import com.azure.resourcemanager.computefleet.models.VirtualMachineScaleSetPublicIPAddressConfiguration; -import com.azure.resourcemanager.computefleet.models.VirtualMachineScaleSetPublicIPAddressConfigurationProperties; import com.azure.resourcemanager.computefleet.models.VirtualMachineScaleSetStorageProfile; import com.azure.resourcemanager.computefleet.models.VmSizeProfile; import com.azure.resourcemanager.network.NetworkManager; import com.azure.resourcemanager.network.models.IpVersion; +import com.azure.resourcemanager.network.models.LoadBalancer; +import com.azure.resourcemanager.network.models.LoadBalancerSkuType; import com.azure.resourcemanager.network.models.Network; -import com.azure.resourcemanager.network.models.PublicIpPrefix; -import com.azure.resourcemanager.network.models.PublicIpPrefixSku; -import com.azure.resourcemanager.network.models.PublicIpPrefixSkuName; -import com.azure.resourcemanager.network.models.PublicIpPrefixSkuTier; +import com.azure.resourcemanager.network.models.PublicIPSkuType; +import com.azure.resourcemanager.network.models.PublicIpAddress; +import com.azure.resourcemanager.network.models.TransportProtocol; import com.azure.resourcemanager.resources.ResourceManager; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -77,7 +71,7 @@ public class ComputeFleetManagerTests extends TestProxyTestBase { @Override public void beforeTest() { - final TokenCredential credential = new AzurePowerShellCredentialBuilder().build(); + final TokenCredential credential = new DefaultAzureCredentialBuilder().build(); final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); computeFleetManager = ComputeFleetManager @@ -124,8 +118,8 @@ public void testCreateComputeFleet() { String fleetName = "fleet" + randomPadding(); String vmName = "vm" + randomPadding(); String vnetName = "vnet" + randomPadding(); + String loadBalancerName = "loadBalancer" + randomPadding(); String publicIpName = "publicIp" + randomPadding(); - String publicIpPrefixName = "publicIpPrefix" + randomPadding(); String adminUser = "adminUser" + randomPadding(); String adminPwd = UUID.randomUUID().toString().replace("-", "@").substring(0, 13); // @embedStart @@ -133,21 +127,33 @@ public void testCreateComputeFleet() { .define(vnetName) .withRegion(REGION) .withExistingResourceGroup(resourceGroupName) - .withAddressSpace("10.0.0.0/16") - .withSubnet("default", "10.0.0.0/24") + .withAddressSpace("172.16.0.0/16") + .defineSubnet("default") + .withAddressPrefix("172.16.0.0/24") + .attach() .create(); - PublicIpPrefix publicIpPrefix = networkManager.publicIpPrefixes() - .define(publicIpPrefixName) + PublicIpAddress publicIpAddress = networkManager.publicIpAddresses() + .define(publicIpName) .withRegion(REGION) .withExistingResourceGroup(resourceGroupName) - .withSku( - new PublicIpPrefixSku() - .withName(PublicIpPrefixSkuName.STANDARD) - .withTier(PublicIpPrefixSkuTier.REGIONAL) - ) - .withPrefixLength(28) - .withPublicIpAddressVersion(IpVersion.IPV4) + .withSku(PublicIPSkuType.STANDARD) + .withIpAddressVersion(IpVersion.IPV4) + .withStaticIP() + .create(); + + LoadBalancer loadBalancer = networkManager.loadBalancers() + .define(loadBalancerName) + .withRegion(REGION) + .withExistingResourceGroup(resourceGroupName) + .defineLoadBalancingRule(loadBalancerName + "-lbrule") + .withProtocol(TransportProtocol.TCP) + .fromExistingPublicIPAddress(publicIpAddress) + .fromFrontendPort(80) + .toBackend(loadBalancerName + "-backend") + .toBackendPort(80) + .attach() + .withSku(LoadBalancerSkuType.STANDARD) .create(); fleet = computeFleetManager.fleets() @@ -228,24 +234,10 @@ public void testCreateComputeFleet() { new ApiEntityReference() .withId(network.subnets().get("default").id()) ) - .withPublicIPAddressConfiguration( - new VirtualMachineScaleSetPublicIPAddressConfiguration() - .withName(publicIpName) - .withSku( - new PublicIPAddressSku() - .withName(PublicIPAddressSkuName.STANDARD) - .withTier(PublicIPAddressSkuTier.REGIONAL) - ) - .withProperties( - new VirtualMachineScaleSetPublicIPAddressConfigurationProperties() - .withDeleteOption(DeleteOptions.DELETE) - .withPublicIPAddressVersion(IPVersion.IPV4) - .withIdleTimeoutInMinutes(9) - .withPublicIPPrefix( - new SubResource() - .withId(publicIpPrefix.id()) - ) - ) + .withLoadBalancerBackendAddressPools( + loadBalancer.loadBalancingRules() + .get(loadBalancerName + "-lbrule") + .innerModel().backendAddressPools() ) ) ) @@ -253,7 +245,7 @@ public void testCreateComputeFleet() { ) ) ) - .withNetworkApiVersion(NetworkApiVersion.TWO_ZERO_TWO_ZERO_ONE_ONE_ZERO_ONE) + .withNetworkApiVersion(NetworkApiVersion.fromString("2022-07-01")) ) ) .withComputeApiVersion("2024-03-01") From 85b65afe11fcccbc8b12eec6e4103a2cf7f22450 Mon Sep 17 00:00:00 2001 From: hongli750210 Date: Tue, 15 Oct 2024 14:58:56 +0800 Subject: [PATCH 3/8] Fixed comments for pr#42311 and add code for register providers. --- .../ComputeFleetManagerTests.java | 53 ++++++++++++------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/sdk/computefleet/azure-resourcemanager-computefleet/src/test/java/com/azure/resourcemanager/computefleet/ComputeFleetManagerTests.java b/sdk/computefleet/azure-resourcemanager-computefleet/src/test/java/com/azure/resourcemanager/computefleet/ComputeFleetManagerTests.java index d317b5a518b33..dfd23f6e1ce5b 100644 --- a/sdk/computefleet/azure-resourcemanager-computefleet/src/test/java/com/azure/resourcemanager/computefleet/ComputeFleetManagerTests.java +++ b/sdk/computefleet/azure-resourcemanager-computefleet/src/test/java/com/azure/resourcemanager/computefleet/ComputeFleetManagerTests.java @@ -45,18 +45,19 @@ import com.azure.resourcemanager.computefleet.models.VirtualMachineScaleSetStorageProfile; import com.azure.resourcemanager.computefleet.models.VmSizeProfile; import com.azure.resourcemanager.network.NetworkManager; -import com.azure.resourcemanager.network.models.IpVersion; import com.azure.resourcemanager.network.models.LoadBalancer; import com.azure.resourcemanager.network.models.LoadBalancerSkuType; import com.azure.resourcemanager.network.models.Network; -import com.azure.resourcemanager.network.models.PublicIPSkuType; -import com.azure.resourcemanager.network.models.PublicIpAddress; import com.azure.resourcemanager.network.models.TransportProtocol; import com.azure.resourcemanager.resources.ResourceManager; +import com.azure.resourcemanager.resources.fluentcore.utils.ResourceManagerUtils; +import com.azure.resourcemanager.resources.models.Provider; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import java.time.Duration; import java.util.Arrays; +import java.util.List; import java.util.Random; import java.util.UUID; @@ -76,20 +77,22 @@ public void beforeTest() { computeFleetManager = ComputeFleetManager .configure() - .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS)) .authenticate(credential, profile); networkManager = NetworkManager .configure() - .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS)) .authenticate(credential, profile); resourceManager = ResourceManager .configure() - .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS)) .authenticate(credential, profile) .withDefaultSubscription(); + canRegisterProviders(Arrays.asList("Microsoft.Resources", "Microsoft.Network", "Microsoft.AzureFleet")); + // use AZURE_RESOURCE_GROUP_NAME if run in LIVE CI String testResourceGroup = Configuration.getGlobalConfiguration().get("AZURE_RESOURCE_GROUP_NAME"); testEnv = !CoreUtils.isNullOrEmpty(testResourceGroup); @@ -114,16 +117,17 @@ protected void afterTest() { @LiveOnly public void testCreateComputeFleet() { Fleet fleet = null; + Network network = null; + LoadBalancer loadBalancer = null; try { String fleetName = "fleet" + randomPadding(); String vmName = "vm" + randomPadding(); String vnetName = "vnet" + randomPadding(); String loadBalancerName = "loadBalancer" + randomPadding(); - String publicIpName = "publicIp" + randomPadding(); String adminUser = "adminUser" + randomPadding(); String adminPwd = UUID.randomUUID().toString().replace("-", "@").substring(0, 13); // @embedStart - Network network = networkManager.networks() + network = networkManager.networks() .define(vnetName) .withRegion(REGION) .withExistingResourceGroup(resourceGroupName) @@ -133,22 +137,13 @@ public void testCreateComputeFleet() { .attach() .create(); - PublicIpAddress publicIpAddress = networkManager.publicIpAddresses() - .define(publicIpName) - .withRegion(REGION) - .withExistingResourceGroup(resourceGroupName) - .withSku(PublicIPSkuType.STANDARD) - .withIpAddressVersion(IpVersion.IPV4) - .withStaticIP() - .create(); - - LoadBalancer loadBalancer = networkManager.loadBalancers() + loadBalancer = networkManager.loadBalancers() .define(loadBalancerName) .withRegion(REGION) .withExistingResourceGroup(resourceGroupName) .defineLoadBalancingRule(loadBalancerName + "-lbrule") .withProtocol(TransportProtocol.TCP) - .fromExistingPublicIPAddress(publicIpAddress) + .fromExistingSubnet(network, "default") .fromFrontendPort(80) .toBackend(loadBalancerName + "-backend") .toBackendPort(80) @@ -267,10 +262,30 @@ public void testCreateComputeFleet() { if (fleet != null) { computeFleetManager.fleets().deleteById(fleet.id()); } + if (loadBalancer != null) { + networkManager.loadBalancers().deleteById(loadBalancer.id()); + } + if (network != null) { + networkManager.networks().deleteById(network.id()); + } } } private static String randomPadding() { return String.format("%05d", Math.abs(RANDOM.nextInt() % 100000)); } + + private void canRegisterProviders(List providerNamespaces) { + providerNamespaces.forEach(providerNamespace -> { + Provider provider = resourceManager.providers().getByName(providerNamespace); + if (!"Registered".equalsIgnoreCase(provider.registrationState()) + && !"Registering".equalsIgnoreCase(provider.registrationState())) { + provider = resourceManager.providers().register(providerNamespace); + } + while (!"Registered".equalsIgnoreCase(provider.registrationState())) { + ResourceManagerUtils.sleep(Duration.ofSeconds(5)); + provider = resourceManager.providers().getByName(provider.namespace()); + } + }); + } } From 433ccd402fd5e766e6548aa6cc3cb9d28708526b Mon Sep 17 00:00:00 2001 From: hongli750210 Date: Tue, 15 Oct 2024 15:04:38 +0800 Subject: [PATCH 4/8] Fixed comments for pr#42311 and add code for register providers. --- .../ComputeFleetManagerTests.java | 26 +++++++------------ 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/sdk/computefleet/azure-resourcemanager-computefleet/src/test/java/com/azure/resourcemanager/computefleet/ComputeFleetManagerTests.java b/sdk/computefleet/azure-resourcemanager-computefleet/src/test/java/com/azure/resourcemanager/computefleet/ComputeFleetManagerTests.java index dfd23f6e1ce5b..ee364646c13fb 100644 --- a/sdk/computefleet/azure-resourcemanager-computefleet/src/test/java/com/azure/resourcemanager/computefleet/ComputeFleetManagerTests.java +++ b/sdk/computefleet/azure-resourcemanager-computefleet/src/test/java/com/azure/resourcemanager/computefleet/ComputeFleetManagerTests.java @@ -13,7 +13,7 @@ import com.azure.core.test.annotation.LiveOnly; import com.azure.core.util.Configuration; import com.azure.core.util.CoreUtils; -import com.azure.identity.DefaultAzureCredentialBuilder; +import com.azure.identity.AzurePowerShellCredentialBuilder; import com.azure.resourcemanager.computefleet.models.ApiEntityReference; import com.azure.resourcemanager.computefleet.models.BaseVirtualMachineProfile; import com.azure.resourcemanager.computefleet.models.CachingTypes; @@ -72,26 +72,26 @@ public class ComputeFleetManagerTests extends TestProxyTestBase { @Override public void beforeTest() { - final TokenCredential credential = new DefaultAzureCredentialBuilder().build(); + final TokenCredential credential = new AzurePowerShellCredentialBuilder().build(); final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); computeFleetManager = ComputeFleetManager .configure() - .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS)) + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) .authenticate(credential, profile); networkManager = NetworkManager .configure() - .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS)) + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) .authenticate(credential, profile); resourceManager = ResourceManager .configure() - .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS)) + .withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)) .authenticate(credential, profile) .withDefaultSubscription(); - canRegisterProviders(Arrays.asList("Microsoft.Resources", "Microsoft.Network", "Microsoft.AzureFleet")); + canRegisterProviders(Arrays.asList("Microsoft.AzureFleet")); // use AZURE_RESOURCE_GROUP_NAME if run in LIVE CI String testResourceGroup = Configuration.getGlobalConfiguration().get("AZURE_RESOURCE_GROUP_NAME"); @@ -117,8 +117,6 @@ protected void afterTest() { @LiveOnly public void testCreateComputeFleet() { Fleet fleet = null; - Network network = null; - LoadBalancer loadBalancer = null; try { String fleetName = "fleet" + randomPadding(); String vmName = "vm" + randomPadding(); @@ -127,7 +125,7 @@ public void testCreateComputeFleet() { String adminUser = "adminUser" + randomPadding(); String adminPwd = UUID.randomUUID().toString().replace("-", "@").substring(0, 13); // @embedStart - network = networkManager.networks() + Network network = networkManager.networks() .define(vnetName) .withRegion(REGION) .withExistingResourceGroup(resourceGroupName) @@ -137,7 +135,7 @@ public void testCreateComputeFleet() { .attach() .create(); - loadBalancer = networkManager.loadBalancers() + LoadBalancer loadBalancer = networkManager.loadBalancers() .define(loadBalancerName) .withRegion(REGION) .withExistingResourceGroup(resourceGroupName) @@ -240,7 +238,7 @@ public void testCreateComputeFleet() { ) ) ) - .withNetworkApiVersion(NetworkApiVersion.fromString("2022-07-01")) + .withNetworkApiVersion(NetworkApiVersion.fromString("2024-03-01")) ) ) .withComputeApiVersion("2024-03-01") @@ -262,12 +260,6 @@ public void testCreateComputeFleet() { if (fleet != null) { computeFleetManager.fleets().deleteById(fleet.id()); } - if (loadBalancer != null) { - networkManager.loadBalancers().deleteById(loadBalancer.id()); - } - if (network != null) { - networkManager.networks().deleteById(network.id()); - } } } From 01b83ae40a29cd34883617aaffd9f5b3f4f2c4cd Mon Sep 17 00:00:00 2001 From: hongli750210 Date: Tue, 15 Oct 2024 17:08:51 +0800 Subject: [PATCH 5/8] Fix live test exception. --- .../resourcemanager/computefleet/ComputeFleetManagerTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/computefleet/azure-resourcemanager-computefleet/src/test/java/com/azure/resourcemanager/computefleet/ComputeFleetManagerTests.java b/sdk/computefleet/azure-resourcemanager-computefleet/src/test/java/com/azure/resourcemanager/computefleet/ComputeFleetManagerTests.java index ee364646c13fb..82984222b6dbb 100644 --- a/sdk/computefleet/azure-resourcemanager-computefleet/src/test/java/com/azure/resourcemanager/computefleet/ComputeFleetManagerTests.java +++ b/sdk/computefleet/azure-resourcemanager-computefleet/src/test/java/com/azure/resourcemanager/computefleet/ComputeFleetManagerTests.java @@ -165,7 +165,7 @@ public void testCreateComputeFleet() { .withVmSizesProfile( Arrays.asList( new VmSizeProfile().withName("Standard_D4s_v3"), - new VmSizeProfile().withName("Standard_D2s_v3"), + new VmSizeProfile().withName("Standard_D2s_v5"), new VmSizeProfile().withName("Standard_E2s_v3") ) ) From 357bb487ad23561d82c50ee35383b5d634971324 Mon Sep 17 00:00:00 2001 From: hongli750210 Date: Tue, 15 Oct 2024 18:12:51 +0800 Subject: [PATCH 6/8] Fixed comments for pr#42311. --- .../computefleet/ComputeFleetManagerTests.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/sdk/computefleet/azure-resourcemanager-computefleet/src/test/java/com/azure/resourcemanager/computefleet/ComputeFleetManagerTests.java b/sdk/computefleet/azure-resourcemanager-computefleet/src/test/java/com/azure/resourcemanager/computefleet/ComputeFleetManagerTests.java index 82984222b6dbb..06f9b343751d4 100644 --- a/sdk/computefleet/azure-resourcemanager-computefleet/src/test/java/com/azure/resourcemanager/computefleet/ComputeFleetManagerTests.java +++ b/sdk/computefleet/azure-resourcemanager-computefleet/src/test/java/com/azure/resourcemanager/computefleet/ComputeFleetManagerTests.java @@ -157,16 +157,14 @@ public void testCreateComputeFleet() { new FleetProperties() .withSpotPriorityProfile( new SpotPriorityProfile() - .withMaintain(true) + .withMaintain(false) .withCapacity(1) .withEvictionPolicy(EvictionPolicy.DELETE) .withAllocationStrategy(SpotAllocationStrategy.LOWEST_PRICE) ) .withVmSizesProfile( Arrays.asList( - new VmSizeProfile().withName("Standard_D4s_v3"), - new VmSizeProfile().withName("Standard_D2s_v5"), - new VmSizeProfile().withName("Standard_E2s_v3") + new VmSizeProfile().withName("Standard_D4s_v3") ) ) .withComputeProfile( From 2668de3daa187b845c67c14e222ba720731e105b Mon Sep 17 00:00:00 2001 From: hongli750210 Date: Wed, 16 Oct 2024 10:40:42 +0800 Subject: [PATCH 7/8] Fix comment for PR#42311 --- .../resourcemanager/computefleet/ComputeFleetManagerTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/computefleet/azure-resourcemanager-computefleet/src/test/java/com/azure/resourcemanager/computefleet/ComputeFleetManagerTests.java b/sdk/computefleet/azure-resourcemanager-computefleet/src/test/java/com/azure/resourcemanager/computefleet/ComputeFleetManagerTests.java index 06f9b343751d4..f6d249ee4bbe2 100644 --- a/sdk/computefleet/azure-resourcemanager-computefleet/src/test/java/com/azure/resourcemanager/computefleet/ComputeFleetManagerTests.java +++ b/sdk/computefleet/azure-resourcemanager-computefleet/src/test/java/com/azure/resourcemanager/computefleet/ComputeFleetManagerTests.java @@ -249,7 +249,7 @@ public void testCreateComputeFleet() { ) ) .create(); - // @embedStart + // @embedEnd fleet.refresh(); Assertions.assertEquals(fleetName, fleet.name()); Assertions.assertEquals(fleetName, computeFleetManager.fleets().getById(fleet.id()).name()); From ee626f962d27c9afbe4765ea5a5802da93517613 Mon Sep 17 00:00:00 2001 From: hongli750210 Date: Wed, 16 Oct 2024 11:38:51 +0800 Subject: [PATCH 8/8] Change to `// @embedmeStart` and `// @embedmeEnd"` --- .../computefleet/ComputeFleetManagerTests.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/computefleet/azure-resourcemanager-computefleet/src/test/java/com/azure/resourcemanager/computefleet/ComputeFleetManagerTests.java b/sdk/computefleet/azure-resourcemanager-computefleet/src/test/java/com/azure/resourcemanager/computefleet/ComputeFleetManagerTests.java index f6d249ee4bbe2..6b24b00ace534 100644 --- a/sdk/computefleet/azure-resourcemanager-computefleet/src/test/java/com/azure/resourcemanager/computefleet/ComputeFleetManagerTests.java +++ b/sdk/computefleet/azure-resourcemanager-computefleet/src/test/java/com/azure/resourcemanager/computefleet/ComputeFleetManagerTests.java @@ -124,7 +124,7 @@ public void testCreateComputeFleet() { String loadBalancerName = "loadBalancer" + randomPadding(); String adminUser = "adminUser" + randomPadding(); String adminPwd = UUID.randomUUID().toString().replace("-", "@").substring(0, 13); - // @embedStart + // @embedmeStart Network network = networkManager.networks() .define(vnetName) .withRegion(REGION) @@ -249,7 +249,7 @@ public void testCreateComputeFleet() { ) ) .create(); - // @embedEnd + // @embedmeEnd fleet.refresh(); Assertions.assertEquals(fleetName, fleet.name()); Assertions.assertEquals(fleetName, computeFleetManager.fleets().getById(fleet.id()).name());