public void NewBatchPoolAutoScaleHandledProperlyTest()
        {
            BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();

            cmdlet.BatchContext = context;

            cmdlet.Id = "testPool";
            cmdlet.AutoScaleEvaluationInterval = TimeSpan.FromMinutes(15);
            cmdlet.AutoScaleFormula            = "$TargetDedicated=3";

            PoolAddParameter requestParameters = null;

            // Store the request parameters
            RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor <
                PoolAddParameter,
                PoolAddOptions,
                AzureOperationHeaderResponse <PoolAddHeaders> >(requestAction: (r) =>
            {
                requestParameters = r.Parameters;
            });

            cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>()
            {
                interceptor
            };
            commandRuntimeMock.Setup(cr => cr.ShouldProcess(It.IsAny <string>())).Returns(true);
            cmdlet.ExecuteCmdlet();

            // Verify the request parameters match the cmdlet parameters
            Assert.Equal(cmdlet.AutoScaleEvaluationInterval, requestParameters.AutoScaleEvaluationInterval);
            Assert.Equal(cmdlet.AutoScaleFormula, requestParameters.AutoScaleFormula);
            Assert.True(requestParameters.EnableAutoScale);
            Assert.Null(requestParameters.TargetDedicatedNodes);
        }
Exemple #2
0
        public void CanPatchPoolByDeletingAppPkgRefs()
        {
            var poolId = Guid.NewGuid().ToString();
            var client = new BatchServiceClient(new Uri(Url), new BatchSharedKeyCredential(AccountName, AccountKey));

            var poolAddParameter = new PoolAddParameter(poolId, "small", "4");

            poolAddParameter.ApplicationPackageReferences = new[]
            {
                new ApplicationPackageReference {
                    ApplicationId = AppPackageIdOne, Version = "1.0"
                },
                new ApplicationPackageReference {
                    ApplicationId = AppPackageIdTwo
                },
            };

            try
            {
                client.Pool.AddAsync(poolAddParameter).Wait();

                var patchParams = new PoolPatchParameter();
                patchParams.ApplicationPackageReferences = new ApplicationPackageReference[] { };
                var updateResponse = client.Pool.PatchWithHttpMessagesAsync(poolId, patchParams).Result;
                Assert.Equal(HttpStatusCode.OK, updateResponse.Response.StatusCode);

                var pool = client.Pool.GetAsync(poolId).Result;
                Assert.Equal(poolId, pool.Id);
                Assert.Null(pool.ApplicationPackageReferences);
            }
            finally
            {
                TestUtilities.DeletePoolIfExistsNoThrow(client, poolId, output);
            }
        }
Exemple #3
0
        public void CanCreatePoolAndRetrieveAppPkgRefs()
        {
            var poolId = Guid.NewGuid().ToString();
            var client = new BatchServiceClient(new Uri(Url), new BatchSharedKeyCredential(AccountName, AccountKey));

            var poolAddParameter = new PoolAddParameter(poolId, "small", "4");

            poolAddParameter.ApplicationPackageReferences = new[]
            {
                new ApplicationPackageReference {
                    ApplicationId = AppPackageIdOne, Version = "1.0"
                },
                new ApplicationPackageReference {
                    ApplicationId = AppPackageIdTwo
                },
            };

            try
            {
                var addResponse = client.Pool.AddAsync(poolAddParameter).Result;

                var pool = client.Pool.GetAsync(poolId).Result;
                Assert.Equal(poolId, pool.Id);
                Assert.Equal(2, pool.ApplicationPackageReferences.Count);
                Assert.Equal(AppPackageIdOne, pool.ApplicationPackageReferences[0].ApplicationId);
                Assert.Equal("1.0", pool.ApplicationPackageReferences[0].Version);
                Assert.Equal(AppPackageIdTwo, pool.ApplicationPackageReferences[1].ApplicationId);
                Assert.Null(pool.ApplicationPackageReferences[1].Version);
            }
            finally
            {
                TestUtilities.DeletePoolIfExistsNoThrow(client, poolId, output);
            }
        }
Exemple #4
0
        public void CanCreatePoolWithTwoAppPkgRefAndVersion()
        {
            var poolId = Guid.NewGuid().ToString();
            var client = new BatchServiceClient(new Uri(Url), new BatchSharedKeyCredential(AccountName, AccountKey));

            var poolAddParameter = new PoolAddParameter(poolId, "small", "4");

            poolAddParameter.ApplicationPackageReferences = new[]
            {
                new ApplicationPackageReference {
                    ApplicationId = AppPackageIdOne, Version = "1.0"
                },
                new ApplicationPackageReference {
                    ApplicationId = AppPackageIdTwo
                },
            };

            try
            {
                var response = client.Pool.AddWithHttpMessagesAsync(poolAddParameter).Result;
                Assert.Equal(HttpStatusCode.Created, response.Response.StatusCode);
            }
            finally
            {
                TestUtilities.DeletePoolIfExistsNoThrow(client, poolId, output);
            }
        }
Exemple #5
0
        public void MultipleAppPackageReferenceWithNoDefaultFails()
        {
            string poolId = Guid.NewGuid().ToString();
            var    client = new BatchServiceClient(new Uri(Url), new BatchSharedKeyCredential(AccountName, AccountKey));

            var poolAddParameter = new PoolAddParameter(poolId, "small", "4");

            poolAddParameter.ApplicationPackageReferences = new[]
            {
                new ApplicationPackageReference {
                    ApplicationId = AppPackageIdOne
                },                                                                   // valid pkg, but has no default set
                new ApplicationPackageReference {
                    ApplicationId = AppPackageIdTwo
                }
            };

            var exception      = Assert.Throws <AggregateException>(() => client.Pool.AddAsync(poolAddParameter).Result);
            var batchException = (BatchErrorException)exception.InnerException;

            Assert.NotNull(batchException);
            Assert.Equal("InvalidApplicationPackageReferences", batchException.Body.Code);
            Assert.Equal(1, batchException.Body.Values.Count);
            Assert.Equal(AppPackageIdOne, batchException.Body.Values[0].Key);
            Assert.Equal("The specified application package does not have a default version set.", batchException.Body.Values[0].Value);
        }
        public void NewBatchPoolUserAccountsGetPassedToRequest()
        {
            BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();

            cmdlet.BatchContext = context;

            cmdlet.Id = "testPool";
            cmdlet.CloudServiceConfiguration   = new PSCloudServiceConfiguration("4", "*");
            cmdlet.TargetDedicatedComputeNodes = 3;

            PSUserAccount adminUser    = new PSUserAccount("admin", "password1", Azure.Batch.Common.ElevationLevel.Admin);
            PSUserAccount nonAdminUser = new PSUserAccount("user2", "password2", Azure.Batch.Common.ElevationLevel.NonAdmin);
            PSUserAccount sshUser      = new PSUserAccount("user3", "password3", linuxUserConfiguration: new PSLinuxUserConfiguration(uid: 1, gid: 2, sshPrivateKey: "my ssh key"));

            cmdlet.UserAccount = new [] { adminUser, nonAdminUser, sshUser };

            PoolAddParameter requestParameters = null;

            // Store the request parameters
            RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor <
                PoolAddParameter,
                PoolAddOptions,
                AzureOperationHeaderResponse <PoolAddHeaders> >(requestAction: (r) =>
            {
                requestParameters = r.Parameters;
            });

            cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>()
            {
                interceptor
            };
            commandRuntimeMock.Setup(cr => cr.ShouldProcess(It.IsAny <string>())).Returns(true);
            cmdlet.ExecuteCmdlet();

            // Verify the request parameters match the cmdlet parameters
            Assert.Equal(3, requestParameters.UserAccounts.Count);
            Assert.Equal(adminUser.Name, requestParameters.UserAccounts[0].Name);
            Assert.Equal(adminUser.Password, requestParameters.UserAccounts[0].Password);
            Assert.Equal(adminUser.ElevationLevel.ToString().ToLowerInvariant(),
                         requestParameters.UserAccounts[0].ElevationLevel.ToString().ToLowerInvariant());
            Assert.Equal(nonAdminUser.Name, requestParameters.UserAccounts[1].Name);
            Assert.Equal(nonAdminUser.Password, requestParameters.UserAccounts[1].Password);
            Assert.Equal(nonAdminUser.ElevationLevel.ToString().ToLowerInvariant(),
                         requestParameters.UserAccounts[1].ElevationLevel.ToString().ToLowerInvariant());
            Assert.Equal(sshUser.Name, requestParameters.UserAccounts[2].Name);
            Assert.Equal(sshUser.Password, requestParameters.UserAccounts[2].Password);
            Assert.Equal(sshUser.ElevationLevel.ToString().ToLowerInvariant(),
                         requestParameters.UserAccounts[2].ElevationLevel.ToString().ToLowerInvariant());
            Assert.Equal(sshUser.LinuxUserConfiguration.Uid, requestParameters.UserAccounts[2].LinuxUserConfiguration.Uid);
            Assert.Equal(sshUser.LinuxUserConfiguration.Gid, requestParameters.UserAccounts[2].LinuxUserConfiguration.Gid);
            Assert.Equal(sshUser.LinuxUserConfiguration.SshPrivateKey, requestParameters.UserAccounts[2].LinuxUserConfiguration.SshPrivateKey);
        }
Exemple #7
0
        public void BadAppPackageReferenceAndVersionFails()
        {
            var poolId = Guid.NewGuid().ToString();
            var client = new BatchServiceClient(new Uri(Url), new BatchSharedKeyCredential(AccountName, AccountKey));

            var poolAddParameter = new PoolAddParameter(poolId, "small", "4");

            poolAddParameter.ApplicationPackageReferences = new[] { new ApplicationPackageReference {
                                                                        ApplicationId = "bad", Version = "999"
                                                                    } };
            var exception = Assert.Throws <AggregateException>(() => client.Pool.AddAsync(poolAddParameter).Result);

            var batchException = (BatchErrorException)exception.InnerException;

            Assert.NotNull(batchException);
            Assert.Equal("InvalidApplicationPackageReferences", batchException.Body.Code);
            Assert.Equal(1, batchException.Body.Values.Count());
            Assert.Equal("bad:999", batchException.Body.Values[0].Key);
            Assert.Equal("The specified application package does not exist.", batchException.Body.Values[0].Value);
        }
Exemple #8
0
        public void CanUpdatePoolByAddingAppPkgRefs()
        {
            var poolId = Guid.NewGuid().ToString();
            var client = new BatchServiceClient(new Uri(Url), new BatchSharedKeyCredential(AccountName, AccountKey));

            var poolAddParameter = new PoolAddParameter(poolId, "small", "4");

            try
            {
                var addResponse = client.Pool.AddAsync(poolAddParameter).Result;

                var appRefs = new List <ApplicationPackageReference>
                {
                    new ApplicationPackageReference {
                        ApplicationId = AppPackageIdOne, Version = "1.0"
                    },
                    new ApplicationPackageReference {
                        ApplicationId = AppPackageIdTwo
                    },
                };

                var updateParams   = new PoolUpdatePropertiesParameter(new List <CertificateReference>(), appRefs, new List <MetadataItem>());
                var updateResponse = client.Pool.UpdatePropertiesWithHttpMessagesAsync(poolId, updateParams).Result;
                Assert.Equal(HttpStatusCode.NoContent, updateResponse.Response.StatusCode);

                var pool = client.Pool.GetAsync(poolId).Result;
                Assert.Equal(poolId, pool.Id);
                Assert.Equal(2, pool.ApplicationPackageReferences.Count);
                Assert.Equal(AppPackageIdOne, pool.ApplicationPackageReferences[0].ApplicationId);
                Assert.Equal("1.0", pool.ApplicationPackageReferences[0].Version);
                Assert.Equal(AppPackageIdTwo, pool.ApplicationPackageReferences[1].ApplicationId);
                Assert.Null(pool.ApplicationPackageReferences[1].Version);
            }
            finally
            {
                TestUtilities.DeletePoolIfExistsNoThrow(client, poolId, output);
            }
        }
        public void NewBatchPoolOSDiskGetsPassedToRequest()
        {
            BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();

            cmdlet.BatchContext = context;

            cmdlet.Id = "testPool";
            cmdlet.TargetDedicatedComputeNodes = 3;

            Azure.Batch.Common.CachingType cachingType = Azure.Batch.Common.CachingType.ReadWrite;
            cmdlet.VirtualMachineConfiguration =
                new PSVirtualMachineConfiguration(new PSImageReference("offer", "publisher", "sku"), "node agent")
            {
                OSDisk = new PSOSDisk(cachingType)
            };
            PoolAddParameter requestParameters = null;

            // Store the request parameters
            RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor <
                PoolAddParameter,
                PoolAddOptions,
                AzureOperationHeaderResponse <PoolAddHeaders> >(requestAction: (r) =>
            {
                requestParameters = r.Parameters;
            });

            cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>()
            {
                interceptor
            };
            commandRuntimeMock.Setup(cr => cr.ShouldProcess(It.IsAny <string>())).Returns(true);
            cmdlet.ExecuteCmdlet();

            // Verify the request parameters match the cmdlet parameters
            Assert.Equal(cachingType.ToString().ToLowerInvariant(),
                         requestParameters.VirtualMachineConfiguration.OsDisk.Caching.ToString().ToLowerInvariant());
        }
        public void NewBatchPoolParametersGetPassedToRequestTest()
        {
            BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();

            cmdlet.BatchContext = context;

            cmdlet.Id = "testPool";
            cmdlet.ApplicationLicenses = new List <string>()
            {
                "foo", "bar"
            };
            cmdlet.CertificateReferences = new PSCertificateReference[]
            {
                new PSCertificateReference()
                {
                    StoreLocation       = Azure.Batch.Common.CertStoreLocation.LocalMachine,
                    Thumbprint          = "thumbprint",
                    ThumbprintAlgorithm = "sha1",
                    StoreName           = "My",
                    Visibility          = Azure.Batch.Common.CertificateVisibility.StartTask
                }
            };
            cmdlet.CloudServiceConfiguration = new PSCloudServiceConfiguration("4", "*");
            cmdlet.DisplayName = "display name";
            cmdlet.InterComputeNodeCommunicationEnabled = true;
            cmdlet.MaxTasksPerComputeNode = 4;
            cmdlet.Metadata = new Dictionary <string, string>();
            cmdlet.Metadata.Add("meta1", "value1");
            cmdlet.ResizeTimeout = TimeSpan.FromMinutes(20);
            cmdlet.StartTask     = new PSStartTask("cmd /c echo start task");
            cmdlet.TargetDedicatedComputeNodes   = 3;
            cmdlet.TargetLowPriorityComputeNodes = 2;
            cmdlet.TaskSchedulingPolicy          = new PSTaskSchedulingPolicy(Azure.Batch.Common.ComputeNodeFillType.Spread);
            cmdlet.VirtualMachineConfiguration   = new PSVirtualMachineConfiguration(new PSImageReference("offer", "publisher", "sku"), "node agent");
            cmdlet.VirtualMachineSize            = "small";

            PoolAddParameter requestParameters = null;

            // Store the request parameters
            RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor <
                PoolAddParameter,
                PoolAddOptions,
                AzureOperationHeaderResponse <PoolAddHeaders> >(requestAction: (r) =>
            {
                requestParameters = r.Parameters;
            });

            cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>()
            {
                interceptor
            };
            commandRuntimeMock.Setup(cr => cr.ShouldProcess(It.IsAny <string>())).Returns(true);
            cmdlet.ExecuteCmdlet();

            // Verify the request parameters match the cmdlet parameters
            Assert.Equal(cmdlet.ApplicationLicenses[0], requestParameters.ApplicationLicenses[0]);
            Assert.Equal(cmdlet.ApplicationLicenses[1], requestParameters.ApplicationLicenses[1]);
            Assert.Equal(cmdlet.CertificateReferences.Length, requestParameters.CertificateReferences.Count);
            Assert.Equal(cmdlet.CertificateReferences[0].StoreName, requestParameters.CertificateReferences[0].StoreName);
            Assert.Equal(cmdlet.CertificateReferences[0].Thumbprint, requestParameters.CertificateReferences[0].Thumbprint);
            Assert.Equal(cmdlet.CertificateReferences[0].ThumbprintAlgorithm, requestParameters.CertificateReferences[0].ThumbprintAlgorithm);
            Assert.Equal(cmdlet.CloudServiceConfiguration.OSFamily, requestParameters.CloudServiceConfiguration.OsFamily);
            Assert.Equal(cmdlet.CloudServiceConfiguration.TargetOSVersion, requestParameters.CloudServiceConfiguration.TargetOSVersion);
            Assert.Equal(cmdlet.DisplayName, requestParameters.DisplayName);
            Assert.Equal(cmdlet.InterComputeNodeCommunicationEnabled, requestParameters.EnableInterNodeCommunication);
            Assert.Equal(cmdlet.MaxTasksPerComputeNode, requestParameters.MaxTasksPerNode);
            Assert.Equal(cmdlet.Metadata.Count, requestParameters.Metadata.Count);
            Assert.Equal(cmdlet.Metadata["meta1"], requestParameters.Metadata[0].Value);
            Assert.Equal(cmdlet.ResizeTimeout, requestParameters.ResizeTimeout);
            Assert.Equal(cmdlet.StartTask.CommandLine, requestParameters.StartTask.CommandLine);
            Assert.Equal(cmdlet.TargetDedicatedComputeNodes, requestParameters.TargetDedicatedNodes);
            Assert.Equal(cmdlet.TargetLowPriorityComputeNodes, requestParameters.TargetLowPriorityNodes);
            Assert.Equal(cmdlet.TaskSchedulingPolicy.ComputeNodeFillType.ToString(), requestParameters.TaskSchedulingPolicy.NodeFillType.ToString());
            Assert.Equal(cmdlet.VirtualMachineConfiguration.NodeAgentSkuId, requestParameters.VirtualMachineConfiguration.NodeAgentSKUId);
            Assert.Equal(cmdlet.VirtualMachineConfiguration.ImageReference.Publisher, requestParameters.VirtualMachineConfiguration.ImageReference.Publisher);
            Assert.Equal(cmdlet.VirtualMachineConfiguration.ImageReference.Offer, requestParameters.VirtualMachineConfiguration.ImageReference.Offer);
            Assert.Equal(cmdlet.VirtualMachineConfiguration.ImageReference.Sku, requestParameters.VirtualMachineConfiguration.ImageReference.Sku);
            Assert.Equal(cmdlet.VirtualMachineSize, requestParameters.VmSize);
        }
 public virtual Response Add(PoolAddParameter pool, PoolAddOptions poolAddOptions, CancellationToken cancellationToken = default)
 {
     return(RestClient.Add(pool, poolAddOptions, cancellationToken).GetRawResponse());
 }
 public virtual async Task <Response> AddAsync(PoolAddParameter pool, PoolAddOptions poolAddOptions, CancellationToken cancellationToken = default)
 {
     return((await RestClient.AddAsync(pool, poolAddOptions, cancellationToken).ConfigureAwait(false)).GetRawResponse());
 }
Exemple #13
0
 /// <summary>
 /// Adds a Pool to the specified Account.
 /// </summary>
 /// <remarks>
 /// When naming Pools, avoid including sensitive information such as user names
 /// or secret project names. This information may appear in telemetry logs
 /// accessible to Microsoft Support engineers.
 /// </remarks>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='pool'>
 /// The Pool to be added.
 /// </param>
 /// <param name='poolAddOptions'>
 /// Additional parameters for the operation
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <PoolAddHeaders> AddAsync(this IPoolOperations operations, PoolAddParameter pool, PoolAddOptions poolAddOptions = default(PoolAddOptions), CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.AddWithHttpMessagesAsync(pool, poolAddOptions, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Headers);
     }
 }
Exemple #14
0
 /// <summary>
 /// Adds a Pool to the specified Account.
 /// </summary>
 /// <remarks>
 /// When naming Pools, avoid including sensitive information such as user names
 /// or secret project names. This information may appear in telemetry logs
 /// accessible to Microsoft Support engineers.
 /// </remarks>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='pool'>
 /// The Pool to be added.
 /// </param>
 /// <param name='poolAddOptions'>
 /// Additional parameters for the operation
 /// </param>
 public static PoolAddHeaders Add(this IPoolOperations operations, PoolAddParameter pool, PoolAddOptions poolAddOptions = default(PoolAddOptions))
 {
     return(operations.AddAsync(pool, poolAddOptions).GetAwaiter().GetResult());
 }
 /// <summary>
 /// Adds a pool to the specified account.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='pool'>
 /// The pool to be added.
 /// </param>
 /// <param name='poolAddOptions'>
 /// Additional parameters for the operation
 /// </param>
 public static PoolAddHeaders Add(this IPoolOperations operations, PoolAddParameter pool, PoolAddOptions poolAddOptions = default(PoolAddOptions))
 {
     return(System.Threading.Tasks.Task.Factory.StartNew(s => ((IPoolOperations)s).AddAsync(pool, poolAddOptions), operations, System.Threading.CancellationToken.None, System.Threading.Tasks.TaskCreationOptions.None, System.Threading.Tasks.TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }