public void FailoverReadableSecondaryInstance() { using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { ResourceGroup resourceGroup = new ResourceGroup( TestEnvironmentUtilities.DefaultLocationId, name: "mibrkic"); SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); string managedInstanceName = "sqlcl-failovertests-dotnetsdk1"; VirtualNetwork vnet = ManagedInstanceTestFixture.CreateVirtualNetwork(context, resourceGroup, TestEnvironmentUtilities.DefaultLocationId); Microsoft.Azure.Management.Sql.Models.Sku sku = new Microsoft.Azure.Management.Sql.Models.Sku { Name = "MIBC8G5", Tier = "BusinessCritical" }; ManagedInstance managedInstance = sqlClient.ManagedInstances.CreateOrUpdate(resourceGroup.Name, managedInstanceName + SqlManagementTestUtilities.GenerateName(methodName: "failover_readable_secondary"), new ManagedInstance() { AdministratorLogin = SqlManagementTestUtilities.DefaultLogin, AdministratorLoginPassword = SqlManagementTestUtilities.DefaultPassword, Sku = sku, SubnetId = vnet.Subnets[0].Id, Tags = new Dictionary <string, string>(), Location = TestEnvironmentUtilities.DefaultLocationId, }); Assert.NotNull(managedInstance); sqlClient.ManagedInstances.Failover(resourceGroup.Name, managedInstance.Name, ReplicaType.ReadableSecondary); } }
private void createManagedInstances(SqlManagementTestContext context, ResourceGroup resourceGroup, IList <string> managedInstanceNames) { SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); Sku sku = new Sku(); sku.Name = "MIGP8G4"; sku.Tier = "GeneralPurpose"; VirtualNetwork vnet = ManagedInstanceTestFixture.CreateVirtualNetwork(context, resourceGroup, TestEnvironmentUtilities.DefaultLocationId); foreach (string miName in managedInstanceNames) { ManagedInstance managedInstance = sqlClient.ManagedInstances.CreateOrUpdate(resourceGroup.Name, miName, new ManagedInstance() { AdministratorLogin = SqlManagementTestUtilities.DefaultLogin, AdministratorLoginPassword = SqlManagementTestUtilities.DefaultPassword, SubnetId = vnet.Subnets[0].Id, Tags = new Dictionary <string, string>(), Location = TestEnvironmentUtilities.DefaultLocationId, Sku = sku, }); Assert.NotNull(managedInstance); } }
public void TestSetManagedInstanceActiveDirectoryAdministrator() { string aadAdmin = "aadadmin"; string managedInstanceName = "miaadadmin"; using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { Guid objectId = new Guid(TestEnvironmentUtilities.GetUserObjectId()); Guid tenantId = new Guid(TestEnvironmentUtilities.GetTenantId()); SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); ResourceGroup resourceGroup = context.CreateResourceGroup(); // Create vnet and get the subnet id VirtualNetwork vnet = ManagedInstanceTestFixture.CreateVirtualNetwork(context, resourceGroup, TestEnvironmentUtilities.DefaultLocationId); Sku sku = new Sku(); sku.Name = "MIGP8G4"; sku.Tier = "GeneralPurpose"; ManagedInstance instance = sqlClient.ManagedInstances.CreateOrUpdate(resourceGroup.Name, "crud-tests-" + managedInstanceName, new ManagedInstance() { AdministratorLogin = SqlManagementTestUtilities.DefaultLogin, AdministratorLoginPassword = SqlManagementTestUtilities.DefaultPassword, Sku = sku, SubnetId = vnet.Subnets[0].Id, Tags = new Dictionary <string, string>(), Location = TestEnvironmentUtilities.DefaultLocationId, }); Assert.NotNull(instance); // Add new Active Directory Admin ManagedInstanceAdministrator newAdmin = new ManagedInstanceAdministrator(login: aadAdmin, sid: objectId, tenantId: tenantId); ManagedInstanceAdministrator createResult = sqlClient.ManagedInstanceAdministrators.CreateOrUpdate(resourceGroup.Name, instance.Name, newAdmin); Assert.Equal(aadAdmin, createResult.Login); // Get the current Active Directory Admin ManagedInstanceAdministrator getResult = sqlClient.ManagedInstanceAdministrators.Get(resourceGroup.Name, instance.Name); Assert.Equal(aadAdmin, getResult.Login); Assert.Equal(objectId, getResult.Sid); Assert.Equal(tenantId, getResult.TenantId); // Delete the Active Directory Admin on server sqlClient.ManagedInstanceAdministrators.Delete(resourceGroup.Name, instance.Name); // List all Active Directory Admins for isntance. Microsoft.Azure.Management.Sql.Models.Page1 <ManagedInstanceAdministrator> admins = (Microsoft.Azure.Management.Sql.Models.Page1 <ManagedInstanceAdministrator>)sqlClient.ManagedInstanceAdministrators.ListByInstance(resourceGroup.Name, instance.Name); Assert.True(admins == null || !admins.GetEnumerator().MoveNext()); } }
private ManagedInstance CreateManagedInstance(SqlManagementTestContext context, SqlManagementClient sqlClient, ResourceGroup resourceGroup, string callingMethodName = "CreateManagedInstance") { // Create vnet and get the subnet id VirtualNetwork vnet = ManagedInstanceTestFixture.CreateVirtualNetwork(context, resourceGroup, TestEnvironmentUtilities.DefaultLocationId); Sku sku = new Sku(); sku.Name = "MIGP8G4"; sku.Tier = "GeneralPurpose"; ManagedInstance managedInstance = sqlClient.ManagedInstances.CreateOrUpdate(resourceGroup.Name, _testPrefix + SqlManagementTestUtilities.GenerateName(methodName: callingMethodName), new ManagedInstance() { AdministratorLogin = SqlManagementTestUtilities.DefaultLogin, AdministratorLoginPassword = SqlManagementTestUtilities.DefaultPassword, Sku = sku, SubnetId = vnet.Subnets[0].Id, Tags = new Dictionary <string, string>(), Location = TestEnvironmentUtilities.DefaultLocationId, }); return(managedInstance); }
public void ShortTermRetentionOnDroppedDatabase() { string testPrefix = "manageddatabaserestorescenariotest-"; using (SqlManagementTestContext Context = new SqlManagementTestContext(this)) { SqlManagementClient sqlClient = Context.GetClient <SqlManagementClient>(); ResourceGroup resourceGroup = Context.CreateResourceGroup(); // Create vnet and get the subnet id VirtualNetwork vnet = ManagedInstanceTestFixture.CreateVirtualNetwork(Context, resourceGroup, TestEnvironmentUtilities.DefaultLocationId); Sku sku = new Sku(); sku.Name = "MIGP8G4"; sku.Tier = "GeneralPurpose"; ManagedInstance managedInstance = sqlClient.ManagedInstances.CreateOrUpdate(resourceGroup.Name, testPrefix + SqlManagementTestUtilities.GenerateName(), new ManagedInstance() { AdministratorLogin = SqlManagementTestUtilities.DefaultLogin, AdministratorLoginPassword = SqlManagementTestUtilities.DefaultPassword, Sku = sku, SubnetId = vnet.Subnets[0].Id, Tags = new Dictionary <string, string>(), Location = TestEnvironmentUtilities.DefaultLocationId, }); // Create managed database // string dbName = SqlManagementTestUtilities.GenerateName(testPrefix); var db1 = sqlClient.ManagedDatabases.CreateOrUpdate(resourceGroup.Name, managedInstance.Name, dbName, new ManagedDatabase() { Location = managedInstance.Location, }); Assert.NotNull(db1); int startingRetention = 25; int invalidValue = 35; int validValue = 20; // Attempt to increase retention period to 25 days and verfiy that the operation succeeded. Since increasing of retention days for dropped database is disabled, // we need to increase retention beforehand, and test reducing it once database is dropped. ManagedBackupShortTermRetentionPolicy parameters0 = new ManagedBackupShortTermRetentionPolicy(retentionDays: startingRetention); sqlClient.ManagedBackupShortTermRetentionPolicies.CreateOrUpdateWithHttpMessagesAsync(resourceGroup.Name, managedInstance.Name, dbName, parameters0); Microsoft.Rest.ClientRuntime.Azure.TestFramework.TestUtilities.Wait(TimeSpan.FromSeconds(3)); ManagedBackupShortTermRetentionPolicy policy = sqlClient.ManagedBackupShortTermRetentionPolicies.Get(resourceGroup.Name, managedInstance.Name, dbName); Assert.Equal(startingRetention, policy.RetentionDays); // We need to wait for database to create its first backup. Currently if database drops too quickly it won't be restorable. // This will be changed in couple of weeks, howerver since building up Managed Instance takes over 60mins, this wait isn't not be a problem. // No need to sleep if we are playing back the recording. if (HttpMockServer.Mode == HttpRecorderMode.Record) { Thread.Sleep(TimeSpan.FromMinutes(10)); } // Delete the original database sqlClient.ManagedDatabases.Delete(resourceGroup.Name, managedInstance.Name, db1.Name); // Wait until the final backup is created and the restorable dropped database exists. // This could be up to 10 minutes after the database is deleted, and the database must already // have a backup (which was accomplished by the previous wait period). Let's wait up to 15 // just to give it a little more room. IEnumerable <RestorableDroppedManagedDatabase> droppedDatabases; DateTime startTime = DateTime.UtcNow; TimeSpan timeout = TimeSpan.FromMinutes(15); do { droppedDatabases = sqlClient.RestorableDroppedManagedDatabases.ListByInstance(resourceGroup.Name, managedInstance.Name); if (droppedDatabases.Any()) { // Dropped database now exists. Exit polling loop. break; } // Sleep if we are running live to avoid hammering the server. // No need to sleep if we are playing back the recording. if (HttpMockServer.Mode == HttpRecorderMode.Record) { Thread.Sleep(TimeSpan.FromSeconds(30)); } } while (DateTime.UtcNow < startTime + timeout); // Assert that we found a restorable db before timeout ended. Assert.True(droppedDatabases.Any(), "No dropped databases were found after waiting for " + timeout); var rdmd = droppedDatabases.Single(); // Attempt to increase retention period to 3 days and verfiy that the operation fails. ManagedBackupShortTermRetentionPolicy parameters1 = new ManagedBackupShortTermRetentionPolicy(retentionDays: invalidValue); sqlClient.ManagedRestorableDroppedDatabaseBackupShortTermRetentionPolicies.CreateOrUpdateWithHttpMessagesAsync(resourceGroup.Name, managedInstance.Name, rdmd.Name, parameters1); Microsoft.Rest.ClientRuntime.Azure.TestFramework.TestUtilities.Wait(TimeSpan.FromSeconds(3)); policy = sqlClient.ManagedRestorableDroppedDatabaseBackupShortTermRetentionPolicies.Get(resourceGroup.Name, managedInstance.Name, rdmd.Name); Assert.Equal(startingRetention, policy.RetentionDays); // Attempt to increase retention period to 20 days and verfiy that the operation succeeded . ManagedBackupShortTermRetentionPolicy parameters2 = new ManagedBackupShortTermRetentionPolicy(retentionDays: validValue); sqlClient.ManagedRestorableDroppedDatabaseBackupShortTermRetentionPolicies.CreateOrUpdateWithHttpMessagesAsync(resourceGroup.Name, managedInstance.Name, rdmd.Name, parameters2); Microsoft.Rest.ClientRuntime.Azure.TestFramework.TestUtilities.Wait(TimeSpan.FromSeconds(3)); policy = sqlClient.ManagedRestorableDroppedDatabaseBackupShortTermRetentionPolicies.Get(resourceGroup.Name, managedInstance.Name, rdmd.Name); Assert.Equal(validValue, policy.RetentionDays); } }
public void ShortTermRetentionOnLiveDatabase() { string testPrefix = "manageddatabaserestorescenariotest-"; using (SqlManagementTestContext Context = new SqlManagementTestContext(this)) { SqlManagementClient sqlClient = Context.GetClient <SqlManagementClient>(); ResourceGroup resourceGroup = Context.CreateResourceGroup(); // Create vnet and get the subnet id VirtualNetwork vnet = ManagedInstanceTestFixture.CreateVirtualNetwork(Context, resourceGroup, TestEnvironmentUtilities.DefaultLocationId); Sku sku = new Sku(); sku.Name = "MIGP8G4"; sku.Tier = "GeneralPurpose"; ManagedInstance managedInstance = sqlClient.ManagedInstances.CreateOrUpdate(resourceGroup.Name, testPrefix + SqlManagementTestUtilities.GenerateName(), new ManagedInstance() { AdministratorLogin = SqlManagementTestUtilities.DefaultLogin, AdministratorLoginPassword = SqlManagementTestUtilities.DefaultPassword, Sku = sku, SubnetId = vnet.Subnets[0].Id, Tags = new Dictionary <string, string>(), Location = TestEnvironmentUtilities.DefaultLocationId, }); // Create managed database // string dbName = SqlManagementTestUtilities.GenerateName(testPrefix); var db1 = sqlClient.ManagedDatabases.CreateOrUpdate(resourceGroup.Name, managedInstance.Name, dbName, new ManagedDatabase() { Location = managedInstance.Location, }); Assert.NotNull(db1); int basicRetention = 7; int invalidValue = 3; int validValue = 20; // Attempt to increase retention period to 7 days and verfiy that the operation succeeded. ManagedBackupShortTermRetentionPolicy parameters0 = new ManagedBackupShortTermRetentionPolicy(retentionDays: basicRetention); sqlClient.ManagedBackupShortTermRetentionPolicies.CreateOrUpdateWithHttpMessagesAsync(resourceGroup.Name, managedInstance.Name, dbName, parameters0); Microsoft.Rest.ClientRuntime.Azure.TestFramework.TestUtilities.Wait(TimeSpan.FromSeconds(3)); ManagedBackupShortTermRetentionPolicy policy = sqlClient.ManagedBackupShortTermRetentionPolicies.Get(resourceGroup.Name, managedInstance.Name, dbName); Assert.Equal(basicRetention, policy.RetentionDays); // Attempt to increase retention period to 3 days and verfiy that the operation fails. ManagedBackupShortTermRetentionPolicy parameters1 = new ManagedBackupShortTermRetentionPolicy(retentionDays: invalidValue); sqlClient.ManagedBackupShortTermRetentionPolicies.CreateOrUpdateWithHttpMessagesAsync(resourceGroup.Name, managedInstance.Name, dbName, parameters1); Microsoft.Rest.ClientRuntime.Azure.TestFramework.TestUtilities.Wait(TimeSpan.FromSeconds(3)); policy = sqlClient.ManagedBackupShortTermRetentionPolicies.Get(resourceGroup.Name, managedInstance.Name, dbName); Assert.Equal(basicRetention, policy.RetentionDays); // Attempt to increase retention period to 20 days and verfiy that the operation succeeded . ManagedBackupShortTermRetentionPolicy parameters2 = new ManagedBackupShortTermRetentionPolicy(retentionDays: validValue); sqlClient.ManagedBackupShortTermRetentionPolicies.CreateOrUpdateWithHttpMessagesAsync(resourceGroup.Name, managedInstance.Name, dbName, parameters2); Microsoft.Rest.ClientRuntime.Azure.TestFramework.TestUtilities.Wait(TimeSpan.FromSeconds(3)); policy = sqlClient.ManagedBackupShortTermRetentionPolicies.Get(resourceGroup.Name, managedInstance.Name, dbName); Assert.Equal(validValue, policy.RetentionDays); } }
public void RestorableDroppedManagedDatabasesTests() { string testPrefix = "manageddatabaserestorescenariotest-"; using (SqlManagementTestContext Context = new SqlManagementTestContext(this)) { SqlManagementClient sqlClient = Context.GetClient <SqlManagementClient>(); ResourceGroup resourceGroup = Context.CreateResourceGroup(); // Create vnet and get the subnet id VirtualNetwork vnet = ManagedInstanceTestFixture.CreateVirtualNetwork(Context, resourceGroup, TestEnvironmentUtilities.DefaultLocationId); Sku sku = new Sku(); sku.Name = "MIGP8G4"; sku.Tier = "GeneralPurpose"; ManagedInstance managedInstance = sqlClient.ManagedInstances.CreateOrUpdate(resourceGroup.Name, testPrefix + SqlManagementTestUtilities.GenerateName(), new ManagedInstance() { AdministratorLogin = SqlManagementTestUtilities.DefaultLogin, AdministratorLoginPassword = SqlManagementTestUtilities.DefaultPassword, Sku = sku, SubnetId = vnet.Subnets[0].Id, Tags = new Dictionary <string, string>(), Location = TestEnvironmentUtilities.DefaultLocationId, }); // Create managed database // string dbName = SqlManagementTestUtilities.GenerateName(testPrefix); var db1 = sqlClient.ManagedDatabases.CreateOrUpdate(resourceGroup.Name, managedInstance.Name, dbName, new ManagedDatabase() { Location = managedInstance.Location, }); Assert.NotNull(db1); // We need to wait for database to create its first backup. Currently if database drops too quickly it won't be restorable. // This will be changed in couple of weeks, howerver since building up Managed Instance takes over 60mins, this wait isn't not be a problem. // No need to sleep if we are playing back the recording. if (HttpMockServer.Mode == HttpRecorderMode.Record) { Thread.Sleep(TimeSpan.FromMinutes(10)); } // Delete the original database sqlClient.ManagedDatabases.Delete(resourceGroup.Name, managedInstance.Name, db1.Name); // Wait until the final backup is created and the restorable dropped database exists. // This could be up to 10 minutes after the database is deleted, and the database must already // have a backup (which was accomplished by the previous wait period). Let's wait up to 15 // just to give it a little more room. IEnumerable <RestorableDroppedManagedDatabase> droppedDatabases; DateTime startTime = DateTime.UtcNow; TimeSpan timeout = TimeSpan.FromMinutes(15); do { droppedDatabases = sqlClient.RestorableDroppedManagedDatabases.ListByInstance(resourceGroup.Name, managedInstance.Name); if (droppedDatabases.Any()) { // Dropped database now exists. Exit polling loop. break; } // Sleep if we are running live to avoid hammering the server. // No need to sleep if we are playing back the recording. if (HttpMockServer.Mode == HttpRecorderMode.Record) { Thread.Sleep(TimeSpan.FromSeconds(30)); } } while (DateTime.UtcNow < startTime + timeout); // Assert that we found a restorable db before timeout ended. Assert.True(droppedDatabases.Any(), "No dropped databases were found after waiting for " + timeout); // The original database should now exist as a restorable dropped database var droppedDatabase = droppedDatabases.Single(); Assert.StartsWith(db1.Name, droppedDatabase.Name); Assert.True(droppedDatabases.Count() == 1); // Test single get var getDroppedDatabase = sqlClient.RestorableDroppedManagedDatabases.Get(resourceGroup.Name, managedInstance.Name, droppedDatabase.Name); Assert.StartsWith(getDroppedDatabase.Name, droppedDatabase.Name); // Create another managed database // dbName = SqlManagementTestUtilities.GenerateName(testPrefix); var db2 = sqlClient.ManagedDatabases.CreateOrUpdate(resourceGroup.Name, managedInstance.Name, dbName, new ManagedDatabase() { Location = managedInstance.Location, }); Assert.NotNull(db2); // We need to wait for database to create its first backup. Currently if database drops too quickly it won't be restorable. // This will be changed in couple of weeks, howerver since building up Managed Instance takes over 60mins, this wait isn't not be a problem. // No need to sleep if we are playing back the recording. if (HttpMockServer.Mode == HttpRecorderMode.Record) { Thread.Sleep(TimeSpan.FromMinutes(10)); } // Delete the original database sqlClient.ManagedDatabases.Delete(resourceGroup.Name, managedInstance.Name, db2.Name); // Wait until the final backup is created and the restorable dropped database exists. // This could be up to 10 minutes after the database is deleted, and the database must already // have a backup (which was accomplished by the previous wait period). Let's wait up to 15 // just to give it a little more room. do { droppedDatabases = sqlClient.RestorableDroppedManagedDatabases.ListByInstance(resourceGroup.Name, managedInstance.Name); if (droppedDatabases.Any()) { // Dropped database now exists. Exit polling loop. break; } // Sleep if we are running live to avoid hammering the server. // No need to sleep if we are playing back the recording. if (HttpMockServer.Mode == HttpRecorderMode.Record) { Thread.Sleep(TimeSpan.FromSeconds(30)); } } while (DateTime.UtcNow < startTime + timeout); // There should be 2 dropped databases now Assert.True(droppedDatabases.Count() == 2); } }