foreman_rh_cloud 3.0.28 → 3.0.29

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: 56cd1d6cfd15e872954f934c6d4da54a0fa7fac6d376dfce68c7df38bbbab7fe
4
- data.tar.gz: be90bca3b783d987b548a3aa9b2a792a6528fbf7131cd9e130af72c9b4e6c102
3
+ metadata.gz: a50f0107b0ee371ca53cac0aa1cc4efcb4cddb0e71682812fcf14b035298a635
4
+ data.tar.gz: 90a60ab9b0ad34c6f2afd16f6f1f896352f274fa375151232744c2fae9535430
5
5
  SHA512:
6
- metadata.gz: 23a052bbb5346617f391a7a3125c5400ad8c2601d6d79f5101e78e17dcaadbdf0b3a071b2845f707f16b94642ce2b4542e585d6e09afade4d06eedc5dbd46c09
7
- data.tar.gz: 77c1aca4f971996b13067142c932e49dd6fd5df1e5efd6be09dd0e25e086f7859bba47157b826ec6dc2d8e8837dd2bb6e4c36f97e5045f404a2527484c1ed369
6
+ metadata.gz: f6b5ef45a9aaec31e4507245426ec4dd5a27d1cd91ac5df66b5240d9554a3e2282d3f9d2ffb9fbbe0f8ddedcef1e856d31b3dab64ca7da073bf6b61c1cf3b473
7
+ data.tar.gz: 032f6945342c0bd9868234006b5b50f24986c4397be70152e73a05fb468e725314a768c48bd4c2eb6cf996ed161d035a60c5e45b549e489417e8c691ece43883
@@ -1,3 +1,3 @@
1
1
  module ForemanRhCloud
2
- VERSION = '3.0.28'.freeze
2
+ VERSION = '3.0.29'.freeze
3
3
  end
@@ -17,7 +17,6 @@ module InventorySync
17
17
  @sub_ids.map do |sub_id|
18
18
  host_id = host_id(sub_id)
19
19
  if host_id
20
- touched << host_id
21
20
  {
22
21
  host_id: host_id,
23
22
  status: InventorySync::InventoryStatus::SYNC,
@@ -28,10 +27,6 @@ module InventorySync
28
27
  end.compact
29
28
  end
30
29
 
31
- def touched
32
- @touched ||= []
33
- end
34
-
35
30
  def host_id(sub_id)
36
31
  hosts[sub_id]
37
32
  end
@@ -14,11 +14,7 @@ module InventorySync
14
14
  end
15
15
 
16
16
  def setup_statuses
17
- @subscribed_hosts_ids = Set.new(
18
- ForemanInventoryUpload::Generators::Queries.for_slice(
19
- Host.unscoped.where(organization: input[:organization_id])
20
- ).pluck(:id)
21
- )
17
+ @subscribed_hosts_ids = Set.new(affected_host_ids)
22
18
 
23
19
  InventorySync::InventoryStatus.transaction do
24
20
  InventorySync::InventoryStatus.where(host_id: @subscribed_hosts_ids).delete_all
@@ -35,15 +31,18 @@ module InventorySync
35
31
  def update_statuses_batch
36
32
  results = yield
37
33
 
38
- update_hosts_status(results.status_hashes, results.touched)
39
- host_statuses[:sync] += results.touched.size
34
+ existing_hosts = results.status_hashes.select { |hash| @subscribed_hosts_ids.include?(hash[:host_id]) }
35
+
36
+ update_hosts_status(existing_hosts)
37
+ host_statuses[:sync] += existing_hosts.size
40
38
  end
41
39
 
42
40
  private
43
41
 
44
- def update_hosts_status(status_hashes, touched)
42
+ def update_hosts_status(status_hashes)
45
43
  InventorySync::InventoryStatus.create(status_hashes)
46
- @subscribed_hosts_ids.subtract(touched)
44
+ updated_ids = status_hashes.map { |hash| hash[:host_id] }
45
+ @subscribed_hosts_ids.subtract(updated_ids)
47
46
  end
48
47
 
49
48
  def add_missing_hosts_statuses(hosts_ids)
@@ -64,6 +63,12 @@ module InventorySync
64
63
  disconnect: 0,
65
64
  }
66
65
  end
66
+
67
+ def affected_host_ids
68
+ ForemanInventoryUpload::Generators::Queries.for_slice(
69
+ Host.unscoped.where(organization: input[:organization_id])
70
+ ).pluck(:id)
71
+ end
67
72
  end
68
73
  end
69
74
  end
@@ -31,18 +31,14 @@ module InventorySync
31
31
  private
32
32
 
33
33
  def add_missing_insights_facets(uuids_hash)
34
- existing_facets = InsightsFacet.where(host_id: uuids_hash.keys).pluck(:host_id, :uuid)
35
- missing_facets = uuids_hash.except(*existing_facets.map(&:first)).map do |host_id, uuid|
34
+ all_facets = uuids_hash.map do |host_id, uuid|
36
35
  {
37
36
  host_id: host_id,
38
37
  uuid: uuid,
39
38
  }
40
39
  end
41
- InsightsFacet.create(missing_facets)
42
40
 
43
- existing_facets.select { |host_id, uuid| uuid.empty? }.each do |host_id, _uuid|
44
- InsightsFacet.where(host_id: host_id).update_all(uuid: uuids_hash[host_id])
45
- end
41
+ InsightsFacet.upsert_all(all_facets, unique_by: :host_id) unless all_facets.empty?
46
42
  end
47
43
 
48
44
  def plan_self_host_sync
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foreman_rh_cloud",
3
- "version": "3.0.28",
3
+ "version": "3.0.29",
4
4
  "description": "Inventory Upload =============",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -37,6 +37,18 @@ class InventoryFullSyncTest < ActiveSupport::TestCase
37
37
  @host2.subscription_facet.pools << pool
38
38
  @host2_inventory_id = '4536bf5c-ff03-4154-a8c9-32ff4b40e40c'
39
39
 
40
+ # this host would pass our plugin queries, so it could be uploaded to the cloud.
41
+ @host3 = FactoryBot.create(
42
+ :host,
43
+ :with_subscription,
44
+ :with_content,
45
+ content_view: cv.first,
46
+ lifecycle_environment: env,
47
+ organization: env.organization
48
+ )
49
+
50
+ @host3.subscription_facet.pools << pool
51
+
40
52
  ForemanInventoryUpload::Generators::Queries.instance_variable_set(:@fact_names, nil)
41
53
 
42
54
  inventory_json = <<-INVENTORY_JSON
@@ -151,7 +163,7 @@ class InventoryFullSyncTest < ActiveSupport::TestCase
151
163
  {
152
164
  "insights_id": "b533848e-465f-4f1a-9b2b-b71cb2d5239d",
153
165
  "rhel_machine_id": null,
154
- "subscription_manager_id": "d29bde40-348e-437c-8acf-8fa98320fc1b",
166
+ "subscription_manager_id": "#{@host3.subscription_facet.uuid}",
155
167
  "satellite_id": "d29bde40-348e-437c-8acf-8fa98320fc1b",
156
168
  "bios_uuid": "3cd5d972-cfb5-451a-8314-fd2f56629d7c",
157
169
  "ip_addresses": [
@@ -159,7 +171,7 @@ class InventoryFullSyncTest < ActiveSupport::TestCase
159
171
  "fd6e:2298:736e::857",
160
172
  "fd6e:2298:736e:0:2c66:6101:9cc6:2b23"
161
173
  ],
162
- "fqdn": "rhel8-demo.oss-lab.net",
174
+ "fqdn": "#{@host3.fqdn}",
163
175
  "mac_addresses": [
164
176
  "6e:66:a6:fe:fc:07",
165
177
  "00:00:00:00:00:00"
@@ -271,4 +283,18 @@ class InventoryFullSyncTest < ActiveSupport::TestCase
271
283
 
272
284
  ForemanTasks.sync_task(InventorySync::Async::InventoryFullSync, @host1.organization)
273
285
  end
286
+
287
+ test 'Should skip hosts that are not returned in query' do
288
+ assert_nil InventorySync::InventoryStatus.where(host_id: @host3.id).first
289
+
290
+ FactoryBot.create(:setting, name: 'rh_cloud_token', value: 'TEST TOKEN')
291
+ InventorySync::Async::InventoryFullSync.any_instance.expects(:query_inventory).returns(@inventory)
292
+ InventorySync::Async::InventoryFullSync.any_instance.expects(:affected_host_ids).returns([@host1.id, @host2.id])
293
+ FactoryBot.create(:fact_value, fact_name: fact_names['virt::uuid'], value: '1234', host: @host2)
294
+
295
+ ForemanTasks.sync_task(InventorySync::Async::InventoryFullSync, @host1.organization)
296
+ @host2.reload
297
+
298
+ assert_nil InventorySync::InventoryStatus.where(host_id: @host3.id).first
299
+ end
274
300
  end
@@ -265,4 +265,19 @@ class InventoryHostsSyncTest < ActiveSupport::TestCase
265
265
 
266
266
  assert_equal @host2_inventory_id, @host2.insights.uuid
267
267
  end
268
+
269
+ test 'Inventory should sync empty facets list' do
270
+ empty_inventory = @inventory.deep_clone
271
+ empty_inventory['results'] = []
272
+ InventorySync::Async::InventoryHostsSync.any_instance.expects(:query_inventory).returns(empty_inventory)
273
+ InventorySync::Async::InventoryHostsSync.any_instance.expects(:plan_self_host_sync)
274
+
275
+ assert_nil @host2.insights
276
+
277
+ ForemanTasks.sync_task(InventorySync::Async::InventoryHostsSync)
278
+
279
+ @host2.reload
280
+
281
+ assert_nil @host2.insights
282
+ end
268
283
  end
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: 3.0.28
4
+ version: 3.0.29
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-11-04 00:00:00.000000000 Z
11
+ date: 2021-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: katello