Skip to content

Commit

Permalink
Fixes #24852 - Creating Host with empty allocation fails
Browse files Browse the repository at this point in the history
  • Loading branch information
apuntamb authored and xprazak2 committed Nov 14, 2019
1 parent 376a7c3 commit 23dbf2c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
4 changes: 3 additions & 1 deletion app/models/compute_resources/foreman/model/libvirt.rb
Expand Up @@ -278,7 +278,9 @@ def create_volumes(args)
(volumes = args[:volumes]).each do |vol|
vol.name = "#{args[:prefix]}-disk#{volumes.index(vol) + 1}"
vol.capacity = "#{vol.capacity}G" unless vol.capacity.to_s.end_with?('G')
vol.allocation = "#{vol.allocation}G" unless vol.allocation.to_s.end_with?('G')
if vol.allocation.match(/^\d+/) && !vol.allocation.to_s.end_with?('G')
vol.allocation = "#{vol.allocation}G"
end
vol.save
vols << vol
end
Expand Down
4 changes: 2 additions & 2 deletions test/models/compute_resource_test.rb
Expand Up @@ -75,7 +75,7 @@ def setup
end

test "libvirt: 'G' suffix should be appended to libvirt volume capacity if none was specified" do
volume = OpenStruct.new(:capacity => 10)
volume = OpenStruct.new(:capacity => 10, :allocation => '10')
volume.stubs(:save!).returns(true)

result = Foreman::Model::Libvirt.new.send(:create_volumes, {:prefix => 'test', :volumes => [volume]})
Expand All @@ -84,7 +84,7 @@ def setup
end

test "libvirt: no exceptions should be raised if a 'G' suffix was specified for volume capacity" do
volume = OpenStruct.new(:capacity => "10G")
volume = OpenStruct.new(:capacity => "10G", :allocation => "10G")
volume.stubs(:save!).returns(true)

assert_nothing_raised { Foreman::Model::Libvirt.new.send(:create_volumes, {:prefix => 'test', :volumes => [volume]}) }
Expand Down
2 changes: 1 addition & 1 deletion webpack/assets/javascripts/compute_resource/libvirt.js
Expand Up @@ -97,7 +97,7 @@ export function allocationSwitcher(element, action) {
break;
case 'Size':
$(allocation).removeAttr('readonly');
allocation.value = '';
allocation.value = '0G';
$(allocation).focus();
break;
case 'Full':
Expand Down

0 comments on commit 23dbf2c

Please sign in to comment.