+ <%= alert(:header => _('Warning: This will delete this host and all of its data!'),
+ :text => _("This host's stored facts and reports will be deleted too."),
+ :close => false,
+ :class => 'alert-warning'
+ ) %>
+
<%= image_tag 'spinner.gif' %>
+
+
+
+
+
diff --git a/config/environments/production.rb b/config/environments/production.rb
index 23de0857c622..42f747ba6886 100644
--- a/config/environments/production.rb
+++ b/config/environments/production.rb
@@ -83,6 +83,7 @@
ace/keybinding-emacs
diff
host_edit
+ hosts
jquery.cookie
host_checkbox
nfs_visibility
diff --git a/config/routes.rb b/config/routes.rb
index c22558a9a585..af2413a06b94 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -17,7 +17,8 @@
get 'clone'
get 'storeconfig_klasses'
get 'externalNodes'
- get 'setBuild'
+ get 'review_before_build'
+ put 'setBuild'
get 'cancelBuild'
get 'puppetrun'
get 'pxe_config'
diff --git a/test/functional/hosts_controller_test.rb b/test/functional/hosts_controller_test.rb
index 83378ddc6914..866055ac3d42 100644
--- a/test/functional/hosts_controller_test.rb
+++ b/test/functional/hosts_controller_test.rb
@@ -107,28 +107,66 @@ def test_update_valid
assert_template :text => @host.info.to_yaml
end
- test "when host is saved after setBuild, the flash should inform it" do
- Host.any_instance.stubs(:setBuild).returns(true)
- @request.env['HTTP_REFERER'] = hosts_path
-
- get :setBuild, {:id => @host.name}, set_session_user
- assert_response :found
- assert_redirected_to hosts_path
- assert_not_nil flash[:notice]
- assert flash[:notice] == "Enabled #{@host} for rebuild on next boot"
- end
-
test "when host is not saved after setBuild, the flash should inform it" do
Host.any_instance.stubs(:setBuild).returns(false)
@request.env['HTTP_REFERER'] = hosts_path
- get :setBuild, {:id => @host.name}, set_session_user
+ put :setBuild, {:id => @host.name}, set_session_user
assert_response :found
assert_redirected_to hosts_path
assert_not_nil flash[:error]
assert flash[:error] =~ /Failed to enable #{@host} for installation/
end
+ context "when host is saved after setBuild" do
+ setup do
+ @request.env['HTTP_REFERER'] = hosts_path
+ end
+
+ teardown do
+ Host::Managed.any_instance.unstub(:setBuild)
+ @request.env['HTTP_REFERER'] = ''
+ end
+
+ test "the flash should inform it" do
+ Host::Managed.any_instance.stubs(:setBuild).returns(true)
+ put :setBuild, {:id => @host.name}, set_session_user
+ assert_response :found
+ assert_redirected_to hosts_path
+ assert_not_nil flash[:notice]
+ assert flash[:notice] == "Enabled #{@host} for rebuild on next boot"
+ end
+
+ test 'and reboot was requested, the flash should inform it' do
+ Host::Managed.any_instance.stubs(:setBuild).returns(true)
+ # Setup a power mockup
+ class PowerShmocker
+ def reset
+ true
+ end
+ end
+ Host::Managed.any_instance.stubs(:power).returns(PowerShmocker.new())
+
+ put :setBuild, {:id => @host.name, :host => {:build => '1'}}, set_session_user
+ assert_response :found
+ assert_redirected_to hosts_path
+ assert_not_nil flash[:notice]
+ assert_equal(flash[:notice], "Enabled #{@host} for reboot and rebuild")
+ end
+
+ test 'and reboot requested and reboot failed, the flash should inform it' do
+ Host::Managed.any_instance.stubs(:setBuild).returns(true)
+ put :setBuild, {:id => @host.name, :host => {:build => '1'}}, set_session_user
+ assert_raise Foreman::Exception do
+ @host.power.reset
+ end
+ assert_response :found
+ assert_redirected_to hosts_path
+ assert_not_nil flash[:notice]
+ assert_equal(flash[:notice], "Enabled #{@host} for rebuild on next boot")
+ end
+ end
+
def test_clone
ComputeResource.any_instance.stubs(:vm_compute_attributes_for).returns({})
get :clone, {:id => Host.first.name}, set_session_user
@@ -788,6 +826,13 @@ class Host::Valid < Host::Base; end
refute host.compute_resource_id
end
+ test '#review_before_build' do
+ HostBuildStatus.any_instance.stubs(:host_status).returns(true)
+ xhr :get, :review_before_build, {:id => @host.name}, set_session_user
+ assert_response :success
+ assert_template 'review_before_build'
+ end
+
private
def initialize_host
User.current = users(:admin)
diff --git a/test/integration/host_test.rb b/test/integration/host_test.rb
index 10dd8fa72170..c0c2ad884c16 100644
--- a/test/integration/host_test.rb
+++ b/test/integration/host_test.rb
@@ -37,7 +37,7 @@ def setup
assert page.has_link?("Metrics", :href => "#metrics")
assert page.has_link?("Templates", :href => "#template")
assert page.has_link?("Edit", :href => "/hosts/#{@host.fqdn}/edit")
- assert page.has_link?("Build", :href => "/hosts/#{@host.fqdn}/setBuild")
+ assert page.has_link?("Build", :href => "/hosts/#{@host.fqdn}#review_before_build")
assert page.has_link?("Run puppet", :href => "/hosts/#{@host.fqdn}/puppetrun")
assert page.has_link?("Delete", :href => "/hosts/#{@host.fqdn}")
end
diff --git a/test/unit/host_build_status_test.rb b/test/unit/host_build_status_test.rb
new file mode 100644
index 000000000000..6bef6786df44
--- /dev/null
+++ b/test/unit/host_build_status_test.rb
@@ -0,0 +1,32 @@
+require 'test_helper'
+
+class HostBuildStatusTest < ActiveSupport::TestCase
+ attr_reader :build
+
+ setup do
+ User.current = users(:admin)
+ host = Host.new(:name => "myfullhost", :mac => "aabbecddeeff", :ip => "2.3.4.03", :ptable => ptables(:one), :medium => media(:one),
+ :domain => domains(:mydomain), :operatingsystem => operatingsystems(:redhat), :subnet => subnets(:one), :puppet_proxy => smart_proxies(:puppetmaster),
+ :subnet => subnets(:one), :architecture => architectures(:x86_64), :environment => environments(:production), :managed => true,
+ :owner_type => "User", :root_pass => "xybxa6JUkz63w")
+ @build = host.build_status
+ # bypass host.valid?
+ HostBuildStatus.any_instance.stubs(:host_status).returns(true)
+ end
+
+ test "should be able to render a template" do
+ assert_blank build.errors[:templates]
+ end
+
+ test "should fail rendering a template" do
+ host = FactoryGirl.create(:host, :managed)
+ kind = FactoryGirl.create(:template_kind)
+ config_template = FactoryGirl.create(:config_template, :template => "provision script <%= @foreman.server.status %>",:name => "My Failed Template", :template_kind => kind, :operatingsystem_ids => [host.operatingsystem_id], :environment_ids => [host.environment_id], :hostgroup_ids => [host.hostgroup_id] )
+ @build = host.build_status
+ refute_empty @build.errors[:templates]
+ end
+
+ test "should be able to refresh a smart proxy" do
+ assert_empty build.errors[:proxies]
+ end
+end