Skip to content

Add Complete to DeploymentMode when creating new deployment #697

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Aug 4, 2015
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,7 @@ public void TestTemplateShowsErrorMessage()
}))
.Callback((string rg, string dn, Deployment d, CancellationToken c) => { deploymentFromValidate = d; });

IEnumerable<PSResourceManagerError> error = resourcesClient.ValidatePSResourceGroupDeployment(parameters);
IEnumerable<PSResourceManagerError> error = resourcesClient.ValidatePSResourceGroupDeployment(parameters, DeploymentMode.Incremental);
Assert.Equal(2, error.Count());
}

Expand Down Expand Up @@ -1054,7 +1054,7 @@ public void TestTemplateShowsSuccessMessage()
}))
.Callback((string rg, string dn, Deployment d, CancellationToken c) => { deploymentFromValidate = d; });

IEnumerable<PSResourceManagerError> error = resourcesClient.ValidatePSResourceGroupDeployment(parameters);
IEnumerable<PSResourceManagerError> error = resourcesClient.ValidatePSResourceGroupDeployment(parameters, DeploymentMode.Incremental);
Assert.Equal(0, error.Count());
progressLoggerMock.Verify(f => f("Template is valid."), Times.Once());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void TestNewDeploymentAndProviderRegistration()
ResourcesController.NewInstance.RunPsTest("Test-NewDeploymentAndProviderRegistration");
}

[Fact(Skip = "Known test failure")]
[Fact]
public void TestNewResourceGroupWithTemplate()
{
ResourcesController.NewInstance.RunPsTest("Test-NewResourceGroupWithTemplateThenGetWithAndWithoutDetails");
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using System.Management.Automation;
using Microsoft.Azure.Commands.Resources.Models;
using Microsoft.Azure.Commands.Resources.ResourceGroupDeployments;
using Microsoft.Azure.Management.Resources.Models;
using Moq;
using Xunit;

Expand Down Expand Up @@ -75,9 +76,9 @@ public void ValidatesPSResourceGroupDeploymentWithUserTemplate()
}
};
resourcesClientMock.Setup(f => f.ValidatePSResourceGroupDeployment(
It.IsAny<ValidatePSResourceGroupDeploymentParameters>()))
It.IsAny<ValidatePSResourceGroupDeploymentParameters>(), DeploymentMode.Incremental))
.Returns(expected)
.Callback((ValidatePSResourceGroupDeploymentParameters p) => { actualParameters = p; });
.Callback((ValidatePSResourceGroupDeploymentParameters p, DeploymentMode m) => { actualParameters = p; m = DeploymentMode.Incremental; });

cmdlet.ResourceGroupName = resourceGroupName;
cmdlet.TemplateFile = expectedParameters.TemplateFile;
Expand Down Expand Up @@ -123,9 +124,9 @@ public void ValidatesPSResourceGroupDeploymentWithGalleryTemplate()
}
};
resourcesClientMock.Setup(f => f.ValidatePSResourceGroupDeployment(
It.IsAny<ValidatePSResourceGroupDeploymentParameters>()))
It.IsAny<ValidatePSResourceGroupDeploymentParameters>(), DeploymentMode.Incremental))
.Returns(expected)
.Callback((ValidatePSResourceGroupDeploymentParameters p) => { actualParameters = p; });
.Callback((ValidatePSResourceGroupDeploymentParameters p, DeploymentMode m) => { actualParameters = p; m = DeploymentMode.Incremental; });

cmdlet.ResourceGroupName = resourceGroupName;
cmdlet.GalleryTemplateIdentity = expectedParameters.GalleryTemplateIdentity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Management.Resources.Models;

namespace Microsoft.Azure.Commands.Resources.Models
{
public class CreatePSResourceGroupDeploymentParameters : ValidatePSResourceGroupDeploymentParameters
{
public string DeploymentName { get; set; }

public DeploymentMode DeploymentMode { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ public virtual List<GenericResourceExtended> FilterResources(FilterResourcesOpti
public virtual PSResourceGroupDeployment ExecuteDeployment(CreatePSResourceGroupDeploymentParameters parameters)
{
parameters.DeploymentName = GenerateDeploymentName(parameters);
Deployment deployment = CreateBasicDeployment(parameters);
Deployment deployment = CreateBasicDeployment(parameters, parameters.DeploymentMode);
TemplateValidationInfo validationInfo = CheckBasicDeploymentErrors(parameters.ResourceGroupName, parameters.DeploymentName, deployment);

if (validationInfo.Errors.Count != 0)
Expand Down Expand Up @@ -563,9 +563,9 @@ public virtual void CancelDeployment(string resourceGroup, string deploymentName
/// </summary>
/// <param name="parameters">The deployment create options</param>
/// <returns>True if valid, false otherwise.</returns>
public virtual List<PSResourceManagerError> ValidatePSResourceGroupDeployment(ValidatePSResourceGroupDeploymentParameters parameters)
public virtual List<PSResourceManagerError> ValidatePSResourceGroupDeployment(ValidatePSResourceGroupDeploymentParameters parameters, DeploymentMode deploymentMode)
{
Deployment deployment = CreateBasicDeployment(parameters);
Deployment deployment = CreateBasicDeployment(parameters, deploymentMode);
TemplateValidationInfo validationInfo = CheckBasicDeploymentErrors(parameters.ResourceGroupName, Guid.NewGuid().ToString(), deployment);

if (validationInfo.Errors.Count == 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,12 +324,12 @@ private List<DeploymentOperation> GetNewOperations(List<DeploymentOperation> old
return newOperations;
}

private Deployment CreateBasicDeployment(ValidatePSResourceGroupDeploymentParameters parameters)
private Deployment CreateBasicDeployment(ValidatePSResourceGroupDeploymentParameters parameters, DeploymentMode deploymentMode)
{
Deployment deployment = new Deployment
{
Properties = new DeploymentProperties {
Mode = DeploymentMode.Incremental,
Mode = deploymentMode,
Template = GetTemplate(parameters.TemplateFile, parameters.GalleryTemplateIdentity),
Parameters = GetDeploymentParameters(parameters.TemplateParameterObject)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

using System.Management.Automation;
using Microsoft.Azure.Commands.Resources.Models;
using Microsoft.Azure.Management.Resources.Models;
using Microsoft.WindowsAzure.Commands.Utilities.Common;

namespace Microsoft.Azure.Commands.Resources
Expand All @@ -34,20 +35,47 @@ public class NewAzureResourceGroupDeploymentCommand : ResourceWithParameterBaseC
[ValidateNotNullOrEmpty]
public string ResourceGroupName { get; set; }

[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The deployment mode.")]
public DeploymentMode Mode { get; set; }

[Parameter(Mandatory = false, HelpMessage = "Do not ask for confirmation.")]
public SwitchParameter Force { get; set; }

public NewAzureResourceGroupDeploymentCommand()
{
this.Mode = DeploymentMode.Incremental;
}

public override void ExecuteCmdlet()
{
CreatePSResourceGroupDeploymentParameters parameters = new CreatePSResourceGroupDeploymentParameters()
{
ResourceGroupName = ResourceGroupName,
DeploymentName = Name,
DeploymentMode = Mode,
GalleryTemplateIdentity = GalleryTemplateIdentity,
TemplateFile = TemplateUri ?? this.TryResolvePath(TemplateFile),
TemplateParameterObject = GetTemplateParameterObject(TemplateParameterObject),
TemplateVersion = TemplateVersion,
StorageAccountName = StorageAccountName
};

WriteObject(ResourcesClient.ExecuteDeployment(parameters));
if(this.Mode == DeploymentMode.Complete)
{
this.ConfirmAction(
this.Force,
"Are you sure you want to use the complete deployment mode? Resources in the resource group '" + ResourceGroupName + "' which are not included in the template will be deleted.",
"Creating a deployment with Complete mode",
ResourceGroupName,
() =>
{
WriteObject(ResourcesClient.ExecuteDeployment(parameters));
});
}
else
{
WriteObject(ResourcesClient.ExecuteDeployment(parameters));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using System.Collections.Generic;
using System.Management.Automation;
using Microsoft.Azure.Commands.Resources.Models;
using Microsoft.Azure.Management.Resources.Models;
using Microsoft.WindowsAzure.Commands.Utilities.Common;

namespace Microsoft.Azure.Commands.Resources.ResourceGroupDeployments
Expand All @@ -29,6 +30,14 @@ public class TestAzureResourceGroupTemplateCommand : ResourceWithParameterBaseCm
[ValidateNotNullOrEmpty]
public string ResourceGroupName { get; set; }

[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The deployment mode.")]
public DeploymentMode Mode { get; set; }

public TestAzureResourceGroupTemplateCommand()
{
this.Mode = DeploymentMode.Incremental;
}

public override void ExecuteCmdlet()
{
ValidatePSResourceGroupDeploymentParameters parameters = new ValidatePSResourceGroupDeploymentParameters()
Expand All @@ -41,7 +50,7 @@ public override void ExecuteCmdlet()
StorageAccountName = StorageAccountName
};

WriteObject(ResourcesClient.ValidatePSResourceGroupDeployment(parameters));
WriteObject(ResourcesClient.ValidatePSResourceGroupDeployment(parameters, Mode));
}
}
}