Skip to content

Commit 9b6776f

Browse files
committed
Introducing commandlets for enabling and disabling RDP access and including changes for enabling RDP during cluster create
1 parent 9340028 commit 9b6776f

20 files changed

+838
-32
lines changed

src/ServiceManagement/HDInsight/Commands.HDInsight.Test/Commands.HDInsight.Test.csproj

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3-
<Import Project="..\..\..\packages\xunit.runner.visualstudio.2.0.0\build\net20\xunit.runner.visualstudio.props" Condition="Exists('..\..\..\packages\xunit.runner.visualstudio.2.0.0\build\net20\xunit.runner.visualstudio.props')" />
3+
<Import Project="..\..\..\packages\xunit.runner.visualstudio.2.0.0\build\net20\xunit.runner.visualstudio.props" Condition="Exists('..\..\..\packages\xunit.runner.visualstudio.2.0.0\build\net20\xunit.runner.visualstudio.props')" />
44
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
55
<PropertyGroup>
66
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -15,7 +15,7 @@
1515
<TargetFrameworkProfile />
1616
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\..\</SolutionDir>
1717
<RestorePackages>true</RestorePackages>
18-
<NuGetPackageImportStamp>3042119d</NuGetPackageImportStamp>
18+
<NuGetPackageImportStamp>3042119d</NuGetPackageImportStamp>
1919
</PropertyGroup>
2020
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
2121
<DebugSymbols>true</DebugSymbols>
@@ -49,7 +49,7 @@
4949
<Reference Include="Hyak.Common">
5050
<HintPath>..\..\..\packages\Hyak.Common.1.0.2\lib\portable-net403+win+wpa81\Hyak.Common.dll</HintPath>
5151
</Reference>
52-
<Reference Include="Microsoft.Azure.Common">
52+
<Reference Include="Microsoft.Azure.Common">
5353
<HintPath>..\..\..\packages\Microsoft.Azure.Common.2.1.0\lib\net45\Microsoft.Azure.Common.dll</HintPath>
5454
</Reference>
5555
<Reference Include="Microsoft.Azure.Common.Authentication">
@@ -72,10 +72,10 @@
7272
<HintPath>..\..\..\packages\Microsoft.Data.Services.Client.5.6.0\lib\net40\Microsoft.Data.Services.Client.dll</HintPath>
7373
</Reference>
7474
<Reference Include="Microsoft.Hadoop.Client">
75-
<HintPath>..\..\..\packages\Microsoft.Hadoop.Client.1.5.5\lib\net45\Microsoft.Hadoop.Client.dll</HintPath>
75+
<HintPath>..\..\..\packages\Microsoft.Hadoop.Client.1.5.6\lib\net45\Microsoft.Hadoop.Client.dll</HintPath>
7676
</Reference>
7777
<Reference Include="Microsoft.HDInsight.Net.Http.Formatting">
78-
<HintPath>..\..\..\packages\Microsoft.Hadoop.Client.1.5.5\lib\net45\Microsoft.HDInsight.Net.Http.Formatting.dll</HintPath>
78+
<HintPath>..\..\..\packages\Microsoft.Hadoop.Client.1.5.6\lib\net45\Microsoft.HDInsight.Net.Http.Formatting.dll</HintPath>
7979
</Reference>
8080
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory">
8181
<SpecificVersion>False</SpecificVersion>
@@ -96,23 +96,23 @@
9696
</Reference>
9797
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
9898
<Reference Include="Microsoft.WindowsAzure.Configuration, Version=1.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
99-
<SpecificVersion>False</SpecificVersion>
99+
<SpecificVersion>False</SpecificVersion>
100100
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.ConfigurationManager.1.8.0.0\lib\net35-full\Microsoft.WindowsAzure.Configuration.dll</HintPath>
101101
</Reference>
102102
<Reference Include="Microsoft.WindowsAzure.Management">
103103
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.4.1.1\lib\net40\Microsoft.WindowsAzure.Management.dll</HintPath>
104104
</Reference>
105105
<Reference Include="Microsoft.WindowsAzure.Management.HDInsight">
106-
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.HDInsight.1.5.5\lib\net45\Microsoft.WindowsAzure.Management.HDInsight.dll</HintPath>
106+
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.HDInsight.1.5.6\lib\net45\Microsoft.WindowsAzure.Management.HDInsight.dll</HintPath>
107107
</Reference>
108108
<Reference Include="Microsoft.WindowsAzure.Management.HDInsight.Contracts">
109-
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.HDInsight.1.5.5\lib\net45\Microsoft.WindowsAzure.Management.HDInsight.Contracts.dll</HintPath>
109+
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.HDInsight.1.5.6\lib\net45\Microsoft.WindowsAzure.Management.HDInsight.Contracts.dll</HintPath>
110110
</Reference>
111111
<Reference Include="Microsoft.WindowsAzure.Management.HDInsight.Framework">
112-
<HintPath>..\..\..\packages\Microsoft.Hadoop.Client.1.5.5\lib\net45\Microsoft.WindowsAzure.Management.HDInsight.Framework.dll</HintPath>
112+
<HintPath>..\..\..\packages\Microsoft.Hadoop.Client.1.5.6\lib\net45\Microsoft.WindowsAzure.Management.HDInsight.Framework.dll</HintPath>
113113
</Reference>
114114
<Reference Include="Microsoft.WindowsAzure.Management.HDInsight.Framework.Core">
115-
<HintPath>..\..\..\packages\Microsoft.Hadoop.Client.1.5.5\lib\net45\Microsoft.WindowsAzure.Management.HDInsight.Framework.Core.dll</HintPath>
115+
<HintPath>..\..\..\packages\Microsoft.Hadoop.Client.1.5.6\lib\net45\Microsoft.WindowsAzure.Management.HDInsight.Framework.Core.dll</HintPath>
116116
</Reference>
117117
<Reference Include="Microsoft.WindowsAzure.Storage, Version=3.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
118118
<HintPath>..\..\..\packages\WindowsAzure.Storage.3.0.3.0\lib\net40\Microsoft.WindowsAzure.Storage.dll</HintPath>
@@ -163,6 +163,7 @@
163163
<Compile Include="HDInsight\CmdLetTests\GetJobOutputCmdletTests.cs" />
164164
<Compile Include="HDInsight\CmdLetTests\GetJobsCmdletTests.cs" />
165165
<Compile Include="HDInsight\CmdLetTests\GetPropertiesCmdletTests.cs" />
166+
<Compile Include="HDInsight\CmdLetTests\GrantRdpAccessCmdletTests.cs" />
166167
<Compile Include="HDInsight\CmdLetTests\GrantHttpAccessCmdletTests.cs" />
167168
<Compile Include="HDInsight\CmdLetTests\HDInsightTestCaseBase.cs" />
168169
<Compile Include="HDInsight\CmdLetTests\InvokeHiveCmdletTests.cs" />
@@ -187,6 +188,7 @@
187188
<Compile Include="HDInsight\CommandTests\HDInsightGetJobsCommandTests.cs" />
188189
<Compile Include="HDInsight\CommandTests\HDInsightGetPropertiesCommandTests.cs" />
189190
<Compile Include="HDInsight\CommandTests\InvokeHiveCommandTests.cs" />
191+
<Compile Include="HDInsight\CommandTests\ManageAzureHDInsightRdpAccessCommandTests.cs" />
190192
<Compile Include="HDInsight\CommandTests\ManageAzureHDInsightHttpAccessCommandTests.cs" />
191193
<Compile Include="HDInsight\CommandTests\NewHDInsightMapReduceJobCommandTests.cs" />
192194
<Compile Include="HDInsight\CommandTests\NewHDInsightPigJobCommandTests.cs" />
@@ -247,7 +249,7 @@
247249
<Project>{5ee72c53-1720-4309-b54b-5fb79703195f}</Project>
248250
<Name>Commands.Common</Name>
249251
</ProjectReference>
250-
<ProjectReference Include="..\..\..\Common\Commands.ScenarioTests.Common\Commands.ScenarioTests.Common.csproj">
252+
<ProjectReference Include="..\..\..\Common\Commands.ScenarioTests.Common\Commands.ScenarioTests.Common.csproj">
251253
<Project>{c1bda476-a5cc-4394-914d-48b0ec31a710}</Project>
252254
<Name>Commands.ScenarioTests.Common</Name>
253255
</ProjectReference>

src/ServiceManagement/HDInsight/Commands.HDInsight.Test/HDInsight/CmdLetTests/CmdletHardCodes.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public static class CmdletConstants
2828
public const string Combiner = "Combiner";
2929
public const string CoreConfig = "Core";
3030
public const string Credential = "Credential";
31+
public const string RdpCredential = "RdpCredential";
32+
public const string RdpAccessExpiry = "RdpAccessExpiry";
3133
public const string DatabaseName = "DatabaseName";
3234
public const string Debug = "Debug";
3335
public const string DefaultStorageContainerName = "DefaultStorageContainerName";
@@ -39,6 +41,7 @@ public static class CmdletConstants
3941
public const string GetAzureHDInsightJobOutput = "Get-AzureHDInsightJobOutput";
4042
public const string GetAzureHDInsightProperties = "Get-AzureHDInsightProperties";
4143
public const string GrantAzureHDInsightHttpAccess = "Grant-AzureHDInsightHttpServicesAccess";
44+
public const string GrantAzureHDInsightRdpAccess = "Grant-AzureHDInsightRdpAccess";
4245
public const string HdfsConfig = "Hdfs";
4346
public const string HiveArgs = "Arguments";
4447
public const string HiveConfig = "Hive";
@@ -78,6 +81,7 @@ public static class CmdletConstants
7881
public const string Reducer = "Reducer";
7982
public const string RemoveAzureHDInsightCluster = "Remove-AzureHDInsightCluster";
8083
public const string RevokeAzureHDInsightHttpAccess = "Revoke-AzureHDInsightHttpServicesAccess";
84+
public const string RevokeAzureHDInsightRdpAccess = "Revoke-AzureHDInsightRdpAccess";
8185
public const string SetAzureHDInsightClusterSize = "Set-AzureHDInsightClusterSize";
8286
public const string SetAzureHDInsightDefaultStorage = "Set-AzureHDInsightDefaultStorage";
8387
public const string Show = "Show";
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
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;
16+
using System.Collections.Generic;
17+
using System.Linq;
18+
using Microsoft.VisualStudio.TestTools.UnitTesting;
19+
using Microsoft.WindowsAzure.Commands.Test.Utilities.HDInsight.PowerShellTestAbstraction.Interfaces;
20+
using Microsoft.WindowsAzure.Commands.Test.Utilities.HDInsight.Utilities;
21+
using Microsoft.WindowsAzure.Management.HDInsight;
22+
using Microsoft.WindowsAzure.Management.HDInsight.Cmdlet.DataObjects;
23+
using Microsoft.WindowsAzure.Management.HDInsight.Cmdlet.GetAzureHDInsightClusters.Extensions;
24+
25+
namespace Microsoft.WindowsAzure.Commands.Test.HDInsight.CmdLetTests
26+
{
27+
[TestClass]
28+
public class GrantRdpAccessCmdletTests : HDInsightTestCaseBase
29+
{
30+
[TestCleanup]
31+
public override void TestCleanup()
32+
{
33+
base.TestCleanup();
34+
}
35+
36+
[TestMethod]
37+
[TestCategory("CheckIn")]
38+
[TestCategory("Integration")]
39+
[TestCategory("PowerShell")]
40+
41+
public void CanGrantRdpAccessToHDInsightCluster()
42+
{
43+
IHDInsightCertificateCredential creds = GetValidCredentials();
44+
using (IRunspace runspace = this.GetPowerShellRunspace())
45+
{
46+
AzureHDInsightCluster cluster = GetClusterWithRdpAccessDisabled(runspace);
47+
IPipelineResult results =
48+
runspace.NewPipeline()
49+
.AddCommand(CmdletConstants.GrantAzureHDInsightRdpAccess)
50+
.WithParameter(CmdletConstants.Location, cluster.Location)
51+
.WithParameter(CmdletConstants.Name, cluster.Name)
52+
.WithParameter(CmdletConstants.RdpCredential, GetAzurePsCredentials())
53+
.WithParameter(CmdletConstants.RdpAccessExpiry, DateTime.UtcNow.AddDays(6))
54+
.Invoke();
55+
56+
AzureHDInsightCluster accessgrantedCluster = GetCluster(creds, cluster.Name, runspace);
57+
Assert.IsNotNull(accessgrantedCluster);
58+
Assert.AreEqual(accessgrantedCluster.RdpUserName, TestCredentials.AzureUserName);
59+
}
60+
}
61+
62+
[TestInitialize]
63+
public override void Initialize()
64+
{
65+
base.Initialize();
66+
}
67+
68+
internal static AzureHDInsightCluster GetClusterWithRdpAccessDisabled(IRunspace runspace)
69+
{
70+
IHDInsightCertificateCredential creds = GetValidCredentials();
71+
IPipelineResult results =
72+
runspace.NewPipeline()
73+
.AddCommand(CmdletConstants.GetAzureHDInsightCluster)
74+
.Invoke();
75+
76+
List<AzureHDInsightCluster> testClusters = results.Results.ToEnumerable<AzureHDInsightCluster>().ToList();
77+
AzureHDInsightCluster testCluster = testClusters.FirstOrDefault(cluster => cluster.RdpUserName.IsNullOrEmpty());
78+
if (testCluster == null)
79+
{
80+
testCluster = testClusters.Last();
81+
RevokeRdpAccessToCluster(creds, testCluster, runspace);
82+
}
83+
84+
return testCluster;
85+
}
86+
87+
internal static void RevokeRdpAccessToCluster(
88+
IHDInsightCertificateCredential connectionCredentials, AzureHDInsightCluster cluster, IRunspace runspace)
89+
{
90+
IPipelineResult results =
91+
runspace.NewPipeline()
92+
.AddCommand(CmdletConstants.RevokeAzureHDInsightRdpAccess)
93+
.WithParameter(CmdletConstants.Location, cluster.Location)
94+
.WithParameter(CmdletConstants.Name, cluster.Name)
95+
.Invoke();
96+
97+
AzureHDInsightCluster accessRevokedCluster = GetCluster(connectionCredentials, cluster.Name, runspace);
98+
Assert.IsNotNull(accessRevokedCluster);
99+
Assert.IsTrue(string.IsNullOrEmpty(accessRevokedCluster.RdpUserName));
100+
}
101+
102+
internal static AzureHDInsightCluster GetCluster(
103+
IHDInsightCertificateCredential connectionCredentials, string clusterName, IRunspace runspace)
104+
{
105+
IPipelineResult results =
106+
runspace.NewPipeline()
107+
.AddCommand(CmdletConstants.GetAzureHDInsightCluster)
108+
.WithParameter(CmdletConstants.Name, clusterName)
109+
.Invoke();
110+
111+
List<AzureHDInsightCluster> clusters = results.Results.ToEnumerable<AzureHDInsightCluster>().ToList();
112+
return clusters.FirstOrDefault();
113+
}
114+
}
115+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
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;
16+
using System.Collections.Generic;
17+
using System.Linq;
18+
using Microsoft.VisualStudio.TestTools.UnitTesting;
19+
using Microsoft.WindowsAzure.Commands.Test.HDInsight.CmdLetTests;
20+
using Microsoft.WindowsAzure.Management.HDInsight;
21+
using Microsoft.WindowsAzure.Management.HDInsight.Cmdlet.Commands.CommandInterfaces;
22+
using Microsoft.WindowsAzure.Management.HDInsight.Cmdlet.DataObjects;
23+
using Microsoft.WindowsAzure.Management.HDInsight.Cmdlet.GetAzureHDInsightClusters;
24+
using Microsoft.WindowsAzure.Management.HDInsight.Cmdlet.GetAzureHDInsightClusters.Extensions;
25+
using Microsoft.WindowsAzure.Management.HDInsight.Cmdlet.ServiceLocation;
26+
27+
namespace Microsoft.WindowsAzure.Commands.Test.HDInsight.CommandTests
28+
{
29+
[TestClass]
30+
public class ManageAzureHDInsightRdpAccessCommandTests : HDInsightTestCaseBase
31+
{
32+
[TestCleanup]
33+
public override void TestCleanup()
34+
{
35+
base.TestCleanup();
36+
}
37+
38+
[TestMethod]
39+
[TestCategory("Integration")]
40+
[TestCategory("CheckIn")]
41+
[TestCategory("Rdfe")]
42+
public void CanGrantHDInsightRdpAccess()
43+
{
44+
var rdpUserName = "rdpuser";
45+
IHDInsightCertificateCredential creds = GetValidCredentials();
46+
AzureHDInsightCluster testCluster = GetClusterWithRdpAccessDisabled(creds);
47+
AzureHDInsightCluster cluster = EnableRdpAccessToCluster(
48+
creds, testCluster, rdpUserName, TestCredentials.AzurePassword, DateTime.UtcNow.AddDays(6));
49+
Assert.IsNotNull(cluster);
50+
Assert.AreEqual(cluster.RdpUserName, rdpUserName);
51+
}
52+
53+
[TestMethod]
54+
[TestCategory("Integration")]
55+
[TestCategory("CheckIn")]
56+
[TestCategory("Rdfe")]
57+
public void CanRevokeAccessToRdpServices()
58+
{
59+
IHDInsightCertificateCredential creds = GetValidCredentials();
60+
AzureHDInsightCluster testCluster = GetClusterWithRdpAccessDisabled(creds);
61+
EnableRdpAccessToCluster(creds, testCluster, TestCredentials.AzureUserName, TestCredentials.AzurePassword,
62+
DateTime.UtcNow.AddDays(6));
63+
AzureHDInsightCluster cluster = DisableRdpAccessToCluster(creds, testCluster);
64+
Assert.IsNotNull(cluster);
65+
Assert.IsTrue(string.IsNullOrEmpty(cluster.RdpUserName));
66+
}
67+
68+
[TestInitialize]
69+
public override void Initialize()
70+
{
71+
base.Initialize();
72+
}
73+
74+
private static AzureHDInsightCluster GetClusterWithRdpAccessDisabled(IHDInsightCertificateCredential creds)
75+
{
76+
IGetAzureHDInsightClusterCommand client = ServiceLocator.Instance.Locate<IAzureHDInsightCommandFactory>().CreateGet();
77+
client.CurrentSubscription = GetCurrentSubscription();
78+
client.EndProcessing();
79+
List<AzureHDInsightCluster> clusters = client.Output.ToList();
80+
AzureHDInsightCluster containerWithRdpAccessDisabled = clusters.FirstOrDefault(cluster => cluster.RdpUserName.IsNullOrEmpty());
81+
if (containerWithRdpAccessDisabled == null)
82+
{
83+
containerWithRdpAccessDisabled = clusters.Last();
84+
DisableRdpAccessToCluster(creds, containerWithRdpAccessDisabled);
85+
}
86+
87+
return containerWithRdpAccessDisabled;
88+
}
89+
90+
private static AzureHDInsightCluster DisableRdpAccessToCluster(
91+
IHDInsightCertificateCredential creds, AzureHDInsightCluster containerWithRdpAccessDisabled)
92+
{
93+
IManageAzureHDInsightRdpAccessCommand rdpManagementClient =
94+
ServiceLocator.Instance.Locate<IAzureHDInsightCommandFactory>().CreateManageRdpAccess();
95+
rdpManagementClient.CurrentSubscription = GetCurrentSubscription();
96+
rdpManagementClient.RdpCredential = GetAzurePsCredentials();
97+
rdpManagementClient.Name = containerWithRdpAccessDisabled.Name;
98+
rdpManagementClient.Location = containerWithRdpAccessDisabled.Location;
99+
rdpManagementClient.Enable = false;
100+
rdpManagementClient.EndProcessing();
101+
return rdpManagementClient.Output.First();
102+
}
103+
104+
private static AzureHDInsightCluster EnableRdpAccessToCluster(
105+
IHDInsightCertificateCredential creds, AzureHDInsightCluster containerWithRdpAccessDisabled, string rdpUserName, string rdpPassword, DateTime expiry)
106+
{
107+
IManageAzureHDInsightRdpAccessCommand rdpManagementClient =
108+
ServiceLocator.Instance.Locate<IAzureHDInsightCommandFactory>().CreateManageRdpAccess();
109+
rdpManagementClient.CurrentSubscription = GetCurrentSubscription();
110+
rdpManagementClient.RdpCredential = GetPSCredential(rdpUserName, rdpPassword);
111+
rdpManagementClient.Name = containerWithRdpAccessDisabled.Name;
112+
rdpManagementClient.Location = containerWithRdpAccessDisabled.Location;
113+
rdpManagementClient.RdpAccessExpiry = expiry;
114+
rdpManagementClient.Enable = true;
115+
116+
rdpManagementClient.EndProcessing();
117+
return rdpManagementClient.Output.First();
118+
}
119+
}
120+
}

0 commit comments

Comments
 (0)