Skip to content

Commit

Permalink
Merge pull request #165 from rchaganti/dev
Browse files Browse the repository at this point in the history
Adding xNetAdapterRDMA
  • Loading branch information
PlagueHO committed Dec 13, 2016
2 parents 0e1d86f + af4d4fa commit ef3d914
Show file tree
Hide file tree
Showing 9 changed files with 565 additions and 0 deletions.
155 changes: 155 additions & 0 deletions DSCResources/MSFT_xNetAdapterRDMA/MSFT_xNetAdapterRDMA.psm1
@@ -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
}
}
@@ -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;
};
@@ -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.
'@
22 changes: 22 additions & 0 deletions Examples/Sample_xNetAdapterRDMA_Disable.ps1
@@ -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
22 changes: 22 additions & 0 deletions Examples/Sample_xNetAdapterRDMA_Enable.ps1
@@ -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
6 changes: 6 additions & 0 deletions README.md
Expand Up @@ -18,6 +18,7 @@ The **xNetworking** module contains the following resources:
- **xHostsFile**: Adds, edits or removes entries from the hosts file on a node.
- **xNetAdapterBinding**: Bind or unbind transport or filters to a network interface.
- **xDnsClientGlobalSetting**: Configure DNS client global settings.
- **xNetAdapterRDMA**: Enable or disable RDMA on a network adapter.

This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
Expand Down Expand Up @@ -154,6 +155,10 @@ Please check out common DSC Resources [contributing guidelines](https://github.c
- **`[Boolean]` UseDevolution** (_Write_): Specifies that devolution is activated.
- **`[Uint32]` DevolutionLevel** (_Write_): Specifies the number of labels up to which devolution should occur.

### xNetAdapterRDMA
* **`[String]` Name**: Specifies the name of the adapter for which RDMA configuration needs to be done.
* **`[Boolean]` Enabled**: Specifies if RDMA setting must be enabled or disabled. { $true | $false }

## Functions

### Get-xNetworkAdapterName
Expand Down Expand Up @@ -207,6 +212,7 @@ The following error may occur when applying xFirewall configurations on Windows
- Changed parameter format in Readme.md to improve information coverage and consistency.
- Changed all MOF files to be consistent and meet HQRM guidelines.
- Removed most markdown errors (MD*) in Readme.md.
- Added xNetAdapterRDMA resource
- Fixes to support changes to DSCResource.Tests.

### 3.0.0.0
Expand Down
63 changes: 63 additions & 0 deletions Tests/Integration/MSFT_xNetAdapterRDMA.Integration.Tests.ps1
@@ -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
}
24 changes: 24 additions & 0 deletions Tests/Integration/MSFT_xNetAdapterRDMA.config.ps1
@@ -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
}
}
}

0 comments on commit ef3d914

Please sign in to comment.