Skip to content

Commit

Permalink
Fixes #17496 - disable Boot disk button for non-intel arch
Browse files Browse the repository at this point in the history
  • Loading branch information
Swapnil Abnave authored and domcleal committed Dec 14, 2016
1 parent 80aed5e commit 889f60d
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 10 deletions.
34 changes: 24 additions & 10 deletions app/helpers/concerns/foreman_bootdisk/hosts_helper_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,34 @@ module ForemanBootdisk::HostsHelperExt
end

def host_title_actions_with_bootdisk(*args)
if @host.bootdisk_downloadable?
title_actions(
button_group(
select_action_button(_('Boot disk'), {:class => 'btn btn-group'},
display_bootdisk_link_if_authorized(_("Host '%s' image") % @host.name.split('.')[0], {:controller => 'foreman_bootdisk/disks', :action => 'host', :id => @host}, :class=>'la'),
display_bootdisk_link_if_authorized(_("Full host '%s' image") % @host.name.split('.')[0], {:controller => 'foreman_bootdisk/disks', :action => 'full_host', :id => @host}, :class=>'la'),
content_tag(:li, "", :class => "divider"),
display_bootdisk_link_if_authorized(_("Generic image"), {:controller => 'foreman_bootdisk/disks', :action => 'generic'}, :class=>'la'),
display_bootdisk_for_subnet,
content_tag(:li, "", :class => "divider"),
display_bootdisk_link_if_authorized(_("Help"), {:controller => 'foreman_bootdisk/disks', :action => 'help'}, :class=>'la')
)
)
)
else
bootdisk_button_disabled
end

host_title_actions_without_bootdisk(*args)
end

def bootdisk_button_disabled
title_actions(
button_group(
select_action_button(_('Boot disk'), {:class => 'btn btn-group'},
display_bootdisk_link_if_authorized(_("Host '%s' image") % @host.name.split('.')[0], {:controller => 'foreman_bootdisk/disks', :action => 'host', :id => @host}, :class=>'la'),
display_bootdisk_link_if_authorized(_("Full host '%s' image") % @host.name.split('.')[0], {:controller => 'foreman_bootdisk/disks', :action => 'full_host', :id => @host}, :class=>'la'),
content_tag(:li, "", :class => "divider"),
display_bootdisk_link_if_authorized(_("Generic image"), {:controller => 'foreman_bootdisk/disks', :action => 'generic'}, :class=>'la'),
display_bootdisk_for_subnet,
content_tag(:li, "", :class => "divider"),
display_bootdisk_link_if_authorized(_("Help"), {:controller => 'foreman_bootdisk/disks', :action => 'help'}, :class=>'la')
)
link_to(_("Boot disk"), '#', :disabled => true, :class => 'btn btn-default',
:title => _("Boot disk download not available for %s architecture") % @host.architecture.name)
)
)
host_title_actions_without_bootdisk(*args)
end

# need to wrap this one in a test for template proxy presence
Expand Down
8 changes: 8 additions & 0 deletions app/models/concerns/foreman_bootdisk/host_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ def bootdisk?
managed? && bootdisk_build? && SETTINGS[:unattended]
end

def bootdisk_downloadable?
architecture.blank? || intel_arch?
end

def intel_arch?
/i.86|x86[_-]64/ =~ architecture.name
end

def validate_media_with_bootdisk?
validate_media_without_bootdisk? || (managed && bootdisk_build? && build?)
end
Expand Down
30 changes: 30 additions & 0 deletions test/unit/concerns/host_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,34 @@ class ForemanBootdisk::HostTest < ActiveSupport::TestCase
assert_equal false, h.bootdisk?
end
end

context "#bootdisk_downloadable?" do
test "should be true for 64 bit architecture" do
architecture = Architecture.where(:name => 'x86_64').first
host = FactoryGirl.build(:host, :managed, :architecture => architecture)

assert host.bootdisk_downloadable?
end

test "should be true for 32 bit architecture" do
architecture = FactoryGirl.create(:architecture, :name => 'i386')
host = FactoryGirl.build(:host, :managed, :architecture => architecture)

assert host.bootdisk_downloadable?
end

test "should be false for non-intel architecture" do
architecture = Architecture.where(:name => 's390').first
host = FactoryGirl.build(:host, :managed, :architecture => architecture)

assert_not host.bootdisk_downloadable?
end

test 'should be true if architecture is absent' do
host = FactoryGirl.build(:host, :managed, :architecture => nil)

assert_equal host.architecture, nil
assert host.bootdisk_downloadable?
end
end
end

0 comments on commit 889f60d

Please sign in to comment.