From 3c802d3f5c282880379e5e847193996adbf7e75d Mon Sep 17 00:00:00 2001 From: felipedf Date: Fri, 9 Nov 2018 10:31:45 -0300 Subject: [PATCH] Enhancement on PhysicalDisks test --- .../parser/component_parser/canister.rb | 25 ++++++++--- .../definitions/physical_infra_collections.rb | 4 +- .../physical_infra_manager/refresher_spec.rb | 45 +++++++++++-------- .../physical_infra_manager/full_refresh.yml | 13 ++++++ 4 files changed, 62 insertions(+), 25 deletions(-) diff --git a/app/models/manageiq/providers/lenovo/inventory/parser/component_parser/canister.rb b/app/models/manageiq/providers/lenovo/inventory/parser/component_parser/canister.rb index 88bc9296bb..08c43aade7 100644 --- a/app/models/manageiq/providers/lenovo/inventory/parser/component_parser/canister.rb +++ b/app/models/manageiq/providers/lenovo/inventory/parser/component_parser/canister.rb @@ -38,7 +38,7 @@ def build(storage_xclarity, parent) canister = @persister.canisters.build(data[:parsed_canister]) - build_associations(canister, data[:raw_data]) + build_associations(parent[:object], canister, data[:raw_data]) end end @@ -46,9 +46,10 @@ def build(storage_xclarity, parent) # @param canister [InventoryObject] # @param canister_raw_data [Hash] - def build_associations(canister, canister_raw_data) + def build_associations(storage, canister, canister_raw_data) comp_system = build_computer_system(canister) build_hardware(comp_system, canister_raw_data) + build_physical_disks(storage, canister, canister_raw_data) end def build_hardware(comp_system, canister_raw_data) @@ -66,12 +67,22 @@ def build_guest_devices(hardware, canister_properties) :object => hardware) end + def build_physical_disks(storage, canister, canister_raw_data) + driver_index = 0 + canister_raw_data.[]('drives')&.each do |drive| + components(:physical_disks).build(drive, driver_index.to_s, storage, canister) + driver_index += 1 + end + end + def parse_canisters_inside_components(components) canisters = [] + canister_index = 0 components.each do |component| component['canisters'].each do |canister| - canisters << { :parsed_canister => parse_canister(canister), + canisters << { :parsed_canister => parse_canister(canister, canister_index), :raw_data => canister } + canister_index += 1 end end canisters @@ -79,20 +90,24 @@ def parse_canisters_inside_components(components) def parse_canisters_inside_storage(storage) canisters = [] + canister_index = 0 storage.canisters.each do |canister| - canisters << { :parsed_canister => parse_canister(canister), + canisters << { :parsed_canister => parse_canister(canister, canister_index), :raw_data => canister } + canister_index += 1 end canisters end - def parse_canister(canister) + def parse_canister(canister, canister_index) result = {} CANISTER.each_pair do |key, canister_key| next unless canister_key.kind_of?(String) result[key] = canister[canister_key] end + result[:ems_ref] = (canister['uuid'] || '') + '_' + canister_index.to_s + result end end diff --git a/app/models/manageiq/providers/lenovo/inventory/persister/definitions/physical_infra_collections.rb b/app/models/manageiq/providers/lenovo/inventory/persister/definitions/physical_infra_collections.rb index ee82fdf920..a6d5ab5f11 100644 --- a/app/models/manageiq/providers/lenovo/inventory/persister/definitions/physical_infra_collections.rb +++ b/app/models/manageiq/providers/lenovo/inventory/persister/definitions/physical_infra_collections.rb @@ -2,8 +2,10 @@ module ManageIQ::Providers::Lenovo::Inventory::Persister::Definitions::PhysicalI extend ActiveSupport::Concern def initialize_physical_infra_inventory_collections - %i(customization_scripts + %i(canisters + customization_scripts physical_chassis + physical_disks physical_racks physical_servers physical_storages diff --git a/spec/models/manageiq/providers/lenovo/physical_infra_manager/refresher_spec.rb b/spec/models/manageiq/providers/lenovo/physical_infra_manager/refresher_spec.rb index 30d293b945..31804bc866 100644 --- a/spec/models/manageiq/providers/lenovo/physical_infra_manager/refresher_spec.rb +++ b/spec/models/manageiq/providers/lenovo/physical_infra_manager/refresher_spec.rb @@ -121,13 +121,13 @@ def assert_specific_server end def assert_specific_storage - storage = PhysicalStorage.find_by(:ems_ref => "208000C0FF2683AF") - storage_physical_disk_one = PhysicalDisk.find_by(:ems_ref => "208000C0FF2683AF_0") + storage = PhysicalStorage.find_by(:ems_ref => "123400C0FF261234") + canister = Canister.find_by(:ems_ref => "_0") + physical_disk_one = PhysicalDisk.find_by(:ems_ref => "123400C0FF261234_0") - expect(storage.name).to eq("S3200-1") - expect(storage.uid_ems).to eq("208000C0FF2683AF") - expect(storage.ems_ref).to eq("208000C0FF2683AF") - expect(storage.access_state).to eq("Online") + expect(storage.name).to eq("S8000-1") + expect(storage.uid_ems).to eq("123400C0FF261234") + expect(storage.ems_ref).to eq("123400C0FF261234") expect(storage.access_state).to eq("Online") expect(storage.health_state).to eq("Critical") expect(storage.overall_health_state).to eq("Critical") @@ -135,25 +135,32 @@ def assert_specific_storage expect(storage.drive_bays).to eq(12) expect(storage.enclosures).to eq(1) expect(storage.canister_slots).to eq(2) - expect(storage.physical_disks.count).to eq(4) - expect(storage.canisters.count).to eq(2) - - expect(storage_physical_disk_one.model).to eq("ST9300653SS") - expect(storage_physical_disk_one.vendor).to eq("IBM-ESXS") - expect(storage_physical_disk_one.status).to eq("Up") - expect(storage_physical_disk_one.location).to eq("0.22") - expect(storage_physical_disk_one.serial_number).to eq("6XN43QX50000B349D4LY") - expect(storage_physical_disk_one.health_state).to eq("OK") - expect(storage_physical_disk_one.controller_type).to eq("SAS") - expect(storage_physical_disk_one.disk_size).to eq("300.0GB") - expect(storage_physical_disk_one.physical_storage_id).to eq(storage.id) + expect(storage.physical_disks.size).to eq(1) + expect(storage.canisters.size).to eq(2) + + expect(canister.name).to eq("controller_a") + expect(canister.ems_ref).to eq("_0") + expect(canister.status).to eq("Operational") + expect(canister.controller_redundancy_status).to eq("Operational but not redundant") + expect(canister.physical_disks.size).to eq(1) + + expect(physical_disk_one.model).to eq("Canister_Driver_Model") + expect(physical_disk_one.vendor).to eq("Canister_Driver_Vendor") + expect(physical_disk_one.status).to eq("Up") + expect(physical_disk_one.location).to eq("0.50") + expect(physical_disk_one.serial_number).to eq("20183QX50000B3492018") + expect(physical_disk_one.health_state).to eq("OK") + expect(physical_disk_one.controller_type).to eq("SAS") + expect(physical_disk_one.disk_size).to eq("300.0GB") + expect(physical_disk_one.physical_storage_id).to eq(storage.id) + expect(physical_disk_one.canister_id).to eq(canister.id) end def assert_table_counts expect(PhysicalRack.count).to eq(3) expect(PhysicalServer.count).to eq(2) expect(PhysicalStorage.count).to eq(2) - expect(PhysicalDisk.count).to eq(4) + expect(PhysicalDisk.count).to eq(5) expect(GuestDevice.count).to eq(8) expect(PhysicalNetworkPort.count).to eq(50) end diff --git a/spec/vcr_cassettes/manageiq/providers/lenovo/physical_infra_manager/full_refresh.yml b/spec/vcr_cassettes/manageiq/providers/lenovo/physical_infra_manager/full_refresh.yml index a537fd426f..a3bcea94b9 100644 --- a/spec/vcr_cassettes/manageiq/providers/lenovo/physical_infra_manager/full_refresh.yml +++ b/spec/vcr_cassettes/manageiq/providers/lenovo/physical_infra_manager/full_refresh.yml @@ -1545,6 +1545,19 @@ http_interactions: "healthRecommendation":"", "ipAddress":"10.243.5.61" }, + "drives":[{ + "model": "Canister_Driver_Model", + "vendorName": "Canister_Driver_Vendor", + "status": "Up", + "location": "0.50", + "serialNumber": "20183QX50000B3492018", + "healthReason": "", + "health": "OK", + "type": "SAS", + "healthRecommendation": "", + "size": "300.0GB" + } + ], "diskChannels":2, "revision":"0", "cmmDisplayName":"controller_a",