Skip to content

Commit 9872616

Browse files
committed
(MODULES-4257) Modify instance and features for SQL Server 2016
Previously the sqlserver_instance and sqlserver_feature acceptance tests were failing. This was mainly due to SQL Server 2016 not having a feature for the SQL Management Studio (ADV_SSMS and SSMS). However it was later found that the super features called Tools and SQL were not providing an adequate abstraction e.g. they were not rolled up in the Facter facts. This commit adds support for SQL Server 2016 by the following: - Deprecating the use of 'Tools' in the sqlserver_features and 'SQL' in the sqlserver_instance custom types. These super features will continue to function however use of them will generate a deprecation warning - The acceptance tests for the super features was removed - Most tests which referred to ADV_SSMS and SSMS were removed. Where not possible, they were guarded to not be tested on SQL Server 2016. - An installation media version detection method was added as Dot Net 3.5 is not required for SQL Server 2016 installation. This is only applicable for SQL Server 2012 and 2014. - Refactored the instances method for sqlserver_features to support multiple server editions on a server but until MODULES-5060 is resolved, only the first set is returned.
1 parent 1e33983 commit 9872616

File tree

10 files changed

+140
-131
lines changed

10 files changed

+140
-131
lines changed

lib/puppet/provider/sqlserver_features/mssql.rb

+22-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
require 'json'
22
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'sqlserver'))
3+
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'puppet_x/sqlserver/server_helper'))
4+
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'puppet_x/sqlserver/features'))
35

46
FEATURE_RESERVED_SWITCHES =
57
%w(AGTSVCACCOUNT AGTSVCPASSWORD ASSVCACCOUNT AGTSVCPASSWORD PID
@@ -10,18 +12,25 @@ def self.instances
1012
instances = []
1113
result = Facter.value(:sqlserver_features)
1214
debug "Parsing result #{result}"
13-
result = !result[SQL_2014].empty? ? result[SQL_2014] : result[SQL_2012]
14-
if !result.empty?
15-
existing_instance = {:name => "Generic Features",
16-
:ensure => :present,
17-
:features => result.sort
15+
16+
ALL_SQL_VERSIONS.each do |sql_version|
17+
next if result[sql_version].empty?
18+
instance_props = {:name => "Generic Features",
19+
:ensure => :present,
20+
:features => result[sql_version].sort
1821
}
19-
debug "Parsed features = #{existing_instance[:features]}"
22+
debug "Parsed features = #{instance_props[:features]}"
2023

21-
instance = new(existing_instance)
24+
instance = new(instance_props)
2225
debug "Created instance #{instance}"
2326
instances << instance
27+
28+
# Due to MODULES-5060 we can only output one feature set. If we output
29+
# multiple then it is not possible to install or uninstall due to multiple
30+
# resources with the same name.
31+
break
2432
end
33+
2534
instances
2635
end
2736

@@ -82,8 +91,7 @@ def create_temp_for_install_switch
8291
config_file = ["[OPTIONS]"]
8392
@resource[:install_switches].each_pair do |k, v|
8493
if FEATURE_RESERVED_SWITCHES.include? k
85-
warn("Reserved switch [#{k}] found for `install_switches`, please know the provided value
86-
may be overridden by some command line arguments")
94+
warn("Reserved switch [#{k}] found for `install_switches`, please know the provided value may be overridden by some command line arguments")
8795
end
8896
if v.is_a?(Numeric) || (v.is_a?(String) && v =~ /^(true|false|1|0)$/i)
8997
config_file << "#{k}=#{v}"
@@ -111,7 +119,11 @@ def create
111119
warn "Uninstalling all sql server features not tied into an instance because an empty array was passed, please use ensure absent instead."
112120
destroy
113121
else
114-
installNet35(@resource[:windows_feature_source])
122+
instance_version = PuppetX::Sqlserver::ServerHelper.sql_version_from_install_source(@resource[:source])
123+
Puppet.debug("Installation source detected as version #{instance_version}") unless instance_version.nil?
124+
125+
installNet35(@resource[:windows_feature_source]) unless instance_version == SQL_2016
126+
115127
debug "Installing features #{@resource[:features]}"
116128
add_features(@resource[:features])
117129
@property_hash[:features] = @resource[:features]

lib/puppet/provider/sqlserver_instance/mssql.rb

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require 'json'
22
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'sqlserver'))
3-
3+
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'puppet_x/sqlserver/server_helper'))
4+
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'puppet_x/sqlserver/features'))
45

56
INSTANCE_RESERVED_SWITCHES =
67
%w(AGTSVCACCOUNT AGTSVCPASSWORD ASSVCACCOUNT AGTSVCPASSWORD PID
@@ -70,7 +71,11 @@ def create
7071
warn "Uninstalling all features for instance #{@resource[:name]} because an empty array was passed, please use ensure absent instead."
7172
destroy
7273
else
73-
installNet35(@resource[:windows_feature_source])
74+
instance_version = PuppetX::Sqlserver::ServerHelper.sql_version_from_install_source(@resource[:source])
75+
Puppet.debug("Installation source detected as version #{instance_version}") unless instance_version.nil?
76+
77+
installNet35(@resource[:windows_feature_source]) unless instance_version == SQL_2016
78+
7479
add_features(@resource[:features])
7580
end
7681
end
@@ -80,8 +85,7 @@ def create_temp_for_install_switch
8085
config_file = ["[OPTIONS]"]
8186
@resource[:install_switches].each_pair do |k, v|
8287
if INSTANCE_RESERVED_SWITCHES.include? k
83-
warn("Reserved switch [#{k}] found for `install_switches`, please know the provided value
84-
may be overridden by some command line arguments")
88+
warn("Reserved switch [#{k}] found for `install_switches`, please know the provided value may be overridden by some command line arguments")
8589
end
8690
if v.is_a?(Numeric) || (v.is_a?(String) && v =~ /^(true|false|1|0)$/i)
8791
config_file << "#{k}=#{v}"

lib/puppet/type/sqlserver_features.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@
3636

3737
newproperty(:features, :array_matching => :all) do
3838
desc 'Specifies features to install, uninstall, or upgrade. The list of top-level features include
39-
Tools, BC, Conn, SSMS, ADV_SSMS, SDK, IS and MDS. The Tools feature will install Management
40-
Tools, Books online components, SQL Server Data Tools, and other shared components.'
41-
newvalues(:Tools, :BC, :Conn, :SSMS, :ADV_SSMS, :SDK, :IS, :MDS)
39+
BC, Conn, SSMS, ADV_SSMS, SDK, IS and MDS.'
40+
newvalues(:Tools, :BC, :Conn, :SSMS, :ADV_SSMS, :SDK, :IS, :MDS, :BOL, :DREPLAY_CTLR, :DREPLAY_CLT)
4241
munge do |value|
4342
if PuppetX::Sqlserver::ServerHelper.is_super_feature(value)
43+
Puppet.deprecation_warning("Using #{value} is deprecated for features in sql_features resources")
4444
PuppetX::Sqlserver::ServerHelper.get_sub_features(value).collect { |v| v.to_s }
4545
else
4646
value

lib/puppet/type/sqlserver_instance.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@
2727

2828
newproperty(:features, :array_matching => :all) do
2929
desc 'Specifies features to install, uninstall, or upgrade. The list of top-level features include
30-
SQL, SQLEngine, Replication, FullText, DQ AS, and RS. The SQL feature will install the Database Engine,
31-
Replication, Full-Text, and Data Quality Services (DQS) server.'
32-
newvalues(:SQL, :SQLEngine, :Replication, :FullText, :DQ, :AS, :RS)
30+
SQLEngine, Replication, FullText, DQ AS, and RS.'
31+
newvalues(:SQL, :SQLEngine, :Replication, :FullText, :DQ, :AS, :RS, :POLYBASE, :ADVANCEDANALYTICS)
3332
munge do |value|
3433
if PuppetX::Sqlserver::ServerHelper.is_super_feature(value)
34+
Puppet.deprecation_warning("Using #{value} is deprecated for features in sql_instance resources")
3535
PuppetX::Sqlserver::ServerHelper.get_sub_features(value).collect { |v| v.to_s }
3636
else
3737
value

lib/puppet_x/sqlserver/server_helper.rb

+27
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,33 @@ def self.is_domain_or_local_user?(user, hostname)
2121
true
2222
end
2323
end
24+
25+
# Returns either SQL_2016, SQL_2014 or SQL_2012 if it can determine the SQL Version from the install source
26+
# Returns nil if it can not be determined
27+
def self.sql_version_from_install_source(source_dir)
28+
# Attempt to read the Mediainfo.xml file in the root of the install media
29+
media_file = File.expand_path("#{source_dir}/MediaInfo.xml")
30+
return nil unless File.exist?(media_file)
31+
# As we don't have a XML parser easily, just use simple text matching to find the following XML element. This
32+
# also means we can just ignore BOM markers etc.
33+
# <Property Id="BaselineVersion" Value="xx.yyy.zz." />
34+
content = File.read(media_file)
35+
index1 = content.index('"BaselineVersion"')
36+
return nil if index1.nil?
37+
index2 = content.index('/>',index1)
38+
return nil if index2.nil?
39+
content = content.slice(index1 + 18, index2 - index1 - 18)
40+
# Extract the version number from the text snippet
41+
# Value="xx.yyy.zz."
42+
ver = content.match('"(.+)"')
43+
return nil if ver.nil?
44+
45+
return SQL_2016 if ver[1].start_with?('13.')
46+
return SQL_2014 if ver[1].start_with?('12.')
47+
return SQL_2012 if ver[1].start_with?('11.')
48+
49+
nil
50+
end
2451
end
2552
end
2653
end

spec/acceptance/sqlserver_instance_spec.rb

+1-20
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def sql_query_is_user_sysadmin(username)
8181
end
8282

8383
inst_name = new_random_instance_name
84-
features = ['SQL', 'SQLEngine', 'Replication', 'FullText', 'DQ']
84+
features = ['SQLEngine', 'Replication', 'FullText', 'DQ']
8585

8686
it "create #{inst_name} instance" do
8787
ensure_sqlserver_instance(host, features, inst_name,'present',"['Administrator','ExtraSQLAdmin']")
@@ -114,25 +114,6 @@ def sql_query_is_user_sysadmin(username)
114114
end
115115
end
116116

117-
context "Feature has only one 'SQL'", {:testrail => ['89032']} do
118-
inst_name = new_random_instance_name
119-
features = ['SQL']
120-
121-
after(:all) do
122-
ensure_sqlserver_instance(host, features, inst_name, 'absent')
123-
end
124-
125-
it "create #{inst_name} instance with only one SQL feature" do
126-
ensure_sqlserver_instance(host, features, inst_name)
127-
128-
validate_sql_install(host, {:version => version}) do |r|
129-
expect(r.stdout).to match(/#{inst_name}\s+Database Engine Services/)
130-
expect(r.stdout).to match(/#{inst_name}\s+SQL Server Replication/)
131-
expect(r.stdout).to match(/#{inst_name}\s+Data Quality Services/)
132-
end
133-
end
134-
end
135-
136117
context "Feature has only one 'RS'", {:testrail => ['89034']} do
137118
inst_name = new_random_instance_name
138119
features = ['RS']

0 commit comments

Comments
 (0)