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 shared memory pools as Resource Pools #115

Merged
merged 10 commits into from Nov 14, 2022
Expand Up @@ -15,6 +15,8 @@ class ManageIQ::Providers::IbmPowerHmc::InfraManager < ManageIQ::Providers::Infr
require_nested :Vios
require_nested :Storage
require_nested :ResourcePool
require_nested :MemoryResourcePool
require_nested :ProcessorResourcePool

supports :create
supports :metrics
Expand Down
Expand Up @@ -25,7 +25,7 @@ def self.event_to_hash(event, ems_id)
when "LogicalPartition", "VirtualIOServer"
event_hash[:vm_ems_ref] = uuid
event_hash[:host_ems_ref] = host_uuid unless host_uuid.nil?
when "VirtualSwitch", "VirtualNetwork", "SharedProcessorPool"
when "VirtualSwitch", "VirtualNetwork", "SharedProcessorPool", "SharedMemoryPool"
event_hash[:host_ems_ref] = host_uuid unless host_uuid.nil?
when "UserTask"
event_hash[:message] = event.usertask["key"]
Expand Down
Expand Up @@ -48,7 +48,7 @@ def parse
new_targets.concat(handle_usertask(raw_event[:usertask]))
when "Cluster"
new_targets << {:assoc => :storages, :ems_ref => elems[:uuid]}
when "SharedProcessorPool"
when "SharedProcessorPool", "SharedMemoryPool"
new_targets << {:assoc => :resource_pools, :ems_ref => "#{elems[:manager_uuid]}_#{elems[:uuid]}"}
end

Expand Down
@@ -0,0 +1,2 @@
class ManageIQ::Providers::IbmPowerHmc::InfraManager::MemoryResourcePool < ManageIQ::Providers::IbmPowerHmc::InfraManager::ResourcePool
end
@@ -0,0 +1,2 @@
class ManageIQ::Providers::IbmPowerHmc::InfraManager::ProcessorResourcePool < ManageIQ::Providers::IbmPowerHmc::InfraManager::ResourcePool
end
Expand Up @@ -263,6 +263,17 @@ def shared_processor_pools
end.compact
end

def shared_memory_pools
@shared_memory_pools ||= cecs.flat_map do |sys|
connection.shared_memory_pool(sys.uuid)
rescue IbmPowerHmc::Connection::HttpNotFound
nil
rescue IbmPowerHmc::Connection::HttpError => e
$ibm_power_hmc_log.error("shared_memory_pool query failed for #{sys.uuid}: #{e}")
raise
end.compact
end

private

def cec_cpu_freq(sys)
Expand Down
Expand Up @@ -516,6 +516,11 @@ def self.parse_macaddr(macaddr)
end

def parse_resource_pools
parse_cpu_resource_pools
parse_mem_resource_pools
end

def parse_cpu_resource_pools
collector.shared_processor_pools.each do |pool|
next if pool.name =~ /^SharedPool\d\d$/ && pool.max == "0"

Expand All @@ -524,7 +529,8 @@ def parse_resource_pools
:uid_ems => ref,
:ems_ref => ref,
:name => pool.name,
:parent => persister.hosts.lazy_find(pool.sys_uuid)
:parent => persister.hosts.lazy_find(pool.sys_uuid),
:type => ManageIQ::Providers::IbmPowerHmc::InfraManager::ProcessorResourcePool.name
}
if pool.name == "DefaultPool"
params[:cpu_shares] = 0
Expand All @@ -543,4 +549,22 @@ def parse_resource_pools
persister.resource_pools.build(params)
end
end

def parse_mem_resource_pools
collector.shared_memory_pools.each do |pool|
ref = "#{pool.sys_uuid}_#{pool.uuid}"
persister.resource_pools.build(
:uid_ems => ref,
:ems_ref => ref,
:name => "DefaultMemPool",
:parent => persister.hosts.lazy_find(pool.sys_uuid),
:type => ManageIQ::Providers::IbmPowerHmc::InfraManager::MemoryResourcePool.name,
:memory_shares => pool.max_mb.to_i - pool.available_mb.to_i,
:memory_reserve => pool.available_mb,
:memory_reserve_expand => true,
:memory_limit => pool.max_mb,
:is_default => false
)
end
end
end
Expand Up @@ -126,6 +126,18 @@
end
end

context "SharedMemoryPool" do
let(:filename) { "test_data/shared_memory_pool.xml" }
it "#event_to_hash" do
expect(described_class.event_to_hash(event, nil)).to(
include(
:host_ems_ref => "d47a585d-eaa8-3a54-b4dc-93346276ea37",
:message => "Other"
)
)
end
end

context "UserTask" do
let(:filename) { "test_data/template.xml" }
it "#event_to_hash" do
Expand Down
Expand Up @@ -116,6 +116,12 @@
[[:resource_pools, {:ems_ref => 'd47a585d-eaa8-3a54-b4dc-93346276ea37_27aae064-2855-39a0-b4e6-e3c9b5572036'}]]
)
end
it "SharedMemoryPool" do
assert_event_triggers_target(
"test_data/shared_memory_pool.xml",
[[:resource_pools, {:ems_ref => 'd47a585d-eaa8-3a54-b4dc-93346276ea37_557f7755-a4dc-30de-816d-387f42dd8fd3'}]]
)
end
end

def assert_event_triggers_target(filename, expected_targets, usertask = nil)
Expand Down
@@ -1,10 +1,11 @@
describe ManageIQ::Providers::IbmPowerHmc::InfraManager::Refresher do
let(:host_uuid) { "0685d4a6-2021-3044-84e3-59f44e9cc5d7" }
let(:vios_uuid) { "4165A16F-0766-40F3-B9E2-7272E1910F2E" }
let(:lpar_uuid) { "646AE0BC-CF06-4F6B-83CB-7A3ECCF903E3" }
let(:template_uuid) { "84f2d0b8-d86e-4a51-a012-8ddc4339c1f7" }
let(:storage_uuid) { "8f2a83e9-f4c7-35e5-987e-9ac54a498dab" }
let(:respool_uuid) { "d47a585d-eaa8-3a54-b4dc-93346276ea37_c41d8844-1d39-3512-944d-50f58de2d42d" }
let(:host_uuid) { "0685d4a6-2021-3044-84e3-59f44e9cc5d7" }
let(:vios_uuid) { "4165A16F-0766-40F3-B9E2-7272E1910F2E" }
let(:lpar_uuid) { "646AE0BC-CF06-4F6B-83CB-7A3ECCF903E3" }
let(:template_uuid) { "84f2d0b8-d86e-4a51-a012-8ddc4339c1f7" }
let(:storage_uuid) { "8f2a83e9-f4c7-35e5-987e-9ac54a498dab" }
let(:respool_cpu_uuid) { "d47a585d-eaa8-3a54-b4dc-93346276ea37_c41d8844-1d39-3512-944d-50f58de2d42d" }
let(:respool_mem_uuid) { "d47a585d-eaa8-3a54-b4dc-93346276ea37_557f7755-a4dc-30de-816d-387f42dd8fd3" }

it ".ems_type" do
expect(described_class.ems_type).to eq(:ibm_power_hmc)
Expand All @@ -28,6 +29,7 @@
assert_specific_vios
assert_specific_lpar
assert_specific_template
assert_specific_resource_pool
end

def assert_ems
Expand Down Expand Up @@ -244,6 +246,17 @@ def assert_specific_template
:read_only => true
)
end

def assert_specific_resource_pool
cpu_pool = ems.resource_pools.find_by(:ems_ref => respool_cpu_uuid)
expect(cpu_pool).to have_attributes(
:type => "ManageIQ::Providers::IbmPowerHmc::InfraManager::ProcessorResourcePool"
)
mem_pool = ems.resource_pools.find_by(:ems_ref => respool_mem_uuid)
expect(mem_pool).to have_attributes(
:type => "ManageIQ::Providers::IbmPowerHmc::InfraManager::MemoryResourcePool"
)
end
end

context "#target_refresh" do
Expand Down Expand Up @@ -278,8 +291,12 @@ def target_refresh(target, example)
target_refresh(ems.storages.find_by(:ems_ref => storage_uuid), example)
end

it "resource_pool" do |example|
target_refresh(ems.resource_pools.find_by(:ems_ref => respool_uuid), example)
it "resource_pool (cpu)" do |example|
target_refresh(ems.resource_pools.find_by(:ems_ref => respool_cpu_uuid), example)
end

it "resource_pool (mem)" do |example|
target_refresh(ems.resource_pools.find_by(:ems_ref => respool_mem_uuid), example)
end
end

Expand Down
@@ -0,0 +1,31 @@
<feed xmlns:ns2='http://a9.com/-/spec/opensearch/1.1/' xmlns:ns3='http://www.w3.org/1999/xhtml' xmlns='http://www.w3.org/2005/Atom'>
<id>064240ce-c295-34cb-a0b5-8e6ee0e7a615</id>
<updated>2022-11-10T15:14:04.523+01:00</updated>
<link href='https://coophmc2:12443/rest/api/uom/Event' rel='SELF'/>
<link href='https://coophmc2:12443/rest/api/uom/ManagementConsole/67c67e9a-c027-3a3d-9399-ebe6aa14e12e' rel='MANAGEMENT_CONSOLE'/>
<generator>IBM Power Systems Management Console</generator>
<entry>
<id>c9e172c9-58b4-39dd-833f-567e0d52135e</id>
<title>Event</title>
<published>2022-11-10T15:14:05.240+01:00</published>
<link href='https://coophmc2:12443/rest/api/uom/Event/c9e172c9-58b4-39dd-833f-567e0d52135e' rel='SELF'/>
<author>
<name>IBM Power Systems Management Console</name>
</author>
<etag:etag xmlns:etag='http://www.ibm.com/xmlns/systems/power/firmware/uom/mc/2012_10/' xmlns='http://www.ibm.com/xmlns/systems/power/firmware/uom/mc/2012_10/'>116654840</etag:etag>
<content type='application/vnd.ibm.powervm.uom+xml; type=Event'>
<Event:Event xmlns:Event='http://www.ibm.com/xmlns/systems/power/firmware/uom/mc/2012_10/' xmlns:ns2='http://www.w3.org/XML/1998/namespace/k2' schemaVersion='V1_5_0' xmlns='http://www.ibm.com/xmlns/systems/power/firmware/uom/mc/2012_10/'>
<Metadata>
<Atom>
<AtomID>c9e172c9-58b4-39dd-833f-567e0d52135e</AtomID>
<AtomCreated>1668089645239</AtomCreated>
</Atom>
</Metadata>
<EventType kb='ROR' kxe='false'>MODIFY_URI</EventType>
<EventID kb='ROR' kxe='false'>1667807043782</EventID>
<EventData kb='ROR' kxe='false'>https://coophmc2:12443/rest/api/uom/ManagedSystem/d47a585d-eaa8-3a54-b4dc-93346276ea37/SharedMemoryPool/557f7755-a4dc-30de-816d-387f42dd8fd3</EventData>
<EventDetail kb='ROR' kxe='false'>Other</EventDetail>
</Event:Event>
</content>
</entry>
</feed>