Skip to content

Commit

Permalink
Add Quota calculations for reconfigure resize disks
Browse files Browse the repository at this point in the history
Added test for disk_resize

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1533263
Made 2 changes as requested

Added log_and_raise for disk_names that are not found.
Added a test case where the disk_name doesn't exist

Modified error text to be generic
Removed embedded method
Included the disk name when we raise the exception
  • Loading branch information
billfitzgerald0120 committed Dec 5, 2018
1 parent 7e6c26d commit 0031d91
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def vmdb_object(model, id)

def get_disk_size(disk_name)
mydisk = $evm.vmdb('disk').find_by(:filename => disk_name)
raise "ERROR - Disk_name not found for Reconfiguration" if mydisk.nil?
raise "ERROR - #{disk_name} not found for Reconfiguration" if mydisk.nil?
mydisk.size.to_i
end

Expand All @@ -171,6 +171,13 @@ def requested_storage(args_hash)
args_hash[:prov_value] -= current_size
end
end
args_hash[:resource].options[:disk_resize]&.each do |disk|
# Disk_resize only supports increasing the size.
$evm.log(:info, "Reconfigure Disk Resize: #{disk.inspect}")
current_size = get_disk_size(disk['disk_name'])
$evm.log(:info, "Current disk size: #{current_size.to_s(:human_size)}")
args_hash[:prov_value] += disk['disk_size_in_mb'].to_i.megabytes - current_size
end
else
vm_size = args_hash[:resource].vm_template.provisioned_storage
args_hash[:prov_value] = vm_size
Expand Down
16 changes: 16 additions & 0 deletions spec/automation/unit/method_validation/requested_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,22 @@ def check_results(requested_hash, storage, cpu, vms, memory)
check_results(ws.root['quota_requested'], 10.megabytes, 2, 1, 4096.megabytes)
end

it "resize 10 to 20 megabyte disk, difference is 10" do
# Disk_resize only supports increasing the size.
setup_model("vmware_reconfigure")
@reconfigure_request.update_attributes(:options => {:src_ids => [@vm_vmware.id], :request_type => :vm_reconfigure,\
:disk_resize => [{"disk_name" => disk.filename, "disk_size_in_mb" => 20}]})
ws = run_automate_method(reconfigure_attrs)
check_results(ws.root['quota_requested'], 10.megabytes, 0, 1, 0)
end

it "resize a disk thats not found" do
setup_model("vmware_reconfigure")
@reconfigure_request.update_attributes(:options => {:src_ids => [@vm_vmware.id], :request_type => :vm_reconfigure,\
:disk_resize => [{"disk_name" => "not found", "disk_size_in_mb" => 20}]})
expect { run_automate_method(reconfigure_attrs) }.to raise_error(MiqAeException::UnknownMethodRc)
end

it "removes a disk " do
setup_model("vmware_reconfigure")
@reconfigure_request.update_attributes(:options => {:src_ids => [@vm_vmware.id], :request_type => :vm_reconfigure,\
Expand Down

0 comments on commit 0031d91

Please sign in to comment.