Skip to content

Commit 701a5d2

Browse files
committed
(CONT-490) - Add support for SQL Server 2022
This commit adds support for SQL Server 2022 to the puppetlabs-sqlserver module.
1 parent 460d0af commit 701a5d2

File tree

12 files changed

+117
-55
lines changed

12 files changed

+117
-55
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
## Overview
2222

23-
The sqlserver module installs and manages Microsoft SQL Server 2012, 2014, 2016, 2017, 2019 on Windows systems.
23+
The sqlserver module installs and manages Microsoft SQL Server 2012, 2014, 2016, 2017, 2019 and 2022 on Windows systems.
2424

2525
## Module Description
2626

@@ -272,9 +272,9 @@ For information on the classes and types, see the [REFERENCE.md](https://github.
272272

273273
## Limitations
274274

275-
SQL 2017 and 2019 detection support has been added. This support is limited to functionality already present for other versions. No new SQL 2017 or above specific functionality has been added in this release.
275+
SQL 2017, 2019 and 2022 detection support has been added. This support is limited to functionality already present for other versions.
276276

277-
This module can manage only a single version of SQL Server on a given host (one and only one of SQL Server 2012, 2014, 2016, 2017, or 2019). The module is able to manage multiple SQL Server instances of the same version.
277+
This module can manage only a single version of SQL Server on a given host (one and only one of SQL Server 2012, 2014, 2016, 2017, 2019 or 2022). The module is able to manage multiple SQL Server instances of the same version.
278278

279279
This module cannot manage the SQL Server Native Client SDK (also known as SNAC_SDK). The SQL Server installation media can install the SDK, but it is not able to uninstall the SDK. Note that the 'sqlserver_features' fact detects the presence of the SDK.
280280

lib/puppet/provider/sqlserver.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ class Puppet::Provider::Sqlserver < Puppet::Provider # rubocop:disable Style/Doc
1919
end
2020

2121
def try_execute(command, msg = nil, obfuscate_strings = nil, acceptable_exit_codes = [0])
22-
res = execute(command.compact, failonfail: false)
22+
command&.compact
23+
res = execute(command, failonfail: false)
2324

2425
unless acceptable_exit_codes.include?(res.exitstatus)
2526
msg = "Failure occured when trying to install SQL Server #{@resource[:name]}" if msg.nil?

lib/puppet/provider/sqlserver_features/mssql.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def create
127127
instance_version = PuppetX::Sqlserver::ServerHelper.sql_version_from_install_source(@resource[:source])
128128
Puppet.debug("Installation source detected as version #{instance_version}") unless instance_version.nil?
129129

130-
install_net_35(@resource[:windows_feature_source]) unless [SQL_2016, SQL_2017, SQL_2019].include? instance_version
130+
install_net_35(@resource[:windows_feature_source]) unless [SQL_2016, SQL_2017, SQL_2019, SQL_2022].include? instance_version
131131

132132
debug "Installing features #{@resource[:features]}"
133133
add_features(@resource[:features])

lib/puppet/provider/sqlserver_instance/mssql.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def create
105105
instance_version = PuppetX::Sqlserver::ServerHelper.sql_version_from_install_source(@resource[:source])
106106
Puppet.debug("Installation source detected as version #{instance_version}") unless instance_version.nil?
107107

108-
install_net_35(@resource[:windows_feature_source]) unless [SQL_2016, SQL_2017, SQL_2019].include? instance_version
108+
install_net_35(@resource[:windows_feature_source]) unless [SQL_2016, SQL_2017, SQL_2019, SQL_2022].include? instance_version
109109

110110
add_features(@resource[:features])
111111
end

lib/puppet_x/sqlserver/features.rb

+9-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
SQL_2016 ||= 'SQL_2016'
88
SQL_2017 ||= 'SQL_2017'
99
SQL_2019 ||= 'SQL_2019'
10+
SQL_2022 ||= 'SQL_2022'
1011

11-
ALL_SQL_VERSIONS ||= [SQL_2012, SQL_2014, SQL_2016, SQL_2017, SQL_2019].freeze
12+
ALL_SQL_VERSIONS ||= [SQL_2012, SQL_2014, SQL_2016, SQL_2017, SQL_2019, SQL_2022].freeze
1213

1314
# rubocop:disable Style/ClassAndModuleChildren
1415
module PuppetX
@@ -39,6 +40,10 @@ class Features # rubocop:disable Style/Documentation
3940
major_version: 15,
4041
registry_path: '150',
4142
},
43+
SQL_2022 => {
44+
major_version: 16,
45+
registry_path: '160',
46+
},
4247
}.freeze
4348

4449
SQL_REG_ROOT ||= 'Software\Microsoft\Microsoft SQL Server'
@@ -145,6 +150,8 @@ def self.get_instance_features(reg_root, instance_name)
145150

146151
def self.get_shared_features(version)
147152
shared_features = {
153+
# Client tools support removed with SQLServer 2022
154+
# (ref https://learn.microsoft.com/en-us/sql/database-engine/install-windows/install-sql-server-on-server-core?view=sql-server-ver16#BK_SupportedFeatures)
148155
'Connectivity_Full' => 'Conn', # Client Tools Connectivity
149156
'SDK_Full' => 'SDK', # Client Tools SDK
150157
'MDSCoreFeature' => 'MDS', # Master Data Services
@@ -156,7 +163,7 @@ def self.get_shared_features(version)
156163
'SQL_DReplay_Controller' => 'DREPLAY_CTLR', # Distributed Replay Controller
157164
'SQL_DReplay_Client' => 'DREPLAY_CLT', # Distributed Replay Client
158165
'sql_shared_mr' => 'SQL_SHARED_MR', # R Server (Standalone)
159-
166+
# SQL Client Connectivity SDK (Installed by default)
160167
# also WMI: SqlService WHERE SQLServiceType = 4 # MsDtsServer
161168
'SQL_DTS_Full' => 'IS', # Integration Services
162169
# currently ignoring Reporting Services Shared

lib/puppet_x/sqlserver/server_helper.rb

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def self.sql_version_from_install_source(source_dir)
4444
ver = content.match('"(.+)"')
4545
return nil if ver.nil?
4646

47+
return SQL_2022 if ver[1].start_with?('16.')
4748
return SQL_2019 if ver[1].start_with?('15.')
4849
return SQL_2017 if ver[1].start_with?('14.')
4950
return SQL_2016 if ver[1].start_with?('13.')

lib/puppet_x/sqlserver/sql_connection.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def open(config)
3131

3232
def get_connection_string(config)
3333
params = {
34-
'Provider' => 'SQLNCLI11',
34+
'Provider' => 'MSOLEDBSQL',
3535
'Initial Catalog' => config[:database] || 'master',
3636
'Application Name' => 'Puppet',
3737
'Data Source' => '.',
@@ -50,8 +50,8 @@ def get_connection_string(config)
5050
# SQL Server based authentication
5151
raise ArgumentError, _('admin_user must not be empty or nil') unless admin_user != ''
5252
raise ArgumentError, _('admin_pass must not be empty or nil') unless admin_pass != ''
53-
params.store('User ID', admin_user)
54-
params.store('Password', admin_pass)
53+
params.store('UID', admin_user)
54+
params.store('PWD', admin_pass)
5555
end
5656

5757
if !config[:instance_name].nil? && config[:instance_name] !~ %r{^MSSQLSERVER$}

metadata.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "puppetlabs-sqlserver",
33
"version": "3.2.1",
44
"author": "puppetlabs",
5-
"summary": "The `sqlserver` module installs and manages MS SQL Server 2012, 2014, 2016, 2017, and 2019 on Windows systems.",
5+
"summary": "The `sqlserver` module installs and manages MS SQL Server 2012, 2014, 2016, 2017, 2019 and 2022 on Windows systems.",
66
"license": "proprietary",
77
"source": "https://github.com/puppetlabs/puppetlabs-sqlserver",
88
"project_page": "https://github.com/puppetlabs/puppetlabs-sqlserver",
@@ -44,7 +44,8 @@
4444
"sql2014",
4545
"sql2016",
4646
"sql2017",
47-
"sql2019",
47+
"sql2019",
48+
"sql2022",
4849
"tsql",
4950
"database"
5051
],

spec/acceptance/z_last_sqlserver_features_spec.rb

+37-18
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
def ensure_sql_features(features, ensure_val = 'present')
1111
pp = <<-MANIFEST
1212
sqlserver::config{ 'MSSQLSERVER':
13-
admin_pass => '<%= SQL_ADMIN_PASS %>',
14-
admin_user => '<%= SQL_ADMIN_USER %>',
13+
admin_pass => '<%= SQL_ADMIN_PASS %>',
14+
admin_user => '<%= SQL_ADMIN_USER %>',
1515
}
1616
sqlserver_features{ 'MSSQLSERVER':
1717
ensure => #{ensure_val},
@@ -29,8 +29,8 @@ def ensure_sql_features(features, ensure_val = 'present')
2929
def bind_and_apply_failing_manifest(features, ensure_val = 'present')
3030
pp = <<-MANIFEST
3131
sqlserver::config{ 'MSSQLSERVER':
32-
admin_pass => '<%= SQL_ADMIN_PASS %>',
33-
admin_user => '<%= SQL_ADMIN_USER %>',
32+
admin_pass => '<%= SQL_ADMIN_PASS %>',
33+
admin_user => '<%= SQL_ADMIN_USER %>',
3434
}
3535
sqlserver_features{ 'MSSQLSERVER':
3636
ensure => #{ensure_val},
@@ -44,7 +44,10 @@ def bind_and_apply_failing_manifest(features, ensure_val = 'present')
4444
end
4545

4646
context 'can install' do
47-
features = if version.to_i >= 2016
47+
# Client Tools removed in Server2022 (Backwards Compatibility, Connectivity, SDK)
48+
features = if version.to_i == 2022
49+
['IS', 'MDS', 'DQC']
50+
elsif version.to_i >= 2016 && version.to_i < 2022
4851
['BC', 'Conn', 'SDK', 'IS', 'MDS', 'DQC']
4952
else
5053
['BC', 'Conn', 'SSMS', 'ADV_SSMS', 'SDK', 'IS', 'MDS', 'DQC']
@@ -58,17 +61,22 @@ def bind_and_apply_failing_manifest(features, ensure_val = 'present')
5861
ensure_sql_features(features)
5962

6063
validate_sql_install(version: version) do |r|
61-
expect(r.stdout).to match(%r{Client Tools Connectivity})
62-
expect(r.stdout).to match(%r{Client Tools Backwards Compatibility})
63-
expect(r.stdout).to match(%r{Client Tools SDK})
64+
# Client Tools removed in Server2022
65+
unless version.to_i == 2022
66+
expect(r.stdout).to match(%r{Client Tools Connectivity})
67+
expect(r.stdout).to match(%r{Client Tools Backwards Compatibility})
68+
expect(r.stdout).to match(%r{Client Tools SDK})
69+
end
6470
expect(r.stdout).to match(%r{Integration Services})
6571
expect(r.stdout).to match(%r{Master Data Services})
6672
end
6773
end
6874
end
6975

7076
context 'can remove' do
71-
features = if version.to_i >= 2016
77+
features = if version.to_i == 2022
78+
['IS', 'MDS', 'DQC']
79+
elsif version.to_i >= 2016 && version.to_i < 2022
7280
['BC', 'Conn', 'SDK', 'IS', 'MDS', 'DQC']
7381
else
7482
['BC', 'Conn', 'SSMS', 'ADV_SSMS', 'SDK', 'IS', 'MDS', 'DQC']
@@ -78,17 +86,22 @@ def bind_and_apply_failing_manifest(features, ensure_val = 'present')
7886
ensure_sql_features(features, 'absent')
7987

8088
validate_sql_install(version: version) do |r|
81-
expect(r.stdout).not_to match(%r{Client Tools Connectivity})
82-
expect(r.stdout).not_to match(%r{Client Tools Backwards Compatibility})
83-
expect(r.stdout).not_to match(%r{Client Tools SDK})
89+
# Client Tools removed in Server2022
90+
unless version.to_i == 2022
91+
expect(r.stdout).not_to match(%r{Client Tools Connectivity})
92+
expect(r.stdout).not_to match(%r{Client Tools Backwards Compatibility})
93+
expect(r.stdout).not_to match(%r{Client Tools SDK})
94+
end
8495
expect(r.stdout).not_to match(%r{Integration Services})
8596
expect(r.stdout).not_to match(%r{Master Data Services})
8697
end
8798
end
8899
end
89100

90101
context 'can remove independent feature' do
91-
features = if version.to_i >= 2016
102+
features = if version.to_i == 2022
103+
['IS', 'MDS', 'DQC']
104+
elsif version.to_i >= 2016 && version.to_i < 2022
92105
['BC', 'Conn', 'SDK', 'IS', 'MDS', 'DQC']
93106
else
94107
['BC', 'Conn', 'SSMS', 'ADV_SSMS', 'SDK', 'IS', 'MDS', 'DQC']
@@ -102,7 +115,7 @@ def bind_and_apply_failing_manifest(features, ensure_val = 'present')
102115
ensure_sql_features(features, 'absent')
103116
end
104117

105-
it "'BC'" do
118+
it "'BC'", unless: version.to_i == 2022 do
106119
ensure_sql_features(features - ['BC'])
107120

108121
validate_sql_install(version: version) do |r|
@@ -121,7 +134,7 @@ def bind_and_apply_failing_manifest(features, ensure_val = 'present')
121134
end
122135
end
123136

124-
it "'SDK' + 'IS" do
137+
it "'SDK' + 'IS", unless: version.to_i == 2022 do
125138
ensure_sql_features(features - ['SDK', 'IS'])
126139

127140
validate_sql_install(version: version) do |r|
@@ -136,7 +149,7 @@ def bind_and_apply_failing_manifest(features, ensure_val = 'present')
136149
bind_and_apply_failing_manifest(features)
137150
end
138151

139-
it 'fails when ADV_SSMS is supplied but SSMS is not - FM-2712' do
152+
it 'fails when ADV_SSMS is supplied but SSMS is not - FM-2712', unless: version.to_i >= 2016 do
140153
pending('error not shown on Sql Server 2014') if version .to_i == 2014
141154
features = ['BC', 'Conn', 'ADV_SSMS', 'SDK']
142155
bind_and_apply_failing_manifest(features)
@@ -146,7 +159,13 @@ def bind_and_apply_failing_manifest(features, ensure_val = 'present')
146159
context 'with no installed instances' do
147160
# Currently this test can only be run on a machine once and will error if run a second time
148161
context 'can install' do
149-
features = ['BC', 'Conn', 'SDK', 'IS', 'MDS', 'DQC']
162+
features = if version.to_i == 2022
163+
['IS', 'MDS', 'DQC']
164+
elsif version.to_i >= 2016 && version.to_i < 2022
165+
['BC', 'Conn', 'SDK', 'IS', 'MDS', 'DQC']
166+
else
167+
['BC', 'Conn', 'SSMS', 'ADV_SSMS', 'SDK', 'IS', 'MDS', 'DQC']
168+
end
150169

151170
def remove_sql_instance
152171
pp = <<-MANIFEST
@@ -171,7 +190,7 @@ def remove_sql_instance
171190
ensure_sql_features(features)
172191

173192
validate_sql_install(version: version) do |r|
174-
# SQL Server 2016 will not install the client tools features.
193+
# SQL Server 2016+ will not install the client tools features.
175194
expect(r.stdout).not_to match(%r{MSSQLSERVER\s+Database Engine Services})
176195
expect(r.stdout).not_to match(%r{MSSQLSERVER\s+SQL Server Replication})
177196
expect(r.stdout).not_to match(%r{MSSQLSERVER\s+Data Quality Services})

spec/spec_helper_acceptance_local.rb

+31-12
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ class Helper
99
end
1010

1111
WIN_ISO_ROOT = 'https://artifactory.delivery.puppetlabs.net/artifactory/generic__iso/iso/windows'
12-
WIN_2012R2_ISO = 'en_windows_server_2012_r2_with_update_x64_dvd_6052708.iso'
12+
WIN_2019_ISO = 'en_windows_server_2019_updated_july_2020_x64_dvd_94453821.iso'
1313
QA_RESOURCE_ROOT = 'https://artifactory.delivery.puppetlabs.net/artifactory/generic__iso/iso/SQLServer'
14+
SQL_2022_ISO = 'SQLServer2022-x64-ENU-Dev.iso'
1415
SQL_2019_ISO = 'SQLServer2019CTP2.4-x64-ENU.iso'
1516
SQL_2017_ISO = 'SQLServer2017-x64-ENU.iso'
1617
SQL_2016_ISO = 'en_sql_server_2016_enterprise_with_service_pack_1_x64_dvd_9542382.iso'
@@ -26,7 +27,7 @@ class Helper
2627

2728
iso_opts = {
2829
folder: WIN_ISO_ROOT,
29-
file: WIN_2012R2_ISO,
30+
file: WIN_2019_ISO,
3031
drive_letter: 'I',
3132
}
3233
mount_iso(iso_opts)
@@ -49,14 +50,18 @@ def node_vars?
4950

5051
def sql_version?
5152
vars = node_vars?
52-
53-
if vars['sqlversion']
54-
return vars['sqlversion'].match(%r{sqlserver_(.*)})[1]
53+
unless vars.nil?
54+
if vars['sqlversion']
55+
return vars['sqlversion'].match(%r{sqlserver_(.*)})[1]
56+
end
5557
end
5658
# Return's a default version if none was given
57-
'2016'
59+
'2022'
5860
end
5961

62+
# this mounts the OS and SQL iso
63+
# OS iso mounts to I drive
64+
# SQL iso mounts to H drive
6065
def mount_iso(opts = {})
6166
folder = opts[:folder]
6267
file = opts[:file]
@@ -111,6 +116,12 @@ def base_install(sql_version)
111116
file: SQL_2019_ISO,
112117
drive_letter: 'H',
113118
}
119+
when 2022
120+
iso_opts = {
121+
folder: QA_RESOURCE_ROOT,
122+
file: SQL_2022_ISO,
123+
drive_letter: 'H'
124+
}
114125
end
115126
# Mount the ISO on the agent
116127
mount_iso(iso_opts)
@@ -207,13 +218,21 @@ def validate_sql_install(opts = {}, &block)
207218
end
208219

209220
def get_install_paths(version)
210-
vers = { '2012' => '110', '2014' => '120', '2016' => '130', '2017' => '140', '2019' => '150' }
221+
vers = { '2012' => '110', '2014' => '120', '2016' => '130', '2017' => '140', '2019' => '150', '2022' => '160' }
211222

212223
raise _('Valid version must be specified') unless vers.keys.include?(version)
213224

214-
dir = "%ProgramFiles%/Microsoft SQL Server/#{vers[version]}/Setup Bootstrap"
215-
sql_directory = 'SQL'
216-
sql_directory += 'Server' if version != '2017'
217-
218-
[dir, "#{dir}\\#{sql_directory}#{version}"]
225+
dir = "C://Program Files/Microsoft SQL Server/#{vers[version]}/Setup Bootstrap"
226+
sql_directory = case version
227+
when '2022'
228+
"SQL#{version}"
229+
when '2019'
230+
"SQL#{version}CTP2.4"
231+
when '2017'
232+
"SQL#{version}"
233+
else
234+
"SQLServer#{version}"
235+
end
236+
237+
[dir, "#{dir}\\#{sql_directory}"]
219238
end

0 commit comments

Comments
 (0)