
We want to allow a resource X to be created without starting it, and then for a group/clone Y to be created referencing X, which can subsequently be started. This ensures that child resources are only started via their parent, respecting the constraints their parent needs to impose (e.g. ordering if the parent is a group). However in this case, changing target-role on Y causes a "Do you want to override target-role for child resource ..." interactive prompt. When STDIN is not a tty, --force is required to ensure that the target-role on the child resource. This only works with newer versions of crm which are patched according to: https://bugzilla.novell.com/show_bug.cgi?id=868697
107 lines
3.1 KiB
Ruby
107 lines
3.1 KiB
Ruby
# Shared code used to test providers of runnable Chef resources
|
|
# representing Pacemaker CIB objects. For example the provider
|
|
# for primitives is runnable (since primitives can be started
|
|
# and stopped) but constraints cannot.
|
|
|
|
this_dir = File.dirname(__FILE__)
|
|
require File.expand_path('provider', this_dir)
|
|
require File.expand_path('shellout', this_dir)
|
|
|
|
shared_examples "a runnable resource" do |fixture|
|
|
def expect_running(running)
|
|
expect_any_instance_of(cib_object_class) \
|
|
.to receive(:running?) \
|
|
.and_return(running)
|
|
end
|
|
|
|
it_should_behave_like "all Pacemaker LWRPs", fixture
|
|
|
|
include Chef::RSpec::Mixlib::ShellOut
|
|
|
|
describe ":delete action" do
|
|
it "should not delete a running resource" do
|
|
stub_shellout(fixture.definition_string)
|
|
expect_running(true)
|
|
|
|
expected_error = "Cannot delete running #{fixture}"
|
|
expect { provider.run_action :delete }.to \
|
|
raise_error(RuntimeError, expected_error)
|
|
|
|
cmd = "crm configure delete '#{fixture.name}'"
|
|
expect(@chef_run).not_to run_execute(cmd)
|
|
expect(@resource).not_to be_updated
|
|
end
|
|
|
|
it "should delete a non-running resource" do
|
|
stub_shellout(fixture.definition_string)
|
|
expect_running(false)
|
|
|
|
provider.run_action :delete
|
|
|
|
cmd = "crm configure delete '#{fixture.name}'"
|
|
expect(@chef_run).to run_execute(cmd)
|
|
expect(@resource).to be_updated
|
|
end
|
|
end
|
|
|
|
describe ":start action" do
|
|
it_should_behave_like "action on non-existent resource", \
|
|
:start,
|
|
"crm --force resource start #{fixture.name}", \
|
|
"Cannot start non-existent #{fixture}"
|
|
|
|
it "should do nothing to a started resource" do
|
|
stub_shellout(fixture.definition_string)
|
|
expect_running(true)
|
|
|
|
provider.run_action :start
|
|
|
|
cmd = "crm --force resource start #{fixture.name}"
|
|
expect(@chef_run).not_to run_execute(cmd)
|
|
expect(@resource).not_to be_updated
|
|
end
|
|
|
|
it "should start a stopped resource" do
|
|
config = fixture.definition_string.sub("Started", "Stopped")
|
|
stub_shellout(config)
|
|
expect_running(false)
|
|
|
|
provider.run_action :start
|
|
|
|
cmd = "crm --force resource start '#{fixture.name}'"
|
|
expect(@chef_run).to run_execute(cmd)
|
|
expect(@resource).to be_updated
|
|
end
|
|
end
|
|
|
|
describe ":stop action" do
|
|
it_should_behave_like "action on non-existent resource", \
|
|
:stop,
|
|
"crm --force resource stop #{fixture.name}", \
|
|
"Cannot stop non-existent #{fixture}"
|
|
|
|
it "should do nothing to a stopped resource" do
|
|
stub_shellout(fixture.definition_string)
|
|
expect_running(false)
|
|
|
|
provider.run_action :stop
|
|
|
|
cmd = "crm --force resource start #{fixture.name}"
|
|
expect(@chef_run).not_to run_execute(cmd)
|
|
expect(@resource).not_to be_updated
|
|
end
|
|
|
|
it "should stop a started resource" do
|
|
stub_shellout(fixture.definition_string)
|
|
expect_running(true)
|
|
|
|
provider.run_action :stop
|
|
|
|
cmd = "crm --force resource stop '#{fixture.name}'"
|
|
expect(@chef_run).to run_execute(cmd)
|
|
expect(@resource).to be_updated
|
|
end
|
|
end
|
|
|
|
end
|