From 9cca837baea67fe3da52b5d3d1c1c52d75684c0d Mon Sep 17 00:00:00 2001 From: "Hong Li(MSFT)" <74638143+v-hongli1@users.noreply.github.com> Date: Wed, 31 Jul 2024 13:57:23 +0800 Subject: [PATCH] Refactor resourcemanager tests to work with latest TestProxy (#41301) Refactor resourcemanager tests to work with latest TestProxy. --- .../azure-resourcemanager-compute/assets.json | 2 +- ...VirtualMachineEMSILMSIOperationsTests.java | 22 +- ...achineScaleSetEMSILMSIOperationsTests.java | 233 +++++++++--------- ...VirtualMachineScaleSetOperationsTests.java | 41 +-- .../azure-resourcemanager-monitor/assets.json | 2 +- .../resourcemanager/monitor/AlertsTests.java | 41 ++- .../azure-resourcemanager-redis/assets.json | 2 +- .../redis/RedisCacheOperationsTests.java | 9 +- .../assets.json | 2 +- .../resources/DeploymentsTests.java | 61 ++--- .../azure-resourcemanager/assets.json | 2 +- .../AzureResourceManagerTests.java | 5 +- .../resourcemanager/TestTrafficManager.java | 43 +++- 13 files changed, 244 insertions(+), 221 deletions(-) diff --git a/sdk/resourcemanager/azure-resourcemanager-compute/assets.json b/sdk/resourcemanager/azure-resourcemanager-compute/assets.json index 0c1e4d6e1867a..0b832c74dd318 100644 --- a/sdk/resourcemanager/azure-resourcemanager-compute/assets.json +++ b/sdk/resourcemanager/azure-resourcemanager-compute/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "java", "TagPrefix": "java/resourcemanager/azure-resourcemanager-compute", - "Tag": "java/resourcemanager/azure-resourcemanager-compute_b77244749d" + "Tag": "java/resourcemanager/azure-resourcemanager-compute_2e5d9e7287" } diff --git a/sdk/resourcemanager/azure-resourcemanager-compute/src/test/java/com/azure/resourcemanager/compute/VirtualMachineEMSILMSIOperationsTests.java b/sdk/resourcemanager/azure-resourcemanager-compute/src/test/java/com/azure/resourcemanager/compute/VirtualMachineEMSILMSIOperationsTests.java index c968a6f7f8bcc..f052a05a7f8d3 100644 --- a/sdk/resourcemanager/azure-resourcemanager-compute/src/test/java/com/azure/resourcemanager/compute/VirtualMachineEMSILMSIOperationsTests.java +++ b/sdk/resourcemanager/azure-resourcemanager-compute/src/test/java/com/azure/resourcemanager/compute/VirtualMachineEMSILMSIOperationsTests.java @@ -4,29 +4,29 @@ package com.azure.resourcemanager.compute; import com.azure.core.http.rest.PagedIterable; -import com.azure.core.test.annotation.LiveOnly; +import com.azure.core.management.Region; +import com.azure.core.test.annotation.DoNotRecord; +import com.azure.resourcemanager.authorization.models.BuiltInRole; +import com.azure.resourcemanager.authorization.models.RoleAssignment; import com.azure.resourcemanager.compute.models.KnownLinuxVirtualMachineImage; import com.azure.resourcemanager.compute.models.ResourceIdentityType; import com.azure.resourcemanager.compute.models.VirtualMachine; -import com.azure.resourcemanager.authorization.models.BuiltInRole; -import com.azure.resourcemanager.authorization.models.RoleAssignment; import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes; import com.azure.resourcemanager.msi.models.Identity; import com.azure.resourcemanager.network.models.Network; -import com.azure.resourcemanager.resources.models.ResourceGroup; -import com.azure.core.management.Region; import com.azure.resourcemanager.resources.fluentcore.model.Creatable; -import java.util.Iterator; -import java.util.Set; +import com.azure.resourcemanager.resources.models.ResourceGroup; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import reactor.core.publisher.Mono; -@LiveOnly +import java.util.Iterator; +import java.util.Set; + public class VirtualMachineEMSILMSIOperationsTests extends ComputeManagementTest { // LiveOnly because test needs to be refactored for storing/evaluating PrincipalId private String rgName = ""; - private Region region = Region.US_WEST_CENTRAL; + private Region region = Region.US_WEST2; private final String vmName = "javavm"; @Override @@ -35,7 +35,9 @@ protected void cleanUpResources() { } @Test + @DoNotRecord(skipInPlayback = true) public void canCreateUpdateVirtualMachineWithEMSI() { + // LiveOnly because "test timing out after latest test proxy update" // this.resourceManager.resourceGroups().beginDeleteByName("41522c6e938c4f6"); rgName = generateRandomResourceName("java-emsi-c-rg", 15); String identityName1 = generateRandomResourceName("msi-id", 15); @@ -254,7 +256,9 @@ public void canCreateUpdateVirtualMachineWithEMSI() { } @Test + @DoNotRecord(skipInPlayback = true) public void canCreateVirtualMachineWithLMSIAndEMSI() { + // LiveOnly because "test timing out after latest test proxy update" rgName = generateRandomResourceName("java-emsi-c-rg", 15); String identityName1 = generateRandomResourceName("msi-id", 15); String networkName = generateRandomResourceName("nw", 10); diff --git a/sdk/resourcemanager/azure-resourcemanager-compute/src/test/java/com/azure/resourcemanager/compute/VirtualMachineScaleSetEMSILMSIOperationsTests.java b/sdk/resourcemanager/azure-resourcemanager-compute/src/test/java/com/azure/resourcemanager/compute/VirtualMachineScaleSetEMSILMSIOperationsTests.java index f9c9c03d169a7..7b7d5e3a4fcdf 100644 --- a/sdk/resourcemanager/azure-resourcemanager-compute/src/test/java/com/azure/resourcemanager/compute/VirtualMachineScaleSetEMSILMSIOperationsTests.java +++ b/sdk/resourcemanager/azure-resourcemanager-compute/src/test/java/com/azure/resourcemanager/compute/VirtualMachineScaleSetEMSILMSIOperationsTests.java @@ -4,32 +4,39 @@ package com.azure.resourcemanager.compute; import com.azure.core.http.rest.PagedIterable; -import com.azure.core.test.annotation.LiveOnly; +import com.azure.core.management.Region; +import com.azure.resourcemanager.authorization.models.BuiltInRole; +import com.azure.resourcemanager.authorization.models.RoleAssignment; import com.azure.resourcemanager.compute.models.KnownLinuxVirtualMachineImage; import com.azure.resourcemanager.compute.models.ResourceIdentityType; import com.azure.resourcemanager.compute.models.VirtualMachineScaleSet; import com.azure.resourcemanager.compute.models.VirtualMachineScaleSetSkuTypes; -import com.azure.resourcemanager.authorization.models.BuiltInRole; -import com.azure.resourcemanager.authorization.models.RoleAssignment; import com.azure.resourcemanager.msi.models.Identity; import com.azure.resourcemanager.network.models.LoadBalancer; import com.azure.resourcemanager.network.models.Network; -import com.azure.resourcemanager.resources.models.ResourceGroup; -import com.azure.core.management.Region; import com.azure.resourcemanager.resources.fluentcore.model.Creatable; -import java.util.Iterator; -import java.util.Set; - +import com.azure.resourcemanager.resources.models.ResourceGroup; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import reactor.core.publisher.Mono; -@LiveOnly +import java.util.Iterator; +import java.util.Set; + public class VirtualMachineScaleSetEMSILMSIOperationsTests extends ComputeManagementTest { // LiveOnly because test needs to be refactored for storing/evaluating PrincipalId private String rgName = ""; - private Region region = Region.US_WEST_CENTRAL; + private Region region = Region.US_WEST2; private final String vmssName = "javavmss"; + private ResourceGroup resourceGroup; + + @BeforeEach + public void initResources() { + // Create a resource group + rgName = generateRandomResourceName("java-emsi-c-rg", 15); + resourceGroup = this.resourceManager.resourceGroups().define(rgName).withRegion(region).create(); + } @Override protected void cleanUpResources() { @@ -38,13 +45,10 @@ protected void cleanUpResources() { @Test public void canCreateUpdateVirtualMachineScaleSetWithEMSI() throws Exception { - rgName = generateRandomResourceName("java-ems-c-rg", 15); String identityName1 = generateRandomResourceName("msi-id", 15); String identityName2 = generateRandomResourceName("msi-id", 15); String networkName = generateRandomResourceName("nw", 10); - ResourceGroup resourceGroup = this.resourceManager.resourceGroups().define(rgName).withRegion(region).create(); - // Create a virtual network to which we will assign "EMSI" with reader access // Network network = @@ -148,56 +152,60 @@ public void canCreateUpdateVirtualMachineScaleSetWithEMSI() throws Exception { // Ensure expected role assignment exists for explicitly created EMSI // - PagedIterable roleAssignmentsForNetwork = - this.msiManager.authorizationManager().roleAssignments().listByScope(network.id()); boolean found = false; - for (RoleAssignment roleAssignment : roleAssignmentsForNetwork) { - if (roleAssignment.principalId() != null - && roleAssignment.principalId().equalsIgnoreCase(createdIdentity.principalId())) { - found = true; - break; + RoleAssignment assignment; + if (!isPlaybackMode()) { + // principalId redacted + PagedIterable roleAssignmentsForNetwork = + this.msiManager.authorizationManager().roleAssignments().listByScope(network.id()); + for (RoleAssignment roleAssignment : roleAssignmentsForNetwork) { + if (roleAssignment.principalId() != null + && roleAssignment.principalId().equalsIgnoreCase(createdIdentity.principalId())) { + found = true; + break; + } } - } - Assertions - .assertTrue( - found, - "Expected role assignment not found for the virtual network for identity" + createdIdentity.name()); - - RoleAssignment assignment = - lookupRoleAssignmentUsingScopeAndRoleAsync(network.id(), BuiltInRole.READER, createdIdentity.principalId()) - .block(); - - Assertions - .assertNotNull( - assignment, "Expected role assignment with ROLE not found for the virtual network for identity"); + Assertions + .assertTrue( + found, + "Expected role assignment not found for the virtual network for identity" + createdIdentity.name()); - // Ensure expected role assignment exists for explicitly created EMSI - // - PagedIterable roleAssignmentsForResourceGroup = - this.msiManager.authorizationManager().roleAssignments().listByScope(resourceGroup.id()); + assignment = + lookupRoleAssignmentUsingScopeAndRoleAsync(network.id(), BuiltInRole.READER, createdIdentity.principalId()) + .block(); - found = false; - for (RoleAssignment roleAssignment : roleAssignmentsForResourceGroup) { - if (roleAssignment.principalId() != null - && roleAssignment.principalId().equalsIgnoreCase(implicitlyCreatedIdentity.principalId())) { - found = true; - break; + Assertions + .assertNotNull( + assignment, "Expected role assignment with ROLE not found for the virtual network for identity"); + + // Ensure expected role assignment exists for explicitly created EMSI + // + PagedIterable roleAssignmentsForResourceGroup = + this.msiManager.authorizationManager().roleAssignments().listByScope(resourceGroup.id()); + + found = false; + for (RoleAssignment roleAssignment : roleAssignmentsForResourceGroup) { + if (roleAssignment.principalId() != null + && roleAssignment.principalId().equalsIgnoreCase(implicitlyCreatedIdentity.principalId())) { + found = true; + break; + } } - } - Assertions - .assertTrue( - found, - "Expected role assignment not found for the resource group for identity" - + implicitlyCreatedIdentity.name()); + Assertions + .assertTrue( + found, + "Expected role assignment not found for the resource group for identity" + + implicitlyCreatedIdentity.name()); - assignment = - lookupRoleAssignmentUsingScopeAndRoleAsync( + assignment = + lookupRoleAssignmentUsingScopeAndRoleAsync( resourceGroup.id(), BuiltInRole.CONTRIBUTOR, implicitlyCreatedIdentity.principalId()) - .block(); + .block(); - Assertions - .assertNotNull( - assignment, "Expected role assignment with ROLE not found for the resource group for identity"); + Assertions + .assertNotNull( + assignment, "Expected role assignment with ROLE not found for the resource group for identity"); + } emsiIds = virtualMachineScaleSet.userAssignedManagedServiceIdentityIds(); Iterator itr = emsiIds.iterator(); @@ -296,14 +304,9 @@ public void canCreateUpdateVirtualMachineScaleSetWithEMSI() throws Exception { @Test public void canCreateVirtualMachineScaleSetWithLMSIAndEMSI() throws Exception { - rgName = generateRandomResourceName("java-emsi-c-rg", 15); String identityName1 = generateRandomResourceName("msi-id", 15); String networkName = generateRandomResourceName("nw", 10); - // Create a resource group - // - ResourceGroup resourceGroup = resourceManager.resourceGroups().define(rgName).withRegion(region).create(); - // Create a virtual network to which we will assign "EMSI" with reader access // Network network = @@ -380,78 +383,76 @@ public void canCreateVirtualMachineScaleSetWithLMSIAndEMSI() throws Exception { // Ensure expected role assignment exists for LMSI // - PagedIterable roleAssignmentsForNetwork = - this.msiManager.authorizationManager().roleAssignments().listByScope(network.id()); - boolean found = false; - for (RoleAssignment roleAssignment : roleAssignmentsForNetwork) { - if (roleAssignment.principalId() != null - && roleAssignment - .principalId() - .equalsIgnoreCase(virtualMachineScaleSet.systemAssignedManagedServiceIdentityPrincipalId())) { - found = true; - break; + if (!isPlaybackMode()) { + // principalId redacted + PagedIterable roleAssignmentsForNetwork = + this.msiManager.authorizationManager().roleAssignments().listByScope(network.id()); + boolean found = false; + for (RoleAssignment roleAssignment : roleAssignmentsForNetwork) { + if (roleAssignment.principalId() != null + && roleAssignment + .principalId() + .equalsIgnoreCase(virtualMachineScaleSet.systemAssignedManagedServiceIdentityPrincipalId())) { + found = true; + break; + } } - } - Assertions - .assertTrue( - found, - "Expected role assignment not found for the virtual network for local identity" - + virtualMachineScaleSet.systemAssignedManagedServiceIdentityPrincipalId()); + Assertions + .assertTrue( + found, + "Expected role assignment not found for the virtual network for local identity" + + virtualMachineScaleSet.systemAssignedManagedServiceIdentityPrincipalId()); - RoleAssignment assignment = - lookupRoleAssignmentUsingScopeAndRoleAsync( + RoleAssignment assignment = + lookupRoleAssignmentUsingScopeAndRoleAsync( network.id(), BuiltInRole.CONTRIBUTOR, virtualMachineScaleSet.systemAssignedManagedServiceIdentityPrincipalId()) - .block(); - - Assertions - .assertNotNull( - assignment, - "Expected role assignment with ROLE not found for the virtual network for system assigned identity"); + .block(); - // Ensure expected role assignment exists for EMSI - // - PagedIterable roleAssignmentsForResourceGroup = - this - .msiManager - .authorizationManager() - .roleAssignments() - .listByScope( - resourceManager.resourceGroups().getByName(virtualMachineScaleSet.resourceGroupName()).id()); - found = false; - for (RoleAssignment roleAssignment : roleAssignmentsForResourceGroup) { - if (roleAssignment.principalId() != null - && roleAssignment.principalId().equalsIgnoreCase(identity.principalId())) { - found = true; - break; + Assertions + .assertNotNull( + assignment, + "Expected role assignment with ROLE not found for the virtual network for system assigned identity"); + + // Ensure expected role assignment exists for EMSI + // + PagedIterable roleAssignmentsForResourceGroup = + this + .msiManager + .authorizationManager() + .roleAssignments() + .listByScope( + resourceManager.resourceGroups().getByName(virtualMachineScaleSet.resourceGroupName()).id()); + found = false; + for (RoleAssignment roleAssignment : roleAssignmentsForResourceGroup) { + if (roleAssignment.principalId() != null + && roleAssignment.principalId().equalsIgnoreCase(identity.principalId())) { + found = true; + break; + } } - } - Assertions - .assertTrue( - found, "Expected role assignment not found for the resource group for identity" + identity.name()); + Assertions + .assertTrue( + found, "Expected role assignment not found for the resource group for identity" + identity.name()); - assignment = - lookupRoleAssignmentUsingScopeAndRoleAsync( + assignment = + lookupRoleAssignmentUsingScopeAndRoleAsync( resourceGroup.id(), BuiltInRole.CONTRIBUTOR, identity.principalId()) - .block(); + .block(); - Assertions - .assertNotNull( - assignment, - "Expected role assignment with ROLE not found for the resource group for system assigned identity"); + Assertions + .assertNotNull( + assignment, + "Expected role assignment with ROLE not found for the resource group for system assigned identity"); + } } @Test public void canUpdateVirtualMachineScaleSetWithEMSIAndLMSI() throws Exception { - rgName = generateRandomResourceName("java-emsi-c-rg", 15); String identityName1 = generateRandomResourceName("msi-id-1", 15); String identityName2 = generateRandomResourceName("msi-id-2", 15); - // Create a resource group - // - ResourceGroup resourceGroup = resourceManager.resourceGroups().define(rgName).withRegion(region).create(); - // Create a virtual network for VMSS // Network vmssNetwork = @@ -542,7 +543,7 @@ public void canUpdateVirtualMachineScaleSetWithEMSIAndLMSI() throws Exception { // Ensure the "User Assigned (External) MSI" id can be retrieved from the virtual machine // - emsiIds = virtualMachineScaleSet.userAssignedManagedServiceIdentityIds(); + emsiIds = virtualMachineScaleSet.innerModel().identity().userAssignedIdentities().keySet(); Assertions.assertNotNull(emsiIds); Assertions.assertEquals(1, emsiIds.size()); diff --git a/sdk/resourcemanager/azure-resourcemanager-compute/src/test/java/com/azure/resourcemanager/compute/VirtualMachineScaleSetOperationsTests.java b/sdk/resourcemanager/azure-resourcemanager-compute/src/test/java/com/azure/resourcemanager/compute/VirtualMachineScaleSetOperationsTests.java index 7338cc8bcc31b..a249a71a2afb2 100644 --- a/sdk/resourcemanager/azure-resourcemanager-compute/src/test/java/com/azure/resourcemanager/compute/VirtualMachineScaleSetOperationsTests.java +++ b/sdk/resourcemanager/azure-resourcemanager-compute/src/test/java/com/azure/resourcemanager/compute/VirtualMachineScaleSetOperationsTests.java @@ -8,7 +8,6 @@ import com.azure.core.management.Region; import com.azure.core.management.SubResource; import com.azure.core.management.profile.AzureProfile; -import com.azure.core.test.annotation.LiveOnly; import com.azure.resourcemanager.authorization.models.BuiltInRole; import com.azure.resourcemanager.authorization.models.RoleAssignment; import com.azure.resourcemanager.compute.fluent.models.VirtualMachineScaleSetInner; @@ -946,25 +945,24 @@ public void canCreateZoneRedundantVirtualMachineScaleSetWithZoneResilientLoadBal } @Test - @LiveOnly public void canEnableMSIOnVirtualMachineScaleSetWithoutRoleAssignment() throws Exception { - // LiveOnly because test needs to be refactored for storing/evaluating PrincipalId final String vmssName = generateRandomResourceName("vmss", 10); - ResourceGroup resourceGroup = this.resourceManager.resourceGroups().define(rgName).withRegion(region).create(); + Region localRegion = Region.US_WEST2; + ResourceGroup resourceGroup = this.resourceManager.resourceGroups().define(rgName).withRegion(localRegion).create(); Network network = this .networkManager .networks() .define("vmssvnet") - .withRegion(region) + .withRegion(localRegion) .withExistingResourceGroup(resourceGroup) .withAddressSpace("10.0.0.0/28") .withSubnet("subnet1", "10.0.0.0/28") .create(); LoadBalancer publicLoadBalancer = - createInternetFacingLoadBalancer(region, resourceGroup, "1", LoadBalancerSkuType.BASIC); + createInternetFacingLoadBalancer(localRegion, resourceGroup, "1", LoadBalancerSkuType.BASIC); List backends = new ArrayList<>(); for (String backend : publicLoadBalancer.backends().keySet()) { backends.add(backend); @@ -976,7 +974,7 @@ public void canEnableMSIOnVirtualMachineScaleSetWithoutRoleAssignment() throws E .computeManager .virtualMachineScaleSets() .define(vmssName) - .withRegion(region) + .withRegion(localRegion) .withExistingResourceGroup(resourceGroup) .withSku(VirtualMachineScaleSetSkuTypes.STANDARD_A0) .withExistingPrimaryNetworkSubnet(network, "subnet1") @@ -1002,21 +1000,24 @@ public void canEnableMSIOnVirtualMachineScaleSetWithoutRoleAssignment() throws E // Ensure role assigned for resource group // - PagedIterable rgRoleAssignments = authorizationManager.roleAssignments().listByScope(resourceGroup.id()); - Assertions.assertNotNull(rgRoleAssignments); - boolean found = false; - for (RoleAssignment roleAssignment : rgRoleAssignments) { - if (roleAssignment.principalId() != null - && roleAssignment - .principalId() - .equalsIgnoreCase(virtualMachineScaleSet.systemAssignedManagedServiceIdentityPrincipalId())) { - found = true; - break; + if (!isPlaybackMode()) { + // principalId redacted + PagedIterable rgRoleAssignments = authorizationManager.roleAssignments().listByScope(resourceGroup.id()); + Assertions.assertNotNull(rgRoleAssignments); + boolean found = false; + for (RoleAssignment roleAssignment : rgRoleAssignments) { + if (roleAssignment.principalId() != null + && roleAssignment + .principalId() + .equalsIgnoreCase(virtualMachineScaleSet.systemAssignedManagedServiceIdentityPrincipalId())) { + found = true; + break; + } } + Assertions + .assertFalse( + found, "Resource group should not have a role assignment with virtual machine scale set MSI principal"); } - Assertions - .assertFalse( - found, "Resource group should not have a role assignment with virtual machine scale set MSI principal"); } @Test diff --git a/sdk/resourcemanager/azure-resourcemanager-monitor/assets.json b/sdk/resourcemanager/azure-resourcemanager-monitor/assets.json index cb9fd7dce4ccd..19372011883c1 100644 --- a/sdk/resourcemanager/azure-resourcemanager-monitor/assets.json +++ b/sdk/resourcemanager/azure-resourcemanager-monitor/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "java", "TagPrefix": "java/resourcemanager/azure-resourcemanager-monitor", - "Tag": "java/resourcemanager/azure-resourcemanager-monitor_886d7d8599" + "Tag": "java/resourcemanager/azure-resourcemanager-monitor_4cc812dd58" } diff --git a/sdk/resourcemanager/azure-resourcemanager-monitor/src/test/java/com/azure/resourcemanager/monitor/AlertsTests.java b/sdk/resourcemanager/azure-resourcemanager-monitor/src/test/java/com/azure/resourcemanager/monitor/AlertsTests.java index 34e76f690907b..b3247262b2e86 100644 --- a/sdk/resourcemanager/azure-resourcemanager-monitor/src/test/java/com/azure/resourcemanager/monitor/AlertsTests.java +++ b/sdk/resourcemanager/azure-resourcemanager-monitor/src/test/java/com/azure/resourcemanager/monitor/AlertsTests.java @@ -7,7 +7,6 @@ import com.azure.core.http.rest.PagedIterable; import com.azure.core.management.Region; import com.azure.core.management.profile.AzureProfile; -import com.azure.core.test.annotation.LiveOnly; import com.azure.resourcemanager.compute.models.KnownLinuxVirtualMachineImage; import com.azure.resourcemanager.compute.models.VirtualMachine; import com.azure.resourcemanager.monitor.models.ActionGroup; @@ -31,9 +30,7 @@ import java.util.Arrays; import java.util.Iterator; -@LiveOnly public class AlertsTests extends MonitorManagementTest { - // LiveOnly because test needs to be refactored to check for resource region private String rgName = ""; private String saName = ""; @@ -105,7 +102,7 @@ public void canCRUDMetricAlerts() throws Exception { Assertions.assertNotNull(ma); Assertions.assertEquals(1, ma.scopes().size()); - Assertions.assertEquals(sa.id(), ma.scopes().iterator().next()); + assertResourceIdEquals(sa.id(), ma.scopes().iterator().next()); Assertions .assertEquals( "This alert rule is for U3 - Single resource multiple-criteria with dimensions-single timeseries", @@ -116,7 +113,7 @@ public void canCRUDMetricAlerts() throws Exception { Assertions.assertEquals(true, ma.enabled()); Assertions.assertEquals(true, ma.autoMitigate()); Assertions.assertEquals(1, ma.actionGroupIds().size()); - Assertions.assertEquals(ag.id(), ma.actionGroupIds().iterator().next()); + assertResourceIdEquals(ag.id(), ma.actionGroupIds().iterator().next()); Assertions.assertEquals(1, ma.alertCriterias().size()); MetricAlertCondition ac1 = ma.alertCriterias().values().iterator().next(); Assertions.assertEquals("Metric1", ac1.name()); @@ -183,7 +180,7 @@ public void canCRUDMetricAlerts() throws Exception { Assertions.assertNotNull(ma); Assertions.assertEquals(1, ma.scopes().size()); - Assertions.assertEquals(sa.id(), ma.scopes().iterator().next()); + assertResourceIdEquals(sa.id(), ma.scopes().iterator().next()); Assertions .assertEquals( "This alert rule is for U3 - Single resource multiple-criteria with dimensions-single timeseries", @@ -194,7 +191,7 @@ public void canCRUDMetricAlerts() throws Exception { Assertions.assertEquals(false, ma.enabled()); Assertions.assertEquals(true, ma.autoMitigate()); Assertions.assertEquals(1, ma.actionGroupIds().size()); - Assertions.assertEquals(ag.id(), ma.actionGroupIds().iterator().next()); + assertResourceIdEquals(ag.id(), ma.actionGroupIds().iterator().next()); Assertions.assertEquals(2, ma.alertCriterias().size()); Iterator maCriteriaIterator = ma.alertCriterias().values().iterator(); ac1 = maCriteriaIterator.next(); @@ -231,7 +228,7 @@ public void canCRUDMetricAlerts() throws Exception { Assertions.assertNotNull(maFromGet); Assertions.assertEquals(1, maFromGet.scopes().size()); - Assertions.assertEquals(sa.id(), maFromGet.scopes().iterator().next()); + assertResourceIdEquals(sa.id(), maFromGet.scopes().iterator().next()); Assertions .assertEquals( "This alert rule is for U3 - Single resource multiple-criteria with dimensions-single timeseries", @@ -242,7 +239,7 @@ public void canCRUDMetricAlerts() throws Exception { Assertions.assertEquals(false, maFromGet.enabled()); Assertions.assertEquals(true, maFromGet.autoMitigate()); Assertions.assertEquals(1, maFromGet.actionGroupIds().size()); - Assertions.assertEquals(ag.id(), maFromGet.actionGroupIds().iterator().next()); + assertResourceIdEquals(ag.id(), maFromGet.actionGroupIds().iterator().next()); Assertions.assertEquals(2, maFromGet.alertCriterias().size()); maCriteriaIterator = maFromGet.alertCriterias().values().iterator(); ac1 = maCriteriaIterator.next(); @@ -283,7 +280,7 @@ public void canCRUDMetricAlerts() throws Exception { Assertions.assertNotNull(maFromGet); Assertions.assertEquals(1, maFromGet.scopes().size()); - Assertions.assertEquals(sa.id(), maFromGet.scopes().iterator().next()); + assertResourceIdEquals(sa.id(), maFromGet.scopes().iterator().next()); Assertions .assertEquals( "This alert rule is for U3 - Single resource multiple-criteria with dimensions-single timeseries", @@ -294,7 +291,7 @@ public void canCRUDMetricAlerts() throws Exception { Assertions.assertEquals(false, maFromGet.enabled()); Assertions.assertEquals(true, maFromGet.autoMitigate()); Assertions.assertEquals(1, maFromGet.actionGroupIds().size()); - Assertions.assertEquals(ag.id(), maFromGet.actionGroupIds().iterator().next()); + assertResourceIdEquals(ag.id(), maFromGet.actionGroupIds().iterator().next()); Assertions.assertEquals(2, maFromGet.alertCriterias().size()); maCriteriaIterator = maFromGet.alertCriterias().values().iterator(); ac1 = maCriteriaIterator.next(); @@ -391,7 +388,10 @@ public void canCRUDMultipleResourceMetricAlerts() throws Exception { ma.refresh(); Assertions.assertEquals(2, ma.scopes().size()); Assertions.assertEquals(vm1.type(), ma.innerModel().targetResourceType()); - Assertions.assertEquals(vm1.regionName(), ma.innerModel().targetResourceRegion()); + if (!isPlaybackMode()) { + // targetResourceRegion sanitized + Assertions.assertEquals(vm1.regionName(), ma.innerModel().targetResourceRegion()); + } Assertions.assertEquals(1, ma.alertCriterias().size()); Assertions.assertEquals(0, ma.dynamicAlertCriterias().size()); Assertions.assertEquals("Percentage CPU", ma.alertCriterias().get("Metric1").metricName()); @@ -418,7 +418,10 @@ public void canCRUDMultipleResourceMetricAlerts() throws Exception { ma.refresh(); Assertions.assertEquals(2, ma.scopes().size()); Assertions.assertEquals(vm1.type(), ma.innerModel().targetResourceType()); - Assertions.assertEquals(vm1.regionName(), ma.innerModel().targetResourceRegion()); + if (!isPlaybackMode()) { + // targetResourceRegion sanitized + Assertions.assertEquals(vm1.regionName(), ma.innerModel().targetResourceRegion()); + } Assertions.assertEquals(0, ma.alertCriterias().size()); Assertions.assertEquals(1, ma.dynamicAlertCriterias().size()); MetricDynamicAlertCondition condition = ma.dynamicAlertCriterias().get("Metric2"); @@ -486,7 +489,7 @@ public void canCRUDActivityLogAlerts() { Assertions.assertEquals("AutoScale-VM-Creation-Failed", ala.description()); Assertions.assertEquals(true, ala.enabled()); Assertions.assertEquals(1, ala.actionGroupIds().size()); - Assertions.assertEquals(ag.id(), ala.actionGroupIds().iterator().next()); + assertResourceIdEquals(ag.id(), ala.actionGroupIds().iterator().next()); Assertions.assertEquals(3, ala.equalsConditions().size()); Assertions.assertEquals("Administrative", ala.equalsConditions().get("category")); Assertions.assertEquals(justAvm.id(), ala.equalsConditions().get("resourceId")); @@ -505,9 +508,7 @@ public void canCRUDActivityLogAlerts() { Assertions.assertEquals(ala.equalsConditions().size(), alaFromGet.equalsConditions().size()); Assertions .assertEquals(ala.equalsConditions().get("category"), alaFromGet.equalsConditions().get("category")); - Assertions - .assertEquals( - ala.equalsConditions().get("resourceId"), alaFromGet.equalsConditions().get("resourceId")); + assertResourceIdEquals(ala.equalsConditions().get("resourceId"), alaFromGet.equalsConditions().get("resourceId")); Assertions .assertEquals( ala.equalsConditions().get("operationName"), alaFromGet.equalsConditions().get("operationName")); @@ -526,7 +527,7 @@ public void canCRUDActivityLogAlerts() { Assertions.assertEquals("AutoScale-VM-Creation-Failed", ala.description()); Assertions.assertEquals(false, ala.enabled()); Assertions.assertEquals(1, ala.actionGroupIds().size()); - Assertions.assertEquals(ag.id(), ala.actionGroupIds().iterator().next()); + assertResourceIdEquals(ag.id(), ala.actionGroupIds().iterator().next()); Assertions.assertEquals(3, ala.equalsConditions().size()); Assertions.assertEquals("Administrative", ala.equalsConditions().get("category")); Assertions.assertEquals(justAvm.id(), ala.equalsConditions().get("resourceId")); @@ -549,9 +550,7 @@ public void canCRUDActivityLogAlerts() { Assertions.assertEquals(ala.equalsConditions().size(), alaFromGet.equalsConditions().size()); Assertions .assertEquals(ala.equalsConditions().get("category"), alaFromGet.equalsConditions().get("category")); - Assertions - .assertEquals( - ala.equalsConditions().get("resourceId"), alaFromGet.equalsConditions().get("resourceId")); + assertResourceIdEquals(ala.equalsConditions().get("resourceId"), alaFromGet.equalsConditions().get("resourceId")); Assertions.assertEquals(ala.equalsConditions().get("status"), alaFromGet.equalsConditions().get("status")); Assertions .assertEquals( diff --git a/sdk/resourcemanager/azure-resourcemanager-redis/assets.json b/sdk/resourcemanager/azure-resourcemanager-redis/assets.json index 300b0c10bd338..f6fa4a2e02330 100644 --- a/sdk/resourcemanager/azure-resourcemanager-redis/assets.json +++ b/sdk/resourcemanager/azure-resourcemanager-redis/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "java", "TagPrefix": "java/resourcemanager/azure-resourcemanager-redis", - "Tag": "java/resourcemanager/azure-resourcemanager-redis_e08fbbf910" + "Tag": "java/resourcemanager/azure-resourcemanager-redis_0a4a807d07" } diff --git a/sdk/resourcemanager/azure-resourcemanager-redis/src/test/java/com/azure/resourcemanager/redis/RedisCacheOperationsTests.java b/sdk/resourcemanager/azure-resourcemanager-redis/src/test/java/com/azure/resourcemanager/redis/RedisCacheOperationsTests.java index 95fcb93817304..76d8ae593809f 100644 --- a/sdk/resourcemanager/azure-resourcemanager-redis/src/test/java/com/azure/resourcemanager/redis/RedisCacheOperationsTests.java +++ b/sdk/resourcemanager/azure-resourcemanager-redis/src/test/java/com/azure/resourcemanager/redis/RedisCacheOperationsTests.java @@ -6,7 +6,6 @@ import com.azure.core.management.AzureEnvironment; import com.azure.core.management.Region; import com.azure.core.management.exception.ManagementException; -import com.azure.core.test.annotation.LiveOnly; import com.azure.resourcemanager.redis.models.DayOfWeek; import com.azure.resourcemanager.redis.models.PublicNetworkAccess; import com.azure.resourcemanager.redis.models.RebootType; @@ -317,9 +316,7 @@ public void canCRUDLinkedServers() throws Exception { } @Test - @LiveOnly public void canCreateRedisWithRdbAof() { - // LiveOnly because "connectionString cannot be stored in recordings." StorageAccount storageAccount = storageManager .storageAccounts() @@ -367,8 +364,10 @@ public void canCreateRedisWithRdbAof() { .withRedisConfiguration("aof-storage-connection-string-1", connectionString) .create(); Assertions.assertEquals("true", redisCache.innerModel().redisConfiguration().aofBackupEnabled()); - Assertions.assertNotNull(redisCache.innerModel().redisConfiguration().aofStorageConnectionString0()); - Assertions.assertNotNull(redisCache.innerModel().redisConfiguration().aofStorageConnectionString1()); + if (!isPlaybackMode()) { + Assertions.assertNotNull(redisCache.innerModel().redisConfiguration().aofStorageConnectionString0()); + Assertions.assertNotNull(redisCache.innerModel().redisConfiguration().aofStorageConnectionString1()); + } assertSameVersion(RedisCache.RedisVersion.V6, redisCache.redisVersion()); } diff --git a/sdk/resourcemanager/azure-resourcemanager-resources/assets.json b/sdk/resourcemanager/azure-resourcemanager-resources/assets.json index 95bc070b71930..c9761ac3bee78 100644 --- a/sdk/resourcemanager/azure-resourcemanager-resources/assets.json +++ b/sdk/resourcemanager/azure-resourcemanager-resources/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "java", "TagPrefix": "java/resourcemanager/azure-resourcemanager-resources", - "Tag": "java/resourcemanager/azure-resourcemanager-resources_d2b26f3d6e" + "Tag": "java/resourcemanager/azure-resourcemanager-resources_0725d576ae" } diff --git a/sdk/resourcemanager/azure-resourcemanager-resources/src/test/java/com/azure/resourcemanager/resources/DeploymentsTests.java b/sdk/resourcemanager/azure-resourcemanager-resources/src/test/java/com/azure/resourcemanager/resources/DeploymentsTests.java index a4c355636f15f..f42b64e15f681 100644 --- a/sdk/resourcemanager/azure-resourcemanager-resources/src/test/java/com/azure/resourcemanager/resources/DeploymentsTests.java +++ b/sdk/resourcemanager/azure-resourcemanager-resources/src/test/java/com/azure/resourcemanager/resources/DeploymentsTests.java @@ -217,35 +217,38 @@ public void canCancelVirtualNetworkDeployment() throws Exception { @Test public void canUpdateVirtualNetworkDeployment() throws Exception { final String dp = "dpC" + testId; - - // Begin create - Accepted acceptedDeployment = resourceClient.deployments() - .define(dp) - .withExistingResourceGroup(rgName) - .withTemplateLink(TEMPLATE_URI, CONTENT_VERSION) - .withParametersLink(PARAMETERS_URI, CONTENT_VERSION) - .withMode(DeploymentMode.COMPLETE) - .beginCreate(); - Deployment createdDeployment = acceptedDeployment.getActivationResponse().getValue(); - Deployment deployment = resourceClient.deployments().getByResourceGroup(rgName, dp); - Assertions.assertEquals(createdDeployment.correlationId(), deployment.correlationId()); - Assertions.assertEquals(dp, deployment.name()); - // Cancel - deployment.cancel(); - deployment = resourceClient.deployments().getByResourceGroup(rgName, dp); - Assertions.assertEquals("Canceled", deployment.provisioningState()); - // Update - deployment.update() - .withTemplate(UPDATE_TEMPLATE) - .withParameters(UPDATE_PARAMETERS) - .withMode(DeploymentMode.INCREMENTAL) - .apply(); - deployment = resourceClient.deployments().getByResourceGroup(rgName, dp); - Assertions.assertEquals(DeploymentMode.INCREMENTAL, deployment.mode()); - Assertions.assertEquals("Succeeded", deployment.provisioningState()); - GenericResource genericVnet = resourceClient.genericResources().get(rgName, "Microsoft.Network", "", "virtualnetworks", "VNet2", NETWORK_API_VERSION); - Assertions.assertNotNull(genericVnet); - resourceClient.genericResources().delete(rgName, "Microsoft.Network", "", "virtualnetworks", "VNet2", NETWORK_API_VERSION); + try { + // Begin create + Accepted acceptedDeployment = resourceClient.deployments() + .define(dp) + .withExistingResourceGroup(rgName) + .withTemplateLink(TEMPLATE_URI, CONTENT_VERSION) + .withParametersLink(PARAMETERS_URI, CONTENT_VERSION) + .withMode(DeploymentMode.COMPLETE) + .beginCreate(); + Deployment createdDeployment = acceptedDeployment.getActivationResponse().getValue(); + Deployment deployment = resourceClient.deployments().getByResourceGroup(rgName, dp); + Assertions.assertEquals(createdDeployment.correlationId(), deployment.correlationId()); + Assertions.assertEquals(dp, deployment.name()); + // Cancel + deployment.cancel(); + deployment = resourceClient.deployments().getByResourceGroup(rgName, dp); + Assertions.assertEquals("Canceled", deployment.provisioningState()); + // Update + deployment.update() + .withTemplate(UPDATE_TEMPLATE) + .withParameters(UPDATE_PARAMETERS) + .withMode(DeploymentMode.INCREMENTAL) + .apply(); + deployment = resourceClient.deployments().getByResourceGroup(rgName, dp); + Assertions.assertEquals(DeploymentMode.INCREMENTAL, deployment.mode()); + Assertions.assertEquals("Succeeded", deployment.provisioningState()); + GenericResource genericVnet = resourceClient.genericResources().get(rgName, "Microsoft.Network", "", "virtualnetworks", "VNet2", NETWORK_API_VERSION); + Assertions.assertNotNull(genericVnet); + resourceClient.genericResources().delete(rgName, "Microsoft.Network", "", "virtualnetworks", "VNet2", NETWORK_API_VERSION); + } finally { + resourceClient.deployments().deleteByResourceGroup(rgName, dp); + } } @Test diff --git a/sdk/resourcemanager/azure-resourcemanager/assets.json b/sdk/resourcemanager/azure-resourcemanager/assets.json index 6e1850be1d664..403abe3a38901 100644 --- a/sdk/resourcemanager/azure-resourcemanager/assets.json +++ b/sdk/resourcemanager/azure-resourcemanager/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "java", "TagPrefix": "java/resourcemanager/azure-resourcemanager", - "Tag": "java/resourcemanager/azure-resourcemanager_b75c83930c" + "Tag": "java/resourcemanager/azure-resourcemanager_5772fed02d" } diff --git a/sdk/resourcemanager/azure-resourcemanager/src/test/java/com/azure/resourcemanager/AzureResourceManagerTests.java b/sdk/resourcemanager/azure-resourcemanager/src/test/java/com/azure/resourcemanager/AzureResourceManagerTests.java index 8803ca61886c4..005e75db40a55 100644 --- a/sdk/resourcemanager/azure-resourcemanager/src/test/java/com/azure/resourcemanager/AzureResourceManagerTests.java +++ b/sdk/resourcemanager/azure-resourcemanager/src/test/java/com/azure/resourcemanager/AzureResourceManagerTests.java @@ -13,7 +13,6 @@ import com.azure.core.management.exception.ManagementException; import com.azure.core.management.profile.AzureProfile; import com.azure.core.test.annotation.DoNotRecord; -import com.azure.core.test.annotation.LiveOnly; import com.azure.core.test.models.TestProxySanitizer; import com.azure.core.test.models.TestProxySanitizerType; import com.azure.core.util.logging.ClientLogger; @@ -1094,10 +1093,8 @@ public void createStorageAccount() { // } @Test - @LiveOnly public void testTrafficManager() throws Exception { - // LiveOnly because "subscription references cannot be stored in recordings" - new TestTrafficManager(azureResourceManager.publicIpAddresses()) + new TestTrafficManager(azureResourceManager.publicIpAddresses(), isPlaybackMode()) .runTest(azureResourceManager.trafficManagerProfiles(), azureResourceManager.resourceGroups()); } diff --git a/sdk/resourcemanager/azure-resourcemanager/src/test/java/com/azure/resourcemanager/TestTrafficManager.java b/sdk/resourcemanager/azure-resourcemanager/src/test/java/com/azure/resourcemanager/TestTrafficManager.java index 71dc359531418..1eb38fdcd5e9a 100644 --- a/sdk/resourcemanager/azure-resourcemanager/src/test/java/com/azure/resourcemanager/TestTrafficManager.java +++ b/sdk/resourcemanager/azure-resourcemanager/src/test/java/com/azure/resourcemanager/TestTrafficManager.java @@ -3,11 +3,11 @@ package com.azure.resourcemanager; +import com.azure.core.management.Region; import com.azure.core.util.logging.ClientLogger; import com.azure.core.util.logging.LogLevel; import com.azure.resourcemanager.network.models.PublicIpAddress; import com.azure.resourcemanager.network.models.PublicIpAddresses; -import com.azure.core.management.Region; import com.azure.resourcemanager.resources.models.ResourceGroup; import com.azure.resourcemanager.trafficmanager.models.EndpointType; import com.azure.resourcemanager.trafficmanager.models.TargetAzureResourceType; @@ -16,14 +16,16 @@ import com.azure.resourcemanager.trafficmanager.models.TrafficManagerNestedProfileEndpoint; import com.azure.resourcemanager.trafficmanager.models.TrafficManagerProfile; import com.azure.resourcemanager.trafficmanager.models.TrafficManagerProfiles; -import java.util.Map; import org.junit.jupiter.api.Assertions; +import java.util.Map; + /** Test of traffic manager management. */ public class TestTrafficManager extends TestTemplate { private static final ClientLogger LOGGER = new ClientLogger(TestTrafficManager.class); private final PublicIpAddresses publicIpAddresses; + private final boolean isPlaybackMode; private final String externalEndpointName21 = "external-ep-1"; private final String externalEndpointName22 = "external-ep-2"; @@ -36,8 +38,9 @@ public class TestTrafficManager extends TestTemplate