foreman_rh_cloud 4.0.23 → 4.0.24

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5420c61e798ba0e1362d27e112917e42c2ca4b03d6cba6a0f152f4ca05a53074
4
- data.tar.gz: 8de40681c62902d41ed1432d33b89ec53602f69e27e9ec7c0fce6f917e3a7b02
3
+ metadata.gz: b73f3b045ed5bcbba051801155232d62a0884b30da8e461328a17e509fe0f0ec
4
+ data.tar.gz: 2cc1a0c73e193de7d26b368e9a78760ee302f78ecafeef6c27e18165293d0d2d
5
5
  SHA512:
6
- metadata.gz: 3c2128a80e4fc952cfc5d8a3f652cd85851a02bd939a7bfd1f9e3c33e3487763e99872b90d1fc4a591206849e18a4df3e4e229964fef6bf4d2994b0c359309cf
7
- data.tar.gz: acaca7aca5b8a5f0ad5f72b8f8bd6f28bc5110d49a8d9489046245046b99942d9adba8d0184251359a1d3120d85667f18781e3c49f6c48b64f12a10897bffad7
6
+ metadata.gz: 2eb0bb9cdb4d2aefa66acec328c98467a7db33de69e0256f966cca0f929756fb9100a5880d8d9a03f358cfafaf6e5aa32cf9896125c0eab8e3de9b9ebbb09269
7
+ data.tar.gz: 12e435965a84de5c538e98463fcdacbacd70eefd692822782cdb5ec4ed1e9f91e6d31f65466cffaa4b415c4491ff62e393a1e2f716f4542b03e5911fe6a34b97
@@ -6,6 +6,10 @@ class InsightsClientReportStatus < HostStatus::Status
6
6
  NOT_MANAGED = 2 # host_registration_insights = false
7
7
  NOT_MANAGED_WITH_DATA = 3 # host_registration_insights = false & getting data
8
8
 
9
+ scope :stale, -> { where.not(reported_at: (Time.now - REPORT_INTERVAL)..Time.now) }
10
+ scope :reporting, -> { where(status: REPORTING) }
11
+ scope :not_managed_with_data, -> { where(status: NOT_MANAGED_WITH_DATA) }
12
+
9
13
  def self.status_name
10
14
  N_('Insights')
11
15
  end
@@ -56,10 +56,6 @@ module ForemanRhCloud
56
56
 
57
57
  def path_params(request_path, certs)
58
58
  case request_path
59
- when metadata_request?
60
- {
61
- url: ForemanRhCloud.base_url + request_path.sub('/redhat_access/r/insights', '/api'),
62
- }
63
59
  when platform_request?
64
60
  {
65
61
  url: ForemanRhCloud.cert_base_url + request_path.sub('/redhat_access/r/insights/platform', '/api'),
@@ -76,10 +72,6 @@ module ForemanRhCloud
76
72
  end
77
73
  end
78
74
 
79
- def metadata_request?
80
- ->(request_path) { request_path.include? '/static' }
81
- end
82
-
83
75
  def platform_request?
84
76
  ->(request_path) { request_path.include? '/platform' }
85
77
  end
@@ -70,8 +70,16 @@ module ForemanInventoryUpload
70
70
  folder
71
71
  end
72
72
 
73
+ def self.inventory_base_url
74
+ ForemanRhCloud.base_url + "/api/inventory/v1/hosts"
75
+ end
76
+
73
77
  def self.inventory_export_url
74
78
  tags = URI.encode("satellite/satellite_instance_id=#{Foreman.instance_id}")
75
- ForemanRhCloud.base_url + "/api/inventory/v1/hosts?tags=#{tags}"
79
+ inventory_base_url + "?tags=#{tags}"
80
+ end
81
+
82
+ def self.inventory_self_url
83
+ inventory_base_url + "?hostname_or_id=#{ForemanRhCloud.foreman_host.fqdn}"
76
84
  end
77
85
  end
@@ -27,6 +27,7 @@ module ForemanInventoryUpload
27
27
  'insights_client::obfuscate_ip_enabled',
28
28
  'insights_client::hostname',
29
29
  'insights_client::ips',
30
+ 'insights_id',
30
31
  ]).pluck(:name, :id)
31
32
  ]
32
33
  end
@@ -49,6 +49,7 @@ module ForemanInventoryUpload
49
49
  @stream.simple_field('satellite_id', uuid_value!(host.subscription_facet&.uuid))
50
50
  @stream.simple_field('bios_uuid', bios_uuid(host))
51
51
  @stream.simple_field('vm_uuid', uuid_value(fact_value(host, 'virt::uuid')))
52
+ @stream.simple_field('insights_id', uuid_value(fact_value(host, 'insights_id')))
52
53
  report_ip_addresses(host, host_ips_cache)
53
54
  report_mac_addresses(host)
54
55
  @stream.object_field('system_profile') do
@@ -6,6 +6,18 @@ module ForemanRhCloud
6
6
  class Engine < ::Rails::Engine
7
7
  engine_name 'foreman_rh_cloud'
8
8
 
9
+ def self.register_scheduled_task(task_class, cronline)
10
+ return if ForemanTasks::RecurringLogic.joins(:tasks)
11
+ .merge(ForemanTasks::Task.where(label: task_class.name))
12
+ .exists?
13
+
14
+ User.as_anonymous_admin do
15
+ recurring_logic = ForemanTasks::RecurringLogic.new_from_cronline(cronline)
16
+ recurring_logic.save!
17
+ recurring_logic.start(task_class)
18
+ end
19
+ end
20
+
9
21
  initializer 'foreman_rh_cloud.load_default_settings', :before => :load_config_initializers do
10
22
  require_dependency File.expand_path('../../app/models/setting/rh_cloud.rb', __dir__)
11
23
  end
@@ -138,15 +150,8 @@ module ForemanRhCloud
138
150
  # skip object creation when admin user is not present, for example in test DB
139
151
  if User.unscoped.find_by_login(User::ANONYMOUS_ADMIN).present?
140
152
  ::ForemanTasks.dynflow.config.on_init(false) do |world|
141
- unless ForemanTasks::RecurringLogic.joins(:tasks).merge(
142
- ForemanTasks::Task.where(label: 'InventorySync::Async::InventoryScheduledSync')
143
- ).exists?
144
- User.as_anonymous_admin do
145
- recurring_logic = ForemanTasks::RecurringLogic.new_from_cronline("0 0 * * *")
146
- recurring_logic.save!
147
- recurring_logic.start(InventorySync::Async::InventoryScheduledSync)
148
- end
149
- end
153
+ ForemanRhCloud::Engine.register_scheduled_task(InventorySync::Async::InventoryScheduledSync, '0 0 * * *')
154
+ ForemanRhCloud::Engine.register_scheduled_task(InsightsCloud::Async::InsightsClientStatusAging, '0 0 * * *')
150
155
  end
151
156
  end
152
157
  end
@@ -1,3 +1,3 @@
1
1
  module ForemanRhCloud
2
- VERSION = '4.0.23'.freeze
2
+ VERSION = '4.0.24'.freeze
3
3
  end
@@ -0,0 +1,17 @@
1
+ module InsightsCloud
2
+ module Async
3
+ class InsightsClientStatusAging < ::Actions::EntryAction
4
+ include ::Actions::RecurringAction
5
+
6
+ def run
7
+ # update all stale records to "not reporting" counterpart
8
+ InsightsClientReportStatus.stale.reporting.update_all(status: InsightsClientReportStatus::NO_REPORT)
9
+ InsightsClientReportStatus.stale.not_managed_with_data.update_all(status: InsightsClientReportStatus::NOT_MANAGED)
10
+ end
11
+
12
+ def logger
13
+ action_logger
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,6 +1,8 @@
1
1
  module InventorySync
2
2
  module Async
3
3
  class HostResult
4
+ attr_reader :uuid_by_fqdn
5
+
4
6
  def initialize(result)
5
7
  @total = result['total']
6
8
  @count = result['count']
@@ -8,6 +10,7 @@ module InventorySync
8
10
  @per_page = result['per_page']
9
11
  @sub_ids = result["results"].map { |host| host['subscription_manager_id'] }
10
12
  @uuid_by_sub_id = Hash[result["results"].map { |host| [host['subscription_manager_id'], host['id']] }]
13
+ @uuid_by_fqdn = Hash[result["results"].map { |host| [host['fqdn'].downcase, host['id']] }]
11
14
  end
12
15
 
13
16
  def status_hashes
@@ -19,6 +22,7 @@ module InventorySync
19
22
  host_id: host_id,
20
23
  status: InventorySync::InventoryStatus::SYNC,
21
24
  reported_at: DateTime.current,
25
+ type: InventorySync::InventoryStatus.name,
22
26
  }
23
27
  end
24
28
  end.compact
@@ -4,6 +4,12 @@ module InventorySync
4
4
  set_callback :iteration, :around, :setup_facet_transaction
5
5
  set_callback :step, :around, :create_facets
6
6
 
7
+ def plan
8
+ # by default the tasks will be executed concurrently
9
+ plan_self
10
+ plan_self_host_sync
11
+ end
12
+
7
13
  def setup_facet_transaction
8
14
  InsightsFacet.transaction do
9
15
  yield
@@ -33,6 +39,10 @@ module InventorySync
33
39
  InsightsFacet.where(host_id: host_id).update_all(uuid: uuids_hash[host_id])
34
40
  end
35
41
  end
42
+
43
+ def plan_self_host_sync
44
+ plan_action InventorySync::Async::InventorySelfHostSync
45
+ end
36
46
  end
37
47
  end
38
48
  end
@@ -0,0 +1,30 @@
1
+ module InventorySync
2
+ module Async
3
+ class InventorySelfHostSync < QueryInventoryJob
4
+ set_callback :step, :around, :create_facets
5
+
6
+ def create_facets
7
+ # get the results from the event
8
+ results = yield
9
+
10
+ add_missing_insights_facet(results.uuid_by_fqdn) unless results.uuid_by_fqdn.empty?
11
+ results
12
+ end
13
+
14
+ private
15
+
16
+ def add_missing_insights_facet(uuids_hash)
17
+ facet = InsightsFacet.find_or_create_by(host_id: ForemanRhCloud.foreman_host.id) do |facet|
18
+ facet.uuid = uuids_hash.values.first
19
+ end
20
+
21
+ # fix empty uuid in case the facet already exists
22
+ facet.update(uuid: uuids_hash.values.first) unless facet.uuid
23
+ end
24
+
25
+ def request_url
26
+ ForemanInventoryUpload.inventory_self_url
27
+ end
28
+ end
29
+ end
30
+ end
@@ -31,7 +31,7 @@ module InventorySync
31
31
  def query_inventory(page = 1)
32
32
  hosts_inventory_response = execute_cloud_request(
33
33
  method: :get,
34
- url: ForemanInventoryUpload.inventory_export_url,
34
+ url: request_url,
35
35
  headers: {
36
36
  params: {
37
37
  per_page: 100,
@@ -46,6 +46,10 @@ module InventorySync
46
46
  def logger
47
47
  action_logger
48
48
  end
49
+
50
+ def request_url
51
+ ForemanInventoryUpload.inventory_export_url
52
+ end
49
53
  end
50
54
  end
51
55
  end
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foreman_rh_cloud",
3
- "version": "4.0.23",
3
+ "version": "4.0.24",
4
4
  "description": "Inventory Upload =============",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -11,6 +11,39 @@ module InsightsCloud::Api
11
11
  host = FactoryBot.create(:host, :with_subscription, :organization => org)
12
12
  User.current = ::Katello::CpConsumerUser.new(:uuid => host.subscription_facet.uuid, :login => host.subscription_facet.uuid)
13
13
  InsightsCloud::Api::MachineTelemetriesController.any_instance.stubs(:upstream_owner).returns({ 'uuid' => 'abcdefg' })
14
+
15
+ @cert1 = "-----BEGIN CERTIFICATE-----\r\n" +
16
+ "MIIFdDCCA1ygAwIBAgIJAM5Uqykb3EAtMA0GCSqGSIb3DQEBCwUAME8xCzAJBgNV\r\n" +
17
+ "BAYTAklMMREwDwYDVQQIDA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+ "-----END CERTIFICATE-----"
14
47
  end
15
48
 
16
49
  test "should respond with response from cloud" do
@@ -30,6 +63,14 @@ module InsightsCloud::Api
30
63
  ::ForemanRhCloud::CloudRequestForwarder.any_instance.expects(:execute_cloud_request).with do |opts|
31
64
  opts[:headers][:content_type] == 'application/json'
32
65
  end.returns(res)
66
+ InsightsCloud::Api::MachineTelemetriesController.any_instance.expects(:candlepin_id_cert)
67
+ .returns(
68
+ {
69
+ cert: @cert1,
70
+ key: OpenSSL::PKey::RSA.new(1024).to_pem,
71
+ }
72
+ )
73
+ InsightsCloud::Api::MachineTelemetriesController.any_instance.expects(:cp_owner_id).returns('123')
33
74
 
34
75
  post :forward_request, as: :json, params: { "path" => "static/v1/test", "machine_telemetry" => {"foo" => "bar"} }
35
76
  assert_equal @body, @response.body
@@ -0,0 +1,33 @@
1
+ require 'test_plugin_helper'
2
+ require 'foreman_tasks/test_helpers'
3
+
4
+ class InsightsClientStatusAgingTest < ActiveSupport::TestCase
5
+ include ForemanTasks::TestHelpers::WithInThreadExecutor
6
+
7
+ setup do
8
+ User.current = User.find_by(login: 'secret_admin')
9
+
10
+ @host1 = FactoryBot.create(:host)
11
+ @host2 = FactoryBot.create(:host)
12
+ @host3 = FactoryBot.create(:host)
13
+ @host4 = FactoryBot.create(:host)
14
+
15
+ @hosts = [@host1, @host2, @host3, @host4]
16
+ end
17
+
18
+ test 'stale statuses should change' do
19
+ InsightsClientReportStatus.find_or_initialize_by(host_id: @host1.id).update(status: InsightsClientReportStatus::REPORTING, reported_at: Time.now - InsightsClientReportStatus::REPORT_INTERVAL - 1.day)
20
+ InsightsClientReportStatus.find_or_initialize_by(host_id: @host2.id).update(status: InsightsClientReportStatus::NO_REPORT, reported_at: Time.now - InsightsClientReportStatus::REPORT_INTERVAL - 1.day)
21
+ InsightsClientReportStatus.find_or_initialize_by(host_id: @host3.id).update(status: InsightsClientReportStatus::NOT_MANAGED, reported_at: Time.now - InsightsClientReportStatus::REPORT_INTERVAL - 1.day)
22
+ InsightsClientReportStatus.find_or_initialize_by(host_id: @host4.id).update(status: InsightsClientReportStatus::NOT_MANAGED_WITH_DATA, reported_at: Time.now - InsightsClientReportStatus::REPORT_INTERVAL - 1.day)
23
+
24
+ ForemanTasks.sync_task(InsightsCloud::Async::InsightsClientStatusAging)
25
+
26
+ @hosts.each(&:reload)
27
+
28
+ assert_equal InsightsClientReportStatus::NO_REPORT, @host1.get_status(InsightsClientReportStatus).status
29
+ assert_equal InsightsClientReportStatus::NO_REPORT, @host2.get_status(InsightsClientReportStatus).status
30
+ assert_equal InsightsClientReportStatus::NOT_MANAGED, @host3.get_status(InsightsClientReportStatus).status
31
+ assert_equal InsightsClientReportStatus::NOT_MANAGED, @host4.get_status(InsightsClientReportStatus).status
32
+ end
33
+ end
@@ -243,6 +243,7 @@ class InventoryHostsSyncTest < ActiveSupport::TestCase
243
243
 
244
244
  test 'Inventory should sync UUID for existing Insights Facets' do
245
245
  InventorySync::Async::InventoryHostsSync.any_instance.expects(:query_inventory).returns(@inventory)
246
+ InventorySync::Async::InventoryHostsSync.any_instance.expects(:plan_self_host_sync)
246
247
 
247
248
  @host2.build_insights.save
248
249
 
@@ -255,6 +256,7 @@ class InventoryHostsSyncTest < ActiveSupport::TestCase
255
256
 
256
257
  test 'Inventory should sync UUID for new Insights Facets' do
257
258
  InventorySync::Async::InventoryHostsSync.any_instance.expects(:query_inventory).returns(@inventory)
259
+ InventorySync::Async::InventoryHostsSync.any_instance.expects(:plan_self_host_sync)
258
260
 
259
261
  ForemanTasks.sync_task(InventorySync::Async::InventoryHostsSync)
260
262
 
@@ -0,0 +1,103 @@
1
+ require 'test_plugin_helper'
2
+ require 'foreman_tasks/test_helpers'
3
+
4
+ class InventorySelfHostSyncTest < ActiveSupport::TestCase
5
+ include ForemanTasks::TestHelpers::WithInThreadExecutor
6
+
7
+ setup do
8
+ User.current = User.find_by(login: 'secret_admin')
9
+
10
+ # this host would pass our plugin queries, so it could be uploaded to the cloud.
11
+ @host1 = FactoryBot.create(:host)
12
+ @host1_inventory_id = '3255d080-e6c1-44e2-8d72-b044b9a38d8f'
13
+
14
+ ForemanInventoryUpload::Generators::Queries.instance_variable_set(:@fact_names, nil)
15
+
16
+ ForemanRhCloud.stubs(:foreman_host).returns(@host1)
17
+
18
+ inventory_json = <<-INVENTORY_JSON
19
+ {
20
+ "total": 1,
21
+ "count": 1,
22
+ "page": 1,
23
+ "per_page": 1,
24
+ "results": [
25
+ {
26
+ "insights_id": "e0dc5144-d78e-43ed-97be-a7a21d1b6946",
27
+ "rhel_machine_id": null,
28
+ "subscription_manager_id": "0f97ee19-6862-4900-aea4-f121c8754776",
29
+ "satellite_id": "0f97ee19-6862-4900-aea4-f121c8754776",
30
+ "bios_uuid": "6a0b199a-8225-4ade-ae44-3b18cfc84a01",
31
+ "ip_addresses": [
32
+ "192.168.122.136"
33
+ ],
34
+ "fqdn": "#{@host1.fqdn}",
35
+ "mac_addresses": [
36
+ "52:54:00:02:d1:2a",
37
+ "00:00:00:00:00:00"
38
+ ],
39
+ "external_id": null,
40
+ "id": "#{@host1_inventory_id}",
41
+ "account": "1460290",
42
+ "display_name": "insights-rh8.example.com",
43
+ "ansible_host": null,
44
+ "facts": [
45
+ {
46
+ "namespace": "satellite",
47
+ "facts": {
48
+ "virtual_host_name": "virt-who-nobody.home-1",
49
+ "satellite_instance_id": "fc4d0cb0-a0b0-421e-b096-b028319b8e47",
50
+ "is_simple_content_access": false,
51
+ "distribution_version": "8.3",
52
+ "satellite_version": "6.8.4",
53
+ "organization_id": 1,
54
+ "is_hostname_obfuscated": false,
55
+ "virtual_host_uuid": "a90e6294-4766-420a-8dc0-3ec5b96d60ec"
56
+ }
57
+ },
58
+ {
59
+ "namespace": "yupana",
60
+ "facts": {
61
+ "report_platform_id": "d37afa50-08ce-4efb-a0e5-759c2a016661",
62
+ "report_slice_id": "5bf791d7-5e30-4a3c-929a-11dd9fa6eb72",
63
+ "source": "Satellite",
64
+ "yupana_host_id": "78c62486-0ac4-406c-a4c0-3a1f81112a2d",
65
+ "account": "1460290"
66
+ }
67
+ }
68
+ ],
69
+ "reporter": "puptoo",
70
+ "stale_timestamp": "2021-03-19T06:05:12.092136+00:00",
71
+ "stale_warning_timestamp": "2021-03-26T06:05:12.092136+00:00",
72
+ "culled_timestamp": "2021-04-02T06:05:12.092136+00:00",
73
+ "created": "2021-02-08T13:22:50.555671+00:00",
74
+ "updated": "2021-03-18T01:05:12.131847+00:00"
75
+ }
76
+ ]
77
+ }
78
+ INVENTORY_JSON
79
+ @inventory = JSON.parse(inventory_json)
80
+ end
81
+
82
+ test 'Inventory should sync UUID for existing Insights Facets' do
83
+ InventorySync::Async::InventorySelfHostSync.any_instance.expects(:query_inventory).returns(@inventory)
84
+
85
+ @host1.build_insights.save
86
+
87
+ ForemanTasks.sync_task(InventorySync::Async::InventorySelfHostSync)
88
+
89
+ @host1.reload
90
+
91
+ assert_equal @host1_inventory_id, @host1.insights.uuid
92
+ end
93
+
94
+ test 'Inventory should sync UUID for new Insights Facets' do
95
+ InventorySync::Async::InventorySelfHostSync.any_instance.expects(:query_inventory).returns(@inventory)
96
+
97
+ ForemanTasks.sync_task(InventorySync::Async::InventorySelfHostSync)
98
+
99
+ @host1.reload
100
+
101
+ assert_equal @host1_inventory_id, @host1.insights.uuid
102
+ end
103
+ end
@@ -42,9 +42,9 @@ class CloudRequestForwarderTest < ActiveSupport::TestCase
42
42
  test 'should prepare correct cloud url' do
43
43
  paths = {
44
44
  "/redhat_access/r/insights/platform/module-update-router/v1/channel?module=insights-core" => "https://cert.cloud.redhat.com/api/module-update-router/v1/channel?module=insights-core",
45
- "/redhat_access/r/insights/v1/static/release/insights-core.egg" => "https://cloud.redhat.com/api/v1/static/release/insights-core.egg",
46
- "/redhat_access/r/insights/v1/static/uploader.v2.json" => "https://cloud.redhat.com/api/v1/static/uploader.v2.json",
47
- "/redhat_access/r/insights/v1/static/uploader.v2.json.asc" => "https://cloud.redhat.com/api/v1/static/uploader.v2.json.asc",
45
+ "/redhat_access/r/insights/v1/static/release/insights-core.egg" => "https://cert-api.access.redhat.com/r/insights/v1/static/release/insights-core.egg",
46
+ "/redhat_access/r/insights/v1/static/uploader.v2.json" => "https://cert-api.access.redhat.com/r/insights/v1/static/uploader.v2.json",
47
+ "/redhat_access/r/insights/v1/static/uploader.v2.json.asc" => "https://cert-api.access.redhat.com/r/insights/v1/static/uploader.v2.json.asc",
48
48
  "/redhat_access/r/insights/platform/inventory/v1/hosts" => "https://cert.cloud.redhat.com/api/inventory/v1/hosts",
49
49
  "/redhat_access/r/insights/platform/ingress/v1/upload" => "https://cert.cloud.redhat.com/api/ingress/v1/upload",
50
50
  "/redhat_access/r/insights/uploads/67200803-132b-474b-a6f9-37be74185df4" => "https://cert-api.access.redhat.com/r/insights/uploads/67200803-132b-474b-a6f9-37be74185df4",
@@ -53,6 +53,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
53
53
  'insights_client::hostname',
54
54
  'insights_client::obfuscate_ip_enabled',
55
55
  'insights_client::ips',
56
+ 'insights_id',
56
57
  ]
57
58
  end
58
59
 
@@ -657,6 +658,20 @@ class SliceGeneratorTest < ActiveSupport::TestCase
657
658
  assert_not_nil actual_host['bios_uuid']
658
659
  end
659
660
 
661
+ test 'passes valid insights_id field' do
662
+ FactoryBot.create(:fact_value, fact_name: fact_names['insights_id'], value: 'D30B0B42-7824-2635-C62D-491394DE43F7', host: @host)
663
+
664
+ batch = Host.where(id: @host.id).in_batches.first
665
+ generator = create_generator(batch)
666
+
667
+ json_str = generator.render
668
+ actual = JSON.parse(json_str.join("\n"))
669
+
670
+ assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
671
+ assert_not_nil(actual_host = actual['hosts'].first)
672
+ assert_not_nil actual_host['insights_id']
673
+ end
674
+
660
675
  private
661
676
 
662
677
  def create_generator(batch, name = '00000000-0000-0000-0000-000000000000')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_rh_cloud
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.23
4
+ version: 4.0.24
5
5
  platform: ruby
6
6
  authors:
7
7
  - Foreman Red Hat Cloud team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-30 00:00:00.000000000 Z
11
+ date: 2021-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: katello
@@ -221,6 +221,7 @@ files:
221
221
  - lib/foreman_rh_cloud/engine.rb
222
222
  - lib/foreman_rh_cloud/version.rb
223
223
  - lib/insights_cloud.rb
224
+ - lib/insights_cloud/async/insights_client_status_aging.rb
224
225
  - lib/insights_cloud/async/insights_full_sync.rb
225
226
  - lib/insights_cloud/async/insights_generate_notifications.rb
226
227
  - lib/insights_cloud/async/insights_resolutions_sync.rb
@@ -231,6 +232,7 @@ files:
231
232
  - lib/inventory_sync/async/inventory_full_sync.rb
232
233
  - lib/inventory_sync/async/inventory_hosts_sync.rb
233
234
  - lib/inventory_sync/async/inventory_scheduled_sync.rb
235
+ - lib/inventory_sync/async/inventory_self_host_sync.rb
234
236
  - lib/inventory_sync/async/query_inventory_job.rb
235
237
  - lib/tasks/foreman_rh_cloud_tasks.rake
236
238
  - lib/tasks/insights.rake
@@ -249,12 +251,14 @@ files:
249
251
  - test/controllers/uploads_settings_controller_test.rb
250
252
  - test/factories/insights_factories.rb
251
253
  - test/factories/inventory_upload_factories.rb
254
+ - test/jobs/insights_client_status_aging_test.rb
252
255
  - test/jobs/insights_full_sync_test.rb
253
256
  - test/jobs/insights_resolutions_sync_test.rb
254
257
  - test/jobs/insights_rules_sync_test.rb
255
258
  - test/jobs/inventory_full_sync_test.rb
256
259
  - test/jobs/inventory_hosts_sync_test.rb
257
260
  - test/jobs/inventory_scheduled_sync_test.rb
261
+ - test/jobs/inventory_self_host_sync_test.rb
258
262
  - test/jobs/upload_report_job_test.rb
259
263
  - test/models/insights_client_report_status_test.rb
260
264
  - test/test_plugin_helper.rb
@@ -677,12 +681,14 @@ test_files:
677
681
  - test/controllers/uploads_settings_controller_test.rb
678
682
  - test/factories/insights_factories.rb
679
683
  - test/factories/inventory_upload_factories.rb
684
+ - test/jobs/insights_client_status_aging_test.rb
680
685
  - test/jobs/insights_full_sync_test.rb
681
686
  - test/jobs/insights_resolutions_sync_test.rb
682
687
  - test/jobs/insights_rules_sync_test.rb
683
688
  - test/jobs/inventory_full_sync_test.rb
684
689
  - test/jobs/inventory_hosts_sync_test.rb
685
690
  - test/jobs/inventory_scheduled_sync_test.rb
691
+ - test/jobs/inventory_self_host_sync_test.rb
686
692
  - test/jobs/upload_report_job_test.rb
687
693
  - test/models/insights_client_report_status_test.rb
688
694
  - test/test_plugin_helper.rb