Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #165 from rchaganti/dev
Adding xNetAdapterRDMA
- Loading branch information
Showing
9 changed files
with
565 additions
and
0 deletions.
There are no files selected for viewing
155 changes: 155 additions & 0 deletions
155
DSCResources/MSFT_xNetAdapterRDMA/MSFT_xNetAdapterRDMA.psm1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
#region localizeddata | ||
if (Test-Path "${PSScriptRoot}\${PSUICulture}") | ||
{ | ||
Import-LocalizedData -BindingVariable localizedData -filename MSFT_xNetAdapterRDMA.psd1 ` | ||
-BaseDirectory "${PSScriptRoot}\${PSUICulture}" | ||
} | ||
else | ||
{ | ||
#fallback to en-US | ||
Import-LocalizedData -BindingVariable localizedData -filename MSFT_xNetAdapterRDMA.psd1 ` | ||
-BaseDirectory "${PSScriptRoot}\en-US" | ||
} | ||
#endregion | ||
|
||
<# | ||
.SYNOPSIS | ||
Gets MSFT_xVMNetAdapterRDMA resource current state. | ||
.PARAMETER Name | ||
Specifies the name of the network adapter for which the RDMA configuration needs to be retrieved. | ||
#> | ||
function Get-TargetResource | ||
{ | ||
[CmdletBinding()] | ||
[OutputType([Hashtable])] | ||
param | ||
( | ||
[parameter(Mandatory = $true)] | ||
[String] | ||
$Name | ||
) | ||
|
||
$configuration = @{ | ||
Name = $Name | ||
} | ||
|
||
try | ||
{ | ||
Write-Verbose -Message $localizedData.CheckNetAdapter | ||
$netAdapter = Get-NetAdapterRdma -Name $Name -ErrorAction Stop | ||
if ($netAdapter) | ||
{ | ||
Write-Verbose -Message $localizedData.CheckNetAdapterRDMA | ||
$configuration.Add('Enabled',$netAdapter.Enabled) | ||
return $configuration | ||
} | ||
} | ||
catch | ||
{ | ||
throw $localizedData.NetAdapterNotFound | ||
} | ||
} | ||
|
||
<# | ||
.SYNOPSIS | ||
Sets MSFT_xVMNetAdapterRDMA resource state. | ||
.PARAMETER Name | ||
Specifies the name of the network adapter for which the | ||
RDMA configuration needs to be retrieved. | ||
.PARAMETER Enabled | ||
Specifies if the RDMA configuration should be enabled or disabled. | ||
This is a boolean value and the default is $true. | ||
#> | ||
function Set-TargetResource | ||
{ | ||
[CmdletBinding()] | ||
param | ||
( | ||
[parameter(Mandatory = $true)] | ||
[String] | ||
$Name, | ||
|
||
[parameter()] | ||
[Boolean] | ||
$Enabled = $true | ||
) | ||
|
||
$configuration = @{ | ||
Name = $Name | ||
} | ||
|
||
try | ||
{ | ||
Write-Verbose -Message $localizedData.CheckNetAdapter | ||
$netAdapter = Get-NetAdapterRdma -Name $Name -ErrorAction Stop | ||
if ($netAdapter) | ||
{ | ||
Write-Verbose -Message $localizedData.CheckNetAdapterRDMA | ||
if ($netAdapter.Enabled -ne $Enabled) | ||
{ | ||
Write-Verbose -Message $localizedData.NetAdapterRDMADifferent | ||
Write-Verbose -Message $localizedData.SetNetAdapterRDMA | ||
Set-NetAdapterRdma -Name $Name -Enabled $Enabled | ||
} | ||
} | ||
} | ||
catch | ||
{ | ||
throw $localizedData.NetAdapterNotFound | ||
} | ||
} | ||
|
||
<# | ||
.SYNOPSIS | ||
Tests if MSFT_xVMNetAdapterRDMA resource state is indeed desired state or not. | ||
.PARAMETER Name | ||
Specifies the name of the network adapter for which the | ||
RDMA configuration needs to be retrieved. | ||
.PARAMETER Enabled | ||
Specifies if the RDMA configuration should be enabled or disabled. | ||
This is a boolean value and the default is $true. | ||
#> | ||
function Test-TargetResource | ||
{ | ||
[CmdletBinding()] | ||
[OutputType([System.Boolean])] | ||
param | ||
( | ||
[parameter(Mandatory = $true)] | ||
[String] | ||
$Name, | ||
|
||
[parameter()] | ||
[Boolean] | ||
$Enabled = $true | ||
) | ||
|
||
try | ||
{ | ||
Write-Verbose -Message $localizedData.CheckNetAdapter | ||
$netAdapter = Get-NetAdapterRdma -Name $Name -ErrorAction Stop | ||
if ($netAdapter) | ||
{ | ||
Write-Verbose -Message $localizedData.CheckNetAdapterRDMA | ||
if ($netAdapter.Enabled -ne $Enabled) | ||
{ | ||
Write-Verbose -Message $localizedData.NetAdapterRDMADifferent | ||
return $false | ||
} | ||
else | ||
{ | ||
Write-Verbose -Message $localizedData.NetAdapterRDMAMatches | ||
return $true | ||
} | ||
} | ||
} | ||
catch | ||
{ | ||
throw $localizedData.NetAdapterNotFound | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
DSCResources/MSFT_xNetAdapterRDMA/MSFT_xNetAdapterRDMA.schema.mof
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[ClassVersion("1.0.0.0"), FriendlyName("xNetAdapterRDMA")] | ||
class MSFT_xNetAdapterRDMA : OMI_BaseResource | ||
{ | ||
[Key, Description("Specifies the name of network adapter for which RDMA needs to be configured.")] String Name; | ||
[Write, Description("Specifies whether RDMA is enabled or disabled.")] Boolean Enabled; | ||
}; |
8 changes: 8 additions & 0 deletions
8
DSCResources/MSFT_xNetAdapterRDMA/en-US/MSFT_xNetAdapterRDMA.psd1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
ConvertFrom-StringData @' | ||
CheckNetAdapter = Checking if network adapter exists or not. | ||
CheckNetAdapterRDMA = Checking if RDMA is enabled and in desired state for this adapter. | ||
NetAdapterNotFound = Network Adapter not found. | ||
NetAdapterRDMADifferent = Network adapter RDMA setting is not in desired state. This will be configured. | ||
SetNetAdapterRDMA = Setting network adapter RDMA configuration to desired state. | ||
NetAdapterRDMAMatches = Network adapter RDMA configuration is in desired state. No action needed. | ||
'@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#This configuration disables RDMA setting on the network adapter. | ||
configuration Sample_xNetAdapterRDMA_Disable | ||
{ | ||
param | ||
( | ||
[string[]]$NodeName = 'localhost' | ||
) | ||
|
||
Import-DSCResource -ModuleName xNetworking -Name xNetAdapterRDMA | ||
|
||
Node $NodeName | ||
{ | ||
xNetAdapterRDMA SMBAdapter1 | ||
{ | ||
Name = 'SMB1_1' | ||
Enabled = $false | ||
} | ||
} | ||
} | ||
|
||
Sample_xNetAdapterRDMA_Disable | ||
Start-DscConfiguration -Path Sample_xNetAdapterRDMA_Disable -Wait -Verbose -Force |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#This configuration enables RDMA setting on the network adapter. | ||
configuration Sample_xNetAdapterRDMA_Enable | ||
{ | ||
param | ||
( | ||
[string[]]$NodeName = 'localhost' | ||
) | ||
|
||
Import-DSCResource -ModuleName xNetworking -Name xNetAdapterRDMA | ||
|
||
Node $NodeName | ||
{ | ||
xNetAdapterRDMA SMBAdapter1 | ||
{ | ||
Name = 'SMB1_1' | ||
Enabled = $true | ||
} | ||
} | ||
} | ||
|
||
Sample_xNetAdapterRDMA_Enable | ||
Start-DscConfiguration -Path Sample_xNetAdapterRDMA_Enable -Wait -Verbose -Force |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
Tests/Integration/MSFT_xNetAdapterRDMA.Integration.Tests.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#Remove this following line before using this integration test script | ||
return | ||
|
||
$script:DSCModuleName = 'xNetworking' | ||
$script:DSCResourceName = 'MSFT_xNetAdapterRDMA' | ||
|
||
#region HEADER | ||
if ( (-not (Test-Path -Path '.\DSCResource.Tests\')) -or ` | ||
(-not (Test-Path -Path '.\DSCResource.Tests\TestHelper.psm1')) ) | ||
{ | ||
& git @('clone','https://github.com/PowerShell/DscResource.Tests.git') | ||
} | ||
else | ||
{ | ||
& git @('-C',(Join-Path -Path (Get-Location) -ChildPath '\DSCResource.Tests\'),'pull') | ||
} | ||
Import-Module .\DSCResource.Tests\TestHelper.psm1 -Force | ||
$TestEnvironment = Initialize-TestEnvironment ` | ||
-DSCModuleName $script:DSCModuleName ` | ||
-DSCResourceName $script:DSCResourceName ` | ||
-TestType Integration | ||
#endregion | ||
|
||
# Using try/finally to always cleanup even if something awful happens. | ||
try | ||
{ | ||
#region Integration Tests | ||
$ConfigFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:DSCResourceName).config.ps1" | ||
. $ConfigFile -Verbose -ErrorAction Stop | ||
|
||
Describe "$($script:DSCResourceName)_Integration" { | ||
#region DEFAULT TESTS | ||
It 'Should compile without throwing' { | ||
{ | ||
& "$($script:DSCResourceName)_Config" -OutputPath $TestDrive | ||
Start-DscConfiguration -Path $TestDrive ` | ||
-ComputerName localhost -Wait -Verbose -Force | ||
} | Should not throw | ||
} | ||
|
||
It 'should be able to call Get-DscConfiguration without throwing' { | ||
{ Get-DscConfiguration -Verbose -ErrorAction Stop } | Should Not throw | ||
} | ||
#endregion | ||
|
||
It 'Should have set the resource and all the parameters should match' { | ||
$result = Get-DscConfiguration | Where-Object {$_.ConfigurationName -eq "$($script:DSCResourceName)_Config"} | ||
$result.Name | Should Be $TestAdapter.Name | ||
$result.Enabled | Should Be $TestAdapter.Enabled | ||
} | ||
|
||
Set-NetAdapterRDMA ` | ||
-Name $TestAdapter.Name ` | ||
-Enabled $false | ||
} | ||
#endregion | ||
} | ||
finally | ||
{ | ||
#region FOOTER | ||
Restore-TestEnvironment -TestEnvironment $TestEnvironment | ||
#endregion | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
$TestAdapter = [PSObject]@{ | ||
Name = 'SMB1_1' | ||
Enabled = $true | ||
} | ||
|
||
#This configuration enables RDMA setting on the network adapter. | ||
configuration MSFT_xNetAdapterRDMA_Config | ||
{ | ||
param | ||
( | ||
[string[]]$NodeName = 'localhost' | ||
) | ||
|
||
Import-DSCResource -ModuleName xNetworking -Name xNetAdapterRDMA | ||
|
||
Node $NodeName | ||
{ | ||
xNetAdapterRDMA SMB1 | ||
{ | ||
Name = $TestAdapter.Name | ||
Enabled = $TestAdapter.Enabled | ||
} | ||
} | ||
} |
Oops, something went wrong.