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

xExchInstall: Add remaining xExchInstall Unit Tests and add common setup tests #321

Merged
merged 6 commits into from
Sep 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# Needed for publishing of examples, build worker defaults to core.autocrlf=input.
* text eol=crlf

# Allow Excel files in examples to be saved as binary files
*.xl* binary
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
- Added default template files .codecov.yml, .gitattributes, and .gitignore, and
.vscode folder.
- Add Unit Tests for xExchAntiMalwareScanning
- Add remaining Unit Tests for xExchInstall, and for most common setup
functions

## 1.23.0.0

Expand Down
236 changes: 118 additions & 118 deletions DSCResources/MSFT_xExchEventLogLevel/MSFT_xExchEventLogLevel.psm1
Original file line number Diff line number Diff line change
@@ -1,118 +1,118 @@
function Get-TargetResource
{
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSDSCUseVerboseMessageInDSCResource", "")]
[CmdletBinding()]
[OutputType([System.Collections.Hashtable])]
param
(
[Parameter(Mandatory = $true)]
[System.String]
$Identity,
[Parameter(Mandatory = $true)]
[System.Management.Automation.PSCredential]
[System.Management.Automation.Credential()]
$Credential,
[Parameter(Mandatory = $true)]
[ValidateSet('Lowest','Low','Medium','High','Expert')]
[System.String]
$Level
)
Write-FunctionEntry -Parameters @{'Identity' = $Identity} -Verbose:$VerbosePreference
#Establish remote Powershell session
Get-RemoteExchangeSession -Credential $Credential -CommandsToLoad 'Get-EventLogLevel' -Verbose:$VerbosePreference
$eventLogLevel = Get-EventLogLevel -Identity "$($env:COMPUTERNAME)\$($Identity)"
if ($null -ne $eventLogLevel)
{
$returnValue = @{
Identity = [System.String] $Identity
Level = [System.String] $eventLogLevel.EventLevel
}
}
$returnValue
}
function Set-TargetResource
{
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSDSCUseVerboseMessageInDSCResource", "")]
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[System.String]
$Identity,
[Parameter(Mandatory = $true)]
[System.Management.Automation.PSCredential]
[System.Management.Automation.Credential()]
$Credential,
[Parameter(Mandatory = $true)]
[ValidateSet('Lowest','Low','Medium','High','Expert')]
[System.String]
$Level
)
Write-FunctionEntry -Parameters @{'Identity' = $Identity} -Verbose:$VerbosePreference
#Establish remote Powershell session
Get-RemoteExchangeSession -Credential $Credential -CommandsToLoad 'Set-EventLogLevel' -Verbose:$VerbosePreference
Set-EventLogLevel -Identity "$($env:COMPUTERNAME)\$($Identity)" -Level $Level
}
function Test-TargetResource
{
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSDSCUseVerboseMessageInDSCResource", "")]
[CmdletBinding()]
[OutputType([System.Boolean])]
param
(
[Parameter(Mandatory = $true)]
[System.String]
$Identity,
[Parameter(Mandatory = $true)]
[System.Management.Automation.PSCredential]
[System.Management.Automation.Credential()]
$Credential,
[Parameter(Mandatory = $true)]
[ValidateSet('Lowest','Low','Medium','High','Expert')]
[System.String]
$Level
)
Write-FunctionEntry -Parameters @{'Identity' = $Identity} -Verbose:$VerbosePreference
#Establish remote Powershell session
Get-RemoteExchangeSession -Credential $Credential -CommandsToLoad 'Get-EventLogLevel' -Verbose:$VerbosePreference
$eventLogLevel = Get-EventLogLevel -Identity "$($env:COMPUTERNAME)\$($Identity)"
$testResults = $true
if ($null -eq $eventLogLevel)
{
Write-Error -Message 'Failed to retrieve any objects with specified Identity.'
$testResults = $false
}
else
{
if (!(Test-ExchangeSetting -Name 'Level' -Type 'String' -ExpectedValue $Level -ActualValue $eventLogLevel.EventLevel -PSBoundParametersIn $PSBoundParameters -Verbose:$VerbosePreference))
{
$testResults = $false
}
}
return $testResults
}
Export-ModuleMember -Function *-TargetResource
function Get-TargetResource
{
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSDSCUseVerboseMessageInDSCResource", "")]
[CmdletBinding()]
[OutputType([System.Collections.Hashtable])]
param
(
[Parameter(Mandatory = $true)]
[System.String]
$Identity,

[Parameter(Mandatory = $true)]
[System.Management.Automation.PSCredential]
[System.Management.Automation.Credential()]
$Credential,

[Parameter(Mandatory = $true)]
[ValidateSet('Lowest','Low','Medium','High','Expert')]
[System.String]
$Level
)

Write-FunctionEntry -Parameters @{'Identity' = $Identity} -Verbose:$VerbosePreference

#Establish remote Powershell session
Get-RemoteExchangeSession -Credential $Credential -CommandsToLoad 'Get-EventLogLevel' -Verbose:$VerbosePreference

$eventLogLevel = Get-EventLogLevel -Identity "$($env:COMPUTERNAME)\$($Identity)"

if ($null -ne $eventLogLevel)
{
$returnValue = @{
Identity = [System.String] $Identity
Level = [System.String] $eventLogLevel.EventLevel
}
}

$returnValue
}

function Set-TargetResource
{
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSDSCUseVerboseMessageInDSCResource", "")]
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[System.String]
$Identity,

[Parameter(Mandatory = $true)]
[System.Management.Automation.PSCredential]
[System.Management.Automation.Credential()]
$Credential,

[Parameter(Mandatory = $true)]
[ValidateSet('Lowest','Low','Medium','High','Expert')]
[System.String]
$Level
)

Write-FunctionEntry -Parameters @{'Identity' = $Identity} -Verbose:$VerbosePreference

#Establish remote Powershell session
Get-RemoteExchangeSession -Credential $Credential -CommandsToLoad 'Set-EventLogLevel' -Verbose:$VerbosePreference

Set-EventLogLevel -Identity "$($env:COMPUTERNAME)\$($Identity)" -Level $Level
}

function Test-TargetResource
{
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSDSCUseVerboseMessageInDSCResource", "")]
[CmdletBinding()]
[OutputType([System.Boolean])]
param
(
[Parameter(Mandatory = $true)]
[System.String]
$Identity,

[Parameter(Mandatory = $true)]
[System.Management.Automation.PSCredential]
[System.Management.Automation.Credential()]
$Credential,

[Parameter(Mandatory = $true)]
[ValidateSet('Lowest','Low','Medium','High','Expert')]
[System.String]
$Level
)

Write-FunctionEntry -Parameters @{'Identity' = $Identity} -Verbose:$VerbosePreference

#Establish remote Powershell session
Get-RemoteExchangeSession -Credential $Credential -CommandsToLoad 'Get-EventLogLevel' -Verbose:$VerbosePreference

$eventLogLevel = Get-EventLogLevel -Identity "$($env:COMPUTERNAME)\$($Identity)"

$testResults = $true

if ($null -eq $eventLogLevel)
{
Write-Error -Message 'Failed to retrieve any objects with specified Identity.'

$testResults = $false
}
else
{
if (!(Test-ExchangeSetting -Name 'Level' -Type 'String' -ExpectedValue $Level -ActualValue $eventLogLevel.EventLevel -PSBoundParametersIn $PSBoundParameters -Verbose:$VerbosePreference))
{
$testResults = $false
}
}

return $testResults
}

Export-ModuleMember -Function *-TargetResource
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[ClassVersion("1.0.0.0"), FriendlyName("xExchEventLogLevel")]
class MSFT_xExchEventLogLevel : OMI_BaseResource
{
[Key, Description("The Identity parameter specifies the name of the event logging category for which you want to set the event logging level.")] String Identity;
[Required, Description("Credentials used to establish a remote Powershell session to Exchange"), EmbeddedInstance("MSFT_Credential")] String Credential;
[Required, Description("The Level parameter specifies the log level for the specific event logging category."), ValueMap{"Lowest","Low","Medium","High","Expert"}, Values{"Lowest","Low","Medium","High","Expert"}] String Level;
};

[ClassVersion("1.0.0.0"), FriendlyName("xExchEventLogLevel")]
class MSFT_xExchEventLogLevel : OMI_BaseResource
{
[Key, Description("The Identity parameter specifies the name of the event logging category for which you want to set the event logging level.")] String Identity;
[Required, Description("Credentials used to establish a remote Powershell session to Exchange"), EmbeddedInstance("MSFT_Credential")] String Credential;
[Required, Description("The Level parameter specifies the log level for the specific event logging category."), ValueMap{"Lowest","Low","Medium","High","Expert"}, Values{"Lowest","Low","Medium","High","Expert"}] String Level;
};

36 changes: 3 additions & 33 deletions DSCResources/MSFT_xExchInstall/MSFT_xExchInstall.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -72,23 +72,7 @@ function Set-TargetResource

Start-ExchangeScheduledTask -Path "$Path" -Arguments "$Arguments" -Credential $Credential -TaskName 'Install Exchange' -Verbose:$VerbosePreference

$detectedExsetup = $false

Write-Verbose -Message 'Waiting up to 60 seconds before exiting to give time for ExSetup.exe to start'

for ($i = 0; $i -lt 60; $i++)
{
if ($null -eq (Get-Process -Name ExSetup -ErrorAction SilentlyContinue))
{
Start-Sleep -Seconds 1
}
else
{
Write-Verbose -Message 'Detected that ExSetup.exe is running'
$detectedExsetup = $true
break
}
}
$detectedExsetup = Wait-ForProcessStart -ProcessName 'ExSetup' -Verbose:$VerbosePreference

if ($detectedExsetup -eq $false)
{
Expand All @@ -112,24 +96,10 @@ function Set-TargetResource
if ($waitingForSetup)
{
#Now wait for setup to finish
while ($null -ne (Get-Process -Name ExSetup -ErrorAction SilentlyContinue))
{
Write-Verbose -Message "Setup is still running at $([DateTime]::Now). Sleeping for 1 minute."
Start-Sleep -Seconds 60
}
Wait-ForProcessStop -ProcessName 'ExSetup' -Verbose:$VerbosePreference
}

#Check install status one more time and see if setup was successful
$installStatus = Get-ExchangeInstallStatus -Arguments $Arguments -Verbose:$VerbosePreference

if ($installStatus.SetupComplete)
{
Write-Verbose -Message 'Exchange setup completed successfully'
}
else
{
throw 'Exchange setup did not complete successfully. See "<system drive>\ExchangeSetupLogs\ExchangeSetup.log" for details.'
}
Assert-ExchangeSetupArgumentsComplete -Arguments $Arguments -Verbose:$VerbosePreference
}

function Test-TargetResource
Expand Down
Loading