示例#1
0
        private string GetDeploymentName(string slot)
        {
            Func <string, Deployment> func = null;

            try
            {
                MoveAzureDeploymentCommand moveAzureDeploymentCommand = this;
                if (func == null)
                {
                    func = (string s) => base.Channel.GetDeploymentBySlot(s, this.ServiceName, slot.ToString());
                }
                Deployment deployment = ((CmdletBase <IServiceManagement>)moveAzureDeploymentCommand).RetryCall <Deployment>(func);
                if (deployment != null)
                {
                    string name = deployment.Name;
                    return(name);
                }
            }
            catch (CommunicationException communicationException)
            {
            }
            return(null);
        }
        public void ExecuteTestCase(MoveAzureDeploymentTestInputParameters parameters)
        {
            var channel = new SimpleServiceManagement
            {
                GetDeploymentBySlotThunk = ar =>
                {
                    if (ar.Values["deploymentSlot"].ToString() == DeploymentSlotType.Production)
                    {
                        if (parameters.ProductionDeployment == null)
                        {
                            throw new ServiceManagementClientException(HttpStatusCode.NotFound, new ServiceManagementError(), String.Empty);
                        }
                        return parameters.ProductionDeployment;
                    }
                    if (ar.Values["deploymentSlot"].ToString() == DeploymentSlotType.Staging)
                    {
                        if (parameters.StagingDeployment == null)
                        {
                            throw new ServiceManagementClientException(HttpStatusCode.NotFound, new ServiceManagementError(), String.Empty);
                        }
                        return parameters.StagingDeployment;
                    }

                    return null;
                },
                SwapDeploymentThunk = ar =>
                {
                    var input = (SwapDeploymentInput)ar.Values["input"];

                    if (input.Production == null && parameters.ProductionDeployment == null)
                    {
                        if (input.SourceDeployment != parameters.StagingDeployment.Name)
                        {
                            Assert.Fail("Expected values Staging/Prod'{0},{1}', found '{2},{3}'",
                                parameters.StagingDeployment.Name, null, input.SourceDeployment, null);
                        }
                    }
                    else if (input.Production != parameters.ProductionDeployment.Name || input.SourceDeployment != parameters.StagingDeployment.Name)
                    {
                        Assert.Fail("Expected values Staging/Prod'{0},{1}', found '{2},{3}'",
                            parameters.StagingDeployment.Name, parameters.ProductionDeployment.Name, input.SourceDeployment, input.Production);
                    }
                }
            };

            // Test
            var moveAzureDeployment = new MoveAzureDeploymentCommand(channel)
            {
                ShareChannel = true,
                CommandRuntime = new MockCommandRuntime(),
                ServiceName = "testService",
                CurrentSubscription = new SubscriptionData
                {
                    SubscriptionId = "testId"
                }
            };

            try
            {
                moveAzureDeployment.ExecuteCommand();
                if(parameters.ThrowsException)
                {
                    Assert.Fail(parameters.Description);
                }
            }
            catch (Exception e)
            {
                if(e.GetType() != parameters.ExceptionType)
                {
                    Assert.Fail("Expected exception type is {0}, however found {1}", parameters.ExceptionType, e.GetType());
                }
                if(!parameters.ThrowsException)
                {
                    Assert.Fail("{0} fails unexpectedly: {1}", parameters.Description, e);
                }
            }
        }
示例#3
0
        public void MoveDeploymentProcess()
        {
            Func <string, Deployment> func   = null;
            Action <string>           action = null;

            using (OperationContextScope operationContextScope = new OperationContextScope((IContextChannel)base.Channel))
            {
                try
                {
                    new List <PersistentVMRoleContext>();
                    MoveAzureDeploymentCommand moveAzureDeploymentCommand = this;
                    if (func == null)
                    {
                        func = (string s) => base.Channel.GetDeploymentBySlot(s, this.ServiceName, "Production");
                    }
                    Deployment deployment = ((CmdletBase <IServiceManagement>)moveAzureDeploymentCommand).RetryCall <Deployment>(func);
                    if (deployment.RoleList != null && string.Compare(deployment.RoleList[0].RoleType, "PersistentVMRole", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        throw new ArgumentException("Cannot Move Deployments with Virtual Machines Present");
                    }
                }
                catch (CommunicationException communicationException1)
                {
                    CommunicationException communicationException = communicationException1;
                    if (communicationException as EndpointNotFoundException == null || base.IsVerbose())
                    {
                        this.WriteErrorDetails(communicationException);
                    }
                }
            }
            string deploymentName = this.GetDeploymentName("Production");
            string str            = this.GetDeploymentName("Staging");

            if (str != null)
            {
                SwapDeploymentInput swapDeploymentInput = new SwapDeploymentInput();
                swapDeploymentInput.SourceDeployment = str;
                swapDeploymentInput.Production       = deploymentName;
                using (OperationContextScope operationContextScope1 = new OperationContextScope((IContextChannel)base.Channel))
                {
                    try
                    {
                        CmdletExtensions.WriteVerboseOutputForObject(this, swapDeploymentInput);
                        MoveAzureDeploymentCommand moveAzureDeploymentCommand1 = this;
                        if (action == null)
                        {
                            action = (string s) => base.Channel.SwapDeployment(s, this.ServiceName, swapDeploymentInput);
                        }
                        ((CmdletBase <IServiceManagement>)moveAzureDeploymentCommand1).RetryCall(action);
                        Operation operation = base.WaitForOperation(base.CommandRuntime.ToString());
                        ManagementOperationContext managementOperationContext = new ManagementOperationContext();
                        managementOperationContext.set_OperationDescription(base.CommandRuntime.ToString());
                        managementOperationContext.set_OperationId(operation.OperationTrackingId);
                        managementOperationContext.set_OperationStatus(operation.Status);
                        ManagementOperationContext managementOperationContext1 = managementOperationContext;
                        base.WriteObject(managementOperationContext1, true);
                    }
                    catch (CommunicationException communicationException3)
                    {
                        CommunicationException communicationException2 = communicationException3;
                        this.WriteErrorDetails(communicationException2);
                    }
                }
                return;
            }
            else
            {
                throw new ArgumentException("The Staging deployment slot is empty.");
            }
        }