|
| 1 | +# ---------------------------------------------------------------------------------- |
| 2 | +# |
| 3 | +# Copyright Microsoft Corporation |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# Unless required by applicable law or agreed to in writing, software |
| 9 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | +# See the License for the specific language governing permissions and |
| 12 | +# limitations under the License. |
| 13 | +# ---------------------------------------------------------------------------------- |
| 14 | + |
| 15 | +<# |
| 16 | +.SYNOPSIS |
| 17 | +Test Cassandra Cluster CRUD cmdlets using Name paramter set |
| 18 | +#> |
| 19 | +function Test-ManagedCassandraCreateUpdateGetCmdlets |
| 20 | +{ |
| 21 | + $RgName = "nova-powershell-tests-rg" |
| 22 | + $ClusterName = "cluster8ea4cb76-7009-4b56-b09c-13dad8371a42" |
| 23 | + $DCName = "dc1" |
| 24 | + $Location = "central us" |
| 25 | + $VnetName = "cassandra-mi-vnet" |
| 26 | + |
| 27 | + Try { |
| 28 | + # Because New-AzRoleAssignmentWithId in tools\ScenarioTest.ResourceManager\AzureRM.Resources.ps1 |
| 29 | + # is broken, we can't assign the Network Contributor role to virtual networks in the test. Therefore you |
| 30 | + # must set up a resource group with the following PowerShell script: |
| 31 | + # |
| 32 | + # $RgName = "nova-powershell-tests-rg" |
| 33 | + # $Location = "central us" |
| 34 | + # $resourceGroup = New-AzResourceGroup -ResourceGroupName $RgName -Location $Location |
| 35 | + # $vnetProperties = @{ |
| 36 | + # Name = 'cassandra-mi-vnet' |
| 37 | + # ResourceGroupName = $RgName |
| 38 | + # Location = $Location |
| 39 | + # AddressPrefix = '10.0.0.0/16' |
| 40 | + # } |
| 41 | + # $vnet = New-AzVirtualNetwork @vnetProperties |
| 42 | + # $subnetProperties = @{ |
| 43 | + # Name = 'default' |
| 44 | + # VirtualNetwork = $vnet |
| 45 | + # AddressPrefix = '10.0.0.0/24' |
| 46 | + # } |
| 47 | + # $subnet = Add-AzVirtualNetworkSubnetConfig @subnetProperties |
| 48 | + # $vnet = $vnet | Set-AzVirtualNetwork |
| 49 | + # New-AzRoleAssignment -ObjectId "e5007d2c-4b13-4a74-9b6a-605d99f03501" -RoleDefinitionName 'Network Contributor' -Scope $SubnetId |
| 50 | + # $SubnetId = $vnet.Subnets[0].Id |
| 51 | + # |
| 52 | + # then set this variable to the $SubnetId value produced by the script. |
| 53 | + $SubnetId = "/subscriptions/dd31ecae-4522-468e-8b27-5befd051dd53/resourceGroups/nova-powershell-tests-rg/providers/Microsoft.Network/virtualNetworks/cassandra-mi-vnet/subnets/default" |
| 54 | + |
| 55 | + $initialClusterCount = (Get-AzManagedCassandraCluster -ResourceGroupName $RgName).Count |
| 56 | + |
| 57 | + $response = New-AzManagedCassandraCluster ` |
| 58 | + -ResourceGroupName $RgName ` |
| 59 | + -ClusterName $ClusterName ` |
| 60 | + -Location $Location ` |
| 61 | + -InitialCassandraAdminPassword "password" ` |
| 62 | + -DelegatedManagementSubnetId $SubnetId |
| 63 | + Assert-AreEqual "Succeeded" $response.Properties.ProvisioningState |
| 64 | + Assert-AreEqual $ClusterName $response.Name |
| 65 | + Assert-AreEqual 0 $response.Properties.ExternalSeedNodes.Count |
| 66 | + |
| 67 | + $clusterId = $response.Id |
| 68 | + |
| 69 | + $cluster = Get-AzManagedCassandraCluster -ResourceGroupName $RgName -ClusterName $ClusterName |
| 70 | + Assert-AreEqual "Succeeded" $cluster.Properties.ProvisioningState |
| 71 | + Assert-AreEqual $SubnetId $cluster.Properties.DelegatedManagementSubnetId |
| 72 | + Assert-AreEqual $true $cluster.Properties.RepairEnabled |
| 73 | + |
| 74 | + $cluster2 = Get-AzManagedCassandraCluster -ResourceId $clusterId |
| 75 | + Assert-AreEqual $cluster.Id $cluster2.Id |
| 76 | + Assert-AreEqual $cluster.Location $cluster2.Location |
| 77 | + Assert-AreEqual $cluster.Properties.HoursBetweenBackups $cluster2.Properties.HoursBetweenBackups |
| 78 | + Assert-AreEqual $cluster.Properties.CassandraVersion $cluster2.Properties.CassandraVersion |
| 79 | + |
| 80 | + Update-AzManagedCassandraCluster -ResourceId $clusterId ` |
| 81 | + -ExternalSeedNode "127.0.0.1", "127.0.0.2", "127.0.0.3" |
| 82 | + while ($true) { |
| 83 | + $response = Get-AzManagedCassandraCluster -ResourceId $clusterId |
| 84 | + if ($response.Properties.ExternalSeedNodes.Count -eq 3) |
| 85 | + { |
| 86 | + break |
| 87 | + } |
| 88 | + Start-Sleep -s 1 |
| 89 | + } |
| 90 | + $response = Get-AzManagedCassandraCluster -ResourceId $clusterId |
| 91 | + Assert-AreEqual 3 $response.Properties.ExternalSeedNodes.Count |
| 92 | + |
| 93 | + $dcResponse = New-AzManagedCassandraDatacenter ` |
| 94 | + -ResourceGroupName $RgName ` |
| 95 | + -ClusterName $ClusterName ` |
| 96 | + -DatacenterName $DCName ` |
| 97 | + -Location $Location ` |
| 98 | + -NodeCount 3 ` |
| 99 | + -DelegatedSubnetId $SubnetId |
| 100 | + Assert-AreEqual "Succeeded" $dcResponse.Properties.ProvisioningState |
| 101 | + Assert-AreEqual 3 $dcResponse.Properties.NodeCount |
| 102 | + |
| 103 | + $dcId = $dcResponse.Id |
| 104 | + |
| 105 | + $dc = Get-AzManagedCassandraDatacenter -ResourceGroupName $RgName -ClusterName $ClusterName -DatacenterName $DCName |
| 106 | + Assert-AreEqual "Succeeded" $dc.Properties.ProvisioningState |
| 107 | + Assert-AreEqual 3 $dc.Properties.NodeCount |
| 108 | + |
| 109 | + $dc2 = Get-AzManagedCassandraDatacenter -ResourceId $dcId |
| 110 | + Assert-AreEqual $dc.Id $dc2.Id |
| 111 | + Assert-AreEqual $dc.Name $dc2.Name |
| 112 | + Assert-AreEqual $dc.Properties.NodeCount $dc2.Properties.NodeCount |
| 113 | + |
| 114 | + Remove-AzManagedCassandraDatacenter -ResourceId $dcId |
| 115 | + |
| 116 | + Remove-AzManagedCassandraCluster -ResourceId $clusterId |
| 117 | + } |
| 118 | + Finally { |
| 119 | + } |
| 120 | +} |
| 121 | + |
0 commit comments