Merge "Fixed MSSQL template to support 2008, 2014, 2016 versions"

This commit is contained in:
Jenkins 2017-05-25 08:04:08 +00:00 committed by Gerrit Code Review
commit 5d85fb437d
3 changed files with 93 additions and 8 deletions

View File

@ -22,8 +22,6 @@ $fullPath = Join-Path $currentLocation $modulePath
Import-Module -Name $fullPath -DisableNameChecking -Force Import-Module -Name $fullPath -DisableNameChecking -Force
$heatTemplateName = "MSSQL" $heatTemplateName = "MSSQL"
$sqlLogFile = Join-Path ${ENV:ProgramFiles} -ChildPath `
"\Microsoft SQL Server\110\Setup Bootstrap\Log\Summary.txt"
function Log { function Log {
param( param(
@ -81,8 +79,13 @@ function Get-MSSQLParameters {
$parameters += "/IACCEPTSQLSERVERLICENSETERMS=1 " $parameters += "/IACCEPTSQLSERVERLICENSETERMS=1 "
$parameters += "/INSTANCENAME=$MssqlInstanceName " $parameters += "/INSTANCENAME=$MssqlInstanceName "
$parameters += "/FEATURES=$MssqlFeatures " $parameters += "/FEATURES=$MssqlFeatures "
if (($MSSQLVersion -gt 12) -and($MssqlFeatures -split "," -contains "ADV_SSMS")) {
Log "MSSQL 2016 is not compatible with ADV_SSMS feature"
}
$parameters += "/SQLSYSADMINACCOUNTS=Admin " $parameters += "/SQLSYSADMINACCOUNTS=Admin "
$parameters += "/UpdateEnabled=1 " if ($MSSQLVersion -gt 10) {
$parameters += "/UpdateEnabled=1 "
}
$parameters += "/AGTSVCSTARTUPTYPE=Automatic " $parameters += "/AGTSVCSTARTUPTYPE=Automatic "
$parameters += "/BROWSERSVCSTARTUPTYPE=Automatic " $parameters += "/BROWSERSVCSTARTUPTYPE=Automatic "
$parameters += "/SECURITYMODE=SQL " $parameters += "/SECURITYMODE=SQL "
@ -129,6 +132,43 @@ function Add-NetRules {
-Protocol TCP -LocalPort 100-65000 -Program $sqlServerBinaryPath -Protocol TCP -LocalPort 100-65000 -Program $sqlServerBinaryPath
} }
function Load-XML {
Param (
[Parameter(Mandatory =$true)]
[string]$XMLFile
)
$xml=New-Object System.Xml.XmlDataDocument
$xml.Load($XMLFile)
return $xml
}
function Get-MSSQlVersion {
Param (
[Parameter(Mandatory =$true)]
[string]$MediaInfoXMLPath
)
if( -not (Test-Path $MediaInfoXMLPath)) {
Log "MediaInfoXMLPath does not exist!"
}
$xml = Load-XML ($MediaInfoXMLPath)
try {
return $xml.MediaInfo.Properties.Property[1].Value.ToString().SubString(0,2)
} catch {
# Note: for MSSQL Server 2008, the value does not exist
return 10
}
}
function Get-MSSQLLogFile {
Param (
[Parameter(Mandatory =$true)]
[string]$MSSQLVersion
)
$sqlLogFile = Join-Path ${ENV:ProgramFiles} -ChildPath `
("\Microsoft SQL Server\{0}0\Setup Bootstrap\Log\Summary.txt" -f $MSSQLVersion)
return $sqlLogFile
}
function Install-MSSQLInternal { function Install-MSSQLInternal {
param( param(
$MssqlServiceUsername, $MssqlServiceUsername,
@ -150,8 +190,13 @@ function Install-MSSQLInternal {
$localIsoPath = Copy-FilesLocal $MssqlIsoUNCPath $localIsoPath = Copy-FilesLocal $MssqlIsoUNCPath
Log "MSSQL ISO Mount." Log "MSSQL ISO Mount."
$iso = Mount-DiskImage -PassThru $localIsoPath $iso = Mount-DiskImage -PassThru $localIsoPath
Get-PSDrive | Out-Null
$driveLetter = (Get-Volume -DiskImage $iso).DriveLetter
$MediaInfoXMLPath = $driveLetter + ":\MediaInfo.xml"
$MSSQLVersion = Get-MSSQLVersion $MediaInfoXMLPath
$isoSetupPath = $driveLetter + ":\setup.exe"
$sqlLogFile= Get-MSSQLLogFile $MSSQLVersion
$isoSetupPath = (Get-Volume -DiskImage $iso).DriveLetter + ":\setup.exe"
if (Test-Path $sqlLogFile) { if (Test-Path $sqlLogFile) {
Remove-Item $sqlLogFile -Force Remove-Item $sqlLogFile -Force
} }

View File

@ -50,8 +50,7 @@ parameters:
mssql_features: mssql_features:
type: string type: string
default: > default: SQLENGINE,ADV_SSMS
SQLENGINE,ADV_SSMS
description: > description: >
The mssql features to be installed The mssql features to be installed

View File

@ -53,10 +53,44 @@ InModuleScope $moduleName {
} }
} }
InModuleScope $moduleName {
Describe "Test Get MSSQLLogFile" {
Context "On Success" {
$MSSQLVersion = "13"
Mock Join-Path { return $true } -Verifiable
Get-MSSQLLogFile $MSSQLVersion
It "should verify caled all mocks" {
Assert-VerifiableMocks
}
}
}
}
InModuleScope $moduleName {
Describe "Test Get MSSQLVersion" {
Context "On Success" {
$MSSQLVersion = "13"
Mock Load-XML { return $MSSQLVersion } -Verifiable
Mock Log { return $true} -Verifiable
$version =Get-MSSQLVersion $MSSQLVersion
It "should verify caled all mocks" {
Assert-VerifiableMocks
}
}
}
}
InModuleScope $moduleName { InModuleScope $moduleName {
Describe "Test Get MSSQL Error" { Describe "Test Get MSSQL Error" {
$sqlLogFile = Join-Path ${ENV:ProgramFiles} -ChildPath `
"\Microsoft SQL Server\110\Setup Bootstrap\Log\Summary.txt"
Context "With errors" { Context "With errors" {
$fakeErrors = @("err1") $fakeErrors = @("err1")
Mock Select-String { return $fakeErrors } -Verifiable Mock Select-String { return $fakeErrors } -Verifiable
Mock Log { return $true } -Verifiable Mock Log { return $true } -Verifiable
@ -72,6 +106,7 @@ InModuleScope $moduleName {
} }
Context "No errors" { Context "No errors" {
$fakeErrors = @() $fakeErrors = @()
Mock Select-String { return $fakeErrors } -Verifiable Mock Select-String { return $fakeErrors } -Verifiable
$result = Get-MSSQLError $result = Get-MSSQLError
@ -137,6 +172,8 @@ InModuleScope $moduleName {
Mock Copy-FilesLocal { return $true } -Verifiable Mock Copy-FilesLocal { return $true } -Verifiable
Mock Mount-DiskImage { return $cimInstance } -Verifiable Mock Mount-DiskImage { return $cimInstance } -Verifiable
Mock Get-Volume { return $true } -Verifiable Mock Get-Volume { return $true } -Verifiable
Mock Get-MSSQLVersion { return $MediaInfoXMLPath } -Verifiable
Mock Get-MSSQLLogFile { return $MSSQLVersion } -Verifiable
Mock Test-Path { return $true } -Verifiable Mock Test-Path { return $true } -Verifiable
Mock Remove-Item { return $true } -Verifiable Mock Remove-Item { return $true } -Verifiable
Mock Get-MSSQLParameters { return $true } -Verifiable Mock Get-MSSQLParameters { return $true } -Verifiable
@ -198,6 +235,10 @@ InModuleScope $moduleName {
-MssqlWaitConditionToken $MssqlWaitConditionToken -MssqlWaitConditionToken $MssqlWaitConditionToken
It "should be successful" { It "should be successful" {
$result | Should Be $true
}
It "should verify caled all mocks" {
Assert-VerifiableMocks Assert-VerifiableMocks
} }
} }