Skip to content
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

New Az Cmdlets for Service fabric Managed Clusters and Node Types #12838

Merged
merged 28 commits into from
Sep 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
fc7ed9c
add initial cmdlets new, get managed clsuters and node types and restart
Aug 5, 2020
e6e0143
adding remove, reimage and fixing restart
Aug 5, 2020
afba87e
error on create and resouce exists adding delete cluster and get by list
Aug 5, 2020
9f067d7
add extension and secrets and updates
Aug 6, 2020
80733bb
fix typo in files
Aug 6, 2020
7aa0b6c
fix type and add all cmdlets to Az.ServiceFabric.psd1
Aug 6, 2020
2572a17
change provision after type
Aug 6, 2020
f897ef4
add secrets and extensions to PSManagedNodeType
Aug 6, 2020
449dc9d
fix add extension get nodetype parameters
Aug 7, 2020
b1c72aa
add remove client cert and fix should process
Aug 7, 2020
bbcab01
show correalation on exception and fix issuertp type
Aug 7, 2020
549ffbb
rename update commands to set and add help files
Aug 8, 2020
bc6f0c2
add inputObjec, resourceId params, fix typos and design comments
Aug 19, 2020
575c847
add -AsJob for long running operations
Aug 19, 2020
f3e8629
fix examples
Aug 19, 2020
0983289
remove SupportsShouldProcess for get cmdlets
Aug 19, 2020
ac88ad3
fix set parameters by resouceId or object
Aug 30, 2020
0ad613d
adding managed clusters tests
Sep 1, 2020
90f718b
recording tests
Sep 1, 2020
d44e35d
re record cluster and app test
Sep 2, 2020
9dfb957
update help
Sep 2, 2020
b56f0fe
update changelog
Sep 2, 2020
d4a2293
add online version
Sep 2, 2020
a782193
add cred scan suppressiong
Sep 2, 2020
863c9d4
fix static analiysis and macos build issue
Sep 3, 2020
9fa182b
remove EnsureSuccessStatusCode
Sep 3, 2020
852d72f
set byObj as default paramter set
Sep 3, 2020
5cde3d2
update publisher and type help message and throw on remove ext not found
Sep 7, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 38 additions & 6 deletions src/ServiceFabric/ServiceFabric.Test/ScenarioTests/Common.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -68,25 +68,30 @@ function Get-NewCertName
function Get-SecretUrl
{
# Thumbprint for this cert should be specified in TestServiceFabric.cs in ServiceFabricCmdletBase.TestThumbprint
return "https://azurermsfkvtest.vault.azure.net:443/secrets/AzureRMSFTestCert2/6e96bff504d54f36916489281423b8c6"
return "https://azurermsfkvtest.vault.azure.net:443/secrets/AzureRMSFTestCert2/4e680cd578ba4e57b650d9f89cd20835"
}

function Get-InitialThumbprint
{
return "3545EEBFA6F5EA7A1D436F5D6C708AD6A7110D6B"
}

function Get-Thumbprint
{
# Change the thumbprint in the TestServiceFabric.cs file as well in ServiceFabricCmdletBase.TestThumbprint
return "910AC565E683987971F34531A824284E3B936040"
return "9ED6D1B225C63DC653CB0D9E16CFD7F799785FAC"
}

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

function Get-CertAppThumbprint
{
# Change the thumbprint in the TestServiceFabric.cs file as well in ServiceFabricCmdletBase.TestThumbprintAppCert
return "EE28AF31B2741B52311A00F78DFF4F46240BB4F8"
return "3B892D25432FDA538F54B1EADD0B28BA82C488CC"
}

function Get-CACertCommonName
Expand All @@ -101,12 +106,12 @@ function Get-CACertIssuerThumbprint

function Get-CACertSecretUrl
{
return "https://azurermsfkvtest.vault.azure.net:443/secrets/azurermsfcntest/0cd47f8218aa40e3a47e0597b8017247"
return "https://azurermsfkvtest.vault.azure.net:443/secrets/azurermsfcntest/219a6d1803c34447b686db16ecd6285a"
}

function Get-CertWUSecretUrl
{
return "https://azurermsfkvtestwu.vault.azure.net/secrets/AzureRMSFTestCertWU/5250a7acbaa143fa9d493840d4de1c01"
return "https://azurermsfkvtestwu.vault.azure.net:443/secrets/AzureRMSFTestCertWU/5236086354ac470e8efa4e0426b6144d"
}

function Get-DurabilityLevel
Expand Down Expand Up @@ -182,6 +187,33 @@ function WaitForClusterReadyState($clusterName, $resourceGroupName, $timeoutInSe
return $false
}

function WaitForAllJob($timeoutInSeconds = 1200)
{
$timeoutTime = (Get-Date).AddSeconds($timeoutInSeconds)
$allJobs = Get-Job
do
{
$completed = Get-Job | Where-Object { $_.State -eq "Completed" }
if ($completed.Count -eq $allJobs.Count)
{
return $true
break
}

$failed = Get-Job | Where-Object { $_.State -eq "Failed" }
if ($failed.Count -gt 0)
{
Write-Error "At least one Job failed" $failed
return $false
}

Start-Sleep -Seconds 15
} while ((Get-Date) -lt $timeoutTime)

Write-Error "WaitForJob timed out"
return $false
}

# Application functions

function Get-AppTypeName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,8 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using System;
using System.IO;
using Microsoft.Azure.Commands.ServiceFabric.Commands;
using Microsoft.Azure.Commands.ServiceFabric.Common;
using Microsoft.Azure.ServiceManagement.Common.Models;
using Microsoft.WindowsAzure.Commands.Common;
using Microsoft.WindowsAzure.Commands.ScenarioTest;
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
using Xunit;
Expand All @@ -33,8 +29,8 @@ public ServiceFabricApplicationTests(ITestOutputHelper output)
{
_logger = new XunitTracingInterceptor(output);
XunitTracingInterceptor.AddToContext(_logger);
ServiceFabricCmdletBase.WriteVerboseIntervalInSec = 0;

ServiceFabricCommonCmdletBase.WriteVerboseIntervalInSec = 0;
ServiceFabricCmdletBase.RunningTest = true;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Commands.ServiceFabric.Commands;
using Microsoft.Azure.ServiceManagement.Common.Models;
using Microsoft.WindowsAzure.Commands.ScenarioTest;
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
using Xunit;
using Xunit.Abstractions;

namespace Microsoft.Azure.Commands.ServiceFabric.Test.ScenarioTests
{
public class ServiceFabricManagedClustersTests : RMTestBase
{
public XunitTracingInterceptor _logger;

public ServiceFabricManagedClustersTests(ITestOutputHelper output)
{
_logger = new XunitTracingInterceptor(output);
XunitTracingInterceptor.AddToContext(_logger);

ServiceFabricCommonCmdletBase.WriteVerboseIntervalInSec = 0;
ServiceFabricCmdletBase.RunningTest = true;
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestCreateBasicCluster()
{
TestController.NewInstance.RunPsTest(_logger, "Test-CreateBasicCluster");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestNodeTypeOperations()
{
TestController.NewInstance.RunPsTest(_logger, "Test-NodeTypeOperations");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestCertAndExtension()
{
TestController.NewInstance.RunPsTest(_logger, "Test-CertAndExtension");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# ----------------------------------------------------------------------------------
#
# Copyright Microsoft Corporation
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ----------------------------------------------------------------------------------

function Test-CreateBasicCluster
{
$resourceGroupName = "sfmcps-rg-" + (getAssetname)
$clusterName = "sfmcps-" + (getAssetname)
$pass = (ConvertTo-SecureString -AsPlainText -Force "TestPass1234!@#")
$location = "southcentralus"
$testClientTp = "123BDACDCDFB2C7B250192C6078E47D1E1DB119B"
Assert-ThrowsContains { Get-AzServiceFabricManagedCluster -ResourceGroupName $resourceGroupName -Name $clusterName } "NotFound"

$cluster = New-AzServiceFabricManagedCluster -ResourceGroupName $resourceGroupName -ClusterName $clusterName -Location $location `
-AdminPassword $pass -Sku Basic -ClientCertThumbprint $testClientTp -Verbose
Assert-AreEqual "Succeeded" $cluster.ProvisioningState
Assert-AreEqual "WaitingForNodes" $cluster.ClusterState

$pnt = New-AzServiceFabricManagedNodeType -ResourceGroupName $resourceGroupName -ClusterName $clusterName -Name pnt -InstanceCount 5 -Primary

# shouldn't be allowed to remove the only primary node type in the cluster
Assert-ThrowsContains { $pnt | Remove-AzServiceFabricManagedNodeType } "InvalidParameter"

$cluster = Get-AzServiceFabricManagedCluster -ResourceGroupName $resourceGroupName -Name $clusterName
Assert-AreEqual "Deploying" $cluster.ClusterState

# scale primary node type
$pnt = Set-AzServiceFabricManagedNodeType -ResourceGroupName $resourceGroupName -ClusterName $clusterName -Name pnt -InstanceCount 6
Assert-AreEqual 6 $pnt.VmInstanceCount

$removeResponse = $cluster | Remove-AzServiceFabricManagedCluster -PassThru
Assert-True { $removeResponse }

Assert-ThrowsContains { Get-AzServiceFabricManagedCluster -ResourceGroupName $resourceGroupName -ClusterName $clusterName } "NotFound"
}

function Test-NodeTypeOperations
{
$resourceGroupName = "sfmcps-rg-" + (getAssetname)
$clusterName = "sfmcps-" + (getAssetname)
$location = "southcentralus"
$testClientTp = "123BDACDCDFB2C7B250192C6078E47D1E1DB119B"
$pass = (ConvertTo-SecureString -AsPlainText -Force "TestPass1234!@#")
Assert-ThrowsContains { Get-AzServiceFabricManagedCluster -ResourceGroupName $resourceGroupName -Name $clusterName } "NotFound"

$cluster = New-AzServiceFabricManagedCluster -ResourceGroupName $resourceGroupName -ClusterName $clusterName -Location $location `
-AdminPassword $pass -Sku Standard -ClientCertThumbprint $testClientTp -Verbose
Assert-AreEqual "Succeeded" $cluster.ProvisioningState
Assert-AreEqual "WaitingForNodes" $cluster.ClusterState

New-AzServiceFabricManagedNodeType -ResourceGroupName $resourceGroupName -ClusterName $clusterName -Name pnt -InstanceCount 5 -Primary -AsJob
New-AzServiceFabricManagedNodeType -ResourceGroupName $resourceGroupName -ClusterName $clusterName -Name snt -InstanceCount 6 -AsJob

#wait for nodetypes
WaitForAllJob

$restart = Restart-AzServiceFabricManagedNodeType -ResourceGroupName $resourceGroupName -ClusterName $clusterName -Name snt -NodeName snt_0, snt_1 -PassThru
Assert-True { $restart }

$delete = Remove-AzServiceFabricManagedNodeType -ResourceGroupName $resourceGroupName -ClusterName $clusterName -Name snt -NodeName snt_1 -PassThru
Assert-True { $delete }

$reimage = Set-AzServiceFabricManagedNodeType -ResourceGroupName $resourceGroupName -ClusterName $clusterName -Name snt -NodeName snt_3 -Reimage -PassThru
Assert-True { $reimage }

$snt = Get-AzServiceFabricManagedNodeType -ResourceGroupName $resourceGroupName -ClusterName $clusterName -Name snt
$removeResponse = $snt | Remove-AzServiceFabricManagedNodeType -PassThru
Assert-True { $removeResponse }

$removeResponse = $cluster | Remove-AzServiceFabricManagedCluster -PassThru
Assert-True { $removeResponse }
}

function Test-CertAndExtension
{
$resourceGroupName = "sfmcps-rg-" + (getAssetname)
$clusterName = "sfmcps-" + (getAssetname)
$location = "southcentralus"
$testClientTp = "123BDACDCDFB2C7B250192C6078E47D1E1DB119B"
$pass = (ConvertTo-SecureString -AsPlainText -Force "TestPass1234!@#")
Assert-ThrowsContains { Get-AzServiceFabricManagedCluster -ResourceGroupName $resourceGroupName -Name $clusterName } "NotFound"

$cluster = New-AzServiceFabricManagedCluster -ResourceGroupName $resourceGroupName -ClusterName $clusterName -Location $location `
-AdminPassword $pass -Sku Standard -ClientCertThumbprint $testClientTp -Verbose
Assert-AreEqual "Succeeded" $cluster.ProvisioningState
Assert-AreEqual "WaitingForNodes" $cluster.ClusterState

$pnt = New-AzServiceFabricManagedNodeType -ResourceGroupName $resourceGroupName -ClusterName $clusterName -Name pnt -InstanceCount 5 -Primary

# add extension
$extName = 'csetest';
$publisher = 'Microsoft.Compute';
$extType = 'BGInfo';
$extVer = '2.1';

$pnt = Add-AzServiceFabricManagedNodeTypeVMExtension -ResourceGroupName $resourceGroupName -ClusterName $clusterName -NodeTypeName pnt `
-Name $extName -Publisher $publisher -Type $extType -TypeHandlerVersion $extVer -Verbose

$pnt = Get-AzServiceFabricManagedNodeType -ResourceGroupName $resourceGroupName -ClusterName $clusterName -Name pnt

Assert-NotNull $pnt.VmExtensions
Assert-AreEqual 1 $pnt.VmExtensions.Count

# add client cert
Assert-AreEqual 1 $cluster.Clients.Count
$testClientTp2 = "123BDACDCDFB2C7B250192C6078E47D1E1DB7777"
$cluster = Add-AzServiceFabricManagedClusterClientCertificate -ResourceGroupName $resourceGroupName -ClusterName $clusterName -Thumbprint $testClientTp2
Assert-AreEqual 2 $cluster.Clients.Count
Assert-AreEqual $testClientTp2 $cluster.Clients[1].Thumbprint

# remove client cert
$remove = Remove-AzServiceFabricManagedClusterClientCertificate -ResourceGroupName $resourceGroupName -ClusterName $clusterName -Thumbprint $testClientTp2 -PassThru
Assert-True { $remove }

$cluster = Get-AzServiceFabricManagedCluster -ResourceGroupName $resourceGroupName -Name $clusterName
Assert-AreEqual 1 $cluster.Clients.Count

$removeResponse = $cluster | Remove-AzServiceFabricManagedCluster -PassThru
Assert-True { $removeResponse }
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ public TestServiceFabric(ITestOutputHelper output)
XunitTracingInterceptor.AddToContext(_logger);

AddAzureRmServiceFabricNodeType.dontRandom = true;
ServiceFabricCmdletBase.WriteVerboseIntervalInSec = 0;
ServiceFabricCommonCmdletBase.WriteVerboseIntervalInSec = 0;
ServiceFabricCmdletBase.RunningTest = true;
ServiceFabricCmdletBase.NewCreatedKeyVaultWaitTimeInSec = 0;
//change the thumbprint in the common.ps1 file as well
ServiceFabricCmdletBase.TestThumbprint = "910AC565E683987971F34531A824284E3B936040";
ServiceFabricCmdletBase.TestThumbprint = "9ED6D1B225C63DC653CB0D9E16CFD7F799785FAC";
ServiceFabricCmdletBase.TestCommonNameCACert = "azurermsfcntest.southcentralus.cloudapp.azure.com";
ServiceFabricCmdletBase.TestCommonNameAppCert = "AzureRMSFTestCertApp";
ServiceFabricCmdletBase.TestThumbprintAppCert = "EE28AF31B2741B52311A00F78DFF4F46240BB4F8";
ServiceFabricCmdletBase.TestThumbprintAppCert = "3B892D25432FDA538F54B1EADD0B28BA82C488CC";
ServiceFabricCmdletBase.TestAppCert = false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function Test-RemoveAzureRmServiceFabricClusterCertificate
{
$clusterName = Get-ClusterName
$resourceGroupName = Get-ResourceGroupName
$thumbprint = Get-Thumbprint
$thumbprint = Get-InitialThumbprint

WaitForClusterReadyStateIfRecord $clusterName $resourceGroupName

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Azure.KeyVault" Version="3.0.1" />
<PackageReference Include="Microsoft.Azure.KeyVault.WebKey" Version="3.0.1" />
<PackageReference Include="Microsoft.Azure.Management.ServiceFabric" Version="1.2.0" />
<PackageReference Include="Microsoft.Azure.Management.ServiceFabric" Version="1.3.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading