diff --git a/app/models/manageiq/providers/amazon/cloud_manager/refresh_parser.rb b/app/models/manageiq/providers/amazon/cloud_manager/refresh_parser.rb index 001445b40..17f173a14 100644 --- a/app/models/manageiq/providers/amazon/cloud_manager/refresh_parser.rb +++ b/app/models/manageiq/providers/amazon/cloud_manager/refresh_parser.rb @@ -171,10 +171,10 @@ def self.key_pair_type def parse_image(image, is_public) uid = image.image_id location = image.image_location - guest_os = (image.platform == "windows") ? "windows" : "linux" - if guest_os == "linux" + guest_os = image.platform == "windows" ? "windows_generic" : "linux_generic" + if guest_os == "linux_generic" guest_os = OperatingSystem.normalize_os_name(location) - guest_os = "linux" if guest_os == "unknown" + guest_os = "linux_generic" if guest_os == "unknown" end name = get_from_tags(image, :name) @@ -198,7 +198,9 @@ def parse_image(image, is_public) # the is_public flag here avoids having to make an additional API call # per image, since we already know whether it's a public image :publicly_available => is_public, - + :operating_system => { + :product_name => guest_os # FIXME: duplicated information used by some default reports + }, :hardware => { :guest_os => guest_os, :bitness => architecture_to_bitness(image.architecture), @@ -273,7 +275,9 @@ def parse_instance(instance) parent_image = @data_index.fetch_path(:vms, instance.image_id) if parent_image new_result[:parent_vm] = parent_image - new_result.store_path(:hardware, :guest_os, parent_image.fetch_path(:hardware, :guest_os)) + guest_os = parent_image.fetch_path(:hardware, :guest_os) + new_result.store_path(:hardware, :guest_os, guest_os) + new_result.store_path(:operating_system, :product_name, guest_os) # FIXME: duplicated information used by some default reports end if flavor[:ephemeral_disk_count] > 0 diff --git a/app/models/manageiq/providers/amazon/inventory/parser/cloud_manager.rb b/app/models/manageiq/providers/amazon/inventory/parser/cloud_manager.rb index ee91417bf..f81f9848c 100644 --- a/app/models/manageiq/providers/amazon/inventory/parser/cloud_manager.rb +++ b/app/models/manageiq/providers/amazon/inventory/parser/cloud_manager.rb @@ -58,15 +58,16 @@ def images(images) ) image_hardware(persister_image, image) + image_operating_system(persister_image, image) vm_and_template_labels(persister_image, image["tags"] || []) end end def image_hardware(persister_image, image) - guest_os = image['platform'] == "windows" ? "windows" : "linux" - if guest_os == "linux" + guest_os = image['platform'] == "windows" ? "windows_generic" : "linux_generic" + if guest_os == "linux_generic" guest_os = OperatingSystem.normalize_os_name(image['image_location']) - guest_os = "linux" if guest_os == "unknown" + guest_os = "linux_generic" if guest_os == "unknown" end persister.hardwares.find_or_build(persister_image).assign_attributes( @@ -77,6 +78,13 @@ def image_hardware(persister_image, image) ) end + def image_operating_system(persister_image, image) + persister.operating_systems.find_or_build(persister_image).assign_attributes( + # FIXME: duplicated information used by some default reports + :product_name => persister.hardwares.lazy_find(image['image_id'], :key => :guest_os) + ) + end + def vm_and_template_labels(resource, tags) tags.each do |tag| persister.vm_and_template_labels.find_or_build_by(:resource => resource, :name => tag["key"]).assign_attributes( @@ -192,6 +200,7 @@ def instances ) instance_hardware(persister_instance, instance, flavor) + instance_operating_system(persister_instance, instance) vm_and_template_labels(persister_instance, instance["tags"] || []) end end @@ -213,6 +222,13 @@ def instance_hardware(persister_instance, instance, flavor) hardware_disks(persister_hardware, instance, flavor) end + def instance_operating_system(persister_instance, instance) + persister.operating_systems.find_or_build(persister_instance).assign_attributes( + # FIXME: duplicated information used by some default reports + :product_name => persister.hardwares.lazy_find(instance['image_id'], :key => :guest_os) + ) + end + def hardware_networks(persister_hardware, instance) hardware_network(persister_hardware, instance['private_ip_address'].presence, diff --git a/app/models/manageiq/providers/amazon/inventory/persister/cloud_manager.rb b/app/models/manageiq/providers/amazon/inventory/persister/cloud_manager.rb index 4f5c98284..fbff77988 100644 --- a/app/models/manageiq/providers/amazon/inventory/persister/cloud_manager.rb +++ b/app/models/manageiq/providers/amazon/inventory/persister/cloud_manager.rb @@ -2,7 +2,7 @@ class ManageIQ::Providers::Amazon::Inventory::Persister::CloudManager < ManageIQ def initialize_inventory_collections add_inventory_collections( cloud, - %i(vms miq_templates hardwares networks disks availability_zones vm_and_template_labels + %i(vms miq_templates hardwares operating_systems networks disks availability_zones vm_and_template_labels flavors key_pairs orchestration_stacks orchestration_stacks_resources orchestration_stacks_outputs orchestration_stacks_parameters orchestration_templates) ) diff --git a/app/models/manageiq/providers/amazon/inventory/persister/target_collection.rb b/app/models/manageiq/providers/amazon/inventory/persister/target_collection.rb index a4679beae..8ebfdfcd6 100644 --- a/app/models/manageiq/providers/amazon/inventory/persister/target_collection.rb +++ b/app/models/manageiq/providers/amazon/inventory/persister/target_collection.rb @@ -16,8 +16,8 @@ def initialize_inventory_collections # Child models with references in the Parent InventoryCollections for Cloud add_inventory_collections( cloud, - %i(hardwares networks disks vm_and_template_labels orchestration_stacks_resources orchestration_stacks_outputs - orchestration_stacks_parameters) + %i(hardwares operating_systems networks disks vm_and_template_labels orchestration_stacks_resources + orchestration_stacks_outputs orchestration_stacks_parameters) ) add_inventory_collection(cloud.orchestration_templates) diff --git a/app/models/manageiq/providers/amazon/inventory_collection_default/cloud_manager.rb b/app/models/manageiq/providers/amazon/inventory_collection_default/cloud_manager.rb index 0736b2c92..73c268ca9 100644 --- a/app/models/manageiq/providers/amazon/inventory_collection_default/cloud_manager.rb +++ b/app/models/manageiq/providers/amazon/inventory_collection_default/cloud_manager.rb @@ -72,6 +72,16 @@ def hardwares(extra_attributes = {}) super(attributes.merge!(extra_attributes)) end + def operating_systems(extra_attributes = {}) + attributes = { + :inventory_object_attributes => [ + :product_name, + ] + } + + super(attributes.merge!(extra_attributes)) + end + def networks(extra_attributes = {}) attributes = { :inventory_object_attributes => [ diff --git a/spec/models/manageiq/providers/amazon/aws_refresher_spec_common.rb b/spec/models/manageiq/providers/amazon/aws_refresher_spec_common.rb index 389f48a1b..169148eb6 100644 --- a/spec/models/manageiq/providers/amazon/aws_refresher_spec_common.rb +++ b/spec/models/manageiq/providers/amazon/aws_refresher_spec_common.rb @@ -273,12 +273,16 @@ def assert_specific_template ) expect(@template.ext_management_system).to eq(@ems) - expect(@template.operating_system).to be_nil # TODO: This should probably not be nil + expect(@template.operating_system).to( + have_attributes( + :product_name => "linux_generic", + ) + ) expect(@template.custom_attributes.size).to eq(0) expect(@template.snapshots.size).to eq(0) expect(@template.hardware).to have_attributes( - :guest_os => "linux", + :guest_os => "linux_generic", :guest_os_full_name => nil, :bios => nil, :annotation => nil, @@ -336,7 +340,11 @@ def assert_specific_template_2 ) expect(@template2.ext_management_system).to eq(@ems) - expect(@template2.operating_system).to be_nil # TODO: This should probably not be nil + expect(@template2.operating_system).to( + have_attributes( + :product_name => "linux_redhat", + ) + ) expect(@template2.custom_attributes.size).to eq(0) expect(@template2.snapshots.size).to eq(0) @@ -520,13 +528,17 @@ def assert_specific_vm_powered_on expect(v.security_groups) .to match_array [sg_2, @sg] - expect(v.operating_system).to be_nil # TODO: This should probably not be nil + expect(v.operating_system).to( + have_attributes( + :product_name => "linux_generic", + ) + ) expect(v.custom_attributes.size).to eq(2) expect(v.snapshots.size).to eq(0) # expect(v.tags.size).to eq(0) expect(v.hardware).to have_attributes( - :guest_os => "linux", + :guest_os => "linux_generic", :guest_os_full_name => nil, :bios => nil, :annotation => nil, @@ -613,7 +625,11 @@ def assert_specific_vm_powered_off .where(:name => "EmsRefreshSpec-SecurityGroup2").first expect(v.security_groups) .to match_array [sg_2, @sg] - expect(v.operating_system).to be_nil # TODO: This should probably not be nil + expect(v.operating_system).to( + have_attributes( + :product_name => "linux_generic", + ) + ) expect(v.custom_attributes.size).to eq(2) expect(v.custom_attributes.find_by(:name => "Name").value).to eq("EmsRefreshSpec-PoweredOff") expect(v.custom_attributes.find_by(:name => "owner").value).to eq("UNKNOWN") @@ -622,7 +638,7 @@ def assert_specific_vm_powered_off expect(v.hardware).to have_attributes( :config_version => nil, :virtual_hw_version => nil, - :guest_os => "linux", + :guest_os => "linux_generic", :cpu_sockets => 1, :bios => nil, :bios_location => nil, @@ -720,7 +736,11 @@ def assert_specific_vm_on_cloud_network ] expect(v.load_balancer_health_check_states_with_reason).to match_array healt_check_states_with_reason - expect(v.operating_system).to be_nil # TODO: This should probably not be nil + expect(v.operating_system).to( + have_attributes( + :product_name => "linux_generic", + ) + ) expect(v.custom_attributes.size).to eq(2) expect(v.custom_attributes.find_by(:name => "Name").value).to eq("EmsRefreshSpec-PoweredOn-VPC") expect(v.custom_attributes.find_by(:name => "owner").value).to eq("UNKNOWN") @@ -730,7 +750,7 @@ def assert_specific_vm_on_cloud_network have_attributes( :config_version => nil, :virtual_hw_version => nil, - :guest_os => "linux", + :guest_os => "linux_generic", :cpu_sockets => 1, :bios => nil, :bios_location => nil, @@ -864,7 +884,17 @@ def assert_specific_vm_on_cloud_network_public_ip expect(v.network_ports.first.ipaddresses).to match_array([@ip2.fixed_ip_address, @ip2.address]) expect(v.ipaddresses).to match_array([@ip2.fixed_ip_address, @ip2.address]) - expect(v.operating_system).to be_nil # TODO: This should probably not be nil + if options.inventory_object_refresh + expect(v.operating_system).to( + have_attributes( + :product_name => "linux_redhat", + ) + ) + else + # Old refresh can't fetch the public image and there fore also operating_system + expect(v.operating_system).to be_nil + end + expect(v.custom_attributes.size).to eq(2) expect(v.custom_attributes.find_by(:name => "Name").value).to eq("EmsRefreshSpec-PoweredOn-VPC1") expect(v.custom_attributes.find_by(:name => "owner").value).to eq("UNKNOWN") @@ -874,7 +904,7 @@ def assert_specific_vm_on_cloud_network_public_ip have_attributes( :config_version => nil, :virtual_hw_version => nil, - :guest_os => @template2.try(:hardware).try(:guest_os), + :guest_os => options.inventory_object_refresh ? "linux_redhat" : nil, :cpu_sockets => 1, :bios => nil, :bios_location => nil, diff --git a/spec/models/manageiq/providers/amazon/aws_refresher_spec_counts.rb b/spec/models/manageiq/providers/amazon/aws_refresher_spec_counts.rb index 47d038441..d0968b00d 100644 --- a/spec/models/manageiq/providers/amazon/aws_refresher_spec_counts.rb +++ b/spec/models/manageiq/providers/amazon/aws_refresher_spec_counts.rb @@ -137,6 +137,7 @@ def table_counts_from_api :network => networks_count, :network_port => network_ports_count, :network_router => network_routers_count, + :operating_system => instances_and_images_count, :orchestration_stack => orchestration_stacks_count, :orchestration_stack_output => orchestration_stack_outputs_count, :orchestration_stack_parameter => orchestration_stack_parameters_count, diff --git a/spec/models/manageiq/providers/amazon/cloud_manager/stubbed_refresher_spec.rb b/spec/models/manageiq/providers/amazon/cloud_manager/stubbed_refresher_spec.rb index 8f4c88af6..7d7a02c75 100644 --- a/spec/models/manageiq/providers/amazon/cloud_manager/stubbed_refresher_spec.rb +++ b/spec/models/manageiq/providers/amazon/cloud_manager/stubbed_refresher_spec.rb @@ -147,7 +147,7 @@ def expected_table_counts(disconnect = nil) :guest_device => 0, :hardware => vm_count_plus_disconnect_inv + image_count_plus_disconnect_inv, :network => vm_count_plus_disconnect_inv * 2, - :operating_system => 0, + :operating_system => vm_count_plus_disconnect_inv + image_count_plus_disconnect_inv, :snapshot => 0, :system_service => 0, :relationship => vm_count_plus_disconnect_inv + image_count_plus_disconnect_inv, diff --git a/spec/models/manageiq/providers/amazon/cloud_manager/vcr_specs/refresher_other_region_spec.rb b/spec/models/manageiq/providers/amazon/cloud_manager/vcr_specs/refresher_other_region_spec.rb index dafd4c038..b5d341c43 100644 --- a/spec/models/manageiq/providers/amazon/cloud_manager/vcr_specs/refresher_other_region_spec.rb +++ b/spec/models/manageiq/providers/amazon/cloud_manager/vcr_specs/refresher_other_region_spec.rb @@ -45,6 +45,8 @@ def table_counts_from_api counts = super counts[:network_router] = 0 # We do not collect NetworkRouters in old refresh + # Old refresh can't fetch some images, those will have missing operating_system + counts[:operating_system] = counts[:operating_system] - Vm.all.select { |x| x.genealogy_parent.nil? }.count counts end end @@ -146,12 +148,16 @@ def assert_specific_template ) expect(@template.ext_management_system).to eq(@ems) - expect(@template.operating_system).to be_nil # TODO: This should probably not be nil + expect(@template.operating_system).to( + have_attributes( + :product_name => "linux_generic", + ) + ) expect(@template.custom_attributes.size).to eq(0) expect(@template.snapshots.size).to eq(0) expect(@template.hardware).to have_attributes( - :guest_os => "linux", + :guest_os => "linux_generic", :guest_os_full_name => nil, :bios => nil, :annotation => nil, @@ -202,12 +208,16 @@ def assert_specific_vm_powered_on expect(v.cloud_subnet).to be_nil expect(v.security_groups).to eq([@sg]) expect(v.key_pairs).to eq([@kp]) - expect(v.operating_system).to be_nil # TODO: This should probably not be nil + expect(v.operating_system).to( + have_attributes( + :product_name => "linux_generic", + ) + ) expect(v.custom_attributes.size).to eq(1) expect(v.snapshots.size).to eq(0) expect(v.hardware).to have_attributes( - :guest_os => "linux", + :guest_os => "linux_generic", :guest_os_full_name => nil, :bios => nil, :annotation => nil, diff --git a/spec/models/manageiq/providers/amazon/cloud_manager/vcr_specs/refresher_spec.rb b/spec/models/manageiq/providers/amazon/cloud_manager/vcr_specs/refresher_spec.rb index 41c4baceb..36d7b3e8a 100644 --- a/spec/models/manageiq/providers/amazon/cloud_manager/vcr_specs/refresher_spec.rb +++ b/spec/models/manageiq/providers/amazon/cloud_manager/vcr_specs/refresher_spec.rb @@ -41,6 +41,8 @@ def table_counts_from_api counts = super counts[:network_router] = 0 # We do not collect NetworkRouters in old refresh + # Old refresh can't fetch some images, those will have missing operating_system + counts[:operating_system] = counts[:operating_system] - Vm.all.select { |x| x.genealogy_parent.nil? }.count counts end end diff --git a/spec/models/manageiq/providers/amazon/cloud_manager/vcr_specs/targeted_refresh_spec.rb b/spec/models/manageiq/providers/amazon/cloud_manager/vcr_specs/targeted_refresh_spec.rb index fae87b9f2..1c0182e04 100644 --- a/spec/models/manageiq/providers/amazon/cloud_manager/vcr_specs/targeted_refresh_spec.rb +++ b/spec/models/manageiq/providers/amazon/cloud_manager/vcr_specs/targeted_refresh_spec.rb @@ -44,21 +44,22 @@ assert_specific_vm_powered_on assert_counts( - :auth_private_key => 1, - :availability_zone => 1, - :cloud_volume => 1, - :custom_attribute => 2, - :disk => 1, - :firewall_rule => 13, - :flavor => 3, - :floating_ip => 2, - :hardware => 2, - :miq_template => 1, - :network => 2, - :network_port => 2, - :security_group => 2, - :vm => 1, - :vm_or_template => 2 + :auth_private_key => 1, + :availability_zone => 1, + :cloud_volume => 1, + :custom_attribute => 2, + :disk => 1, + :firewall_rule => 13, + :flavor => 3, + :floating_ip => 2, + :hardware => 2, + :operating_system => 2, + :miq_template => 1, + :network => 2, + :network_port => 2, + :security_group => 2, + :vm => 1, + :vm_or_template => 2 ) end end @@ -96,23 +97,24 @@ assert_specific_vm_on_cloud_network assert_counts( - :auth_private_key => 1, - :availability_zone => 1, - :cloud_network => 1, - :cloud_subnet => 1, - :cloud_volume => 2, - :custom_attribute => 2, - :disk => 2, - :firewall_rule => 3, - :flavor => 3, - :floating_ip => 3, - :hardware => 2, - :miq_template => 1, - :network => 2, - :network_port => 3, - :security_group => 1, - :vm => 1, - :vm_or_template => 2 + :auth_private_key => 1, + :availability_zone => 1, + :cloud_network => 1, + :cloud_subnet => 1, + :cloud_volume => 2, + :custom_attribute => 2, + :disk => 2, + :firewall_rule => 3, + :flavor => 3, + :floating_ip => 3, + :hardware => 2, + :operating_system => 2, + :miq_template => 1, + :network => 2, + :network_port => 3, + :security_group => 1, + :vm => 1, + :vm_or_template => 2 ) end end @@ -141,23 +143,24 @@ assert_specific_vm_on_cloud_network_public_ip assert_counts( - :auth_private_key => 1, - :availability_zone => 1, - :cloud_network => 1, - :cloud_subnet => 1, - :cloud_volume => 2, - :custom_attribute => 2, - :disk => 2, - :firewall_rule => 3, - :flavor => 3, - :floating_ip => 1, - :hardware => 2, - :miq_template => 1, - :network => 2, - :network_port => 1, - :security_group => 1, - :vm => 1, - :vm_or_template => 2 + :auth_private_key => 1, + :availability_zone => 1, + :cloud_network => 1, + :cloud_subnet => 1, + :cloud_volume => 2, + :custom_attribute => 2, + :disk => 2, + :firewall_rule => 3, + :flavor => 3, + :floating_ip => 1, + :hardware => 2, + :operating_system => 2, + :miq_template => 1, + :network => 2, + :network_port => 1, + :security_group => 1, + :vm => 1, + :vm_or_template => 2 ) end end @@ -306,6 +309,7 @@ :flavor => 3, :floating_ip => 1, :hardware => 2, + :operating_system => 2, :miq_template => 1, :network => 2, :network_port => 1,