internal virtual void TestInitialize([System.Runtime.CompilerServices.CallerMemberName] string methodName = "testframework_failed") { Context = HDInsightMockContext.Start(this.GetType().FullName, methodName); CommonData = new CommonTestFixture(); HDInsightClient = Context.GetServiceClient <HDInsightManagementClient>(); HDInsightManagementHelper = new HDInsightManagementHelper(CommonData, Context); if (IsRecordMode) { // Set mode to none to skip recording during setup HttpMockServer.Mode = HttpRecorderMode.None; HDInsightManagementHelper.RegisterSubscriptionForResource("Microsoft.HDInsight"); HDInsightManagementHelper.RegisterSubscriptionForResource("Microsoft.Storage"); HDInsightManagementHelper.RegisterSubscriptionForResource("Microsoft.DataLakeStore"); HDInsightManagementHelper.RegisterSubscriptionForResource("Microsoft.ManagedIdentity"); HDInsightManagementHelper.RegisterSubscriptionForResource("Microsoft.KeyVault"); this.CreateResources(); // Set mode back to record HttpMockServer.Mode = HttpRecorderMode.Record; string mockedSubscriptionId = TestUtilities.GenerateGuid().ToString(); CommonData.SubscriptionId = HDInsightManagementTestUtilities.GetSubscriptionId(); this.Context.AddTextReplacementRule(CommonData.SubscriptionId, mockedSubscriptionId); } }
public void TestCreateWithADLSv2() { TestInitialize(); string mockedTenantId = TestUtilities.GenerateGuid().ToString(); CommonData.TenantId = GetTenantId(); this.Context.AddTextReplacementRule(CommonData.TenantId, mockedTenantId); string mockedClientObjectId = TestUtilities.GenerateGuid().ToString(); CommonData.ClientObjectId = GetServicePrincipalObjectId(); this.Context.AddTextReplacementRule(CommonData.ClientObjectId, mockedClientObjectId); // Create an Azure storage account with Data Lake Storage Gen 2. string adlsV2AccountName = TestUtilities.GenerateName("hdicsharpadlsv2"); var storageV2AccountAccessKey = HDInsightManagementHelper.CreateStorageAccount( CommonData.ResourceGroupName, adlsV2AccountName, CommonData.Location, out string storageAccountSuffix, Kind.StorageV2, true); string storageResourceId = HDInsightManagementHelper.GetStorageAccountId(CommonData.ResourceGroupName, adlsV2AccountName); // Create a user assigned managed identity. var msi = CreateMsi(CommonData.ManagedIdentityName); // Wait some time in order to improve robustness TestUtilities.Wait(TimeSpan.FromMinutes(1)); // Assign Storage Blob Data Contributor access to the created managed identity on Azure Storage. string assignmentName = TestUtilities.GenerateGuid().ToString(); HDInsightManagementHelper.AddRoleAssignment(storageResourceId, CommonData.AdlsGen2RequiredRoleName, assignmentName, msi.PrincipalId?.ToString()); string clusterName = TestUtilities.GenerateName("hdisdk-adlgen2"); var createParams = CommonData.PrepareClusterCreateParamsForADLSv2(adlsV2AccountName, storageResourceId, msi.Id); // Add additional storage account createParams.Properties.StorageProfile.Storageaccounts.Add( new StorageAccount { Name = CommonData.StorageAccountName + CommonData.BlobEndpointSuffix, Key = CommonData.StorageAccountKey, Container = CommonData.ContainerName.ToLower(), IsDefault = false } ); // Create a HDInsight cluster var cluster = HDInsightClient.Clusters.Create(CommonData.ResourceGroupName, clusterName, createParams); ValidateCluster(clusterName, createParams, cluster); }
public void TestPrivateEndpointConnection() { TestInitialize(); string clusterName = TestUtilities.GenerateName("hdisdk-pe"); var createParams = CommonData.PrepareClusterCreateParamsForWasb(); createParams.Location = "South Central US"; var networkProperties = new NetworkProperties(ResourceProviderConnection.Outbound, PrivateLink.Enabled); createParams.Properties.NetworkProperties = networkProperties; string storageAccountResourceId = string.Format("/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Storage/storageAccounts/{2}", CommonData.SubscriptionId, CommonData.ResourceGroupName, CommonData.StorageAccountName); createParams.Properties.StorageProfile.Storageaccounts[0].ResourceId = storageAccountResourceId; string vnetId = "/subscriptions/964c10bb-8a6c-43bc-83d3-6b318c6c7305/resourceGroups/rg/providers/Microsoft.Network/virtualNetworks/fakevnet"; string subnetId = "/subscriptions/964c10bb-8a6c-43bc-83d3-6b318c6c7305/resourceGroups/rg/providers/Microsoft.Network/virtualNetworks/fakevnet/subnets/default"; foreach (var role in createParams.Properties.ComputeProfile.Roles) { role.VirtualNetworkProfile = new VirtualNetworkProfile(vnetId, subnetId); } var cluster = HDInsightClient.Clusters.Create(CommonData.ResourceGroupName, clusterName, createParams); var privateLinkResourceListResult = HDInsightClient.PrivateLinkResources.ListByCluster(CommonData.ResourceGroupName, clusterName); Assert.NotNull(privateLinkResourceListResult); var headNodePrivateLinkResource = privateLinkResourceListResult.Value.Where(pls => pls.Name.Equals("headnode")).FirstOrDefault(); // call Network sdk to create private endpoint and choose the approve manually way. // please notice that the NetworkPrivateEndpoint privateEndpointParameter = new NetworkPrivateEndpoint() { Location = cluster.Location, ManualPrivateLinkServiceConnections = new List <NetworkPrivateLinkServiceConnection> { new NetworkPrivateLinkServiceConnection() { Name = cluster.Name, // Private link service name is the cluster name PrivateLinkServiceId = cluster.Id, // Private link service id is the cluster resource id GroupIds = new List <string> { headNodePrivateLinkResource.GroupId, }, RequestMessage = "Want to connect to head node private link resource." }, }, Subnet = new Subnet(id: subnetId) }; string privateEndpointName = "headnodepe"; var createPrivateEndpointResult = HDInsightManagementHelper.CreatePrivateEndpoint(CommonData.ResourceGroupName, privateEndpointName, privateEndpointParameter); // Get the private endpoint connection and check the status var privateEndpointConnectionListResult = HDInsightClient.PrivateEndpointConnections.ListByCluster(CommonData.ResourceGroupName, clusterName); Assert.NotNull(privateEndpointConnectionListResult); foreach (var privateEndpointConnection in privateEndpointConnectionListResult) { Assert.Equal(PrivateLinkServiceConnectionStatus.Pending, privateEndpointConnection.PrivateLinkServiceConnectionState.Status); //Approve privateEndpointConnection.PrivateLinkServiceConnectionState.Status = PrivateLinkServiceConnectionStatus.Approved; HDInsightClient.PrivateEndpointConnections.CreateOrUpdate(CommonData.ResourceGroupName, clusterName, privateEndpointConnection.Name, privateEndpointConnection); //Delete HDInsightClient.PrivateEndpointConnections.Delete(CommonData.ResourceGroupName, clusterName, privateEndpointConnection.Name); } }