Skip to content

FM-2303 Add install switches needed by customer #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 5, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
##2015-03-10 - 1.1.0
###Summary

Add ability to provide unmaged install switches

####Features
- `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

##2014-12-08 - 1.0.0
Initial release
75 changes: 43 additions & 32 deletions README.md

Large diffs are not rendered by default.

40 changes: 37 additions & 3 deletions lib/puppet/provider/sqlserver_features/mssql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ def self.instances
existing_instance = {:name => "Generic Features",
:ensure => :present,
:features =>
PuppetX::Sqlserver::ServerHelper.translate_features(
jsonResult['Generic Features']).sort!
PuppetX::Sqlserver::ServerHelper.translate_features(
jsonResult['Generic Features']).sort!
}
debug "Parsed features = #{existing_instance[:features]}"

Expand Down Expand Up @@ -59,8 +59,42 @@ def modify_features(action, features)
cmd_args << "/PID=#{@resource[:pid]}"
end
end
try_execute(cmd_args, "Unable to #{action} features (#{features.join(', ')})")
begin
config_file = create_temp_for_install_switch unless action == 'uninstall'
cmd_args << "/ConfigurationFile=\"#{config_file.path}\"" unless config_file.nil?
try_execute(cmd_args, "Unable to #{action} features (#{features.join(', ')})")
ensure
if config_file
config_file.close
config_file.unlink
end
end
end
end

def create_temp_for_install_switch
if not_nil_and_not_empty? @resource[:install_switches]
config_file = ["[OPTIONS]"]
@resource[:install_switches].each_pair do |k, v|
if RESERVED_SWITCHES.include? k
warn("Reserved switch [#{k}] found for `install_switches`, please know the provided value
may be overridden by some command line arguments")
end
if v.is_a?(Numeric) || (v.is_a?(String) && v =~ /\d/)
config_file << "#{k}=#{v}"
elsif v.nil?
config_file << k
else
config_file << "#{k}=\"#{v}\""
end
end
config_temp = Tempfile.new(['sqlconfig', '.ini'])
config_temp.write(config_file.join("\n"))
config_temp.flush
config_temp.close
return config_temp
end
return nil
end

def installNet35
Expand Down
60 changes: 54 additions & 6 deletions lib/puppet/provider/sqlserver_instance/mssql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'sqlserver'))

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

def self.instances
instances = []
Expand All @@ -12,8 +15,8 @@ def self.instances
existing_instance = {:name => instance_name,
:ensure => :present,
:features =>
PuppetX::Sqlserver::ServerHelper.translate_features(
jsonResult[instance_name]['features']).sort!
PuppetX::Sqlserver::ServerHelper.translate_features(
jsonResult[instance_name]['features']).sort!
}
instance = new(existing_instance)
instances << instance
Expand Down Expand Up @@ -42,7 +45,17 @@ def add_features(features)
def modify_features(features, action)
if not_nil_and_not_empty? features
debug "#{action.capitalize}ing features '#{features.join(',')}'"
try_execute(build_cmd_args(features, action), "Error trying to #{action} features (#{features.join(', ')}")
cmd_args = build_cmd_args(features, action)
begin
config_file = create_temp_for_install_switch unless action == 'uninstall'
cmd_args << "/ConfigurationFile=\"#{config_file.path}\"" unless config_file.nil?
try_execute(cmd_args, "Error trying to #{action} features (#{features.join(', ')}")
ensure
if config_file
config_file.close
config_file.unlink
end
end
end
end

Expand All @@ -56,9 +69,44 @@ def create
destroy
else
installNet35
cmd_args = build_cmd_args(@resource[:features])
try_execute(cmd_args)
add_features(@resource[:features])
# cmd_args = build_cmd_args(@resource[:features])
# begin
# config_file = create_temp_for_install_switch
# cmd_args << "/ConfigurationFile=\"#{config_file.path}\"" unless config_file.nil?
# try_execute(cmd_args)
# ensure
# if config_file
# config_file.close
# config_file.unlink
# end
# end
end
end

def create_temp_for_install_switch
if not_nil_and_not_empty? @resource[:install_switches]
config_file = ["[OPTIONS]"]
@resource[:install_switches].each_pair do |k, v|
if RESERVED_SWITCHES.include? k
warn("Reserved switch [#{k}] found for `install_switches`, please know the provided value
may be overridden by some command line arguments")
end
if v.is_a?(Numeric) || (v.is_a?(String) && v =~ /\d/)
config_file << "#{k}=#{v}"
elsif v.nil?
config_file << k
else
config_file << "#{k}=\"#{v}\""
end
end
config_temp = Tempfile.new(['sqlconfig', '.ini'])
config_temp.write(config_file.join("\n"))
config_temp.flush
config_temp.close
return config_temp
end
return nil
end

def basic_cmd_args(features, action)
Expand All @@ -73,7 +121,7 @@ def basic_cmd_args(features, action)
def build_cmd_args(features, action="install")
cmd_args = basic_cmd_args(features, action)
if action == 'install'
(@resource.parameters.keys - %w(ensure loglevel features name provider source sql_sysadmin_accounts sql_security_mode).map(&:to_sym)).sort.collect do |key|
(@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|
cmd_args << "/#{key.to_s.gsub(/_/, '').upcase}=\"#{@resource[key]}\""
end
if not_nil_and_not_empty? @resource[:sql_sysadmin_accounts]
Expand Down
7 changes: 7 additions & 0 deletions lib/puppet/type/sqlserver_features.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@
end
end

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

def validate
if set?(:features)
self[:features] = self[:features].flatten.sort.uniq
Expand Down
9 changes: 9 additions & 0 deletions lib/puppet/type/sqlserver_instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'puppet_x/sqlserver/server_helper'))

Puppet::Type::newtype(:sqlserver_instance) do

ensurable

newparam(:name, :namevar => true) do
munge do |value|
value.upcase
Expand Down Expand Up @@ -114,6 +116,13 @@
newvalues('SQL')
end

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


def validate
if set?(:agt_svc_account)
Expand Down
4 changes: 2 additions & 2 deletions metadata.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "puppetlabs-sqlserver",
"version": "1.0.0",
"version": "1.1.0",
"author": "puppetlabs",
"summary": "The `sqlserver` module installs and manages MS SQL Server 2012 and 2014 on Windows systems.",
"license": "Puppet Labs Enterprise",
"source": "PRIVATE",
"project_page": "https://tickets.puppetlabs.com/browse/MODULES/component/12400",
"issues_url": "https://tickets.puppetlabs.com/browse/MODULES/component/12400",
"tags": ["ms sql", "mssql", "sql server", "microsoft sql server", "windows", "sql 2012", "sql 2014"],
"tags": ["sql", "mssql", "sqlserver", "microsoft", "sql2012", "sql2014", "tsql", "database"],
"operatingsystem_support": [
{
"operatingsystem": "Windows",
Expand Down
60 changes: 49 additions & 11 deletions spec/unit/puppet/provider/sqlserver__instance_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
require 'spec_helper'
require 'mocha'

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

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

RSpec.describe provider_class do
subject { provider_class }
let(:additional_install_switches) { [] }

def stub_uninstall(args, installed_features)
cmd_args = ["#{args[:source]}/setup.exe",
Expand All @@ -32,7 +34,7 @@ def stub_uninstall(args, installed_features)
'/IACCEPTSQLSERVERLICENSETERMS',
"/INSTANCENAME=#{execute_args[:name]}",
"/FEATURES=#{execute_args[:features].join(',')}",]
(execute_args.keys - %w(ensure loglevel features name source sql_sysadmin_accounts sql_security_mode).map(&:to_sym)).sort.collect do |key|
(execute_args.keys - %w(ensure loglevel features name source sql_sysadmin_accounts sql_security_mode install_switches).map(&:to_sym)).sort.collect do |key|
cmd_args << "/#{key.to_s.gsub(/_/, '').upcase}=\"#{@resource[key]}\""
end
if execute_args[:sql_security_mode]
Expand All @@ -58,13 +60,16 @@ def stub_uninstall(args, installed_features)
'/IACCEPTSQLSERVERLICENSETERMS',
"/INSTANCENAME=#{execute_args[:name]}",
"/FEATURES=#{execute_args[:features].join(',')}",]
(execute_args.keys - %w( ensure loglevel features name source sql_sysadmin_accounts sql_security_mode).map(&:to_sym)).sort.collect do |key|
(execute_args.keys - %w( ensure loglevel features name source sql_sysadmin_accounts sql_security_mode install_switches).map(&:to_sym)).sort.collect do |key|
cmd_args << "/#{key.to_s.gsub(/_/, '').upcase}=\"#{@resource[key]}\""
end
if execute_args[:sql_security_mode]
cmd_args << "/SECURITYMODE=SQL"
end
cmd_args << "/SQLSYSADMINACCOUNTS=#{ Array.new(@resource[:sql_sysadmin_accounts]).collect { |account| "\"#{account}\"" }.join(' ')}"
additional_install_switches.each do |switch|
cmd_args << switch
end
Puppet::Util::Execution.stubs(:execute).with(cmd_args.compact).returns(0)
@provider.create
}
Expand Down Expand Up @@ -110,19 +115,19 @@ def stub_uninstall(args, installed_features)
it_behaves_like 'destroy on create' do
let(:installed_features) { %w(SQLEngine Replication) }
let(:args) { {
:name => 'MYSQLSERVER',
:source => 'C:\myinstallexecs',
:features => []
:name => 'MYSQLSERVER',
:source => 'C:\myinstallexecs',
:features => []
} }
end
end

describe 'it should uninstall' do
it_behaves_like 'destroy' do
let(:args) { {
:name => 'MYSQLSERVER',
:source => 'C:\myinstallexecs',
:features => []
:name => 'MYSQLSERVER',
:source => 'C:\myinstallexecs',
:features => []
} }
let(:installed_features) { %w(SQLEngine Replication) }
end
Expand All @@ -131,11 +136,44 @@ def stub_uninstall(args, installed_features)
describe 'installed features even if provided features' do
it_behaves_like 'destroy' do
let(:args) { {
:name => 'MYSQLSERVER',
:source => 'C:\myinstallexecs',
:features => ['SQL']
:name => 'MYSQLSERVER',
:source => 'C:\myinstallexecs',
:features => ['SQL']
} }
let(:installed_features) { %w(SQLEngine Replication) }
end
end

describe 'install_switches' do
before :each do
@file_double = Tempfile.new(['sqlconfig', '.ini'])
@file_double.stubs(:write)
@file_double.stubs(:flush)
@file_double.stubs(:close)
Tempfile.stubs(:new).with(['sqlconfig', '.ini']).returns(@file_double)
end

it_behaves_like 'create' do
args = get_basic_args
args[:install_switches] = {'ERRORREPORTING' => 1}
let(:additional_install_switches) { ["/ConfigurationFile=\"#{@file_double.path}\""] }
let(:args) { args }
munged = {:features => Array.new(args[:features])}
munged[:features].delete('SQL')
munged[:features] += %w(DQ FullText Replication SQLEngine)
munged[:features].sort!
let(:munged_values) { munged }
end
it_behaves_like 'create' do
args = get_basic_args
args[:install_switches] = {'ERRORREPORTING' => 1, 'SQLBACKUPDIR' => 'I:\DBbackup'}
let(:additional_install_switches) { ["/ConfigurationFile=\"#{@file_double.path}\""] }
let(:args) { args }
munged = {:features => Array.new(args[:features])}
munged[:features].delete('SQL')
munged[:features] += %w(DQ FullText Replication SQLEngine)
munged[:features].sort!
let(:munged_values) { munged }
end
end
end
Loading