Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #22933 - fix functional test case for reboot all hosts #413

Merged
merged 1 commit into from Mar 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 10 additions & 11 deletions test/functional/discovered_hosts_controller_test.rb
Expand Up @@ -103,7 +103,7 @@ def test_edit_form_quick_submit
assert managed_host.build
assert_redirected_to host_url(managed_host)
assert_equal hostgroup.id, managed_host.hostgroup_id
assert_match(/Successfully/, flash[:notice])
assert_match(/Successfully/, flash[:success])
end
end

Expand Down Expand Up @@ -178,7 +178,7 @@ def test_reboot_success
post :reboot, params: { :id => host.id }, session: set_session_user_default_manager
assert_redirected_to discovered_hosts_url
assert_nil flash[:error]
assert_equal "Rebooting host #{host.name}", flash[:notice]
assert_equal "Rebooting host #{host.name}", flash[:success]
end

def test_reboot_failure
Expand Down Expand Up @@ -208,7 +208,7 @@ def test_auto_provision_success
post :auto_provision, params: { :id => host.id }, session: set_session_user(User.current)
assert_response :redirect
assert_nil flash[:error]
assert_match(/^Host macaabbccddeeff.* was provisioned/, flash[:notice])
assert_match(/^Host macaabbccddeeff.* was provisioned/, flash[:success])
managed_host = Host.find(host.id)
assert managed_host.build
end
Expand All @@ -220,7 +220,7 @@ def test_auto_provision_no_rule_success
post :auto_provision, params: { :id => host.id }, session: set_session_user(User.current)
assert_response :redirect
assert_nil flash[:error]
assert_equal "No rule found for host macaabbccddeeff", flash[:notice]
assert_equal "No rule found for host macaabbccddeeff", flash[:success]
end

def test_auto_provision_all_success
Expand All @@ -238,7 +238,7 @@ def test_auto_provision_all_success
post :auto_provision_all, params: {}, session: set_session_user(User.current)
assert_response :redirect
assert_nil flash[:error]
assert_equal "Discovered hosts are provisioning now", flash[:notice]
assert_equal "Discovered hosts are provisioning now", flash[:success]
end

def test_auto_provision_all_no_rule_success
Expand All @@ -256,18 +256,17 @@ def test_auto_provision_all_no_rule_success
post :auto_provision_all, params: {}, session: set_session_user(User.current)
assert_response :redirect
assert_nil flash[:error]
assert_equal "Discovered hosts are provisioning now", flash[:notice]
assert_equal "Discovered hosts are provisioning now", flash[:success]
end

def test_reboot_all_success
@request.env["HTTP_REFERER"] = discovered_hosts_url
host = discover_host_from_facts(@facts)
::ForemanDiscovery::NodeAPI::PowerService.any_instance.expects(:reboot).returns(true)
post :reboot, params: { :id => host.id }, session: set_session_user_default_manager
post :reboot_all, params: { }, session: set_session_user_default_manager
assert_redirected_to discovered_hosts_url
assert_equal "Rebooting host #{host.name}", flash[:notice]
assert_nil flash[:error]
assert_equal "Rebooting host macaabbccddeeff", flash[:notice]
assert_equal "Discovered hosts are rebooting now", flash[:success]
end

def test_reboot_all_failure
Expand All @@ -277,7 +276,7 @@ def test_reboot_all_failure
post :reboot_all, params: { }, session: set_session_user_default_manager
assert_redirected_to discovered_hosts_url
assert_equal "Errors during reboot: #{host.name}: failed to reboot", flash[:error]
assert_nil flash[:notice]
assert_nil flash[:success]
end

def test_reboot_all_error
Expand All @@ -287,7 +286,7 @@ def test_reboot_all_error
post :reboot_all, params: { }, session: set_session_user_default_manager
assert_redirected_to discovered_hosts_url
assert_match(/ERF50-4973/, flash[:error])
assert_nil flash[:notice]
assert_nil flash[:success]
end

def test_no_dns_rebuild_if_dns_pending
Expand Down
2 changes: 0 additions & 2 deletions test/integration/discovered_hosts_test.rb
Expand Up @@ -5,8 +5,6 @@ class DiscoveredHostsTest < IntegrationTestWithJavascript
let(:discovered_host) { FactoryBot.create(:discovered_host, :with_facts) }
let(:discovered_hosts) { Host::Discovered.all }

extend Minitest::OptionalRetry

setup do
assert discovered_notification_blueprint
discovered_host.save!
Expand Down
20 changes: 14 additions & 6 deletions test/unit/host_discovered_test.rb
Expand Up @@ -152,12 +152,20 @@ class HostDiscoveredTest < ActiveSupport::TestCase
assert_equal 'e41f13cc3658',host.name
end

test "should refresh existing discovered" do
interface = mock()
interface.stubs(:host).returns(Host.create(:name => "xyz", :type => "Host::Discovered"))
::Nic::Managed.stubs(:where).with(:mac => @facts['discovery_bootif'].downcase, :primary => true).returns([interface])
host = discover_host_from_facts(@facts)
assert_equal 'xyz', host.name
test "should refresh facts and NICs of an existing discovered host" do
host1 = discover_host_from_facts(@facts)
assert_equal 'mace41f13cc3658', host1.name
assert_equal 'IBM System x -[7870K4G]-', host1.facts["productname"]
assert_equal 1, Host::Discovered.where(:name => 'mace41f13cc3658').count
assert_equal '10.35.27.3', host1.ip

@facts["ipaddress_eth0"] = "1.2.3.4"
@facts["productname"] = "Dishwasher DW400"
host2 = discover_host_from_facts(@facts)
assert_equal 'mace41f13cc3658', host2.name
assert_equal 'Dishwasher DW400', host2.facts["productname"]
assert_equal '1.2.3.4', host2.ip
assert_equal 1, Host::Discovered.where(:name => 'mace41f13cc3658').count
end

test "should raise when hostname fact cannot be found" do
Expand Down