Skip to content

Commit b4b507d

Browse files
authored
CosmosDB - New Restore Parameter (#22585)
* restore new param public network access * minor fixes * test change * stable changes 1 * md param def changed * reverting test changes for build * restore ts * test and test recording
1 parent b595765 commit b4b507d

File tree

6 files changed

+3524
-2
lines changed

6 files changed

+3524
-2
lines changed

src/CosmosDB/CosmosDB.Test/ScenarioTests/RestoreTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ public void TestSqlRestoreAccountCmdlets()
3030
TestRunner.RunTestScript("Test-SqlRestoreAccountCmdlets");
3131
}
3232

33+
[Fact]
34+
[Trait(Category.AcceptanceType, Category.CheckIn)]
35+
public void TestSqlRestoreAccountPublicNetworkAccessCmdlets()
36+
{
37+
TestRunner.RunTestScript("Test-SqlRestoreAccountPublicNetworkAccessCmdlets");
38+
}
39+
3340
[Fact]
3441
[Trait(Category.AcceptanceType, Category.CheckIn)]
3542
public void TestSqlRestoreFromNewAccountCmdlets()

src/CosmosDB/CosmosDB.Test/ScenarioTests/RestoreTests.ps1

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,4 +746,48 @@ function Test-ProvisionCosmosDBAccountBackupPolicyWithContinuous7DaysCmdLets {
746746
Assert-NotNull $sourceRestorableAccount.DatabaseAccountName
747747
Assert-NotNull $sourceRestorableAccount.CreationTime
748748
Assert-NotNull $sourceRestorableAccount.OldestRestorableTime
749+
}
750+
751+
function Test-SqlRestoreAccountPublicNetworkAccessCmdlets {
752+
#use an existing account with the following information
753+
$rgName = "CosmosDBResourceGroup64"
754+
$cosmosDBAccountName = "restored2-cosmosdb-12103-3"
755+
$sourceCosmosDBAccountName = "cosmosdb-12103"
756+
$databaseName = "TestDB1";
757+
$collectionName1 = "TestCollectionInDB1";
758+
$collectionName2 = "TestCollectionInDB2";
759+
$location = "West US"
760+
$apiKind = "Sql"
761+
$consistencyLevel = "Session"
762+
$PartitionKeyPathValue = "/foo/bar"
763+
$PartitionKeyKindValue = "Hash"
764+
$locations = @()
765+
$locations += New-AzCosmosDBLocationObject -Location "West Us" -FailoverPriority 0 -IsZoneRedundant 0
766+
$publicNetworkAccess = "Disabled"
767+
768+
$resourceGroup = New-AzResourceGroup -ResourceGroupName $rgName -Location $location
769+
New-AzCosmosDBAccount -ResourceGroupName $rgName -LocationObject $locations -Name $sourceCosmosDBAccountName -ApiKind $apiKind -DefaultConsistencyLevel $consistencyLevel -BackupPolicyType Continuous
770+
$NewDatabase = New-AzCosmosDBSqlDatabase -AccountName $sourceCosmosDBAccountName -ResourceGroupName $rgName -Name $databaseName
771+
$NewContainer = New-AzCosmosDBSqlContainer -AccountName $sourceCosmosDBAccountName -ResourceGroupName $rgName -DatabaseName $databaseName -Name $collectionName1 -PartitionKeyPath $PartitionKeyPathValue -PartitionKeyKind $PartitionKeyKindValue -Throughput 600
772+
$NewContainer = New-AzCosmosDBSqlContainer -AccountName $sourceCosmosDBAccountName -ResourceGroupName $rgName -DatabaseName $databaseName -Name $collectionName2 -PartitionKeyPath $PartitionKeyPathValue -PartitionKeyKind $PartitionKeyKindValue -Throughput 600
773+
Start-TestSleep -Seconds 100
774+
775+
$datatabaseToRestore = New-AzCosmosDBDatabaseToRestore -DatabaseName $databaseName -CollectionName $collectionName1, $collectionName2
776+
$sourceCosmosDBAccount = Get-AzCosmosDBAccount -Name $sourceCosmosDBAccountName -ResourceGroupName $rgName
777+
$sourceRestorableAccount = Get-AzCosmosDBRestorableDatabaseAccount -Location $sourceCosmosDBAccount.Location -DatabaseAccountInstanceId $sourceCosmosDBAccount.InstanceId
778+
$restoreTimestampInUtc = $sourceRestorableAccount.CreationTime.AddSeconds(200)
779+
$restoredCosmosDBAccount = Restore-AzCosmosDBAccount -RestoreTimestampInUtc $restoreTimestampInUtc -SourceDatabaseAccountName $sourceCosmosDBAccountName -Location $sourceCosmosDBAccount.Location -TargetResourceGroupName $rgName -TargetDatabaseAccountName $cosmosDBAccountName -DatabasesToRestore $datatabaseToRestore -PublicNetworkAccess $publicNetworkAccess
780+
781+
Assert-NotNull $sourceRestorableAccount
782+
Assert-AreEqual $restoredCosmosDBAccount.Name $cosmosDBAccountName
783+
Assert-AreEqual $restoredCosmosDBAccount.CreateMode "Restore"
784+
Assert-NotNull $restoredCosmosDBAccount.RestoreParameters
785+
Assert-AreEqual $restoredCosmosDBAccount.RestoreParameters.RestoreSource $sourceRestorableAccount.Id
786+
787+
Assert-NotNull $restoredCosmosDBAccount.RestoreParameters.DatabasesToRestore
788+
Assert-AreEqual $restoredCosmosDBAccount.RestoreParameters.DatabasesToRestore[0].DatabaseName $databaseName
789+
Assert-AreEqual $restoredCosmosDBAccount.RestoreParameters.DatabasesToRestore[0].CollectionNames[0] $collectionName1
790+
791+
# Assert public network acccess is disabled
792+
Assert-AreEqual $restoredCosmosDBAccount.PublicNetworkAccess $publicNetworkAccess
749793
}

0 commit comments

Comments
 (0)