/// <summary> /// Creates a new pool. /// </summary> /// <param name="parameters">The parameters to use when creating the pool.</param> public void CreatePool(NewPoolParameters parameters) { if (parameters == null) { throw new ArgumentNullException("parameters"); } PoolOperations poolOperations = parameters.Context.BatchOMClient.PoolOperations; CloudPool pool = poolOperations.CreatePool(poolId: parameters.PoolId, osFamily: parameters.OSFamily, virtualMachineSize: parameters.VirtualMachineSize); pool.DisplayName = parameters.DisplayName; pool.ResizeTimeout = parameters.ResizeTimeout; pool.MaxTasksPerComputeNode = parameters.MaxTasksPerComputeNode; pool.InterComputeNodeCommunicationEnabled = parameters.InterComputeNodeCommunicationEnabled; if (!string.IsNullOrEmpty(parameters.AutoScaleFormula)) { pool.AutoScaleEnabled = true; pool.AutoScaleFormula = parameters.AutoScaleFormula; } else if (parameters.TargetDedicated.HasValue) { pool.TargetDedicated = parameters.TargetDedicated; } if (parameters.TaskSchedulingPolicy != null) { pool.TaskSchedulingPolicy = parameters.TaskSchedulingPolicy.omObject; } if (parameters.StartTask != null) { Utils.Utils.StartTaskSyncCollections(parameters.StartTask); pool.StartTask = parameters.StartTask.omObject; } if (parameters.Metadata != null) { pool.Metadata = new List <MetadataItem>(); foreach (DictionaryEntry m in parameters.Metadata) { pool.Metadata.Add(new MetadataItem(m.Key.ToString(), m.Value.ToString())); } } if (parameters.CertificateReferences != null) { pool.CertificateReferences = new List <CertificateReference>(); foreach (PSCertificateReference c in parameters.CertificateReferences) { pool.CertificateReferences.Add(c.omObject); } } WriteVerbose(string.Format(Resources.CreatingPool, parameters.PoolId)); pool.Commit(parameters.AdditionalBehaviors); }
private static async Task TestPoolCreateAndUpdateWithCertificateReferencesAsync( BatchClient batchCli, IList <CertificateReference> certificateReferences) { PoolOperations poolOperations = batchCli.PoolOperations; string poolId = "CreateAndUpdateWithCertificateReferences-" + TestUtilities.GetMyName(); try { // create a pool with initial cert refs CloudPool boundPool; { CloudPool unboundPool = poolOperations.CreatePool( poolId: poolId, virtualMachineSize: PoolFixture.VMSize, cloudServiceConfiguration: new CloudServiceConfiguration(PoolFixture.OSFamily), targetDedicatedComputeNodes: 0); // create the pool with initial cert refs unboundPool.CertificateReferences = certificateReferences; await unboundPool.CommitAsync().ConfigureAwait(false); boundPool = await poolOperations.GetPoolAsync(poolId).ConfigureAwait(false); // confirm the refs are there Assert.NotNull(boundPool.CertificateReferences); AssertCertificateReferenceCollectionsAreSame(certificateReferences, boundPool.CertificateReferences); } // mutate the cert refs: assign only one { List <CertificateReference> listOfOne = new List <CertificateReference>(); // just pick one cert listOfOne.Add(certificateReferences.ToArray()[1]); boundPool.CertificateReferences = listOfOne; await boundPool.CommitAsync().ConfigureAwait(false); await boundPool.RefreshAsync().ConfigureAwait(false); // confirm that the ref collection is correct AssertCertificateReferenceCollectionsAreSame(listOfOne, boundPool.CertificateReferences); } // mutate the pool cert refs: assign null to clear { boundPool.CertificateReferences = null; await boundPool.CommitAsync().ConfigureAwait(false); await boundPool.RefreshAsync().ConfigureAwait(false); Assert.Empty(boundPool.CertificateReferences); } } finally { // cleanup TestUtilities.DeletePoolIfExistsAsync(batchCli, poolId).Wait(); } }
public void Bug1965363_2384616_Wat7OSVersionFeatures() { Action test = () => { using (BatchClient batchCli = TestUtilities.OpenBatchClientAsync(TestUtilities.GetCredentialsFromEnvironment()).Result) { PoolOperations poolOperations = batchCli.PoolOperations; try { this.testOutputHelper.WriteLine("Listing OS Versions:"); /* bug 2384616 ListOsVersions hidden for wat 8 * * // test ListOSVersion * foreach (OSVersion curOSV in poolMgr.ListOSVersions()) * { * this.testOutputHelper.WriteLine("Label: " + curOSV.Label); * this.testOutputHelper.WriteLine(" Version: " + curOSV.Version); * this.testOutputHelper.WriteLine(" Family: " + curOSV.Family); * this.testOutputHelper.WriteLine(" FamilyLabel: " + curOSV.FamilyLabel); * this.testOutputHelper.WriteLine(" isDefault: " + curOSV.IsDefault); * this.testOutputHelper.WriteLine(" IsActive: " + curOSV.IsActive); * * string expDate; * * if (curOSV.ExpirationDate.HasValue) * { * expDate = curOSV.ExpirationDate.Value.ToString(); * } * else * { * expDate = "<null/novalue>"; * } * * this.testOutputHelper.WriteLine(" ExpirationDate: " + expDate); * } * */ // create pool tests // forget to set CloudServiceConfiguration on Create, get error { CloudPool noArgs = poolOperations.CreatePool("Bug1965363ButNoOSFamily-" + TestUtilities.GetMyName(), PoolFixture.VMSize, default(CloudServiceConfiguration), targetDedicated: 0); BatchException ex = TestUtilities.AssertThrows <BatchException>(() => noArgs.Commit()); string exStr = ex.ToString(); // we are expecting an exception, assert if the exception is not the correct one. Assert.Contains("cloudServiceConfiguration", exStr); } // create a pool WITH an osFamily { string poolIdHOSF = "Bug1965363HasOSF-" + TestUtilities.GetMyName(); try { CloudPool hasOSF = poolOperations.CreatePool(poolIdHOSF, PoolFixture.VMSize, new CloudServiceConfiguration(PoolFixture.OSFamily), targetDedicated: 0); hasOSF.Commit(); } finally { poolOperations.DeletePool(poolIdHOSF); } } // TODO: ultimately we will either need to find (via list) a family with more than one version or // manually update these strings as OS versions are depricated //See here for other OS versions if this test fails: http://azure.microsoft.com/en-us/documentation/articles/cloud-services-guestos-update-matrix/ const string familyVersion0 = "*"; const string familyVersion1 = "WA-GUEST-OS-4.32_201605-01"; // "UpdatePoolOS" tests (ChangeOSVersion in OM) // PoolManager { string poolIdChangeOSV = "Bug1965363ChangeOSVviaMGR-" + TestUtilities.GetMyName(); try { CloudPool unboundPool = poolOperations.CreatePool( poolIdChangeOSV, PoolFixture.VMSize, new CloudServiceConfiguration(PoolFixture.OSFamily, familyVersion0), // start with version 0 targetDedicated: 0); unboundPool.Commit(); // fetch the bound pool CloudPool boundPool = poolOperations.GetPool(poolIdChangeOSV); Assert.Equal(familyVersion0, boundPool.CloudServiceConfiguration.CurrentOSVersion); // switch to new version poolOperations.ChangeOSVersion(poolIdChangeOSV, familyVersion1); // UpdatePoolOS is has latency??? PollForOSVersionChange(boundPool, familyVersion1); // check to make sure the new value is set boundPool.Refresh(); Assert.Equal(familyVersion1, boundPool.CloudServiceConfiguration.CurrentOSVersion); } finally { TestUtilities.DeletePoolIfExistsAsync(batchCli, poolIdChangeOSV).Wait(); } } // ICloudPool { string poolIdChangeOSV = "Bug1965363ChangeOSVviaPool-" + TestUtilities.GetMyName(); try { CloudPool unboundPool = poolOperations.CreatePool( poolIdChangeOSV, PoolFixture.VMSize, new CloudServiceConfiguration(PoolFixture.OSFamily, familyVersion0), // start with version 0 targetDedicated: 0); unboundPool.Commit(); // fetch the bound pool CloudPool boundPool = poolOperations.GetPool(poolIdChangeOSV); Assert.Equal(familyVersion0, boundPool.CloudServiceConfiguration.CurrentOSVersion); // switch to new version boundPool.ChangeOSVersion(familyVersion1); // UpdatePoolOS is has latency??? PollForOSVersionChange(boundPool, familyVersion1); // check to make sure the new value is set boundPool.Refresh(); Assert.Equal(familyVersion1, boundPool.CloudServiceConfiguration.CurrentOSVersion); } finally { TestUtilities.DeletePoolIfExistsAsync(batchCli, poolIdChangeOSV).Wait(); } } // autopoolspec tests { string jobId = "Bug1965363WIName-" + TestUtilities.GetMyName(); // test not setting osversion try { CloudJob unboundJob = batchCli.JobOperations.CreateJob(jobId, new PoolInformation()); AutoPoolSpecification aps = new AutoPoolSpecification(); PoolSpecification ps = new PoolSpecification(); // test unbound set constraint ps.CloudServiceConfiguration = new CloudServiceConfiguration(PoolFixture.OSFamily); // test unbound get constraint this.testOutputHelper.WriteLine("pus.CloudServiceConfiguration.OSFamily == " + ps.CloudServiceConfiguration.OSFamily); ps.VirtualMachineSize = PoolFixture.VMSize; ps.TargetDedicated = 0; // trivial size for testing purposes aps.PoolSpecification = ps; aps.PoolLifetimeOption = PoolLifetimeOption.Job; unboundJob.PoolInformation.AutoPoolSpecification = aps; // commit to test validation unboundJob.Commit(); // get bound job CloudJob boundJob = batchCli.JobOperations.GetJob(jobId); // test bound get constraints this.testOutputHelper.WriteLine(" OSFamily == " + boundJob.PoolInformation.AutoPoolSpecification.PoolSpecification.CloudServiceConfiguration.OSFamily); string targetOSVersion = boundJob.PoolInformation.AutoPoolSpecification.PoolSpecification.CloudServiceConfiguration.TargetOSVersion; if (string.IsNullOrEmpty(targetOSVersion)) { targetOSVersion = "<null or empty"; } this.testOutputHelper.WriteLine(" TargetOSVersion == " + targetOSVersion); } finally { // cleanup TestUtilities.DeleteJobIfExistsAsync(batchCli, jobId).Wait(); } { string jobScheduleId = "Bug1965363WINameSettingAndChanging-" + TestUtilities.GetMyName(); // test setting osversion try { AutoPoolSpecification aps = new AutoPoolSpecification(); PoolSpecification ps = new PoolSpecification(); CloudJobSchedule unboundJobSchedule = batchCli.JobScheduleOperations.CreateJobSchedule( jobScheduleId, new Schedule() { RecurrenceInterval = TimeSpan.FromDays(7) }, new JobSpecification(new PoolInformation() { AutoPoolSpecification = aps })); // test unbound set constraint ps.CloudServiceConfiguration = new CloudServiceConfiguration(PoolFixture.OSFamily, familyVersion0); // test unbound get constraint this.testOutputHelper.WriteLine("pus.CloudServiceConfiguration.OSFamily == " + ps.CloudServiceConfiguration.OSFamily); this.testOutputHelper.WriteLine("pus.CloudServiceConfiguration.TargetOSVersion == " + ps.CloudServiceConfiguration.TargetOSVersion); ps.VirtualMachineSize = PoolFixture.VMSize; ps.TargetDedicated = 0; // trivial size for testing purposes aps.PoolSpecification = ps; aps.PoolLifetimeOption = PoolLifetimeOption.Job; unboundJobSchedule.Commit(); // get bound job schedule CloudJobSchedule boundJobSchedule = batchCli.JobScheduleOperations.GetJobSchedule(jobScheduleId); // test bound get constraints this.testOutputHelper.WriteLine(" OSFamily == " + boundJobSchedule.JobSpecification.PoolInformation.AutoPoolSpecification.PoolSpecification.CloudServiceConfiguration.OSFamily); this.testOutputHelper.WriteLine(" TargetOSVersion == " + boundJobSchedule.JobSpecification.PoolInformation.AutoPoolSpecification.PoolSpecification.CloudServiceConfiguration.TargetOSVersion); // assert the value is as set above Assert.Equal(familyVersion0, boundJobSchedule.JobSpecification.PoolInformation.AutoPoolSpecification.PoolSpecification.CloudServiceConfiguration.TargetOSVersion); // change values const string altFamily = "3"; const string altOSVersion = "WA-GUEST-OS-3.39_201605-01"; // change values on the bound PUS PoolSpecification boundPS = boundJobSchedule.JobSpecification.PoolInformation.AutoPoolSpecification.PoolSpecification; boundPS.CloudServiceConfiguration = new CloudServiceConfiguration(altFamily, altOSVersion); // flush changes boundJobSchedule.Commit(); // confirm changes took boundJobSchedule.Refresh(); Assert.Equal(altFamily, boundJobSchedule.JobSpecification.PoolInformation.AutoPoolSpecification.PoolSpecification.CloudServiceConfiguration.OSFamily); Assert.Equal(altOSVersion, boundJobSchedule.JobSpecification.PoolInformation.AutoPoolSpecification.PoolSpecification.CloudServiceConfiguration.TargetOSVersion); } finally { // cleanup TestUtilities.DeleteJobScheduleIfExistsAsync(batchCli, jobScheduleId).Wait(); } } } } catch (Exception ex) { // special case os version beacuse it is a common failure and requires human intervention/editing // test for expired os version Assert.DoesNotContain("The specified OS Version does not exists", ex.ToString()); throw; } } }; SynchronizationContextHelper.RunTest(test, TestTimeout); }
/// <summary> /// Creates a new pool. /// </summary> /// <param name="parameters">The parameters to use when creating the pool.</param> public void CreatePool(NewPoolParameters parameters) { if (parameters == null) { throw new ArgumentNullException("parameters"); } PoolOperations poolOperations = parameters.Context.BatchOMClient.PoolOperations; CloudPool pool = poolOperations.CreatePool(); pool.Id = parameters.PoolId; pool.VirtualMachineSize = parameters.VirtualMachineSize; pool.DisplayName = parameters.DisplayName; pool.ResizeTimeout = parameters.ResizeTimeout; pool.MaxTasksPerComputeNode = parameters.MaxTasksPerComputeNode; pool.InterComputeNodeCommunicationEnabled = parameters.InterComputeNodeCommunicationEnabled; if (!string.IsNullOrEmpty(parameters.AutoScaleFormula)) { pool.AutoScaleEnabled = true; pool.AutoScaleEvaluationInterval = parameters.AutoScaleEvaluationInterval; pool.AutoScaleFormula = parameters.AutoScaleFormula; } else if (parameters.TargetDedicatedComputeNodes.HasValue || parameters.TargetLowPriorityComputeNodes.HasValue) { pool.TargetDedicatedComputeNodes = parameters.TargetDedicatedComputeNodes; pool.TargetLowPriorityComputeNodes = parameters.TargetLowPriorityComputeNodes; } if (parameters.TaskSchedulingPolicy != null) { pool.TaskSchedulingPolicy = parameters.TaskSchedulingPolicy.omObject; } if (parameters.StartTask != null) { Utils.Utils.StartTaskSyncCollections(parameters.StartTask); pool.StartTask = parameters.StartTask.omObject; } if (parameters.Metadata != null) { pool.Metadata = new List <MetadataItem>(); foreach (DictionaryEntry m in parameters.Metadata) { pool.Metadata.Add(new MetadataItem(m.Key.ToString(), m.Value.ToString())); } } if (parameters.CertificateReferences != null) { pool.CertificateReferences = new List <CertificateReference>(); foreach (PSCertificateReference c in parameters.CertificateReferences) { pool.CertificateReferences.Add(c.omObject); } } if (parameters.ApplicationPackageReferences != null) { pool.ApplicationPackageReferences = parameters.ApplicationPackageReferences.ToList().ConvertAll(apr => apr.omObject); } if (parameters.CloudServiceConfiguration != null) { pool.CloudServiceConfiguration = parameters.CloudServiceConfiguration.omObject; } if (parameters.VirtualMachineConfiguration != null) { Utils.Utils.VirtualMachineConfigurationSyncCollections(parameters.VirtualMachineConfiguration); pool.VirtualMachineConfiguration = parameters.VirtualMachineConfiguration.omObject; } if (parameters.NetworkConfiguration != null) { pool.NetworkConfiguration = parameters.NetworkConfiguration.omObject; } if (parameters.MountConfiguration != null) { pool.MountConfiguration = new List <MountConfiguration>(); foreach (PSMountConfiguration m in parameters.MountConfiguration) { pool.MountConfiguration.Add(m.omObject); } } if (parameters.UserAccounts != null) { pool.UserAccounts = parameters.UserAccounts.ToList().ConvertAll(user => user.omObject); } if (parameters.ApplicationLicenses != null) { pool.ApplicationLicenses = parameters.ApplicationLicenses; } WriteVerbose(string.Format(Resources.CreatingPool, parameters.PoolId)); pool.Commit(parameters.AdditionalBehaviors); }