Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add safe navigation if ip is nil on hosts sync #900

Merged
merged 3 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion foreman_rh_cloud.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Gem::Specification.new do |s|
s.required_ruby_version = '>= 2.7', '< 4'

s.add_dependency 'foreman_ansible'
s.add_dependency 'foreman-tasks'
s.add_dependency 'foreman-tasks', '~> 9.0.0'
s.add_dependency 'katello'

s.add_development_dependency 'rdoc'
Expand Down
2 changes: 1 addition & 1 deletion lib/foreman_rh_cloud/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module ForemanRhCloud
VERSION = '9.0.56'.freeze
VERSION = '9.0.58'.freeze
end
2 changes: 1 addition & 1 deletion lib/inventory_sync/async/inventory_hosts_sync.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def to_missing_host_record(host_result, organization)

def to_ip_address_string(ip_addresses)
string_size = 0
ip_addresses.take_while { |address| (string_size += address.length) <= MAX_IP_STRING_SIZE }
ip_addresses&.take_while { |address| (string_size += address.length) <= MAX_IP_STRING_SIZE }
end

def plan_self_host_sync
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "foreman_rh_cloud",
"version": "9.0.56",
"version": "9.0.58",
"description": "Inventory Upload =============",
"main": "index.js",
"scripts": {
Expand Down
58 changes: 53 additions & 5 deletions test/jobs/inventory_hosts_sync_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,59 @@ class InventoryHostsSyncTest < ActiveSupport::TestCase

inventory_json = <<-INVENTORY_JSON
{
"total": 3,
"count": 3,
"total": 4,
"count": 4,
"page": 1,
"per_page": 3,
"per_page": 4,
"results": [
{
"insights_id": "72d29d75-dbbf-4121-9566-2f581ab77f39",
"rhel_machine_id": null,
"subscription_manager_id": "d29bde40-348e-437c-8acf-8fa98320fc1c",
"satellite_id": "bb72bf95-0a19-4090-8009-f0d8c68aca61",
"bios_uuid": "b48a7e5f-cb50-4029-a75e-366bf43db642",
"fqdn": "rhel81-demo.oss-lab.net",
"mac_addresses": [
"52:54:00:aa:12:12",
"00:00:00:00:00:00"
],
"external_id": null,
"id": "59ab38db-c25b-4fc7-bfb2-c8eb01d865a4",
"account": "1460290",
"display_name": "insights-rh71.example.com",
"ansible_host": null,
"facts": [
{
"namespace": "satellite",
"facts": {
"virtual_host_name": "virt-who-nobody.home-1",
"satellite_instance_id": "fc4d0cb0-a0b0-421e-b096-b028319b8e47",
"is_simple_content_access": false,
"distribution_version": "7.3",
"satellite_version": "6.8.4",
"organization_id": 1,
"is_hostname_obfuscated": false,
"virtual_host_uuid": "a90e6294-4766-420a-8dc0-3ec5b96d60ec"
}
},
{
"namespace": "yupana",
"facts": {
"report_platform_id": "d37afa50-08ce-4efb-a0e5-759c2a016661",
"report_slice_id": "5bf791d7-5e30-4a3c-929a-11dd9fa6eb72",
"source": "Satellite",
"yupana_host_id": "e85958b6-58db-4cfd-aeb6-01ee81bc0f43",
"account": "1460290"
}
}
],
"reporter": "puptoo",
"stale_timestamp": "2021-03-19T07:57:42.466399+00:00",
"stale_warning_timestamp": "2021-03-26T07:57:42.466399+00:00",
"culled_timestamp": "2021-04-02T07:57:42.466399+00:00",
"created": "2021-02-08T14:36:03.613880+00:00",
"updated": "2021-03-18T02:57:42.535250+00:00"
},
{
"insights_id": "72d29d75-dbbf-4121-9566-2f581ab77f36",
"rhel_machine_id": null,
Expand Down Expand Up @@ -307,7 +355,7 @@ def fact_names

ForemanTasks.sync_task(InventorySync::Async::InventoryHostsSync, [org])

assert_equal 2, InsightsMissingHost.count
assert_equal 3, InsightsMissingHost.count
end

test 'Inventory should remove old missing host records' do
Expand All @@ -324,6 +372,6 @@ def fact_names

ForemanTasks.sync_task(InventorySync::Async::InventoryHostsSync, [org])

assert_equal 2, InsightsMissingHost.count
assert_equal 3, InsightsMissingHost.count
end
end
Loading