Skip to content

Commit 8dd308b

Browse files
authored
Merge pull request #2744 from nemanja88/dev
[HDINSIGHT] NullRef SShCreds bug
2 parents 63896f1 + 4c26007 commit 8dd308b

File tree

2 files changed

+93
-2
lines changed

2 files changed

+93
-2
lines changed

src/ResourceManager/HDInsight/Commands.HDInsight.Test/UnitTests/NewClusterTests.cs

Lines changed: 92 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,14 @@ public class NewClusterTests : HDInsightTestBase
3131
private const string StorageKey = "O9EQvp3A3AjXq/W27rst1GQfLllhp01qlJMJfSU1hVW2K42gUeiUUn2D8zX2lU3taiXSSfqkZlcPv+nQcYUxYw==";
3232
private const int ClusterSize = 4;
3333

34-
private readonly PSCredential _httpCred;
34+
private readonly PSCredential _httpCred, _sshCred;
3535

3636
public NewClusterTests(Xunit.Abstractions.ITestOutputHelper output)
3737
{
3838
ServiceManagemenet.Common.Models.XunitTracingInterceptor.AddToContext(new ServiceManagemenet.Common.Models.XunitTracingInterceptor(output));
3939
base.SetupTestsForManagement();
4040
_httpCred = new PSCredential("hadoopuser", string.Format("Password1!").ConvertToSecureString());
41+
_sshCred = new PSCredential("sshuser", string.Format("Password1!").ConvertToSecureString());
4142
cmdlet = new NewAzureHDInsightClusterCommand
4243
{
4344
CommandRuntime = commandRuntimeMock.Object,
@@ -130,5 +131,95 @@ public void CanCreateNewHDInsightCluster()
130131
clusterout.OperatingSystemType == OSType.Windows)),
131132
Times.Once);
132133
}
134+
135+
[Fact]
136+
[Trait(Category.AcceptanceType, Category.CheckIn)]
137+
public void CanCreateNewHDInsightCluster_Linux()
138+
{
139+
cmdlet.ClusterName = ClusterName;
140+
cmdlet.ResourceGroupName = ResourceGroupName;
141+
cmdlet.ClusterSizeInNodes = ClusterSize;
142+
cmdlet.Location = Location;
143+
cmdlet.HttpCredential = _httpCred;
144+
cmdlet.DefaultStorageAccountName = StorageName;
145+
cmdlet.DefaultStorageAccountKey = StorageKey;
146+
cmdlet.ClusterType = ClusterType;
147+
cmdlet.SshCredential = _sshCred;
148+
cmdlet.OSType = OSType.Linux;
149+
150+
var cluster = new Cluster
151+
{
152+
Id = "id",
153+
Name = ClusterName,
154+
Location = Location,
155+
Properties = new ClusterGetProperties
156+
{
157+
ClusterVersion = "3.1",
158+
ClusterState = "Running",
159+
ClusterDefinition = new ClusterDefinition
160+
{
161+
ClusterType = ClusterType
162+
},
163+
QuotaInfo = new QuotaInfo
164+
{
165+
CoresUsed = 24
166+
},
167+
OperatingSystemType = OSType.Linux
168+
}
169+
};
170+
var coreConfigs = new Dictionary<string, string>
171+
{
172+
{"fs.defaultFS", "wasb://giyertestcsmv2@" + StorageName},
173+
{
174+
"fs.azure.account.key." + StorageName,
175+
StorageKey
176+
}
177+
};
178+
var gatewayConfigs = new Dictionary<string, string>
179+
{
180+
{"restAuthCredential.isEnabled", "true"},
181+
{"restAuthCredential.username", _httpCred.UserName},
182+
{"restAuthCredential.password", _httpCred.Password.ConvertToString()}
183+
};
184+
185+
var configurations = new Dictionary<string, Dictionary<string, string>>
186+
{
187+
{"core-site", coreConfigs},
188+
{"gateway", gatewayConfigs}
189+
};
190+
var serializedConfig = JsonConvert.SerializeObject(configurations);
191+
cluster.Properties.ClusterDefinition.Configurations = serializedConfig;
192+
193+
var getresponse = new ClusterGetResponse { Cluster = cluster };
194+
195+
hdinsightManagementMock.Setup(c => c.CreateNewCluster(ResourceGroupName, ClusterName, It.Is<ClusterCreateParameters>(
196+
parameters =>
197+
parameters.ClusterSizeInNodes == ClusterSize &&
198+
parameters.DefaultStorageAccountName == StorageName &&
199+
parameters.DefaultStorageAccountKey == StorageKey &&
200+
parameters.Location == Location &&
201+
parameters.UserName == _httpCred.UserName &&
202+
parameters.Password == _httpCred.Password.ConvertToString() &&
203+
parameters.ClusterType == ClusterType &&
204+
parameters.OSType == OSType.Linux &&
205+
parameters.SshUserName == _sshCred.UserName &&
206+
parameters.SshPassword == _sshCred.Password.ConvertToString())))
207+
.Returns(getresponse)
208+
.Verifiable();
209+
210+
cmdlet.ExecuteCmdlet();
211+
212+
commandRuntimeMock.VerifyAll();
213+
commandRuntimeMock.Verify(f => f.WriteObject(It.Is<AzureHDInsightCluster>(
214+
clusterout =>
215+
clusterout.ClusterState == "Running" &&
216+
clusterout.ClusterType == ClusterType &&
217+
clusterout.ClusterVersion == "3.1" &&
218+
clusterout.CoresUsed == 24 &&
219+
clusterout.Location == Location &&
220+
clusterout.Name == ClusterName &&
221+
clusterout.OperatingSystemType == OSType.Linux)),
222+
Times.Once);
223+
}
133224
}
134225
}

src/ResourceManager/HDInsight/Commands.HDInsight/ManagementCommands/NewAzureHDInsightClusterCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ public override void ExecuteCmdlet()
323323
parameters.RdpPassword = RdpCredential.Password.ConvertToString();
324324
}
325325

326-
if (OSType == OSType.Linux)
326+
if (OSType == OSType.Linux && SshCredential != null)
327327
{
328328
parameters.SshUserName = SshCredential.UserName;
329329
if (!string.IsNullOrEmpty(SshCredential.Password.ConvertToString()))

0 commit comments

Comments
 (0)