Skip to content

Commit 3b54488

Browse files
committed
Merge branch 'master' into stable
* master: (MODULES-3752) Fix modifying server_roles for an existing WINDOWS_LOGIN (BKR-914) Add workaround for beaker bug BKR-914 (MODULES-3083) Fix modifying server roles for an existing login (MODULES-3256) Fix creating a login resource with additional attributes (MODULES-3256) Refactor sqlserver_login_spec acceptance test (MODULES-2554) Fix remove database (MODULES-2323) Fix deleting an SQL login (MODULES-3202) Fix install dependencies with custom source (MODULES-3256) Fix create/delete of Windows based logins (MODULES-3427) Allow multiple SYSADMIN role accounts (PA-285) Branding name change
2 parents 91df626 + ace9f91 commit 3b54488

File tree

16 files changed

+610
-298
lines changed

16 files changed

+610
-298
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,10 @@ Installs and configures features such as SSMS and Master Data Service.
204204

205205
* `pid`: *Optional.* Supplies a product key to configure which edition of SQL Server to use. Valid options: a string containing a valid product key. Default: undef (if not specified, SQL Server runs in Evaluation mode).
206206

207+
* `source`: *Required.* Locates the SQL Server installer. Valid options: a string containing the path to an executable. Puppet must have permission to execute the installer.
208+
209+
* `windows_feature_source`: *Optional.* Specifies the location of the Windows Feature source files. This may be needed to install the .Net Framework. See https://support.microsoft.com/en-us/kb/2734782 for more information.
210+
207211
Please note that if an option is set in both its own specific parameter and `install_switches`, the specifically named parameter takes precedence. For example, if you set the product key in both `pid` and in `install_switches`, SQL Server honors the `pid` parameter.
208212

209213
For more information about installer switches and configuring SQL Server, see the links below:
@@ -259,6 +263,8 @@ Installs and configures a SQL Server instance.
259263

260264
* `sql_sysadmin_accounts`: *Required.* Specifies one or more SQL or system accounts to receive sysadmin status. Valid options: an array containing one or more valid usernames.
261265

266+
* `windows_feature_source`: *Optional.* Specifies the location of the Windows Feature source files. This may be needed to install the .Net Framework. See https://support.microsoft.com/en-us/kb/2734782 for more information.
267+
262268
Please note that if an option is set in both its own specific parameter and `install_switches`, the specifically named parameter takes precedence. For example, if you set the product key in both `pid` and in `install_switches`, SQL Server honors the `pid` parameter.
263269

264270
For more information about installer switches and configuring SQL Server, see the links below:

lib/puppet/provider/sqlserver.rb

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,32 @@ def not_nil_and_not_empty?(obj)
3939
!obj.nil? and !obj.empty?
4040
end
4141

42-
def self.run_install_dot_net
43-
install_dot_net = <<-DOTNET
44-
Install-WindowsFeature NET-Framework-Core
42+
def self.run_install_dot_net(source_location = nil)
43+
if (!source_location.nil?)
44+
warn("The specified windows_source_location directory for sqlserver of \"#{source_location}\" does not exist") unless Puppet::FileSystem.directory?(source_location)
45+
end
4546

46-
Write-Host "Installing .Net Framework 3.5, do not close this prompt..."
47-
DISM /Online /Enable-Feature /FeatureName:NetFx3 /All /LimitAccess /Source:$LocalSource | Out-Null
47+
install_dot_net = <<-DOTNET
4848
$Result = Dism /online /Get-featureinfo /featurename:NetFx3
4949
If($Result -contains "State : Enabled")
5050
{
51-
Write-Host "Install .Net Framework 3.5 successfully."
51+
Write-Host ".Net Framework 3.5 is already installed."
5252
}
5353
Else
5454
{
55-
Write-Host "Failed to install Install .Net Framework 3.5,please make sure the local source is correct."
55+
Write-Host "Installing .Net Framework 3.5, do not close this prompt..."
56+
DISM /Online /Enable-Feature /FeatureName:NetFx3 /All /NoRestart /Quiet /LimitAccess #{ "/Source:\"#{source_location}\"" unless source_location.nil? } | Out-Null
57+
$Result = Dism /online /Get-featureinfo /featurename:NetFx3
58+
If($Result -contains "State : Enabled")
59+
{
60+
Write-Host "Install .Net Framework 3.5 successfully."
61+
}
62+
Else
63+
{
64+
Write-Host "Failed to install Install .Net Framework 3.5#{ ", please make sure the windows_feature_source is correct" unless source_location.nil?}."
65+
}
5666
}
57-
DOTNET
67+
DOTNET
5868
powershell([install_dot_net])
5969
end
6070
end

lib/puppet/provider/sqlserver_features/mssql.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,16 @@ def create_temp_for_install_switch
9999
return nil
100100
end
101101

102-
def installNet35
103-
result = Puppet::Provider::Sqlserver.run_install_dot_net
102+
def installNet35(source_location = nil)
103+
result = Puppet::Provider::Sqlserver.run_install_dot_net(source_location)
104104
end
105105

106106
def create
107107
if @resource[:features].empty?
108108
warn "Uninstalling all sql server features not tied into an instance because an empty array was passed, please use ensure absent instead."
109109
destroy
110110
else
111-
installNet35
111+
installNet35(@resource[:windows_feature_source])
112112
debug "Installing features #{@resource[:features]}"
113113
add_features(@resource[:features])
114114
@property_hash[:features] = @resource[:features]

lib/puppet/provider/sqlserver_instance/mssql.rb

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,16 @@ def modify_features(features, action)
5757
end
5858
end
5959

60-
def installNet35
61-
result = Puppet::Provider::Sqlserver.run_install_dot_net
60+
def installNet35(source_location = nil)
61+
result = Puppet::Provider::Sqlserver.run_install_dot_net(source_location)
6262
end
6363

6464
def create
6565
if @resource[:features].empty?
6666
warn "Uninstalling all features for instance #{@resource[:name]} because an empty array was passed, please use ensure absent instead."
6767
destroy
6868
else
69-
installNet35
69+
installNet35(@resource[:windows_feature_source])
7070
add_features(@resource[:features])
7171
# cmd_args = build_cmd_args(@resource[:features])
7272
# begin
@@ -125,16 +125,32 @@ def build_cmd_args(features, action="install")
125125
end
126126
end
127127

128-
format_cmd_args_array('/SQLSYSADMINACCOUNTS', @resource[:sql_sysadmin_accounts], cmd_args)
128+
format_cmd_args_array('/SQLSYSADMINACCOUNTS', @resource[:sql_sysadmin_accounts], cmd_args, true)
129129
format_cmd_args_array('/ASSYSADMINACCOUNTS', @resource[:as_sysadmin_accounts], cmd_args)
130130
end
131131
cmd_args
132132
end
133133

134-
def format_cmd_args_array(switch, arr, cmd_args)
134+
def format_cmd_args_array(switch, arr, cmd_args, use_discrete = false)
135135
if not_nil_and_not_empty? arr
136136
arr = [arr] if !arr.kind_of?(Array)
137-
cmd_args << "#{switch}=#{arr.collect { |item| "\"#{item}\"" }.join(' ')}"
137+
138+
# The default action is to join the array elements with a space ' ' so the cmd_args ends up like;
139+
# ["/SWITCH=\"Element1\" \"Element2\""]
140+
# Whereas if use_discrete is set, the args are appended as discrete elements in the cmd_args array e.g.;
141+
# ["/SWITCH=\"Element1\"","\"Element2\""]
142+
143+
if use_discrete
144+
arr.map.with_index { |var,i|
145+
if i == 0
146+
cmd_args << "#{switch}=\"#{var}\""
147+
else
148+
cmd_args << "\"#{var}\""
149+
end
150+
}
151+
else
152+
cmd_args << "#{switch}=#{arr.collect { |item| "\"#{item}\"" }.join(' ')}"
153+
end
138154
end
139155
end
140156

lib/puppet/type/sqlserver_features.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414

1515
newparam(:source)
1616

17+
newparam(:windows_feature_source) do
18+
desc 'Specify the location of the Windows Feature source files. This may be needed to install the .Net Framework.
19+
See https://support.microsoft.com/en-us/kb/2734782 for more information.'
20+
end
21+
1722
newparam(:pid) do
1823
desc 'Specify the SQL Server product key to configure which edition you would like to use.'
1924

lib/puppet/type/sqlserver_instance.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515

1616
end
1717

18+
newparam(:windows_feature_source) do
19+
desc 'Specify the location of the Windows Feature source files. This may be needed to install the .Net Framework.
20+
See https://support.microsoft.com/en-us/kb/2734782 for more information.'
21+
end
22+
1823
newparam(:pid) do
1924
desc 'Specify the SQL Server product key to configure which edition you would like to use.'
2025

spec/acceptance/sqlserver_database_spec.rb

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ def run_sql_query_opts (query, expected_row_count)
2929
end
3030

3131
after(:each) do
32-
3332
# delete created database:
34-
3533
pp = <<-MANIFEST
3634
sqlserver::config{'MSSQLSERVER':
3735
admin_user => 'sa',
@@ -41,8 +39,7 @@ def run_sql_query_opts (query, expected_row_count)
4139
ensure => 'absent',
4240
}
4341
MANIFEST
44-
#comment out the below line because of ticket MODULES-2554.
45-
#ensure_sqlserver_database(host, pp)
42+
ensure_sqlserver_database(host, pp)
4643
end
4744

4845
it "Test Case C89019: Create a database" do
@@ -67,6 +64,37 @@ def run_sql_query_opts (query, expected_row_count)
6764
run_sql_query(host, run_sql_query_opts(query, 1))
6865
end
6966

67+
it "Delete a database" do
68+
pp = <<-MANIFEST
69+
sqlserver::config{'MSSQLSERVER':
70+
admin_user => 'sa',
71+
admin_pass => 'Pupp3t1@',
72+
}
73+
sqlserver::database{'#{@db_name}':
74+
}
75+
MANIFEST
76+
ensure_sqlserver_database(host, pp)
77+
78+
puts "Validate the Database '#{@db_name}' exists"
79+
query = "SELECT database_id from sys.databases WHERE name = '#{@db_name}';"
80+
run_sql_query(host, run_sql_query_opts(query, 1))
81+
82+
pp = <<-MANIFEST
83+
sqlserver::config{'MSSQLSERVER':
84+
admin_user => 'sa',
85+
admin_pass => 'Pupp3t1@',
86+
}
87+
sqlserver::database{'#{@db_name}':
88+
ensure => absent,
89+
}
90+
MANIFEST
91+
ensure_sqlserver_database(host, pp)
92+
93+
puts "Validate the Database '#{@db_name}' does not exist"
94+
query = "SELECT database_id from sys.databases WHERE name = '#{@db_name}';"
95+
run_sql_query(host, run_sql_query_opts(query, 0))
96+
end
97+
7098
it "Test Case C89076: Create database with optional collation_name" do
7199
pp = <<-MANIFEST
72100
sqlserver::config{'MSSQLSERVER':

spec/acceptance/sqlserver_instance_spec.rb

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,16 @@ def new_random_instance_name
1111
describe "sqlserver_instance", :node => host do
1212
version = host['sql_version'].to_s
1313

14-
15-
def ensure_sqlserver_instance(host, features, inst_name, ensure_val = 'present')
14+
def ensure_sqlserver_instance(host, features, inst_name, ensure_val = 'present', sysadmin_accounts = "['Administrator']")
1615
manifest = <<-MANIFEST
1716
sqlserver_instance{'#{inst_name}':
1817
name => '#{inst_name}',
1918
ensure => <%= ensure_val %>,
2019
source => 'H:',
20+
security_mode => 'SQL',
21+
sa_pwd => 'Pupp3t1@',
2122
features => [ <%= mssql_features %> ],
22-
sql_sysadmin_accounts => ['Administrator'],
23+
sql_sysadmin_accounts => #{sysadmin_accounts},
2324
agt_svc_account => 'Administrator',
2425
agt_svc_password => 'Qu@lity!',
2526
}
@@ -34,18 +35,69 @@ def ensure_sqlserver_instance(host, features, inst_name, ensure_val = 'present')
3435
end
3536
end
3637

38+
#Return options for run_sql_query
39+
def run_sql_query_opts (inst_name, query, expected_row_count)
40+
run_sql_query_opt = {
41+
:query => query,
42+
:instance => inst_name,
43+
:server => '.',
44+
:sql_admin_user => 'sa',
45+
:sql_admin_pass => 'Pupp3t1@',
46+
:expected_row_count => expected_row_count,
47+
}
48+
end
49+
50+
def sql_query_is_user_sysadmin(username)
51+
<<-QUERY
52+
Select [Name]
53+
FROM SYS.Server_Principals
54+
WHERE (type = 'S' or type = 'U')
55+
AND [Name] like '%\\#{username}'
56+
AND is_disabled = 0 AND IS_SRVROLEMEMBER('sysadmin', name) = 1;
57+
QUERY
58+
end
59+
3760
context "Create an instance", {:testrail => ['88978', '89028', '89031', '89043', '89061']} do
61+
62+
before(:context) do
63+
@ExtraAdminUser = 'ExtraSQLAdmin'
64+
pp = <<-MANIFEST
65+
user { '#{@ExtraAdminUser}':
66+
ensure => present,
67+
password => 'Puppet01!',
68+
}
69+
MANIFEST
70+
apply_manifest_on(host,pp)
71+
end
72+
73+
after(:context) do
74+
pp = <<-MANIFEST
75+
user { '#{@ExtraAdminUser}':
76+
ensure => absent,
77+
}
78+
MANIFEST
79+
apply_manifest_on(host,pp)
80+
end
81+
3882
inst_name = new_random_instance_name
3983
features = ['SQL', 'SQLEngine', 'Replication', 'FullText', 'DQ']
4084

4185
it "create #{inst_name} instance" do
42-
ensure_sqlserver_instance(host, features, inst_name)
86+
ensure_sqlserver_instance(host, features, inst_name,'present',"['Administrator','ExtraSQLAdmin']")
4387

4488
validate_sql_install(host, {:version => version}) do |r|
4589
expect(r.stdout).to match(/#{Regexp.new(inst_name)}/)
4690
end
4791
end
4892

93+
it "#{inst_name} instance has Administrator as a sysadmin" do
94+
run_sql_query(host, run_sql_query_opts(inst_name, sql_query_is_user_sysadmin('Administrator'), expected_row_count = 1))
95+
end
96+
97+
it "#{inst_name} instance has ExtraSQLAdmin as a sysadmin" do
98+
run_sql_query(host, run_sql_query_opts(inst_name, sql_query_is_user_sysadmin('ExtraSQLAdmin'), expected_row_count = 1))
99+
end
100+
49101
it "remove #{inst_name} instance" do
50102
ensure_sqlserver_instance(host, features, inst_name, 'absent')
51103

0 commit comments

Comments
 (0)