Skip to content

Commit

Permalink
Fix health interop issues with Azure Stack Hub (#384)
Browse files Browse the repository at this point in the history
# Description
Summary of changes:
- Removed a couple of health tests that rely on NC URI API call
- Updated the callers to not pass rest credentials
- Fixed class call where the backticks were commented out

# Change type
- [x] Bug fix (non-breaking change)
- [ ] Code style update (formatting, local variables)
- [ ] New Feature (non-breaking change that adds new functionality
without impacting existing)
- [ ] Breaking change (fix or feature that may cause functionality
impact)
- [ ] Other

# Checklist:
- [x] My code follows the style and contribution guidelines of this
project.
- [x] I have tested and validated my code changes.
  • Loading branch information
arudell authored Feb 6, 2025
1 parent 6a56fe8 commit 00b9e7b
Showing 1 changed file with 40 additions and 149 deletions.
189 changes: 40 additions & 149 deletions src/modules/SdnDiag.Health.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -310,26 +310,26 @@ function CreateorUpdateFault {
Write-Verbose "SubsystemID: $script:subsystemId"
Write-Verbose "EntityTypeSubSystem: $script:entityTypeSubSystem"

$retValue = [Microsoft.NetworkHud.FunctionalTests.Module.HciHealthUtils]::HciModifyFault( `
$Fault.KeyFaultingObjectDescription, # $entityType, `
$Fault.KeyFaultingObjectID, # $entityId, `
$Fault.KeyFaultingObjectDescription, # "E Desc", `
$Fault.FaultingObjectLocation, # $entityLocation, `
$Fault.KeyFaultingObjectID, # $entityId, `
$HCI_MODIFY_FAULT_ACTION_MODIFY, #action `
$Fault.KeyFaultingObjectType, # $faultType, `
$HEALTH_URGENCY_UNHEALTHY, # `
$null = [Microsoft.NetworkHud.FunctionalTests.Module.HciHealthUtils]::HciModifyFault( `
$Fault.KeyFaultingObjectDescription, ` # $entityType
$Fault.KeyFaultingObjectID, ` # $entityId
$Fault.KeyFaultingObjectDescription, ` # "E Desc"
$Fault.FaultingObjectLocation, ` # $entityLocation
$Fault.KeyFaultingObjectID, ` # $entityId
$HCI_MODIFY_FAULT_ACTION_MODIFY, ` #action
$Fault.KeyFaultingObjectType, ` # $faultType
$HEALTH_URGENCY_UNHEALTHY, `
"Fault Title", `
$Fault.FaultDescription, # fault description
$Fault.FaultActionRemediation, # fault remediation action
$HCI_MODIFY_FAULT_FLAG_NONE) | Out-Null

$retValue = [Microsoft.NetworkHud.FunctionalTests.Module.HciHealthUtils]::HciModifyRelationship(
$Fault.KeyFaultingObjectDescription, # $entityType, `
$Fault.KeyFaultingObjectID, # $entityId, `
$Fault.KeyFaultingObjectDescription, # $entityDescription
$Fault.FaultingObjectLocation, # $entityLocation, `
$Fault.KeyFaultingObjectID, # $entityId, `
$Fault.FaultDescription, ` # fault description
$Fault.FaultActionRemediation, ` # fault remediation action
$HCI_MODIFY_FAULT_FLAG_NONE)

$null = [Microsoft.NetworkHud.FunctionalTests.Module.HciHealthUtils]::HciModifyRelationship(
$Fault.KeyFaultingObjectDescription, ` # $entityType
$Fault.KeyFaultingObjectID, ` # $entityId
$Fault.KeyFaultingObjectDescription, ` # $entityDescription
$Fault.FaultingObjectLocation, ` # $entityLocation
$Fault.KeyFaultingObjectID, ` # $entityId
$HCI_MODIFY_RELATIONSHIP_ACTION_MODIFY, `
$script:entityTypeSubSystem, `
$script:subsystemId, `
Expand All @@ -339,7 +339,7 @@ function CreateorUpdateFault {
"TestGroupKey", `
$HEALTH_URGENCY_UNHEALTHY, `
$HEALTH_RELATIONSHIP_COLLECTION, `
$HCI_MODIFY_RELATIONSHIP_FLAG_NONE) | Out-Null
$HCI_MODIFY_RELATIONSHIP_FLAG_NONE)
}

function DeleteFaultBy {
Expand Down Expand Up @@ -440,7 +440,7 @@ function DeleteFaultById {

InitFaults
Write-Verbose "DeleteFaultById $faultId"
$fault = Get-HealthFault | ? { $_.FaultId -eq $faultUniqueID }
$fault = Get-HealthFault | Where-Object { $_.FaultId -eq $faultUniqueID }

if ($null -eq $fault) {
throw "Fault with ID $faultUniqueID not found"
Expand Down Expand Up @@ -553,7 +553,7 @@ function UpdateFaultSet {
$wmiFault.FaultingObjectUniqueId -eq $fault.KeyFaultingObjectID -and `
$wmiFault.FaultType -eq $fault.KeyFaultingObjectType) {
$found = $true
break
break
}
}
if(-not $found) {
Expand All @@ -562,7 +562,7 @@ function UpdateFaultSet {
LogHealthFaultToEventLog -fault $Fault -operation DeleteByFaultID
$convFault = ConvertFaultToPsObject -healthFault $sdnHealthFault -faultOpType "Delete"
$healthTest.HealthFault += $convFault
}
}
}
# update the new new set of faults
foreach ($fault in $failureFaults) {
Expand Down Expand Up @@ -746,7 +746,7 @@ function IsSdnService {
return $serviceName -in @( "NCHostAgent", "SlbHostAgent")
}
function IsSdnFault {

<#
.SYNOPSIS
Checks if the provided fault is an SDN fault
Expand Down Expand Up @@ -802,7 +802,7 @@ function IsCurrentNodeClusterOwner {
This function is used to determine if the current node is the owner of the cluster. This is used to determine if the current node is the primary node in a cluster.
#>

$res = Get-ClusterResource -Name "ApiService" -ErrorAction Ignore | select OwnerNode
$res = Get-ClusterResource -Name "ApiService" -ErrorAction Ignore | Select-Object OwnerNode

if ( $null -eq $res ) {
Write-Verbose "Active Node unavailable"
Expand Down Expand Up @@ -915,7 +915,7 @@ function IsConfigurationStateSkipped {
if ($Code -eq "Success") {
return $true
}
}
}
# known issue in SDN where the policy configuration failure is reported on VFP on LNETs
# todo : remove this once the issue is fixed in SDN
elseif ($Source -eq "VirtualSwitch") {
Expand Down Expand Up @@ -1183,26 +1183,20 @@ function Debug-SdnFabricInfrastructure {
$sdnFabricDetails.ComputerName = $environmentInfo[$object.ToString()]
}

$restApiParams = @{
NcUri = $sdnFabricDetails.NcUrl
}
$restApiParams += $restCredParam

# before proceeding with tests, ensure that the computer objects we are testing against are running the latest version of SdnDiagnostics
Install-SdnDiagnostics -ComputerName $sdnFabricDetails.ComputerName -Credential $Credential

$params = @{
ComputerName = $sdnFabricDetails.ComputerName
Credential = $Credential
ScriptBlock = $null
ArgumentList = @($restApiParams)
}

switch ($object) {
'Gateway' { $params.ScriptBlock = { param($boundParams) Debug-SdnGateway @boundParams } }
'LoadBalancerMux' { $params.ScriptBlock = { param($boundParams) Debug-SdnLoadBalancerMux @boundParams } }
'NetworkController' { $params.ScriptBlock = { param($boundParams) Debug-SdnNetworkController @boundParams } }
'Server' { $params.ScriptBlock = { param($boundParams) Debug-SdnServer @boundParams } }
'Gateway' { $params.ScriptBlock = { Debug-SdnGateway } }
'LoadBalancerMux' { $params.ScriptBlock = { Debug-SdnLoadBalancerMux } }
'NetworkController' { $params.ScriptBlock = { Debug-SdnNetworkController } }
'Server' { $params.ScriptBlock = { Debug-SdnServer } }
}

$healthReport = Invoke-SdnCommand @params
Expand Down Expand Up @@ -1435,7 +1429,7 @@ function GetSdnResourceFromNc {
if ($null -ne $cert) {
$sdnRequestParams["NcRestCertificate"] = $cert
Write-Verbose "Retrieving $NcUri with certificate $($cert.Subject) thumbprint $($cert.Thumbprint)"
}
}
else {
Write-Verbose "Retrieving $NcUri without certificate"
}
Expand Down Expand Up @@ -1512,25 +1506,8 @@ function Get-SdnFabricInfrastructureResult {
}

function Debug-SdnNetworkController {
[CmdletBinding(DefaultParameterSetName = 'RestCredential')]
param (
[Parameter(Mandatory = $true)]
[ValidateScript({
if ($_.Scheme -ne "http" -and $_.Scheme -ne "https") {
throw New-Object System.FormatException("Parameter is expected to be in http:// or https:// format.")
}
return $true
})]
[Uri]$NcUri,

[Parameter(Mandatory = $false, ParameterSetName = 'RestCredential')]
[System.Management.Automation.PSCredential]
[System.Management.Automation.Credential()]
$NcRestCredential = [System.Management.Automation.PSCredential]::Empty,

[Parameter(Mandatory = $true, ParameterSetName = 'RestCertificate')]
[X509Certificate]$NcRestCertificate
)
[CmdletBinding()]
param ()

Confirm-IsNetworkController
$healthReport = New-SdnRoleHealthReport -Role 'NetworkController'
Expand Down Expand Up @@ -1584,34 +1561,14 @@ function Debug-SdnNetworkController {
}

function Debug-SdnServer {
[CmdletBinding(DefaultParameterSetName = 'RestCredential')]
param (
[Parameter(Mandatory = $true)]
[ValidateScript({
if ($_.Scheme -ne "http" -and $_.Scheme -ne "https") {
throw New-Object System.FormatException("Parameter is expected to be in http:// or https:// format.")
}
return $true
})]
[Uri]$NcUri,

[Parameter(Mandatory = $false, ParameterSetName = 'RestCredential')]
[System.Management.Automation.PSCredential]
[System.Management.Automation.Credential()]
$NcRestCredential = [System.Management.Automation.PSCredential]::Empty,

[Parameter(Mandatory = $true, ParameterSetName = 'RestCertificate')]
[X509Certificate]$NcRestCertificate
)
[CmdletBinding()]
param ()

Confirm-IsServer
$config = Get-SdnModuleConfiguration -Role 'Server'
[string[]]$services = $config.properties.services.Keys
$healthReport = New-SdnRoleHealthReport -Role 'Server'

$ncRestParams = $PSBoundParameters
$serverResource = Get-SdnResource @ncRestParams -Resource:Servers

try {
# execute tests based on the cluster type
switch ($Global:SdnDiagnostics.EnvironmentInfo.ClusterConfigType) {
Expand Down Expand Up @@ -1639,14 +1596,6 @@ function Debug-SdnServer {
Test-SdnNetworkControllerApiNameResolution -NcUri $NcUri
)

# these tests have dependencies on network controller rest API being available
# and will only be executed if we have been able to get the data from the network controller
if ($serverResource) {
$healthReport.HealthTest += @(
Test-ServerHostId -InstanceId $serverResource.InstanceId
)
}

# enumerate all the tests performed so we can determine if any completed with WARN or FAIL
# if any of the tests completed with WARN, we will set the aggregate result to WARN
# if any of the tests completed with FAIL, we will set the aggregate result to FAIL and then break out of the foreach loop
Expand All @@ -1670,40 +1619,15 @@ function Debug-SdnServer {
}

function Debug-SdnLoadBalancerMux {
[CmdletBinding(DefaultParameterSetName = 'RestCredential')]
param (
[Parameter(Mandatory = $true)]
[ValidateScript({
if ($_.Scheme -ne "http" -and $_.Scheme -ne "https") {
throw New-Object System.FormatException("Parameter is expected to be in http:// or https:// format.")
}
return $true
})]
[Uri]$NcUri,

[Parameter(Mandatory = $false, ParameterSetName = 'RestCredential')]
[System.Management.Automation.PSCredential]
[System.Management.Automation.Credential()]
$NcRestCredential = [System.Management.Automation.PSCredential]::Empty,

[Parameter(Mandatory = $true, ParameterSetName = 'RestCertificate')]
[X509Certificate]$NcRestCertificate
)
[CmdletBinding()]
param ()

Confirm-IsLoadBalancerMux
$config = Get-SdnModuleConfiguration -Role 'LoadBalancerMux'
[string[]]$services = $config.properties.services.Keys
$healthReport = New-SdnRoleHealthReport -Role 'LoadBalancerMux'

$ncRestParams = $PSBoundParameters

try {
$muxCertRegKey = Get-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\SlbMux" -Name MuxCert
$virtualServers = Get-SdnResource -Resource VirtualServers @ncRestParams
$muxVirtualServer = $virtualServers | Where-Object { $_.properties.connections.managementaddresses -contains $muxCertRegKey.MuxCert }
$loadBalancerMux = Get-SdnLoadBalancerMux @ncRestParams | Where-Object { $_.properties.virtualserver.resourceRef -ieq $muxVirtualServer.resourceRef }
$peerRouters = $loadBalancerMux.properties.routerConfiguration.peerRouterConfigurations.routerIPAddress

$healthReport.HealthTest += @(
Test-SdnNonSelfSignedCertificateInTrustedRootStore
Test-SdnServiceState -ServiceName $services
Expand All @@ -1712,14 +1636,6 @@ function Debug-SdnLoadBalancerMux {
Test-SdnNetworkControllerApiNameResolution -NcUri $NcUri
)

# these tests have dependencies on network controller rest API being available
# and will only be executed if we have been able to get the data from the network controller
if ($muxVirtualServer) {
$healthReport.HealthTest += @(
Test-SdnMuxConnectionStateToRouter -RouterIPAddress $peerRouters
)
}

# enumerate all the tests performed so we can determine if any completed with WARN or FAIL
# if any of the tests completed with WARN, we will set the aggregate result to WARN
# if any of the tests completed with FAIL, we will set the aggregate result to FAIL and then break out of the foreach loop
Expand All @@ -1743,40 +1659,14 @@ function Debug-SdnLoadBalancerMux {
}

function Debug-SdnGateway {
[CmdletBinding(DefaultParameterSetName = 'RestCredential')]
param (
[Parameter(Mandatory = $true, ParameterSetName = 'RestCredential')]
[Parameter(Mandatory = $true, ParameterSetName = 'RestCertificate')]
[ValidateScript({
if ($_.Scheme -ne "http" -and $_.Scheme -ne "https") {
throw New-Object System.FormatException("Parameter is expected to be in http:// or https:// format.")
}
return $true
})]
[Uri]$NcUri,

[Parameter(Mandatory = $false, ParameterSetName = 'RestCredential')]
[System.Management.Automation.PSCredential]
[System.Management.Automation.Credential()]
$NcRestCredential = [System.Management.Automation.PSCredential]::Empty,

[Parameter(Mandatory = $true, ParameterSetName = 'RestCertificate')]
[X509Certificate]$NcRestCertificate
)
[CmdletBinding()]
param ()

Confirm-IsRasGateway
$config = Get-SdnModuleConfiguration -Role 'Gateway'
[string[]]$services = $config.properties.services.Keys
$healthReport = New-SdnRoleHealthReport -Role 'Gateway'

$ncRestParams = @{
NcUri = $NcUri
}
switch ($PSCmdlet.ParameterSetName) {
'RestCredential' { $ncRestParams += @{ NcRestCredential = $NcRestCredential } }
'RestCertificate' { $ncRestParams += @{ NcRestCertificate = $NcRestCertificate } }
}

try {
$healthReport.HealthTest += @(
Test-SdnNonSelfSignedCertificateInTrustedRootStore
Expand Down Expand Up @@ -2855,6 +2745,7 @@ function Test-SdnConfigurationState {
##### MUX HEALTH VALIDATIONS ######
###################################


function Test-SdnMuxConnectionStateToRouter {
<#
SYNOPSIS
Expand Down

0 comments on commit 00b9e7b

Please sign in to comment.