|
| 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 Get,Enable or Disable Azure Monitor in Azure HDInsight Cluster |
| 18 | +#> |
| 19 | +function Test-AzureMonitorRelatedCommands{ |
| 20 | + |
| 21 | + # Create some resources that will be used throughout test |
| 22 | + try |
| 23 | + { |
| 24 | + $location = "East US" |
| 25 | + |
| 26 | + # prepare parameter for creating parameter |
| 27 | + $params= Prepare-ClusterCreateParameter -location $location |
| 28 | + |
| 29 | + # create cluster that will be used throughout test |
| 30 | + $cluster = New-AzHDInsightCluster -Location $params.location -ResourceGroupName $params.resourceGroupName ` |
| 31 | + -ClusterName $params.clusterName -ClusterSizeInNodes $params.clusterSizeInNodes -ClusterType $params.clusterType ` |
| 32 | + -StorageAccountResourceId $params.storageAccountResourceId -StorageAccountKey $params.storageAccountKey ` |
| 33 | + -HttpCredential $params.httpCredential -SshCredential $params.sshCredential ` |
| 34 | + -MinSupportedTlsVersion $params.minSupportedTlsVersion |
| 35 | + Assert-NotNull $cluster |
| 36 | + |
| 37 | + $workspaceName = Generate-Name("workspace-ps-test") |
| 38 | + $resourceGroupName = $cluster.ResourceGroup |
| 39 | + |
| 40 | + #create a new Log Analytics Workspace |
| 41 | + $sku = "pernode" |
| 42 | + $workspace = New-AzOperationalInsightsWorkspace -Location $location -Name $workspaceName -ResourceGroupName $resourceGroupName -Sku $sku |
| 43 | + |
| 44 | + #get workspace's primaryKey |
| 45 | + $keys = Get-AzOperationalInsightsWorkspaceSharedKey -ResourceGroupName $resourceGroupName -Name $workspace.Name |
| 46 | + Assert-NotNull $keys |
| 47 | + #test Get-AzHDInsightAzureMonitor |
| 48 | + $result = Get-AzHDInsightAzureMonitor -ClusterName $cluster.Name -ResourceGroupName $cluster.ResourceGroup |
| 49 | + Assert-Null $result.WorkspaceId |
| 50 | + |
| 51 | + #test Enable-AzHDInsightAzureMonitor |
| 52 | + $workspaceId = $workspace.CustomerId |
| 53 | + $primaryKey = $keys.PrimarySharedKey |
| 54 | + |
| 55 | + Assert-NotNull $workspaceId |
| 56 | + Assert-NotNull $primaryKey |
| 57 | + Enable-AzHDInsightAzureMonitor -ClusterName $cluster.Name -ResourceGroup $cluster.ResourceGroup -WorkspaceId $workspaceId -Primary $primaryKey |
| 58 | + |
| 59 | + $result = Get-AzHDInsightAzureMonitor -ClusterName $cluster.Name -ResourceGroupName $cluster.ResourceGroup |
| 60 | + Assert-True {$result.ClusterMonitoringEnabled} |
| 61 | + Assert-AreEqual $result.WorkspaceId $workspaceId |
| 62 | + |
| 63 | + #test Disable-AzHDInsightAzureMonitor |
| 64 | + Disable-AzHDInsightAzureMonitor -ClusterName $cluster.Name -ResourceGroupName $cluster.ResourceGroup |
| 65 | + $result = Get-AzHDInsightAzureMonitor -ClusterName $cluster.Name -ResourceGroupName $cluster.ResourceGroup |
| 66 | + Assert-False {$result.ClusterMonitoringEnabled} |
| 67 | + Assert-Null $result.WorkspaceId |
| 68 | + } |
| 69 | + finally |
| 70 | + { |
| 71 | + # Delete cluster and resource group |
| 72 | + Remove-AzHDInsightCluster -ClusterName $cluster.Name |
| 73 | + Remove-AzResourceGroup -ResourceGroupName $cluster.ResourceGroup |
| 74 | + } |
| 75 | +} |
0 commit comments