Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add resource group based LTR APIs + tests to azure sdk #6957

Merged
merged 7 commits into from
Jul 19, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions eng/mgmt/mgmtmetadata/sql_resource-manager.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ Commencing code generation
Generating CSharp code
Executing AutoRest command
cmd.exe /c autorest.cmd https://github.com/Azure/azure-rest-api-specs/blob/master/specification/sql/resource-manager/readme.md --csharp --version=latest --reflect-api-versions --csharp-sdks-folder=.
2019-07-11 15:27:39 UTC
2019-07-16 21:28:54 UTC
Azure-rest-api-specs repository information
GitHub fork: Azure
Branch: master
Commit: 808cfe2da58aa6f1d93bed748004dfb97268e6e3
Commit: 737110f8edd3689144c45d6fd34e7c6143171ab8
AutoRest information
Requested version: latest
Bootstrapper version: [email protected]

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,16 @@ public static IEnumerable<Tuple<string, string, string>> ApiInfo_SqlManagementCl
}.AsEnumerable();
}
}
// BEGIN: Code Generation Metadata Section
public static readonly String AutoRestVersion = "latest";
public static readonly String AutoRestBootStrapperVersion = "[email protected]";
public static readonly String AutoRestCmdExecuted = "cmd.exe /c autorest.cmd https://github.com/Azure/azure-rest-api-specs/blob/master/specification/sql/resource-manager/readme.md --csharp --version=latest --reflect-api-versions --csharp-sdks-folder=.";
public static readonly String GithubForkName = "Azure";
public static readonly String GithubBranchName = "master";
public static readonly String GithubCommidId = "737110f8edd3689144c45d6fd34e7c6143171ab8";
public static readonly String CodeGenerationErrors = "";
public static readonly String GithubRepoName = "azure-rest-api-specs";
// END: Code Generation Metadata Section
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,19 @@ public partial class SqlManagementClient : ServiceClient<SqlManagementClient>, I
/// </summary>
public virtual IManagedInstancesOperations ManagedInstances { get; private set; }

/// <summary>
/// Initializes a new instance of the SqlManagementClient class.
/// </summary>
/// <param name='httpClient'>
/// HttpClient to be used
/// </param>
/// <param name='disposeHttpClient'>
/// True: will dispose the provided httpClient on calling SqlManagementClient.Dispose(). False: will not dispose provided httpClient</param>
protected SqlManagementClient(HttpClient httpClient, bool disposeHttpClient) : base(httpClient, disposeHttpClient)
{
Initialize();
}

/// <summary>
/// Initializes a new instance of the SqlManagementClient class.
/// </summary>
Expand Down Expand Up @@ -577,6 +590,33 @@ public SqlManagementClient(ServiceClientCredentials credentials, params Delegati
}
}

/// <summary>
/// Initializes a new instance of the SqlManagementClient class.
/// </summary>
/// <param name='credentials'>
/// Required. Credentials needed for the client to connect to Azure.
/// </param>
/// <param name='httpClient'>
/// HttpClient to be used
/// </param>
/// <param name='disposeHttpClient'>
/// True: will dispose the provided httpClient on calling SqlManagementClient.Dispose(). False: will not dispose provided httpClient</param>
/// <exception cref="System.ArgumentNullException">
/// Thrown when a required parameter is null
/// </exception>
public SqlManagementClient(ServiceClientCredentials credentials, HttpClient httpClient, bool disposeHttpClient) : this(httpClient, disposeHttpClient)
{
if (credentials == null)
{
throw new System.ArgumentNullException("credentials");
}
Credentials = credentials;
if (Credentials != null)
{
Credentials.InitializeServiceClient(this);
}
}

/// <summary>
/// Initializes a new instance of the SqlManagementClient class.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@
<PackageId>Microsoft.Azure.Management.Sql</PackageId>
<Description>Azure SQL Management SDK library</Description>
<AssemblyName>Microsoft.Azure.Management.Sql</AssemblyName>
<Version>1.32.0-preview</Version>
<Version>1.33.0-preview</Version>
<PackageTags>Microsoft Azure SQL Management;SQL;SQL Management;</PackageTags>
<PackageReleaseNotes>
<![CDATA[
New features:
- Added support for instance pools.
- Added support for instance pool usages.
- Added support for managed instances in instance pools.
- Added support for resource group based LTR APIs.
]]>
</PackageReleaseNotes>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@
[assembly: AssemblyTitle("Microsoft Azure SQL Management Library")]
[assembly: AssemblyDescription("Provides management functionality for Microsoft Azure SQL.")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.32.0.0")]
[assembly: AssemblyFileVersion("1.33.0.0")]

Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,27 @@ public void TestLongTermRetentionV2Backups()
}
}

[Fact]
public void TestLongTermRetentionV2ResourceGroupBasedBackups()
{
using (SqlManagementTestContext context = new SqlManagementTestContext(this))
{
ResourceGroup resourceGroup = context.CreateResourceGroup();
Server server = context.CreateServer(resourceGroup);
SqlManagementClient sqlClient = context.GetClient<SqlManagementClient>();
Database database = sqlClient.Databases.CreateOrUpdate(resourceGroup.Name, server.Name, SqlManagementTestUtilities.GenerateName(), new Database { Location = server.Location });

// Get the backups under the resource group, server and database. Assert there are no backups returned.
//
IPage<LongTermRetentionBackup> backups = sqlClient.LongTermRetentionBackups.ListByResourceGroupLocation(resourceGroup.Name, server.Location);
Assert.True(backups.Count() == 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you care how many backups are returned? Don't you just want the API to succeed (i.e. not throw)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed the checks

backups = sqlClient.LongTermRetentionBackups.ListByResourceGroupServer(resourceGroup.Name, server.Location, server.Name);
Assert.True(backups.Count() == 0);
backups = sqlClient.LongTermRetentionBackups.ListByResourceGroupDatabase(resourceGroup.Name, server.Location, server.Name, database.Name);
Assert.True(backups.Count() == 0);
Assert.Throws(typeof(CloudException), () => sqlClient.LongTermRetentionBackups.GetByResourceGroup(resourceGroup.Name, server.Location, server.Name, database.Name, "backup"));
}
}

[Fact]
public void TestShortTermRetentionPolicyOnPremium()
Expand Down Expand Up @@ -298,10 +319,10 @@ public void TestLongTermRetentionV2Crud()
// Set the weekly retention on the database so that the first backup gets picked up
// Wait about 18 hours until it gets properly copied and you see the backup when run get backups
//
string locationName = "";
string resourceGroupName = "";
string serverName = "";
string databaseName = "";
string locationName = "brazilsouth";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

discussed offline, added comments and keep the change so test could pass in playback mode

string resourceGroupName = "brrg";
string serverName = "ltrtest3";
string databaseName = "mydb";

using (SqlManagementTestContext context = new SqlManagementTestContext(this))
{
Expand All @@ -312,7 +333,7 @@ public void TestLongTermRetentionV2Crud()
//
Microsoft.Azure.Management.Sql.Models.BackupLongTermRetentionPolicy parameters = new Microsoft.Azure.Management.Sql.Models.BackupLongTermRetentionPolicy(weeklyRetention: "P2W");
var policyResult = sqlClient.BackupLongTermRetentionPolicies.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName, serverName, databaseName, parameters).Result;
sqlClient.GetPutOrPatchOperationResultAsync(policyResult, new Dictionary<string, List<string>>(), CancellationToken.None).Wait();
Assert.Equal(System.Net.HttpStatusCode.OK, policyResult.Response.StatusCode);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed


// Get the policy and verify the weekly policy is two weeks
//
Expand Down Expand Up @@ -364,7 +385,7 @@ public void TestLongTermRetentionV2Crud()
//
parameters = new Microsoft.Azure.Management.Sql.Models.BackupLongTermRetentionPolicy(weeklyRetention: "P1W");
policyResult = sqlClient.BackupLongTermRetentionPolicies.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName, serverName, databaseName, parameters).Result;
sqlClient.GetPutOrPatchOperationResultAsync(policyResult, new Dictionary<string, List<string>>(), CancellationToken.None).Wait();
Assert.Equal(System.Net.HttpStatusCode.OK, policyResult.Response.StatusCode);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed


// Get the policy and verify the weekly policy is two weeks
//
Expand All @@ -373,6 +394,83 @@ public void TestLongTermRetentionV2Crud()
}
}

[Fact(Skip = "Manual test due to long setup time required (over 18 hours).")]
public void TestLongTermRetentionV2ResourceGroupBasedCrud()
{
// MANUAL INSTRUCTIONS
// Create a server and database and fill in the appropriate information below
// Set the weekly retention on the database so that the first backup gets picked up
// Wait about 18 hours until it gets properly copied and you see the backup when run get backups
//
string locationName = "brazilsouth";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please clear out the names

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

discussed offline will keep the change

string resourceGroupName = "brrg";
string serverName = "ltrtest3";
string databaseName = "mydb";

using (SqlManagementTestContext context = new SqlManagementTestContext(this))
{
SqlManagementClient sqlClient = context.GetClient<SqlManagementClient>();
Database database = sqlClient.Databases.Get(resourceGroupName, serverName, databaseName);

// Set the retention policy to two weeks for the weekly retention policy
//
Microsoft.Azure.Management.Sql.Models.BackupLongTermRetentionPolicy parameters = new Microsoft.Azure.Management.Sql.Models.BackupLongTermRetentionPolicy(weeklyRetention: "P2W");
var policyResult = sqlClient.BackupLongTermRetentionPolicies.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName, serverName, databaseName, parameters).Result;
Assert.Equal(System.Net.HttpStatusCode.OK, policyResult.Response.StatusCode);

// Get the policy and verify the weekly policy is two weeks
//
Microsoft.Azure.Management.Sql.Models.BackupLongTermRetentionPolicy policy = sqlClient.BackupLongTermRetentionPolicies.Get(resourceGroupName, serverName, databaseName);
Assert.Equal(parameters.WeeklyRetention, policy.WeeklyRetention);

// Get the backups under the location, server, and database. Assert there is at least one backup for each call.
//
IPage<LongTermRetentionBackup> backups = sqlClient.LongTermRetentionBackups.ListByResourceGroupLocation(resourceGroupName, locationName);
Assert.True(backups.Count() >= 1);
backups = sqlClient.LongTermRetentionBackups.ListByResourceGroupServer(resourceGroupName, locationName, serverName);
Assert.True(backups.Count() >= 1);
backups = sqlClient.LongTermRetentionBackups.ListByResourceGroupDatabase(resourceGroupName, locationName, serverName, databaseName);
Assert.True(backups.Count() >= 1);

// Get a specific backup using the previous call
//
LongTermRetentionBackup backup = sqlClient.LongTermRetentionBackups.GetByResourceGroup(resourceGroupName, locationName, serverName, databaseName, backups.First().Name);
Assert.NotNull(backup);

// Restore the backup
//
Database restoredDatabase = sqlClient.Databases.CreateOrUpdate(
resourceGroupName, serverName, databaseName: SqlManagementTestUtilities.GenerateName(),
parameters: new Database
{
Location = locationName,
CreateMode = CreateMode.RestoreLongTermRetentionBackup,
LongTermRetentionBackupResourceId = backup.Id
});

// Delete the backup.
//
var deleteResult = sqlClient.LongTermRetentionBackups.DeleteByResourceGroupWithHttpMessagesAsync(resourceGroupName, locationName, serverName, databaseName, backup.Name).Result;
Assert.Equal(System.Net.HttpStatusCode.OK, deleteResult.Response.StatusCode);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you checking statuscode? generate client internals already check the status code. I don't think that this is a detail that you really care about at this layer.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could just call sqlClient.LongTermRetentionBackups.DeleteByResourceGroup(...) and let the generated SDK do its own validation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, did that


// Verify the backup is gone.
//
backups = sqlClient.LongTermRetentionBackups.ListByResourceGroupDatabase(resourceGroupName, locationName, serverName, databaseName);
Assert.True(backups.Count() == 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Assert.Equal

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the check


// Set the retention policy back to one week for the weekly retention policy
//
parameters = new Microsoft.Azure.Management.Sql.Models.BackupLongTermRetentionPolicy(weeklyRetention: "P1W");
policyResult = sqlClient.BackupLongTermRetentionPolicies.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName, serverName, databaseName, parameters).Result;
Assert.Equal(System.Net.HttpStatusCode.OK, policyResult.Response.StatusCode);

// Get the policy and verify the weekly policy is one week
//
policy = sqlClient.BackupLongTermRetentionPolicies.Get(resourceGroupName, serverName, databaseName);
Assert.Equal(parameters.WeeklyRetention, policy.WeeklyRetention);
}
}

[Fact(Skip = "Manual test due to long setup time required (potentially several hours).")]
public void TestDatabaseGeoRecovery()
{
Expand Down
Loading