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 #2693 - don't cause handle_ca error when no Puppet CA associated with host #806

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions app/models/host/managed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,9 @@ def pm_fqdn
# Called after a host is given their provisioning template
# Returns : Boolean status of the operation
def handle_ca
return true if Rails.env == "test"
return true unless Setting[:manage_puppetca]
if puppetca?
respond_to?(:initialize_puppetca,true) && initialize_puppetca && delCertificate && setAutosign
end
return true unless puppetca?
respond_to?(:initialize_puppetca,true) && initialize_puppetca && delCertificate && setAutosign
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what am I missing? that it returned false before?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it returned nil before, which caused the controller to think it'd failed. You wrote this patch :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in that case 👍

end

# returns the host correct disk layout, custom or common
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/hosts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ dhcp:
subnet: one
domain: mydomain
puppet_proxy: puppetmaster
puppet_ca_proxy: puppetmaster
managed: true
compute_resource: one

Expand Down
4 changes: 4 additions & 0 deletions test/functional/unattended_controller_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
require 'test_helper'

class UnattendedControllerTest < ActionController::TestCase
setup do
Host::Managed.any_instance.stubs(:handle_ca).returns(true)
end

test "should get a kickstart" do
@request.env["HTTP_X_RHN_PROVISIONING_MAC_0"] = "eth0 #{hosts(:redhat).mac}"
get :kickstart
Expand Down
46 changes: 33 additions & 13 deletions test/unit/host_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -396,19 +396,39 @@ def setup_filtered_user
assert_equal ConfigTemplate.find_by_name("MyFinish"), host.configTemplate({:kind => "finish"})
end

test "when provisioning a new host we should not call puppetca if its disabled" do
# TODO improve this test :-)
Setting[:manage_puppetca] = false
assert hosts(:one).handle_ca
end

test "custom_disk_partition_with_erb" do
h = hosts(:one)
h.disk = "<%= 1 + 1 %>"
assert h.save
assert h.disk.present?
assert_equal "2", h.diskLayout
end
test "handle_ca must not perform actions when the manage_puppetca setting is false" do
h = hosts(:one)
Setting[:manage_puppetca] = false
h.expects(:initialize_puppetca).never()
h.expects(:setAutosign).never()
assert h.handle_ca
end

test "handle_ca must not perform actions when no Puppet CA proxy is associated" do
h = hosts(:one)
Setting[:manage_puppetca] = true
refute h.puppetca?
h.expects(:initialize_puppetca).never()
assert h.handle_ca
end

test "handle_ca must call initialize, delete cert and add autosign methods" do
h = hosts(:dhcp)
Setting[:manage_puppetca] = true
assert h.puppetca?
h.expects(:initialize_puppetca).returns(true)
h.expects(:delCertificate).returns(true)
h.expects(:setAutosign).returns(true)
assert h.handle_ca
end

test "custom_disk_partition_with_erb" do
h = hosts(:one)
h.disk = "<%= 1 + 1 %>"
assert h.save
assert h.disk.present?
assert_equal "2", h.diskLayout
end

test "models are updated when host.model has no value" do
h = hosts(:one)
Expand Down