make keystone config fixture data more reusable
This commit is contained in:
parent
1f274b73fd
commit
2dbb942f43
@ -1,17 +1,35 @@
|
||||
shared_context "keystone config" do
|
||||
before(:all) do
|
||||
@params = {
|
||||
"os_password" => "adminpw",
|
||||
"os_auth_url" => "http://node1:5000/v2.0",
|
||||
"os_username" => "admin",
|
||||
"os_tenant_name" => "openstack"
|
||||
}
|
||||
params_string = @params.map { |k,v| %'#{k}="#{v}"' }.join(" ")
|
||||
@config = <<EOF
|
||||
require ::File.join(::File.dirname(__FILE__), *%w(.. libraries cib_objects))
|
||||
|
||||
module Chef::RSpec
|
||||
module Pacemaker
|
||||
module Config
|
||||
extend Chef::Libraries::Pacemaker::CIBObjects
|
||||
|
||||
RA = {
|
||||
:agent => "ocf:openstack:keystone",
|
||||
:params => [
|
||||
[ "os_password", "adminpw" ],
|
||||
[ "os_auth_url", "http://node1:5000/v2.0" ],
|
||||
[ "os_username", "admin" ],
|
||||
[ "os_tenant_name", "openstack" ]
|
||||
],
|
||||
:meta => [
|
||||
[ "target-role", "Started" ],
|
||||
[ "is-managed", "true" ]
|
||||
],
|
||||
:op => [
|
||||
[ "monitor", { "interval" => "10s" } ]
|
||||
],
|
||||
}
|
||||
RA[:params_string] = resource_params_string(RA[:params])
|
||||
RA[:meta_string] = resource_meta_string(RA[:meta])
|
||||
RA[:op_string] = resource_op_string(RA[:op])
|
||||
RA[:config] = <<EOF
|
||||
primitive keystone ocf:openstack:keystone \\
|
||||
params #{params_string} \\
|
||||
meta target-role="Started" is-managed="true" \\
|
||||
op monitor interval="10s"
|
||||
#{RA[:params_string]} \\
|
||||
#{RA[:meta_string]} \\
|
||||
#{RA[:op_string]}
|
||||
EOF
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -11,6 +11,9 @@ describe Chef::Libraries::Pacemaker::CIBObjects do
|
||||
end
|
||||
end
|
||||
|
||||
shared_context "keystone config" do
|
||||
let(:ra) { Chef::RSpec::Pacemaker::Config::RA }
|
||||
end
|
||||
|
||||
shared_context "keystone primitive" do
|
||||
include_context "shellout stubs"
|
||||
@ -20,7 +23,7 @@ describe Chef::Libraries::Pacemaker::CIBObjects do
|
||||
Mixlib::ShellOut.any_instance.stub(:error!)
|
||||
expect_any_instance_of(Mixlib::ShellOut) \
|
||||
.to receive(:stdout) \
|
||||
.and_return(@config)
|
||||
.and_return(ra[:config])
|
||||
end
|
||||
end
|
||||
|
||||
@ -37,7 +40,7 @@ describe Chef::Libraries::Pacemaker::CIBObjects do
|
||||
include_context "keystone primitive"
|
||||
|
||||
it "should retrieve cluster config" do
|
||||
expect(get_cib_object_definition("keystone")).to eq(@config)
|
||||
expect(get_cib_object_definition("keystone")).to eq(ra[:config])
|
||||
end
|
||||
end
|
||||
|
||||
@ -69,7 +72,7 @@ describe Chef::Libraries::Pacemaker::CIBObjects do
|
||||
include_context "keystone config"
|
||||
|
||||
it "should return primitive" do
|
||||
expect(cib_object_type(@config)).to eq("primitive")
|
||||
expect(cib_object_type(ra[:config])).to eq("primitive")
|
||||
end
|
||||
|
||||
it "should raise an error without valid config" do
|
||||
@ -156,7 +159,7 @@ describe Chef::Libraries::Pacemaker::CIBObjects do
|
||||
include_context "keystone config"
|
||||
|
||||
it "should extract a hash from config" do
|
||||
expect(extract_hash("keystone", @config, "params")).to eq(@params)
|
||||
expect(extract_hash("keystone", ra[:config], "params")).to eq(Hash[ra[:params]])
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -14,34 +14,20 @@ describe "Chef::Provider::PacemakerPrimitive" do
|
||||
|
||||
@resource = Chef::Resource::PacemakerPrimitive.new("keystone", @run_context)
|
||||
|
||||
@resource.agent "ocf:openstack:keystone"
|
||||
ra_params = {
|
||||
"os_auth_url" => "http://localhost:5000/v2.0",
|
||||
"os_tenant_name" => "openstack",
|
||||
"os_username" => "admin",
|
||||
"os_password" => "adminpw",
|
||||
"user" => "openstack-keystone"
|
||||
}
|
||||
ra_meta = {
|
||||
"target-role" => "Started",
|
||||
"is-managed" => "true"
|
||||
}
|
||||
ra_op = {
|
||||
"monitor" => { "interval" => "10s" }
|
||||
}
|
||||
|
||||
@resource.params ra_params
|
||||
@resource.meta ra_meta
|
||||
@resource.op ra_op
|
||||
ra = Chef::RSpec::Pacemaker::Config::RA
|
||||
@resource.agent ra[:agent]
|
||||
@resource.params Hash[ra[:params]]
|
||||
@resource.meta Hash[ra[:meta]]
|
||||
@resource.op Hash[ra[:op]]
|
||||
end
|
||||
|
||||
describe ":create action" do
|
||||
include_context "keystone config"
|
||||
let(:ra) { Chef::RSpec::Pacemaker::Config::RA }
|
||||
|
||||
it "should do nothing if the primitive already exists" do
|
||||
provider = Chef::Provider::PacemakerPrimitive.new(@resource, @run_context)
|
||||
expect(provider).to receive(:cib_object_exists?).at_least(:once).and_return(true)
|
||||
expect(provider).to receive(:get_cib_object_definition).and_return(@config)
|
||||
expect(provider).to receive(:get_cib_object_definition).and_return(ra[:config])
|
||||
expect(Mixlib::ShellOut).not_to receive(:new)
|
||||
provider.run_action :create
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user