diff --git a/libraries/chef/mixin/pacemaker/standard_cib_object.rb b/libraries/chef/mixin/pacemaker/standard_cib_object.rb index 45fd0c6..0490d9b 100644 --- a/libraries/chef/mixin/pacemaker/standard_cib_object.rb +++ b/libraries/chef/mixin/pacemaker/standard_cib_object.rb @@ -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 diff --git a/spec/providers/primitive_spec.rb b/spec/providers/primitive_spec.rb index f005698..b6cd746 100644 --- a/spec/providers/primitive_spec.rb +++ b/spec/providers/primitive_spec.rb @@ -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)