Skip to content

Commit debfb78

Browse files
a-santamariaAlfredo Santamaria Gomez
andauthored
New Az Cmdlets for Service fabric Managed Clusters and Node Types (#12838)
* add initial cmdlets new, get managed clsuters and node types and restart * adding remove, reimage and fixing restart * error on create and resouce exists adding delete cluster and get by list * add extension and secrets and updates * fix typo in files * fix type and add all cmdlets to Az.ServiceFabric.psd1 * change provision after type * add secrets and extensions to PSManagedNodeType * fix add extension get nodetype parameters * add remove client cert and fix should process * show correalation on exception and fix issuertp type * rename update commands to set and add help files * add inputObjec, resourceId params, fix typos and design comments * add -AsJob for long running operations * fix examples * remove SupportsShouldProcess for get cmdlets * fix set parameters by resouceId or object * adding managed clusters tests * recording tests * re record cluster and app test * update help * update changelog * add online version * add cred scan suppressiong * fix static analiysis and macos build issue * remove EnsureSuccessStatusCode * set byObj as default paramter set * update publisher and type help message and throw on remove ext not found Co-authored-by: Alfredo Santamaria Gomez <[email protected]>
1 parent 2e20a16 commit debfb78

File tree

76 files changed

+43639
-27769
lines changed

Some content is hidden

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

76 files changed

+43639
-27769
lines changed

src/ServiceFabric/ServiceFabric.Test/ScenarioTests/Common.ps1

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,25 +68,30 @@ function Get-NewCertName
6868
function Get-SecretUrl
6969
{
7070
# Thumbprint for this cert should be specified in TestServiceFabric.cs in ServiceFabricCmdletBase.TestThumbprint
71-
return "https://azurermsfkvtest.vault.azure.net:443/secrets/AzureRMSFTestCert2/6e96bff504d54f36916489281423b8c6"
71+
return "https://azurermsfkvtest.vault.azure.net:443/secrets/AzureRMSFTestCert2/4e680cd578ba4e57b650d9f89cd20835"
72+
}
73+
74+
function Get-InitialThumbprint
75+
{
76+
return "3545EEBFA6F5EA7A1D436F5D6C708AD6A7110D6B"
7277
}
7378

7479
function Get-Thumbprint
7580
{
7681
# Change the thumbprint in the TestServiceFabric.cs file as well in ServiceFabricCmdletBase.TestThumbprint
77-
return "910AC565E683987971F34531A824284E3B936040"
82+
return "9ED6D1B225C63DC653CB0D9E16CFD7F799785FAC"
7883
}
7984

8085
function Get-CertAppSecretUrl
8186
{
8287
# Thumbprint for this cert should be specified in TestServiceFabric.cs in ServiceFabricCmdletBase.TestThumbprintAppCert
83-
return "https://azurermsfkvtest.vault.azure.net:443/secrets/AzureRMSFTestCertApp/ca4c0f7efa254d9ba0b267b8aaebb878"
88+
return "https://azurermsfkvtest.vault.azure.net:443/secrets/AzureRMSFTestCertApp/599d307311bf4508b7511ed482fa746f"
8489
}
8590

8691
function Get-CertAppThumbprint
8792
{
8893
# Change the thumbprint in the TestServiceFabric.cs file as well in ServiceFabricCmdletBase.TestThumbprintAppCert
89-
return "EE28AF31B2741B52311A00F78DFF4F46240BB4F8"
94+
return "3B892D25432FDA538F54B1EADD0B28BA82C488CC"
9095
}
9196

9297
function Get-CACertCommonName
@@ -101,12 +106,12 @@ function Get-CACertIssuerThumbprint
101106

102107
function Get-CACertSecretUrl
103108
{
104-
return "https://azurermsfkvtest.vault.azure.net:443/secrets/azurermsfcntest/0cd47f8218aa40e3a47e0597b8017247"
109+
return "https://azurermsfkvtest.vault.azure.net:443/secrets/azurermsfcntest/219a6d1803c34447b686db16ecd6285a"
105110
}
106111

107112
function Get-CertWUSecretUrl
108113
{
109-
return "https://azurermsfkvtestwu.vault.azure.net/secrets/AzureRMSFTestCertWU/5250a7acbaa143fa9d493840d4de1c01"
114+
return "https://azurermsfkvtestwu.vault.azure.net:443/secrets/AzureRMSFTestCertWU/5236086354ac470e8efa4e0426b6144d"
110115
}
111116

112117
function Get-DurabilityLevel
@@ -182,6 +187,33 @@ function WaitForClusterReadyState($clusterName, $resourceGroupName, $timeoutInSe
182187
return $false
183188
}
184189

190+
function WaitForAllJob($timeoutInSeconds = 1200)
191+
{
192+
$timeoutTime = (Get-Date).AddSeconds($timeoutInSeconds)
193+
$allJobs = Get-Job
194+
do
195+
{
196+
$completed = Get-Job | Where-Object { $_.State -eq "Completed" }
197+
if ($completed.Count -eq $allJobs.Count)
198+
{
199+
return $true
200+
break
201+
}
202+
203+
$failed = Get-Job | Where-Object { $_.State -eq "Failed" }
204+
if ($failed.Count -gt 0)
205+
{
206+
Write-Error "At least one Job failed" $failed
207+
return $false
208+
}
209+
210+
Start-Sleep -Seconds 15
211+
} while ((Get-Date) -lt $timeoutTime)
212+
213+
Write-Error "WaitForJob timed out"
214+
return $false
215+
}
216+
185217
# Application functions
186218

187219
function Get-AppTypeName

src/ServiceFabric/ServiceFabric.Test/ScenarioTests/ServiceFabricApplicationTests.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,8 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using System;
16-
using System.IO;
1715
using Microsoft.Azure.Commands.ServiceFabric.Commands;
18-
using Microsoft.Azure.Commands.ServiceFabric.Common;
1916
using Microsoft.Azure.ServiceManagement.Common.Models;
20-
using Microsoft.WindowsAzure.Commands.Common;
2117
using Microsoft.WindowsAzure.Commands.ScenarioTest;
2218
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
2319
using Xunit;
@@ -33,8 +29,8 @@ public ServiceFabricApplicationTests(ITestOutputHelper output)
3329
{
3430
_logger = new XunitTracingInterceptor(output);
3531
XunitTracingInterceptor.AddToContext(_logger);
36-
37-
ServiceFabricCmdletBase.WriteVerboseIntervalInSec = 0;
32+
33+
ServiceFabricCommonCmdletBase.WriteVerboseIntervalInSec = 0;
3834
ServiceFabricCmdletBase.RunningTest = true;
3935
}
4036

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Azure.Commands.ServiceFabric.Commands;
16+
using Microsoft.Azure.ServiceManagement.Common.Models;
17+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
18+
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
19+
using Xunit;
20+
using Xunit.Abstractions;
21+
22+
namespace Microsoft.Azure.Commands.ServiceFabric.Test.ScenarioTests
23+
{
24+
public class ServiceFabricManagedClustersTests : RMTestBase
25+
{
26+
public XunitTracingInterceptor _logger;
27+
28+
public ServiceFabricManagedClustersTests(ITestOutputHelper output)
29+
{
30+
_logger = new XunitTracingInterceptor(output);
31+
XunitTracingInterceptor.AddToContext(_logger);
32+
33+
ServiceFabricCommonCmdletBase.WriteVerboseIntervalInSec = 0;
34+
ServiceFabricCmdletBase.RunningTest = true;
35+
}
36+
37+
[Fact]
38+
[Trait(Category.AcceptanceType, Category.CheckIn)]
39+
public void TestCreateBasicCluster()
40+
{
41+
TestController.NewInstance.RunPsTest(_logger, "Test-CreateBasicCluster");
42+
}
43+
44+
[Fact]
45+
[Trait(Category.AcceptanceType, Category.CheckIn)]
46+
public void TestNodeTypeOperations()
47+
{
48+
TestController.NewInstance.RunPsTest(_logger, "Test-NodeTypeOperations");
49+
}
50+
51+
[Fact]
52+
[Trait(Category.AcceptanceType, Category.CheckIn)]
53+
public void TestCertAndExtension()
54+
{
55+
TestController.NewInstance.RunPsTest(_logger, "Test-CertAndExtension");
56+
}
57+
}
58+
}
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# ----------------------------------------------------------------------------------
2+
#
3+
# Copyright Microsoft Corporation
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
# ----------------------------------------------------------------------------------
14+
15+
function Test-CreateBasicCluster
16+
{
17+
$resourceGroupName = "sfmcps-rg-" + (getAssetname)
18+
$clusterName = "sfmcps-" + (getAssetname)
19+
$pass = (ConvertTo-SecureString -AsPlainText -Force "TestPass1234!@#")
20+
$location = "southcentralus"
21+
$testClientTp = "123BDACDCDFB2C7B250192C6078E47D1E1DB119B"
22+
Assert-ThrowsContains { Get-AzServiceFabricManagedCluster -ResourceGroupName $resourceGroupName -Name $clusterName } "NotFound"
23+
24+
$cluster = New-AzServiceFabricManagedCluster -ResourceGroupName $resourceGroupName -ClusterName $clusterName -Location $location `
25+
-AdminPassword $pass -Sku Basic -ClientCertThumbprint $testClientTp -Verbose
26+
Assert-AreEqual "Succeeded" $cluster.ProvisioningState
27+
Assert-AreEqual "WaitingForNodes" $cluster.ClusterState
28+
29+
$pnt = New-AzServiceFabricManagedNodeType -ResourceGroupName $resourceGroupName -ClusterName $clusterName -Name pnt -InstanceCount 5 -Primary
30+
31+
# shouldn't be allowed to remove the only primary node type in the cluster
32+
Assert-ThrowsContains { $pnt | Remove-AzServiceFabricManagedNodeType } "InvalidParameter"
33+
34+
$cluster = Get-AzServiceFabricManagedCluster -ResourceGroupName $resourceGroupName -Name $clusterName
35+
Assert-AreEqual "Deploying" $cluster.ClusterState
36+
37+
# scale primary node type
38+
$pnt = Set-AzServiceFabricManagedNodeType -ResourceGroupName $resourceGroupName -ClusterName $clusterName -Name pnt -InstanceCount 6
39+
Assert-AreEqual 6 $pnt.VmInstanceCount
40+
41+
$removeResponse = $cluster | Remove-AzServiceFabricManagedCluster -PassThru
42+
Assert-True { $removeResponse }
43+
44+
Assert-ThrowsContains { Get-AzServiceFabricManagedCluster -ResourceGroupName $resourceGroupName -ClusterName $clusterName } "NotFound"
45+
}
46+
47+
function Test-NodeTypeOperations
48+
{
49+
$resourceGroupName = "sfmcps-rg-" + (getAssetname)
50+
$clusterName = "sfmcps-" + (getAssetname)
51+
$location = "southcentralus"
52+
$testClientTp = "123BDACDCDFB2C7B250192C6078E47D1E1DB119B"
53+
$pass = (ConvertTo-SecureString -AsPlainText -Force "TestPass1234!@#")
54+
Assert-ThrowsContains { Get-AzServiceFabricManagedCluster -ResourceGroupName $resourceGroupName -Name $clusterName } "NotFound"
55+
56+
$cluster = New-AzServiceFabricManagedCluster -ResourceGroupName $resourceGroupName -ClusterName $clusterName -Location $location `
57+
-AdminPassword $pass -Sku Standard -ClientCertThumbprint $testClientTp -Verbose
58+
Assert-AreEqual "Succeeded" $cluster.ProvisioningState
59+
Assert-AreEqual "WaitingForNodes" $cluster.ClusterState
60+
61+
New-AzServiceFabricManagedNodeType -ResourceGroupName $resourceGroupName -ClusterName $clusterName -Name pnt -InstanceCount 5 -Primary -AsJob
62+
New-AzServiceFabricManagedNodeType -ResourceGroupName $resourceGroupName -ClusterName $clusterName -Name snt -InstanceCount 6 -AsJob
63+
64+
#wait for nodetypes
65+
WaitForAllJob
66+
67+
$restart = Restart-AzServiceFabricManagedNodeType -ResourceGroupName $resourceGroupName -ClusterName $clusterName -Name snt -NodeName snt_0, snt_1 -PassThru
68+
Assert-True { $restart }
69+
70+
$delete = Remove-AzServiceFabricManagedNodeType -ResourceGroupName $resourceGroupName -ClusterName $clusterName -Name snt -NodeName snt_1 -PassThru
71+
Assert-True { $delete }
72+
73+
$reimage = Set-AzServiceFabricManagedNodeType -ResourceGroupName $resourceGroupName -ClusterName $clusterName -Name snt -NodeName snt_3 -Reimage -PassThru
74+
Assert-True { $reimage }
75+
76+
$snt = Get-AzServiceFabricManagedNodeType -ResourceGroupName $resourceGroupName -ClusterName $clusterName -Name snt
77+
$removeResponse = $snt | Remove-AzServiceFabricManagedNodeType -PassThru
78+
Assert-True { $removeResponse }
79+
80+
$removeResponse = $cluster | Remove-AzServiceFabricManagedCluster -PassThru
81+
Assert-True { $removeResponse }
82+
}
83+
84+
function Test-CertAndExtension
85+
{
86+
$resourceGroupName = "sfmcps-rg-" + (getAssetname)
87+
$clusterName = "sfmcps-" + (getAssetname)
88+
$location = "southcentralus"
89+
$testClientTp = "123BDACDCDFB2C7B250192C6078E47D1E1DB119B"
90+
$pass = (ConvertTo-SecureString -AsPlainText -Force "TestPass1234!@#")
91+
Assert-ThrowsContains { Get-AzServiceFabricManagedCluster -ResourceGroupName $resourceGroupName -Name $clusterName } "NotFound"
92+
93+
$cluster = New-AzServiceFabricManagedCluster -ResourceGroupName $resourceGroupName -ClusterName $clusterName -Location $location `
94+
-AdminPassword $pass -Sku Standard -ClientCertThumbprint $testClientTp -Verbose
95+
Assert-AreEqual "Succeeded" $cluster.ProvisioningState
96+
Assert-AreEqual "WaitingForNodes" $cluster.ClusterState
97+
98+
$pnt = New-AzServiceFabricManagedNodeType -ResourceGroupName $resourceGroupName -ClusterName $clusterName -Name pnt -InstanceCount 5 -Primary
99+
100+
# add extension
101+
$extName = 'csetest';
102+
$publisher = 'Microsoft.Compute';
103+
$extType = 'BGInfo';
104+
$extVer = '2.1';
105+
106+
$pnt = Add-AzServiceFabricManagedNodeTypeVMExtension -ResourceGroupName $resourceGroupName -ClusterName $clusterName -NodeTypeName pnt `
107+
-Name $extName -Publisher $publisher -Type $extType -TypeHandlerVersion $extVer -Verbose
108+
109+
$pnt = Get-AzServiceFabricManagedNodeType -ResourceGroupName $resourceGroupName -ClusterName $clusterName -Name pnt
110+
111+
Assert-NotNull $pnt.VmExtensions
112+
Assert-AreEqual 1 $pnt.VmExtensions.Count
113+
114+
# add client cert
115+
Assert-AreEqual 1 $cluster.Clients.Count
116+
$testClientTp2 = "123BDACDCDFB2C7B250192C6078E47D1E1DB7777"
117+
$cluster = Add-AzServiceFabricManagedClusterClientCertificate -ResourceGroupName $resourceGroupName -ClusterName $clusterName -Thumbprint $testClientTp2
118+
Assert-AreEqual 2 $cluster.Clients.Count
119+
Assert-AreEqual $testClientTp2 $cluster.Clients[1].Thumbprint
120+
121+
# remove client cert
122+
$remove = Remove-AzServiceFabricManagedClusterClientCertificate -ResourceGroupName $resourceGroupName -ClusterName $clusterName -Thumbprint $testClientTp2 -PassThru
123+
Assert-True { $remove }
124+
125+
$cluster = Get-AzServiceFabricManagedCluster -ResourceGroupName $resourceGroupName -Name $clusterName
126+
Assert-AreEqual 1 $cluster.Clients.Count
127+
128+
$removeResponse = $cluster | Remove-AzServiceFabricManagedCluster -PassThru
129+
Assert-True { $removeResponse }
130+
}

src/ServiceFabric/ServiceFabric.Test/ScenarioTests/TestServiceFabric.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ public TestServiceFabric(ITestOutputHelper output)
3636
XunitTracingInterceptor.AddToContext(_logger);
3737

3838
AddAzureRmServiceFabricNodeType.dontRandom = true;
39-
ServiceFabricCmdletBase.WriteVerboseIntervalInSec = 0;
39+
ServiceFabricCommonCmdletBase.WriteVerboseIntervalInSec = 0;
4040
ServiceFabricCmdletBase.RunningTest = true;
4141
ServiceFabricCmdletBase.NewCreatedKeyVaultWaitTimeInSec = 0;
4242
//change the thumbprint in the common.ps1 file as well
43-
ServiceFabricCmdletBase.TestThumbprint = "910AC565E683987971F34531A824284E3B936040";
43+
ServiceFabricCmdletBase.TestThumbprint = "9ED6D1B225C63DC653CB0D9E16CFD7F799785FAC";
4444
ServiceFabricCmdletBase.TestCommonNameCACert = "azurermsfcntest.southcentralus.cloudapp.azure.com";
4545
ServiceFabricCmdletBase.TestCommonNameAppCert = "AzureRMSFTestCertApp";
46-
ServiceFabricCmdletBase.TestThumbprintAppCert = "EE28AF31B2741B52311A00F78DFF4F46240BB4F8";
46+
ServiceFabricCmdletBase.TestThumbprintAppCert = "3B892D25432FDA538F54B1EADD0B28BA82C488CC";
4747
ServiceFabricCmdletBase.TestAppCert = false;
4848
}
4949

src/ServiceFabric/ServiceFabric.Test/ScenarioTests/TestServiceFabric.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ function Test-RemoveAzureRmServiceFabricClusterCertificate
8383
{
8484
$clusterName = Get-ClusterName
8585
$resourceGroupName = Get-ResourceGroupName
86-
$thumbprint = Get-Thumbprint
86+
$thumbprint = Get-InitialThumbprint
8787

8888
WaitForClusterReadyStateIfRecord $clusterName $resourceGroupName
8989

src/ServiceFabric/ServiceFabric.Test/ServiceFabric.Test.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<ItemGroup>
1414
<PackageReference Include="Microsoft.Azure.KeyVault" Version="3.0.1" />
1515
<PackageReference Include="Microsoft.Azure.KeyVault.WebKey" Version="3.0.1" />
16-
<PackageReference Include="Microsoft.Azure.Management.ServiceFabric" Version="1.2.0" />
16+
<PackageReference Include="Microsoft.Azure.Management.ServiceFabric" Version="1.3.0" />
1717
</ItemGroup>
1818

1919
<ItemGroup>

0 commit comments

Comments
 (0)