handle creation errors more robustly
We have seen strange cases where creation of a new CIB object apparently failed: http://pastebin.suse.de/9346 Even though this is strange, we should certainly expect Pacemaker::CIBObject.from_name to return nil in a few cases, so we need to handle that properly.
This commit is contained in:
parent
7493171164
commit
4febff5dc7
@ -46,13 +46,16 @@ class Chef
|
||||
action :nothing
|
||||
end.run_action(:run)
|
||||
|
||||
cib_object = Pacemaker::CIBObject.from_name(new_resource.name)
|
||||
if cib_object.exists?
|
||||
new_resource.updated_by_last_action(true)
|
||||
::Chef::Log.info "Successfully configured #{cib_object}"
|
||||
else
|
||||
::Chef::Log.error "Failed to configure #{cib_object}"
|
||||
created_cib_object = Pacemaker::CIBObject.from_name(new_resource.name)
|
||||
|
||||
raise "Failed to create #{cib_object}" if created_cib_object.nil?
|
||||
unless created_cib_object.exists?
|
||||
# This case seems pretty unlikely
|
||||
raise "Definition missing for #{created_cib_object} after creation"
|
||||
end
|
||||
|
||||
new_resource.updated_by_last_action(true)
|
||||
::Chef::Log.info "Successfully configured #{created_cib_object}"
|
||||
end
|
||||
|
||||
def standard_delete_resource
|
||||
|
@ -110,6 +110,28 @@ describe "Chef::Provider::PacemakerPrimitive" do
|
||||
expect(@resource).to be_updated
|
||||
end
|
||||
|
||||
it "should barf if crm fails to create the primitive" do
|
||||
stub_shellout("", ["crm configure failed", "oh noes", 3])
|
||||
|
||||
expect { provider.run_action :create }.to \
|
||||
raise_error(RuntimeError, "Failed to create #{fixture}")
|
||||
|
||||
expect(@chef_run).to run_execute(fixture.crm_configure_command)
|
||||
expect(@resource).not_to be_updated
|
||||
end
|
||||
|
||||
# This scenario seems rather artificial and unlikely, but it doesn't
|
||||
# do any harm to test it.
|
||||
it "should barf if crm creates a primitive with empty definition" do
|
||||
stub_shellout("", "")
|
||||
|
||||
expect { provider.run_action :create }.to \
|
||||
raise_error(RuntimeError, "Failed to create #{fixture}")
|
||||
|
||||
expect(@chef_run).to run_execute(fixture.crm_configure_command)
|
||||
expect(@resource).not_to be_updated
|
||||
end
|
||||
|
||||
it "should barf if the primitive is already defined with the wrong agent" do
|
||||
existing_agent = "ocf:openstack:something-else"
|
||||
definition = fixture.definition_string.sub(fixture.agent, existing_agent)
|
||||
|
Loading…
x
Reference in New Issue
Block a user