diff --git a/providers/primitive.rb b/providers/primitive.rb index 081bf9a..773250a 100644 --- a/providers/primitive.rb +++ b/providers/primitive.rb @@ -31,7 +31,8 @@ action :create do create_resource(name) else if @current_resource.agent != new_resource.agent - raise "Existing primitive '#{name}' has agent but recipe wanted #{new_resource.agent}" + raise "Existing primitive '#{name}' has agent '#{@current_resource.agent}' " \ + "but recipe wanted '#{new_resource.agent}'" end modify_resource(name) diff --git a/spec/providers/primitive_spec.rb b/spec/providers/primitive_spec.rb index 5cdffb0..94cff9d 100644 --- a/spec/providers/primitive_spec.rb +++ b/spec/providers/primitive_spec.rb @@ -71,7 +71,19 @@ describe "Chef::Provider::PacemakerPrimitive" do end it "should barf if the primitive has the wrong agent" do - pending "not implemented yet" + existing_agent = "ocf:openstack:something-else" + config = ra[:config].sub(ra[:agent], existing_agent) + provider = Chef::Provider::PacemakerPrimitive.new(@resource, @run_context) + + # get_cib_object_definition is invoked by load_current_resource + # and later used to see whether to create or modify. + expect(provider).to receive(:get_cib_object_definition).and_return(config) + + expected_error = \ + "Existing primitive '#{ra[:name]}' has agent '#{existing_agent}' " \ + "but recipe wanted '#{@resource.agent}'" + expect { provider.run_action :create }.to \ + raise_error(RuntimeError, expected_error) end end end