Skip to content

Commit f3d087f

Browse files
committed
(MODULES-11567): Enhance validation methods to resolve deferred values for validation in sqlserver_instance type
1 parent 4c3e5fb commit f3d087f

File tree

6 files changed

+76
-9
lines changed

6 files changed

+76
-9
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ jobs:
6969
with:
7070
ref: ${{ github.event.pull_request.head.sha }}
7171

72-
- name: Activate Ruby 2.7
72+
- name: Activate Ruby 3.2
7373
uses: ruby/setup-ruby@v1
7474
with:
75-
ruby-version: "2.7"
75+
ruby-version: "3.2"
7676
bundler-cache: true
7777

7878
- name: Print bundle environment
@@ -93,7 +93,7 @@ jobs:
9393
run: |
9494
bundle exec rake 'litmus:install_module'
9595
96-
- name: Authenitcate with GCP
96+
- name: Authenticate with GCP
9797
run: |
9898
echo '${{ secrets.GCP_CONNECTION }}' >> creds.json
9999
bundle exec bolt file upload creds.json C:\\creds.json --targets ssh_nodes --inventoryfile spec/fixtures/litmus_inventory.yaml
@@ -114,7 +114,7 @@ jobs:
114114
115115
- name: Run acceptance tests
116116
run: |
117-
bundle exec rake 'litmus:acceptance:parallel'
117+
timeout 60m bundle exec rake 'litmus:acceptance:parallel' --trace
118118
119119
- name: Remove test environment
120120
if: ${{ always() }}

.github/workflows/nightly.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ jobs:
6767
with:
6868
ref: ${{ github.event.pull_request.head.sha }}
6969

70-
- name: Activate Ruby 2.7
70+
- name: Activate Ruby 3.2
7171
uses: ruby/setup-ruby@v1
7272
with:
73-
ruby-version: "2.7"
73+
ruby-version: "3.2"
7474
bundler-cache: true
7575

7676
- name: Print bundle environment

lib/puppet/type/sqlserver_instance.rb

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ def validate
131131
end
132132

133133
def set?(key)
134-
!self[key].nil? && !self[key].empty?
134+
self_key = resolve_deferred_value(self[key])
135+
!self_key.nil? && !self_key.empty?
135136
end
136137

137138
def validate_user_password_required(account, pass)
@@ -144,11 +145,11 @@ def validate_user_password_required(account, pass)
144145
end
145146

146147
def domain_or_local_user?(user)
147-
PuppetX::Sqlserver::ServerHelper.is_domain_or_local_user?(user, Facter.value(:hostname))
148+
PuppetX::Sqlserver::ServerHelper.is_domain_or_local_user?(resolve_deferred_value(user), Facter.value(:hostname))
148149
end
149150

150151
def strong_password?(key)
151-
password = self[key]
152+
password = resolve_deferred_value(self[key])
152153
return unless password
153154

154155
message_start = "Password for #{key} is not strong"
@@ -162,4 +163,12 @@ def strong_password?(key)
162163

163164
true
164165
end
166+
167+
# When preprocess_deferred is false, deferred values remain unresolved at the time of validation, causing it to fail.
168+
# To address this, following logic is added to explicitly resolve deferred values during validation
169+
def resolve_deferred_value(value)
170+
return value unless value.is_a?(Puppet::Pops::Evaluator::DeferredValue)
171+
172+
value.resolve
173+
end
165174
end

spec/acceptance/sqlserver_instance_spec.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,35 @@ def sql_query_is_user_sysadmin(username)
134134
end
135135
end
136136
end
137+
138+
# Ensure that the instance can be created with deferred values
139+
# for service account and password, which are resolved at the time of
140+
# the instance creation.
141+
# This is useful for scenarios where the values are not known at the time
142+
# of the Puppet run, such as when using Hiera to fetch values from a
143+
# secure vault or when the values are dynamically generated.
144+
# def ensure_sqlserver_instance_with_deferred_values
145+
# inst_name = new_random_instance_name
146+
147+
# pp = <<-MANIFEST
148+
# sqlserver_instance{'#{inst_name}':
149+
# agt_svc_account => Deferred('pick', ['nexus\\travis']),
150+
# agt_svc_password => Deferred('pick', ['Hunter-2']),
151+
# }
152+
# MANIFEST
153+
154+
# idempotent_apply(pp)
155+
# end
156+
157+
# context 'Deferred values' do
158+
# it 'validate deferred values' do
159+
# expect { ensure_sqlserver_instance_with_deferred_values }.not_to raise_error
160+
# end
161+
162+
# it 'apply deferred values' do
163+
# ensure_sqlserver_instance_with_deferred_values
164+
165+
# run_sql_query(run_sql_query_opts('MSSQLSERVER', sql_query_is_user_sysadmin('nexus\\travis'), 1))
166+
# end
167+
# end
137168
end

spec/spec_helper_acceptance_local.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ def node_vars?
6565

6666
def sql_version?
6767
vars = node_vars?
68+
puts "-----------------------Vars: #{vars}------------------------"
6869
return vars['sqlversion'].match(%r{sqlserver_(.*)})[1] if !vars.nil? && (vars['sqlversion'])
6970

7071
# Return's a default version if none was given
@@ -75,6 +76,7 @@ def sql_version?
7576
# OS iso mounts to I drive
7677
# SQL iso mounts to H drive
7778
def mount_iso(opts = {})
79+
puts "--------------------opts: #{opts}--------------------"
7880
folder = opts[:folder]
7981
file = opts[:file]
8082
drive_letter = opts[:drive_letter]
@@ -99,6 +101,7 @@ def mount_iso(opts = {})
99101
end
100102

101103
def base_install(sql_version)
104+
puts "--------------SQL version: #{sql_version.to_i}-----------------"
102105
case sql_version.to_i
103106
when 2014
104107
iso_opts = {

spec/unit/puppet/type/sqlserver_instance_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,28 @@
8484
end
8585
end
8686
end
87+
88+
describe 'agt_svc_account' do
89+
context 'when value is a deferred value' do
90+
let(:args) do
91+
basic_args.merge({ agt_svc_account: Puppet::Pops::Evaluator::DeferredValue.new(proc { 'nexus\\travis' }) })
92+
end
93+
94+
it 'validate' do
95+
subject = Puppet::Type.type(:sqlserver_instance).new(args)
96+
expect(subject.resolve_deferred_value(subject[:agt_svc_account])).to eq('nexus\\travis')
97+
end
98+
end
99+
100+
context 'when value is not a deferred value' do
101+
let(:args) do
102+
basic_args.merge({ agt_svc_account: 'nexus\\travis' })
103+
end
104+
105+
it 'validate' do
106+
subject = Puppet::Type.type(:sqlserver_instance).new(args)
107+
expect(subject.resolve_deferred_value(subject[:agt_svc_account])).to eq('nexus\\travis')
108+
end
109+
end
110+
end
87111
end

0 commit comments

Comments
 (0)