Skip to content

Commit

Permalink
Merge pull request #170 from EsdrasVP/parse_physical_storage
Browse files Browse the repository at this point in the history
Parse Physical Storage
  • Loading branch information
agrare committed Jun 7, 2018
2 parents c4fd8e9 + b04de4c commit 239e89f
Show file tree
Hide file tree
Showing 9 changed files with 687 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ def parse_physical_server(node, compliance, rack = nil, chassis = nil)
PhysicalServerParser.parse_physical_server(node, compliance, rack, chassis)
end

def parse_physical_storage(node, rack = nil)
PhysicalStorageParser.parse_physical_storage(node, rack)
end

def parse_config_pattern(config_pattern)
ConfigPatternParser.parse_config_pattern(config_pattern)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class PhysicalInfraManager::Parser::ParserDictionaryConstants
MIQ_TYPES = {
"physical_server" => "ManageIQ::Providers::Lenovo::PhysicalInfraManager::PhysicalServer",
"physical_switch" => "ManageIQ::Providers::Lenovo::PhysicalInfraManager::PhysicalSwitch",
"physical_storage" => "ManageIQ::Providers::Lenovo::PhysicalInfraManager::PhysicalStorage",
"physical_chassis" => "ManageIQ::Providers::Lenovo::PhysicalInfraManager::PhysicalChassis",
"template" => "ManageIQ::Providers::Lenovo::PhysicalInfraManager::Template",
}.freeze
Expand Down Expand Up @@ -64,6 +65,38 @@ class PhysicalInfraManager::Parser::ParserDictionaryConstants
:vlan_key => 'PVID',
}.freeze

PHYSICAL_STORAGE = {
:name => 'name',
:uid_ems => 'uuid',
:ems_ref => 'uuid',
:access_state => 'accessState',
:overall_health_state => 'overallHealthState',
:drive_bays => 'driveBays',
:enclosures => 'enclosureCount',
:canister_slots => 'canisterSlots',
:asset_detail => {
:product_name => 'productName',
:machine_type => 'machineType',
:model => 'model',
:serial_number => 'serialNumber',
:contact => 'contact',
:description => 'description',
:location => 'location.location',
:room => 'location.room',
:rack_name => 'location.rack',
:lowest_rack_unit => 'location.lowestRackUnit',
},
:computer_system => {
:hardware => {
:guest_devices => '',
},
},
}.freeze

PHYSICAL_STORAGE_NETWORK = {
:ipaddress => 'mgmtProcIPaddress',
}.freeze

PHYSICAL_CHASSIS = {
:name => 'name',
:uid_ems => 'uuid',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module ManageIQ::Providers::Lenovo
class PhysicalInfraManager::Parser::PhysicalStorageParser < PhysicalInfraManager::Parser::ComponentParser
class << self
#
# Parse a storage into a hash
#
# @param [Hash] storage_hash - hash containing physical storage raw data
# @param [Hash] rack - parsed physical rack data
#
# @return [Hash] containing the physical storage information
#
def parse_physical_storage(storage_hash, rack)
storage = XClarityClient::Storage.new(storage_hash)
result = parse(storage, parent::ParserDictionaryConstants::PHYSICAL_STORAGE)

result[:physical_rack] = rack if rack
result[:type] = parent::ParserDictionaryConstants::MIQ_TYPES["physical_storage"]
result[:health_state] = parent::ParserDictionaryConstants::HEALTH_STATE_MAP[storage.cmmHealthState.nil? ? storage.cmmHealthState : storage.cmmHealthState.downcase]
result[:computer_system][:hardware] = get_hardwares(storage)

return storage.uuid, result
end

private

def get_hardwares(storage)
parsed_storage_network = parse(storage, parent::ParserDictionaryConstants::PHYSICAL_STORAGE_NETWORK)

{
:guest_devices => [{
:device_type => "management",
:network => parsed_storage_network
}]
}
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module ManageIQ::Providers
class Lenovo::PhysicalInfraManager::PhysicalStorage < ::PhysicalStorage
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@ def init_parser(connection)
self.class.parent::Parser.get_instance(version)
end

# Retrieve all physical infrastructure that can be obtained from the LXCA (racks, chassis, servers, switches)
# as XClarity objects and add it to the +@data+ as a hash.
# Retrieve all physical infrastructure that can be obtained from the
# LXCA (racks, chassis, servers, switches) as XClarity objects and
# add it to the +@data+ as a hash.
def get_all_physical_infra
@data[:physical_racks] = []
@data[:physical_chassis] = []
@data[:physical_servers] = []
@data[:physical_racks] = []
@data[:physical_chassis] = []
@data[:physical_storages] = []
@data[:physical_servers] = []

racks = get_plain_physical_racks
racks.each do |rack|
Expand Down Expand Up @@ -83,6 +85,13 @@ def get_all_physical_infra
@data[:physical_servers] << parsed_server
end
end

# Retrieve and parse storages that are inside the rack.
rack_storages = get_plain_physical_storages_inside_rack(rack)
rack_storages.each do |storage|
_, parsed_storage = @parser.parse_physical_storage(storage, parsed_rack)
@data[:physical_storages] << parsed_storage
end
end
end

Expand All @@ -101,6 +110,11 @@ def get_plain_physical_chassis_inside_rack(rack)
rack.chassisList.map { |chassis| chassis["itemInventory"] }
end

# Returns physical storages that are inside a rack.
def get_plain_physical_storages_inside_rack(rack)
rack.storageList.map { |storage| storage["itemInventory"] }
end

# Returns physical servers that are inside a chassis.
def get_plain_physical_servers_inside_chassis(chassis)
chassis["nodes"].reject { |node| node["type"] == "SCU" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,65 @@
end
end

context 'parse physical storages' do
before do
@result = ems_inv_to_hashes
end

it 'will retrieve physical storages' do
expect(@result[:physical_storages].size).to eq(1)
end

it 'will parse physical storage fields' do
physical_storage = @result[:physical_storages][0]
expected_type = "ManageIQ::Providers::Lenovo::PhysicalInfraManager::PhysicalStorage"

expect(physical_storage[:name]).to eq("S3200-1")
expect(physical_storage[:uid_ems]).to eq("208000C0FF2683AF")
expect(physical_storage[:ems_ref]).to eq("208000C0FF2683AF")
expect(physical_storage[:access_state]).to eq("Online")
expect(physical_storage[:access_state]).to eq("Online")
expect(physical_storage[:health_state]).to eq("Critical")
expect(physical_storage[:overall_health_state]).to eq("Critical")
expect(physical_storage[:type]).to eq(expected_type)
expect(physical_storage[:drive_bays]).to eq(12)
expect(physical_storage[:enclosures]).to eq(1)
expect(physical_storage[:canister_slots]).to eq(2)
end

it 'will parse physical storage asset detail data' do
physical_storage = @result[:physical_storages][0]
asset_detail = physical_storage[:asset_detail]

expect(asset_detail[:product_name]).to eq("S3200")
expect(asset_detail[:machine_type]).to eq("6411")
expect(asset_detail[:model]).to eq("S3200")
expect(asset_detail[:serial_number]).to eq("2683AF")
expect(asset_detail[:contact]).to eq("Bay Nguyen")
expect(asset_detail[:description]).to eq("RTP_S3200_1")
expect(asset_detail[:location]).to be_nil
expect(asset_detail[:room]).to be_nil
expect(asset_detail[:rack_name]).to be_nil
expect(asset_detail[:lowest_rack_unit]).to eq(0)
end

it 'will parse physical storage hardware data' do
physical_storage = @result[:physical_storages][0]
computer_system = physical_storage[:computer_system]
expect(computer_system).to_not be_nil

hardware = computer_system[:hardware]
expect(hardware).to_not be_nil
expect(hardware[:guest_devices]).to_not be_nil
expect(hardware[:guest_devices]).to be_kind_of(Array)
expect(hardware[:guest_devices].size).to eq(1)

guest_device = hardware[:guest_devices][0]
expect(guest_device[:device_type]).to eq("management")
expect(guest_device[:network][:ipaddress]).to eq("10.243.5.61")
end
end

context 'parse physical chassis' do
let(:result) do
VCR.use_cassette("#{described_class.name.underscore}_ems_inv_to_hashes") do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
result = refresher.parse_legacy_inventory(ems)

expect(result[:physical_servers].size).to eq(3)
expect(result[:physical_storages].size).to eq(1)
expect(result[:physical_chassis].size).to eq(1)
expect(result[:physical_racks].size).to eq(1)
end
Expand All @@ -78,6 +79,7 @@
assert_table_counts
assert_specific_rack
assert_specific_server
assert_specific_storage
assert_guest_table_contents
assert_physical_network_ports_table_content
end
Expand All @@ -101,10 +103,27 @@ def assert_specific_server
expect(server.physical_rack_id).to be_truthy
end

def assert_specific_storage
storage = PhysicalStorage.find_by(:ems_ref => "208000C0FF2683AF")

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.access_state).to eq("Online")
expect(storage.health_state).to eq("Critical")
expect(storage.overall_health_state).to eq("Critical")
expect(storage.type).to eq("ManageIQ::Providers::Lenovo::PhysicalInfraManager::PhysicalStorage")
expect(storage.drive_bays).to eq(12)
expect(storage.enclosures).to eq(1)
expect(storage.canister_slots).to eq(2)
end

def assert_table_counts
expect(PhysicalRack.count).to eq(3)
expect(PhysicalServer.count).to eq(2)
expect(GuestDevice.count).to eq(4)
expect(PhysicalStorage.count).to eq(1)
expect(GuestDevice.count).to eq(5)
expect(PhysicalNetworkPort.count).to eq(34)
end

Expand Down
Loading

0 comments on commit 239e89f

Please sign in to comment.