Skip to content
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

(MODULES-2386) Using as_sysadmin_accounts without AS feature should error #220

Merged
merged 1 commit into from Jun 21, 2017
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/puppet/provider/sqlserver_instance/mssql.rb
Expand Up @@ -71,6 +71,10 @@ def create
warn "Uninstalling all features for instance #{@resource[:name]} because an empty array was passed, please use ensure absent instead."
destroy
else
unless @resource[:as_sysadmin_accounts].nil? || @resource[:features].include?('AS')
fail('The parameter as_sysadmin_accounts was specified however the AS feature was not included in the installed features. Either remove the as_sysadmin_accounts parameter or add AS as a feature to the instance.')
end

instance_version = PuppetX::Sqlserver::ServerHelper.sql_version_from_install_source(@resource[:source])
Puppet.debug("Installation source detected as version #{instance_version}") unless instance_version.nil?

Expand Down
51 changes: 51 additions & 0 deletions spec/unit/puppet/provider/sqlserver_instance_spec.rb
Expand Up @@ -90,6 +90,45 @@ def stub_uninstall(args, installed_features, exit_code = 0)
}
end

shared_examples 'create_failure' do |exit_code, error_matcher|
it {
execute_args = args.merge(munged_values)
@resource = Puppet::Type::Sqlserver_instance.new(args)
@provider = provider_class.new(@resource)

stub_powershell_call(subject)
stub_source_which_call args[:source]

cmd_args = ["#{execute_args[:source]}/setup.exe",
"/ACTION=install",
'/Q',
'/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 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

# wrap each arg in doublequotes
admin_args = execute_args[:sql_sysadmin_accounts].map { |a| "\"#{a}\"" }
# prepend first arg only with CLI switch
admin_args[0] = "/SQLSYSADMINACCOUNTS=" + admin_args[0]
cmd_args += admin_args

additional_install_switches.each do |switch|
cmd_args << switch
end

@provider.stubs(:warn).with(anything).times(0)

result = Puppet::Util::Execution::ProcessOutput.new('', exit_code || 0)
Puppet::Util::Execution.stubs(:execute).with(cmd_args.compact, failonfail: false).returns(result)
expect{ @provider.create }.to raise_error(error_matcher)
}
end

shared_examples 'destroy' do |exit_code, warning_matcher|
it {
Expand Down Expand Up @@ -127,6 +166,18 @@ def stub_uninstall(args, installed_features, exit_code = 0)
end
end

describe 'it should raise error if as_sysadmin_accounts is specified without AS feature' do
it_behaves_like 'create_failure', 1, /as_sysadmin_accounts was specified however the AS feature was not included/i do
args = get_basic_args
args[:features] = ['SQLEngine']
args[:as_sysadmin_accounts] = 'username'

let(:args) { args }
munged = {:features => Array.new(args[:features])}
let(:munged_values) { munged }
end
end

describe 'it should raise warning on install when 1641 exit code returned' do
it_behaves_like 'create', 1641, /reboot initiated/i do
args = get_basic_args
Expand Down