Skip to content

Commit

Permalink
Fix DeleteOptions on Public Ip Address (issue#38806 NetworkInterface …
Browse files Browse the repository at this point in the history
…fix only)
  • Loading branch information
v-hongli1 committed Mar 8, 2024
1 parent 150d4dd commit 2a3b5ad
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<NicIpConfiguration> 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<NicIpConfiguration> 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()
Expand Down

0 comments on commit 2a3b5ad

Please sign in to comment.