From 5869facf1a77cc1f8c98791ee5e52d812b053495 Mon Sep 17 00:00:00 2001 From: Rohini Chandra <61837065+r14chandra@users.noreply.github.com> Date: Thu, 3 Oct 2024 14:19:47 +0530 Subject: [PATCH] RHINENG-12954 Don't override OS and cloud provider value --- ros/lib/utils.py | 2 +- ros/processor/inventory_events_consumer.py | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/ros/lib/utils.py b/ros/lib/utils.py index 58546b2d..dc9ee01c 100644 --- a/ros/lib/utils.py +++ b/ros/lib/utils.py @@ -362,7 +362,7 @@ def system_allowed_in_ros(msg, reporter): msg.get('type') == 'updated' and is_platform_metadata_check_pass(msg) ): - return is_valid_cloud_provider(cloud_provider) + return is_valid_cloud_provider(cloud_provider) and is_valid_operating_system(operating_system) is_ros = msg["platform_metadata"].get("is_ros") return validate_ros_payload(is_ros, cloud_provider, operating_system) diff --git a/ros/processor/inventory_events_consumer.py b/ros/processor/inventory_events_consumer.py index bff9a5f2..d03c338b 100644 --- a/ros/processor/inventory_events_consumer.py +++ b/ros/processor/inventory_events_consumer.py @@ -5,7 +5,7 @@ from ros.lib import consume from ros.lib.app import app from ros.extensions import db, cache -from ros.lib.utils import get_or_create, system_allowed_in_ros, update_system_record, is_platform_metadata_check_pass +from ros.lib.utils import get_or_create, system_allowed_in_ros, update_system_record from confluent_kafka import KafkaException from ros.lib.models import RhAccount, System from ros.lib.config import ( @@ -149,16 +149,22 @@ def process_system_details(self, msg): host = msg['host'] with app.app_context(): # 'platform_metadata' field not included when the host is updated via the API. - if (msg.get('type') == 'updated' and is_platform_metadata_check_pass(msg)): + if (msg.get('type') == 'updated'): system_fields = { "inventory_id": host['id'], "display_name": host['display_name'], "fqdn": host['fqdn'], - "cloud_provider": host['system_profile']['cloud_provider'], "stale_timestamp": host['stale_timestamp'], - "operating_system": host['system_profile'].get('operating_system'), "groups": host.get('groups', []) } + + operating_system = host['system_profile'].get('operating_system') + cloud_provider = host['system_profile'].get('cloud_provider') + if (operating_system is not None): + system_fields.update({"operating_system": operating_system}) + if (cloud_provider is not None): + system_fields.update({"cloud_provider": cloud_provider}) + system = update_system_record(db.session, **system_fields) if system is not None: db.session.commit()