Skip to content

Commit c5fceca

Browse files
committed
Merge branch 'release'
* release: (24 commits) (FM-2110) sqlserver_tsql docs FM-2122: Added new PE-only development paragraph to readme Fix metadata.json and capture back puppet module build metadata.json (BKR-147) add Gemfile setting for BEAKER_VERSION for puppet... (maint) Adjust Geppetto rules (FM-2094) Fix examples to use sqlserver (maint) - Add .geppetto-rc.json to configure excludes Don't quote install switches true, false, 0, 1 (maint) Redefine installer switch definitions (maint) Add ACL module to fixtures dependency (maint) Add PE version requirement 3.7.x < 4.0.0 (maint) Refactor command line switch parsing (FM-2576) Add /ASSYSADMINACCOUNTS installer support (FM-2576) Whitelist parameters installer accepts (FM-2575) - Fixed bug with login exists, and creation Fix spec tests raise_error check (FM-2404) Refactor acceptance specs to not use shared context Add acceptance test starting framework, YAY ACCEPTANCE TESTS DOCS: Improved example for install_switches param FM-2328: document install_switches param in sqlserver ... Paired-with: Travis Fields <[email protected]>
2 parents 45bed60 + 3526447 commit c5fceca

File tree

14 files changed

+430
-55
lines changed

14 files changed

+430
-55
lines changed

.fixtures.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
fixtures:
22
forge_modules:
3+
acl: "puppetlabs/acl"
34
stdlib: "puppetlabs/stdlib"
45
acl: "puppetlabs/acl"
56
symlinks:

.geppetto-rc.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"excludes": [
3+
"**/spec/**",
4+
"**/pkg/**"
5+
]
6+
}

Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,7 @@ else
4343
gem 'puppet', '~> 3.7', :require => false
4444
end
4545

46+
if File.exists? "#{__FILE__}.local"
47+
eval(File.read("#{__FILE__}.local"), binding)
48+
end
4649
# vim:ft=ruby

lib/puppet/provider/sqlserver_features/mssql.rb

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
require 'json'
22
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'sqlserver'))
33

4-
Puppet::Type::type(:sqlserver_features).provide(:mssql, :parent => Puppet::Provider::Sqlserver) do
4+
FEATURE_RESERVED_SWITCHES =
5+
%w(AGTSVCACCOUNT AGTSVCPASSWORD ASSVCACCOUNT AGTSVCPASSWORD PID
6+
RSSVCACCOUNT RSSVCPASSWORD SAPWD SECURITYMODE SQLSYSADMINACCOUNTS FEATURES)
57

8+
Puppet::Type::type(:sqlserver_features).provide(:mssql, :parent => Puppet::Provider::Sqlserver) do
69
def self.instances
710
instances = []
811
jsonResult = Puppet::Provider::Sqlserver.run_discovery_script
@@ -11,8 +14,8 @@ def self.instances
1114
existing_instance = {:name => "Generic Features",
1215
:ensure => :present,
1316
:features =>
14-
PuppetX::Sqlserver::ServerHelper.translate_features(
15-
jsonResult['Generic Features']).sort!
17+
PuppetX::Sqlserver::ServerHelper.translate_features(
18+
jsonResult['Generic Features']).sort!
1619
}
1720
debug "Parsed features = #{existing_instance[:features]}"
1821

@@ -59,8 +62,42 @@ def modify_features(action, features)
5962
cmd_args << "/PID=#{@resource[:pid]}"
6063
end
6164
end
62-
try_execute(cmd_args, "Unable to #{action} features (#{features.join(', ')})")
65+
begin
66+
config_file = create_temp_for_install_switch unless action == 'uninstall'
67+
cmd_args << "/ConfigurationFile=\"#{config_file.path}\"" unless config_file.nil?
68+
try_execute(cmd_args, "Unable to #{action} features (#{features.join(', ')})")
69+
ensure
70+
if config_file
71+
config_file.close
72+
config_file.unlink
73+
end
74+
end
75+
end
76+
end
77+
78+
def create_temp_for_install_switch
79+
if not_nil_and_not_empty? @resource[:install_switches]
80+
config_file = ["[OPTIONS]"]
81+
@resource[:install_switches].each_pair do |k, v|
82+
if FEATURE_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")
85+
end
86+
if v.is_a?(Numeric) || (v.is_a?(String) && v =~ /^(true|false|1|0)$/i)
87+
config_file << "#{k}=#{v}"
88+
elsif v.nil?
89+
config_file << k
90+
else
91+
config_file << "#{k}=\"#{v}\""
92+
end
93+
end
94+
config_temp = Tempfile.new(['sqlconfig', '.ini'])
95+
config_temp.write(config_file.join("\n"))
96+
config_temp.flush
97+
config_temp.close
98+
return config_temp
6399
end
100+
return nil
64101
end
65102

66103
def installNet35

lib/puppet/provider/sqlserver_instance/mssql.rb

Lines changed: 68 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
require 'json'
22
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'sqlserver'))
33

4-
Puppet::Type::type(:sqlserver_instance).provide(:mssql, :parent => Puppet::Provider::Sqlserver) do
54

5+
INSTANCE_RESERVED_SWITCHES =
6+
%w(AGTSVCACCOUNT AGTSVCPASSWORD ASSVCACCOUNT AGTSVCPASSWORD PID
7+
RSSVCACCOUNT RSSVCPASSWORD SAPWD SECURITYMODE SQLSYSADMINACCOUNTS FEATURES)
8+
9+
Puppet::Type::type(:sqlserver_instance).provide(:mssql, :parent => Puppet::Provider::Sqlserver) do
610
def self.instances
711
instances = []
812
jsonResult = Puppet::Provider::Sqlserver.run_discovery_script
@@ -12,8 +16,8 @@ def self.instances
1216
existing_instance = {:name => instance_name,
1317
:ensure => :present,
1418
:features =>
15-
PuppetX::Sqlserver::ServerHelper.translate_features(
16-
jsonResult[instance_name]['features']).sort!
19+
PuppetX::Sqlserver::ServerHelper.translate_features(
20+
jsonResult[instance_name]['features']).sort!
1721
}
1822
instance = new(existing_instance)
1923
instances << instance
@@ -42,7 +46,17 @@ def add_features(features)
4246
def modify_features(features, action)
4347
if not_nil_and_not_empty? features
4448
debug "#{action.capitalize}ing features '#{features.join(',')}'"
45-
try_execute(build_cmd_args(features, action), "Error trying to #{action} features (#{features.join(', ')}")
49+
cmd_args = build_cmd_args(features, action)
50+
begin
51+
config_file = create_temp_for_install_switch unless action == 'uninstall'
52+
cmd_args << "/ConfigurationFile=\"#{config_file.path}\"" unless config_file.nil?
53+
try_execute(cmd_args, "Error trying to #{action} features (#{features.join(', ')}")
54+
ensure
55+
if config_file
56+
config_file.close
57+
config_file.unlink
58+
end
59+
end
4660
end
4761
end
4862

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

64113
def basic_cmd_args(features, action)
@@ -73,20 +122,25 @@ def basic_cmd_args(features, action)
73122
def build_cmd_args(features, action="install")
74123
cmd_args = basic_cmd_args(features, action)
75124
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|
77-
cmd_args << "/#{key.to_s.gsub(/_/, '').upcase}=\"#{@resource[key]}\""
78-
end
79-
if not_nil_and_not_empty? @resource[:sql_sysadmin_accounts]
80-
if @resource[:sql_sysadmin_accounts].kind_of?(Array)
81-
cmd_args << "/SQLSYSADMINACCOUNTS=#{ Array.new(@resource[:sql_sysadmin_accounts]).collect { |account| "\"#{account}\"" }.join(' ')}"
82-
else
83-
cmd_args << "/SQLSYSADMINACCOUNTS=\"#{@resource[:sql_sysadmin_accounts]}\""
125+
%w(pid sa_pwd sql_svc_account sql_svc_password agt_svc_account agt_svc_password as_svc_account as_svc_password rs_svc_account rs_svc_password security_mode).map(&:to_sym).sort.collect do |key|
126+
if not_nil_and_not_empty? @resource[key]
127+
cmd_args << "/#{key.to_s.gsub(/_/, '').upcase}=\"#{@resource[key]}\""
84128
end
85129
end
130+
131+
format_cmd_args_array('/SQLSYSADMINACCOUNTS', @resource[:sql_sysadmin_accounts], cmd_args)
132+
format_cmd_args_array('/ASSYSADMINACCOUNTS', @resource[:as_sysadmin_accounts], cmd_args)
86133
end
87134
cmd_args
88135
end
89136

137+
def format_cmd_args_array(switch, arr, cmd_args)
138+
if not_nil_and_not_empty? arr
139+
arr = [arr] if !arr.kind_of?(Array)
140+
cmd_args << "#{switch}=#{arr.collect { |item| "\"#{item}\"" }.join(' ')}"
141+
end
142+
end
143+
90144
def destroy
91145
cmd_args = basic_cmd_args(current_installed_features, 'uninstall')
92146
try_execute(cmd_args, "Unable to uninstall instance #{@resource[:name]}")

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)

metadata.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,16 @@
77
"source": "https://tickets.puppetlabs.com/browse/MODULES/component/12400",
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": [
11+
"sql",
12+
"mssql",
13+
"sqlserver",
14+
"microsoft",
15+
"sql2012",
16+
"sql2014",
17+
"tsql",
18+
"database"
19+
],
1120
"operatingsystem_support": [
1221
{
1322
"operatingsystem": "Windows",
@@ -20,7 +29,7 @@
2029
"requirements": [
2130
{
2231
"name": "pe",
23-
"version_requirement": "3.7.x"
32+
"version_requirement": ">= 3.7.0 < 4.0.0"
2433
}
2534
],
2635
"dependencies": [
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
HOSTS:
2+
debian6:
3+
roles:
4+
- master
5+
- database
6+
- dashboard
7+
platform: debian-6-i386
8+
template: debian-6-i386
9+
hypervisor: vcloud
10+
sql2012:
11+
roles:
12+
- agent
13+
- default
14+
- sql2012
15+
platform: windows-2012r2-x86_64
16+
template: win-2012r2-x86_64
17+
hypervisor: vcloud
18+
sql2014:
19+
roles:
20+
- agent
21+
- sql2014
22+
platform: windows-2012r2-x86_64
23+
template: win-2012r2-x86_64
24+
hypervisor: vcloud
25+
CONFIG:
26+
nfs_server: none
27+
consoleport: 443
28+
datastore: instance0
29+
folder: Delivery/Quality Assurance/FOSS/Dynamic
30+
resourcepool: delivery/Quality Assurance/FOSS/Dynamic
31+
pooling_api: http://vcloud.delivery.puppetlabs.net/

spec/spec_helper_acceptance.rb

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
require 'beaker-rspec/spec_helper'
2+
require 'beaker-rspec/helpers/serverspec'
3+
require 'sql_testing_helpers'
4+
5+
QA_RESOURCE_ROOT = "http://int-resources.ops.puppetlabs.net/QA_resources/microsoft_sql/iso/"
6+
SQL_2014_ISO = "SQLServer2014-x64-ENU.iso"
7+
SQL_2012_ISO = "SQLServer2012SP1-FullSlipstream-ENU-x64.iso"
8+
9+
RSpec.configure do |c|
10+
# Readable test descriptions
11+
c.formatter = :documentation
12+
c.before(:suite) do
13+
base_install
14+
end
15+
end
16+
17+
FUTURE_PARSER = ENV['FUTURE_PARSER'] == 'true' || false
18+
19+
unless ENV['RS_PROVISION'] == 'no' or ENV['BEAKER_provision'] == 'no'
20+
is_foss = (ENV['IS_PE'] == 'no' || ENV['IS_PE'] == 'false') ? true : false
21+
if hosts.first.is_pe? && !is_foss
22+
install_pe
23+
else
24+
version = ENV['PUPPET_VERSION'] || '3.7.4'
25+
download_url = ENV['WIN_DOWNLOAD_URL'] || 'http://downloads.puppetlabs.com/windows/'
26+
hosts.each do |host|
27+
if host['platform'] =~ /windows/i
28+
install_puppet_from_msi(host,
29+
{
30+
:win_download_url => download_url,
31+
:version => version,
32+
:install_32 => true})
33+
end
34+
end
35+
end
36+
37+
agents.each do |agent|
38+
step "Install sqlserver module to agent #{agent.node_name}"
39+
on agent, "mkdir -p #{default['distmoduledir']}/sqlserver"
40+
result = on agent, "echo #{default['distmoduledir']}"
41+
target = result.raw_output.chomp
42+
proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
43+
exec_puppet = <<-EOS
44+
exec{'Download':
45+
command => 'powershell.exe -command "Invoke-WebRequest https://forgeapi.puppetlabs.com"',
46+
path => ['c:\\windows\\sysnative\\WindowsPowershell\\v1.0','c:\\windows\\system32\\WindowsPowershell\\v1.0'],
47+
}
48+
EOS
49+
apply_manifest_on(agent, exec_puppet)
50+
%w(puppetlabs/stdlib puppetlabs/acl cyberious/pget puppetlabs/reboot puppetlabs/registry).each do |dep|
51+
on agent, puppet("module install #{dep}")
52+
end
53+
on agent, "git clone https://github.com/puppetlabs/puppetlabs-mount_iso #{target}/mount_iso"
54+
install_dev_puppet_module_on(agent, {:proj_root => proj_root, :target_module_path => "#{target}", :module_name => 'sqlserver'})
55+
end
56+
end
57+
58+

0 commit comments

Comments
 (0)