Skip to content

HPF PR: dev <- Azure:dev #519

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 5 commits into from
Apr 28, 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 @@ -34,7 +34,7 @@ function Test-DataLakeStoreClusterCreate{
$workernodeSize = "Standard_D3"
$username = "admin"
$passwd = " "
$certPasswd = " "
$certPasswd = ""
$certPath = " "
$certFile = "sp.pfx"
$servPrincipal = "sp"
Expand All @@ -48,7 +48,11 @@ function Test-DataLakeStoreClusterCreate{
$sshCred=New-Object System.Management.Automation.PSCredential($sshUser,$sshPasswd)

#execute
$cluster = New-AzureRmHDInsightCluster -Location $locName -ResourceGroupName $rmGroup -ClusterType Hadoop -ClusterName $clusterName -ClusterSizeInNodes $clusterNodes -HttpCredential $credential -DefaultStorageAccountName "ypseastus.blob.core.windows.net" -DefaultStorageAccountKey $storageAccountKey -DefaultStorageContainer $clusterName -Version $version -SshCredential $sshCred -OSType Linux -ObjectId $objectId -CertificateFilePath $certFilePath -CertificatePassword $certPasswd
$cluster = New-AzureRmHDInsightCluster -Location $locName -ResourceGroupName $rmGroup -ClusterType Hadoop `
-ClusterName $clusterName -ClusterSizeInNodes $clusterNodes -HttpCredential $credential `
-DefaultStorageAccountName "$saName.blob.core.windows.net" -DefaultStorageAccountKey $storageAccountKey `
-DefaultStorageContainer $clusterName -Version $version -SshCredential $sshCred -OSType Linux `
-ObjectId $objectId -CertificateFilePath $certFilePath -CertificatePassword $certPasswd

#assert
Assert-NotNull $cluster
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ protected HDInsightManagementClient GetHdInsightManagementClient()
return TestBase.GetServiceClient<HDInsightManagementClient>(this.csmTestFactory);
}

/// <summary>
/// Runs the PowerShell test
/// </summary>
/// <param name="scripts">script to be executed</param>
public void RunPsTest(params string[] scripts)
{
var callingClassType = TestUtilities.GetCallingClass(2);
Expand All @@ -68,6 +72,14 @@ public void RunPsTest(params string[] scripts)
mockName);
}

/// <summary>
/// Runs the PowerShell test under mock undo context based on the test mode setting (Record|Playback)
/// </summary>
/// <param name="scriptBuilder">Script builder delegate</param>
/// <param name="initialize">initialize action</param>
/// <param name="cleanup">cleanup action</param>
/// <param name="callingClassType">Calling class type</param>
/// <param name="mockName">Mock Name</param>
public void RunPsTestWorkflow(
Func<string[]> scriptBuilder,
Action<CSMTestEnvironmentFactory> initialize,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ public class DataLakeStoreTests : HDInsightTestBase
private Guid AadTenantId = new Guid("11111111-1111-1111-1111-111111111111");
private string Certificate = "";
private string CertificatePassword = "";

private byte[] CertificateFileContents = { };
private readonly PSCredential _httpCred;
private Mock<AzureHDInsightConfig> AzureHDInsightconfigMock;

public DataLakeStoreTests()
{
Expand All @@ -54,120 +55,52 @@ public DataLakeStoreTests()
CommandRuntime = commandRuntimeMock.Object,
HDInsightManagementClient = hdinsightManagementMock.Object
};
AzureHDInsightconfigMock = new Mock<AzureHDInsightConfig>();
}

[Fact(Skip="Test currently failing. To be fixed in next release.")]
[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void CanCreateNewHDInsightDataLakeStoreCluster()
public void CanCreateClusterConfigWithDataLakeStoreParameters()
{
cmdlet.ClusterName = ClusterName;
cmdlet.ResourceGroupName = ResourceGroupName;
cmdlet.ClusterSizeInNodes = ClusterSize;
cmdlet.Location = Location;
cmdlet.HttpCredential = _httpCred;
cmdlet.DefaultStorageAccountName = StorageName;
cmdlet.DefaultStorageAccountKey = StorageKey;
cmdlet.AadTenantId = AadTenantId;
cmdlet.ObjectId = ObjectId;
cmdlet.CertificateFilePath = Certificate;
cmdlet.CertificatePassword = CertificatePassword;

var cluster = new Cluster
{
Id = "id",
Name = ClusterName,
Location = Location,
Properties = new ClusterGetProperties
{
ClusterVersion = "3.2",
ClusterState = "Running",
ClusterDefinition = new ClusterDefinition
{
ClusterType = ClusterType
},
QuotaInfo = new QuotaInfo
{
CoresUsed = 24
},
OperatingSystemType = OSType.Windows
}
};
var coreConfigs = new Dictionary<string, string>
{
{"fs.defaultFS", "wasb://dummycsmv2@" + StorageName},
{
"fs.azure.account.key." + StorageName,
StorageKey
}
};
var gatewayConfigs = new Dictionary<string, string>
{
{"restAuthCredential.isEnabled", "true"},
{"restAuthCredential.username", _httpCred.UserName},
{"restAuthCredential.password", _httpCred.Password.ConvertToString()}
};
var datalakeStoreConfigs = new Dictionary<string, string>
{
{"clusterIdentity.applicationId", ObjectId.ToString()},
{"clusterIdentity.certificate", Certificate},
{"clusterIdentity.certificatePassword", CertificatePassword},
{"clusterIdentity.aadTenantId", AadTenantId.ToString()}
};
var configurations = new Dictionary<string, Dictionary<string, string>>
var newclusteridentitycmdlet = new NewAzureHDInsightClusterConfigCommand()
{
{"core-site", coreConfigs},
{"gateway", gatewayConfigs},
{"clusterIdentity", datalakeStoreConfigs}
CommandRuntime = commandRuntimeMock.Object,
HDInsightManagementClient = hdinsightManagementMock.Object,
ObjectId = ObjectId,
CertificateFilePath = Certificate,
AadTenantId = AadTenantId,
CertificatePassword = CertificatePassword
};
var serializedConfig = JsonConvert.SerializeObject(configurations);
cluster.Properties.ClusterDefinition.Configurations = serializedConfig;

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.Windows)))
.Returns(getresponse)
.Verifiable();

cmdlet.ExecuteCmdlet();

commandRuntimeMock.VerifyAll();
commandRuntimeMock.Verify(f => f.WriteObject(It.Is<AzureHDInsightCluster>(
clusterout =>
clusterout.ClusterState == "Running" &&
clusterout.ClusterType == ClusterType &&
clusterout.ClusterVersion == "3.2" &&
clusterout.CoresUsed == 24 &&
clusterout.Location == Location &&
clusterout.Name == ClusterName &&
clusterout.OperatingSystemType == OSType.Windows)),
Times.Once);
newclusteridentitycmdlet.ExecuteCmdlet();
commandRuntimeMock.Verify(
f =>
f.WriteObject(
It.Is<AzureHDInsightConfig>(
c =>
c.AADTenantId == AadTenantId &&
c.CertificatePassword == CertificatePassword &&
c.ObjectId == ObjectId &&
c.CertificateFilePath == Certificate
)),
Times.Once);
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void CanCreateClusterConfigWithDataLakeStoreParameters()
public void CanCreateDataLakeClusterWithCertificationFileContents()
{
var newclusteridentitycmdlet = new NewAzureHDInsightClusterConfigCommand()
var clusterIdentityCmdlet = new NewAzureHDInsightClusterConfigCommand()
{
CommandRuntime = commandRuntimeMock.Object,
HDInsightManagementClient = hdinsightManagementMock.Object,
CertificateFilePath = Certificate,
ObjectId = ObjectId,
CertificateFileContents = CertificateFileContents,
AadTenantId = AadTenantId,
CertificatePassword = CertificatePassword
};

newclusteridentitycmdlet.ExecuteCmdlet();
clusterIdentityCmdlet.ExecuteCmdlet();
commandRuntimeMock.Verify(
f =>
f.WriteObject(
Expand All @@ -176,9 +109,43 @@ public void CanCreateClusterConfigWithDataLakeStoreParameters()
c.AADTenantId == AadTenantId &&
c.CertificatePassword == CertificatePassword &&
c.ObjectId == ObjectId &&
c.CertificateFilePath == Certificate
c.CertificateFileContents == CertificateFileContents
)),
Times.Once);
Times.Once);
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void ShouldThrowIfCertificateOptionsAreNotPassed()
{
var clusterIdentityCmdlet = new AddAzureHDInsightClusterIdentity()
{
CommandRuntime = commandRuntimeMock.Object,
HDInsightManagementClient = hdinsightManagementMock.Object,
ObjectId = ObjectId,
AadTenantId = AadTenantId,
CertificatePassword = CertificatePassword
};

Assert.Throws<ArgumentException>(() => clusterIdentityCmdlet.ExecuteCmdlet());
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void ShouldThrowIfBothCertificateOptionsArePassed()
{
var clusterIdentityCmdlet = new AddAzureHDInsightClusterIdentity()
{
CommandRuntime = commandRuntimeMock.Object,
HDInsightManagementClient = hdinsightManagementMock.Object,
ObjectId = ObjectId,
AadTenantId = AadTenantId,
CertificatePassword = CertificatePassword,
CertificateFileContents = CertificateFileContents,
CertificateFilePath = Certificate
};

Assert.Throws<ArgumentException>(() => clusterIdentityCmdlet.ExecuteCmdlet());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@ namespace Microsoft.Azure.Commands.HDInsight.ManagementCommands
{
[Cmdlet(
VerbsCommon.Add,
Constants.CommandNames.AzureHDInsightClusterIdentity),
Constants.CommandNames.AzureHDInsightClusterIdentity,
DefaultParameterSetName = CertificateFilePathSet),
OutputType(typeof(AzureHDInsightConfig))]
public class AddAzureHDInsightClusterIdentity : HDInsightCmdletBase
{
private const string CertificateFilePathSet = "CertificateFilePath";
private const string CertificateFileContentsSet = "CertificateFileContents";

#region Input Parameter Definitions

[Parameter(Position = 0,
Expand All @@ -41,9 +45,16 @@ public class AddAzureHDInsightClusterIdentity : HDInsightCmdletBase

[Parameter(Position = 2,
Mandatory = true,
HelpMessage = "The Service Principal certificate for accessing Azure Data Lake.")]
HelpMessage = "The Service Principal certificate file path for accessing Azure Data Lake.",
ParameterSetName = CertificateFilePathSet)]
public string CertificateFilePath { get; set; }

[Parameter(Position = 2,
Mandatory = true,
HelpMessage = "The Service Principal certificate file contents for accessing Azure Data Lake.",
ParameterSetName = CertificateFileContentsSet)]
public byte[] CertificateFileContents { get; set; }

[Parameter(Position = 3,
Mandatory = true,
HelpMessage = "The Service Principal certificate password for accessing Azure Data Lake.")]
Expand All @@ -52,16 +63,32 @@ public class AddAzureHDInsightClusterIdentity : HDInsightCmdletBase
[Parameter(Position = 4,
Mandatory = false,
HelpMessage = "The Service Principal AAD Tenant Id for accessing Azure Data Lake.")]
public Guid AadTenantId { get; set; }
public Guid AadTenantId { get; set; }

#endregion

public override void ExecuteCmdlet()
{
switch (ParameterSetName)
{
case CertificateFilePathSet:
{
Config.CertificateFilePath = CertificateFilePath;
}
break;
case CertificateFileContentsSet:
{
Config.CertificateFileContents = CertificateFileContents;
}
break;
default:
throw new ArgumentException("Please specify CertificateFilePath or CertificateFileContent");
}

Config.ObjectId = ObjectId;
Config.AADTenantId = AadTenantId;
Config.CertificateFilePath = CertificateFilePath;
Config.CertificatePassword = CertificatePassword;

WriteObject(Config);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,17 @@ namespace Microsoft.Azure.Commands.HDInsight
{
[Cmdlet(
VerbsCommon.New,
Constants.CommandNames.AzureHDInsightCluster),
Constants.CommandNames.AzureHDInsightCluster,
DefaultParameterSetName = DefaultParameterSet),
OutputType(
typeof(AzureHDInsightCluster))]
public class NewAzureHDInsightClusterCommand : HDInsightCmdletBase
{
private ClusterCreateParameters parameters;
private const string CertificateFilePathSet = "CertificateFilePath";
private const string CertificateFileContentsSet = "CertificateFileContents";
private const string DefaultParameterSet = "Default";

#region Input Parameter Definitions

[Parameter(
Expand Down Expand Up @@ -118,6 +123,7 @@ public AzureHDInsightConfig Config
OozieMetastore = OozieMetastore,
ObjectId = ObjectId,
AADTenantId = AadTenantId,
CertificateFileContents = CertificateFileContents,
CertificateFilePath = CertificateFilePath,
CertificatePassword = CertificatePassword
};
Expand Down Expand Up @@ -155,6 +161,7 @@ var storageAccount in
parameters.ZookeeperNodeSize = value.ZookeeperNodeSize;
HiveMetastore = value.HiveMetastore;
OozieMetastore = value.OozieMetastore;
CertificateFileContents = value.CertificateFileContents;
CertificateFilePath = value.CertificateFilePath;
AadTenantId = value.AADTenantId;
ObjectId = value.ObjectId;
Expand Down Expand Up @@ -282,13 +289,18 @@ public DateTime RdpAccessExpiry
[Parameter(HelpMessage = "Gets or sets the Service Principal Object Id for accessing Azure Data Lake.")]
public Guid ObjectId { get; set; }

[Parameter(HelpMessage = "Gets or sets the Service Principal Certificate for accessing Azure Data Lake.")]
[Parameter(HelpMessage = "Gets or sets the Service Principal Certificate file path for accessing Azure Data Lake.",
ParameterSetName = CertificateFilePathSet)]
public string CertificateFilePath { get; set; }

[Parameter(HelpMessage = "Gets or sets the Service Principal Certificate file contents for accessing Azure Data Lake.",
ParameterSetName = CertificateFileContentsSet)]
public byte[] CertificateFileContents { get; set; }

[Parameter(HelpMessage = "Gets or sets the Service Principal Certificate Password for accessing Azure Data Lake.")]
public string CertificatePassword { get; set; }

[Parameter(HelpMessage = "Gets or sets the Service Principal AAD Tenant Id for accessing Azure Data Lake.", ParameterSetName = "ServicePrincipal")]
[Parameter(HelpMessage = "Gets or sets the Service Principal AAD Tenant Id for accessing Azure Data Lake.")]
public Guid AadTenantId { get; set; }

#endregion
Expand Down Expand Up @@ -352,14 +364,18 @@ var storageAccount in
var metastore = HiveMetastore;
parameters.HiveMetastore = new Metastore(metastore.SqlAzureServerName, metastore.DatabaseName, metastore.Credential.UserName, metastore.Credential.Password.ConvertToString());
}
if (CertificateFilePath != null && CertificatePassword != null)
if(!string.IsNullOrEmpty(CertificatePassword))
{
if (!string.IsNullOrEmpty(CertificateFilePath)){
CertificateFileContents = File.ReadAllBytes(CertificateFilePath);
}
var servicePrincipal = new Management.HDInsight.Models.ServicePrincipal(
GetApplicationId(), GetTenantId(AadTenantId), File.ReadAllBytes(CertificateFilePath),
GetApplicationId(), GetTenantId(AadTenantId), CertificateFileContents,
CertificatePassword);

parameters.Principal = servicePrincipal;
}

var cluster = HDInsightManagementClient.CreateNewCluster(ResourceGroupName, ClusterName, parameters);

if (cluster != null)
Expand Down
Loading