예제 #1
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);
        }
예제 #2
0
        /// <summary>
        /// Handle the test environment with machines ready, work include:
        /// 1. Install the Saber Agent services on the machines and start the services on remote machine
        /// 2. Update the environment information for the TestAgent and SUT, then the TestAgent and SUT know the details of each other(mainly IPs here)
        /// 3. Specify what kinds of works the Saber Agent services will take after it restarted. such as 
        ///   1). to tell services hosted on test agent to install the S1 build
        ///   2). to tell the services hosted on test agent to run the test case for which job
        /// 4. After that, the test environment status is AgentServiceInstalling or AgentServiceInstalledAndReady
        /// Below actions are taken by other components
        /// 5. The saber agent service on the test agent will install the S1 build, before that it'll wait the SUT to be AgentServiceInstalledAndReady
        /// 6. The saber agent service will set the environment status to be BuildInstalled
        /// 7. Then the environment manager will restart all the machines in SUT
        /// 8. After restarted, the saber agent in test agent will check all the machines in SUT are started and start to run the test cases.
        /// </summary>
        /// <param name="environment"></param>
        public void HandleTestEnvironmentWithStatusMachinesReady(TestEnvironment environment)
        {
            EnvironmentType type = EnvironmentConfigHelper.GetResidenceType(environment.Config);
            if (type == EnvironmentType.Residence_Together)
            {
                //add the jobId into the configuration file to let the Test Agent know which job the test agent is for.
                TestEnvironmentConfigHelper config = new TestEnvironmentConfigHelper(environment.Config);
                config.TestAgentConfiguration.Categories.Add(string.Format("JobId={0}", EnvironmentManager.GetAutomationJobOfTestEnvironment(environment).JobId.ToString()));
                //config.TestAgentConfiguration.Categories.Add(string.Format("mode={0}", SaberAgentMode.InstallS1Build));
                environment.SetEnvironmentConfig(config.ToXML());
                environment.SetEnvironmentStatus(EnvironmentStatus.AgentServiceInstalling);
                try
                {
                    InstallTestAgentWindowsServiceOnEnvironmentAsynchronous(environment);
                }
                catch (Exception ex)
                {
                    ATFEnvironment.Log.logger.Error(string.Format("Execption captured when install test agent windows service on environment asynchronously for environment {0}",environment.EnvironmentId), ex);
                }

                ATFEnvironment.Log.logger.Info(string.Format("Test Agents started to be installed on environment {0}", environment.Name));
                ATFEnvironment.Log.logger.Info(string.Format("Environment status changes from MachinesReady -> AgentServiceInstalling"));
            }
            else if (type == EnvironmentType.TestAgentAlone)
            {
                //to make sure in the test agent, we have the information about the SUT,
                //we'll first check whether the SUT is MachinesReady,
                //if yes, we'll copy the SUT config to the TestAgent config, then setup the Saber Agent
                //else, do nothing and wait another loop
                TestEnvironment sutEnvironment = EnvironmentManager.GetSUTEnvironmentOfTestAgentEnvironment(environment);
                if (null != sutEnvironment)
                {
                    //if the sut is machine ready or other status after machine ready
                    if (sutEnvironment.EnvironmentStatus == EnvironmentStatus.MachinesReady ||
                        sutEnvironment.EnvironmentStatus == EnvironmentStatus.AgentServiceInstalling ||
                        sutEnvironment.EnvironmentStatus == EnvironmentStatus.AgentServiceInstalledAndReady ||
                        sutEnvironment.EnvironmentStatus == EnvironmentStatus.BuildInstalled ||
                        sutEnvironment.EnvironmentStatus == EnvironmentStatus.Ready
                    )
                    {
                        //update the SUT part of the configuration of the test agent configuration.
                        //then the test agent know the detail of the SUT.
                        TestEnvironmentConfigHelper sutConfig = new TestEnvironmentConfigHelper(sutEnvironment.Config);
                        TestEnvironmentConfigHelper testAgentConfig = new TestEnvironmentConfigHelper(environment.Config);
                        testAgentConfig.SUTConfiguration = sutConfig.SUTConfiguration;
                        environment.SetEnvironmentConfig(testAgentConfig.ToXML());

                        //add the jobId into the configuration file to let the Test Agent know which job the test agent is for.
                        TestEnvironmentConfigHelper config = new TestEnvironmentConfigHelper(environment.Config);
                        config.TestAgentConfiguration.Categories.Add("JobId=" + EnvironmentManager.GetAutomationJobOfTestEnvironment(environment).JobId.ToString());
                        environment.SetEnvironmentConfig(config.ToXML());

                        //Install the Saber Agent service into the environment
                        environment.SetEnvironmentStatus(EnvironmentStatus.AgentServiceInstalling);
                        InstallTestAgentWindowsServiceOnEnvironmentAsynchronous(environment);

                        ATFEnvironment.Log.logger.Info(string.Format("Start to install Saber Agent on environment {0}", environment.Name));
                        ATFEnvironment.Log.logger.Info(string.Format("Environment status changes from MachinesReady -> AgentServiceInstalling"));
                    }
                }
            }
            else if (type == EnvironmentType.SUTAlone)//TODO, do we need to install the build on the SUT? currently we do nothing and assume that the environment is ready
            {
                TestEnvironmentConfigHelper config = new TestEnvironmentConfigHelper(environment.Config);
                config.TestAgentConfiguration.Categories.Add(string.Format("JobId={0}", EnvironmentManager.GetAutomationJobOfTestEnvironment(environment).JobId.ToString()));
                environment.SetEnvironmentConfig(config.ToXML());

                ATFEnvironment.Log.logger.Info(string.Format("Test Agents started to be installed on environment {0}", environment.Name));
                //ATFEnvironment.Log.logger.Info(string.Format("Environment status changes from {0} -> AgentServiceInstalling", environment.EnvironmentStatus));
                environment.SetEnvironmentStatus(EnvironmentStatus.AgentServiceInstalling);
                InstallTestAgentWindowsServiceOnEnvironmentAsynchronous(environment);
                ATFEnvironment.Log.logger.Info(string.Format("Test Agents have been installed on environment {0}", environment.Name));

            }
        }