Skip to content

Commit aa2307e

Browse files
Fixing some more test cases
Signed-off-by: paragchak-sumo <[email protected]>
1 parent 7bd4897 commit aa2307e

File tree

11 files changed

+339
-57
lines changed

11 files changed

+339
-57
lines changed

.fixtures.yml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,48 +2,48 @@ fixtures:
22
repositories:
33
apt:
44
repo: https://github.com/puppetlabs/puppetlabs-apt.git
5-
ref: 5.0.1
5+
ref: 9.1.0
66
stdlib:
77
repo: https://github.com/puppetlabs/puppetlabs-stdlib.git
8-
ref: 5.1.0
8+
ref: 9.3.0
99
datacat:
1010
repo: https://github.com/richardc/puppet-datacat.git
1111
ref: 0.6.2
1212
yumrepo_core:
1313
repo: https://github.com/puppetlabs/puppetlabs-yumrepo_core
14-
ref: 1.0.1
14+
ref: 2.0.0
1515
puppet_version: ">= 6.0.0"
1616
chocolatey:
1717
repo: https://github.com/puppetlabs/puppetlabs-chocolatey.git
18-
ref: 3.0.0
18+
ref: 8.0.0
1919
# Needed by chocolatey
2020
registry:
2121
repo: https://github.com/puppetlabs/puppetlabs-registry.git
22-
ref: 1.0.0
22+
ref: 5.0.1
2323
# Needed by chocolatey
2424
powershell:
2525
repo: https://github.com/puppetlabs/puppetlabs-powershell.git
26-
ref: 1.0.1
26+
ref: 6.0.0
2727
# Need by postgresql
2828
augeas_core:
2929
repo: https://github.com/puppetlabs/puppetlabs-augeas_core
30-
ref: 1.0.4
30+
ref: 1.3.0
3131
puppet_version: ">= 6.0.0"
3232
# Need by postgresql
3333
concat:
3434
repo: https://github.com/puppetlabs/puppetlabs-concat.git
35-
ref: v6.0.0
35+
ref: 9.0.0
3636
postgresql:
3737
repo: https://github.com/puppetlabs/puppetlabs-postgresql.git
38-
ref: v6.4.0
38+
ref: 9.1.0
3939
archive:
4040
repo: https://github.com/voxpupuli/puppet-archive.git
41-
ref: 'v3.0.0'
41+
ref: 7.0.0
4242
windows_env:
4343
repo: https://github.com/voxpupuli/puppet-windows_env.git
44-
ref: 'v3.0.0'
44+
ref: 5.0.0
4545
systemd:
4646
repo: https://github.com/camptocamp/puppet-systemd.git
47-
ref: '2.0.0'
47+
ref: 5.2.0
4848
symlinks:
4949
sensu: "#{source_dir}"

.github/workflows/acceptance-cluster.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ jobs:
1717
puppet:
1818
- puppet6
1919
- puppet7
20+
- puppet8
2021
use_agent:
2122
- no
2223
- yes
@@ -30,7 +31,7 @@ jobs:
3031
- name: Setup ruby
3132
uses: ruby/setup-ruby@v1
3233
with:
33-
ruby-version: '3.2.2'
34+
ruby-version: '3.1.4'
3435
bundler-cache: true
3536
bundler: '2.4.10'
3637
- name: Decrypt secrets
@@ -41,8 +42,9 @@ jobs:
4142
- name: Run tests
4243
run: bundle exec rake acceptance
4344
env:
45+
RUN_ACCEPTANCE: 1
4446
BEAKER_PUPPET_COLLECTION: ${{ matrix.puppet }}
45-
BEAKER_set: centos-7-cluster
47+
BEAKER_set: rocky-8-cluster
4648
BEAKER_sensu_mode: cluster
4749
BEAKER_sensu_use_agent: ${{ matrix.use_agent }}
4850
BEAKER_sensu_ci_build: ${{ matrix.ci_build }}

.github/workflows/acceptance-full.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ jobs:
2222
puppet:
2323
- puppet6
2424
- puppet7
25+
- puppet8
2526
use_agent:
2627
- no
2728
ci_build:
@@ -37,6 +38,10 @@ jobs:
3738
ci_build: no
3839
- sensu_mode: bolt
3940
puppet: puppet6
41+
- sensu_mode: types
42+
puppet: puppet8
43+
use_agent: yes
44+
ci_build: no
4045
env:
4146
BEAKER_debug: true
4247
name: ${{ matrix.set }} ${{ matrix.puppet }} (mode=${{ matrix.sensu_mode }} use-agent=${{ matrix.use_agent }} CI=${{ matrix.ci_build }})
@@ -45,7 +50,7 @@ jobs:
4550
- name: Setup ruby
4651
uses: ruby/setup-ruby@v1
4752
with:
48-
ruby-version: '3.2.2'
53+
ruby-version: '3.1.4'
4954
bundler-cache: true
5055
bundler: '2.4.10'
5156
- name: Decrypt secrets
@@ -56,6 +61,7 @@ jobs:
5661
- name: Run tests
5762
run: bundle exec rake acceptance
5863
env:
64+
RUN_ACCEPTANCE: 1
5965
BEAKER_PUPPET_COLLECTION: ${{ matrix.puppet }}
6066
BEAKER_set: centos-7
6167
BEAKER_sensu_mode: ${{ matrix.sensu_mode }}

.github/workflows/acceptance.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,18 @@ jobs:
2020
- ubuntu-1804
2121
- ubuntu-2004
2222
- amazonlinux-201803
23+
- centos-7
2324
puppet:
2425
- puppet6
2526
- puppet7
27+
- puppet8
2628
ci_build:
2729
- no
2830
exclude:
2931
- puppet: puppet7
3032
ci_build: yes
33+
- puppet: puppet8
34+
ci_build: yes
3135
env:
3236
BEAKER_debug: true
3337
name: ${{ matrix.set }} ${{ matrix.puppet }} (ci=${{ matrix.ci_build }})
@@ -36,7 +40,7 @@ jobs:
3640
- name: Setup ruby
3741
uses: ruby/setup-ruby@v1
3842
with:
39-
ruby-version: '3.2.2'
43+
ruby-version: '3.1.4'
4044
bundler-cache: true
4145
bundler: '2.4.10'
4246
- name: Decrypt secrets
@@ -47,6 +51,7 @@ jobs:
4751
- name: Run tests
4852
run: bundle exec rake acceptance
4953
env:
54+
RUN_ACCEPTANCE: 1
5055
BEAKER_PUPPET_COLLECTION: ${{ matrix.puppet }}
5156
BEAKER_set: ${{ matrix.set }}
5257
BEAKER_sensu_ci_build: ${{ matrix.ci_build }}

.github/workflows/release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- name: Setup Ruby
1919
uses: ruby/setup-ruby@v1
2020
with:
21-
ruby-version: '3.2.2'
21+
ruby-version: '3.1.4'
2222
bundler-cache: true
2323
bundler: '2.4.10'
2424
- name: Build and Deploy

.github/workflows/unit.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,18 @@ jobs:
1616
fail-fast: false
1717
matrix:
1818
include:
19-
- ruby: 3.2.2
19+
- ruby: 3.1.4
2020
puppet: 6
2121
fixtures: .fixtures.yml
2222
allow_failure: false
23-
- ruby: 3.2.2
23+
- ruby: 3.1.4
2424
puppet: 7
2525
fixtures: .fixtures.yml
2626
allow_failure: false
27+
- ruby: 3.1.4
28+
puppet: 8
29+
fixtures: .fixtures.yml
30+
allow_failure: false
2731
- ruby: 2.5.7
2832
puppet: 6
2933
fixtures: .fixtures-latest.yml

lib/facter/sensu_facts.rb

Lines changed: 147 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,17 @@ def self.get_version_info(exe)
3030
resolved = Facter.which('sensuctl')
3131
exe_path = resolved unless resolved.nil?
3232
end
33-
version_output = Facter::Core::Execution.execute("#{exe_path} version")
33+
34+
# Check if executable exists and is executable
35+
return version_info unless exe_path && File.executable?(exe_path)
36+
37+
# Add timeout and better error handling
38+
version_output = Facter::Core::Execution.execute("#{exe_path} version", timeout: 10)
39+
40+
# Debug output for troubleshooting
41+
if version_output.nil? || version_output.empty?
42+
return version_info
43+
end
3444
case exe
3545
when 'sensu-backend', '/bin/sensu-backend'
3646
if (m = version_output.match(/sensu-backend version\s+([0-9]+(?:\.[0-9]+)*)/))
@@ -73,7 +83,37 @@ def self.add_agent_facts
7383
Facter.add(:sensu_agent_version) do
7484
setcode do
7585
exe = Facter.which('sensu-agent') || 'sensu-agent'
76-
Facter.get_version_info(exe)['sensu_agent_version']
86+
# Retry up to 5 times with 2 second delay
87+
retries = 0
88+
begin
89+
# Check if executable exists first
90+
return '' unless exe && File.executable?(exe)
91+
92+
result = Facter.get_version_info(exe)['sensu_agent_version']
93+
if result && !result.empty?
94+
result
95+
else
96+
# Try direct execution as fallback
97+
begin
98+
output = Facter::Core::Execution.execute("#{exe} version", timeout: 10)
99+
if output && (m = output.match(/sensu-agent version\s+([0-9]+(?:\.[0-9]+)*)/))
100+
m[1]
101+
else
102+
''
103+
end
104+
rescue StandardError
105+
''
106+
end
107+
end
108+
rescue StandardError
109+
retries += 1
110+
if retries < 5
111+
sleep(2)
112+
retry
113+
else
114+
''
115+
end
116+
end
77117
end
78118
end
79119
end
@@ -82,13 +122,81 @@ def self.add_backend_facts
82122
Facter.add(:sensu_backend_version) do
83123
setcode do
84124
exe = Facter.which('sensu-backend')
85-
exe.nil? ? nil : Facter.get_version_info(exe)['sensu_backend_version']
125+
if exe.nil?
126+
''
127+
else
128+
# Retry up to 5 times with 2 second delay
129+
retries = 0
130+
begin
131+
# Check if executable exists first
132+
return '' unless File.executable?(exe)
133+
134+
result = Facter.get_version_info(exe)['sensu_backend_version']
135+
if result && !result.empty?
136+
result
137+
else
138+
# Try direct execution as fallback
139+
begin
140+
output = Facter::Core::Execution.execute("#{exe} version", timeout: 10)
141+
if output && (m = output.match(/sensu-backend version\s+([0-9]+(?:\.[0-9]+)*)/))
142+
m[1]
143+
else
144+
''
145+
end
146+
rescue StandardError
147+
''
148+
end
149+
end
150+
rescue StandardError
151+
retries += 1
152+
if retries < 5
153+
sleep(2)
154+
retry
155+
else
156+
''
157+
end
158+
end
159+
end
86160
end
87161
end
88162
Facter.add(:sensu_backend_etcd_version) do
89163
setcode do
90164
exe = Facter.which('sensu-backend')
91-
exe.nil? ? nil : Facter.get_version_info(exe)['sensu_backend_etcd_version']
165+
if exe.nil?
166+
''
167+
else
168+
# Retry up to 5 times with 2 second delay
169+
retries = 0
170+
begin
171+
# Check if executable exists first
172+
return '' unless File.executable?(exe)
173+
174+
result = Facter.get_version_info(exe)['sensu_backend_etcd_version']
175+
if result && !result.empty?
176+
result
177+
else
178+
# Try direct execution as fallback
179+
begin
180+
output = Facter::Core::Execution.execute("#{exe} version", timeout: 10)
181+
if output && (m = output.match(/etcd version\s+([0-9]+(?:\.[0-9]+)*)/))
182+
m[1]
183+
else
184+
''
185+
end
186+
rescue StandardError
187+
''
188+
end
189+
end
190+
rescue StandardError
191+
retries += 1
192+
if retries < 5
193+
sleep(2)
194+
retry
195+
else
196+
''
197+
end
198+
end
199+
end
92200
end
93201
end
94202
end
@@ -97,7 +205,41 @@ def self.add_sensuctl_facts
97205
Facter.add(:sensuctl_version) do
98206
setcode do
99207
exe = Facter.which('sensuctl')
100-
exe.nil? ? nil : Facter.get_version_info(exe)['sensuctl_version']
208+
if exe.nil?
209+
''
210+
else
211+
# Retry up to 5 times with 2 second delay
212+
retries = 0
213+
begin
214+
# Check if executable exists first
215+
return '' unless File.executable?(exe)
216+
217+
result = Facter.get_version_info(exe)['sensuctl_version']
218+
if result && !result.empty?
219+
result
220+
else
221+
# Try direct execution as fallback
222+
begin
223+
output = Facter::Core::Execution.execute("#{exe} version", timeout: 10)
224+
if output && (m = output.match(/sensuctl version\s+([0-9]+(?:\.[0-9]+)*)/))
225+
m[1]
226+
else
227+
''
228+
end
229+
rescue StandardError
230+
''
231+
end
232+
end
233+
rescue StandardError
234+
retries += 1
235+
if retries < 5
236+
sleep(2)
237+
retry
238+
else
239+
''
240+
end
241+
end
242+
end
101243
end
102244
end
103245
end

0 commit comments

Comments
 (0)