Skip to content

Commit d7f3102

Browse files
author
Travis Fields
committed
FM-2303 Add install switches to sqlserver_install and sqlserver_features
1 parent b6b6310 commit d7f3102

File tree

7 files changed

+106
-33
lines changed

7 files changed

+106
-33
lines changed

lib/puppet/provider/sqlserver_features/mssql.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ def self.instances
1111
existing_instance = {:name => "Generic Features",
1212
:ensure => :present,
1313
:features =>
14-
PuppetX::Sqlserver::ServerHelper.translate_features(
15-
jsonResult['Generic Features']).sort!
14+
PuppetX::Sqlserver::ServerHelper.translate_features(
15+
jsonResult['Generic Features']).sort!
1616
}
1717
debug "Parsed features = #{existing_instance[:features]}"
1818

@@ -58,6 +58,15 @@ def modify_features(action, features)
5858
if not_nil_and_not_empty?(@resource[:pid])
5959
cmd_args << "/PID=#{@resource[:pid]}"
6060
end
61+
if not_nil_and_not_empty?(@resource[:install_switches])
62+
@resource[:install_switches].each_pair do |k, v|
63+
if v.is_a?(Numeric) || (v.is_a?(String) && v =~ /\d/)
64+
cmd_args << "/#{k}=#{v}"
65+
else
66+
cmd_args << "/#{k}='#{v}'"
67+
end
68+
end
69+
end
6170
end
6271
try_execute(cmd_args, "Unable to #{action} features (#{features.join(', ')})")
6372
end

lib/puppet/provider/sqlserver_instance/mssql.rb

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ def self.instances
1212
existing_instance = {:name => instance_name,
1313
:ensure => :present,
1414
:features =>
15-
PuppetX::Sqlserver::ServerHelper.translate_features(
16-
jsonResult[instance_name]['features']).sort!
15+
PuppetX::Sqlserver::ServerHelper.translate_features(
16+
jsonResult[instance_name]['features']).sort!
1717
}
1818
instance = new(existing_instance)
1919
instances << instance
@@ -73,7 +73,7 @@ def basic_cmd_args(features, action)
7373
def build_cmd_args(features, action="install")
7474
cmd_args = basic_cmd_args(features, action)
7575
if action == 'install'
76-
(@resource.parameters.keys - %w(ensure loglevel features name provider source sql_sysadmin_accounts sql_security_mode).map(&:to_sym)).sort.collect do |key|
76+
(@resource.parameters.keys - %w(ensure loglevel features name provider source sql_sysadmin_accounts sql_security_mode install_switches).map(&:to_sym)).sort.collect do |key|
7777
cmd_args << "/#{key.to_s.gsub(/_/, '').upcase}=\"#{@resource[key]}\""
7878
end
7979
if not_nil_and_not_empty? @resource[:sql_sysadmin_accounts]
@@ -83,6 +83,15 @@ def build_cmd_args(features, action="install")
8383
cmd_args << "/SQLSYSADMINACCOUNTS=\"#{@resource[:sql_sysadmin_accounts]}\""
8484
end
8585
end
86+
if not_nil_and_not_empty? @resource[:install_switches]
87+
@resource[:install_switches].each_pair do |k, v|
88+
if v.is_a?(Numeric) || (v.is_a?(String) && v =~ /\d/)
89+
cmd_args << "/#{k}=#{v}"
90+
else
91+
cmd_args << "/#{k}='#{v}'"
92+
end
93+
end
94+
end
8695
end
8796
cmd_args
8897
end

lib/puppet/type/sqlserver_features.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@
4343
end
4444
end
4545

46+
newparam(:install_switches) do
47+
desc 'A hash of switches you want to pass to the installer'
48+
validate do |value|
49+
fail ArguemntError, 'install_switch must be in the form of a Hash' unless value.is_a?(Hash)
50+
end
51+
end
52+
4653
def validate
4754
if set?(:features)
4855
self[:features] = self[:features].flatten.sort.uniq

lib/puppet/type/sqlserver_instance.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'puppet_x/sqlserver/server_helper'))
33

44
Puppet::Type::newtype(:sqlserver_instance) do
5+
56
ensurable
7+
68
newparam(:name, :namevar => true) do
79
munge do |value|
810
value.upcase
@@ -114,6 +116,13 @@
114116
newvalues('SQL')
115117
end
116118

119+
newparam(:install_switches) do
120+
desc 'A hash of switches you want to pass to the installer'
121+
validate do |value|
122+
fail ArguemntError, 'install_switch must be in the form of a Hash' unless value.is_a?(Hash)
123+
end
124+
end
125+
117126

118127
def validate
119128
if set?(:agt_svc_account)

spec/unit/puppet/provider/sqlserver__instance_spec.rb

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
RSpec.describe provider_class do
88
subject { provider_class }
9+
let(:additional_install_switches) { [] }
910

1011
def stub_uninstall(args, installed_features)
1112
cmd_args = ["#{args[:source]}/setup.exe",
@@ -32,7 +33,7 @@ def stub_uninstall(args, installed_features)
3233
'/IACCEPTSQLSERVERLICENSETERMS',
3334
"/INSTANCENAME=#{execute_args[:name]}",
3435
"/FEATURES=#{execute_args[:features].join(',')}",]
35-
(execute_args.keys - %w(ensure loglevel features name source sql_sysadmin_accounts sql_security_mode).map(&:to_sym)).sort.collect do |key|
36+
(execute_args.keys - %w(ensure loglevel features name source sql_sysadmin_accounts sql_security_mode install_switches).map(&:to_sym)).sort.collect do |key|
3637
cmd_args << "/#{key.to_s.gsub(/_/, '').upcase}=\"#{@resource[key]}\""
3738
end
3839
if execute_args[:sql_security_mode]
@@ -58,13 +59,16 @@ def stub_uninstall(args, installed_features)
5859
'/IACCEPTSQLSERVERLICENSETERMS',
5960
"/INSTANCENAME=#{execute_args[:name]}",
6061
"/FEATURES=#{execute_args[:features].join(',')}",]
61-
(execute_args.keys - %w( ensure loglevel features name source sql_sysadmin_accounts sql_security_mode).map(&:to_sym)).sort.collect do |key|
62+
(execute_args.keys - %w( ensure loglevel features name source sql_sysadmin_accounts sql_security_mode install_switches).map(&:to_sym)).sort.collect do |key|
6263
cmd_args << "/#{key.to_s.gsub(/_/, '').upcase}=\"#{@resource[key]}\""
6364
end
6465
if execute_args[:sql_security_mode]
6566
cmd_args << "/SECURITYMODE=SQL"
6667
end
6768
cmd_args << "/SQLSYSADMINACCOUNTS=#{ Array.new(@resource[:sql_sysadmin_accounts]).collect { |account| "\"#{account}\"" }.join(' ')}"
69+
additional_install_switches.each do |switch|
70+
cmd_args << switch
71+
end
6872
Puppet::Util::Execution.stubs(:execute).with(cmd_args.compact).returns(0)
6973
@provider.create
7074
}
@@ -110,19 +114,19 @@ def stub_uninstall(args, installed_features)
110114
it_behaves_like 'destroy on create' do
111115
let(:installed_features) { %w(SQLEngine Replication) }
112116
let(:args) { {
113-
:name => 'MYSQLSERVER',
114-
:source => 'C:\myinstallexecs',
115-
:features => []
117+
:name => 'MYSQLSERVER',
118+
:source => 'C:\myinstallexecs',
119+
:features => []
116120
} }
117121
end
118122
end
119123

120124
describe 'it should uninstall' do
121125
it_behaves_like 'destroy' do
122126
let(:args) { {
123-
:name => 'MYSQLSERVER',
124-
:source => 'C:\myinstallexecs',
125-
:features => []
127+
:name => 'MYSQLSERVER',
128+
:source => 'C:\myinstallexecs',
129+
:features => []
126130
} }
127131
let(:installed_features) { %w(SQLEngine Replication) }
128132
end
@@ -131,11 +135,36 @@ def stub_uninstall(args, installed_features)
131135
describe 'installed features even if provided features' do
132136
it_behaves_like 'destroy' do
133137
let(:args) { {
134-
:name => 'MYSQLSERVER',
135-
:source => 'C:\myinstallexecs',
136-
:features => ['SQL']
138+
:name => 'MYSQLSERVER',
139+
:source => 'C:\myinstallexecs',
140+
:features => ['SQL']
137141
} }
138142
let(:installed_features) { %w(SQLEngine Replication) }
139143
end
140144
end
145+
146+
describe 'install_switches' do
147+
it_behaves_like 'create' do
148+
args = get_basic_args
149+
args[:install_switches] = {'ERRORREPORTING' => 1}
150+
let(:additional_install_switches) { ['/ERRORREPORTING=1'] }
151+
let(:args) { args }
152+
munged = {:features => Array.new(args[:features])}
153+
munged[:features].delete('SQL')
154+
munged[:features] += %w(DQ FullText Replication SQLEngine)
155+
munged[:features].sort!
156+
let(:munged_values) { munged }
157+
end
158+
it_behaves_like 'create' do
159+
args = get_basic_args
160+
args[:install_switches] = {'ERRORREPORTING' => 1, 'SQLBACKUPDIR' => 'I:\DBbackup'}
161+
let(:additional_install_switches) { ['/ERRORREPORTING=1', '/SQLBACKUPDIR=\'I:\DBbackup\''] }
162+
let(:args) { args }
163+
munged = {:features => Array.new(args[:features])}
164+
munged[:features].delete('SQL')
165+
munged[:features] += %w(DQ FullText Replication SQLEngine)
166+
munged[:features].sort!
167+
let(:munged_values) { munged }
168+
end
169+
end
141170
end

spec/unit/puppet/provider/sqlserver_features_spec.rb

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,24 @@
77
RSpec.describe provider_class do
88
subject { provider_class }
99

10-
shared_examples 'create' do |args, munged_args = {}|
10+
shared_examples 'create' do |args, munged_args = {}, additional_switches = []|
1111
it {
1212
@resource = Puppet::Type::Sqlserver_features.new(args)
1313
@provider = provider_class.new(@resource)
1414

1515
stub_powershell_call(subject)
1616

1717
executed_args = args.merge(munged_args)
18-
stub_add_features(executed_args, executed_args[:features])
18+
stub_add_features(executed_args, executed_args[:features], additional_switches)
1919
@provider.create
2020
}
2121
end
2222

2323
shared_context 'features' do
2424
@feature_params = {
25-
:name => 'Base features',
26-
:source => 'C:\myinstallexecs',
27-
:features => %w(BC SSMS)
25+
:name => 'Base features',
26+
:source => 'C:\myinstallexecs',
27+
:features => %w(BC SSMS)
2828
}
2929
let(:feature_remove) { [] }
3030
let(:feature_add) { [] }
@@ -35,6 +35,13 @@
3535
it_should_behave_like 'create', @feature_params
3636
end
3737

38+
context 'it should provide the correct command default command' do
39+
include_context 'features'
40+
@feature_params[:install_switches] ={'ERRORREPORTING' => 1, 'SQLBACKUPDIR' => 'I:\DBbackup'}
41+
additional_switches = ['/ERRORREPORTING=1', '/SQLBACKUPDIR=\'I:\DBbackup\'']
42+
it_should_behave_like 'create', @feature_params, {}, additional_switches
43+
end
44+
3845
context 'it should expand the superset for features' do
3946
include_context 'features'
4047
@feature_params[:features] = %w(Tools)
@@ -100,21 +107,21 @@
100107
describe 'it should call destroy on empty array' do
101108
it {
102109
feature_params = {
103-
:name => 'Base features',
104-
:source => 'C:\myinstallexecs',
105-
:features => []
110+
:name => 'Base features',
111+
:source => 'C:\myinstallexecs',
112+
:features => []
106113
}
107114
@resource = Puppet::Type::Sqlserver_features.new(feature_params)
108115
@provider = provider_class.new(@resource)
109116
@provider.stubs(:current_installed_features).returns(%w(SSMS ADV_SSMS Conn))
110117
Puppet::Util.stubs(:which).with("#{feature_params[:source]}/setup.exe").returns("#{feature_params[:source]}/setup.exe")
111118
Puppet::Util::Execution.expects(:execute).with(
112-
["#{feature_params[:source]}/setup.exe",
113-
"/ACTION=uninstall",
114-
'/Q',
115-
'/IACCEPTSQLSERVERLICENSETERMS',
116-
"/FEATURES=#{%w(SSMS ADV_SSMS Conn).join(',')}",
117-
]).returns(0)
119+
["#{feature_params[:source]}/setup.exe",
120+
"/ACTION=uninstall",
121+
'/Q',
122+
'/IACCEPTSQLSERVERLICENSETERMS',
123+
"/FEATURES=#{%w(SSMS ADV_SSMS Conn).join(',')}",
124+
]).returns(0)
118125
@provider.create
119126
}
120127
end

spec/unit/puppet/sqlserver_spec_helper.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ def stub_powershell_call(subject)
77
Puppet::Provider::Sqlserver.stubs(:run_install_dot_net).returns()
88
end
99

10-
def stub_add_features(args, features)
11-
stub_modify_features('install', args, features)
10+
def stub_add_features(args, features, additional_switches = [])
11+
stub_modify_features('install', args, features, additional_switches)
1212
end
1313

1414
def stub_remove_features(args, features)
1515
stub_modify_features('uninstall', args, features)
1616
end
1717

18-
def stub_modify_features(action, args, features)
18+
def stub_modify_features(action, args, features, additional_switches = [])
1919
cmds = ["#{args[:source]}/setup.exe",
2020
"/ACTION=#{action}",
2121
'/Q',
@@ -28,5 +28,8 @@ def stub_modify_features(action, args, features)
2828
if args.has_key?(:is_svc_password)
2929
cmds << "/ISSVCPASSWORD=#{args[:is_svc_password]}"
3030
end
31+
additional_switches.each do |switch|
32+
cmds << switch
33+
end
3134
Puppet::Util::Execution.stubs(:execute).with(cmds).returns(0)
3235
end

0 commit comments

Comments
 (0)