Ejemplo n.º 1
0
 protected void CleanupArtifactSources(
     string artifactSourceName,
     string location,
     AzureDeploymentManagerClient deploymentManagerClient,
     DeploymentManagerClientHelper clientHelper)
 {
     deploymentManagerClient.ArtifactSources.Delete(
         resourceGroupName: clientHelper.ResourceGroupName,
         artifactSourceName: artifactSourceName);
 }
Ejemplo n.º 2
0
        private Rollout WaitForRolloutTermination(
            string rolloutName,
            AzureDeploymentManagerClient deploymentManagerClient,
            DeploymentManagerClientHelper clientHelper)
        {
            Rollout rollout;

            do
            {
                DeploymentManagerTestUtilities.Sleep(TimeSpan.FromMinutes(1));
                rollout = deploymentManagerClient.Rollouts.Get(
                    resourceGroupName: clientHelper.ResourceGroupName,
                    rolloutName: rolloutName);
            } while (rollout.Status == "Running");

            return(rollout);
        }
Ejemplo n.º 3
0
        private ArtifactSource CreateArtifactSource(
            string storageAccountName,
            string artifactSourceName,
            string location,
            AzureDeploymentManagerClient deploymentManagerClient,
            DeploymentManagerClientHelper clientHelper,
            bool setupContainer = false)
        {
            if (setupContainer)
            {
                this.SetupContainer(storageAccountName, clientHelper);
            }

            var authentication = new SasAuthentication()
            {
                SasUri = clientHelper.GetBlobContainerSasUri(
                    clientHelper.ResourceGroupName,
                    storageAccountName,
                    containerName: EndToEndFunctionalTests.ContainerName)
            };

            var inputArtifactSource = new ArtifactSource(
                location: location,
                sourceType: EndToEndFunctionalTests.ArtifactSourceType,
                authentication: authentication,
                artifactRoot: EndToEndFunctionalTests.ArtifactRoot,
                name: artifactSourceName);

            var artifactSourceResponse = deploymentManagerClient.ArtifactSources.CreateOrUpdate(
                resourceGroupName: clientHelper.ResourceGroupName,
                artifactSourceName: artifactSourceName,
                artifactSourceInfo: inputArtifactSource);

            this.ValidateArtifactSource(inputArtifactSource, artifactSourceResponse);
            return(artifactSourceResponse);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DeploymentManagerClient"/> class.
 /// </summary>
 /// <param name="context">The current Azure session context.</param>
 internal DeploymentManagerClient(IAzureContext context)
 {
     this._client = AzureSession.Instance.ClientFactory.CreateArmClient <AzureDeploymentManagerClient>(context, AzureEnvironment.Endpoint.ResourceManager);
 }
Ejemplo n.º 5
0
        private void RolloutCrudTests(
            string serviceTopologyId,
            string artifactSourceId,
            string serviceUnitId,
            string failureServiceUnitId,
            string stepId,
            string location,
            AzureDeploymentManagerClient deploymentManagerClient,
            DeploymentManagerClientHelper clientHelper)
        {
            var rolloutName        = clientHelper.ResourceGroupName + "Rollout";
            var failureRolloutName = clientHelper.ResourceGroupName + "FailureRollout";

            var userAssignedIdentity = this.SetManagedIdentity(clientHelper);

            var identity = new Identity()
            {
                Type        = "userAssigned",
                IdentityIds = new List <string>()
                {
                    userAssignedIdentity
                }
            };

            var stepGroup = new Step(
                name: "First_Region",
                deploymentTargetId: serviceUnitId)
            {
                PreDeploymentSteps = new List <PrePostStep> ()
                {
                    new PrePostStep(stepId)
                }
            };

            var stepGroupForFailureRollout = new Step(
                name: "FirstRegion",
                deploymentTargetId: failureServiceUnitId);

            var rolloutRequest = new RolloutRequest(
                location: location,
                buildVersion: "1.0.0.0",
                identity: identity,
                targetServiceTopologyId: serviceTopologyId,
                artifactSourceId: artifactSourceId,
                stepGroups: new List <Step>()
            {
                stepGroup
            });

            var createRolloutResponse = deploymentManagerClient.Rollouts.CreateOrUpdate(
                resourceGroupName: clientHelper.ResourceGroupName,
                rolloutName: rolloutName,
                rolloutRequest: rolloutRequest);

            this.ValidateRollout(rolloutRequest, createRolloutResponse);

            // Kick off a rollout that would fail to test restart operation.
            var failureRolloutRequest = new RolloutRequest(
                location: location,
                buildVersion: "1.0.0.0",
                identity: identity,
                targetServiceTopologyId: serviceTopologyId,
                artifactSourceId: artifactSourceId,
                stepGroups: new List <Step>()
            {
                stepGroupForFailureRollout
            });

            var failureRolloutResponse = deploymentManagerClient.Rollouts.CreateOrUpdate(
                resourceGroupName: clientHelper.ResourceGroupName,
                rolloutName: failureRolloutName,
                rolloutRequest: failureRolloutRequest);

            this.ValidateRollout(failureRolloutRequest, failureRolloutResponse);

            // Test Get rollout.
            var rollout = deploymentManagerClient.Rollouts.Get(
                resourceGroupName: clientHelper.ResourceGroupName,
                rolloutName: rolloutName);

            Assert.NotNull(rollout);
            Assert.Equal("Running", rollout.Status);
            Assert.NotNull(rollout.OperationInfo);
            Assert.Equal(0, rollout.OperationInfo.RetryAttempt);

            // Test cancel rollout.
            rollout = deploymentManagerClient.Rollouts.Cancel(
                resourceGroupName: clientHelper.ResourceGroupName,
                rolloutName: rolloutName);

            Assert.NotNull(rollout);
            Assert.Equal("Canceling", rollout.Status);

            this.WaitForRolloutTermination(
                rolloutName,
                deploymentManagerClient,
                clientHelper);

            // Test delete rollout.
            deploymentManagerClient.Rollouts.Delete(
                resourceGroupName: clientHelper.ResourceGroupName,
                rolloutName: rolloutName);

            var cloudException = Assert.Throws <CloudException>(() => deploymentManagerClient.Rollouts.Get(
                                                                    resourceGroupName: clientHelper.ResourceGroupName,
                                                                    rolloutName: rolloutName));

            Assert.Equal(HttpStatusCode.NotFound, cloudException.Response.StatusCode);

            // Check status of rollout expected to fail and attempt restart operation.
            var failureRollout = this.WaitForRolloutTermination(
                failureRolloutName,
                deploymentManagerClient,
                clientHelper);

            Assert.NotNull(failureRollout);
            Assert.Equal("Failed", failureRollout.Status);

            // Test Restart rollout.
            failureRollout = deploymentManagerClient.Rollouts.Restart(
                resourceGroupName: clientHelper.ResourceGroupName,
                rolloutName: failureRolloutName);

            Assert.NotNull(failureRollout);
            Assert.Equal("Running", failureRollout.Status);
            Assert.Equal(1, failureRollout.TotalRetryAttempts);
            Assert.Equal(false.ToString(), failureRollout.OperationInfo.SkipSucceededOnRetry.ToString());
        }
Ejemplo n.º 6
0
        private void StepsCrudTests(
            string serviceTopologyId,
            string artifactSourceId,
            string serviceUnitId,
            string failureServiceUnitId,
            string location,
            DeploymentManagerClientHelper clientHelper,
            AzureDeploymentManagerClient deploymentManagerClient)
        {
            // Test Create step.
            var stepName       = clientHelper.ResourceGroupName + "WaitStep";
            var stepProperties = new WaitStepProperties()
            {
                Attributes = new WaitStepAttributes()
                {
                    Duration = "PT5M"
                }
            };

            var inputStep = new StepResource(
                location: location,
                properties: stepProperties,
                name: stepName);

            var stepResponse = deploymentManagerClient.Steps.CreateOrUpdate(
                resourceGroupName: clientHelper.ResourceGroupName,
                stepName: stepName,
                stepInfo: inputStep);

            this.ValidateStep(inputStep, stepResponse);

            // Test Get step.
            var getStepResource = deploymentManagerClient.Steps.Get(
                resourceGroupName: clientHelper.ResourceGroupName,
                stepName: stepName);

            this.ValidateStep(inputStep, getStepResource);

            this.RolloutCrudTests(
                serviceTopologyId: serviceTopologyId,
                artifactSourceId: artifactSourceId,
                serviceUnitId: serviceUnitId,
                failureServiceUnitId: failureServiceUnitId,
                stepId: getStepResource.Id,
                location: location,
                deploymentManagerClient: deploymentManagerClient,
                clientHelper: clientHelper);

            // Test Update step.
            ((WaitStepProperties)(getStepResource.Properties)).Attributes.Duration = "PT10M";
            var updatedStepResource = deploymentManagerClient.Steps.CreateOrUpdate(
                resourceGroupName: clientHelper.ResourceGroupName,
                stepName: stepName,
                stepInfo: getStepResource);

            this.ValidateStep(getStepResource, updatedStepResource);

            // Test Delete step.
            deploymentManagerClient.Steps.Delete(
                resourceGroupName: clientHelper.ResourceGroupName,
                stepName: stepName);

            var cloudException = Assert.Throws <CloudException>(() => deploymentManagerClient.Steps.Get(
                                                                    resourceGroupName: clientHelper.ResourceGroupName,
                                                                    stepName: stepName));

            Assert.Equal(HttpStatusCode.NotFound, cloudException.Response.StatusCode);
        }
Ejemplo n.º 7
0
        private void ServiceUnitCrudTests(
            ArtifactSource artifactSource,
            ServiceTopologyResource serviceTopologyResource,
            string serviceName,
            string location,
            AzureDeploymentManagerClient deploymentManagerClient,
            DeploymentManagerClientHelper clientHelper)
        {
            var serviceUnitName        = clientHelper.ResourceGroupName + "ServiceUnit";
            var failureServiceUnitName = clientHelper.ResourceGroupName + "InvalidServiceUnit";
            var targetResourceGroup    = clientHelper.ResourceGroupName;
            var artifacts = new ServiceUnitArtifacts()
            {
                ParametersArtifactSourceRelativePath = ParametersFileName,
                TemplateArtifactSourceRelativePath   = TemplateFileName
            };

            var inputServiceUnit = new ServiceUnitResource(
                location: location,
                targetResourceGroup: targetResourceGroup,
                name: serviceUnitName,
                deploymentMode: DeploymentMode.Incremental,
                artifacts: artifacts);

            var createServiceResponse = deploymentManagerClient.ServiceUnits.CreateOrUpdate(
                resourceGroupName: clientHelper.ResourceGroupName,
                serviceTopologyName: serviceTopologyResource.Name,
                serviceName: serviceName,
                serviceUnitName: serviceUnitName,
                serviceUnitInfo: inputServiceUnit);

            this.ValidateServiceUnit(inputServiceUnit, createServiceResponse);

            // Test Get service unit.
            var serviceUnit = deploymentManagerClient.ServiceUnits.Get(
                resourceGroupName: clientHelper.ResourceGroupName,
                serviceTopologyName: serviceTopologyResource.Name,
                serviceName: serviceName,
                serviceUnitName: serviceUnitName);

            this.ValidateServiceUnit(inputServiceUnit, serviceUnit);

            // Create a service unit that fails deployment for failure rollout scenario.
            var invalidArtifacts = new ServiceUnitArtifacts()
            {
                ParametersArtifactSourceRelativePath = InvalidParametersFileName,
                TemplateArtifactSourceRelativePath   = TemplateFileName
            };

            var failureServiceUnitInput = new ServiceUnitResource(
                location: location,
                targetResourceGroup: targetResourceGroup,
                name: failureServiceUnitName,
                deploymentMode: DeploymentMode.Incremental,
                artifacts: invalidArtifacts);

            var failureServiceUnitResponse = deploymentManagerClient.ServiceUnits.CreateOrUpdate(
                resourceGroupName: clientHelper.ResourceGroupName,
                serviceTopologyName: serviceTopologyResource.Name,
                serviceName: serviceName,
                serviceUnitName: failureServiceUnitName,
                serviceUnitInfo: failureServiceUnitInput);

            this.ValidateServiceUnit(failureServiceUnitInput, failureServiceUnitResponse);

            // Test Steps CRUD operations along with running a rollout.
            this.StepsCrudTests(
                serviceTopologyResource.Id,
                artifactSource.Id,
                serviceUnit.Id,
                failureServiceUnitResponse.Id,
                location,
                clientHelper,
                deploymentManagerClient);

            // Test Update service unit.
            serviceUnit.DeploymentMode = DeploymentMode.Complete;
            serviceUnit.Artifacts.ParametersArtifactSourceRelativePath = ParametersCopyFileName;
            serviceUnit.Artifacts.TemplateArtifactSourceRelativePath   = TemplateCopyFileName;
            var updatedService = deploymentManagerClient.ServiceUnits.CreateOrUpdate(
                resourceGroupName: clientHelper.ResourceGroupName,
                serviceTopologyName: serviceTopologyResource.Name,
                serviceName: serviceName,
                serviceUnitName: serviceUnitName,
                serviceUnitInfo: serviceUnit);

            this.ValidateServiceUnit(serviceUnit, updatedService);

            // Test Delete service unit.
            deploymentManagerClient.ServiceUnits.Delete(
                resourceGroupName: clientHelper.ResourceGroupName,
                serviceTopologyName: serviceTopologyResource.Name,
                serviceName: serviceName,
                serviceUnitName: serviceUnitName);

            var cloudException = Assert.Throws <CloudException>(() => deploymentManagerClient.ServiceUnits.Get(
                                                                    resourceGroupName: clientHelper.ResourceGroupName,
                                                                    serviceTopologyName: serviceTopologyResource.Name,
                                                                    serviceName: serviceName,
                                                                    serviceUnitName: serviceUnitName));

            Assert.Equal(HttpStatusCode.NotFound, cloudException.Response.StatusCode);

            deploymentManagerClient.ServiceUnits.Delete(
                resourceGroupName: clientHelper.ResourceGroupName,
                serviceTopologyName: serviceTopologyResource.Name,
                serviceName: serviceName,
                serviceUnitName: failureServiceUnitName);
        }
Ejemplo n.º 8
0
        private void ServiceCrudTests(
            ArtifactSource artifactSource,
            ServiceTopologyResource serviceTopologyResource,
            string location,
            AzureDeploymentManagerClient deploymentManagerClient,
            DeploymentManagerClientHelper clientHelper)
        {
            var serviceName    = clientHelper.ResourceGroupName + "Service";
            var targetLocation = location;

            var inputService = new ServiceResource(
                location: location,
                name: serviceName,
                targetLocation: targetLocation,
                targetSubscriptionId: EndToEndFunctionalTests.subscriptionId);

            var createServiceResponse = deploymentManagerClient.Services.CreateOrUpdate(
                resourceGroupName: clientHelper.ResourceGroupName,
                serviceTopologyName: serviceTopologyResource.Name,
                serviceName: serviceName,
                serviceInfo: inputService);

            this.ValidateService(inputService, createServiceResponse);

            // Test Get service.
            var service = deploymentManagerClient.Services.Get(
                resourceGroupName: clientHelper.ResourceGroupName,
                serviceTopologyName: serviceTopologyResource.Name,
                serviceName: serviceName);

            this.ValidateService(inputService, service);

            // Test CRUD operations on service units.
            this.ServiceUnitCrudTests(
                artifactSource,
                serviceTopologyResource,
                serviceName,
                location,
                deploymentManagerClient,
                clientHelper);

            // Test Update service.
            service.TargetSubscriptionId = "1e591dc1-b014-4754-b53b-58b67bcab1cd";
            var updatedService = deploymentManagerClient.Services.CreateOrUpdate(
                resourceGroupName: clientHelper.ResourceGroupName,
                serviceTopologyName: serviceTopologyResource.Name,
                serviceName: serviceName,
                serviceInfo: service);

            this.ValidateService(service, updatedService);

            // Test Delete service.
            deploymentManagerClient.Services.Delete(
                resourceGroupName: clientHelper.ResourceGroupName,
                serviceTopologyName: serviceTopologyResource.Name,
                serviceName: serviceName);

            var cloudException = Assert.Throws <CloudException>(() => deploymentManagerClient.Services.Get(
                                                                    resourceGroupName: clientHelper.ResourceGroupName,
                                                                    serviceTopologyName: serviceTopologyResource.Name,
                                                                    serviceName: serviceName));

            Assert.Equal(HttpStatusCode.NotFound, cloudException.Response.StatusCode);
        }
Ejemplo n.º 9
0
        private void HealthCheckStepTests(
            string location,
            DeploymentManagerClientHelper clientHelper,
            AzureDeploymentManagerClient deploymentManagerClient)
        {
            // Test Create step.
            var stepName = clientHelper.ResourceGroupName + "HealthCheckStep";

            var healthChecks = new List <RestHealthCheck>();

            healthChecks.Add(new RestHealthCheck()
            {
                Name    = "webAppHealthCheck",
                Request = new RestRequest()
                {
                    Method         = RestRequestMethod.GET,
                    Uri            = "https://clientvalidations.deploymentmanager.net/healthstatus",
                    Authentication = new ApiKeyAuthentication()
                    {
                        Name       = "code",
                        InProperty = RestAuthLocation.Header,
                        Value      = "AuthValue"
                    }
                },
                Response = new RestResponse()
                {
                    SuccessStatusCodes = new List <string> {
                        "200", "204"
                    },
                    Regex = new RestResponseRegex()
                    {
                        MatchQuantifier = RestMatchQuantifier.All,
                        Matches         = new List <string>
                        {
                            "Contoso-Service-EndToEnd",
                            "(?i)\"health_status\":((.|\n)*)\"(green|yellow)\"",
                            "(?mi)^(\"application_host\": 94781052)$"
                        }
                    }
                }
            });

            healthChecks.Add(new RestHealthCheck()
            {
                Name    = "webBackEndHealthCheck",
                Request = new RestRequest()
                {
                    Method         = RestRequestMethod.GET,
                    Uri            = "https://clientvalidations.deploymentmanager.net/healthstatus",
                    Authentication = new RolloutIdentityAuthentication()
                },
                Response = new RestResponse()
                {
                    SuccessStatusCodes = new List <string> {
                        "200", "204"
                    },
                    Regex = new RestResponseRegex()
                    {
                        MatchQuantifier = RestMatchQuantifier.All,
                        Matches         = new List <string>
                        {
                            "Contoso-Service-Backend",
                            "(?i)\"health_status\":((.|\n)*)\"(green|yellow)\"",
                            "(?mi)^(\"application_host\": 94781055)$"
                        }
                    }
                }
            });

            var stepProperties = new HealthCheckStepProperties()
            {
                Attributes = new RestHealthCheckStepAttributes()
                {
                    WaitDuration         = "PT10M",
                    MaxElasticDuration   = "PT15M",
                    HealthyStateDuration = "PT30M",
                    HealthChecks         = healthChecks
                }
            };

            var inputStep = new StepResource(
                location: location,
                properties: stepProperties,
                name: stepName);

            var stepResponse = deploymentManagerClient.Steps.CreateOrUpdate(
                resourceGroupName: clientHelper.ResourceGroupName,
                stepName: stepName,
                stepInfo: inputStep);

            this.ValidateHealthCheckStep(inputStep, stepResponse);

            // Test list steps.
            var steps = deploymentManagerClient.Steps.List(
                resourceGroupName: clientHelper.ResourceGroupName);

            Assert.Equal(2, steps.Count);
            this.ValidateHealthCheckStep(inputStep, steps.ToList().First(s => s.Name.Equals(inputStep.Name, StringComparison.InvariantCultureIgnoreCase)));

            deploymentManagerClient.Steps.Delete(
                resourceGroupName: clientHelper.ResourceGroupName,
                stepName: stepName);

            var cloudException = Assert.Throws <CloudException>(() => deploymentManagerClient.Steps.Get(
                                                                    resourceGroupName: clientHelper.ResourceGroupName,
                                                                    stepName: stepName));

            Assert.Equal(HttpStatusCode.NotFound, cloudException.Response.StatusCode);
        }