コード例 #1
0
        /// <summary>
        /// Look control panel and web server to come up.
        /// </summary>
        /// <param name="device"></param>
        /// <param name="retry"></param>
        /// <returns></returns>
        private bool IsDeviceRunning(IDevice device, int retry, ref bool controlPanelUp, ref bool embeddedServerUp)
        {
            ExecutionServices.SystemTrace.LogDebug($"Retry Count: {retry}");
            var status = device.GetDeviceStatus();

            Application.DoEvents();

            if (!controlPanelUp)
            {
                controlPanelUp = IsWebServicesUp(device);
                if (controlPanelUp)
                {
                    //_activityExecutionDetailLog = new ActivityExecutionDetailLog(_executionData, "ControlPanelUp", fwRevision);
                    //ExecutionServices.DataLogger.Submit(_activityExecutionDetailLog);
                    _performanceLogger.RecordEvent(DeviceWorkflowMarker.WebServicesUp);
                }
            }

            if (!embeddedServerUp)
            {
                embeddedServerUp = (status == DeviceStatus.Running || status == DeviceStatus.Warning || status == DeviceStatus.Down);
                if (embeddedServerUp)
                {
                    //_activityExecutionDetailLog = new ActivityExecutionDetailLog(_executionData, "PostUpgradeFirmware", fwRevision);
                    //ExecutionServices.DataLogger.Submit(_activityExecutionDetailLog);
                    _performanceLogger.RecordEvent(DeviceWorkflowMarker.EmbeddedWebServerUp);
                }
            }


            return(controlPanelUp && embeddedServerUp);
        }
コード例 #2
0
        public PluginExecutionResult Execute(PluginExecutionData executionData)
        {
            var                  result          = new PluginExecutionResult(PluginResult.Passed);
            IAssetInfo           printAsset      = (IAssetInfo)executionData.Assets.First();;
            DeviceWorkflowLogger workflowLogger  = new DeviceWorkflowLogger(executionData);
            PrintDeviceInfo      printDeviceInfo = (PrintDeviceInfo)executionData.Assets.First();

            var activityData = executionData.GetMetadata <JetAdvantageActivityData>();

            try
            {
                using (_device = GetDevice(printDeviceInfo))
                {
                    FillFormWithActivityData(activityData);
                    workflowLogger.RecordEvent(DeviceWorkflowMarker.DeviceLockBegin);
                    UpdateStatus("Starting JetAdvantage Pull Printing Application");

                    _manager = new JetAdvantageManager(executionData, workflowLogger, _device, printDeviceInfo);
                    _manager.StatusUpdate += _manager_StatusUpdate;

                    var token = new AssetLockToken(printAsset, TimeSpan.FromHours(1), TimeSpan.FromHours(1));

                    ExecutionServices.CriticalSection.Run(token, () =>
                    {
                        var retryManager = new PluginRetryManager(executionData, UpdateStatus);
                        result           = retryManager.Run(() => _manager.RunJetAdvantage());
                    });
                }
                workflowLogger.RecordEvent(DeviceWorkflowMarker.DeviceLockEnd);
            }
            catch (DeviceCommunicationException ex)
            {
                return(new PluginExecutionResult(PluginResult.Failed, ex.Message, "Device communication error."));
            }
            catch (DeviceInvalidOperationException ex)
            {
                return(new PluginExecutionResult(PluginResult.Failed, ex.Message, "Device automation error."));
            }
            catch (DeviceWorkflowException ex)
            {
                result = new PluginExecutionResult(PluginResult.Failed, ex, "Device workflow error.");
            }
            catch (ScalableTest.Framework.Synchronization.AcquireLockTimeoutException)
            {
                return(new PluginExecutionResult(PluginResult.Skipped, "Could not obtain lock on specified device(s).", "Device unavailable."));
            }
            catch (ScalableTest.Framework.Synchronization.HoldLockTimeoutException)
            {
                return(new PluginExecutionResult(PluginResult.Error, $"Automation did not complete within {TimeSpan.FromHours(1)}.", "Automation timeout exceeded."));
            }
            finally
            {
                UpdateStatus($"Finished JetAdvantage Printing activity");
            }


            return(result);
        }
コード例 #3
0
        /// <summary>
        /// Launches the application.
        /// </summary>
        /// <param name="device">The device.</param>
        /// <param name="deviceAsset">The device asset.</param>
        /// <returns>PluginExecutionResult</returns>
        private PluginExecutionResult LaunchApp(IDevice device, IDeviceInfo deviceAsset)
        {
            PluginExecutionResult result = new PluginExecutionResult(PluginResult.Passed);
            string buttonText            = _activityData.InitiationButton;

            try
            {
                _workflowLogger.RecordEvent(DeviceWorkflowMarker.ActivityBegin);

                AuthenticationInitMethod aim = GetAuthenticationInitMethod(_activityData.InitiationButton);
                DeviceSignOutMethod      deviceUnauthMethod = SignOutMethod.GetSignOutMethod(_activityData.UnAuthenticateMethod);
                IAuthenticator           auth = GetAuthenticator(device, deviceAsset);

                // retrieve the Authentication solution, plugin.
                IAuthenticationDriver app = GetApp(device);

                UpdateStatus("Launching authentication for " + buttonText + ".");
                if (!aim.Equals(AuthenticationInitMethod.DoNotSignIn))
                {
                    app.Launch(auth, aim);
                }
                else
                {
                    UpdateStatus("Skip Sign In :: Do not Sign In");
                }

                UpdateStatus("Logging out of device " + deviceAsset.AssetId + " - " + deviceAsset.Address + " by " + _activityData.UnAuthenticateMethod);
                if (deviceUnauthMethod.Equals(DeviceSignOutMethod.DoNotSignOut))
                {
                    UpdateStatus("Skip Sign Out :: Do Not Sign Out");
                }
                else
                {
                    app.SignOut(deviceUnauthMethod, device);
                }

                _workflowLogger.RecordEvent(DeviceWorkflowMarker.ActivityEnd);
            }
            catch (DeviceCommunicationException ex)
            {
                result = new PluginExecutionResult(PluginResult.Failed, ex.Message, "Device communication error.");
            }
            catch (DeviceInvalidOperationException ex)
            {
                result = new PluginExecutionResult(PluginResult.Failed, ex.Message, "Device automation error.");
            }
            catch (DeviceWorkflowException ex)
            {
                result = new PluginExecutionResult(PluginResult.Failed, ex, "Device workflow error.");
            }

            return(result);
        }
コード例 #4
0
        /// <summary>
        /// Executes this plugin's workflow using the specified <see cref="PluginExecutionData" />.
        /// </summary>
        /// <param name="executionData">The execution data.</param>
        /// <returns>A <see cref="PluginExecutionResult" /> indicating the outcome of the execution.</returns>
        public PluginExecutionResult Execute(PluginExecutionData executionData)
        {
            _executionData     = executionData;
            _performanceLogger = new DeviceWorkflowLogger(_executionData);
            _activityData      = executionData.GetMetadata <EWSFirmwarePerformanceActivityData>();

            TimeSpan lockTimeout = TimeSpan.FromMinutes(10);
            TimeSpan holdTimeout = TimeSpan.FromMinutes(60);

            PluginExecutionResult result = new PluginExecutionResult(PluginResult.Failed, "Failed to Start Upgrade");


            ///Dictionary<string, PluginExecutionResult> results = new Dictionary<string, PluginExecutionResult>();
            if (_executionData.Assets.OfType <IDeviceInfo>().Count() == 0)
            {
                return(new PluginExecutionResult(PluginResult.Failed, $"There were no assets retrieved.  If this is a count-based run, your reservation in asset inventory may have expired.", "DeviceInfo Asset error"));
            }

            try
            {
                var assetTokens = _executionData.Assets.OfType <IDeviceInfo>().Select(n => new AssetLockToken(n, lockTimeout, holdTimeout));
                _performanceLogger.RecordEvent(DeviceWorkflowMarker.DeviceLockBegin);
                ExecutionServices.CriticalSection.Run(assetTokens, selectedToken =>
                {
                    _performanceLogger.RecordEvent(DeviceWorkflowMarker.ActivityBegin);

                    IDeviceInfo asset = (selectedToken as AssetLockToken).AssetInfo as IDeviceInfo;
                    ExecutionServices.DataLogger.Submit(new ActivityExecutionAssetUsageLog(_executionData, asset));

                    ExecutionServices.SystemTrace.LogDebug("Validating Firmware bundle for the selected asset");
                    result = ValidateFirmwareBundles(asset.AssetId, asset.AdminPassword, asset.Address);
                    if (result.Result == PluginResult.Failed)
                    {
                        throw new DeviceWorkflowException($"Failed to validate FW bundle for device {asset.AssetId}. Error: {result.Message}");
                    }
                    if (result.Result != PluginResult.Skipped)
                    {
                        ExecutionServices.SystemTrace.LogDebug($"Performing update on device {asset.AssetId} at address {asset.Address}");

                        result = UpgradeFirmware(asset);
                    }
                });
            }
            catch (Exception e)
            {
                ExecutionServices.SystemTrace.LogDebug(e);
                UpdateStatus(e.Message);
                result = new PluginExecutionResult(PluginResult.Failed, e.Message);
            }
            _performanceLogger.RecordEvent(DeviceWorkflowMarker.ActivityEnd);
            _performanceLogger.RecordEvent(DeviceWorkflowMarker.DeviceLockEnd);
            return(result);
        }
コード例 #5
0
        /// <summary>
        /// Execute the task of the PrintFromUsb activity.
        /// </summary>
        /// <param name="executionData"></param>
        /// <returns></returns>
        public PluginExecutionResult Execute(PluginExecutionData executionData)
        {
            PluginExecutionResult result = new PluginExecutionResult(PluginResult.Failed);

            var acquireTimeout = TimeSpan.FromMinutes(10);
            var holdTimeout    = TimeSpan.FromMinutes(10);

            _executionData = executionData;
            _deviceAssets  = executionData.Assets.OfType <IDeviceInfo>().ToList();

            //If there is no device to run
            if (_deviceAssets.Count() == 0)
            {
                //Skip When there are no device to execute on.
                return(new PluginExecutionResult(PluginResult.Skipped, "No Asset available to run."));
            }

            _workflowLogger = new DeviceWorkflowLogger(executionData);
            UpdateStatus("Starting task engine");
            List <AssetLockToken> tokens = _deviceAssets.Select(n => new AssetLockToken(n, acquireTimeout, holdTimeout)).ToList();

            _workflowLogger.RecordEvent(DeviceWorkflowMarker.DeviceLockBegin);
            ExecutionServices.CriticalSection.Run(tokens, selectedToken =>
            {
                IDeviceInfo deviceInfo = (selectedToken as AssetLockToken).AssetInfo as IDeviceInfo;
                if (!deviceInfo.Attributes.HasFlag(AssetAttributes.Printer))
                {
                    result = new PluginExecutionResult(PluginResult.Skipped, "Device does not have print capability.");
                    return;
                }

                UpdateStatus($"Using device {deviceInfo.AssetId} ({deviceInfo.Address})");
                ExecutionServices.DataLogger.Submit(new ActivityExecutionAssetUsageLog(executionData, deviceInfo));
                using (IDevice device = IDeviceCreate(deviceInfo))
                {
                    var retryManager = new PluginRetryManager(executionData, UpdateStatus);
                    result           = retryManager.Run(() => RunApp(device));
                }
            });

            _workflowLogger.RecordEvent(DeviceWorkflowMarker.DeviceLockEnd);

            return(result);
        }
コード例 #6
0
        private PluginExecutionResult TriggerReboot(IDevice device)
        {
            PluginExecutionResult result = new PluginExecutionResult(PluginResult.Failed, "Failed to Trigger Reboot");


            //FalconReboot
            //Powermanagement

            // bool jediRebootSuccess = false;
            try
            {
                JediOmniDevice dev = new JediOmniDevice(device.Address, device.AdminPassword);
                PUTCDM(device.Address, @"{""snmpv1v2Enabled"": ""true"",""accessOption"": ""readWrite"",""readOnlyPublicAllowed"": ""true"",""readOnlyCommunityNameSet"": ""false"",""writeOnlyCommunitryNameSet"": ""false""}");


                dev.PowerManagement.Reboot();
                //jediRebootSuccess = true;
                //_performanceLogger.RecordEvent(DeviceWorkflowMarker.DeviceRebootBegin);
            }
            catch (Exception e)
            {
                ExecutionServices.SystemTrace.LogInfo($"Could not reboot via Jedi, Attempting Falcon Service. Error:{e.Message}");
                throw;
            }



            int maxRetries = (int)TimeSpan.FromMinutes(30).TotalSeconds / 10;


            if (Retry.UntilTrue(() => HasDeviceRebooted(device), maxRetries / 5, TimeSpan.FromSeconds(5)))
            {
                _performanceLogger.RecordEvent(DeviceWorkflowMarker.DeviceRebootBegin);
                result = new PluginExecutionResult(PluginResult.Passed);
                UpdateStatus("Device has Rebooted. Waiting for device to boot up...");
            }
            else
            {
                result = new PluginExecutionResult(PluginResult.Failed, $@"Failed to trigger reboot within {maxRetries*5} seconds");
            }

            return(result);
        }
コード例 #7
0
        /// <summary>
        /// Entrypoint for the Plugin Task Execution for TwainDriverConfiguration Plugin
        /// </summary>
        /// <param name="executionData"></param>
        /// <returns></returns>
        public PluginExecutionResult Execute(PluginExecutionData executionData)
        {
            PluginExecutionResult result = new PluginExecutionResult(PluginResult.Passed);
            var acquireTimeout           = TimeSpan.FromMinutes(5);
            var holdTimeout = TimeSpan.FromMinutes(5);

            _executionData = executionData;
            _deviceAssets  = executionData.Assets.OfType <IDeviceInfo>().ToList();
            try
            {
                _workflowLogger = new DeviceWorkflowLogger(executionData);
                UpdateStatus("Starting task engine");
                List <AssetLockToken> tokens = _deviceAssets.Select(n => new AssetLockToken(n, acquireTimeout, holdTimeout)).ToList();
                _workflowLogger.RecordEvent(DeviceWorkflowMarker.DeviceLockBegin);
                ExecutionServices.CriticalSection.Run(tokens, selectedToken =>
                {
                    IDeviceInfo deviceInfo = (selectedToken as AssetLockToken).AssetInfo as IDeviceInfo;

                    UpdateStatus($"Using device {deviceInfo.AssetId} ({deviceInfo.Address})");
                    using (IDevice device = DeviceConstructor.Create(deviceInfo))
                    {
                        var retryManager = new PluginRetryManager(executionData, UpdateStatus);
                        result           = retryManager.Run(() => RunTwain(device, executionData));
                    }
                });

                _workflowLogger.RecordEvent(DeviceWorkflowMarker.DeviceLockEnd);
            }
            catch (DeviceCommunicationException ex)
            {
                return(new PluginExecutionResult(PluginResult.Failed, ex.Message, "Device communication error."));
            }
            catch (DeviceInvalidOperationException ex)
            {
                return(new PluginExecutionResult(PluginResult.Failed, ex.Message, "Device automation error."));
            }
            catch (DeviceWorkflowException ex)
            {
                return(new PluginExecutionResult(PluginResult.Failed, ex, "Device workflow error."));
            }

            return(result);
        }
コード例 #8
0
ファイル: KellyTest.cs プロジェクト: ProjectAgri20/newrepo
        private void LogPerformance(int iterations)
        {
            try
            {
                PluginConfigurationData configData     = PluginConfigurationData.LoadFromFile("C:\\Work\\PluginConfig\\GFriendDataBlank.plugindata");
                PluginExecutionData     executionData  = CreateExecutionData(configData);
                DeviceWorkflowLogger    workflowLogger = new DeviceWorkflowLogger(executionData);

                for (int i = 0; i < iterations; i++)
                {
                    workflowLogger.RecordEvent(DeviceWorkflowMarker.DeviceLockBegin);
                }
            }
            catch (Exception ex)
            {
                TraceFactory.Logger.Error(ex);
            }
        }
コード例 #9
0
        /// <summary>
        /// Executes this plugin's workflow using the specified <see cref="PluginExecutionData" />.
        /// </summary>
        /// <param name="executionData">The execution data.</param>
        /// <returns>A <see cref="PluginExecutionResult" /> indicating the outcome of the execution.</returns>
        public PluginExecutionResult Execute(PluginExecutionData executionData)
        {
            UpdateStatus("Starting activity.");
            UpdateLabel(sessionId_value_label, executionData.SessionId);

            _workflowLogger = new DeviceWorkflowLogger(executionData);
            GFriendExecutionActivityData data = executionData.GetMetadata <GFriendExecutionActivityData>();

            UpdateStatus("Prepare Files.");
            string scriptPath;

            if (executionData.Environment.PluginSettings.ContainsKey("GFScriptPath"))
            {
                scriptPath = executionData.Environment.PluginSettings["GFScriptPath"];
            }
            else
            {
                scriptPath = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "scripts", executionData.SessionId);
            }
            UpdateStatus($"GFriend files will be saved to {scriptPath}");

            GFriendPreparationManager.PrepareFiles(data.GFriendFiles, scriptPath);

            string scriptToRun = data.GFriendFiles.Where(s => s.FileType.Equals(GFFileTypes.GFScript)).FirstOrDefault()?.FileName ?? string.Empty;

            if (string.IsNullOrEmpty(scriptToRun))
            {
                UpdateStatus("GF Script file does not exist. Please check activity data");
                return(new PluginExecutionResult(PluginResult.Failed, "Invalid activity data (No Script File)"));
            }

            scriptToRun = Path.Combine(scriptPath, scriptToRun);
            UpdateStatus($"GFriend test script {scriptToRun} will be exeucted.");

            // Run GFriend
            _consoleWriter = new OutputWriter(output_RichTextBox);
            Console.SetOut(_consoleWriter);

            IDeviceInfo           deviceInfo;
            PluginExecutionResult executionResult = new PluginExecutionResult(PluginResult.Passed);

            if (executionData.Assets.Count > 0)
            {
                var devices     = executionData.Assets.OfType <IDeviceInfo>();
                var assetTokens = devices.Select(n => new AssetLockToken(n, data.LockTimeouts));
                _workflowLogger.RecordEvent(DeviceWorkflowMarker.DeviceLockBegin);
                ExecutionServices.CriticalSection.Run(assetTokens, selectedToken =>
                {
                    deviceInfo = (selectedToken as AssetLockToken).AssetInfo as IDeviceInfo;
                    UpdateLabel(dut_value_label, deviceInfo.AssetId);
                    ExecutionServices.DataLogger.Submit(new ActivityExecutionAssetUsageLog(executionData, deviceInfo));
                    executionResult = RunGFriendScript(executionData, scriptToRun, deviceInfo);
                });
                _workflowLogger.RecordEvent(DeviceWorkflowMarker.DeviceLockEnd);
            }
            else
            {
                executionResult = RunGFriendScript(executionData, scriptToRun, null);
            }

            var standardOutput = new StreamWriter(Console.OpenStandardOutput());

            standardOutput.AutoFlush = true;
            Console.SetOut(standardOutput);

            UpdateStatus("Finished activity.");
            UpdateStatus($"Result = {executionResult.Result}");

            return(executionResult);
        }
コード例 #10
0
        /// <summary>
        /// Executes this plugin's workflow using the specified <see cref="T:HP.ScalableTest.Framework.Plugin.PluginExecutionData" />.
        /// </summary>
        /// <param name="executionData">The execution data.</param>
        /// <returns>A <see cref="T:HP.ScalableTest.Framework.Plugin.PluginExecutionResult" /> indicating the outcome of the execution.</returns>
        public PluginExecutionResult Execute(PluginExecutionData executionData)
        {
            PluginExecutionResult result = new PluginExecutionResult(PluginResult.Passed);

            _executionData = executionData;

            _deviceAssets = executionData.Assets.OfType <IDeviceInfo>().ToList();
            ExecutionServices.SystemTrace.LogDebug($"# of assets in ExecutionData: {executionData.Assets.Count}");

            try
            {
                UpdateStatus("Starting activity...");
                _activityData = executionData.GetMetadata <AuthenticationData>(ConverterProvider.GetMetadataConverters());

                _workflowLogger = new DeviceWorkflowLogger(executionData);
                TimeSpan acquireTimeout = _activityData.LockTimeouts.AcquireTimeout;
                TimeSpan holdTimeout    = _activityData.LockTimeouts.HoldTimeout;

                string msg = string.Empty;

                List <AssetLockToken> tokens = _deviceAssets.Select(n => new AssetLockToken(n, acquireTimeout, holdTimeout)).ToList();
                _workflowLogger.RecordEvent(DeviceWorkflowMarker.DeviceLockBegin);
                ExecutionServices.CriticalSection.Run(tokens, selectedToken =>
                {
                    IDeviceInfo deviceInfo = (selectedToken as AssetLockToken).AssetInfo as IDeviceInfo;
                    LogDevice(deviceInfo);

                    using (IDevice device = SetDevice(deviceInfo))
                    {
                        var retryManager = new PluginRetryManager(executionData, UpdateStatus);
                        result           = retryManager.Run(() => LaunchApp(device, deviceInfo));
                    }
                });

                _workflowLogger.RecordEvent(DeviceWorkflowMarker.DeviceLockEnd);
            }
            catch (DeviceCommunicationException ex)
            {
                return(new PluginExecutionResult(PluginResult.Failed, ex.Message, "Device communication error."));
            }
            catch (DeviceInvalidOperationException ex)
            {
                return(new PluginExecutionResult(PluginResult.Failed, ex.Message, "Device automation error."));
            }
            catch (DeviceWorkflowException ex)
            {
                result = new PluginExecutionResult(PluginResult.Failed, ex, "Device workflow error.");
            }
            catch (AcquireLockTimeoutException)
            {
                return(new PluginExecutionResult(PluginResult.Skipped, "Could not obtain lock on specified devices(s).", "Device unavailable."));
            }
            catch (HoldLockTimeoutException)
            {
                return(new PluginExecutionResult(PluginResult.Error, $"Automation did not complete within {_activityData.LockTimeouts.HoldTimeout}.", "Automation timeout exceeded."));
            }
            finally
            {
                UpdateStatus("Finished activity");
            }
            return(result);
        }
コード例 #11
0
        private PluginExecutionResult RunApp(IDevice device)
        {
            try
            {
                PluginExecutionResult result = new PluginExecutionResult(PluginResult.Failed);

                _activityData = _executionData.GetMetadata <PrintFromUsbActivityData>();

                IUsbApp        usbApp = UsbAppFactory.Create(device);
                IAuthenticator auth   = AuthenticatorFactory.Create(device, _executionData.Credential, AuthenticationProvider.Auto);

                usbApp.WorkflowLogger = auth.WorkflowLogger = _workflowLogger;

                var preparationManager = DevicePreparationManagerFactory.Create(device);
                preparationManager.InitializeDevice(true);
                preparationManager.WorkflowLogger = _workflowLogger;

                // need to add the ability for user to set eager or lazy authentication
                //AuthenticationMode am = (_data.ApplicationAuthentication == false) ? AuthenticationMode.Eager : AuthenticationMode.Lazy;

                usbApp.Pacekeeper = auth.Pacekeeper = new Pacekeeper(TimeSpan.FromSeconds(2));
                _workflowLogger.RecordEvent(DeviceWorkflowMarker.ActivityBegin);
                usbApp.LaunchPrintFromUsb(auth, AuthenticationMode.Lazy);
                UpdateStatus("The Print From USB app is launched");

                usbApp.SelectUsbPrint(_activityData.UsbName);
                UpdateStatus("The USB is selected");

                usbApp.SelectFile();
                UpdateStatus("File to Print is selected");

                if (usbApp.ExecutePrintJob())
                {
                    UpdateStatus("The selected file is printed");
                    result = new PluginExecutionResult(PluginResult.Passed);
                }

                preparationManager.NavigateHome();
                if (preparationManager.SignOutRequired())
                {
                    preparationManager.SignOut();
                }
                _workflowLogger.RecordEvent(DeviceWorkflowMarker.ActivityEnd);
                return(result);
            }
            catch (DeviceCommunicationException ex)
            {
                GatherTriageData(device, ex.ToString());
                return(new PluginExecutionResult(PluginResult.Failed, ex.Message, "Device communication error."));
            }
            catch (DeviceInvalidOperationException ex)
            {
                GatherTriageData(device, ex.ToString());
                return(new PluginExecutionResult(PluginResult.Failed, ex.Message, "Device automation error."));
            }
            catch (DeviceWorkflowException ex)
            {
                GatherTriageData(device, ex.ToString());
                return(new PluginExecutionResult(PluginResult.Failed, ex, "Device workflow error."));
            }
            catch (Exception ex)
            {
                GatherTriageData(device, ex.ToString());
                throw;
            }
        }
コード例 #12
0
        /// <summary>
        /// Executes this plugin's workflow using the specified <see cref="PluginExecutionData" />.
        /// </summary>
        /// <param name="executionData">The execution data.</param>
        /// <returns>A <see cref="PluginExecutionResult" /> indicating the outcome of the execution.</returns>
        public PluginExecutionResult Execute(PluginExecutionData executionData)
        {
            _executionData     = executionData;
            _activityData      = executionData.GetMetadata <RebootActivityData>();
            _performanceLogger = new DeviceWorkflowLogger(_executionData);

            TimeSpan lockTimeout = TimeSpan.FromMinutes(10);
            TimeSpan holdTimeout = TimeSpan.FromMinutes(60);


            UpdateStatus("Starting activity.");
            if (_executionData.Assets.OfType <IDeviceInfo>().Count() == 0)
            {
                return(new PluginExecutionResult(PluginResult.Failed, $"There were no assets retrieved.  If this is a count-based run, your reservation in asset inventory may have expired.", "DeviceInfo Asset error"));
            }

            PluginExecutionResult result = new PluginExecutionResult(PluginResult.Failed, "Failed to Start Reboot");


            try
            {
                var assetTokens = _executionData.Assets.OfType <IDeviceInfo>().Select(n => new AssetLockToken(n, lockTimeout, holdTimeout));
                _performanceLogger.RecordEvent(DeviceWorkflowMarker.DeviceLockBegin);

                ExecutionServices.CriticalSection.Run(assetTokens, selectedToken =>
                {
                    _performanceLogger.RecordEvent(DeviceWorkflowMarker.ActivityBegin);

                    IDeviceInfo asset = (selectedToken as AssetLockToken).AssetInfo as IDeviceInfo;
                    ExecutionServices.DataLogger.Submit(new ActivityExecutionAssetUsageLog(_executionData, asset));
                    IDevice device = DeviceConstructor.Create(asset);


                    ExecutionServices.SystemTrace.LogInfo($@"Rebooting {asset.AssetId}");
                    UpdateStatus($@"Rebooting {asset.AssetId}");

                    result = RebootDevice(device);


                    //If we rebooted AND we want to set PJL, do so
                    if (_activityData.SetPaperless)
                    {
                        //Wait for WS* to come back up. It's one of the last services
                        WaitForService(device);

                        Thread.Sleep(60000);
                        EnablePJL(device);
                        Thread.Sleep(1000);
                        SetPaperlessPrintMode(true, device);
                    }
                });
            }
            catch (Exception e)
            {
                ExecutionServices.SystemTrace.LogInfo(e);
                UpdateStatus(e.Message);
                result = new PluginExecutionResult(PluginResult.Failed, e.Message);
            }


            UpdateStatus("Finished activity.");
            UpdateStatus($"Result = {result.Result}");

            return(result);
        }
コード例 #13
0
        /// <summary>
        /// Executes this plug-in's workflow using the specified <see cref="PluginExecutionData"/>.
        /// </summary>
        /// <param name="executionData">The execution data.</param>
        /// <returns>A <see cref="PluginExecutionResult"/> indicating the outcome of the
        /// execution.</returns>
        public PluginExecutionResult Execute(PluginExecutionData executionData)
        {
            _executionData     = executionData;
            _performanceLogger = new DeviceWorkflowLogger(_executionData);
            _activityData      = _executionData.GetMetadata <DriverlessPrintingActivityData>();
            var printer = executionData.Assets.OfType <PrintDeviceInfo>().FirstOrDefault();

            if (printer == null)
            {
                return(new PluginExecutionResult(PluginResult.Skipped, "No assets available for execution."));
            }
            if (!printer.Attributes.HasFlag(AssetAttributes.Printer))
            {
                return(new PluginExecutionResult(PluginResult.Skipped, "The device has no print capability."));
            }
            var address = printer.Address;

            var iteratorMode = _activityData.ShuffleDocuments
                ? CollectionSelectorMode.ShuffledRoundRobin
                : CollectionSelectorMode.Random;
            var      documentIterator = new DocumentCollectionIterator(iteratorMode);
            var      document         = documentIterator.GetNext(executionData.Documents);
            FileInfo localFile        = ExecutionServices.FileRepository.GetFile(document);

            if (_activityData.PinProtected)
            {
                AddPinProtection(localFile, _activityData.Pin);
            }

            if (_activityData.PrintMethod == PrintMethod.Random)
            {
                Random newRandom = new Random(4);
                var    randomInt = newRandom.Next(0, 999) % 4;
                _activityData.PrintMethod = (PrintMethod)randomInt;
            }

            _performanceLogger.RecordEvent(DeviceWorkflowMarker.PrintJobBegin);
            UpdateStatus($"Printing {document.FileName} via {_activityData.PrintMethod}.");
            switch (_activityData.PrintMethod)
            {
            default:
                Print9100(address, localFile);
                break;

            case PrintMethod.Ftp:
                PrintFtp(address, "admin", printer.AdminPassword, localFile, true);
                break;

            case PrintMethod.Ipp:
                PrintIpp(address, localFile);
                break;

            case PrintMethod.Ews:
                PrintEws(address, printer.AdminPassword, localFile);
                break;
            }
            _performanceLogger.RecordEvent(DeviceWorkflowMarker.PrintJobEnd);
            _performanceLogger.RecordExecutionDetail(DeviceWorkflowMarker.PrintJobEnd, _activityData.PrintMethod.ToString());
            ActivityExecutionDocumentUsageLog documentLog = new ActivityExecutionDocumentUsageLog(executionData, document);

            ExecutionServices.DataLogger.Submit(documentLog);

            if (_activityData.PrintJobSeparator)
            {
                UpdateStatus("Printing Job Separator.");
                PrintJobSeparator(address);
            }
            localFile.Delete();
            return(_result);
        }
コード例 #14
0
        /// <summary>
        /// Performs a firmware update on Omni and WindJammer Devices
        /// </summary>
        /// <param name="asset"></param>
        /// <returns>A <see cref="PluginExecutionResult" /> indicating the outcome of the execution.</returns>
        public PluginExecutionResult UpgradeFirmware(IDeviceInfo asset)
        {
            IDevice device    = DeviceConstructor.Create(asset);
            string  sessionId = GetSessionId(device.Address);

            _activityExecutionDetailLog = new ActivityExecutionDetailLog(_executionData, "FirmwareFlashMethod", "EWS");
            ExecutionServices.DataLogger.Submit(_activityExecutionDetailLog);


            PluginExecutionResult result = new PluginExecutionResult(PluginResult.Failed, "Failed to Update Firmware");
            string startingFW            = device.GetDeviceInfo().FirmwareRevision;

            device_textBox.InvokeIfRequired(c => { c.Text = device.Address; });
            currentRevision_textBox.InvokeIfRequired(c => { c.Text = startingFW; });

            UpdateStatus($"Firmware upgrade for device {device.Address} is in progress, please wait...");
            bool downgrade = false;

            if (device is JediWindjammerDevice)
            {
                result = SignInWJ(device.Address, device.AdminPassword, sessionId);

                _performanceLogger.RecordEvent(DeviceWorkflowMarker.FirmwareUpdateBegin);
                result = FlashFirmwareWJ(asset, sessionId);
            }
            else if (device is JediOmniDevice)
            {
                sessionId = SignInOmni(device.Address, device.AdminPassword);

                _performanceLogger.RecordEvent(DeviceWorkflowMarker.FirmwareUpdateBegin);
                result    = FlashOmniFirmware(asset, ref sessionId);
                downgrade = result.Message == "True" ? true : false;
            }
            ExecutionServices.SystemTrace.LogInfo($"FW Update Complete");
            _activityExecutionDetailLog = new ActivityExecutionDetailLog(_executionData, "FirmwareFlashUpgrade", downgrade ? "false" : "true");
            ExecutionServices.DataLogger.Submit(_activityExecutionDetailLog);

            //Wait for device to finish rebooting or end

            //if (!_activityData.ValidateFlash || downgrade)
            //{
            //    _performanceLogger.RecordEvent(DeviceWorkflowMarker.FirmwareUpdateEnd);
            //    return result;
            //}

            if (result.Result == PluginResult.Failed)
            {
                return(result);
            }

            int maxRetries = (int)_activityData.ValidateTimeOut.TotalSeconds / 10;

            if (Retry.UntilTrue(() => HasDeviceRebooted(device), maxRetries / 5, TimeSpan.FromSeconds(5)))
            {
                _performanceLogger.RecordEvent(DeviceWorkflowMarker.DeviceRebootBegin);
                UpdateStatus("Device has Rebooted. Waiting for device to boot up...");
            }
            else
            {
                result = new PluginExecutionResult(PluginResult.Failed, $"Device did not reboot after firmware was uploaded. Please check the device for pending jobs and try again.");
                return(result);
            }


            ExecutionServices.SystemTrace.LogInfo($"Starting Reboot");
            UpdateStatus("Waiting for device to boot up...");
            //_performanceLogger.RecordEvent(DeviceWorkflowMarker.DeviceRebootBegin);
            //We're probably not up and running right away.
            Thread.Sleep(TimeSpan.FromSeconds(30));

            //int maxRetries = (int)_activityData.ValidateTimeOut.TotalSeconds / 10;
            ExecutionServices.SystemTrace.LogDebug($"Max Retries: {maxRetries}");
            int    retry            = 0;
            string fwRevision       = string.Empty;
            bool   controlPanelUp   = false; //Actually webservices, but close enough.
            bool   embeddedServerUp = false;

            if (Retry.UntilTrue(() => IsDeviceRunning(device, retry++, ref controlPanelUp, ref embeddedServerUp), maxRetries, TimeSpan.FromSeconds(10)))
            {
                try
                {
                    if (downgrade)
                    {
                        SetDefaultPassword(device.Address, device.AdminPassword);
                    }

                    fwRevision = device.GetDeviceInfo().FirmwareRevision;
                    postRevision_textBox.InvokeIfRequired(c => { c.Text = fwRevision; });
                }
                catch
                {
                    fwRevision = string.Empty;
                }
                //Validate update passed by comparing starting and ending FW
                result = startingFW != fwRevision ? new PluginExecutionResult(PluginResult.Passed, $"Firmware upgraded for device {device.Address}") : new PluginExecutionResult(PluginResult.Failed, "The device firmware upgrade validation failed");
            }
            else
            {
                result = new PluginExecutionResult(PluginResult.Failed,
                                                   $"Device firmware could not be validated for device:{device.Address} within {_activityData.ValidateTimeOut}");
            }
            _performanceLogger.RecordEvent(DeviceWorkflowMarker.DeviceRebootEnd);
            _performanceLogger.RecordEvent(DeviceWorkflowMarker.FirmwareUpdateEnd);

            ExecutionServices.SystemTrace.LogInfo($"Reboot End");

            _activityExecutionDetailLog = new ActivityExecutionDetailLog(_executionData, "PostUpgradeFirmware", fwRevision);
            ExecutionServices.DataLogger.Submit(_activityExecutionDetailLog);

            return(result);
        }
コード例 #15
0
        /// <summary>
        /// Executes this plugin's workflow using the specified <see cref="PluginExecutionData" />.
        /// </summary>
        /// <param name="executionData">The execution data.</param>
        /// <returns>A <see cref="PluginExecutionResult" /> indicating the outcome of the execution.</returns>
        public PluginExecutionResult Execute(PluginExecutionData executionData)
        {
            _executionData     = executionData;
            _performanceLogger = new DeviceWorkflowLogger(_executionData);
            _activityData      = executionData.GetMetadata <USBFirmwarePerformanceActivityData>();

            TimeSpan lockTimeout = TimeSpan.FromMinutes(10);
            TimeSpan holdTimeout = TimeSpan.FromMinutes(60);

            PluginExecutionResult result = new PluginExecutionResult(PluginResult.Failed, "Failed to Start Upgrade");


            ///Dictionary<string, PluginExecutionResult> results = new Dictionary<string, PluginExecutionResult>();
            if (_executionData.Assets.OfType <IDeviceInfo>().Count() == 0)
            {
                return(new PluginExecutionResult(PluginResult.Failed, $"There were no assets retrieved.  If this is a count-based run, your reservation in asset inventory may have expired.", "DeviceInfo Asset error"));
            }

            try
            {
                var assetTokens = _executionData.Assets.OfType <IDeviceInfo>().Select(n => new AssetLockToken(n, lockTimeout, holdTimeout));
                _performanceLogger.RecordEvent(DeviceWorkflowMarker.DeviceLockBegin);
                ExecutionServices.CriticalSection.Run(assetTokens, selectedToken =>
                {
                    _performanceLogger.RecordEvent(DeviceWorkflowMarker.ActivityBegin);

                    IDeviceInfo asset = (selectedToken as AssetLockToken).AssetInfo as IDeviceInfo;
                    IDevice device    = DeviceConstructor.Create(asset);
                    ExecutionServices.DataLogger.Submit(new ActivityExecutionAssetUsageLog(_executionData, asset));

                    ExecutionServices.SystemTrace.LogDebug($"Performing update on device {asset.AssetId} at address {asset.Address}");

                    result = UpgradeFirmware(asset);


                    if (result.Result != PluginResult.Passed)
                    {
                        //the update process failed, just return
                        return;
                    }

                    if (!_activityData.ValidateFlash)
                    {
                        _performanceLogger.RecordExecutionDetail(DeviceWorkflowMarker.FirmwareUpdateEnd, device.GetDeviceInfo().FirmwareRevision);
                        return;
                    }

                    int maxRetries = (int)_activityData.ValidateTimeOut.TotalSeconds / 5;
                    if (Retry.UntilTrue(() => HasDeviceRebooted(device), maxRetries, TimeSpan.FromSeconds(5)))
                    {
                        _performanceLogger.RecordEvent(DeviceWorkflowMarker.DeviceRebootBegin);
                        UpdateStatus("Device has Rebooted. Waiting for device to boot up...");
                    }
                    else
                    {
                        result = new PluginExecutionResult(PluginResult.Failed, $"Device did not reboot after firmware was uploaded. Please check the device for pending jobs and try again.");
                        return;
                    }


                    ExecutionServices.SystemTrace.LogInfo($"FW Update Complete");

                    //Wait for device to finish rebooting or end
                    ExecutionServices.SystemTrace.LogInfo($"Starting Reboot");
                    UpdateStatus("Waiting for device to boot up...");
                    //_performanceLogger.RecordEvent(DeviceWorkflowMarker.DeviceRebootBegin);
                    //We're probably not up and running right away.
                    Thread.Sleep(TimeSpan.FromSeconds(30));


                    ExecutionServices.SystemTrace.LogDebug($"Max Retries: {maxRetries}");
                    int retry             = 0;
                    string fwRevision     = string.Empty;
                    bool controlPanelUp   = false; //Actually webservices, but close enough.
                    bool embeddedServerUp = false;
                    if (Retry.UntilTrue(() => IsDeviceRunning(device, retry++, ref controlPanelUp, ref embeddedServerUp), maxRetries, TimeSpan.FromSeconds(10)))
                    {
                        try
                        {
                            fwRevision = device.GetDeviceInfo().FirmwareRevision;
                            postRevision_textBox.InvokeIfRequired(c => { c.Text = fwRevision; });
                        }
                        catch
                        {
                            fwRevision = string.Empty;
                        }
                        //Validate update passed by comparing starting and ending FW
                        //result = startingFW != fwRevision ? new PluginExecutionResult(PluginResult.Passed, $"Firmware upgraded for device {device.Address}") : new PluginExecutionResult(PluginResult.Failed, "The device firmware upgrade validation failed");
                        result = new PluginExecutionResult(PluginResult.Passed);
                    }
                    else
                    {
                        result = new PluginExecutionResult(PluginResult.Failed,
                                                           $"Device firmware could not be validated for device:{device.Address} within {_activityData.ValidateTimeOut}");
                    }
                    _performanceLogger.RecordEvent(DeviceWorkflowMarker.DeviceRebootEnd);
                    _performanceLogger.RecordEvent(DeviceWorkflowMarker.FirmwareUpdateEnd);

                    ExecutionServices.SystemTrace.LogInfo($"Reboot End");

                    _activityExecutionDetailLog = new ActivityExecutionDetailLog(_executionData, "PostUpgradeFirmware", fwRevision);
                    ExecutionServices.DataLogger.Submit(_activityExecutionDetailLog);

                    //return result;
                });
            }
            catch (Exception e)
            {
                ExecutionServices.SystemTrace.LogDebug(e);
                UpdateStatus(e.Message);
                result = new PluginExecutionResult(PluginResult.Failed, e.Message);
            }
            _performanceLogger.RecordEvent(DeviceWorkflowMarker.ActivityEnd);
            _performanceLogger.RecordEvent(DeviceWorkflowMarker.DeviceLockEnd);
            return(result);
        }
コード例 #16
0
        /// <summary>
        /// Executes this plugin's workflow using the specified <see cref="T:HP.ScalableTest.Framework.Plugin.PluginExecutionData" />.
        /// </summary>
        /// <param name="executionData">The execution data.</param>
        /// <returns>A <see cref="T:HP.ScalableTest.Framework.Plugin.PluginExecutionResult" /> indicating the outcome of the execution.</returns>
        public PluginExecutionResult Execute(PluginExecutionData executionData)
        {
            // reset current user as it may have changed since control load.
            _executionData = executionData;
            _currentUser   = _executionData.Credential;
            _activityData  = _executionData.GetMetadata <DirtyDeviceActivityData>(new[] { new DirtyDeviceDataConverter1_1() });

            UpdateExecutionStatus(this, "Starting activity...");

            _currentDevice  = _executionData.Assets.GetRandom <Framework.Assets.IDeviceInfo>();
            _workflowLogger = new DeviceWorkflowLogger(_executionData);

            InitializeControlWithActivityData();

            try
            {
                // Wrap in using to release any connections to the device.  This is critical for Omni operations.
                using (DirtyDeviceManager pluginActivityManager = new DirtyDeviceManager(_currentDevice, _currentUser, _activityData, executionData.Environment))
                {
                    pluginActivityManager.UpdateStatus += (s, e) => UpdateExecutionStatus(s, e);

                    if (_currentDevice == null)
                    {
                        return(new PluginExecutionResult(PluginResult.Error, $"{typeof(IDeviceInfo).Name} retrieved is null.  If this is a count-based run, your reservation in asset inventory may have expired.", "DeviceInfo Asset error"));
                    }
                    else if (_currentDevice.AssetId == null)
                    {
                        return(new PluginExecutionResult(PluginResult.Error, $"{typeof(IDeviceInfo).Name}.AssetId property is null.", "DeviceInfo Asset error"));
                    }
                    else if (_currentDevice.AssetType == null)
                    {
                        return(new PluginExecutionResult(PluginResult.Error, $"{typeof(IDeviceInfo).Name}.AssetType property is null.", "DeviceInfo Asset error"));
                    }
                    else if (pluginActivityManager.Device == null)
                    {
                        return(new PluginExecutionResult(PluginResult.Error, $"{nameof(pluginActivityManager)}.Device property is null.", $"Could not create IDevice (AssetId: {_currentDevice.AssetId})"));
                    }

                    PluginExecutionResult pluginExecutionResult = new PluginExecutionResult(PluginResult.Error, new Exception($"The {typeof(PluginExecutionResult)} was never set by the activity."));
                    try
                    {
                        UpdateExecutionStatus(this, $"Waiting for access to {_currentDevice.AssetId} ({_currentDevice.Address})");
                        var token = new AssetLockToken(_currentDevice, _activityData.LockTimeouts.AcquireTimeout, _activityData.LockTimeouts.HoldTimeout);
                        _workflowLogger.RecordEvent(DeviceWorkflowMarker.DeviceLockBegin);
                        ExecutionServices.CriticalSection.Run(token, () =>
                        {
                            var retryManager      = new PluginRetryManager(executionData, (e) => UpdateExecutionStatus(this, e));
                            pluginExecutionResult = retryManager.Run(() =>
                            {
                                ExecutionServices.DataLogger.Submit(new ActivityExecutionAssetUsageLog(_executionData, _currentDevice.AssetId));

                                try
                                {
                                    pluginActivityManager.ExecuteDirty();
                                    return(new PluginExecutionResult(PluginResult.Passed));
                                }
                                catch (DeviceCommunicationException ex)
                                {
                                    GatherTriageData(ex.ToString(), pluginActivityManager);
                                    return(new PluginExecutionResult(PluginResult.Failed, ex, "Device communication error."));
                                }
                                catch (DeviceInvalidOperationException ex)
                                {
                                    GatherTriageData(ex.ToString(), pluginActivityManager);
                                    return(new PluginExecutionResult(PluginResult.Failed, ex, "Device automation error."));
                                }
                                catch (DeviceWorkflowException ex)
                                {
                                    GatherTriageData(ex.ToString(), pluginActivityManager);
                                    return(new PluginExecutionResult(PluginResult.Failed, ex, "Device workflow error."));
                                }
                                catch (Exception ex)
                                {
                                    GatherTriageData(ex.ToString(), pluginActivityManager);
                                    return(new PluginExecutionResult(PluginResult.Error, new Exception($"The plugin activity threw an unexpected exception: {ex.ToString()}", ex)));
                                }
                            });
                        });
                        _workflowLogger.RecordEvent(DeviceWorkflowMarker.DeviceLockEnd);
                    }
                    catch (AcquireLockTimeoutException ex)
                    {
                        GatherTriageData(ex.ToString(), pluginActivityManager);
                        return(new PluginExecutionResult(PluginResult.Skipped, string.Format("Could not obtain lock on device {0}.", (_currentDevice != null ? _currentDevice.AssetId : "null")), "Device unavailable."));
                    }
                    catch (HoldLockTimeoutException ex)
                    {
                        GatherTriageData(ex.ToString(), pluginActivityManager);
                        return(new PluginExecutionResult(PluginResult.Error, $"Automation did not complete within {_activityData.LockTimeouts.HoldTimeout}.", "Automation timeout exceeded."));
                    }
                    catch (Exception ex)
                    {
                        GatherTriageData(ex.ToString(), pluginActivityManager);
                        return(new PluginExecutionResult(PluginResult.Error, new Exception($"The {typeof(PluginRetryManager).Name} threw an unexpected exception.", ex)));
                    }

                    return(pluginExecutionResult);
                }
            }
            catch (Exception x)
            {
                return(new PluginExecutionResult(PluginResult.Error, x, "Plugin error during activity setup."));
            }
            finally
            {
                UpdateExecutionStatus(this, $"Finished activity.");
            }
        }