Exemplo n.º 1
0
 public static void Delete(TestEnvironment environment)
 {
     using (ES1AutomationEntities context = new ES1AutomationEntities())
     {
         context.TestEnvironments.Attach(environment);
         context.TestEnvironments.Remove(environment);
         context.SaveChanges();
     }
 }
Exemplo n.º 2
0
 public static TestEnvironment Add(TestEnvironment environment)
 {
     using (ES1AutomationEntities context = new ES1AutomationEntities())
     {
         TestEnvironment e = context.TestEnvironments.Add(environment);
         context.SaveChanges();
         return e;
     }
 }
 public RemoteRubyMiniTestExecutionHandler(AutomationJob job2Run, string rootResultPath)
 {
     Project project = AutomationJob.GetProjectOfJobByJobId(job2Run.JobId);
     this.RootResultPath = rootResultPath;
     this.Job2Run = job2Run;
     this.environment = TestEnvironment.GetEnvironmentById(job2Run.TestAgentEnvironmentId.Value);
     this.vcsRootPath = project.VCSRootPath;
     this.remote = GetRemoteTestAgent(this.environment);
     this.executionCommand = GetExecutionCommand(job2Run);
 }
 public RemoteAgent GetRemoteTestAgent(TestEnvironment environment)
 {
     TestEnvironmentConfigHelper config = new TestEnvironmentConfigHelper(environment.Config);
     string domainAdmin = config.SUTConfiguration.SUTDomainConfig.Adminstrator;
     string domainAdminPassword = config.SUTConfiguration.SUTDomainConfig.Password;
     RemoteAgent r = new RemoteAgent();
     foreach (Machine m in config.SUTConfiguration.Machines)
     {
         if (m.Roles.FindAll(role => role.Key == Core.AgentType.RemoteAgent).Count() > 0)
         {
             r.Admin = string.IsNullOrEmpty(m.Administrator) ? domainAdmin : m.Administrator;
             r.Password = string.IsNullOrEmpty(m.Password) ? domainAdminPassword : m.Password;
             r.Server = m.ExternalIP;
             return r;
         }
     }
     return null;
 }
Exemplo n.º 5
0
 /// <summary>
 /// Get the job which is the test environment for.
 /// </summary>
 /// <param name="environment">Test Environment</param>
 /// <returns></returns>
 public static AutomationJob GetAutomationJobOfTestEnvironment(TestEnvironment environment)
 {
     if (environment.EnvironmentStatus == EnvironmentStatus.New || environment.EnvironmentStatus == EnvironmentStatus.Setup)
     {
         return null;
     }
     else
     {
         using (ES1AutomationEntities context = new ES1AutomationEntities())
         {
             AutomationJob job = (from j in context.AutomationJobs
                                  where (j.TestAgentEnvironmentId == environment.EnvironmentId || j.SUTEnvironmentId == environment.EnvironmentId)
                                         && j.Status != (int)JobStatus.End//Currently one environment may be re-used by several jobs, we only return the active one
                                  select j).FirstOrDefault();
             return job;
         }
     }
 }
Exemplo n.º 6
0
        protected void CreateVCloudEnvironmentAsync(TestEnvironment environment, int timeout)
        {
            environment.SetEnvironmentStatus(EnvironmentStatus.Setup);
            System.Threading.Tasks.Task.Factory.StartNew
            (
                () =>
                {
                    try
                    {
                        ATFEnvironment.Log.logger.Debug(string.Format("Creating Envrionment Id = {0}, Name= {1}", environment.EnvironmentId, environment.Name));

                        ATFEnvironment.Log.logger.Info("Try to find vApp Template: " + environment.Description);
                        VappTemplate vAppTemplate = null;
                        vAppTemplate = VCloud.GetVappTemplateByName(Organization, VDC, environment.Description);

                        if (vAppTemplate == null)
                        {
                            string errorMsg = string.Format("vApp template: {0} not find", environment.Description);
                            environment.SetEnvironmentStatus(EnvironmentStatus.Error);
                            ATFEnvironment.Log.logger.Error(errorMsg);
                            throw new EnvironmentException(ModuleName, errorMsg);
                        }

                        ATFEnvironment.Log.logger.Debug("start create vApp: " + environment.Name);
                        var vApp = VCloud.CreateVappFromTemplate(Organization, VDC, environment.Description, environment.Name, timeout);
                        ATFEnvironment.Log.logger.Debug("finish create vApp: " + environment.Name);

                        ATFEnvironment.Log.logger.Debug("start deploy vApp: " + environment.Name);
                        VCloud.DeployVapp(vApp, true, timeout, false);
                        ATFEnvironment.Log.logger.Debug("start deploy vApp: " + environment.Name);
                    }
                    catch (Exception ex)
                    {
                        string errorMsg = string.Format("Failed to create vApp by template: {0}", environment.Description);
                        ATFEnvironment.Log.logger.Error(errorMsg, ex);
                        environment.SetEnvironmentStatus(EnvironmentStatus.Error);//here we set the environment to be error. Because this is a async operation, it's not reasonable to throw an exception.
                    }
                }
            );
        }
Exemplo n.º 7
0
        public virtual void UpdateEnvironmentConfig(TestEnvironment environment)
        {
            IList<VM> vms = null;
            try
            {
                vms = VCloud.GetVMsByVapp(Organization, VDC, environment.Name);
            }
            catch (Exception ex)
            {
                ATFEnvironment.Log.logger.Error(string.Format("Failed to get the VMs of the vAPP {0}", environment.Name), ex);
            }

            if (vms == null)
            {
                ATFEnvironment.Log.logger.Error(string.Format("No vm is found in environment {0}", environment.Name));
                return;
            }

            string xmlConfig = environment.Config;
            EnvironmentType type = EnvironmentConfigHelper.GetResidenceType(xmlConfig);
            foreach (var vm in vms)
            {
                string ip = string.Empty;
                try
                {
                    ip = vm.GetIpAddressesById().Count > 0 ? vm.GetIpAddressesById().First().Value : string.Empty;
                }
                catch(Exception ex)
                {
                    ATFEnvironment.Log.logger.Error("Could not get the IP address of the VM.", ex);
                    environment.SetEnvironmentStatus(EnvironmentStatus.Error);
                    return;
                }
                if (ip != string.Empty)
                {
                    string externalIP = string.Empty;
                    xmlConfig = EnvironmentConfigHelper.SetMachineIP(xmlConfig, type, vm.Resource.name, ip);
                    try
                    {
                        externalIP = vm.GetNetworkConnections().Count > 0 ? vm.GetNetworkConnections()[0].ExternalIpAddress : string.Empty;
                    }
                    catch (Exception ex)
                    {
                        ATFEnvironment.Log.logger.Error(string.Format("Failed to get the external IP of the VM {0}.", vm.Resource.name), ex);
                        environment.SetEnvironmentStatus(EnvironmentStatus.Error);
                        return;
                    }
                    xmlConfig = EnvironmentConfigHelper.SetMachineExternalIP(xmlConfig, type, vm.Resource.name, externalIP);
                }
                else
                {
                    string message = string.Format("Could not get the IP address for the machine {0}", vm.Resource.name);
                    ATFEnvironment.Log.logger.Error(message);
                    environment.SetEnvironmentStatus(EnvironmentStatus.Error);
                    return;
                }
            }

            environment.SetEnvironmentConfig(xmlConfig);
        }
Exemplo n.º 8
0
 public abstract void RebootMachinesAfterProductInstalled(TestEnvironment environment);
Exemplo n.º 9
0
        /// <summary>
        /// Install the test agent windows service on the test agent
        /// </summary>
        private static void InstallTestAgentWindowsServiceOnEnvironmentAsynchronous(TestEnvironment testEnvironment)
        {
            System.Threading.Tasks.Task.Factory.StartNew
            (
                () =>
                {
                    AutomationJob job = GetAutomationJobOfTestEnvironment(testEnvironment);
                    try
                    {
                        job.AddJobProgressInformation(string.Format("Start to install the Saber Agent Service on environment [{0}] for Job [{1}]", testEnvironment.Name, job.Name));

                        //RemoteInstallTestAgentWindowsServiceConcurrentlyAndWaitToFinish(testEnvironment);
                        if (RemoteInstallTestAgentWindowsFormAppConcurrentlyAndWaitToFinsh(testEnvironment))
                        {
                            job.AddJobProgressInformation(string.Format("The Saber Agent service has been installed on environment [{0}] for Job [{1}]", testEnvironment.Name, job.Name));
                            testEnvironment.SetEnvironmentStatus(EnvironmentStatus.AgentServiceInstalledAndReady);
                        }
                        else
                        {
                            job.AddJobProgressInformation(string.Format("The Saber Agent service failed to be installed on environment [{0}] for Job [{1}]", testEnvironment.Name, job.Name));
                            job.SetJobsStatus(JobStatus.Failed);
                        }
                    }
                    catch (Exception ex)
                    {
                        //TODO, exception handling, we may need to revert the record in DB -> reinstall the windows services.
                        ATFEnvironment.Log.logger.Error(string.Format("Error happened when install the Saber Agent service on machine [{0}]", testEnvironment.Name), ex);
                        job.SetJobsStatus(JobStatus.Failed);
                    }
                }
            );
        }
Exemplo n.º 10
0
 public static void Initialize(TestEnvironment environment)
 {
     S1BuilderInstallHelper.environment = environment;
     S1BuilderInstallHelper.config = new TestEnvironmentConfigHelper(environment.Config);
     S1BuilderInstallHelper.domainName = config.DomainConfiguration.Name;
     S1BuilderInstallHelper.domainAdmin = config.DomainConfiguration.Adminstrator;
     S1BuilderInstallHelper.domainAdminPassword = config.DomainConfiguration.Password;
 }
Exemplo n.º 11
0
        public virtual bool DisposeEnvironment(TestEnvironment environment)
        {
            DeleteVCloudEnvironmentAsync(environment);

            return true;
        }
Exemplo n.º 12
0
 private static bool IsEnvironmentError(TestEnvironment environment)
 {
     if (environment.EnvironmentStatus == EnvironmentStatus.Error)
     {
         return true;
     }
     else
     {
         return false;
     }
 }
Exemplo n.º 13
0
 private static bool DoesBeginToPrepareEnvironment(TestEnvironment environment)
 {
     if (environment.EnvironmentStatus == EnvironmentStatus.New ||
         environment.EnvironmentStatus == EnvironmentStatus.Setup ||
         environment.EnvironmentStatus == EnvironmentStatus.MachinesReady ||
         environment.EnvironmentStatus == EnvironmentStatus.AgentServiceInstalledAndReady ||
         environment.EnvironmentStatus == EnvironmentStatus.BuildInstalled ||
         environment.EnvironmentStatus == EnvironmentStatus.AgentServiceInstalling ||
         environment.EnvironmentStatus == EnvironmentStatus.Error ||
         environment.EnvironmentStatus == EnvironmentStatus.Ocuppied)//we'll handle the error when monitor the preparing job
     {
         return true;
     }
     else
     {
         return false;
     }
 }
Exemplo n.º 14
0
        /// <summary>
        /// Invoked when <see cref="ToEntity"/> operation is about to return.
        /// </summary>
        /// <param name="entity"><see cref="TestEnvironment"/> converted from <see cref="TestEnvironmentDTO"/>.</param>
partial         static void OnEntity(this TestEnvironmentDTO dto, TestEnvironment entity);
Exemplo n.º 15
0
        /// <summary>
        /// Converts this instance of <see cref="TestEnvironmentDTO"/> to an instance of <see cref="TestEnvironment"/>.
        /// </summary>
        /// <param name="dto"><see cref="TestEnvironmentDTO"/> to convert.</param>
        public static TestEnvironment ToEntity(this TestEnvironmentDTO dto)
        {
            if (dto == null) return null;

            var entity = new TestEnvironment();

            entity.EnvironmentId = dto.EnvironmentId;
            entity.ProviderId = dto.ProviderId;
            entity.Name = dto.Name;
            entity.Type = dto.Type;
            entity.Status = dto.Status;
            entity.CreateDate = dto.CreateDate;
            entity.ModifyDate = dto.ModifyDate;
            entity.Config = dto.Config;
            entity.Description = dto.Description;

            dto.OnEntity(entity);

            return entity;
        }
Exemplo n.º 16
0
        private static void RemoteInstallTestAgentWindowsServiceConcurrentlyAndWaitToFinish(TestEnvironment environment)
        {
            string domain = string.Empty;
            string administrator = string.Empty;
            string password = string.Empty;
            string serviceBinaryName = "SaberAgent.WinService.exe";
            string serviceName = "SaberAgent";
            string serviceDisplayName = "Galaxy Saber Agent";
            string sourceHostName = ConfigurationManager.AppSettings["SaberAgentInstallerHostMachine"];
            string sourceHostAdmin = ConfigurationManager.AppSettings["SaberAgentInstallerHostMachineAdmin"];
            string sourceHostAdminPassword = ConfigurationManager.AppSettings["SaberAgentInstallerHostMachineAdminPassword"];
            string sourceInstallPath = ConfigurationManager.AppSettings["SaberAgentInstallerPath"];
            string targetSharePath = @"\C$\SaberAgent";
            string targetIntallPath = @"C:\SaberAgent";
            string testAgentConfigFileName = "Environment.xml";
            string configFilePath = sourceInstallPath + @"\" + "Config";
            NetUseHelper.NetUserMachine(sourceHostName, sourceHostAdmin, sourceHostAdminPassword);

            TestEnvironmentConfigHelper config = new TestEnvironmentConfigHelper(environment.Config);
            EnvironmentType type = config.Type;
            if (type == EnvironmentType.Residence_Together)
            {
                domain = config.SUTConfiguration.SUTDomainConfig.Name;
                administrator = config.SUTConfiguration.SUTDomainConfig.Adminstrator;
                password = config.SUTConfiguration.SUTDomainConfig.Password;
                System.Threading.Tasks.Task[] tasks = new System.Threading.Tasks.Task[config.SUTConfiguration.Machines.Count];
                int i = 0;
                foreach (Machine m in config.SUTConfiguration.Machines)
                {
                    Machine temp = m;//it's critical
                    tasks[i] = System.Threading.Tasks.Task.Factory.StartNew(
                        () =>
                        {
                            RemoteInstallTestAgentWindowsServiceOnMachine(temp, targetSharePath, domain, administrator, password, environment.Config, testAgentConfigFileName, sourceInstallPath, targetIntallPath, serviceName, serviceBinaryName, serviceDisplayName);
                        });
                    i++;
                }
                System.Threading.Tasks.Task.WaitAll(tasks);
            }
            else if (type == EnvironmentType.SUTAlone)
            {
                //do nothing
            }
            else if (type == EnvironmentType.TestAgentAlone)
            {
                domain = config.TestAgentConfiguration.TestAgentDomainConfig.Name;
                administrator = config.TestAgentConfiguration.TestAgentDomainConfig.Adminstrator;
                password = config.TestAgentConfiguration.TestAgentDomainConfig.Password;
                System.Threading.Tasks.Task[] tasks = new System.Threading.Tasks.Task[config.TestAgentConfiguration.Machines.Count];
                int i = 0;
                foreach (Machine m in config.TestAgentConfiguration.Machines)
                {
                    Machine temp = m;
                    tasks[i] = System.Threading.Tasks.Task.Factory.StartNew(
                        () =>
                        {
                            RemoteInstallTestAgentWindowsServiceOnMachine(temp, targetSharePath, domain, administrator, password, environment.Config, testAgentConfigFileName, sourceInstallPath, targetIntallPath, serviceName, serviceBinaryName, serviceDisplayName);
                        });
                    i++;
                }
                System.Threading.Tasks.Task.WaitAll(tasks);
                ATFEnvironment.Log.logger.Info(string.Format("Saber Agents are installed on all the machines in Environment {0} successfully.", environment.Name));

            }
        }
Exemplo n.º 17
0
        private static bool RemoteInstallTestAgentWindowsFormAppConcurrentlyAndWaitToFinsh(TestEnvironment environment)
        {
            int timeoutMunites = 30;
            string domain = string.Empty;
            string administrator = string.Empty;
            string password = string.Empty;

            string sourceHostName = ConfigurationManager.AppSettings["SaberAgentInstallerHostMachine"];
            string sourceHostAdmin = ConfigurationManager.AppSettings["SaberAgentInstallerHostMachineAdmin"];
            string sourceHostAdminPassword = ConfigurationManager.AppSettings["SaberAgentInstallerHostMachineAdminPassword"];
            string sourceInstallPath = ConfigurationManager.AppSettings["SaberAgentInstallerPath"];

            string targetSharePath = @"\C$\SaberAgent";
            string targetIntallPath = @"C:\SaberAgent";
            string testAgentConfigFileName = "Environment.xml";
            string configFilePath = sourceInstallPath + @"\" + "Config";

            AutomationJob job = EnvironmentManager.GetAutomationJobOfTestEnvironment(environment);

            int i = 0;
            while (!NetUseHelper.NetUserMachine(sourceHostName, sourceHostAdmin, sourceHostAdminPassword) && i < 10)
            {
                ATFEnvironment.Log.logger.Error(string.Format("Cannot net use the remote machine [{0}]", sourceHostName));
                System.Threading.Thread.Sleep(1000 * 10);
                i++;
            }
            if (i >= 10)
            {
                return false;
            }

            TestEnvironmentConfigHelper config = new TestEnvironmentConfigHelper(environment.Config);
            EnvironmentType type = config.Type;
            if (type == EnvironmentType.Residence_Together)//For Residence_Together, currently there're all Windows Machine
            {
                domain = config.SUTConfiguration.SUTDomainConfig.Name;
                administrator = config.SUTConfiguration.SUTDomainConfig.Adminstrator;
                password = config.SUTConfiguration.SUTDomainConfig.Password;
                System.Threading.Tasks.Task[] tasks = new System.Threading.Tasks.Task[config.SUTConfiguration.Machines.Count];
                i = 0;
                foreach (Machine m in config.SUTConfiguration.Machines)//TODO, here seems only need to install on the test agent machine. Neil
                {
                    Machine temp = m;//it's critical
                    if (IsSaberAgentRequiredInThisMachine(temp))//
                    {
                        tasks[i] = System.Threading.Tasks.Task.Factory.StartNew(
                            () =>
                            {
                                string message = string.Format("Start to install Saber Agent on SUT machine [{0}].", temp.Name);
                                job.AddJobProgressInformation(message);
                                bool ret = RemoteInstallTestAgentWindowsFormAppOnMachine(temp, targetSharePath, domain, administrator, password, environment.Config, testAgentConfigFileName, sourceInstallPath, targetIntallPath);
                                if (ret == true)
                                {
                                    message = string.Format("Saber Agent on Agent machine [{0}] installed.", temp.Name);
                                }
                                else
                                {
                                    message = string.Format("Saber Agent was failed to install on Agent machine [{0}].", temp.Name);
                                }
                                job.AddJobProgressInformation(message);
                            });

                    }
                    else
                    {
                        tasks[i] = System.Threading.Tasks.Task.Factory.StartNew(
                            () =>
                            { }
                            );
                    }
                    i++;
                }

                try
                {
                    if (System.Threading.Tasks.Task.WaitAll(tasks, 1000 * 60 * timeoutMunites))
                    {
                        ATFEnvironment.Log.logger.Info(string.Format("The Saber Agent was installed on all the machine on environment [{0}] successfully.", environment.Name));
                        return true;
                    }
                    else
                    {
                        ATFEnvironment.Log.logger.Info(string.Format("It's timeout to install Saber Agent on all the machine on environment [{0}] within {1} minutes.", environment.Name, timeoutMunites));
                        return false;
                    }
                }
                catch (AggregateException ex)
                {
                    foreach (Exception e in ex.InnerExceptions)
                    {
                        ATFEnvironment.Log.logger.Error(e);
                    }
                    return false;
                }
                catch (Exception ex)
                {
                    ATFEnvironment.Log.logger.Error(ex);
                    return false;
                }
            }
            else if (type == EnvironmentType.SUTAlone)
            {
                //do nothing
                return true;
            }
            else if (type == EnvironmentType.TestAgentAlone)
            {
                domain = config.TestAgentConfiguration.TestAgentDomainConfig.Name;
                administrator = config.TestAgentConfiguration.TestAgentDomainConfig.Adminstrator;
                password = config.TestAgentConfiguration.TestAgentDomainConfig.Password;
                System.Threading.Tasks.Task[] tasks = new System.Threading.Tasks.Task[config.TestAgentConfiguration.Machines.Count];
                i = 0;
                //Not all the test agents configured in the xml need the test agent, some agent is the remote agent on linux system
                foreach (Machine m in GetMachinesNeedTestAgentInstalledOn(config))
                {
                    Machine temp = m;
                    if (IsSaberAgentRequiredInThisMachine(temp))
                    {
                        tasks[i] = System.Threading.Tasks.Task.Factory.StartNew(
                            () =>
                            {
                                string message = string.Format("Start to install Saber Agent on Agent machine [{0}].", temp.Name);
                                job.AddJobProgressInformation(message);
                                bool ret = RemoteInstallTestAgentWindowsFormAppOnMachine(temp, targetSharePath, domain, administrator, password, environment.Config, testAgentConfigFileName, sourceInstallPath, targetIntallPath);
                                if (ret == true)
                                {
                                    message = string.Format("Saber Agent on Agent machine [{0}] installed.", temp.Name);
                                }
                                else
                                {
                                    message = string.Format("Saber Agent was failed to install on Agent machine [{0}].", temp.Name);
                                }
                                job.AddJobProgressInformation(message);
                            });
                    }
                    else
                    {
                        tasks[i] = System.Threading.Tasks.Task.Factory.StartNew(
                                                  () => { });
                    }
                    i++;
                }
                try
                {
                    if (System.Threading.Tasks.Task.WaitAll(tasks, 1000*60*timeoutMunites))
                    {
                        ATFEnvironment.Log.logger.Info(string.Format("The Saber Agent was installed on all the machine on environment [{0}] successfully.", environment.Name));
                        return true;
                    }
                    else
                    {
                        ATFEnvironment.Log.logger.Info(string.Format("It's timeout to install Saber Agent on all the machine on environment [{0}] within {1} minutes.", environment.Name, timeoutMunites));
                        return false;
                    }
                }
                catch (AggregateException ex)
                {
                    foreach (Exception e in ex.InnerExceptions)
                    {
                        ATFEnvironment.Log.logger.Error(e);
                    }
                    return false;
                }
                catch (Exception ex)
                {
                    ATFEnvironment.Log.logger.Error(ex);
                    return false;
                }
            }
            else
            {
                return false;
            }
        }
Exemplo n.º 18
0
        protected void DeleteVCloudEnvironmentAsync(TestEnvironment environment)
        {
            environment.SetEnvironmentStatus(EnvironmentStatus.Disposing);
            System.Threading.Tasks.Task.Factory.StartNew
            (
               () =>
               {
                   try
                   {
                       ATFEnvironment.Log.logger.Debug(string.Format("Disposing Envrionment Id = {0}, Name= {1}", environment.EnvironmentId, environment.Name));

                       Vapp vApp = VCloud.GetVappByName(Organization, VDC, environment.Name);

                       if (vApp != null)
                       {
                           var status = VCloud.GetVAppStatus(vApp);

                           if (!(status == vAppStatus.Undeploy || status == vAppStatus.Error))
                           {
                               ATFEnvironment.Log.logger.Debug("start undeploy vApp: " + environment.Name);
                               VCloud.UndeployVapp(vApp);
                               ATFEnvironment.Log.logger.Debug("finish undeploy vApp: " + environment.Name);
                           }

                           ATFEnvironment.Log.logger.Debug("start delete vApp: " + environment.Name);
                           VCloud.DeleteVapp(vApp);
                           ATFEnvironment.Log.logger.Debug("finish delete vApp: " + environment.Name);
                       }
                   }
                   catch (Exception ex)
                   {
                       ATFEnvironment.Log.logger.Error(string.Format("Failed to dispose envrionment: {0}. Exception: {1}", environment.Name, ex.Message), ex);
                       environment.SetEnvironmentStatus(EnvironmentStatus.Discard);//here we set the environment to be discard. Because this is a async operation, it's not reasonable to throw an exception.
                   }
               }
               );
        }
Exemplo n.º 19
0
        protected void DeployVCloudEnvironmentAsync(TestEnvironment environment, int timeout)
        {
            System.Threading.Tasks.Task.Factory.StartNew
            (
                () =>
                {
                    try
                    {
                        var vApp = VCloud.GetVappByName(Organization, VDC, environment.Name);

                        ATFEnvironment.Log.logger.Debug("start deploy vApp: " + environment.Name);
                        VCloud.DeployVapp(vApp, true, timeout, false);
                        ATFEnvironment.Log.logger.Debug("finish deploy vApp: " + environment.Name);
                    }
                    catch (Exception ex)
                    {
                        string errorMsg = string.Format("Failed to Deploy vApp by template: {0}", environment.Description);
                        ATFEnvironment.Log.logger.Error(errorMsg, ex);
                        environment.SetEnvironmentStatus(EnvironmentStatus.Error);//here we set the environment to be error. Because this is a async operation, it's not reasonable to throw an exception.
                    }
                }
            );
        }
Exemplo n.º 20
0
 private static bool IsEnvironmentReady(TestEnvironment environment)
 {
     TestEnvironmentConfigHelper config = new TestEnvironmentConfigHelper(environment.Config);
     EnvironmentType type = config.Type;
     if (type == EnvironmentType.SUTAlone || type == EnvironmentType.Residence_Together)
     {
         if (environment.EnvironmentStatus == EnvironmentStatus.Ready)
         {
             return true;
         }
         else
         {
             return false;
         }
     }
     else if (type == EnvironmentType.TestAgentAlone)
     {
         if (environment.EnvironmentStatus == EnvironmentStatus.AgentServiceInstalledAndReady ||
             environment.EnvironmentStatus == EnvironmentStatus.Ready || environment.EnvironmentStatus == EnvironmentStatus.Ocuppied)
         {
             return true;
         }
         else
         {
             return false;
         }
     }
     else
     {
         //code should never run to here
         return false;
     }
 }
Exemplo n.º 21
0
        private void DeployAutomationScriptsOfJob(TestEnvironment environment)
        {
            TestEnvironmentConfigHelper helper = new TestEnvironmentConfigHelper(environment.Config);

            foreach (Machine m in helper.TestAgentConfiguration.Machines)
            {
                if (m.Roles.FindAll(r => r.Key == AgentType.RemoteAgent).Count() > 0)//For the remote Agent
                {
                    string message = string.Format("Start to copy automation scripts to remote agent [{0}]", m.Name);

                    job2Run.AddJobProgressInformation(message);

                    SaberAgent.Log.logger.Info(message);

                    string administrator = string.IsNullOrEmpty(m.Administrator)? helper.DomainConfiguration.Adminstrator:m.Administrator;

                    string password = string.IsNullOrEmpty(m.Password)?helper.DomainConfiguration.Password:m.Password;

                    //Clear the existing code
                    message = string.Format("SSHWrapper.DeleteRemoteFolder({0}, {1}, {2}, {3})",m.ExternalIP, administrator, password, RemoteAgentScriptsRootPath);
                    SaberAgent.Log.logger.Debug(message);
                    SSHWrapper.DeleteRemoteFolder(m.ExternalIP, administrator, password, RemoteAgentScriptsRootPath);

                    //copy the automation source code to it
                    message = string.Format("SSHWrapper.CopyDirectoryToRemote({0}, {1}, {2}, {3}, {4})", m.ExternalIP, administrator, password, LocalScriptRootPath, RemoteAgentScriptsRootPath);
                    SaberAgent.Log.logger.Debug(message);
                    SSHWrapper.CopyDirectoryToRemote(m.ExternalIP, administrator, password, LocalScriptRootPath, RemoteAgentScriptsRootPath);

                    message = string.Format("Folder [{0}] is copied to [{1}] on machine [{2}]", LocalScriptRootPath, RemoteAgentScriptsRootPath, m.Name);
                    SaberAgent.Log.logger.Info(message);

                    //Clear the config file
                    string remoteAgentConfigPath = string.Format("{0}/Config", RemoteAgentRootPath);

                    message = string.Format(" SSHWrapper.DeleteRemoteFolder({0}, {1}, {2}, {3})", m.ExternalIP, administrator, password, remoteAgentConfigPath);
                    SaberAgent.Log.logger.Debug(message);
                    SSHWrapper.DeleteRemoteFolder(m.ExternalIP, administrator, password, remoteAgentConfigPath);

                    //Copy the config file to remote
                    message = string.Format("SSHWrapper.CopyDirectoryToRemote({0}, {1}, {2}, {3}, {4})", m.ExternalIP, administrator, password, SaberAgentConfigFolder, remoteAgentConfigPath);
                    SaberAgent.Log.logger.Debug(message);
                    SSHWrapper.CopyDirectoryToRemote(m.ExternalIP, administrator, password, SaberAgentConfigFolder, remoteAgentConfigPath);

                    message = string.Format("Folder [{0}] is copied to [{1}] on machine [{2}]", SaberAgentConfigFolder, remoteAgentConfigPath, m.Name);

                    SaberAgent.Log.logger.Info(message);
                }
            }
        }
Exemplo n.º 22
0
 public abstract void CollectProductionLogsAfterExecutionToLocal(TestEnvironment environment, string resultRootPath);
Exemplo n.º 23
0
 public static void Initialize(TestEnvironment environment)
 {
     DPSearchBuilderInstallerHelper.environment = environment;
     DPSearchBuilderInstallerHelper.config = new TestEnvironmentConfigHelper(environment.Config);
     DPSearchBuilderInstallerHelper.sutDomainName = config.SUTConfiguration.SUTDomainConfig.Name;
     DPSearchBuilderInstallerHelper.sutDomainAdmin = config.SUTConfiguration.SUTDomainConfig.Adminstrator;
     DPSearchBuilderInstallerHelper.sutDomainAdminPassword = config.SUTConfiguration.SUTDomainConfig.Password;
     DPSearchBuilderInstallerHelper.remoteAgent = getRemoteAgent();
     DPSearchBuilderInstallerHelper.job = getAutomationJob();
     DPSearchBuilderInstallerHelper.build = getBuild();
 }
Exemplo n.º 24
0
        /// <summary>
        /// Get the correspording SUT of the Test Agent environment for the same job
        /// </summary>
        /// <param name="environment"></param>
        /// <returns></returns>
        private static TestEnvironment GetSUTEnvironmentOfTestAgentEnvironment(TestEnvironment environment)
        {
            using (ES1AutomationEntities context = new ES1AutomationEntities())
            {
                AutomationJob job = GetAutomationJobOfTestEnvironment(environment);
                if (job.SUTEnvironmentId == null)
                {
                    return null;
                }
                else
                {
                    return (from e in context.TestEnvironments
                            where e.EnvironmentId == job.SUTEnvironmentId.Value
                            select e).FirstOrDefault();
                }

            }
        }
Exemplo n.º 25
0
 public abstract void CheckPreconditionForEachTestExecution(TestEnvironment environment);
Exemplo n.º 26
0
        /// <summary>
        /// Get test environment detail config
        /// </summary>
        /// <returns>
        /// A list of machines in the 
        /// Format of each item is a key-value pair.
        ///
        /// Example:
        ///  List item 1:
        ///     name = DC01
        ///     ip   = 192.168.8.1
        ///     role = DC
        ///     os   = windows server 2008R2
        ///  List item 2:
        ///     name = Exchange01
        ///     ip   = 192.168.8.2
        ///     role = exchange server
        ///     os   = windows server 2008R2
        /// 
        /// </returns>
        public virtual IList<IDictionary<string, string>> GetEnvironmentConfig(TestEnvironment environment)
        {
            var configs = new List<IDictionary<string, string>>();

            XElement config = XElement.Parse(environment.Config);

            foreach (var machineElement in config.Elements("machine"))
            {
                IDictionary<string, string> machineDic = new Dictionary<string, string>();

                foreach (var machineAttr in machineElement.Attributes())
                {
                    machineDic.Add(machineAttr.Name.ToString(), machineAttr.Value.ToString());
                }

                configs.Add(machineDic);
            }

            return configs;
        }
Exemplo n.º 27
0
 public abstract void InstallProduct(TestEnvironment environment);
Exemplo n.º 28
0
        /// <summary>
        /// Refresh environment status
        /// </summary>
        /// <param name="environment"></param>
        public virtual void RefreshEnvironmentStatus(TestEnvironment environment)
        {
            TestEnvironmentConfigHelper config = new TestEnvironmentConfigHelper(environment.Config);
            EnvironmentType type = config.Type;
            EnvironmentDeploymentType deployType = EnvironmentDeploymentType.Undefined;
            vAppStatus status = vAppStatus.Unknow;

            switch (type)
            {
                case EnvironmentType.Residence_Together:
                    deployType = config.SUTConfiguration.DeploymentType;
                    break;
                case EnvironmentType.SUTAlone:
                    deployType = config.SUTConfiguration.DeploymentType;
                    break;
                case EnvironmentType.TestAgentAlone:
                    deployType = config.TestAgentConfiguration.DeploymentType;
                    break;
            }

            switch (environment.EnvironmentStatus)
            {
                case EnvironmentStatus.New:
                    if (deployType == EnvironmentDeploymentType.ToBeCreated)
                    {
                        try
                        {
                            if (IsAllowNewVappDeploy())
                            {
                                RequestEnvironment(environment);
                            }
                        }
                        catch (Exception ex)
                        {
                            ATFEnvironment.Log.logger.Error(ex);
                        }
                    }
                    else
                    {
                        environment.SetEnvironmentStatus(EnvironmentStatus.AgentServiceInstalledAndReady);
                    }
                    break;

                case EnvironmentStatus.Setup:
                    status = vAppStatus.Unknow;
                    try
                    {
                        status = VCloud.GetVAppStatus(Organization, VDC, environment.Name);
                    }
                    catch (Exception ex)
                    {
                        ATFEnvironment.Log.logger.Error("Failed to get the status of vAPP.", ex);
                    }
                    switch (status)
                    {
                        case vAppStatus.Error:
                            environment.SetEnvironmentStatus(EnvironmentStatus.Error);
                            break;

                        case vAppStatus.Ready:
                            UpdateEnvironmentConfig(environment);
                            environment.SetEnvironmentStatus(EnvironmentStatus.MachinesReady);
                            break;

                        case vAppStatus.NotExist://Neil, sometimes the vAPP is not created yet, and request another environment with the same name will cause exception.
                            //if (IsAllowNewVappDeploy())
                            //{
                            //    RequestEnvironment(environment);
                            //}
                            break;

                        // redeploy
                        case vAppStatus.Unknow:
                        case vAppStatus.Undeploy://Neil, The deployment will be done when request the environment, here we did nothing.

                            //if (IsAllowNewVappDeploy())
                            //{
                            //    DeployVCloudEnvironmentAsync(environment, 1000 * 60 * 30);
                            //}
                            break;
                    }

                    break;

                case EnvironmentStatus.MachinesReady:

                    break;

                case EnvironmentStatus.AgentServiceInstalledAndReady:

                    break;

                case EnvironmentStatus.BuildInstalled:

                    break;

                case EnvironmentStatus.Ready:

                    break;

                case EnvironmentStatus.Error:

                    break;

                case EnvironmentStatus.Discard:
                    DisposeEnvironment(environment);
                    break;

                case EnvironmentStatus.Disposing:
                    status = vAppStatus.Unknow;
                    try
                    {
                        status = VCloud.GetVAppStatus(Organization, VDC, environment.Name);
                    }
                    catch (Exception ex)
                    {
                        ATFEnvironment.Log.logger.Error("Failed to get the status of vAPP.", ex);
                    }
                    switch (status)
                    {
                        case vAppStatus.NotExist:
                            environment.SetEnvironmentStatus(EnvironmentStatus.Disposed);
                            break;

                        case vAppStatus.Ready:
                            DisposeEnvironment(environment);
                            break;

                        case vAppStatus.Undeploy:
                            DisposeEnvironment(environment);
                            break;

                        case vAppStatus.Error:
                            DisposeEnvironment(environment);
                            break;
                    }

                    break;
            }
        }
Exemplo n.º 29
0
 public abstract bool WaitAllMachinesStartedAfterReboot(TestEnvironment environment);
Exemplo n.º 30
0
 public virtual void RequestEnvironment(TestEnvironment environment)
 {
     // create vApp in backgroud, timeout 30 minutes
     CreateVCloudEnvironmentAsync(environment, 1000 * 60 * 30);
 }