Skip to content

Commit

Permalink
Import nc module within health module (#312)
Browse files Browse the repository at this point in the history
# Description
This pull request includes several changes to the `SdnDiag.Health`
module, focusing on importing additional modules, improving URL name
resolution, and enhancing service state validation.

### Module Imports:
*
[`src/modules/SdnDiag.Health/SdnDiag.Health.psm1`](diffhunk://#diff-57c55f0db8ff59b4c3946d347cc71a7ff64cd3d3b7f5587e3e3615dcb43f0780R8-R9):
Added imports for `SdnDiag.NetworkController.FC` and
`SdnDiag.NetworkController.SF` modules to extend functionality.

### URL Name Resolution:
* `src/modules/SdnDiag.Health/private/Test-NcUrlNameResolution.ps1`: 
* Updated to use `Get-SdnNetworkController` instead of
`Get-SdnNetworkControllerSF` for consistency.
* Improved logic to handle IP address parsing and comparison for network
controller certificates.
[[1]](diffhunk://#diff-53875d037e2095362d1f4d2ebce09ba56c67e194efbb31a4155b7fc6a28b3a43L30-R47)
[[2]](diffhunk://#diff-53875d037e2095362d1f4d2ebce09ba56c67e194efbb31a4155b7fc6a28b3a43L61-R70)

### Service State Validation:
*
[`src/modules/SdnDiag.Health/private/Test-ServiceState.ps1`](diffhunk://#diff-6853618dcd72434d2b4e84e4b0d8e45e189f4b4990f5694fd2ac2d00cccb2c7dR24-R27):
Added a check to return early if no services are defined, avoiding
unnecessary processing.

# 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 Aug 26, 2024
1 parent 4f3b255 commit 90c7a14
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/modules/SdnDiag.Health/SdnDiag.Health.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Using module .\SdnDiag.Health.Helper.psm1

Import-Module $PSScriptRoot\SdnDiag.Health.Helper.psm1
Import-Module $PSScriptRoot\..\SdnDiag.Common\SdnDiag.Common.psm1
Import-Module $PSScriptRoot\..\SdnDiag.NetworkController.FC\SdnDiag.NetworkController.FC.psm1
Import-Module $PSScriptRoot\..\SdnDiag.NetworkController.SF\SdnDiag.NetworkController.SF.psm1
Import-Module $PSScriptRoot\..\SdnDiag.Utilities\SdnDiag.Utilities.psm1

# create local variable to store configuration data
Expand Down
17 changes: 13 additions & 4 deletions src/modules/SdnDiag.Health/private/Test-NcUrlNameResolution.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,24 @@ function Test-NcUrlNameResolution {
return $sdnHealthObject
}

$networkController = Get-SdnNetworkControllerSF -NetworkController $SdnEnvironmentObject.ComputerName[0] -Credential $Credential
$networkController = Get-SdnNetworkController -NetworkController $SdnEnvironmentObject.ComputerName[0] -Credential $Credential
if ($null -eq $networkController) {
"Unable to retrieve results from Get-SdnNetworkControllerSF" | Trace-Output -Level:Warning
"Unable to retrieve results from Get-SdnNetworkController" | Trace-Output -Level:Warning
return $sdnHealthObject
}

# depending on the configuration returned, will determine if we need to use the RestIPAddress or RestName
$nbApiName = $networkController.ServerCertificate.Subject.Split('=')[1].Trim()

if ($networkController.RestIPAddress) {
$expectedIPAddress = $($networkController.RestIPAddress).Split('/')[0].Trim() # we expect to be in IP/CIDR format
"Network Controller is configured with static RestIPAddress: {0}" -f $expectedIPAddress | Trace-Output -Level:Verbose
}
else {
"Network Controller is configured with RestName" | Trace-Output -Level:Verbose
$ncNodeName = $ncApiReplicaPrimary.ReplicaAddress.Split(':')[0].Trim()
if ($ncNodeName -is [System.Net.IPAddress]) {
$isIpAddress = [System.Net.IPAddress]::TryParse($ncNodeName, [ref]$null)
if ($isIpAddress) {
$expectedIPAddress = $ncNodeName.ToString()
}
else {
Expand All @@ -58,7 +60,14 @@ function Test-NcUrlNameResolution {
}
}

# after we have performed some validation, we want to now perform some DNS resolution to ensure that the NB API URL resolves to the correct IP address
# in this scenario, the certificate is using an IP address as the subject, so we will need to compare the IP address to the expected IP address
# if they match, we will return a success
$isIpAddress = [System.Net.IPAddress]::TryParse($nbApiName, [ref]$null)
if ($isIpAddress -and ($nbApiName -ieq $expectedIPAddress)) {
return $sdnHealthObject
}

# perform some DNS resolution to ensure that the NB API URL resolves to the correct IP address
$dnsResult = Resolve-DnsName -Name $nbApiName -NoHostsFile -ErrorAction SilentlyContinue
if ($null -ieq $dnsResult) {
$sdnHealthObject.Result = 'FAIL'
Expand Down
4 changes: 4 additions & 0 deletions src/modules/SdnDiag.Health/private/Test-ServiceState.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ function Test-ServiceState {

try {
[string[]]$services = $SdnEnvironmentObject.Role.Properties.Services.Keys
if ([string]::IsNullOrEmpty($services)) {
return $sdnHealthObject
}

"Validating {0} service state for {1}" -f ($services -join ', '), ($SdnEnvironmentObject.ComputerName -join ', ') | Trace-Output

$scriptBlock = {
Expand Down

0 comments on commit 90c7a14

Please sign in to comment.