Skip to content

Commit

Permalink
mgmt, fix dns cname update flow (#26400)
Browse files Browse the repository at this point in the history
* mgmt, fix dns cname update flow

* changelog

* fix an unrelated changelog
  • Loading branch information
weidongxu-microsoft authored Jan 11, 2022
1 parent 2025744 commit b512734
Show file tree
Hide file tree
Showing 7 changed files with 771 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

## 2.11.0-beta.1 (Unreleased)

### Features Added

### Breaking Changes
### Other Changes

### Bugs Fixed
#### Dependency Updates

### Other Changes
- Updated `api-version` to `2021-10-01`.

## 2.10.0 (2021-11-22)

Expand Down
4 changes: 4 additions & 0 deletions sdk/resourcemanager/azure-resourcemanager-dns/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## 2.11.0-beta.1 (Unreleased)

### Bugs Fixed

- Fixed issue where update of `CnameRecordSet` did not update `canonicalName`.

### Other Changes

#### Dependency Updates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ public String canonicalName() {

@Override
protected RecordSetInner prepareForUpdate(RecordSetInner resource) {
if (resource.cnameRecord() == null) {
resource.withCnameRecord(new CnameRecord());
}
if (innerModel().cnameRecord().cname() != null) {
resource.cnameRecord().withCname(innerModel().cnameRecord().cname());
}
innerModel().withCnameRecord(new CnameRecord());
return resource;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.resourcemanager.dns;

import com.azure.core.credential.TokenCredential;
import com.azure.core.http.HttpClient;
import com.azure.core.http.HttpPipeline;
import com.azure.core.http.policy.HttpLogOptions;
import com.azure.core.http.policy.HttpPipelinePolicy;
import com.azure.core.http.policy.RetryPolicy;
import com.azure.core.management.profile.AzureProfile;
import com.azure.resourcemanager.resources.ResourceManager;
import com.azure.resourcemanager.resources.fluentcore.utils.HttpPipelineProvider;
import com.azure.resourcemanager.resources.fluentcore.utils.ResourceManagerUtils;
import com.azure.resourcemanager.test.ResourceManagerTestBase;
import com.azure.resourcemanager.test.utils.TestDelayProvider;

import java.time.temporal.ChronoUnit;
import java.util.List;

public class DnsTestBase extends ResourceManagerTestBase {

protected String rgName = "";

protected ResourceManager resourceManager;
protected DnsZoneManager zoneManager;

@Override
protected HttpPipeline buildHttpPipeline(
TokenCredential credential,
AzureProfile profile,
HttpLogOptions httpLogOptions,
List<HttpPipelinePolicy> policies,
HttpClient httpClient) {
return HttpPipelineProvider.buildHttpPipeline(
credential,
profile,
null,
httpLogOptions,
null,
new RetryPolicy("Retry-After", ChronoUnit.SECONDS),
policies,
httpClient);
}

@Override
protected void initializeClients(HttpPipeline httpPipeline, AzureProfile profile) {
ResourceManagerUtils.InternalRuntimeContext.setDelayProvider(new TestDelayProvider(!isPlaybackMode()));
zoneManager = buildManager(DnsZoneManager.class, httpPipeline, profile);
resourceManager = zoneManager.resourceManager();
rgName = generateRandomResourceName("dnsetagtest", 15);
}

@Override
protected void cleanUpResources() {
resourceManager.resourceGroups().deleteByName(rgName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@

package com.azure.resourcemanager.dns;

import com.azure.core.credential.TokenCredential;
import com.azure.core.http.HttpClient;
import com.azure.core.http.HttpPipeline;
import com.azure.core.http.policy.HttpLogOptions;
import com.azure.core.http.policy.HttpPipelinePolicy;
import com.azure.core.http.policy.RetryPolicy;
import com.azure.core.http.rest.PagedIterable;
import com.azure.core.management.exception.ManagementError;
import com.azure.core.management.exception.ManagementException;
Expand All @@ -20,54 +14,10 @@
import com.azure.resourcemanager.dns.models.ZoneType;
import com.azure.resourcemanager.test.utils.TestUtilities;
import com.azure.core.management.Region;
import com.azure.core.management.profile.AzureProfile;
import com.azure.resourcemanager.resources.ResourceManager;
import com.azure.resourcemanager.resources.fluentcore.utils.HttpPipelineProvider;
import com.azure.resourcemanager.resources.fluentcore.utils.ResourceManagerUtils;
import com.azure.resourcemanager.test.ResourceManagerTestBase;
import com.azure.resourcemanager.test.utils.TestDelayProvider;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.time.temporal.ChronoUnit;
import java.util.List;

public class DnsZoneRecordSetETagTests extends ResourceManagerTestBase {
private String rgName = "";

protected ResourceManager resourceManager;
protected DnsZoneManager zoneManager;

@Override
protected HttpPipeline buildHttpPipeline(
TokenCredential credential,
AzureProfile profile,
HttpLogOptions httpLogOptions,
List<HttpPipelinePolicy> policies,
HttpClient httpClient) {
return HttpPipelineProvider.buildHttpPipeline(
credential,
profile,
null,
httpLogOptions,
null,
new RetryPolicy("Retry-After", ChronoUnit.SECONDS),
policies,
httpClient);
}

@Override
protected void initializeClients(HttpPipeline httpPipeline, AzureProfile profile) {
ResourceManagerUtils.InternalRuntimeContext.setDelayProvider(new TestDelayProvider(!isPlaybackMode()));
zoneManager = buildManager(DnsZoneManager.class, httpPipeline, profile);
resourceManager = zoneManager.resourceManager();
rgName = generateRandomResourceName("dnsetagtest", 15);
}

@Override
protected void cleanUpResources() {
resourceManager.resourceGroups().deleteByName(rgName);
}
public class DnsZoneRecordSetETagTests extends DnsTestBase {

@Test
public void canCreateZoneWithDefaultETag() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.resourcemanager.dns;

import com.azure.core.http.rest.PagedIterable;
import com.azure.core.management.Region;
import com.azure.resourcemanager.dns.models.CnameRecordSet;
import com.azure.resourcemanager.dns.models.DnsZone;
import com.azure.resourcemanager.test.utils.TestUtilities;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class RecordSetTests extends DnsTestBase {

@Test
public void canCRUDCname() {
final Region region = Region.US_EAST;
final String topLevelDomain = "www.contoso" + rgName + ".com";

DnsZone dnsZone =
zoneManager
.zones()
.define(topLevelDomain)
.withNewResourceGroup(rgName, region)
.defineCNameRecordSet("www")
.withAlias("cname.contoso.com")
.withTimeToLive(7200)
.attach()
.create();

// Check CNAME records
dnsZone.refresh();
PagedIterable<CnameRecordSet> cnameRecordSets = dnsZone.cNameRecordSets().list();
Assertions.assertEquals(1, TestUtilities.getSize(cnameRecordSets));
CnameRecordSet cnameRecordSet = cnameRecordSets.iterator().next();
Assertions.assertEquals("www", cnameRecordSet.name());
Assertions.assertEquals(7200, cnameRecordSet.timeToLive());
Assertions.assertEquals("cname.contoso.com", cnameRecordSet.canonicalName());

// Update alias and ttl:
dnsZone
.update()
.updateCNameRecordSet("www")
.withAlias("new.contoso.com")
.withTimeToLive(3600)
.parent()
.apply();

// Check CNAME records
dnsZone.refresh();
PagedIterable<CnameRecordSet> updatedCnameRecordSets = dnsZone.cNameRecordSets().list();
Assertions.assertEquals(1, TestUtilities.getSize(updatedCnameRecordSets));
CnameRecordSet updatedCnameRecordSet = updatedCnameRecordSets.iterator().next();
Assertions.assertEquals(3600, updatedCnameRecordSet.timeToLive());
Assertions.assertEquals("new.contoso.com", updatedCnameRecordSet.canonicalName());
}
}
Loading

0 comments on commit b512734

Please sign in to comment.