-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Changes from 4 commits
c305ffa
550f684
8bb4c39
49acf53
ff8908b
996a691
aa03324
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 |
---|---|---|
|
@@ -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 |
---|---|---|
|
@@ -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); | ||
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() | ||
|
@@ -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"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please revert There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)) | ||
{ | ||
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed |
||
|
||
// Get the policy and verify the weekly policy is two weeks | ||
// | ||
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed |
||
|
||
// Get the policy and verify the weekly policy is two weeks | ||
// | ||
|
@@ -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"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please clear out the names There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could just call There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use Assert.Equal There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() | ||
{ | ||
|
There was a problem hiding this comment.
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)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed the checks