|
| 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 | +using System.Collections.Generic; |
| 16 | +using System.Management.Automation; |
| 17 | +using Microsoft.Azure.Commands.HDInsight.Models; |
| 18 | +using Microsoft.Azure.Management.HDInsight.Models; |
| 19 | +using Microsoft.WindowsAzure.Commands.Common; |
| 20 | +using Microsoft.WindowsAzure.Commands.ScenarioTest; |
| 21 | +using Moq; |
| 22 | +using Newtonsoft.Json; |
| 23 | +using Xunit; |
| 24 | + |
| 25 | +namespace Microsoft.Azure.Commands.HDInsight.Test |
| 26 | +{ |
| 27 | + public class PremiumClusterTests : HDInsightTestBase |
| 28 | + { |
| 29 | + private NewAzureHDInsightClusterCommand cmdlet; |
| 30 | + private const string StorageName = "PlaceStorageName"; |
| 31 | + private const string StorageKey = "PlaceStorageKey"; |
| 32 | + private const int ClusterSize = 4; |
| 33 | + |
| 34 | + private readonly PSCredential _httpCred; |
| 35 | + |
| 36 | + public PremiumClusterTests() |
| 37 | + { |
| 38 | + base.SetupTestsForManagement(); |
| 39 | + _httpCred = new PSCredential("hadoopuser", string.Format("Password1!").ConvertToSecureString()); |
| 40 | + cmdlet = new NewAzureHDInsightClusterCommand |
| 41 | + { |
| 42 | + CommandRuntime = commandRuntimeMock.Object, |
| 43 | + HDInsightManagementClient = hdinsightManagementMock.Object |
| 44 | + }; |
| 45 | + } |
| 46 | + |
| 47 | + [Fact] |
| 48 | + [Trait(Category.AcceptanceType, Category.CheckIn)] |
| 49 | + public void CanCreateNewPremiumHDInsightCluster() |
| 50 | + { |
| 51 | + cmdlet.ClusterName = ClusterName; |
| 52 | + cmdlet.ResourceGroupName = ResourceGroupName; |
| 53 | + cmdlet.ClusterSizeInNodes = ClusterSize; |
| 54 | + cmdlet.Location = Location; |
| 55 | + cmdlet.HttpCredential = _httpCred; |
| 56 | + cmdlet.DefaultStorageAccountName = StorageName; |
| 57 | + cmdlet.DefaultStorageAccountKey = StorageKey; |
| 58 | + cmdlet.ClusterType = ClusterType; |
| 59 | + cmdlet.OSType = OSType.Linux; |
| 60 | + cmdlet.ClusterTier = Tier.Premium; |
| 61 | + cmdlet.SshCredential = _httpCred; |
| 62 | + var cluster = new Cluster |
| 63 | + { |
| 64 | + Id = "id", |
| 65 | + Name = ClusterName, |
| 66 | + Location = Location, |
| 67 | + Properties = new ClusterGetProperties |
| 68 | + { |
| 69 | + ClusterVersion = "3.2", |
| 70 | + ClusterState = "Running", |
| 71 | + ClusterDefinition = new ClusterDefinition |
| 72 | + { |
| 73 | + ClusterType = ClusterType |
| 74 | + }, |
| 75 | + QuotaInfo = new QuotaInfo |
| 76 | + { |
| 77 | + CoresUsed = 24 |
| 78 | + }, |
| 79 | + OperatingSystemType = OSType.Linux, |
| 80 | + ClusterTier = Tier.Premium |
| 81 | + } |
| 82 | + }; |
| 83 | + var coreConfigs = new Dictionary<string, string> |
| 84 | + { |
| 85 | + {"fs.defaultFS", "wasb://giyertestcsmv2@" + StorageName}, |
| 86 | + { |
| 87 | + "fs.azure.account.key." + StorageName, |
| 88 | + StorageKey |
| 89 | + } |
| 90 | + }; |
| 91 | + var gatewayConfigs = new Dictionary<string, string> |
| 92 | + { |
| 93 | + {"restAuthCredential.isEnabled", "true"}, |
| 94 | + {"restAuthCredential.username", _httpCred.UserName}, |
| 95 | + {"restAuthCredential.password", _httpCred.Password.ConvertToString()} |
| 96 | + }; |
| 97 | + |
| 98 | + var configurations = new Dictionary<string, Dictionary<string, string>> |
| 99 | + { |
| 100 | + {"core-site", coreConfigs}, |
| 101 | + {"gateway", gatewayConfigs} |
| 102 | + }; |
| 103 | + var serializedConfig = JsonConvert.SerializeObject(configurations); |
| 104 | + cluster.Properties.ClusterDefinition.Configurations = serializedConfig; |
| 105 | + |
| 106 | + var getresponse = new ClusterGetResponse {Cluster = cluster}; |
| 107 | + |
| 108 | + hdinsightManagementMock.Setup(c => c.CreateNewCluster(ResourceGroupName, ClusterName, It.Is<ClusterCreateParameters>( |
| 109 | + parameters => |
| 110 | + parameters.ClusterSizeInNodes == ClusterSize && |
| 111 | + parameters.DefaultStorageAccountName == StorageName && |
| 112 | + parameters.DefaultStorageAccountKey == StorageKey && |
| 113 | + parameters.Location == Location && |
| 114 | + parameters.UserName == _httpCred.UserName && |
| 115 | + parameters.Password == _httpCred.Password.ConvertToString() && |
| 116 | + parameters.SshUserName == _httpCred.UserName && |
| 117 | + parameters.SshPassword == _httpCred.Password.ConvertToString() && |
| 118 | + parameters.ClusterType == ClusterType && |
| 119 | + parameters.OSType == OSType.Linux && |
| 120 | + parameters.ClusterTier == Tier.Premium))) |
| 121 | + .Returns(getresponse) |
| 122 | + .Verifiable(); |
| 123 | + |
| 124 | + cmdlet.ExecuteCmdlet(); |
| 125 | + |
| 126 | + commandRuntimeMock.VerifyAll(); |
| 127 | + commandRuntimeMock.Verify(f => f.WriteObject(It.Is<AzureHDInsightCluster>( |
| 128 | + clusterout => |
| 129 | + clusterout.ClusterState == "Running" && |
| 130 | + clusterout.ClusterType == ClusterType && |
| 131 | + clusterout.ClusterVersion == "3.2" && |
| 132 | + clusterout.CoresUsed == 24 && |
| 133 | + clusterout.Location == Location && |
| 134 | + clusterout.Name == ClusterName && |
| 135 | + clusterout.OperatingSystemType == OSType.Linux && |
| 136 | + clusterout.ClusterTier == Tier.Premium)), |
| 137 | + Times.Once); |
| 138 | + } |
| 139 | + } |
| 140 | +} |
0 commit comments