Skip to content

Commit

Permalink
Merge branch 'main' into fix/re-enable-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
johlju authored Mar 4, 2023
2 parents f9b3175 + e65a410 commit 7315762
Show file tree
Hide file tree
Showing 34 changed files with 182 additions and 172 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Update `appveyor.yml` to use `dotnet tool install` to install _GitVersion_.
- Re-enable integration tests for SqlRSSetup and SqlRS when running against
SQL Server 2019 ([issue #1847](https://github.com/dsccommunity/SqlServerDsc/issues/1847)).
- The private function `Import-SQLPSModule` was replaced throughout with
the public command `Import-SqlDscPreferredModule` ([issue #1848](https://github.com/dsccommunity/SqlServerDsc/issues/1848)).

### Fixed

- `Assert-SetupActionProperties`
- Now throws an exception if the setup action is `Install` and the feature
analysis services is specified without the parameter `ASSysAdminAccounts`
([issue #1845](https://github.com/dsccommunity/SqlServerDsc/issues/1845)).
- Now throws an exception if the setup action is `Install` and the feature
database engine is specified without the parameter `SqlSysAdminAccounts`.
- `Invoke-SetupAction`
- The parameter `SqlSysAdminAccounts` is no longer mandatory to allow
installation where the database engine is not installed.
- `Install-SqlDscServer`
- The parameter `SqlSysAdminAccounts` is no longer mandatory to allow
installation where the database engine is not installed.

## [16.1.0] - 2023-02-28

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ function Set-TargetResource
$StatementTimeout = 600
)

Import-SQLPSModule
Import-SqlDscPreferredModule

# Connect to the defined instance
$serverObject = Connect-SQL -ServerName $ServerName -InstanceName $InstanceName -StatementTimeout $StatementTimeout -ErrorAction 'Stop'
Expand Down
2 changes: 1 addition & 1 deletion source/DSCResources/DSC_SqlAGReplica/DSC_SqlAGReplica.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ function Set-TargetResource
$ProcessOnlyOnActiveNode
)

Import-SQLPSModule
Import-SqlDscPreferredModule

# Connect to the instance
$serverObject = Connect-SQL -ServerName $ServerName -InstanceName $InstanceName -ErrorAction 'Stop'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ function Set-TargetResource
$serverInstance = "$ServerName\$InstanceName"
}

Import-SQLPSModule
Import-SqlDscPreferredModule

switch ($Ensure)
{
Expand Down
6 changes: 3 additions & 3 deletions source/DSCResources/DSC_SqlProtocol/DSC_SqlProtocol.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function Get-TargetResource
$script:localizedData.GetCurrentState -f $protocolNameProperties.DisplayName, $InstanceName, $computerName
)

Import-SQLPSModule
Import-SqlDscPreferredModule

<#
Must connect to the local machine name because $ServerName can point
Expand Down Expand Up @@ -186,7 +186,7 @@ function Get-TargetResource
#>
function Set-TargetResource
{
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='The command Import-SQLPSModule is implicitly called when calling Compare-TargetResourceState')]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='The command Import-SqlDscPreferredModule is implicitly called when calling Compare-TargetResourceState')]
[CmdletBinding()]
param
(
Expand Down Expand Up @@ -415,7 +415,7 @@ function Set-TargetResource
#>
function Test-TargetResource
{
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='The command Import-SQLPSModule is implicitly called when calling Compare-TargetResourceState')]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='The command Import-SqlDscPreferredModule is implicitly called when calling Compare-TargetResourceState')]
[CmdletBinding()]
[OutputType([System.Boolean])]
param
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function Get-TargetResource
$script:localizedData.GetCurrentState -f $IpAddressGroup, $InstanceName, $computerName
)

Import-SQLPSModule
Import-SqlDscPreferredModule

<#
Must connect to the local machine name because $ServerName can point
Expand Down Expand Up @@ -229,7 +229,7 @@ function Get-TargetResource
#>
function Set-TargetResource
{
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='The command Import-SQLPSModule is implicitly called when calling Compare-TargetResourceState')]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='The command Import-SqlDscPreferredModule is implicitly called when calling Compare-TargetResourceState')]
[CmdletBinding()]
param
(
Expand Down Expand Up @@ -493,7 +493,7 @@ function Set-TargetResource
#>
function Test-TargetResource
{
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='The command Import-SQLPSModule is implicitly called when calling Compare-TargetResourceState')]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='The command Import-SqlDscPreferredModule is implicitly called when calling Compare-TargetResourceState')]
[CmdletBinding()]
[OutputType([System.Boolean])]
param
Expand Down
4 changes: 2 additions & 2 deletions source/DSCResources/DSC_SqlRS/DSC_SqlRS.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -467,11 +467,11 @@ function Set-TargetResource
$reportingServicesDatabaseRightsScript = Invoke-RsCimMethod @invokeRsCimMethodParameters

<#
Import-SQLPSModule cmdlet will import SQLPS (SQL 2012/14) or SqlServer module (SQL 2016),
Import-SqlDscPreferredModule cmdlet will import SQLPS (SQL 2012/14) or SqlServer module (SQL 2016),
and if importing SQLPS, change directory back to the original one, since SQLPS changes the
current directory to SQLSERVER:\ on import.
#>
Import-SQLPSModule
Import-SqlDscPreferredModule

$invokeSqlCmdParameters = @{
ServerInstance = $reportingServicesConnection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function Get-TargetResource
$script:localizedData.GetCurrentState -f $InstanceName
)

Import-SQLPSModule
Import-SqlDscPreferredModule

$sqlMajorVersion = Get-SqlInstanceMajorVersion -InstanceName $InstanceName
$localSqlName = Get-SqlLocalServerName -InstanceName $InstanceName
Expand Down Expand Up @@ -227,7 +227,7 @@ function Set-TargetResource
$UninstallWithForce = $true
)

Import-SQLPSModule
Import-SqlDscPreferredModule

if (($DistributorMode -eq 'Remote') -and (-not $RemoteDistributor))
{
Expand Down
6 changes: 3 additions & 3 deletions source/DSCResources/DSC_SqlScript/DSC_SqlScript.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ $script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US'
#>
function Get-TargetResource
{
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='The command Import-SQLPSModule is implicitly called in Invoke-SqlScript')]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='The command Import-SqlDscPreferredModule is implicitly called in Invoke-SqlScript')]
[CmdletBinding()]
[OutputType([System.Collections.Hashtable])]
param
Expand Down Expand Up @@ -211,7 +211,7 @@ function Get-TargetResource
#>
function Set-TargetResource
{
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='The command Import-SQLPSModule is implicitly called in Invoke-SqlScript')]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='The command Import-SqlDscPreferredModule is implicitly called in Invoke-SqlScript')]
[CmdletBinding()]
param
(
Expand Down Expand Up @@ -341,7 +341,7 @@ function Set-TargetResource
#>
function Test-TargetResource
{
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='The command Import-SQLPSModule is implicitly called in Invoke-SqlScript')]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='The command Import-SqlDscPreferredModule is implicitly called in Invoke-SqlScript')]
[CmdletBinding()]
[OutputType([System.Boolean])]
param
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ $script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US'
#>
function Get-TargetResource
{
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='The command Import-SQLPSModule is implicitly called in Invoke-SqlScript')]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='The command Import-SqlDscPreferredModule is implicitly called in Invoke-SqlScript')]
[CmdletBinding()]
[OutputType([System.Collections.Hashtable])]
param
Expand Down Expand Up @@ -211,7 +211,7 @@ function Get-TargetResource
#>
function Set-TargetResource
{
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='The command Import-SQLPSModule is implicitly called in Invoke-SqlScript')]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='The command Import-SqlDscPreferredModule is implicitly called in Invoke-SqlScript')]
[CmdletBinding()]
param
(
Expand Down Expand Up @@ -341,7 +341,7 @@ function Set-TargetResource
#>
function Test-TargetResource
{
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='The command Import-SQLPSModule is implicitly called in Invoke-SqlScript')]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='The command Import-SqlDscPreferredModule is implicitly called in Invoke-SqlScript')]
[CmdletBinding()]
[OutputType([System.Boolean])]
param
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ $script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US'
#>
function Get-TargetResource
{
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='The command Import-SQLPSModule is called when Get-ServiceObject is called')]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='The command Import-SqlDscPreferredModule is called when Get-ServiceObject is called')]
[CmdletBinding()]
[OutputType([System.Collections.Hashtable])]
param
Expand Down Expand Up @@ -127,7 +127,7 @@ function Get-TargetResource
#>
function Test-TargetResource
{
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='The command Import-SQLPSModule is implicitly called when calling Get-TargetResource')]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='The command Import-SqlDscPreferredModule is implicitly called when calling Get-TargetResource')]
[CmdletBinding()]
[OutputType([System.Boolean])]
param
Expand Down Expand Up @@ -209,7 +209,7 @@ function Test-TargetResource
#>
function Set-TargetResource
{
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='The command Import-SQLPSModule is called when Get-ServiceObject is called')]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='The command Import-SqlDscPreferredModule is called when Get-ServiceObject is called')]
[CmdletBinding()]
param
(
Expand Down Expand Up @@ -326,7 +326,7 @@ function Get-ServiceObject
}

# Load the SMO libraries
Import-SQLPSModule
Import-SqlDscPreferredModule

$verboseMessage = $script:localizedData.ConnectingToWmi -f $ServerName
Write-Verbose -Message $verboseMessage
Expand Down
2 changes: 1 addition & 1 deletion source/DSCResources/DSC_SqlSetup/DSC_SqlSetup.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -1615,7 +1615,7 @@ function Set-TargetResource
matches the latest assemblies in GAC, mitigating for example
issue #1151.
#>
Import-SQLPSModule -Force
Import-SqlDscPreferredModule -Force
}

if (-not (Test-TargetResource @PSBoundParameters))
Expand Down
6 changes: 3 additions & 3 deletions source/DSCResources/DSC_SqlTraceFlag/DSC_SqlTraceFlag.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function Get-TargetResource
)

# Import SqlServer module.
Import-SQLPSModule
Import-SqlDscPreferredModule

Write-Verbose -Message (
$script:localizedData.GetConfiguration -f $InstanceName
Expand Down Expand Up @@ -188,7 +188,7 @@ function Set-TargetResource
)

# Import SqlServer module.
Import-SQLPSModule
Import-SqlDscPreferredModule

Write-Verbose -Message (
$script:localizedData.SetConfiguration -f $InstanceName
Expand Down Expand Up @@ -363,7 +363,7 @@ function Set-TargetResource
#>
function Test-TargetResource
{
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='The command Import-SQLPSModule is called when Get-TargetResource is called')]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='The command Import-SqlDscPreferredModule is called when Get-TargetResource is called')]
[CmdletBinding()]
[OutputType([System.Boolean])]
param
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
'Connect-SQL'
'Connect-SQLAnalysis'
'Get-SqlInstanceMajorVersion'
'Import-SQLPSModule'
'Restart-SqlService'
'Restart-ReportingServicesService'
'Invoke-Query'
Expand Down
29 changes: 3 additions & 26 deletions source/Modules/SqlServerDsc.Common/SqlServerDsc.Common.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ function Connect-SQL
$StatementTimeout = 600
)

Import-SQLPSModule
Import-SqlDscPreferredModule

if ($InstanceName -eq 'MSSQLSERVER')
{
Expand Down Expand Up @@ -697,7 +697,7 @@ function Connect-SQLAnalysis
{
if ((Test-FeatureFlag -FeatureFlag $FeatureFlag -TestFlag 'AnalysisServicesConnection'))
{
Import-SQLPSModule
Import-SqlDscPreferredModule

$analysisServicesObject = New-Object -TypeName 'Microsoft.AnalysisServices.Server'

Expand Down Expand Up @@ -860,29 +860,6 @@ function Get-SqlInstanceMajorVersion
return $sqlMajorVersionNumber
}

<#
.SYNOPSIS
Imports the module SQLPS in a standardized way.
.PARAMETER Force
Forces the removal of the previous SQL module, to load the same or newer
version fresh. This is meant to make sure the newest version is used, with
the latest assemblies.
#>
function Import-SQLPSModule
{
[CmdletBinding()]
param
(
[Parameter()]
[System.Management.Automation.SwitchParameter]
$Force
)

Import-SqlDscPreferredModule @PSBoundParameters
}

<#
.SYNOPSIS
Restarts a SQL Server instance and associated services
Expand Down Expand Up @@ -2106,7 +2083,7 @@ function Invoke-SqlScript
$Encrypt
)

Import-SQLPSModule
Import-SqlDscPreferredModule

if ($PSCmdlet.ParameterSetName -eq 'File')
{
Expand Down
17 changes: 17 additions & 0 deletions source/Private/Assert-SetupActionProperties.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,21 @@ function Assert-SetupActionProperties
)
}
}

if ($SetupAction -in ('Install'))
{
if ($Property.ContainsKey('Features') -and $Property.Features -contains 'SQLENGINE')
{
Assert-BoundParameter -BoundParameterList $Property -RequiredParameter @(
'SqlSysAdminAccounts'
)
}

if ($Property.ContainsKey('Features') -and $Property.Features -contains 'AS')
{
Assert-BoundParameter -BoundParameterList $Property -RequiredParameter @(
'ASSysAdminAccounts'
)
}
}
}
2 changes: 1 addition & 1 deletion source/Private/Invoke-SetupAction.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,7 @@ function Invoke-SetupAction
[System.String]
$SqlSvcStartupType,

[Parameter(ParameterSetName = 'Install', Mandatory = $true)]
[Parameter(ParameterSetName = 'Install')]
[Parameter(ParameterSetName = 'CompleteImage')]
[Parameter(ParameterSetName = 'RebuildDatabase', Mandatory = $true)]
[Parameter(ParameterSetName = 'InstallFailoverCluster', Mandatory = $true)]
Expand Down
2 changes: 1 addition & 1 deletion source/Public/Install-SqlDscServer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ function Install-SqlDscServer
[System.String]
$SqlSvcStartupType,

[Parameter(ParameterSetName = 'Install', Mandatory = $true)]
[Parameter(ParameterSetName = 'Install')]
[Parameter(ParameterSetName = 'InstallFailoverCluster', Mandatory = $true)]
[Parameter(ParameterSetName = 'InstallRole')]
[System.String[]]
Expand Down
Loading

0 comments on commit 7315762

Please sign in to comment.