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

Merged xTimeZone and converted to HQRM - Fixes #157 #158

Merged
merged 8 commits into from
May 14, 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
15 changes: 8 additions & 7 deletions .vscode/RunAllTests.ps1
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
[string] $repoRoot = Split-Path -Path (Split-Path -Path $Script:MyInvocation.MyCommand.Path)
if ( (-not (Test-Path -Path (Join-Path -Path $repoRoot -ChildPath 'DSCResource.Tests'))) -or `
(-not (Test-Path -Path (Join-Path -Path $repoRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) )
$repoRoot = Split-Path -Path (Split-Path -Path $Script:MyInvocation.MyCommand.Path)
$dscResourceTestsPath = Join-Path -Path $repoRoot -ChildPath '\Modules\ComputerManagementDsc\DSCResource.Tests\'

if ((-not (Test-Path -Path $dscResourceTestsPath)) -or `
(-not (Test-Path -Path (Join-Path -Path $dscResourceTestsPath -ChildPath 'TestHelper.psm1'))))
{
& git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $repoRoot -ChildPath '\DSCResource.Tests\'))
& git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', $dscResourceTestsPath)
}

Import-Module (Join-Path $PSScriptRoot "..\Tests\TestHarness.psm1" -Resolve)
$dscTestsPath = Join-Path -Path $PSScriptRoot `
-ChildPath "..\Modules\ComputerManagementDsc\DscResource.Tests\Meta.Tests.ps1"
Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\Tests\TestHarness.psm1' -Resolve)
$dscTestsPath = Join-Path -Path $dscResourceTestsPath -ChildPath 'Meta.Tests.ps1'
Invoke-TestHarness -DscTestsPath $dscTestsPath
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

## Unreleased

- TimeZone:
- Migrated xTimeZone resource from [xTimeZone](https://github.com/PowerShell/xTimeZone)
and renamed to TimeZone - fixes [Issue #157](https://github.com/PowerShell/ComputerManagementDsc/issues/157).
- Moved Test-Command from ComputerManagementDsc.ResourceHelper to
ComputerManagementDsc.Common module to match what TimeZone requires.
It was not exported in ComputerManagementDsc.ResourceHelper and not
used.

## 5.0.0.0

- BREAKING CHANGE:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
$modulePath = Join-Path -Path (Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent) -ChildPath 'Modules'

# Import the ComputerManagementDsc Common Modules
Import-Module -Name (Join-Path -Path $modulePath `
-ChildPath (Join-Path -Path 'ComputerManagementDsc.Common' `
-ChildPath 'ComputerManagementDsc.Common.psm1'))

# Import the ComputerManagementDsc Resource Helper Module
Import-Module -Name (Join-Path -Path $modulePath `
-ChildPath (Join-Path -Path 'ComputerManagementDsc.ResourceHelper' `
-ChildPath 'ComputerManagementDsc.ResourceHelper.psm1'))

# Import Localization Strings.
$LocalizedData = Get-LocalizedData `
-ResourceName 'MSFT_TimeZone' `
-ResourcePath (Split-Path -Parent $script:MyInvocation.MyCommand.Path)

<#
.SYNOPSIS
Returns the current time zone of the node.

.PARAMETER IsSingleInstance
Specifies the resource is a single instance, the value must be 'Yes'.

.PARAMETER TimeZone
Specifies the time zone.
#>
function Get-TargetResource
{
[CmdletBinding()]
[OutputType([Hashtable])]
param
(
[Parameter(Mandatory = $true)]
[ValidateSet('Yes')]
[System.String]
$IsSingleInstance,

[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[System.String]
$TimeZone
)

Write-Verbose -Message ($LocalizedData.GettingTimeZoneMessage)

# Get the current time zone Id.
$currentTimeZone = Get-TimeZoneId

$returnValue = @{
IsSingleInstance = 'Yes'
TimeZone = $currentTimeZone
}

# Output the target resource.
return $returnValue
}

<#
.SYNOPSIS
Sets the current time zone of the node.

.PARAMETER IsSingleInstance
Specifies the resource is a single instance, the value must be 'Yes'.

.PARAMETER TimeZone
Specifies the time zone.
#>
function Set-TargetResource
{
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[ValidateSet('Yes')]
[System.String]
$IsSingleInstance,

[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[System.String]
$TimeZone
)

$currentTimeZone = Get-TimeZoneId

if ($currentTimeZone -ne $TimeZone)
{
Write-Verbose -Message ($LocalizedData.SettingTimeZoneMessage)
Set-TimeZoneId -TimeZone $TimeZone
}
else
{
Write-Verbose -Message ($LocalizedData.TimeZoneAlreadySetMessage -f $TimeZone)
}
}

<#
.SYNOPSIS
Tests the current time zone of the node.

.PARAMETER IsSingleInstance
Specifies the resource is a single instance, the value must be 'Yes'.

.PARAMETER TimeZone
Specifies the time zone.
#>
function Test-TargetResource
{
[CmdletBinding()]
[OutputType([System.Boolean])]
param
(
[Parameter(Mandatory = $true)]
[ValidateSet('Yes')]
[System.String]
$IsSingleInstance,

[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[System.String]
$TimeZone
)

Write-Verbose -Message ($LocalizedData.TestingTimeZoneMessage)

return Test-TimeZoneId -TimeZoneId $TimeZone
}

Export-ModuleMember -Function *-TargetResource
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[ClassVersion("1.0.0.0"), FriendlyName("TimeZone")]
class MSFT_TimeZone : OMI_BaseResource
{
[Key, Description("Specifies the resource is a single instance, the value must be 'Yes'."), ValueMap{"Yes"}, Values{"Yes"}] String IsSingleInstance;
[Required, Description("Specifies the TimeZone.")] String TimeZone;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Description

The resource will use the `Get-TimeZone` cmdlet to get the current
time zone. If `Get-TimeZone` is not available them CIM will be used to retrieve
the current time zone. To update the time zone, .NET reflection will be used to
update the time zone if required. If .NET reflection is not supported on the node
(in the case of Nano Server) then tzutil.exe will be used to set the time zone.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# culture="en-US"
ConvertFrom-StringData -StringData @'
GettingTimeZoneMessage = Getting the time zone.
SettingTimeZoneMessage = Setting the time zone.
TimeZoneAlreadySetMessage = Time zone already set to {0}.
TestingTimeZoneMessage = Testing the time zone.
'@
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<#
.EXAMPLE
This example sets the current time zone on the node
to 'Tonga Standard Time'.
#>
Configuration Example
{
param
(
[Parameter()]
[System.String[]]
$NodeName = 'localhost'
)

Import-DSCResource -ModuleName ComputerManagementDsc

Node $NodeName
{
TimeZone TimeZoneExample
{
IsSingleInstance = 'Yes'
TimeZone = 'Tonga Standard Time'
}
}
}
Loading