make fixture variable name generic to facilitate code reuse
This commit is contained in:
@@ -5,9 +5,9 @@ require File.join(File.dirname(__FILE__), %w(.. fixtures colocation_constraint))
|
|||||||
|
|
||||||
describe "Chef::Provider::PacemakerColocation" do
|
describe "Chef::Provider::PacemakerColocation" do
|
||||||
# for use inside examples:
|
# for use inside examples:
|
||||||
let(:colo) { Chef::RSpec::Pacemaker::Config::COLOCATION_CONSTRAINT.dup }
|
let(:fixture) { Chef::RSpec::Pacemaker::Config::COLOCATION_CONSTRAINT.dup }
|
||||||
# for use outside examples (e.g. when invoking shared_examples)
|
# for use outside examples (e.g. when invoking shared_examples)
|
||||||
colo = Chef::RSpec::Pacemaker::Config::COLOCATION_CONSTRAINT.dup
|
fixture = Chef::RSpec::Pacemaker::Config::COLOCATION_CONSTRAINT.dup
|
||||||
|
|
||||||
before(:each) do
|
before(:each) do
|
||||||
runner_opts = {
|
runner_opts = {
|
||||||
@@ -18,9 +18,9 @@ describe "Chef::Provider::PacemakerColocation" do
|
|||||||
@node = @chef_run.node
|
@node = @chef_run.node
|
||||||
@run_context = @chef_run.run_context
|
@run_context = @chef_run.run_context
|
||||||
|
|
||||||
@resource = Chef::Resource::PacemakerColocation.new(colo.name, @run_context)
|
@resource = Chef::Resource::PacemakerColocation.new(fixture.name, @run_context)
|
||||||
@resource.score colo.score
|
@resource.score fixture.score
|
||||||
@resource.resources colo.resources.dup
|
@resource.resources fixture.resources.dup
|
||||||
end
|
end
|
||||||
|
|
||||||
let (:provider) { Chef::Provider::PacemakerColocation.new(@resource, @run_context) }
|
let (:provider) { Chef::Provider::PacemakerColocation.new(@resource, @run_context) }
|
||||||
@@ -35,7 +35,7 @@ describe "Chef::Provider::PacemakerColocation" do
|
|||||||
def test_modify(expected_cmds)
|
def test_modify(expected_cmds)
|
||||||
yield
|
yield
|
||||||
|
|
||||||
expect_definition(colo.definition_string)
|
expect_definition(fixture.definition_string)
|
||||||
|
|
||||||
provider.run_action :create
|
provider.run_action :create
|
||||||
|
|
||||||
@@ -47,8 +47,8 @@ describe "Chef::Provider::PacemakerColocation" do
|
|||||||
|
|
||||||
it "should modify the constraint if it has a different score" do
|
it "should modify the constraint if it has a different score" do
|
||||||
new_score = '100'
|
new_score = '100'
|
||||||
colo.score = new_score
|
fixture.score = new_score
|
||||||
expected_configure_cmd_args = [colo.reconfigure_command]
|
expected_configure_cmd_args = [fixture.reconfigure_command]
|
||||||
test_modify(expected_configure_cmd_args) do
|
test_modify(expected_configure_cmd_args) do
|
||||||
@resource.score new_score
|
@resource.score new_score
|
||||||
end
|
end
|
||||||
@@ -56,7 +56,7 @@ describe "Chef::Provider::PacemakerColocation" do
|
|||||||
|
|
||||||
it "should modify the constraint if it has a resource added" do
|
it "should modify the constraint if it has a resource added" do
|
||||||
new_resource = 'bar:Stopped'
|
new_resource = 'bar:Stopped'
|
||||||
expected = colo.dup
|
expected = fixture.dup
|
||||||
expected.resources = expected.resources.dup + [new_resource]
|
expected.resources = expected.resources.dup + [new_resource]
|
||||||
expected_configure_cmd_args = [expected.reconfigure_command]
|
expected_configure_cmd_args = [expected.reconfigure_command]
|
||||||
test_modify(expected_configure_cmd_args) do
|
test_modify(expected_configure_cmd_args) do
|
||||||
@@ -66,8 +66,8 @@ describe "Chef::Provider::PacemakerColocation" do
|
|||||||
|
|
||||||
it "should modify the constraint if it has a different resource" do
|
it "should modify the constraint if it has a different resource" do
|
||||||
new_resources = ['bar:Started']
|
new_resources = ['bar:Started']
|
||||||
colo.resources = new_resources
|
fixture.resources = new_resources
|
||||||
expected_configure_cmd_args = [colo.reconfigure_command]
|
expected_configure_cmd_args = [fixture.reconfigure_command]
|
||||||
test_modify(expected_configure_cmd_args) do
|
test_modify(expected_configure_cmd_args) do
|
||||||
@resource.resources new_resources
|
@resource.resources new_resources
|
||||||
end
|
end
|
||||||
@@ -77,7 +77,7 @@ describe "Chef::Provider::PacemakerColocation" do
|
|||||||
|
|
||||||
describe ":delete action" do
|
describe ":delete action" do
|
||||||
it_should_behave_like "action on non-existent resource", \
|
it_should_behave_like "action on non-existent resource", \
|
||||||
:delete, "crm configure delete #{colo.name}", nil
|
:delete, "crm configure delete #{fixture.name}", nil
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@@ -5,9 +5,9 @@ require File.join(File.dirname(__FILE__), %w(.. fixtures keystone_primitive))
|
|||||||
|
|
||||||
describe "Chef::Provider::PacemakerPrimitive" do
|
describe "Chef::Provider::PacemakerPrimitive" do
|
||||||
# for use inside examples:
|
# for use inside examples:
|
||||||
let(:rsc) { Chef::RSpec::Pacemaker::Config::KEYSTONE_PRIMITIVE }
|
let(:fixture) { Chef::RSpec::Pacemaker::Config::KEYSTONE_PRIMITIVE }
|
||||||
# for use outside examples (e.g. when invoking shared_examples)
|
# for use outside examples (e.g. when invoking shared_examples)
|
||||||
rsc = Chef::RSpec::Pacemaker::Config::KEYSTONE_PRIMITIVE
|
fixture = Chef::RSpec::Pacemaker::Config::KEYSTONE_PRIMITIVE
|
||||||
|
|
||||||
before(:each) do
|
before(:each) do
|
||||||
runner_opts = {
|
runner_opts = {
|
||||||
@@ -18,11 +18,11 @@ describe "Chef::Provider::PacemakerPrimitive" do
|
|||||||
@node = @chef_run.node
|
@node = @chef_run.node
|
||||||
@run_context = @chef_run.run_context
|
@run_context = @chef_run.run_context
|
||||||
|
|
||||||
@resource = Chef::Resource::PacemakerPrimitive.new(rsc.name, @run_context)
|
@resource = Chef::Resource::PacemakerPrimitive.new(fixture.name, @run_context)
|
||||||
@resource.agent rsc.agent
|
@resource.agent fixture.agent
|
||||||
@resource.params Hash[rsc.params]
|
@resource.params Hash[fixture.params]
|
||||||
@resource.meta Hash[rsc.meta]
|
@resource.meta Hash[fixture.meta]
|
||||||
@resource.op Hash[rsc.op]
|
@resource.op Hash[fixture.op]
|
||||||
end
|
end
|
||||||
|
|
||||||
let (:provider) { Chef::Provider::PacemakerPrimitive.new(@resource, @run_context) }
|
let (:provider) { Chef::Provider::PacemakerPrimitive.new(@resource, @run_context) }
|
||||||
@@ -43,7 +43,7 @@ describe "Chef::Provider::PacemakerPrimitive" do
|
|||||||
def test_modify(expected_cmds)
|
def test_modify(expected_cmds)
|
||||||
yield
|
yield
|
||||||
|
|
||||||
expect_definition(rsc.definition_string)
|
expect_definition(fixture.definition_string)
|
||||||
|
|
||||||
provider.run_action :create
|
provider.run_action :create
|
||||||
|
|
||||||
@@ -57,22 +57,22 @@ describe "Chef::Provider::PacemakerPrimitive" do
|
|||||||
expected_configure_cmd_args = [
|
expected_configure_cmd_args = [
|
||||||
%'--set-parameter "os_password" --parameter-value "newpasswd"',
|
%'--set-parameter "os_password" --parameter-value "newpasswd"',
|
||||||
%'--delete-parameter "os_tenant_name"',
|
%'--delete-parameter "os_tenant_name"',
|
||||||
].map { |args| "crm_resource --resource #{rsc.name} #{args}" }
|
].map { |args| "crm_resource --resource #{fixture.name} #{args}" }
|
||||||
test_modify(expected_configure_cmd_args) do
|
test_modify(expected_configure_cmd_args) do
|
||||||
new_params = Hash[rsc.params].merge("os_password" => "newpasswd")
|
new_params = Hash[fixture.params].merge("os_password" => "newpasswd")
|
||||||
new_params.delete("os_tenant_name")
|
new_params.delete("os_tenant_name")
|
||||||
@resource.params new_params
|
@resource.params new_params
|
||||||
@resource.meta Hash[rsc.meta].merge("target-role" => "Stopped")
|
@resource.meta Hash[fixture.meta].merge("target-role" => "Stopped")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should modify the primitive if it has different meta" do
|
it "should modify the primitive if it has different meta" do
|
||||||
expected_configure_cmd_args = [
|
expected_configure_cmd_args = [
|
||||||
%'--set-parameter "target-role" --parameter-value "Stopped" --meta',
|
%'--set-parameter "target-role" --parameter-value "Stopped" --meta',
|
||||||
].map { |args| "crm_resource --resource #{rsc.name} #{args}" }
|
].map { |args| "crm_resource --resource #{fixture.name} #{args}" }
|
||||||
test_modify(expected_configure_cmd_args) do
|
test_modify(expected_configure_cmd_args) do
|
||||||
@resource.params Hash[rsc.params]
|
@resource.params Hash[fixture.params]
|
||||||
@resource.meta Hash[rsc.meta].merge("target-role" => "Stopped")
|
@resource.meta Hash[fixture.meta].merge("target-role" => "Stopped")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -81,21 +81,21 @@ describe "Chef::Provider::PacemakerPrimitive" do
|
|||||||
%'--set-parameter "os_password" --parameter-value "newpasswd"',
|
%'--set-parameter "os_password" --parameter-value "newpasswd"',
|
||||||
%'--delete-parameter "os_tenant_name"',
|
%'--delete-parameter "os_tenant_name"',
|
||||||
%'--set-parameter "target-role" --parameter-value "Stopped" --meta',
|
%'--set-parameter "target-role" --parameter-value "Stopped" --meta',
|
||||||
].map { |args| "crm_resource --resource #{rsc.name} #{args}" }
|
].map { |args| "crm_resource --resource #{fixture.name} #{args}" }
|
||||||
test_modify(expected_configure_cmd_args) do
|
test_modify(expected_configure_cmd_args) do
|
||||||
new_params = Hash[rsc.params].merge("os_password" => "newpasswd")
|
new_params = Hash[fixture.params].merge("os_password" => "newpasswd")
|
||||||
new_params.delete("os_tenant_name")
|
new_params.delete("os_tenant_name")
|
||||||
@resource.params new_params
|
@resource.params new_params
|
||||||
@resource.meta Hash[rsc.meta].merge("target-role" => "Stopped")
|
@resource.meta Hash[fixture.meta].merge("target-role" => "Stopped")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should modify the primitive if it has different op values" do
|
it "should modify the primitive if it has different op values" do
|
||||||
expected_configure_cmd_args = [
|
expected_configure_cmd_args = [
|
||||||
rsc.reconfigure_command.gsub('60', '120')
|
fixture.reconfigure_command.gsub('60', '120')
|
||||||
]
|
]
|
||||||
test_modify(expected_configure_cmd_args) do
|
test_modify(expected_configure_cmd_args) do
|
||||||
new_op = Hash[rsc.op]
|
new_op = Hash[fixture.op]
|
||||||
# Ensure we're not modifying our expectation as well as the input
|
# Ensure we're not modifying our expectation as well as the input
|
||||||
new_op['monitor'] = new_op['monitor'].dup
|
new_op['monitor'] = new_op['monitor'].dup
|
||||||
new_op['monitor']['timeout'] = '120'
|
new_op['monitor']['timeout'] = '120'
|
||||||
@@ -111,17 +111,17 @@ describe "Chef::Provider::PacemakerPrimitive" do
|
|||||||
|
|
||||||
provider.run_action :create
|
provider.run_action :create
|
||||||
|
|
||||||
expect(@chef_run).to run_execute(rsc.crm_configure_command)
|
expect(@chef_run).to run_execute(fixture.crm_configure_command)
|
||||||
expect(@resource).to be_updated
|
expect(@resource).to be_updated
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should barf if the primitive is already defined with the wrong agent" do
|
it "should barf if the primitive is already defined with the wrong agent" do
|
||||||
existing_agent = "ocf:openstack:something-else"
|
existing_agent = "ocf:openstack:something-else"
|
||||||
definition = rsc.definition_string.sub(rsc.agent, existing_agent)
|
definition = fixture.definition_string.sub(fixture.agent, existing_agent)
|
||||||
expect_definition(definition)
|
expect_definition(definition)
|
||||||
|
|
||||||
expected_error = \
|
expected_error = \
|
||||||
"Existing primitive resource '#{rsc.name}' has agent '#{existing_agent}' " \
|
"Existing primitive resource '#{fixture.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)
|
||||||
@@ -132,28 +132,28 @@ describe "Chef::Provider::PacemakerPrimitive" do
|
|||||||
|
|
||||||
describe ":delete action" do
|
describe ":delete action" do
|
||||||
it_should_behave_like "action on non-existent resource", \
|
it_should_behave_like "action on non-existent resource", \
|
||||||
:delete, "crm configure delete #{rsc.name}", nil
|
:delete, "crm configure delete #{fixture.name}", nil
|
||||||
|
|
||||||
it "should not delete a running resource" do
|
it "should not delete a running resource" do
|
||||||
expect_definition(rsc.definition_string)
|
expect_definition(fixture.definition_string)
|
||||||
expect_running(true)
|
expect_running(true)
|
||||||
|
|
||||||
expected_error = "Cannot delete running primitive resource '#{rsc.name}'"
|
expected_error = "Cannot delete running primitive resource '#{fixture.name}'"
|
||||||
expect { provider.run_action :delete }.to \
|
expect { provider.run_action :delete }.to \
|
||||||
raise_error(RuntimeError, expected_error)
|
raise_error(RuntimeError, expected_error)
|
||||||
|
|
||||||
cmd = "crm configure delete '#{rsc.name}'"
|
cmd = "crm configure delete '#{fixture.name}'"
|
||||||
expect(@chef_run).not_to run_execute(cmd)
|
expect(@chef_run).not_to run_execute(cmd)
|
||||||
expect(@resource).not_to be_updated
|
expect(@resource).not_to be_updated
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should delete a non-running resource" do
|
it "should delete a non-running resource" do
|
||||||
expect_definition(rsc.definition_string)
|
expect_definition(fixture.definition_string)
|
||||||
expect_running(false)
|
expect_running(false)
|
||||||
|
|
||||||
provider.run_action :delete
|
provider.run_action :delete
|
||||||
|
|
||||||
cmd = "crm configure delete '#{rsc.name}'"
|
cmd = "crm configure delete '#{fixture.name}'"
|
||||||
expect(@chef_run).to run_execute(cmd)
|
expect(@chef_run).to run_execute(cmd)
|
||||||
expect(@resource).to be_updated
|
expect(@resource).to be_updated
|
||||||
end
|
end
|
||||||
@@ -162,28 +162,28 @@ describe "Chef::Provider::PacemakerPrimitive" do
|
|||||||
describe ":start action" do
|
describe ":start action" do
|
||||||
it_should_behave_like "action on non-existent resource", \
|
it_should_behave_like "action on non-existent resource", \
|
||||||
:start,
|
:start,
|
||||||
"crm resource start #{rsc.name}", \
|
"crm resource start #{fixture.name}", \
|
||||||
"Cannot start non-existent resource primitive '#{rsc.name}'"
|
"Cannot start non-existent resource primitive '#{fixture.name}'"
|
||||||
|
|
||||||
it "should do nothing to a started resource" do
|
it "should do nothing to a started resource" do
|
||||||
expect_definition(rsc.definition_string)
|
expect_definition(fixture.definition_string)
|
||||||
expect_running(true)
|
expect_running(true)
|
||||||
|
|
||||||
provider.run_action :start
|
provider.run_action :start
|
||||||
|
|
||||||
cmd = "crm resource start #{rsc.name}"
|
cmd = "crm resource start #{fixture.name}"
|
||||||
expect(@chef_run).not_to run_execute(cmd)
|
expect(@chef_run).not_to run_execute(cmd)
|
||||||
expect(@resource).not_to be_updated
|
expect(@resource).not_to be_updated
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should start a stopped resource" do
|
it "should start a stopped resource" do
|
||||||
config = rsc.definition_string.sub("Started", "Stopped")
|
config = fixture.definition_string.sub("Started", "Stopped")
|
||||||
expect_definition(config)
|
expect_definition(config)
|
||||||
expect_running(false)
|
expect_running(false)
|
||||||
|
|
||||||
provider.run_action :start
|
provider.run_action :start
|
||||||
|
|
||||||
cmd = "crm resource start '#{rsc.name}'"
|
cmd = "crm resource start '#{fixture.name}'"
|
||||||
expect(@chef_run).to run_execute(cmd)
|
expect(@chef_run).to run_execute(cmd)
|
||||||
expect(@resource).to be_updated
|
expect(@resource).to be_updated
|
||||||
end
|
end
|
||||||
@@ -192,27 +192,27 @@ describe "Chef::Provider::PacemakerPrimitive" do
|
|||||||
describe ":stop action" do
|
describe ":stop action" do
|
||||||
it_should_behave_like "action on non-existent resource", \
|
it_should_behave_like "action on non-existent resource", \
|
||||||
:stop,
|
:stop,
|
||||||
"crm resource stop #{rsc.name}", \
|
"crm resource stop #{fixture.name}", \
|
||||||
"Cannot stop non-existent resource primitive '#{rsc.name}'"
|
"Cannot stop non-existent resource primitive '#{fixture.name}'"
|
||||||
|
|
||||||
it "should do nothing to a stopped resource" do
|
it "should do nothing to a stopped resource" do
|
||||||
expect_definition(rsc.definition_string)
|
expect_definition(fixture.definition_string)
|
||||||
expect_running(false)
|
expect_running(false)
|
||||||
|
|
||||||
provider.run_action :stop
|
provider.run_action :stop
|
||||||
|
|
||||||
cmd = "crm resource start #{rsc.name}"
|
cmd = "crm resource start #{fixture.name}"
|
||||||
expect(@chef_run).not_to run_execute(cmd)
|
expect(@chef_run).not_to run_execute(cmd)
|
||||||
expect(@resource).not_to be_updated
|
expect(@resource).not_to be_updated
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should stop a started resource" do
|
it "should stop a started resource" do
|
||||||
expect_definition(rsc.definition_string)
|
expect_definition(fixture.definition_string)
|
||||||
expect_running(true)
|
expect_running(true)
|
||||||
|
|
||||||
provider.run_action :stop
|
provider.run_action :stop
|
||||||
|
|
||||||
cmd = "crm resource stop '#{rsc.name}'"
|
cmd = "crm resource stop '#{fixture.name}'"
|
||||||
expect(@chef_run).to run_execute(cmd)
|
expect(@chef_run).to run_execute(cmd)
|
||||||
expect(@resource).to be_updated
|
expect(@resource).to be_updated
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user