Ejemplo n.º 1
0
        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);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Ctor
 /// </summary>
 /// <param name="commonData"></param>
 /// <param name="context"></param>
 public HDInsightManagementHelper(CommonTestFixture commonData, HDInsightMockContext context)
 {
     resourceManagementClient      = context.GetServiceClient <ResourceManagementClient>();
     storageManagementClient       = context.GetServiceClient <StorageManagementClient>();
     identityManagementClient      = context.GetServiceClient <ManagedServiceIdentityClient>();
     authorizationManagementClient = context.GetServiceClient <AuthorizationManagementClient>();
     keyVaultManagementClient      = context.GetServiceClient <KeyVaultManagementClient>();
     keyVaultClient  = GetKeyVaultClient();
     this.commonData = commonData;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Create cluster create parameters for ADLS Gen2 relevant tests
        /// </summary>
        /// <param name="commonData"></param>
        /// <param name="storageAccountName"></param>
        /// <param name="storageResourceId"></param>
        /// <param name="msiResourceId"></param>
        /// <param name="createParams"></param>
        /// <returns></returns>
        public static ClusterCreateParametersExtended PrepareClusterCreateParamsForADLSv2(
            this CommonTestFixture commonData,
            string storageAccountName,
            string storageResourceId,
            string msiResourceId,
            ClusterCreateParametersExtended createParams = null)
        {
            var  createParamsForADLSv2 = createParams ?? commonData.PrepareClusterCreateParams();
            bool isDefault             = !createParamsForADLSv2.Properties.StorageProfile.Storageaccounts.Any();

            createParamsForADLSv2.Properties.StorageProfile.Storageaccounts.Add(
                new HDInsightStorageAccount
            {
                Name          = storageAccountName + commonData.DfsEndpointSuffix,
                IsDefault     = isDefault,
                FileSystem    = commonData.ContainerName.ToLowerInvariant(),
                ResourceId    = storageResourceId,
                MsiResourceId = msiResourceId
            }
                );

            var identity = new ClusterIdentity
            {
                Type = ResourceIdentityType.UserAssigned,
                UserAssignedIdentities = new Dictionary <string, ClusterIdentityUserAssignedIdentitiesValue>
                {
                    { msiResourceId, new ClusterIdentityUserAssignedIdentitiesValue() }
                }
            };

            if (createParamsForADLSv2.Identity == null)
            {
                createParamsForADLSv2.Identity = identity;
            }
            else
            {
                // At this point, only user-assigned managed identity is supported by HDInsight.
                // So identity type is not checked.
                createParamsForADLSv2.Identity.UserAssignedIdentities.Union(identity.UserAssignedIdentities);
            }

            return(createParamsForADLSv2);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Create cluster create parameters for ADLS Gen1 relevant tests.
        /// </summary>
        /// <param name="commonData"></param>
        /// <param name="createParams">
        /// If provided, the method will update the given parameters;
        /// Otherwise, a new create parameters will be created.
        /// </param>
        /// <returns></returns>
        public static ClusterCreateParametersExtended PrepareClusterCreateParamsForADLSv1(this CommonTestFixture commonData, ClusterCreateParametersExtended createParams = null)
        {
            var    createParamsForADLSv1 = createParams ?? commonData.PrepareClusterCreateParams();
            var    configurations        = (Dictionary <string, Dictionary <string, string> >)createParamsForADLSv1.Properties.ClusterDefinition.Configurations;
            string clusterIdentity       = "clusterIdentity";
            var    clusterIdentityConfig = new Dictionary <string, string>()
            {
                { "clusterIdentity.applicationId", commonData.DataLakeClientId },
                { "clusterIdentity.certificate", commonData.CertContent },
                { "clusterIdentity.aadTenantId", "https://login.windows.net/" + commonData.TenantId },
                { "clusterIdentity.resourceUri", "https://datalake.azure.net/" },
                { "clusterIdentity.certificatePassword", commonData.CertPassword }
            };

            configurations.Add(clusterIdentity, clusterIdentityConfig);
            bool isDefault = !createParamsForADLSv1.Properties.StorageProfile.Storageaccounts.Any();

            if (isDefault)
            {
                string coreSite   = "core-site";
                var    coreConfig = new Dictionary <string, string>()
                {
                    { "fs.defaultFS", "adl://home" },
                    { "dfs.adls.home.hostname", commonData.DataLakeStoreAccountName + ".azuredatalakestore.net" },
                    { "dfs.adls.home.mountpoint", commonData.DataLakeStoreMountpoint }
                };

                configurations.Add(coreSite, coreConfig);
            }

            return(createParamsForADLSv1);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Create cluster create parameters for WASB relevant tests.
        /// </summary>
        /// <param name="commonData"></param>
        /// <param name="storageAccountName"></param>
        /// <param name="storageAccountKey"></param>
        /// <returns></returns>
        private static ClusterCreateParametersExtended PrepareClusterCreateParams(this CommonTestFixture commonData, string storageAccountName = null, string storageAccountKey = null)
        {
            var storageAccounts = new List <HDInsightStorageAccount>();

            if (storageAccountName != null)
            {
                storageAccounts.Add(
                    new HDInsightStorageAccount
                {
                    Name      = storageAccountName + commonData.BlobEndpointSuffix,
                    Key       = storageAccountKey,
                    Container = commonData.ContainerName.ToLowerInvariant(),
                    IsDefault = true
                }
                    );
            }

            return(new ClusterCreateParametersExtended
            {
                Location = commonData.Location,
                Properties = new ClusterCreateProperties
                {
                    ClusterVersion = "3.6",
                    OsType = OSType.Linux,
                    Tier = Tier.Standard,
                    ClusterDefinition = new ClusterDefinition
                    {
                        Kind = "Hadoop",
                        Configurations = new Dictionary <string, Dictionary <string, string> >()
                        {
                            { "gateway", new Dictionary <string, string>
                              {
                                  { "restAuthCredential.isEnabled", "true" },
                                  { "restAuthCredential.username", commonData.ClusterUserName },
                                  { "restAuthCredential.password", commonData.ClusterPassword }
                              } }
                        }
                    },
                    ComputeProfile = new ComputeProfile
                    {
                        Roles = new List <Role>
                        {
                            new Role
                            {
                                Name = "headnode",
                                TargetInstanceCount = 2,
                                HardwareProfile = new HardwareProfile
                                {
                                    VmSize = "Large"
                                },
                                OsProfile = new OsProfile
                                {
                                    LinuxOperatingSystemProfile = new LinuxOperatingSystemProfile
                                    {
                                        Username = commonData.SshUsername,
                                        Password = commonData.SshPassword
                                    }
                                }
                            },
                            new Role
                            {
                                Name = "workernode",
                                TargetInstanceCount = 3,
                                HardwareProfile = new HardwareProfile
                                {
                                    VmSize = "Large"
                                },
                                OsProfile = new OsProfile
                                {
                                    LinuxOperatingSystemProfile = new LinuxOperatingSystemProfile
                                    {
                                        Username = commonData.SshUsername,
                                        Password = commonData.SshPassword
                                    }
                                }
                            },
                            new Role
                            {
                                Name = "zookeepernode",
                                TargetInstanceCount = 3,
                                HardwareProfile = new HardwareProfile
                                {
                                    VmSize = "Small"
                                },
                                OsProfile = new OsProfile
                                {
                                    LinuxOperatingSystemProfile = new LinuxOperatingSystemProfile
                                    {
                                        Username = commonData.SshUsername,
                                        Password = commonData.SshPassword
                                    }
                                }
                            }
                        }
                    },
                    StorageProfile = new StorageProfile
                    {
                        Storageaccounts = storageAccounts
                    }
                }
            });
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Create cluster create parameters for WASB relevant tests.
 /// </summary>
 /// <param name="commonData"></param>
 /// <returns></returns>
 public static ClusterCreateParametersExtended PrepareClusterCreateParamsForWasb(this CommonTestFixture commonData)
 {
     return(commonData.PrepareClusterCreateParams(commonData.StorageAccountName, commonData.StorageAccountKey));
 }