tidy up string handling
This commit is contained in:
parent
c3be9fefb4
commit
34fb97e29d
@ -104,6 +104,10 @@ module Pacemaker
|
|||||||
self.class.type(definition)
|
self.class.type(definition)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def to_s
|
||||||
|
"%s '%s'" % [self.class.description, name]
|
||||||
|
end
|
||||||
|
|
||||||
def delete_command
|
def delete_command
|
||||||
"crm configure delete '#{name}'"
|
"crm configure delete '#{name}'"
|
||||||
end
|
end
|
||||||
|
@ -6,7 +6,7 @@ module Pacemaker
|
|||||||
include Chef::Mixin::ShellOut
|
include Chef::Mixin::ShellOut
|
||||||
|
|
||||||
def self.description
|
def self.description
|
||||||
type = self.to_s.split('::').last
|
type = self.to_s.split('::').last.downcase
|
||||||
"#{type} resource"
|
"#{type} resource"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -29,9 +29,9 @@ action :create do
|
|||||||
create_resource(name)
|
create_resource(name)
|
||||||
else
|
else
|
||||||
if @current_resource.agent != new_resource.agent
|
if @current_resource.agent != new_resource.agent
|
||||||
raise "Existing resource primitive '%s' has agent '%s' " \
|
raise "Existing %s has agent '%s' " \
|
||||||
"but recipe wanted '%s'" % \
|
"but recipe wanted '%s'" % \
|
||||||
[ name, @current_resource.agent, new_resource.agent ]
|
[ @current_cib_object, @current_resource.agent, new_resource.agent ]
|
||||||
end
|
end
|
||||||
|
|
||||||
maybe_modify_resource(name)
|
maybe_modify_resource(name)
|
||||||
@ -43,13 +43,13 @@ action :delete do
|
|||||||
next unless @current_resource
|
next unless @current_resource
|
||||||
rsc = Pacemaker::Resource::Primitive.new(name)
|
rsc = Pacemaker::Resource::Primitive.new(name)
|
||||||
if rsc.running?
|
if rsc.running?
|
||||||
raise "Cannot delete running resource primitive #{name}"
|
raise "Cannot delete running #{@current_cib_object}"
|
||||||
end
|
end
|
||||||
execute rsc.delete_command do
|
execute rsc.delete_command do
|
||||||
action :nothing
|
action :nothing
|
||||||
end.run_action(:run)
|
end.run_action(:run)
|
||||||
new_resource.updated_by_last_action(true)
|
new_resource.updated_by_last_action(true)
|
||||||
Chef::Log.info "Deleted primitive '#{name}'."
|
Chef::Log.info "Deleted #{@current_cib_object}"
|
||||||
end
|
end
|
||||||
|
|
||||||
action :start do
|
action :start do
|
||||||
@ -63,7 +63,7 @@ action :start do
|
|||||||
action :nothing
|
action :nothing
|
||||||
end.run_action(:run)
|
end.run_action(:run)
|
||||||
new_resource.updated_by_last_action(true)
|
new_resource.updated_by_last_action(true)
|
||||||
Chef::Log.info "Successfully started primitive '#{name}'."
|
Chef::Log.info "Successfully started #{@current_cib_object}"
|
||||||
end
|
end
|
||||||
|
|
||||||
action :stop do
|
action :stop do
|
||||||
@ -77,7 +77,7 @@ action :stop do
|
|||||||
action :nothing
|
action :nothing
|
||||||
end.run_action(:run)
|
end.run_action(:run)
|
||||||
new_resource.updated_by_last_action(true)
|
new_resource.updated_by_last_action(true)
|
||||||
Chef::Log.info "Successfully stopped primitive '#{name}'."
|
Chef::Log.info "Successfully stopped #{@current_cib_object}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def cib_object_class
|
def cib_object_class
|
||||||
@ -95,7 +95,7 @@ def create_resource(name)
|
|||||||
primitive = Pacemaker::Resource::Primitive.from_chef_resource(new_resource)
|
primitive = Pacemaker::Resource::Primitive.from_chef_resource(new_resource)
|
||||||
cmd = primitive.crm_configure_command
|
cmd = primitive.crm_configure_command
|
||||||
|
|
||||||
Chef::Log.info "Creating new resource primitive #{name}"
|
Chef::Log.info "Creating new #{primitive}"
|
||||||
|
|
||||||
execute cmd do
|
execute cmd do
|
||||||
action :nothing
|
action :nothing
|
||||||
@ -103,14 +103,14 @@ def create_resource(name)
|
|||||||
|
|
||||||
if primitive.exists?
|
if primitive.exists?
|
||||||
new_resource.updated_by_last_action(true)
|
new_resource.updated_by_last_action(true)
|
||||||
Chef::Log.info "Successfully configured primitive '#{name}'."
|
Chef::Log.info "Successfully configured #{primitive}"
|
||||||
else
|
else
|
||||||
Chef::Log.error "Failed to configure primitive #{name}."
|
Chef::Log.error "Failed to configure #{primitive}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def maybe_modify_resource(name)
|
def maybe_modify_resource(name)
|
||||||
Chef::Log.info "Checking existing resource primitive #{name} for modifications"
|
Chef::Log.info "Checking existing #{@current_cib_object} for modifications"
|
||||||
|
|
||||||
cmds = []
|
cmds = []
|
||||||
|
|
||||||
|
@ -133,7 +133,7 @@ describe "Chef::Provider::PacemakerPrimitive" do
|
|||||||
expect_definition(definition)
|
expect_definition(definition)
|
||||||
|
|
||||||
expected_error = \
|
expected_error = \
|
||||||
"Existing resource primitive '#{rsc.name}' has agent '#{existing_agent}' " \
|
"Existing primitive resource '#{rsc.name}' has agent '#{existing_agent}' " \
|
||||||
"but recipe wanted '#{@resource.agent}'"
|
"but recipe wanted '#{@resource.agent}'"
|
||||||
expect { provider.run_action :create }.to \
|
expect { provider.run_action :create }.to \
|
||||||
raise_error(RuntimeError, expected_error)
|
raise_error(RuntimeError, expected_error)
|
||||||
@ -166,7 +166,7 @@ describe "Chef::Provider::PacemakerPrimitive" do
|
|||||||
expect_definition(rsc.definition_string)
|
expect_definition(rsc.definition_string)
|
||||||
expect_running(true)
|
expect_running(true)
|
||||||
|
|
||||||
expected_error = "Cannot delete running resource primitive #{rsc.name}"
|
expected_error = "Cannot delete running primitive resource '#{rsc.name}'"
|
||||||
expect { provider.run_action :delete }.to \
|
expect { provider.run_action :delete }.to \
|
||||||
raise_error(RuntimeError, expected_error)
|
raise_error(RuntimeError, expected_error)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user