Skip to content

Add HDInsight secure hadoop cluster creation support in powershell #3144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@
<Compile Include="HDInsightTestBase.cs" />
<Compile Include="UnitTests\PremiumClusterTests.cs" />
<Compile Include="UnitTests\ScriptActionTests.cs" />
<Compile Include="UnitTests\SecurityProfileTests.cs" />
<None Include="ScenarioTests\HDInsightConfigurationTests.ps1">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down Expand Up @@ -224,4 +225,4 @@
<Folder Include="SessionRecords\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,64 @@ public void CanCreateNewHDInsightCluster()
[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void CanCreateNewHDInsightCluster_Linux()
{
CreateNewHDInsightCluster();

commandRuntimeMock.Verify(f => f.WriteObject(It.Is<AzureHDInsightCluster>(
clusterout =>
clusterout.ClusterState == "Running" &&
clusterout.ClusterType == ClusterType &&
clusterout.ClusterVersion == "3.1" &&
clusterout.CoresUsed == 24 &&
clusterout.Location == Location &&
clusterout.Name == ClusterName &&
clusterout.OperatingSystemType == OSType.Linux)),
Times.Once);

}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void CanCreateNewHDInsightCluster_Secure_Linux()
{
cmdlet.SecurityProfile = new AzureHDInsightSecurityProfile()
{
Domain = "domain.com",
DomainUserCredential = new PSCredential("username", "pass".ConvertToSecureString()),
OrganizationalUnitDN = "OUDN",
LdapsUrls = new[]
{
"ldapsurl"
},
ClusterUsersGroupDNs = new[]
{
"userGroupDn"
}
};

CreateNewHDInsightCluster(addSecurityProfileInresponse:true);

commandRuntimeMock.Verify(f => f.WriteObject(It.Is<AzureHDInsightCluster>(
clusterout =>
clusterout.ClusterState == "Running" &&
clusterout.ClusterType == ClusterType &&
clusterout.ClusterVersion == "3.1" &&
clusterout.CoresUsed == 24 &&
clusterout.Location == Location &&
clusterout.Name == ClusterName &&
clusterout.OperatingSystemType == OSType.Linux &&
clusterout.SecurityProfile.Domain.Equals(cmdlet.SecurityProfile.Domain) &&
clusterout.SecurityProfile.DomainUserCredential.UserName.Equals(
cmdlet.SecurityProfile.DomainUserCredential.UserName) &&
clusterout.SecurityProfile.OrganizationalUnitDN.Equals(cmdlet.SecurityProfile.OrganizationalUnitDN) &&
clusterout.SecurityProfile.LdapsUrls.ArrayToString("")
.Equals(cmdlet.SecurityProfile.LdapsUrls.ArrayToString("")) &&
clusterout.SecurityProfile.ClusterUsersGroupDNs.ArrayToString("")
.Equals(cmdlet.SecurityProfile.ClusterUsersGroupDNs.ArrayToString("")))),
Times.Once);
}

private void CreateNewHDInsightCluster(bool addSecurityProfileInresponse = false)
{
cmdlet.ClusterName = ClusterName;
cmdlet.ResourceGroupName = ResourceGroupName;
Expand All @@ -146,7 +204,7 @@ public void CanCreateNewHDInsightCluster_Linux()
cmdlet.ClusterType = ClusterType;
cmdlet.SshCredential = _sshCred;
cmdlet.OSType = OSType.Linux;

var cluster = new Cluster
{
Id = "id",
Expand All @@ -167,6 +225,26 @@ public void CanCreateNewHDInsightCluster_Linux()
OperatingSystemType = OSType.Linux
}
};

if (addSecurityProfileInresponse)
{
cluster.Properties.SecurityProfile = new SecurityProfile()
{
Domain = "domain.com",
DomainUsername = "username",
DomainUserPassword = "pass",
OrganizationalUnitDN = "OUDN",
LdapsUrls = new[]
{
"ldapsurl"
},
ClusterUsersGroupDNs = new[]
{
"userGroupDn"
}
};
}

var coreConfigs = new Dictionary<string, string>
{
{"fs.defaultFS", "wasb://giyertestcsmv2@" + StorageName},
Expand All @@ -190,22 +268,23 @@ public void CanCreateNewHDInsightCluster_Linux()
var serializedConfig = JsonConvert.SerializeObject(configurations);
cluster.Properties.ClusterDefinition.Configurations = serializedConfig;

var getresponse = new ClusterGetResponse { Cluster = cluster };
var getresponse = new ClusterGetResponse {Cluster = cluster};

hdinsightManagementMock.Setup(c => c.CreateNewCluster(ResourceGroupName, ClusterName, It.Is<ClusterCreateParameters>(
parameters =>
parameters.ClusterSizeInNodes == ClusterSize &&
parameters.DefaultStorageAccountName == StorageName &&
parameters.DefaultStorageAccountKey == StorageKey &&
parameters.Location == Location &&
parameters.UserName == _httpCred.UserName &&
parameters.Password == _httpCred.Password.ConvertToString() &&
parameters.ClusterType == ClusterType &&
parameters.OSType == OSType.Linux &&
parameters.SshUserName == _sshCred.UserName &&
parameters.SshPassword == _sshCred.Password.ConvertToString())))
.Returns(getresponse)
.Verifiable();
hdinsightManagementMock.Setup(
c => c.CreateNewCluster(ResourceGroupName, ClusterName, It.Is<ClusterCreateParameters>(
parameters =>
parameters.ClusterSizeInNodes == ClusterSize &&
parameters.DefaultStorageAccountName == StorageName &&
parameters.DefaultStorageAccountKey == StorageKey &&
parameters.Location == Location &&
parameters.UserName == _httpCred.UserName &&
parameters.Password == _httpCred.Password.ConvertToString() &&
parameters.ClusterType == ClusterType &&
parameters.OSType == OSType.Linux &&
parameters.SshUserName == _sshCred.UserName &&
parameters.SshPassword == _sshCred.Password.ConvertToString())))
.Returns(getresponse)
.Verifiable();

cmdlet.ExecuteCmdlet();

Expand Down Expand Up @@ -268,7 +347,6 @@ public void CanCreateNewHDInsightCluster_LinuxComponentVersion()


cluster.Properties.ClusterDefinition.ComponentVersion = componentVersion;

var coreConfigs = new Dictionary<string, string>
{
{"fs.defaultFS", "wasb://giyertestcsmv2@" + StorageName},
Expand All @@ -292,7 +370,7 @@ public void CanCreateNewHDInsightCluster_LinuxComponentVersion()
var serializedConfig = JsonConvert.SerializeObject(configurations);
cluster.Properties.ClusterDefinition.Configurations = serializedConfig;

var getresponse = new ClusterGetResponse { Cluster = cluster };
var getresponse = new ClusterGetResponse {Cluster = cluster};

hdinsightManagementMock.Setup(c => c.CreateNewCluster(ResourceGroupName, ClusterName, It.Is<ClusterCreateParameters>(
parameters =>
Expand All @@ -309,6 +387,21 @@ public void CanCreateNewHDInsightCluster_LinuxComponentVersion()
parameters.ComponentVersion["Spark"] == componentVersion["Spark"])))
.Returns(getresponse)
.Verifiable();
hdinsightManagementMock.Setup(
c => c.CreateNewCluster(ResourceGroupName, ClusterName, It.Is<ClusterCreateParameters>(
parameters =>
parameters.ClusterSizeInNodes == ClusterSize &&
parameters.DefaultStorageAccountName == StorageName &&
parameters.DefaultStorageAccountKey == StorageKey &&
parameters.Location == Location &&
parameters.UserName == _httpCred.UserName &&
parameters.Password == _httpCred.Password.ConvertToString() &&
parameters.ClusterType == ClusterType &&
parameters.OSType == OSType.Linux &&
parameters.SshUserName == _sshCred.UserName &&
parameters.SshPassword == _sshCred.Password.ConvertToString())))
.Returns(getresponse)
.Verifiable();

cmdlet.ExecuteCmdlet();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using System.Management.Automation;
using Microsoft.Azure.Commands.HDInsight.Models;
using Microsoft.WindowsAzure.Commands.Common;
using Microsoft.WindowsAzure.Commands.ScenarioTest;
using Moq;
using Xunit;

namespace Microsoft.Azure.Commands.HDInsight.Test
{
public class SecurityProfileTests : HDInsightTestBase
{
public SecurityProfileTests(Xunit.Abstractions.ITestOutputHelper output)
{
ServiceManagemenet.Common.Models.XunitTracingInterceptor.AddToContext(new ServiceManagemenet.Common.Models.XunitTracingInterceptor(output));
base.SetupTestsForManagement();
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void CanCreateNewSecurityProfile()
{
SetupConfirmation(commandRuntimeMock);

var config = new AzureHDInsightConfig();
var newconfigcmdlet = new AddAzureHDInsightSecurityProfile()
{
CommandRuntime = commandRuntimeMock.Object,
HDInsightManagementClient = hdinsightManagementMock.Object,
Config = config,
Domain = "domain.com",
DomainUserCredential = new PSCredential("username","pass".ConvertToSecureString()),
OrganizationalUnitDN = "OUDN",
LdapsUrls = new[]
{
"ldapsUrl"
},
ClusterUsersGroupDNs = new []
{
"usersGroupDn"
}
};

newconfigcmdlet.ExecuteCmdlet();
commandRuntimeMock.Verify(
f =>
f.WriteObject(
It.Is<AzureHDInsightConfig>(
c =>
c.ClusterType == ClusterType &&
c.AdditionalStorageAccounts.Count == 0 &&
c.Configurations.Count == 0 &&
string.IsNullOrEmpty(c.WorkerNodeSize) &&
string.IsNullOrEmpty(c.DefaultStorageAccountKey) &&
string.IsNullOrEmpty(c.DefaultStorageAccountName) &&
string.IsNullOrEmpty(c.HeadNodeSize) &&
string.IsNullOrEmpty(c.ZookeeperNodeSize) &&
c.HiveMetastore == null &&
c.OozieMetastore == null &&
c.ScriptActions.Count == 0 &&
c.SecurityProfile.Domain.Equals(newconfigcmdlet.Domain) &&
c.SecurityProfile.DomainUserCredential.UserName.Equals(newconfigcmdlet.DomainUserCredential.UserName) &&
c.SecurityProfile.OrganizationalUnitDN.Equals(newconfigcmdlet.OrganizationalUnitDN) &&
c.SecurityProfile.LdapsUrls.ArrayToString("").Equals(newconfigcmdlet.LdapsUrls.ArrayToString("")) &&
c.SecurityProfile.ClusterUsersGroupDNs.ArrayToString("").Equals(newconfigcmdlet.ClusterUsersGroupDNs.ArrayToString("")))),
Times.Once);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<package id="Microsoft.Azure.Gallery" version="2.6.2-preview" targetFramework="net45" />
<package id="Microsoft.Azure.KeyVault.Core" version="1.0.0" targetFramework="net45" />
<package id="Microsoft.Azure.Management.Authorization" version="0.18.2-preview" targetFramework="net45" />
<package id="Microsoft.Azure.Management.HDInsight" version="1.0.14-preview" targetFramework="net45" />
<package id="Microsoft.Azure.Management.HDInsight" version="1.3.0" targetFramework="net45" />
<package id="Microsoft.Azure.Management.HDInsight.Job" version="2.0.3" targetFramework="net45" />
<package id="Microsoft.Azure.Management.Resources" version="2.20.0-preview" targetFramework="net45" />
<package id="Microsoft.Azure.Management.Storage" version="2.4.0-preview" targetFramework="net45" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
<Compile Include="JobCommands\StopAzureHDInsightJobCommand.cs" />
<Compile Include="JobCommands\StartAzureHDInsightJobCommand.cs" />
<Compile Include="ManagementCommands\AddAzureHDInsightComponentVersionCommand.cs" />
<Compile Include="ManagementCommands\AddAzureHDInsightSecurityProfile.cs" />
<Compile Include="ManagementCommands\SetAzureHDInsightDefaultStorageCommand.cs" />
<Compile Include="ManagementCommands\AddAzureHDInsightClusterIdentity.cs" />
<Compile Include="ManagementCommands\AddAzureHDInsightStorageCommand.cs" />
Expand Down Expand Up @@ -94,6 +95,7 @@
<Compile Include="ManagementCommands\NewAzureHDInsightClusterCommand.cs" />
<Compile Include="ClusterConfigurationUtils.cs" />
<Compile Include="Models\Management\AzureHDInsightScriptAction.cs" />
<Compile Include="Models\Management\AzureHDInsightSecurityProfile.cs" />
<Compile Include="Models\Management\RuntimeScriptActionClusterNodeType.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Expand Down Expand Up @@ -124,14 +126,14 @@
<HintPath>..\..\..\packages\Microsoft.Azure.Graph.RBAC.3.2.0-preview\lib\net45\Microsoft.Azure.Graph.RBAC.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.Management.HDInsight, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Microsoft.Azure.Management.HDInsight.1.3.0\lib\net40\Microsoft.Azure.Management.HDInsight.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.Management.HDInsight.Job">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Microsoft.Azure.Management.HDInsight.Job.2.0.3\lib\net40\Microsoft.Azure.Management.HDInsight.Job.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.ResourceManager, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<Reference Include="Microsoft.Azure.ResourceManager, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Resources.2.20.0-preview\lib\net40\Microsoft.Azure.ResourceManager.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -218,4 +220,4 @@
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public static class CommandNames
public const string AzureHDInsightMetastore = "AzureRmHDInsightMetastore";
public const string AzureHDInsightScriptAction = "AzureRmHDInsightScriptAction";
public const string AzureHDInsightScriptActionHistory = "AzureRmHDInsightScriptActionHistory";
public const string AzureHDInsightSecurityProfile = "AzureRmHDInsightSecurityProfile";
public const string AzureHDInsightPersistedScriptAction = "AzureRmHDInsightPersistedScriptAction";
public const string AzureHDInsightStorage = "AzureRmHDInsightStorage";
public const string AzureHDInsightProperties = "AzureRmHDInsightProperties";
Expand Down
Loading