From 2a3b5ade8e7c90eb29e3beff0ba9e446027a7d17 Mon Sep 17 00:00:00 2001 From: hongli750210 Date: Fri, 8 Mar 2024 16:36:52 +0800 Subject: [PATCH] Fix DeleteOptions on Public Ip Address (issue#38806 NetworkInterface fix only) --- .../azure-resourcemanager-network/assets.json | 2 +- .../NetworkInterfaceOperationsTests.java | 87 +++++++++++++++++++ 2 files changed, 88 insertions(+), 1 deletion(-) diff --git a/sdk/resourcemanager/azure-resourcemanager-network/assets.json b/sdk/resourcemanager/azure-resourcemanager-network/assets.json index e17e065241714..96a791f5acf73 100644 --- a/sdk/resourcemanager/azure-resourcemanager-network/assets.json +++ b/sdk/resourcemanager/azure-resourcemanager-network/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "java", "TagPrefix": "java/resourcemanager/azure-resourcemanager-network", - "Tag": "java/resourcemanager/azure-resourcemanager-network_ebb33fc834" + "Tag": "java/resourcemanager/azure-resourcemanager-network_3b15fe745d" } diff --git a/sdk/resourcemanager/azure-resourcemanager-network/src/test/java/com/azure/resourcemanager/network/NetworkInterfaceOperationsTests.java b/sdk/resourcemanager/azure-resourcemanager-network/src/test/java/com/azure/resourcemanager/network/NetworkInterfaceOperationsTests.java index b453110b8d002..990fbefc01ba7 100644 --- a/sdk/resourcemanager/azure-resourcemanager-network/src/test/java/com/azure/resourcemanager/network/NetworkInterfaceOperationsTests.java +++ b/sdk/resourcemanager/azure-resourcemanager-network/src/test/java/com/azure/resourcemanager/network/NetworkInterfaceOperationsTests.java @@ -823,6 +823,93 @@ public void canUpdateSingleDeleteOptionAndUpdateIPConfiguration() { ipConfigurationInnerList.forEach(ipConfig -> Assertions.assertEquals("secondary", ipConfig.name())); } + @Test + public void canUpdateMultipleDeleteOptionWithDefineSecondaryIPConfiguration() { + String subnetName = generateRandomResourceName("subnet-", 15); + resourceManager.resourceGroups().define(rgName).withRegion(Region.US_EAST).create(); + Network vnet = networkManager.networks() + .define(generateRandomResourceName("vnet-", 15)) + .withRegion(Region.US_EAST) + .withExistingResourceGroup(rgName) + .withAddressSpace("10.0.0.0/28") + .withSubnet(subnetName, "10.0.0.0/28") + .create(); + + NetworkInterface nic = networkManager.networkInterfaces() + .define(generateRandomResourceName("nic-", 15)) + .withRegion(Region.US_EAST) + .withExistingResourceGroup(rgName) + .withExistingPrimaryNetwork(vnet) + .withSubnet(subnetName) + .withPrimaryPrivateIPAddressDynamic() + .withNewPrimaryPublicIPAddress() + .create(); + + nic.update() + .withPublicIPAddressDeleteOptions(DeleteOptions.DELETE, "primary") + .defineSecondaryIPConfiguration("secondary") + .withExistingNetwork(vnet) + .withSubnet(subnetName) + .withPrivateIpAddressDynamic() + .withNewPublicIpAddress() + .attach() + .withPublicIPAddressDeleteOptions(DeleteOptions.DETACH, "secondary") + .apply(); + + nic.refresh(); + Assertions.assertEquals(DeleteOptions.DELETE, nic.primaryIPConfiguration().innerModel().publicIpAddress().deleteOption()); + List ipConfigurationInnerList = nic.ipConfigurations().values() + .stream().filter(ipConfig -> DeleteOptions.DETACH.equals(ipConfig.innerModel().publicIpAddress().deleteOption())) + .collect(Collectors.toList()); + Assertions.assertEquals(1, ipConfigurationInnerList.size()); + ipConfigurationInnerList.forEach(ipConfig -> Assertions.assertEquals("secondary",ipConfig.name())); + } + + @Test + public void canUpdateMultipleDeleteOptionWithUpdateIPConfiguration() { + String subnetName = generateRandomResourceName("subnet-", 15); + resourceManager.resourceGroups().define(rgName).withRegion(Region.US_EAST).create(); + Network vnet = networkManager.networks() + .define(generateRandomResourceName("vnet-", 15)) + .withRegion(Region.US_EAST) + .withExistingResourceGroup(rgName) + .withAddressSpace("10.0.0.0/28") + .withSubnet(subnetName, "10.0.0.0/28") + .create(); + + NetworkInterface nic = networkManager.networkInterfaces() + .define(generateRandomResourceName("nic-", 15)) + .withRegion(Region.US_EAST) + .withExistingResourceGroup(rgName) + .withExistingPrimaryNetwork(vnet) + .withSubnet(subnetName) + .withPrimaryPrivateIPAddressDynamic() + .withNewPrimaryPublicIPAddress() + .defineSecondaryIPConfiguration("secondary") + .withExistingNetwork(vnet) + .withSubnet(subnetName) + .withPrivateIpAddressDynamic() + .withNewPublicIpAddress() + .attach() + .create(); + + nic.update() + .withPublicIPAddressDeleteOptions(DeleteOptions.DELETE, "primary") + .updateIPConfiguration("secondary") + .withNewPublicIpAddress() + .parent() + .withPublicIPAddressDeleteOptions(DeleteOptions.DETACH, "secondary") + .apply(); + + nic.refresh(); + Assertions.assertEquals(DeleteOptions.DELETE, nic.primaryIPConfiguration().innerModel().publicIpAddress().deleteOption()); + List ipConfigurationInnerList = nic.ipConfigurations().values() + .stream().filter(ipConfig -> DeleteOptions.DETACH.equals(ipConfig.innerModel().publicIpAddress().deleteOption())) + .collect(Collectors.toList()); + Assertions.assertEquals(1, ipConfigurationInnerList.size()); + ipConfigurationInnerList.forEach(ipConfig -> Assertions.assertEquals("secondary",ipConfig.name())); + } + private NatGatewayInner createNatGateway() { String natGatewayName = generateRandomResourceName("natgw", 10); return networkManager.serviceClient()