Skip to content

Commit f9f26ae

Browse files
committed
Merge pull request #81 from cyberious/InstallSwitchCherryPick
FM-2303 Add install switches needed by customer
2 parents b6b6310 + e64f1cf commit f9f26ae

File tree

10 files changed

+259
-78
lines changed

10 files changed

+259
-78
lines changed

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,10 @@
1+
##2015-03-10 - 1.1.0
2+
###Summary
3+
4+
Add ability to provide unmaged install switches
5+
6+
####Features
7+
- `sqlserver_instance` and `sqlserver_features` have new parameter `install_switches` which takes a hash of install switches and writes them to a temp configuration file for the the install process
8+
19
##2014-12-08 - 1.0.0
210
Initial release

README.md

+43-32
Large diffs are not rendered by default.

lib/puppet/provider/sqlserver_features/mssql.rb

+37-3
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

@@ -59,8 +59,42 @@ def modify_features(action, features)
5959
cmd_args << "/PID=#{@resource[:pid]}"
6060
end
6161
end
62-
try_execute(cmd_args, "Unable to #{action} features (#{features.join(', ')})")
62+
begin
63+
config_file = create_temp_for_install_switch unless action == 'uninstall'
64+
cmd_args << "/ConfigurationFile=\"#{config_file.path}\"" unless config_file.nil?
65+
try_execute(cmd_args, "Unable to #{action} features (#{features.join(', ')})")
66+
ensure
67+
if config_file
68+
config_file.close
69+
config_file.unlink
70+
end
71+
end
72+
end
73+
end
74+
75+
def create_temp_for_install_switch
76+
if not_nil_and_not_empty? @resource[:install_switches]
77+
config_file = ["[OPTIONS]"]
78+
@resource[:install_switches].each_pair do |k, v|
79+
if RESERVED_SWITCHES.include? k
80+
warn("Reserved switch [#{k}] found for `install_switches`, please know the provided value
81+
may be overridden by some command line arguments")
82+
end
83+
if v.is_a?(Numeric) || (v.is_a?(String) && v =~ /\d/)
84+
config_file << "#{k}=#{v}"
85+
elsif v.nil?
86+
config_file << k
87+
else
88+
config_file << "#{k}=\"#{v}\""
89+
end
90+
end
91+
config_temp = Tempfile.new(['sqlconfig', '.ini'])
92+
config_temp.write(config_file.join("\n"))
93+
config_temp.flush
94+
config_temp.close
95+
return config_temp
6396
end
97+
return nil
6498
end
6599

66100
def installNet35

lib/puppet/provider/sqlserver_instance/mssql.rb

+54-6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'sqlserver'))
33

44
Puppet::Type::type(:sqlserver_instance).provide(:mssql, :parent => Puppet::Provider::Sqlserver) do
5+
RESERVED_SWITCHES =
6+
%w(AGTSVCACCOUNT AGTSVCPASSWORD ASSVCACCOUNT AGTSVCPASSWORD PID
7+
RSSVCACCOUNT RSSVCPASSWORD SAPWD SECURITYMODE SQLSYSADMINACCOUNTS FEATURES)
58

69
def self.instances
710
instances = []
@@ -12,8 +15,8 @@ def self.instances
1215
existing_instance = {:name => instance_name,
1316
:ensure => :present,
1417
:features =>
15-
PuppetX::Sqlserver::ServerHelper.translate_features(
16-
jsonResult[instance_name]['features']).sort!
18+
PuppetX::Sqlserver::ServerHelper.translate_features(
19+
jsonResult[instance_name]['features']).sort!
1720
}
1821
instance = new(existing_instance)
1922
instances << instance
@@ -42,7 +45,17 @@ def add_features(features)
4245
def modify_features(features, action)
4346
if not_nil_and_not_empty? features
4447
debug "#{action.capitalize}ing features '#{features.join(',')}'"
45-
try_execute(build_cmd_args(features, action), "Error trying to #{action} features (#{features.join(', ')}")
48+
cmd_args = build_cmd_args(features, action)
49+
begin
50+
config_file = create_temp_for_install_switch unless action == 'uninstall'
51+
cmd_args << "/ConfigurationFile=\"#{config_file.path}\"" unless config_file.nil?
52+
try_execute(cmd_args, "Error trying to #{action} features (#{features.join(', ')}")
53+
ensure
54+
if config_file
55+
config_file.close
56+
config_file.unlink
57+
end
58+
end
4659
end
4760
end
4861

@@ -56,9 +69,44 @@ def create
5669
destroy
5770
else
5871
installNet35
59-
cmd_args = build_cmd_args(@resource[:features])
60-
try_execute(cmd_args)
72+
add_features(@resource[:features])
73+
# cmd_args = build_cmd_args(@resource[:features])
74+
# begin
75+
# config_file = create_temp_for_install_switch
76+
# cmd_args << "/ConfigurationFile=\"#{config_file.path}\"" unless config_file.nil?
77+
# try_execute(cmd_args)
78+
# ensure
79+
# if config_file
80+
# config_file.close
81+
# config_file.unlink
82+
# end
83+
# end
84+
end
85+
end
86+
87+
def create_temp_for_install_switch
88+
if not_nil_and_not_empty? @resource[:install_switches]
89+
config_file = ["[OPTIONS]"]
90+
@resource[:install_switches].each_pair do |k, v|
91+
if RESERVED_SWITCHES.include? k
92+
warn("Reserved switch [#{k}] found for `install_switches`, please know the provided value
93+
may be overridden by some command line arguments")
94+
end
95+
if v.is_a?(Numeric) || (v.is_a?(String) && v =~ /\d/)
96+
config_file << "#{k}=#{v}"
97+
elsif v.nil?
98+
config_file << k
99+
else
100+
config_file << "#{k}=\"#{v}\""
101+
end
102+
end
103+
config_temp = Tempfile.new(['sqlconfig', '.ini'])
104+
config_temp.write(config_file.join("\n"))
105+
config_temp.flush
106+
config_temp.close
107+
return config_temp
61108
end
109+
return nil
62110
end
63111

64112
def basic_cmd_args(features, action)
@@ -73,7 +121,7 @@ def basic_cmd_args(features, action)
73121
def build_cmd_args(features, action="install")
74122
cmd_args = basic_cmd_args(features, action)
75123
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|
124+
(@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|
77125
cmd_args << "/#{key.to_s.gsub(/_/, '').upcase}=\"#{@resource[key]}\""
78126
end
79127
if not_nil_and_not_empty? @resource[:sql_sysadmin_accounts]

lib/puppet/type/sqlserver_features.rb

+7
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

+9
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)

metadata.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"name": "puppetlabs-sqlserver",
3-
"version": "1.0.0",
3+
"version": "1.1.0",
44
"author": "puppetlabs",
55
"summary": "The `sqlserver` module installs and manages MS SQL Server 2012 and 2014 on Windows systems.",
66
"license": "Puppet Labs Enterprise",
77
"source": "PRIVATE",
88
"project_page": "https://tickets.puppetlabs.com/browse/MODULES/component/12400",
99
"issues_url": "https://tickets.puppetlabs.com/browse/MODULES/component/12400",
10-
"tags": ["ms sql", "mssql", "sql server", "microsoft sql server", "windows", "sql 2012", "sql 2014"],
10+
"tags": ["sql", "mssql", "sqlserver", "microsoft", "sql2012", "sql2014", "tsql", "database"],
1111
"operatingsystem_support": [
1212
{
1313
"operatingsystem": "Windows",

spec/unit/puppet/provider/sqlserver__instance_spec.rb

+49-11
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
require 'spec_helper'
2+
require 'mocha'
23

34
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'sqlserver_install_context.rb'))
45

56
provider_class = Puppet::Type.type(:sqlserver_instance).provider(:mssql)
67

78
RSpec.describe provider_class do
89
subject { provider_class }
10+
let(:additional_install_switches) { [] }
911

1012
def stub_uninstall(args, installed_features)
1113
cmd_args = ["#{args[:source]}/setup.exe",
@@ -32,7 +34,7 @@ def stub_uninstall(args, installed_features)
3234
'/IACCEPTSQLSERVERLICENSETERMS',
3335
"/INSTANCENAME=#{execute_args[:name]}",
3436
"/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|
37+
(execute_args.keys - %w(ensure loglevel features name source sql_sysadmin_accounts sql_security_mode install_switches).map(&:to_sym)).sort.collect do |key|
3638
cmd_args << "/#{key.to_s.gsub(/_/, '').upcase}=\"#{@resource[key]}\""
3739
end
3840
if execute_args[:sql_security_mode]
@@ -58,13 +60,16 @@ def stub_uninstall(args, installed_features)
5860
'/IACCEPTSQLSERVERLICENSETERMS',
5961
"/INSTANCENAME=#{execute_args[:name]}",
6062
"/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|
63+
(execute_args.keys - %w( ensure loglevel features name source sql_sysadmin_accounts sql_security_mode install_switches).map(&:to_sym)).sort.collect do |key|
6264
cmd_args << "/#{key.to_s.gsub(/_/, '').upcase}=\"#{@resource[key]}\""
6365
end
6466
if execute_args[:sql_security_mode]
6567
cmd_args << "/SECURITYMODE=SQL"
6668
end
6769
cmd_args << "/SQLSYSADMINACCOUNTS=#{ Array.new(@resource[:sql_sysadmin_accounts]).collect { |account| "\"#{account}\"" }.join(' ')}"
70+
additional_install_switches.each do |switch|
71+
cmd_args << switch
72+
end
6873
Puppet::Util::Execution.stubs(:execute).with(cmd_args.compact).returns(0)
6974
@provider.create
7075
}
@@ -110,19 +115,19 @@ def stub_uninstall(args, installed_features)
110115
it_behaves_like 'destroy on create' do
111116
let(:installed_features) { %w(SQLEngine Replication) }
112117
let(:args) { {
113-
:name => 'MYSQLSERVER',
114-
:source => 'C:\myinstallexecs',
115-
:features => []
118+
:name => 'MYSQLSERVER',
119+
:source => 'C:\myinstallexecs',
120+
:features => []
116121
} }
117122
end
118123
end
119124

120125
describe 'it should uninstall' do
121126
it_behaves_like 'destroy' do
122127
let(:args) { {
123-
:name => 'MYSQLSERVER',
124-
:source => 'C:\myinstallexecs',
125-
:features => []
128+
:name => 'MYSQLSERVER',
129+
:source => 'C:\myinstallexecs',
130+
:features => []
126131
} }
127132
let(:installed_features) { %w(SQLEngine Replication) }
128133
end
@@ -131,11 +136,44 @@ def stub_uninstall(args, installed_features)
131136
describe 'installed features even if provided features' do
132137
it_behaves_like 'destroy' do
133138
let(:args) { {
134-
:name => 'MYSQLSERVER',
135-
:source => 'C:\myinstallexecs',
136-
:features => ['SQL']
139+
:name => 'MYSQLSERVER',
140+
:source => 'C:\myinstallexecs',
141+
:features => ['SQL']
137142
} }
138143
let(:installed_features) { %w(SQLEngine Replication) }
139144
end
140145
end
146+
147+
describe 'install_switches' do
148+
before :each do
149+
@file_double = Tempfile.new(['sqlconfig', '.ini'])
150+
@file_double.stubs(:write)
151+
@file_double.stubs(:flush)
152+
@file_double.stubs(:close)
153+
Tempfile.stubs(:new).with(['sqlconfig', '.ini']).returns(@file_double)
154+
end
155+
156+
it_behaves_like 'create' do
157+
args = get_basic_args
158+
args[:install_switches] = {'ERRORREPORTING' => 1}
159+
let(:additional_install_switches) { ["/ConfigurationFile=\"#{@file_double.path}\""] }
160+
let(:args) { args }
161+
munged = {:features => Array.new(args[:features])}
162+
munged[:features].delete('SQL')
163+
munged[:features] += %w(DQ FullText Replication SQLEngine)
164+
munged[:features].sort!
165+
let(:munged_values) { munged }
166+
end
167+
it_behaves_like 'create' do
168+
args = get_basic_args
169+
args[:install_switches] = {'ERRORREPORTING' => 1, 'SQLBACKUPDIR' => 'I:\DBbackup'}
170+
let(:additional_install_switches) { ["/ConfigurationFile=\"#{@file_double.path}\""] }
171+
let(:args) { args }
172+
munged = {:features => Array.new(args[:features])}
173+
munged[:features].delete('SQL')
174+
munged[:features] += %w(DQ FullText Replication SQLEngine)
175+
munged[:features].sort!
176+
let(:munged_values) { munged }
177+
end
178+
end
141179
end

0 commit comments

Comments
 (0)