foreman_rh_cloud 12.2.5 → 13.0.1

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: 2081fbfa1331d1d17e96c000bfad7990a679973d5702ae47bc9f544591d1b27a
4
- data.tar.gz: 5e33001a27be919fa1394b235ee4374ef8e8b7086eaffa898ddcd601acca5933
3
+ metadata.gz: a4dce9ac19e0733dc9cc01fcd64669c371efeddd80a77a3fde8bf3772ea122eb
4
+ data.tar.gz: e9ef77d5406bfd9ae621010c52a3dfcd186eead17f49572d92ebc696aaffe851
5
5
  SHA512:
6
- metadata.gz: d04457f59d4c0a027dcd87f996efb850e04db2f123753f5636c134f4e8c0c04226e96854bcb686a7200f83b4ee32fe75deba2c9af6680009dfb2e70a816502f8
7
- data.tar.gz: 716f79c957a3a563374ba257f623b34bfdf30a5ef1a29f5404994cef658146e26d01fb0a52cf218d307734de85edce662f4ea63eb55c88de149b1c5bfd5d5899
6
+ metadata.gz: 1aeddd3fa6f7907a425d2d70a7f79a33a4fb10da819c04eeb1a462a051e3fcc943d5c06266058b7d7c2342a504edc120178abde297565f27e66511ff31709c89
7
+ data.tar.gz: b84acc34c1329198f0b142b9caf0079a530c1c1dcf60142989ccceada0dfd19c0ad33ffa6ce117ba6a210d20de0a2447bf243a431004d8972ad46980b7f92bd5
@@ -1,3 +1,3 @@
1
1
  module ForemanRhCloud
2
- VERSION = '12.2.5'.freeze
2
+ VERSION = '13.0.1'.freeze
3
3
  end
@@ -0,0 +1,71 @@
1
+ require 'rest-client'
2
+
3
+ module InsightsCloud
4
+ module Async
5
+ # Triggers VMaaS reposcan sync via IoP gateway when repositories are synced
6
+ class VmaasReposcanSync < ::Actions::EntryAction
7
+ include ::ForemanRhCloud::CertAuth
8
+
9
+ # Subscribe to Katello repository sync hook action, if available
10
+ def self.subscribe
11
+ 'Actions::Katello::Repository::SyncHook'.constantize
12
+ rescue NameError
13
+ Rails.logger.debug('VMaaS reposcan sync: Repository::SyncHook action not found')
14
+ nil
15
+ end
16
+
17
+ def plan(repo, *_args)
18
+ return unless ::ForemanRhCloud.with_iop_smart_proxy?
19
+
20
+ repo_id = repo.is_a?(Hash) ? (repo[:id] || repo['id']) : nil
21
+ unless repo_id
22
+ logger.error("VMaaS reposcan sync: missing repository id in SyncHook plan parameters: #{repo.inspect}")
23
+ return
24
+ end
25
+
26
+ plan_self
27
+ end
28
+
29
+ def run
30
+ url = ::InsightsCloud.vmaas_reposcan_sync_url
31
+
32
+ response = execute_cloud_request(
33
+ method: :put,
34
+ url: url,
35
+ headers: { 'Content-Type' => 'application/json' }
36
+ )
37
+
38
+ if response.code >= 200 && response.code < 300
39
+ message = "VMaaS reposcan sync triggered successfully: #{response.code}"
40
+ logger.info(message)
41
+ else
42
+ message = "VMaaS reposcan sync failed with status: #{response.code}, body: #{response.body}"
43
+ logger.error(message)
44
+ end
45
+ output[:message] = message
46
+
47
+ response
48
+ rescue RestClient::ExceptionWithResponse => e
49
+ message = "VMaaS reposcan sync failed: #{e.response&.code} - #{e.response&.body}"
50
+ logger.error(message)
51
+ output[:message] = message
52
+ raise
53
+ rescue StandardError => e
54
+ message = "Error triggering VMaaS reposcan sync: #{e.message}, response: #{e.respond_to?(:response) ? e.response : nil}"
55
+ logger.error(message)
56
+ output[:message] = message
57
+ raise
58
+ end
59
+
60
+ def rescue_strategy_for_self
61
+ Dynflow::Action::Rescue::Skip
62
+ end
63
+
64
+ private
65
+
66
+ def logger
67
+ action_logger
68
+ end
69
+ end
70
+ end
71
+ end
@@ -44,4 +44,8 @@ module InsightsCloud
44
44
  def self.enable_cloud_remediations_param
45
45
  'enable_cloud_remediations'
46
46
  end
47
+
48
+ def self.vmaas_reposcan_sync_url
49
+ ForemanRhCloud.iop_smart_proxy.url + '/api/vmaas-reposcan/sync'
50
+ end
47
51
  end
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foreman_rh_cloud",
3
- "version": "12.2.5",
3
+ "version": "13.0.1",
4
4
  "description": "Inventory Upload =============",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -0,0 +1,137 @@
1
+ require 'test_plugin_helper'
2
+ require 'foreman_tasks/test_helpers'
3
+
4
+ class VmaasReposcanSyncTest < ActiveSupport::TestCase
5
+ include ForemanTasks::TestHelpers::WithInThreadExecutor
6
+
7
+ setup do
8
+ @repo_payload = { id: 123 }
9
+ @expected_url = 'https://example.com/api/v1/vmaas/reposcan/sync'
10
+ InsightsCloud.stubs(:vmaas_reposcan_sync_url).returns(@expected_url)
11
+ ForemanRhCloud.stubs(:with_iop_smart_proxy?).returns(true)
12
+ end
13
+
14
+ # Planning behavior
15
+ test 'plan plans_self when repo payload has id and IoP is available' do
16
+ InsightsCloud::Async::VmaasReposcanSync.any_instance.expects(:plan_self).once
17
+
18
+ ForemanTasks.sync_task(InsightsCloud::Async::VmaasReposcanSync, @repo_payload)
19
+ end
20
+
21
+ test 'plan does not plan_self when repo payload is missing id' do
22
+ payload_without_id = {}
23
+
24
+ mock_logger = mock('logger')
25
+ mock_logger.expects(:error).with { |msg| msg =~ /missing repository id/i }
26
+ InsightsCloud::Async::VmaasReposcanSync.any_instance.stubs(:logger).returns(mock_logger)
27
+ InsightsCloud::Async::VmaasReposcanSync.any_instance.expects(:plan_self).never
28
+
29
+ ForemanTasks.sync_task(InsightsCloud::Async::VmaasReposcanSync, payload_without_id)
30
+ end
31
+
32
+ test 'plan does not plan_self when IoP smart proxy is not available' do
33
+ ForemanRhCloud.stubs(:with_iop_smart_proxy?).returns(false)
34
+
35
+ InsightsCloud::Async::VmaasReposcanSync.any_instance.expects(:plan_self).never
36
+
37
+ ForemanTasks.sync_task(InsightsCloud::Async::VmaasReposcanSync, @repo_payload)
38
+ end
39
+
40
+ test 'plan skips repo_id validation when IoP smart proxy is not available' do
41
+ ForemanRhCloud.stubs(:with_iop_smart_proxy?).returns(false)
42
+ payload_without_id = {}
43
+
44
+ # Logger should not be called since IoP check returns early
45
+ InsightsCloud::Async::VmaasReposcanSync.any_instance.expects(:logger).never
46
+ InsightsCloud::Async::VmaasReposcanSync.any_instance.expects(:plan_self).never
47
+
48
+ ForemanTasks.sync_task(InsightsCloud::Async::VmaasReposcanSync, payload_without_id)
49
+ end
50
+
51
+ test 'plan does not plan_self when repository is nil' do
52
+ mock_logger = mock('logger')
53
+ mock_logger.expects(:error).with { |msg| msg =~ /missing repository id/i }
54
+ InsightsCloud::Async::VmaasReposcanSync.any_instance.stubs(:logger).returns(mock_logger)
55
+ InsightsCloud::Async::VmaasReposcanSync.any_instance.expects(:plan_self).never
56
+
57
+ ForemanTasks.sync_task(InsightsCloud::Async::VmaasReposcanSync, nil)
58
+ end
59
+
60
+ # Run behavior
61
+ test 'run triggers VMaaS reposcan sync successfully' do
62
+ mock_response = mock('response')
63
+ mock_response.stubs(:code).returns(200)
64
+
65
+ InsightsCloud::Async::VmaasReposcanSync.any_instance
66
+ .expects(:execute_cloud_request)
67
+ .with do |params|
68
+ params[:method] == :put &&
69
+ params[:url] == @expected_url &&
70
+ params[:headers].is_a?(Hash) &&
71
+ params[:headers]['Content-Type'] == 'application/json'
72
+ end
73
+ .returns(mock_response)
74
+
75
+ task = ForemanTasks.sync_task(InsightsCloud::Async::VmaasReposcanSync, @repo_payload)
76
+
77
+ assert_equal 'VMaaS reposcan sync triggered successfully: 200', task.output[:message]
78
+ end
79
+
80
+ test 'run sets error message in task output for failed response' do
81
+ mock_response = mock('response')
82
+ mock_response.stubs(:code).returns(500)
83
+ mock_response.stubs(:body).returns('Internal Server Error')
84
+
85
+ InsightsCloud::Async::VmaasReposcanSync.any_instance
86
+ .stubs(:execute_cloud_request)
87
+ .returns(mock_response)
88
+
89
+ task = ForemanTasks.sync_task(InsightsCloud::Async::VmaasReposcanSync, @repo_payload)
90
+
91
+ assert_equal 'VMaaS reposcan sync failed with status: 500, body: Internal Server Error', task.output[:message]
92
+ end
93
+
94
+ test 'run sets error message in task output for RestClient exception' do
95
+ error_response = mock('error_response')
96
+ error_response.stubs(:code).returns(500)
97
+ error_response.stubs(:body).returns('Server Error')
98
+ exception = RestClient::ExceptionWithResponse.new(error_response)
99
+
100
+ InsightsCloud::Async::VmaasReposcanSync.any_instance
101
+ .stubs(:execute_cloud_request)
102
+ .raises(exception)
103
+
104
+ error = assert_raises(ForemanTasks::TaskError) do
105
+ ForemanTasks.sync_task(InsightsCloud::Async::VmaasReposcanSync, @repo_payload)
106
+ end
107
+
108
+ assert_equal 'VMaaS reposcan sync failed: 500 - Server Error', error.task.output[:message]
109
+ end
110
+
111
+ test 'run sets error message in task output for StandardError exception' do
112
+ InsightsCloud::Async::VmaasReposcanSync.any_instance
113
+ .stubs(:execute_cloud_request)
114
+ .raises(StandardError.new('Network timeout'))
115
+
116
+ error = assert_raises(ForemanTasks::TaskError) do
117
+ ForemanTasks.sync_task(InsightsCloud::Async::VmaasReposcanSync, @repo_payload)
118
+ end
119
+
120
+ # The task is available via main_action
121
+ assert_match(/Error triggering VMaaS reposcan sync: Network timeout, response: /,
122
+ error.task.main_action.output[:message])
123
+ end
124
+
125
+ test 'run logs and re-raises when cloud request returns error response' do
126
+ error_response = mock('error_response', code: 500, body: 'error')
127
+ exception = RestClient::ExceptionWithResponse.new(error_response)
128
+
129
+ InsightsCloud::Async::VmaasReposcanSync.any_instance
130
+ .stubs(:execute_cloud_request)
131
+ .raises(exception)
132
+
133
+ assert_raises(ForemanTasks::TaskError) do
134
+ ForemanTasks.sync_task(InsightsCloud::Async::VmaasReposcanSync, @repo_payload)
135
+ end
136
+ end
137
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_rh_cloud
3
3
  version: !ruby/object:Gem::Version
4
- version: 12.2.5
4
+ version: 13.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Foreman Red Hat Cloud team
@@ -217,6 +217,7 @@ files:
217
217
  - lib/insights_cloud/async/insights_rules_sync.rb
218
218
  - lib/insights_cloud/async/insights_scheduled_sync.rb
219
219
  - lib/insights_cloud/async/rules_result.rb
220
+ - lib/insights_cloud/async/vmaas_reposcan_sync.rb
220
221
  - lib/insights_cloud/generators/playbook_progress_generator.rb
221
222
  - lib/insights_vulnerability.rb
222
223
  - lib/inventory_sync/async/host_result.rb
@@ -275,6 +276,7 @@ files:
275
276
  - test/unit/fact_helpers_test.rb
276
277
  - test/unit/foreman_rh_cloud_self_host_test.rb
277
278
  - test/unit/insights_facet_test.rb
279
+ - test/unit/lib/insights_cloud/async/vmaas_reposcan_sync_test.rb
278
280
  - test/unit/metadata_generator_test.rb
279
281
  - test/unit/playbook_progress_generator_test.rb
280
282
  - test/unit/rh_cloud_http_proxy_test.rb
@@ -727,6 +729,7 @@ test_files:
727
729
  - test/unit/fact_helpers_test.rb
728
730
  - test/unit/foreman_rh_cloud_self_host_test.rb
729
731
  - test/unit/insights_facet_test.rb
732
+ - test/unit/lib/insights_cloud/async/vmaas_reposcan_sync_test.rb
730
733
  - test/unit/metadata_generator_test.rb
731
734
  - test/unit/playbook_progress_generator_test.rb
732
735
  - test/unit/rh_cloud_http_proxy_test.rb