Beispiel #1
0
        public void Bug1771163TestGetComputeNode_RefreshComputeNode()
        {
            Action test = () =>
            {
                using (BatchClient batchCli = TestUtilities.OpenBatchClientAsync(TestUtilities.GetCredentialsFromEnvironment()).Result)
                {
                    PoolOperations poolOperations = batchCli.PoolOperations;

                    List <ComputeNode> computeNodeList = poolOperations.ListComputeNodes(this.poolFixture.PoolId).ToList();

                    ComputeNode computeNodeToGet = computeNodeList.First();
                    string      computeNodeId    = computeNodeToGet.Id;
                    //
                    // Get compute node via the manager
                    //

                    ComputeNode computeNodeFromManager = poolOperations.GetComputeNode(this.poolFixture.PoolId, computeNodeId);
                    CompareComputeNodeObjects(computeNodeToGet, computeNodeFromManager);

                    //
                    // Get compute node via the pool
                    //
                    CloudPool pool = poolOperations.GetPool(this.poolFixture.PoolId);

                    ComputeNode computeNodeFromPool = pool.GetComputeNode(computeNodeId);
                    CompareComputeNodeObjects(computeNodeToGet, computeNodeFromPool);
                    //
                    // Refresh compute node
                    //

                    //Refresh with a detail level
                    computeNodeToGet.Refresh(new ODATADetailLevel()
                    {
                        SelectClause = "affinityId,id"
                    });

                    //Confirm we have the reduced detail level
                    Assert.Equal(computeNodeToGet.AffinityId, computeNodeFromManager.AffinityId);
                    Assert.Null(computeNodeToGet.IPAddress);
                    Assert.Null(computeNodeToGet.LastBootTime);
                    Assert.Null(computeNodeToGet.State);
                    Assert.Null(computeNodeToGet.StartTaskInformation);

                    //Refresh again with increased detail level
                    computeNodeToGet.Refresh();
                    CompareComputeNodeObjects(computeNodeToGet, computeNodeFromManager);
                }
            };

            SynchronizationContextHelper.RunTest(test, TestTimeout);
        }
        /// <summary>
        /// Lists the pools matching the specified filter options.
        /// </summary>
        /// <param name="options">The options to use when querying for pools.</param>
        /// <returns>The pools matching the specified filter options.</returns>
        public IEnumerable <PSCloudPool> ListPools(ListPoolOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            // Get the single pool matching the specified id
            if (!string.IsNullOrWhiteSpace(options.PoolId))
            {
                WriteVerbose(string.Format(Resources.GetPoolById, options.PoolId));
                PoolOperations   poolOperations = options.Context.BatchOMClient.PoolOperations;
                ODATADetailLevel getDetailLevel = new ODATADetailLevel(selectClause: options.Select, expandClause: options.Expand);
                CloudPool        pool           = poolOperations.GetPool(options.PoolId, detailLevel: getDetailLevel, additionalBehaviors: options.AdditionalBehaviors);
                PSCloudPool      psPool         = new PSCloudPool(pool);
                return(new PSCloudPool[] { psPool });
            }
            // List pools using the specified filter
            else
            {
                string           verboseLogString = null;
                ODATADetailLevel listDetailLevel  = new ODATADetailLevel(selectClause: options.Select, expandClause: options.Expand);
                if (!string.IsNullOrEmpty(options.Filter))
                {
                    verboseLogString             = Resources.GetPoolByOData;
                    listDetailLevel.FilterClause = options.Filter;
                }
                else
                {
                    verboseLogString = Resources.GetPoolNoFilter;
                }
                WriteVerbose(verboseLogString);

                PoolOperations poolOperations                 = options.Context.BatchOMClient.PoolOperations;
                IPagedEnumerable <CloudPool>  pools           = poolOperations.ListPools(listDetailLevel, options.AdditionalBehaviors);
                Func <CloudPool, PSCloudPool> mappingFunction = p => { return(new PSCloudPool(p)); };
                return(PSPagedEnumerable <PSCloudPool, CloudPool> .CreateWithMaxCount(
                           pools, mappingFunction, options.MaxCount, () => WriteVerbose(string.Format(Resources.MaxCount, options.MaxCount))));
            }
        }
        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);
        }