Skip to content

Commit

Permalink
Changes to SqlServiceAccount
Browse files Browse the repository at this point in the history
- Added a read-only parameter ServiceAccountName so correctly returns the
  service account name as a string (issue dsccommunity#982).
  • Loading branch information
johlju committed Jan 1, 2018
1 parent 45f8dbc commit ccb88ef
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 16 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
([issue #930](https://github.com/PowerShell/SqlServerDsc/issues/930)).
- Made the description of parameter RestartService more descriptive
([issue #960](https://github.com/PowerShell/SqlServerDsc/issues/960)).
- Added a read-only parameter ServiceAccountName so correctly returns the
service account name as a string ([issue #982](https://github.com/PowerShell/SqlServerDsc/issues/982)).
- Added integration tests ([issue #980](https://github.com/PowerShell/SqlServerDsc/issues/980)).
- Changes to SqlSetup
- Added parameter `ASServerMode` to support installing Analysis Services in
Expand Down
14 changes: 7 additions & 7 deletions DSCResources/MSFT_SqlServiceAccount/MSFT_SqlServiceAccount.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ function Get-TargetResource
# Replace a domain of '.' with the value for $ServerName
$serviceAccountName = $serviceObject.ServiceAccount -ireplace '^([\.])\\(.*)$', "$ServerName\`$2"

# Return a hashtable with the service information
# Return a hash table with the service information
return @{
ServerName = $ServerName
InstanceName = $InstanceName
ServiceType = $serviceObject.Type
ServiceAccount = $serviceAccountName
ServerName = $ServerName
InstanceName = $InstanceName
ServiceType = $serviceObject.Type
ServiceAccountName = $serviceAccountName
}
}

Expand Down Expand Up @@ -99,7 +99,7 @@ function Get-TargetResource
Forces the service account to be updated.
.EXAMPLE
Test-TargetResource -ServerName $env:COMPUTERNAME -SQLInstaneName MSSQLSERVER -ServiceType DatabaseEngine -ServiceAccount $account
Test-TargetResource -ServerName $env:COMPUTERNAME -InstanceName MSSQLSERVER -ServiceType DatabaseEngine -ServiceAccount $account
#>
function Test-TargetResource
Expand Down Expand Up @@ -172,7 +172,7 @@ function Test-TargetResource
Forces the service account to be updated.
.EXAMPLE
Set-TargetResource -ServerName $env:COMPUTERNAME -SQLInstaneName MSSQLSERVER -ServiceType DatabaseEngine -ServiceAccount $account
Set-TargetResource -ServerName $env:COMPUTERNAME -InstanceName MSSQLSERVER -ServiceType DatabaseEngine -ServiceAccount $account
#>
function Set-TargetResource
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ class MSFT_SqlServiceAccount : OMI_BaseResource
[Required, EmbeddedInstance("MSFT_Credential"), Description("The service account that should be used when running the service.")] String ServiceAccount;
[Write, Description("Determines whether the service is automatically restarted when a change to the configuration was needed.")] Boolean RestartService;
[Write, Description("Forces the service account to be updated. Useful for password changes.")] Boolean Force;
[Read, Description("Returns the service account username for the service.")] String ServiceAccountName;
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

ConvertFrom-StringData @'
ForceServiceAccountUpdate = Force specified, skipping tests. With this configuration, Test-TargetResource will always return 'False'.
CurrentServiceAccount = Current service account is '{0}' for {1}\{2}.
CurrentServiceAccount = Current service account is '{0}' for {1}\\{2}.
ConnectingToWmi = Connecting to WMI on '{0}'.
UpdatingServiceAccount = Setting service account to '{0}' for service {1}.
RestartingService = Restarting '{0}' and any dependent services.
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,11 @@ Manage the service account for SQL Server services.
Useful for password changes. This will cause `Set-TargetResource` to be run on
each consecutive run.

#### Read-Only Properties from Get-TargetResource

* **`[String]` ServiceAccountName** _(Read)_: Returns the service account username
for the service.

#### Examples

* [Run service under a user account](/Examples/Resources/SqlServiceAccount/1-ConfigureServiceAccount-UserAccount.ps1)
Expand Down
16 changes: 8 additions & 8 deletions Tests/Unit/MSFT_SqlServiceAccount.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ try
$testServiceInformation.ServerName | Should -Be $mockSqlServer
$testServiceInformation.InstanceName | Should -Be $mockNamedInstance
$testServiceInformation.ServiceType | Should -Be 'SqlServer'
$testServiceInformation.ServiceAccount | Should -Be $mockDesiredServiceAccountName
$testServiceInformation.ServiceAccountName | Should -Be $mockDesiredServiceAccountName

# Ensure mocks were properly used
Assert-MockCalled -CommandName Import-SQLPSModule -Scope It -Exactly -Times 1
Expand Down Expand Up @@ -705,7 +705,7 @@ try
$currentState = Get-TargetResource @defaultGetTargetResourceParameters

# Validate the service account
$currentState.ServiceAccount | Should -Be $mockLocalServiceAccountName
$currentState.ServiceAccountName | Should -Be $mockLocalServiceAccountName

# Ensure mocks were properly used
Assert-MockCalled -CommandName New-Object -ParameterFilter $mockNewObject_ParameterFilter -Scope It -Exactly -Times 1
Expand Down Expand Up @@ -900,10 +900,10 @@ try
}

It 'Should throw the correct exception if SetServiceAccount call fails' {
$newObjectParms = $mockNewObjectParameters_DefaultInstance.Clone()
$newObjectParms.MockWith = $mockNewObject_ManagedComputer_DefaultInstance_SetServiceAccountException
$newObjectParameters = $mockNewObjectParameters_DefaultInstance.Clone()
$newObjectParameters.MockWith = $mockNewObject_ManagedComputer_DefaultInstance_SetServiceAccountException

Mock @newObjectParms
Mock @newObjectParameters

$setTargetResourceParameters = $defaultSetTargetResourceParameters.Clone()

Expand Down Expand Up @@ -984,10 +984,10 @@ try
}

It 'Should throw the correct exception if SetServiceAccount call fails' {
$newObjectParms = $mockNewObjectParameters_NamedInstance.Clone()
$newObjectParms.MockWith = $mockNewObject_ManagedComputer_NamedInstance_SetServiceAccountException
$newObjectParameters = $mockNewObjectParameters_NamedInstance.Clone()
$newObjectParameters.MockWith = $mockNewObject_ManagedComputer_NamedInstance_SetServiceAccountException

Mock @newObjectParms
Mock @newObjectParameters

$setTargetResourceParameters = $defaultSetTargetResourceParameters.Clone()

Expand Down

0 comments on commit ccb88ef

Please sign in to comment.