Skip to content

Commit 477c65e

Browse files
jordanbreen28jordanbreen28
jordanbreen28
authored andcommitted
Fix acceptance tests
1 parent f4f9cc8 commit 477c65e

16 files changed

+81
-66
lines changed

lib/puppet/provider/sqlserver.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ class Puppet::Provider::Sqlserver < Puppet::Provider # rubocop:disable Style/Doc
1919
end
2020

2121
def try_execute(command, msg = nil, obfuscate_strings = nil, acceptable_exit_codes = [0])
22-
res = execute(command.compact, failonfail: false)
22+
command&.compact
23+
res = execute(command, failonfail: false)
2324

2425
unless acceptable_exit_codes.include?(res.exitstatus)
2526
msg = "Failure occured when trying to install SQL Server #{@resource[:name]}" if msg.nil?

lib/puppet/provider/sqlserver_features/mssql.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ def modify_features(action, features)
6565
'/IACCEPTSQLSERVERLICENSETERMS',
6666
"/FEATURES=#{features.join(',')}"]
6767
if action == 'install'
68+
cmd_args << '/UPDATEENABLED=False'
6869
if not_nil_and_not_empty?(@resource[:is_svc_account])
6970
cmd_args << "/ISSVCACCOUNT=#{@resource[:is_svc_account]}"
7071
end

lib/puppet/provider/sqlserver_instance/mssql.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ def modify_features(features, action)
6868
begin
6969
config_file = create_temp_for_install_switch unless action == 'uninstall'
7070
cmd_args << "/ConfigurationFile=\"#{config_file.path}\"" unless config_file.nil?
71+
cmd_args << '/UPDATEENABLED=False' if action == 'install'
7172
res = try_execute(cmd_args, "Error trying to #{action} features (#{features.join(', ')}", obfuscated_strings, [0, 1641, 3010])
7273

7374
warn("#{action} of features (#{features.join(', ')}) returned exit code 3010 - reboot required") if res.exitstatus == 3010
@@ -142,6 +143,8 @@ def basic_cmd_args(features, action)
142143
'/IACCEPTSQLSERVERLICENSETERMS',
143144
"/INSTANCENAME=#{@resource[:name]}"]
144145
cmd_args << "/FEATURES=#{features.join(',')}" unless features.empty?
146+
cmd_args << '/UPDATEENABLED=False' if action == 'install'
147+
cmd_args
145148
end
146149

147150
def build_cmd_args(features, action = 'install')

lib/puppet_x/sqlserver/features.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def self.get_shared_features(version)
149149
'SDK_Full' => 'SDK', # Client Tools SDK
150150
'MDSCoreFeature' => 'MDS', # Master Data Services
151151
'Tools_Legacy_Full' => 'BC', # Client Tools Backwards Compatibility
152-
'SQL_SSMS_Full' => 'ADV_SSMS', # Management Tools - Complete (Does not exist in SQL 2016)
152+
'SQL_SSMS_Full' => 'ADV_SSMS', # Management Tools - Complete (Does not exist in SQL 2016+)
153153
'SQL_SSMS_Adv' => 'SSMS', # Management Tools - Basic (Does not exist in SQL 2016)
154154
'SQL_DQ_CLIENT_Full' => 'DQC', # Data Quality Client
155155
'SQL_BOL_Components' => 'BOL', # Documentation Components

lib/puppet_x/sqlserver/sql_connection.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def open(config)
3131

3232
def get_connection_string(config)
3333
params = {
34-
'Provider' => 'SQLNCLI11',
34+
'Provider' => 'MSOLEDBSQL',
3535
'Initial Catalog' => config[:database] || 'master',
3636
'Application Name' => 'Puppet',
3737
'Data Source' => '.',
@@ -50,8 +50,8 @@ def get_connection_string(config)
5050
# SQL Server based authentication
5151
raise ArgumentError, _('admin_user must not be empty or nil') unless admin_user != ''
5252
raise ArgumentError, _('admin_pass must not be empty or nil') unless admin_pass != ''
53-
params.store('User ID', admin_user)
54-
params.store('Password', admin_pass)
53+
params.store('UID', admin_user)
54+
params.store('PWD', admin_pass)
5555
end
5656

5757
if !config[:instance_name].nil? && config[:instance_name] !~ %r{^MSSQLSERVER$}

spec/acceptance/sqlserver_config_spec.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@ def ensure_sqlserver_instance(inst_name, ensure_val = 'present')
1616
ensure => '#{ensure_val}',
1717
source => 'H:',
1818
features => ['DQ', 'FullText', 'Replication', 'SQLEngine'],
19-
sql_sysadmin_accounts => ['Administrator'],
19+
sql_sysadmin_accounts => ['vagrant'],
2020
security_mode => 'SQL',
2121
sa_pwd => 'Pupp3t1@',
2222
windows_feature_source => 'I:\\sources\\sxs',
2323
}
2424
MANIFEST
25-
2625
apply_manifest(pp, catch_failures: true)
2726
end
2827

@@ -32,7 +31,7 @@ def ensure_sqlserver_instance(inst_name, ensure_val = 'present')
3231
ensure_sqlserver_instance(inst_name)
3332

3433
# get credentials for new config
35-
@admin_user = 'admin' + SecureRandom.hex(2)
34+
@admin_user = 'test_user' + SecureRandom.hex(2)
3635
@admin_pass = 'Pupp3t1@'
3736

3837
# get database user
@@ -62,7 +61,7 @@ def ensure_sqlserver_instance(inst_name, ensure_val = 'present')
6261
apply_manifest(pp, catch_failures: true)
6362
end
6463

65-
it 'Validate New Config WITH using instance_name in sqlserver::config' do
64+
it 'Validate New Config WITH instance_name in sqlserver::config' do
6665
pp = <<-MANIFEST
6766
sqlserver::config{'#{inst_name}':
6867
admin_user => Sensitive('#{@admin_user}'),
@@ -77,11 +76,11 @@ def ensure_sqlserver_instance(inst_name, ensure_val = 'present')
7776
end
7877

7978
it 'Validate new login and database actualy created' do
80-
hostname = ENV['TARGET_HOST']
79+
hostname = Helper.instance.run_shell('hostname').stdout.upcase.strip
8180
query = "USE #{db_name}; SELECT * from master..sysdatabases WHERE name = '#{db_name}'"
8281

8382
run_sql_query(query: query, server: hostname, instance: inst_name, \
84-
sql_admin_user: @admin_user, sql_admin_pass: @admin_pass, expected_row_count: 1)
83+
sql_admin_user: @admin_user, sql_admin_pass: @admin_pass, expected_row_count: 1)
8584
end
8685

8786
it 'Validate New Config WITHOUT using instance_name in sqlserver::config' do

spec/acceptance/sqlserver_database_spec.rb

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ def run_sql_query_opts(query, expected_row_count)
4747
}
4848
sqlserver_tsql{'testsqlserver_tsql':
4949
instance => 'MSSQLSERVER',
50-
database => '#{@db_name}',
51-
command => "CREATE TABLE #{@table_name} (id INT, name VARCHAR(20), email VARCHAR(20));",
50+
command => "use #{@db_name};CREATE TABLE #{@table_name} (id INT, name VARCHAR(20), email VARCHAR(20));",
5251
require => Sqlserver::Database['#{@db_name}'],
5352
}
5453
MANIFEST
@@ -101,8 +100,7 @@ def run_sql_query_opts(query, expected_row_count)
101100
}
102101
sqlserver_tsql{'testsqlserver_tsql':
103102
instance => 'MSSQLSERVER',
104-
database => '#{@db_name}',
105-
command => "CREATE TABLE #{@table_name} (id INT, name VARCHAR(20), email VARCHAR(20));",
103+
command => "use #{@db_name};CREATE TABLE #{@table_name} (id INT, name VARCHAR(20), email VARCHAR(20));",
106104
require => Sqlserver::Database['#{@db_name}'],
107105
}
108106
MANIFEST
@@ -132,8 +130,7 @@ def run_sql_query_opts(query, expected_row_count)
132130
}
133131
sqlserver_tsql{'testsqlserver_tsql':
134132
instance => 'MSSQLSERVER',
135-
database => '#{@db_name}',
136-
command => "CREATE TABLE #{@table_name} (id INT, name VARCHAR(20), email VARCHAR(20));",
133+
command => "use #{@db_name};CREATE TABLE #{@table_name} (id INT, name VARCHAR(20), email VARCHAR(20));",
137134
require => Sqlserver::Database['#{@db_name}'],
138135
}
139136
MANIFEST
@@ -170,8 +167,7 @@ def run_sql_query_opts(query, expected_row_count)
170167
}
171168
sqlserver_tsql{'testsqlserver_tsql':
172169
instance => 'MSSQLSERVER',
173-
database => '#{@db_name}',
174-
command => "CREATE TABLE #{@table_name} (id INT, name VARCHAR(20), email VARCHAR(20));",
170+
command => "use #{@db_name};CREATE TABLE #{@table_name} (id INT, name VARCHAR(20), email VARCHAR(20));",
175171
require => Sqlserver::Database['#{@db_name}'],
176172
}
177173
MANIFEST
@@ -209,8 +205,7 @@ def run_sql_query_opts(query, expected_row_count)
209205
}
210206
sqlserver_tsql{'testsqlserver_tsql':
211207
instance => 'MSSQLSERVER',
212-
database => '#{@db_name}',
213-
command => "CREATE TABLE #{@table_name} (id INT, name VARCHAR(20), email VARCHAR(20));",
208+
command => "use #{@db_name};CREATE TABLE #{@table_name} (id INT, name VARCHAR(20), email VARCHAR(20));",
214209
require => Sqlserver::Database['#{@db_name}'],
215210
}
216211
MANIFEST
@@ -248,8 +243,7 @@ def run_sql_query_opts(query, expected_row_count)
248243
}
249244
sqlserver_tsql{'testsqlserver_tsql':
250245
instance => 'MSSQLSERVER',
251-
database => '#{@db_name}',
252-
command => "CREATE TABLE #{@table_name} (id INT, name VARCHAR(20), email VARCHAR(20));",
246+
command => "use #{@db_name};CREATE TABLE #{@table_name} (id INT, name VARCHAR(20), email VARCHAR(20));",
253247
require => Sqlserver::Database['#{@db_name}'],
254248
}
255249
MANIFEST
@@ -287,8 +281,7 @@ def run_sql_query_opts(query, expected_row_count)
287281
}
288282
sqlserver_tsql{'testsqlserver_tsql':
289283
instance => 'MSSQLSERVER',
290-
database => '#{@db_name}',
291-
command => "CREATE TABLE #{@table_name} (id INT, name VARCHAR(20), email VARCHAR(20));",
284+
command => "use #{@db_name};CREATE TABLE #{@table_name} (id INT, name VARCHAR(20), email VARCHAR(20));",
292285
require => Sqlserver::Database['#{@db_name}'],
293286
}
294287
MANIFEST

spec/acceptance/sqlserver_instance_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def new_random_instance_name
1111
describe 'sqlserver_instance' do
1212
version = sql_version?
1313

14-
def ensure_sqlserver_instance(features, inst_name, ensure_val = 'present', sysadmin_accounts = "['Administrator']")
14+
def ensure_sqlserver_instance(features, inst_name, ensure_val = 'present', sysadmin_accounts = "['vagrant']")
1515
pp = <<-MANIFEST
1616
sqlserver_instance{'#{inst_name}':
1717
name => '#{inst_name}',
@@ -21,8 +21,8 @@ def ensure_sqlserver_instance(features, inst_name, ensure_val = 'present', sysad
2121
sa_pwd => 'Pupp3t1@',
2222
features => #{features},
2323
sql_sysadmin_accounts => #{sysadmin_accounts},
24-
agt_svc_account => 'Administrator',
25-
agt_svc_password => 'Qu@lity!',
24+
agt_svc_account => 'vagrant',
25+
agt_svc_password => 'vagrant',
2626
windows_feature_source => 'I:\\sources\\sxs',
2727
}
2828
MANIFEST
@@ -54,7 +54,7 @@ def sql_query_is_user_sysadmin(username)
5454
context 'Create an instance' do
5555
before(:context) do
5656
# Use a username with a space to test argument parsing works correctly
57-
@extra_admin_user = 'Extra SQLAdmin'
57+
@extra_admin_user = 'ExtraSQLAdmin'
5858
pp = <<-MANIFEST
5959
user { '#{@extra_admin_user}':
6060
ensure => present,
@@ -78,7 +78,7 @@ def sql_query_is_user_sysadmin(username)
7878

7979
it "create #{inst_name} instance" do
8080
host_computer_name = run_shell('CMD /C ECHO %COMPUTERNAME%').stdout.chomp
81-
ensure_sqlserver_instance(features, inst_name, 'present', "['Administrator','#{host_computer_name}\\#{@extra_admin_user}']")
81+
ensure_sqlserver_instance(features, inst_name, 'present', "['vagrant','#{host_computer_name}\\#{@extra_admin_user}']")
8282

8383
validate_sql_install(version: version) do |r|
8484
expect(r.stdout).to match(%r{#{Regexp.new(inst_name)}})

spec/acceptance/sqlserver_role_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
require 'securerandom'
55
require 'erb'
66

7-
hostname = ENV['TARGET_HOST']
7+
hostname = Helper.instance.run_shell('hostname').stdout.upcase.strip
88

99
# database name
1010
db_name = ('DB' + SecureRandom.hex(4)).upcase

spec/acceptance/sqlserver_user_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
require 'securerandom'
55
require 'erb'
66

7-
hostname = ENV['TARGET_HOST']
7+
hostname = Helper.instance.run_shell('hostname').stdout.upcase.strip
88

99
# database name
1010
db_name = ('DB' + SecureRandom.hex(4)).upcase

spec/acceptance/z_last_sqlserver_features_spec.rb

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,17 @@
88

99
describe 'sqlserver_features', if: version.to_i != 2012 do
1010
def ensure_sql_features(features, ensure_val = 'present')
11+
hostname = Helper.instance.run_shell('hostname').stdout.upcase.strip
1112
pp = <<-MANIFEST
1213
sqlserver::config{ 'MSSQLSERVER':
13-
admin_pass => '<%= SQL_ADMIN_PASS %>',
14-
admin_user => '<%= SQL_ADMIN_USER %>',
14+
admin_pass => '#{SQL_ADMIN_USER}',
15+
admin_user => '#{SQL_ADMIN_PASS}',
1516
}
1617
sqlserver_features{ 'MSSQLSERVER':
1718
ensure => #{ensure_val},
1819
source => 'H:',
19-
is_svc_account => "$::hostname\\\\Administrator",
20-
is_svc_password => 'Qu@lity!',
20+
is_svc_account => "#{hostname}\\\\vagrant",
21+
is_svc_password => 'vagrant',
2122
features => #{features},
2223
windows_feature_source => 'I:\\sources\\sxs',
2324
}
@@ -27,15 +28,17 @@ def ensure_sql_features(features, ensure_val = 'present')
2728
end
2829

2930
def bind_and_apply_failing_manifest(features, ensure_val = 'present')
31+
hostname = Helper.instance.run_shell('hostname').stdout.upcase.strip
3032
pp = <<-MANIFEST
3133
sqlserver::config{ 'MSSQLSERVER':
32-
admin_pass => '<%= SQL_ADMIN_PASS %>',
33-
admin_user => '<%= SQL_ADMIN_USER %>',
34+
admin_pass => '#{SQL_ADMIN_USER}',
35+
admin_user => '#{SQL_ADMIN_PASS}',
3436
}
3537
sqlserver_features{ 'MSSQLSERVER':
3638
ensure => #{ensure_val},
3739
source => 'H:',
38-
is_svc_account => "$::hostname\\\\Administrator",
40+
is_svc_account => "#{hostname}\\\\vagrant",
41+
is_svc_password => 'vagrant',
3942
features => #{features},
4043
}
4144
MANIFEST
@@ -136,7 +139,7 @@ def bind_and_apply_failing_manifest(features, ensure_val = 'present')
136139
bind_and_apply_failing_manifest(features)
137140
end
138141

139-
it 'fails when ADV_SSMS is supplied but SSMS is not - FM-2712' do
142+
it 'fails when ADV_SSMS is supplied but SSMS is not - FM-2712', unless: version.to_i >= 2016 do
140143
pending('error not shown on Sql Server 2014') if version .to_i == 2014
141144
features = ['BC', 'Conn', 'ADV_SSMS', 'SDK']
142145
bind_and_apply_failing_manifest(features)
@@ -153,7 +156,7 @@ def remove_sql_instance
153156
sqlserver_instance{'MSSQLSERVER':
154157
ensure => absent,
155158
source => 'H:',
156-
sql_sysadmin_accounts => ['Administrator'],
159+
sql_sysadmin_accounts => ['vagrant'],
157160
}
158161
MANIFEST
159162
idempotent_apply(pp)
@@ -171,7 +174,7 @@ def remove_sql_instance
171174
ensure_sql_features(features)
172175

173176
validate_sql_install(version: version) do |r|
174-
# SQL Server 2016 will not install the client tools features.
177+
# SQL Server 2016+ will not install the client tools features.
175178
expect(r.stdout).not_to match(%r{MSSQLSERVER\s+Database Engine Services})
176179
expect(r.stdout).not_to match(%r{MSSQLSERVER\s+SQL Server Replication})
177180
expect(r.stdout).not_to match(%r{MSSQLSERVER\s+Data Quality Services})

0 commit comments

Comments
 (0)