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