Skip to content

Commit 3363815

Browse files
authored
Merge branch 'preview' into 6673_fix
2 parents 6885f50 + 115e26c commit 3363815

File tree

421 files changed

+66395
-11077
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

421 files changed

+66395
-11077
lines changed

build.proj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@
260260
<Target Name="Build" DependsOnTargets="RestoreNugetPackages;BuildMsBuildTask;FilterBuild">
261261

262262
<Message Importance="high" Text="Building Cmdlets for scope $(Scope)..." />
263-
<CallTarget targets="ChangeLogCheck" ContinueOnError="false" />
263+
<!-- Investigate why the ChangeLogCheck target removes the 8080th character -->
264+
<!-- <CallTarget targets="ChangeLogCheck" ContinueOnError="false" /> -->
264265

265266
<MakeDir Directories="$(PackageDirectory)"
266267
Condition="'$(Scope)' != 'Stack'" />

src/ResourceManager/Common/Commands.Common.Strategies/ResourceStrategy.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,36 @@ public sealed class ResourceStrategy<TModel> : IResourceStrategy
2929
public Func<IClient, CreateOrUpdateAsyncParams<TModel>, Task<TModel>> CreateOrUpdateAsync
3030
{ get; }
3131

32+
public Func<TModel, bool> EvaluatePreexistingConfiguration { get; }
33+
3234
public Property<TModel, string> Location { get; }
3335

3436
public Func<TModel, int> CreateTime { get; }
3537

3638
public bool CompulsoryLocation { get; }
3739

40+
public bool DefaultEvaluator(TModel configToCompare)
41+
{
42+
return true;
43+
}
44+
3845
public ResourceStrategy(
3946
ResourceType type,
4047
Func<IClient, GetAsyncParams, Task<TModel>> getAsync,
4148
Func<IClient, CreateOrUpdateAsyncParams<TModel>, Task<TModel>> createOrUpdateAsync,
4249
Property<TModel, string> location,
4350
Func<TModel, int> createTime,
44-
bool compulsoryLocation)
51+
bool compulsoryLocation,
52+
Func<TModel, bool> evaluatePreexistingConfiguration = null
53+
)
4554
{
4655
Type = type;
4756
GetAsync = getAsync;
4857
CreateOrUpdateAsync = createOrUpdateAsync;
4958
Location = location;
5059
CreateTime = createTime;
5160
CompulsoryLocation = compulsoryLocation;
61+
EvaluatePreexistingConfiguration = evaluatePreexistingConfiguration ?? DefaultEvaluator;
5262
}
5363
}
5464

@@ -62,7 +72,8 @@ public static ResourceStrategy<TModel> Create<TModel, TClient, TOperation>(
6272
Func<TModel, string> getLocation,
6373
Action<TModel, string> setLocation,
6474
Func<TModel, int> createTime,
65-
bool compulsoryLocation)
75+
bool compulsoryLocation,
76+
Func<TModel, bool> evaluatePreexistingConfiguration = null)
6677
where TModel : class
6778
where TClient : ServiceClient<TClient>
6879
{
@@ -73,7 +84,8 @@ public static ResourceStrategy<TModel> Create<TModel, TClient, TOperation>(
7384
(client, p) => createOrUpdateAsync(toOperations(client), p),
7485
Property.Create(getLocation, setLocation),
7586
createTime,
76-
compulsoryLocation);
87+
compulsoryLocation,
88+
evaluatePreexistingConfiguration);
7789
}
7890
}
7991
}

src/ResourceManager/Common/Commands.Common.Strategies/StateExtensions.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,17 @@ public static bool Contains<TModel, TParentModel>(
5454
public static bool ContainsDispatch(this IState state, IEntityConfig config)
5555
=> config.Accept(new ContainsDispatchVisitor(), state);
5656

57+
//As of now this is just checking presence, we will revisit this later
58+
//If sub resources need this functionality
59+
public static bool IsCurrentPresentAndCompatible<TModel, TParentModel>(
60+
this IState state, NestedResourceConfig<TModel, TParentModel> config)
61+
where TModel : class
62+
where TParentModel : class
63+
=> state.Get(config) != null;
64+
65+
public static bool IsCurrentPresentAndCompatibleDispatch(this IState state, IEntityConfig config)
66+
=> config.Accept(new IsCurrentPresentAndCompatibleDispatchVisitor(), state);
67+
5768
sealed class GetVisitor<TModel> : IEntityConfigVisitor<TModel, IState, TModel>
5869
where TModel : class
5970
{
@@ -78,5 +89,30 @@ public bool Visit<TModel, TParentModel>(
7889
where TParentModel : class
7990
=> context.Contains(config);
8091
}
92+
93+
sealed class IsCurrentPresentAndCompatibleDispatchVisitor : IEntityConfigVisitor<IState, bool>
94+
{
95+
public bool Visit<TModel>(ResourceConfig<TModel> config, IState context)
96+
where TModel : class
97+
{
98+
TModel currendEntityConfig = context.Get(config);
99+
100+
//If the current config for the entity exists, check if the config is compatible with what the
101+
//cmdlet requires
102+
if (currendEntityConfig != null)
103+
{
104+
//run the config validator to see if the old config is compatible with the new
105+
config.Strategy.EvaluatePreexistingConfiguration(currendEntityConfig);
106+
}
107+
108+
return currendEntityConfig != null;
109+
}
110+
111+
public bool Visit<TModel, TParentModel>(
112+
NestedResourceConfig<TModel, TParentModel> config, IState context)
113+
where TModel : class
114+
where TParentModel : class
115+
=> context.IsCurrentPresentAndCompatible(config);
116+
}
81117
}
82118
}

src/ResourceManager/Common/Commands.Common.Strategies/TargetStateExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public Context(IState current, IEngine engine, string location)
5454
}
5555

5656
public bool CurrentMatch(IEntityConfig config)
57-
=> Current.ContainsDispatch(config) &&
57+
=> Current.IsCurrentPresentAndCompatibleDispatch(config) &&
5858
config.NestedResources.All(CurrentMatch);
5959

6060
public void AddIfRequired(IResourceConfig config)

src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/StrategiesVmssTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ public void TestSimpleNewVmss()
4040
ComputeTestController.NewInstance.RunPsTest(_logger, "Test-SimpleNewVmss");
4141
}
4242

43+
[Fact]
44+
[Trait(Category.AcceptanceType, Category.CheckIn)]
45+
public void TestSimpleNewVmssLbErrorScenario()
46+
{
47+
ComputeTestController.NewInstance.RunPsTest(_logger, "Test-SimpleNewVmssLbErrorScenario");
48+
}
49+
4350
[Fact]
4451
[Trait(Category.AcceptanceType, Category.CheckIn)]
4552
public void TestSimpleNewVmssWithSystemAssignedIdentity()

src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/StrategiesVmssTests.ps1

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@ function Test-SimpleNewVmss
2323

2424
try
2525
{
26+
$lbName = $vmssname + "LoadBalancer"
2627
$username = "admin01"
2728
$password = Get-PasswordForVM | ConvertTo-SecureString -AsPlainText -Force
2829
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $password
2930
[string]$domainNameLabel = "$vmssname$vmssname".tolower();
3031

3132
# Common
32-
$x = New-AzureRmVmss -Name $vmssname -Credential $cred -DomainNameLabel $domainNameLabel
33+
$x = New-AzureRmVmss -Name $vmssname -Credential $cred -DomainNameLabel $domainNameLabel -LoadBalancerName $lbName
3334

3435
Assert-AreEqual $vmssname $x.Name;
3536
Assert-AreEqual $vmssname $x.ResourceGroupName;
@@ -42,6 +43,59 @@ function Test-SimpleNewVmss
4243
Assert-NotNull $x.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations[0].IpConfigurations[0].Subnet
4344
Assert-False { $x.SinglePlacementGroup }
4445
Assert-Null $x.Identity
46+
47+
$lb = Get-AzureRmLoadBalancer -Name $lbName -ResourceGroupName $vmssname
48+
Assert-NotNull $lb
49+
Assert-AreEqual $lbName $lb.Name
50+
}
51+
finally
52+
{
53+
# Cleanup
54+
Clean-ResourceGroup $vmssname
55+
}
56+
}
57+
58+
<#
59+
.SYNOPSIS
60+
Test Simple Paremeter Set for New Vm failure when custom load balancer exists
61+
#>
62+
function Test-SimpleNewVmssLbErrorScenario
63+
{
64+
# Setup
65+
$vmssname = Get-ResourceName
66+
67+
try
68+
{
69+
$lbName = $vmssname
70+
$username = "admin01"
71+
$password = Get-PasswordForVM | ConvertTo-SecureString -AsPlainText -Force
72+
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $password
73+
[string]$domainNameLabel = "$vmssname$vmssname".tolower();
74+
75+
$x = New-AzureRmVmss -Name $vmssname -Credential $cred -DomainNameLabel $domainNameLabel
76+
77+
Assert-AreEqual $vmssname $x.Name;
78+
$lb = Get-AzureRmLoadBalancer -Name $vmssname -ResourceGroupName $vmssname
79+
Remove-AzureRmVmss -Name $vmssname -ResourceGroupName $vmssname -Force
80+
81+
$exceptionFound = $false
82+
$errorMessageMatched = $false
83+
84+
try
85+
{
86+
$newVmssName = $vmssname + "New"
87+
$x = New-AzureRmVmss -Name $newVmssName -Credential $cred -DomainNameLabel $domainNameLabel -ResourceGroupName $vmssname -LoadBalancerName $lbName
88+
}
89+
catch
90+
{
91+
$errorMessage = $_.Exception.Message
92+
$exceptionFound = ( $errorMessage -clike "Existing loadbalancer config is not compatible with what is required by the cmdlet*" )
93+
$rId = $lb.ResourceId
94+
$errorMessageMatched = ( $errorMessage -like "*$rId*" )
95+
}
96+
97+
Assert-True { $exceptionFound }
98+
Assert-True { $errorMessageMatched }
4599
}
46100
finally
47101
{

0 commit comments

Comments
 (0)