/// <summary> kicks off batch specified. </summary>
        /// <param name="batch"> A Test batch objectame of batch file to load and run. </param>
        /// <param name="chassisManagerEndPoint"> Chassis Manager endpoint uri. </param>
        /// <param name="globalParameters"> Global Parameters. </param>
        public void RunFrameworkBatch(TestBatch batch, string chassisManagerEndPoint, Parameters globalParameters, string userName, string userPassword)
        {
            var batchResults = new ResultOfTestBatch(batch.Name, chassisManagerEndPoint);

            try
            {
                batch.Run(globalParameters, batchResults, userName, userPassword);
            }
            catch (OperationCanceledException)
            {
                Console.WriteLine("\n********** Batch has Ended.\n");
            }
            finally
            {
                batchResults.Save();
            }
        }
コード例 #2
0
ファイル: Parameters.cs プロジェクト: silupher/ChassisManager
        /// <summary> Clones the Parameters values. </summary>
        /// <returns>An object of type Parameters</returns>
        public object Clone()
        {
            var clone = new Parameters();
            if (this.parameters.Any())
            {
                this.parameters.ToList().ForEach(p => clone[p.Key] = new List<string>(p.Value));
            }

            return clone;
        }
コード例 #3
0
ファイル: Parameters.cs プロジェクト: silupher/ChassisManager
 /// <summary> Gets global parameters through discovery, well known or preconfigured values. </summary>
 /// <returns>A Parameters object having all values to be used for testing. </returns>
 public static Parameters GetSampleParameters()
 {
     var sampleParameters = new Parameters();
     sampleParameters["portNo"] = new List<string>() { "1", "2", "3" };
     sampleParameters["bladeId"] = new List<string>()
     {
         "1", "2", "3", "4", "5", "6", "7", "8", "9",
         "10", "11", "13", "14", "15", "16", "17", "18",
         "19", "20", "21", "22", "23", "24"
     };
     sampleParameters["powerLimitInWatts"] = new List<string>() { "200", "500", "900" };
     sampleParameters["offTime"] = new List<string>() { "10", "15", "61" };
     sampleParameters["bladeInfo"] = new List<string>() { "true", "false" };
     sampleParameters["startTimestamp"] = new List<string>() { System.DateTime.Now.AddHours(-2).ToString() };
     sampleParameters["endTimestamp"] = new List<string>() { System.DateTime.MaxValue.ToString() };
     sampleParameters["userName"] = new List<string>() { "testUser" };
     sampleParameters["role"] = new List<string>() { "wcsCMAdmin", "wcsCMOperator", "wcsCMUser" };
     sampleParameters["newPassword"] = new List<string>() { "NewP7890wd^" };
     sampleParameters["passwordString"] = new List<string>() { "pa$$1234Pwd!" };
     sampleParameters["psuInfo"] = new List<string>() { "true", "false" };
     sampleParameters["bladeHealth"] = new List<string>() { "true", "false" };
     sampleParameters["psuHealth"] = new List<string>() { "true", "false" };
     sampleParameters["fanHealth"] = new List<string>() { "true", "false" };
     sampleParameters["batteryHealth"] = new List<string>() { "true", "false" };
     sampleParameters["batteryInfo"] = new List<string>() { "true", "false" };
     sampleParameters["cpuInfo"] = new List<string>() { "true", "false" };
     sampleParameters["memInfo"] = new List<string>() { "true", "false" };
     sampleParameters["diskInfo"] = new List<string>() { "true", "false" };
     sampleParameters["pcieInfo"] = new List<string>() { "true", "false" };
     sampleParameters["sensorInfo"] = new List<string>() { "true", "false" };
     sampleParameters["temp"] = new List<string>() { "true", "false" };
     sampleParameters["fruInfo"] = new List<string>() { "true", "false" };
     sampleParameters["chassisControllerInfo"] = new List<string>() { "true", "false" };
     sampleParameters["bootType"] = new List<string>() { "NoOverride", "ForcePxe", "ForceDefaultHdd", "ForceIntoBiosSetup", "ForceFloppyOrRemovable" };
     sampleParameters["uefi"] = new List<string>() { "true", "false" };
     sampleParameters["persistent"] = new List<string>() { "true", "false" };
     sampleParameters["bootInstance"] = new List<string>() { "0" };
     sampleParameters["sessionTimeoutInSecs"] = new List<string> { "30", "120", "300" };
     sampleParameters["powerOnWait"] = new List<string> { "true", "false" };
     sampleParameters["sessionToken"] = new List<string> { "1234567891234567" };
     sampleParameters["forceKill"] = new List<string> { "true" };
     return sampleParameters;
 }
        /// <summary> Runs all tests. </summary>
        /// <param name="globalParameters"> Global Parameters. </param>
        /// <param name="batchResults"> Results of batch. </param>
        /// <returns> Result of Test Batch. </returns>
        public void Run(Parameters globalParameters, ResultOfTestBatch batchResults, string userName, string userPassword)
        {
            if (this.GlobalParameters == null)
            {
                this.GlobalParameters = globalParameters;
            }

            var cts = new CancellationTokenSource();
            var parallelOptions = new ParallelOptions()
            {
                MaxDegreeOfParallelism = (int)this.MaximumParallelThreads,
                CancellationToken = cts.Token
            };

            var includedApis = this.TestSequences.SelectMany(ts => ts.Tests).Select(test => test.Name).Distinct();
            var implementedApis = Helper.GetChassisManagerApiList();
            batchResults.ExcludedApis = implementedApis.Where(api => !includedApis.Contains(api));
            batchResults.NonExistingApis = includedApis.Where(api => !implementedApis.Contains(api));
            batchResults.BatchStartTime = DateTime.UtcNow;
            batchResults.BatchState = TestRunState.Running;
            batchResults.Save();

            var keepLooping = false;
            Timer loopingtimer;
            if (this.Duration.HasValue)
            {
                keepLooping = true;
                loopingtimer = new Timer(this.Duration.Value.TotalMilliseconds);
                loopingtimer.Elapsed += delegate(object sender, ElapsedEventArgs args)
                {
                    keepLooping = false;
                    Console.WriteLine("Batch time expired, Ending Batch.");
                    cts.Cancel();
                };

                loopingtimer.Start();
            }

            Timer saveTimer = null;
            if (this.SaveResultFrequency.HasValue)
            {
                saveTimer = new Timer(this.SaveResultFrequency.Value.TotalMilliseconds);
                saveTimer.Elapsed += delegate(object sender, ElapsedEventArgs args)
                {
                    batchResults.Save();
                };

                saveTimer.Start();
            }

            //// Set credentials to run under for each sequence.
            //Parallel.ForEach(this.TestSequences,
            //        ts =>
            //            {
            //                ts.RunAsUserCredentials = new List<UserCredential>();
            //                if (this.UserCredentials != null && !string.IsNullOrWhiteSpace(ts.RunAsRoles))
            //                {
            //                    var runAsUsers = ts.RunAsRoles.Split(',');
            //                    if (runAsUsers.Contains("*"))
            //                    {
            //                        ts.RunAsUserCredentials.AddRange(this.UserCredentials);
            //                    }
            //                    else
            //                    {
            //                        ts.RunAsUserCredentials.AddRange(this.UserCredentials.Where(
            //                            crd => runAsUsers.Contains(crd.Role, StringComparer.InvariantCultureIgnoreCase)));
            //                    }
            //                }

            //                if (!ts.RunAsUserCredentials.Any())
            //                {
            //                    ts.RunAsUserCredentials.Add(null); // Force use of default credentials if none specified;
            //                }
            //            });

            do
            {
                var sequencesToRun = this.TestSequences.ToList();
                if (this.ShuffleSequences.HasValue && this.ShuffleSequences.Value)
                {
                    sequencesToRun.Shuffle();
                }

                var loopResult = Parallel.ForEach(
                    sequencesToRun,
                    parallelOptions,
                    ts =>
                    {
                        var tsResults = ts.Run(
                            batchResults.ChassisManagerEndPoint,
                            this.GlobalParameters,
                            this.ApiSla,
                            userName,
                            userPassword);
                        lock (batchResults.TestResults)
                        {
                            batchResults.TestResults.AddRange(tsResults);
                        }

                        batchResults.Save();
                    });

                batchResults.BatchState = loopResult.IsCompleted &&
                                          batchResults.TestResults.All(t => t.State == TestRunState.RanSuccessfully)
                                          ? TestRunState.RanSuccessfully
                                          : TestRunState.RunFailed;
            }
            while (keepLooping);

            batchResults.BatchEndTime = DateTime.UtcNow;
        }
コード例 #5
0
        /// <summary> Runs the Task Sequence Sequentially. </summary>
        /// <param name="endpoint"> Chassis Manager Endpoint. </param>
        /// <param name="globalParameters"> Global parameter values. </param>
        /// <returns> A list of TestRun objects. </returns>
        public List<ResultOfTest> Run(string endpoint, Parameters globalParameters, TimeSpan? apiSlaFromBatch, string userName, string userPassword)
        {
            if (!this.ApiSla.HasValue && apiSlaFromBatch.HasValue)
            {
                this.ApiSla = apiSlaFromBatch;
            }

            var testResults = new List<ResultOfTest>();

            Console.WriteLine("\n***Start: {0} TimeNow:{1}\n", this.SequenceName, DateTime.UtcNow);

            // Merges and/or overlays globalParameters with LocalParameters based on UseLocalParametersOnly.
            var parameters = (Parameters)globalParameters.Clone();
            if (this.LocalParameters != null && this.LocalParameters.Count > 0)
            {
                foreach (var param in this.LocalParameters)
                {
                    parameters[param.Key, !this.UseLocalParametersOnly] = param.Value;
                }
            }

            //Shuffling all parameters by default; Can add a control if needed to turn this feature on/off.
            parameters.Shuffle();

            var requiredParamValues = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase);
            //this.Tests.ForEach(t => Helper.GetChassisManagerApiParameterList(t.Name).ForEach(p => requiredParamValues[p] = null));
            for (var i = 0; i < this.SequenceIterations; i++)
            {
                // Get new set of values between iterations or if it's first time in the loop.
                if (this.RotateParametersValueBetweenIterations || i == 0)
                {
                    requiredParamValues.Keys.ToList().ForEach(k => requiredParamValues[k] = parameters[k, -1]);
                }

                this.Tests.ForEach(
                    test =>
                    {
                        try
                        {
                            if (!test.SkipTest)
                            {
                                Helper.GetChassisManagerApiParameterList(test.Name).ForEach(p =>
                                {
                                    if (!requiredParamValues.ContainsKey(p))
                                    {
                                        requiredParamValues[p] = parameters[p, -1];
                                    }
                                });
                                var testResult = test.Run(endpoint, this.SequenceName, i, requiredParamValues, this.ApiSla, userName, userPassword);
                                Console.WriteLine(testResult);

                                //// TODO: Validate test results by examining testRun.LastSuccessfulResponse.

                                testResults.Add(testResult);
                            }
                        }
                        catch (KeyNotFoundException ex)
                        {
                            Console.WriteLine("Skipping test {0}; Missing parameter:{1}", test.Name, ex);
                            test.SkipTest = true;
                        }
                    });
            }

            Console.WriteLine("\n***END: {0} Iterations: TimeNow:{1}\n", this.SequenceName, DateTime.UtcNow);
            return testResults;
        }