Skip to content

Commit b321db7

Browse files
authored
Merge pull request Azure#3144 from mumou/dev
Add HDInsight secure hadoop cluster creation support in powershell
2 parents a6847dc + f36ce35 commit b321db7

13 files changed

+9002
-8289
lines changed

src/ResourceManager/HDInsight/Commands.HDInsight.Test/Commands.HDInsight.Test.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@
165165
<Compile Include="HDInsightTestBase.cs" />
166166
<Compile Include="UnitTests\PremiumClusterTests.cs" />
167167
<Compile Include="UnitTests\ScriptActionTests.cs" />
168+
<Compile Include="UnitTests\SecurityProfileTests.cs" />
168169
<None Include="ScenarioTests\HDInsightConfigurationTests.ps1">
169170
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
170171
</None>
@@ -224,4 +225,4 @@
224225
<Folder Include="SessionRecords\" />
225226
</ItemGroup>
226227
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
227-
</Project>
228+
</Project>

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

Lines changed: 111 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,64 @@ public void CanCreateNewHDInsightCluster()
135135
[Fact]
136136
[Trait(Category.AcceptanceType, Category.CheckIn)]
137137
public void CanCreateNewHDInsightCluster_Linux()
138+
{
139+
CreateNewHDInsightCluster();
140+
141+
commandRuntimeMock.Verify(f => f.WriteObject(It.Is<AzureHDInsightCluster>(
142+
clusterout =>
143+
clusterout.ClusterState == "Running" &&
144+
clusterout.ClusterType == ClusterType &&
145+
clusterout.ClusterVersion == "3.1" &&
146+
clusterout.CoresUsed == 24 &&
147+
clusterout.Location == Location &&
148+
clusterout.Name == ClusterName &&
149+
clusterout.OperatingSystemType == OSType.Linux)),
150+
Times.Once);
151+
152+
}
153+
154+
[Fact]
155+
[Trait(Category.AcceptanceType, Category.CheckIn)]
156+
public void CanCreateNewHDInsightCluster_Secure_Linux()
157+
{
158+
cmdlet.SecurityProfile = new AzureHDInsightSecurityProfile()
159+
{
160+
Domain = "domain.com",
161+
DomainUserCredential = new PSCredential("username", "pass".ConvertToSecureString()),
162+
OrganizationalUnitDN = "OUDN",
163+
LdapsUrls = new[]
164+
{
165+
"ldapsurl"
166+
},
167+
ClusterUsersGroupDNs = new[]
168+
{
169+
"userGroupDn"
170+
}
171+
};
172+
173+
CreateNewHDInsightCluster(addSecurityProfileInresponse:true);
174+
175+
commandRuntimeMock.Verify(f => f.WriteObject(It.Is<AzureHDInsightCluster>(
176+
clusterout =>
177+
clusterout.ClusterState == "Running" &&
178+
clusterout.ClusterType == ClusterType &&
179+
clusterout.ClusterVersion == "3.1" &&
180+
clusterout.CoresUsed == 24 &&
181+
clusterout.Location == Location &&
182+
clusterout.Name == ClusterName &&
183+
clusterout.OperatingSystemType == OSType.Linux &&
184+
clusterout.SecurityProfile.Domain.Equals(cmdlet.SecurityProfile.Domain) &&
185+
clusterout.SecurityProfile.DomainUserCredential.UserName.Equals(
186+
cmdlet.SecurityProfile.DomainUserCredential.UserName) &&
187+
clusterout.SecurityProfile.OrganizationalUnitDN.Equals(cmdlet.SecurityProfile.OrganizationalUnitDN) &&
188+
clusterout.SecurityProfile.LdapsUrls.ArrayToString("")
189+
.Equals(cmdlet.SecurityProfile.LdapsUrls.ArrayToString("")) &&
190+
clusterout.SecurityProfile.ClusterUsersGroupDNs.ArrayToString("")
191+
.Equals(cmdlet.SecurityProfile.ClusterUsersGroupDNs.ArrayToString("")))),
192+
Times.Once);
193+
}
194+
195+
private void CreateNewHDInsightCluster(bool addSecurityProfileInresponse = false)
138196
{
139197
cmdlet.ClusterName = ClusterName;
140198
cmdlet.ResourceGroupName = ResourceGroupName;
@@ -146,7 +204,7 @@ public void CanCreateNewHDInsightCluster_Linux()
146204
cmdlet.ClusterType = ClusterType;
147205
cmdlet.SshCredential = _sshCred;
148206
cmdlet.OSType = OSType.Linux;
149-
207+
150208
var cluster = new Cluster
151209
{
152210
Id = "id",
@@ -167,6 +225,26 @@ public void CanCreateNewHDInsightCluster_Linux()
167225
OperatingSystemType = OSType.Linux
168226
}
169227
};
228+
229+
if (addSecurityProfileInresponse)
230+
{
231+
cluster.Properties.SecurityProfile = new SecurityProfile()
232+
{
233+
Domain = "domain.com",
234+
DomainUsername = "username",
235+
DomainUserPassword = "pass",
236+
OrganizationalUnitDN = "OUDN",
237+
LdapsUrls = new[]
238+
{
239+
"ldapsurl"
240+
},
241+
ClusterUsersGroupDNs = new[]
242+
{
243+
"userGroupDn"
244+
}
245+
};
246+
}
247+
170248
var coreConfigs = new Dictionary<string, string>
171249
{
172250
{"fs.defaultFS", "wasb://giyertestcsmv2@" + StorageName},
@@ -190,22 +268,23 @@ public void CanCreateNewHDInsightCluster_Linux()
190268
var serializedConfig = JsonConvert.SerializeObject(configurations);
191269
cluster.Properties.ClusterDefinition.Configurations = serializedConfig;
192270

193-
var getresponse = new ClusterGetResponse { Cluster = cluster };
271+
var getresponse = new ClusterGetResponse {Cluster = cluster};
194272

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();
273+
hdinsightManagementMock.Setup(
274+
c => c.CreateNewCluster(ResourceGroupName, ClusterName, It.Is<ClusterCreateParameters>(
275+
parameters =>
276+
parameters.ClusterSizeInNodes == ClusterSize &&
277+
parameters.DefaultStorageAccountName == StorageName &&
278+
parameters.DefaultStorageAccountKey == StorageKey &&
279+
parameters.Location == Location &&
280+
parameters.UserName == _httpCred.UserName &&
281+
parameters.Password == _httpCred.Password.ConvertToString() &&
282+
parameters.ClusterType == ClusterType &&
283+
parameters.OSType == OSType.Linux &&
284+
parameters.SshUserName == _sshCred.UserName &&
285+
parameters.SshPassword == _sshCred.Password.ConvertToString())))
286+
.Returns(getresponse)
287+
.Verifiable();
209288

210289
cmdlet.ExecuteCmdlet();
211290

@@ -268,7 +347,6 @@ public void CanCreateNewHDInsightCluster_LinuxComponentVersion()
268347

269348

270349
cluster.Properties.ClusterDefinition.ComponentVersion = componentVersion;
271-
272350
var coreConfigs = new Dictionary<string, string>
273351
{
274352
{"fs.defaultFS", "wasb://giyertestcsmv2@" + StorageName},
@@ -292,7 +370,7 @@ public void CanCreateNewHDInsightCluster_LinuxComponentVersion()
292370
var serializedConfig = JsonConvert.SerializeObject(configurations);
293371
cluster.Properties.ClusterDefinition.Configurations = serializedConfig;
294372

295-
var getresponse = new ClusterGetResponse { Cluster = cluster };
373+
var getresponse = new ClusterGetResponse {Cluster = cluster};
296374

297375
hdinsightManagementMock.Setup(c => c.CreateNewCluster(ResourceGroupName, ClusterName, It.Is<ClusterCreateParameters>(
298376
parameters =>
@@ -309,6 +387,21 @@ public void CanCreateNewHDInsightCluster_LinuxComponentVersion()
309387
parameters.ComponentVersion["Spark"] == componentVersion["Spark"])))
310388
.Returns(getresponse)
311389
.Verifiable();
390+
hdinsightManagementMock.Setup(
391+
c => c.CreateNewCluster(ResourceGroupName, ClusterName, It.Is<ClusterCreateParameters>(
392+
parameters =>
393+
parameters.ClusterSizeInNodes == ClusterSize &&
394+
parameters.DefaultStorageAccountName == StorageName &&
395+
parameters.DefaultStorageAccountKey == StorageKey &&
396+
parameters.Location == Location &&
397+
parameters.UserName == _httpCred.UserName &&
398+
parameters.Password == _httpCred.Password.ConvertToString() &&
399+
parameters.ClusterType == ClusterType &&
400+
parameters.OSType == OSType.Linux &&
401+
parameters.SshUserName == _sshCred.UserName &&
402+
parameters.SshPassword == _sshCred.Password.ConvertToString())))
403+
.Returns(getresponse)
404+
.Verifiable();
312405

313406
cmdlet.ExecuteCmdlet();
314407

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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.Management.Automation;
16+
using Microsoft.Azure.Commands.HDInsight.Models;
17+
using Microsoft.WindowsAzure.Commands.Common;
18+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
19+
using Moq;
20+
using Xunit;
21+
22+
namespace Microsoft.Azure.Commands.HDInsight.Test
23+
{
24+
public class SecurityProfileTests : HDInsightTestBase
25+
{
26+
public SecurityProfileTests(Xunit.Abstractions.ITestOutputHelper output)
27+
{
28+
ServiceManagemenet.Common.Models.XunitTracingInterceptor.AddToContext(new ServiceManagemenet.Common.Models.XunitTracingInterceptor(output));
29+
base.SetupTestsForManagement();
30+
}
31+
32+
[Fact]
33+
[Trait(Category.AcceptanceType, Category.CheckIn)]
34+
public void CanCreateNewSecurityProfile()
35+
{
36+
SetupConfirmation(commandRuntimeMock);
37+
38+
var config = new AzureHDInsightConfig();
39+
var newconfigcmdlet = new AddAzureHDInsightSecurityProfile()
40+
{
41+
CommandRuntime = commandRuntimeMock.Object,
42+
HDInsightManagementClient = hdinsightManagementMock.Object,
43+
Config = config,
44+
Domain = "domain.com",
45+
DomainUserCredential = new PSCredential("username","pass".ConvertToSecureString()),
46+
OrganizationalUnitDN = "OUDN",
47+
LdapsUrls = new[]
48+
{
49+
"ldapsUrl"
50+
},
51+
ClusterUsersGroupDNs = new []
52+
{
53+
"usersGroupDn"
54+
}
55+
};
56+
57+
newconfigcmdlet.ExecuteCmdlet();
58+
commandRuntimeMock.Verify(
59+
f =>
60+
f.WriteObject(
61+
It.Is<AzureHDInsightConfig>(
62+
c =>
63+
c.ClusterType == ClusterType &&
64+
c.AdditionalStorageAccounts.Count == 0 &&
65+
c.Configurations.Count == 0 &&
66+
string.IsNullOrEmpty(c.WorkerNodeSize) &&
67+
string.IsNullOrEmpty(c.DefaultStorageAccountKey) &&
68+
string.IsNullOrEmpty(c.DefaultStorageAccountName) &&
69+
string.IsNullOrEmpty(c.HeadNodeSize) &&
70+
string.IsNullOrEmpty(c.ZookeeperNodeSize) &&
71+
c.HiveMetastore == null &&
72+
c.OozieMetastore == null &&
73+
c.ScriptActions.Count == 0 &&
74+
c.SecurityProfile.Domain.Equals(newconfigcmdlet.Domain) &&
75+
c.SecurityProfile.DomainUserCredential.UserName.Equals(newconfigcmdlet.DomainUserCredential.UserName) &&
76+
c.SecurityProfile.OrganizationalUnitDN.Equals(newconfigcmdlet.OrganizationalUnitDN) &&
77+
c.SecurityProfile.LdapsUrls.ArrayToString("").Equals(newconfigcmdlet.LdapsUrls.ArrayToString("")) &&
78+
c.SecurityProfile.ClusterUsersGroupDNs.ArrayToString("").Equals(newconfigcmdlet.ClusterUsersGroupDNs.ArrayToString("")))),
79+
Times.Once);
80+
}
81+
}
82+
}

src/ResourceManager/HDInsight/Commands.HDInsight.Test/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<package id="Microsoft.Azure.Gallery" version="2.6.2-preview" targetFramework="net45" />
77
<package id="Microsoft.Azure.KeyVault.Core" version="1.0.0" targetFramework="net45" />
88
<package id="Microsoft.Azure.Management.Authorization" version="0.18.2-preview" targetFramework="net45" />
9-
<package id="Microsoft.Azure.Management.HDInsight" version="1.0.14-preview" targetFramework="net45" />
9+
<package id="Microsoft.Azure.Management.HDInsight" version="1.3.0" targetFramework="net45" />
1010
<package id="Microsoft.Azure.Management.HDInsight.Job" version="2.0.3" targetFramework="net45" />
1111
<package id="Microsoft.Azure.Management.Resources" version="2.20.0-preview" targetFramework="net45" />
1212
<package id="Microsoft.Azure.Management.Storage" version="2.4.0-preview" targetFramework="net45" />

src/ResourceManager/HDInsight/Commands.HDInsight/Commands.HDInsight.csproj

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
<Compile Include="JobCommands\StopAzureHDInsightJobCommand.cs" />
5252
<Compile Include="JobCommands\StartAzureHDInsightJobCommand.cs" />
5353
<Compile Include="ManagementCommands\AddAzureHDInsightComponentVersionCommand.cs" />
54+
<Compile Include="ManagementCommands\AddAzureHDInsightSecurityProfile.cs" />
5455
<Compile Include="ManagementCommands\SetAzureHDInsightDefaultStorageCommand.cs" />
5556
<Compile Include="ManagementCommands\AddAzureHDInsightClusterIdentity.cs" />
5657
<Compile Include="ManagementCommands\AddAzureHDInsightStorageCommand.cs" />
@@ -94,6 +95,7 @@
9495
<Compile Include="ManagementCommands\NewAzureHDInsightClusterCommand.cs" />
9596
<Compile Include="ClusterConfigurationUtils.cs" />
9697
<Compile Include="Models\Management\AzureHDInsightScriptAction.cs" />
98+
<Compile Include="Models\Management\AzureHDInsightSecurityProfile.cs" />
9799
<Compile Include="Models\Management\RuntimeScriptActionClusterNodeType.cs" />
98100
<Compile Include="Properties\AssemblyInfo.cs" />
99101
</ItemGroup>
@@ -124,14 +126,14 @@
124126
<HintPath>..\..\..\packages\Microsoft.Azure.Graph.RBAC.3.2.0-preview\lib\net45\Microsoft.Azure.Graph.RBAC.dll</HintPath>
125127
</Reference>
126128
<Reference Include="Microsoft.Azure.Management.HDInsight, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
127-
<SpecificVersion>False</SpecificVersion>
129+
<SpecificVersion>False</SpecificVersion>
128130
<HintPath>..\..\..\packages\Microsoft.Azure.Management.HDInsight.1.3.0\lib\net40\Microsoft.Azure.Management.HDInsight.dll</HintPath>
129131
</Reference>
130132
<Reference Include="Microsoft.Azure.Management.HDInsight.Job">
131133
<SpecificVersion>False</SpecificVersion>
132134
<HintPath>..\..\..\packages\Microsoft.Azure.Management.HDInsight.Job.2.0.3\lib\net40\Microsoft.Azure.Management.HDInsight.Job.dll</HintPath>
133135
</Reference>
134-
<Reference Include="Microsoft.Azure.ResourceManager, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
136+
<Reference Include="Microsoft.Azure.ResourceManager, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
135137
<SpecificVersion>False</SpecificVersion>
136138
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Resources.2.20.0-preview\lib\net40\Microsoft.Azure.ResourceManager.dll</HintPath>
137139
</Reference>
@@ -218,4 +220,4 @@
218220
</ProjectReference>
219221
</ItemGroup>
220222
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
221-
</Project>
223+
</Project>

src/ResourceManager/HDInsight/Commands.HDInsight/Constants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public static class CommandNames
2828
public const string AzureHDInsightMetastore = "AzureRmHDInsightMetastore";
2929
public const string AzureHDInsightScriptAction = "AzureRmHDInsightScriptAction";
3030
public const string AzureHDInsightScriptActionHistory = "AzureRmHDInsightScriptActionHistory";
31+
public const string AzureHDInsightSecurityProfile = "AzureRmHDInsightSecurityProfile";
3132
public const string AzureHDInsightPersistedScriptAction = "AzureRmHDInsightPersistedScriptAction";
3233
public const string AzureHDInsightStorage = "AzureRmHDInsightStorage";
3334
public const string AzureHDInsightProperties = "AzureRmHDInsightProperties";

0 commit comments

Comments
 (0)