Skip to content

Commit

Permalink
Merge pull request #9882 from masayag/support_decreasing_memory_in_re…
Browse files Browse the repository at this point in the history
…configure_vm

Update Guaranteed memory when updating VM's memory
(cherry picked from commit 7270d7d)
  • Loading branch information
blomquisg authored and chessbyte committed Aug 30, 2016
1 parent bf51bac commit 4322408
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
15 changes: 14 additions & 1 deletion app/models/manageiq/providers/redhat/infra_manager.rb
Expand Up @@ -218,7 +218,7 @@ def vm_reconfigure(vm, options = {})

vm.with_provider_object do |rhevm_vm|
_log.info("#{log_header} Started...")
rhevm_vm.memory = spec["memoryMB"] * 1.megabyte if spec["memoryMB"]
update_vm_memory(rhevm_vm, spec["memoryMB"] * 1.megabyte) if spec["memoryMB"]

cpu_options = {}
cpu_options[:cores] = spec["numCoresPerSocket"] if spec["numCoresPerSocket"]
Expand All @@ -229,6 +229,19 @@ def vm_reconfigure(vm, options = {})
_log.info("#{log_header} Completed.")
end

# RHEVM requires that the memory of the VM will be bigger or equal to the reserved memory at any given time.
# Therefore, increasing the memory of the vm should precede to updating the reserved memory, and the opposite:
# Decreasing the memory to a lower value than the reserved memory requires first to update the reserved memory
def update_vm_memory(rhevm_vm, memory)
if memory > rhevm_vm.attributes.fetch_path(:memory)
rhevm_vm.memory = memory
rhevm_vm.memory_reserve = memory
else
rhevm_vm.memory_reserve = memory
rhevm_vm.memory = memory
end
end

# Calculates an "ems_ref" from the "href" attribute provided by the oVirt REST API, removing the
# "/ovirt-engine/" prefix, as for historic reasons the "ems_ref" stored in the database does not
# contain it, it only contains the "/api" prefix which was used by older versions of the engine.
Expand Down
23 changes: 16 additions & 7 deletions spec/models/manageiq/providers/redhat/infra_manager_spec.rb
Expand Up @@ -35,22 +35,31 @@
@num_of_sockets = 3
@total_mem_in_mb = 4096

@spec = {"memoryMB" => @total_mem_in_mb,
"numCPUs" => @cores_per_socket * @num_of_sockets,
"numCoresPerSocket" => @cores_per_socket}

@rhevm_vm = double('rhevm_vm').as_null_object
@rhevm_vm_attrs = double('rhevm_vm_attrs')
allow(@rhevm_vm_attrs).to receive(:fetch_path).with(:memory).and_return(@total_mem_in_mb.megabytes)
@rhevm_vm = double('rhevm_vm')
allow(@rhevm_vm).to receive(:attributes).and_return(@rhevm_vm_attrs)
allow(@vm).to receive(:with_provider_object).and_yield(@rhevm_vm)
end

it "cpu_topology=" do
spec = {
"numCPUs" => @cores_per_socket * @num_of_sockets,
"numCoresPerSocket" => @cores_per_socket
}

expect(@rhevm_vm).to receive(:cpu_topology=).with(:cores => @cores_per_socket, :sockets => @num_of_sockets)
@ems.vm_reconfigure(@vm, :spec => @spec)
@ems.vm_reconfigure(@vm, :spec => spec)
end

it "memory=" do
spec = {
"memoryMB" => @total_mem_in_mb
}

expect(@rhevm_vm).to receive(:memory=).with(@total_mem_in_mb.megabytes)
@ems.vm_reconfigure(@vm, :spec => @spec)
expect(@rhevm_vm).to receive(:memory_reserve=).with(@total_mem_in_mb.megabytes)
@ems.vm_reconfigure(@vm, :spec => spec)
end
end

Expand Down

0 comments on commit 4322408

Please sign in to comment.