foreman_leapp 2.0.4 → 2.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 39b76ff9be101528d380dd92e6a34317ff06baa209970768f118376a194f0619
4
- data.tar.gz: d2c650f2b39291ea86a4b1f674513640817f13cb1392609335d77d21a57edb52
3
+ metadata.gz: 3ab2b680299f37a54a1d6463cfb4182f3f225f45ce3c74ece1fa85c43ca78bc4
4
+ data.tar.gz: 8f53d714c059f1697cfd8e001b18722e031254b74b852f291d77478173892b26
5
5
  SHA512:
6
- metadata.gz: 90be586b8c9583b141818d797a32f0c34579ffdca1df9e9f51ccb591dd51e6f9b370632af43120a76081a548bcee52585d36fe36af55970790f92a5c496fe790
7
- data.tar.gz: 7a37d8be2dd4fc5eee7062e53c46cc6b2303a844cc0752f03c0bc0be7a342efeab01c01b579c17c2af7635635c3a6cb0b9c036c5c65984b01a613fbafda9dff6
6
+ metadata.gz: 7fd6eaed188b8932a412371b1d8971ab660f54927594487756086337b2c8d77aa250cc19ce869c3d10a9699834687e59686a65c7e4f2630910d5432b68fc6fcd
7
+ data.tar.gz: ad7bc193c7b5383217aa0cc83e351775cd278f808c34c353d6a1d17e8deace44c650decdb280b8a4f9980e666d73584e1687a678958729cd345602fc0a12065c
@@ -3,10 +3,16 @@
3
3
  module Helpers
4
4
  module JobHelper
5
5
  class << self
6
+ # Returns true if the given feature is present in the job_invocation's job_features,
7
+ # or if a matching RemoteExecutionFeature exists for the job_template.
6
8
  def correct_feature?(job_invocation, feature)
7
- RemoteExecutionFeature.where(job_template_id: job_invocation.pattern_template_invocations
8
- .first
9
- .template_id, label: feature).any?
9
+ # check if the feature exists in the DB for the job_template
10
+ template_id = job_invocation.pattern_template_invocations.first.template_id
11
+ return true if RemoteExecutionFeature.exists?(job_template_id: template_id, label: feature)
12
+
13
+ # Fallback: check if the feature is present in job_features
14
+ job_features = Array(job_invocation.task&.input&.[]('job_features'))
15
+ job_features.include?(feature)
10
16
  end
11
17
  end
12
18
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ForemanLeapp
4
- VERSION = '2.0.4'
4
+ VERSION = '2.0.5'
5
5
  end
@@ -8,22 +8,63 @@ module Helpers
8
8
 
9
9
  let(:job_template) do
10
10
  FactoryBot.create(:job_template, template: 'echo "1"', job_category: 'leapp',
11
- provider_type: 'SSH', name: 'Leapp preupgrade')
11
+ provider_type: 'SSH', name: 'Leapp preupgrade')
12
+ end
13
+ let(:job_invocation) { FactoryBot.create(:job_invocation, :with_task) }
14
+ let(:feature_label) { 'leapp_preupgrade' }
15
+
16
+ setup do
17
+ FactoryBot.create(:template_invocation, template: job_template, job_invocation: job_invocation)
12
18
  end
13
- let(:job_invocation) { FactoryBot.create(:job_invocation) }
14
19
 
15
20
  describe 'correct_feature?' do
16
- setup do
17
- RemoteExecutionFeature.find_by(label: 'leapp_preupgrade').update(job_template: job_template)
18
- FactoryBot.create(:template_invocation, template: job_template, job_invocation: job_invocation)
21
+ test 'returns true when feature is listed in job_features' do
22
+ job_invocation.task.stubs(:input).returns({ 'job_features' => [feature_label] })
23
+ assert helper.correct_feature?(job_invocation, feature_label)
24
+ end
25
+
26
+ test 'returns false when job_features does not include the feature and DB has no match' do
27
+ job_invocation.task.stubs(:input).returns({ 'job_features' => ['some_other_feature'] })
28
+ assert_not helper.correct_feature?(job_invocation, feature_label)
29
+ end
30
+
31
+ test 'returns true when job_features does not include the feature but DB does match' do
32
+ RemoteExecutionFeature.find_by(label: feature_label).update(job_template: job_template)
33
+ job_invocation.task.stubs(:input).returns({ 'job_features' => ['some_other_feature'] })
34
+ assert helper.correct_feature?(job_invocation, feature_label)
35
+ end
36
+
37
+ test 'returns true when job_features key is missing but DB matches' do
38
+ RemoteExecutionFeature.find_by(label: feature_label).update(job_template: job_template)
39
+ job_invocation.task.stubs(:input).returns({})
40
+ assert helper.correct_feature?(job_invocation, feature_label)
41
+ end
42
+
43
+ test 'returns false when job_features key is missing and DB does not match' do
44
+ job_invocation.task.stubs(:input).returns({})
45
+ assert_not helper.correct_feature?(job_invocation, feature_label)
46
+ end
47
+
48
+ test 'returns false when job_features is nil and DB does not match' do
49
+ job_invocation.task.stubs(:input).returns({ 'job_features' => nil })
50
+ assert_not helper.correct_feature?(job_invocation, feature_label)
51
+ end
52
+
53
+ test 'returns true when job_features is nil but DB matches' do
54
+ RemoteExecutionFeature.find_by(label: feature_label).update(job_template: job_template)
55
+ job_invocation.task.stubs(:input).returns({ 'job_features' => nil })
56
+ assert helper.correct_feature?(job_invocation, feature_label)
19
57
  end
20
58
 
21
- it 'correct feature' do
22
- assert helper.correct_feature?(job_invocation, 'leapp_preupgrade')
59
+ test 'returns false when task is nil and feature not found in DB' do
60
+ job_invocation.stubs(:task).returns(nil)
61
+ assert_not helper.correct_feature?(job_invocation, feature_label)
23
62
  end
24
63
 
25
- it 'wrong feature' do
26
- assert_not helper.correct_feature?(job_invocation, 'leapp_preupgrade2')
64
+ test 'returns true when task is nil but DB matches' do
65
+ RemoteExecutionFeature.find_by(label: feature_label).update(job_template: job_template)
66
+ job_invocation.stubs(:task).returns(nil)
67
+ assert helper.correct_feature?(job_invocation, feature_label)
27
68
  end
28
69
  end
29
70
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_leapp
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.4
4
+ version: 2.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Foreman Leapp team
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2025-02-20 00:00:00.000000000 Z
10
+ date: 2025-07-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: foreman_remote_execution
@@ -201,7 +200,6 @@ homepage: https://github.com/theforeman/foreman_leapp
201
200
  licenses:
202
201
  - GPL-3.0
203
202
  metadata: {}
204
- post_install_message:
205
203
  rdoc_options: []
206
204
  require_paths:
207
205
  - lib
@@ -216,8 +214,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
216
214
  - !ruby/object:Gem::Version
217
215
  version: '0'
218
216
  requirements: []
219
- rubygems_version: 3.5.23
220
- signing_key:
217
+ rubygems_version: 3.6.2
221
218
  specification_version: 4
222
219
  summary: A Foreman plugin for Leapp utility.
223
220
  test_files: