Clearer registraton LWRP tests

This is a much clearer way to test LWRPs are executed with
the proper options.  The previous approach was hacky, and
relied upon too much stubbing and ruby magik.  Also, updated
to berkshelf 2.0 where Berksfile.lock is respected.  This
is necessary for berkshelf to lock to the proper cookbook
deps in openstack's CI system.

Change-Id: Ia912efffa137a75352423e7571cb74bca9ab1b5d
This commit is contained in:
John Dewey 2013-06-08 21:33:43 -07:00
parent 5cc19cee1c
commit b0089fbe82
5 changed files with 147 additions and 129 deletions

1
.gitignore vendored
View File

@ -1,2 +1 @@
.bundle/
Berksfile.lock

46
Berksfile.lock Normal file
View File

@ -0,0 +1,46 @@
{
"sha": "aa660f8ff6003966212f763dad49cf52c963a724",
"sources": {
"openstack-image": {
"locked_version": "7.0.0",
"constraint": "= 7.0.0",
"path": "."
},
"openstack-identity": {
"locked_version": "7.0.0",
"git": "git://github.com/stackforge/cookbook-openstack-identity.git",
"ref": "a1ae0fd1d2bba23975b3c6852411383be982faa5"
},
"openstack-common": {
"locked_version": "0.2.6",
"git": "git://github.com/stackforge/cookbook-openstack-common.git",
"ref": "f8781d13de30fb3a191e97e91b13a3ccac139d6f"
},
"database": {
"locked_version": "1.4.0"
},
"mysql": {
"locked_version": "3.0.0",
"constraint": ">= 1.3.0"
},
"openssl": {
"locked_version": "1.0.2"
},
"build-essential": {
"locked_version": "1.4.0"
},
"postgresql": {
"locked_version": "3.0.0",
"constraint": ">= 1.0.0"
},
"apt": {
"locked_version": "1.10.0"
},
"aws": {
"locked_version": "0.101.0"
},
"xfs": {
"locked_version": "1.1.0"
}
}
}

View File

@ -2,7 +2,7 @@ source "https://rubygems.org"
gem "chef", "~> 11.4.4"
gem "json", "<= 1.7.7" # chef 11 dependency
gem "berkshelf", "~> 1.4.5"
gem "berkshelf", "~> 2.0.3"
gem "chefspec", "~> 1.3.0"
gem "foodcritic"
gem "strainer"

View File

@ -8,26 +8,25 @@ GEM
akami (1.2.0)
gyoku (>= 0.4.0)
nokogiri (>= 1.4.0)
berkshelf (1.4.5)
berkshelf (2.0.3)
activesupport (>= 3.2.0)
addressable
addressable (~> 2.3.4)
celluloid (>= 0.14.0)
chozo (>= 0.6.1)
faraday (>= 0.8.5)
hashie (>= 2.0.2)
json (>= 1.5.0)
minitar
mixlib-config (~> 1.1)
mixlib-shellout (~> 1.1)
multi_json (~> 1.5)
retryable
ridley (~> 0.12.4)
solve (>= 0.4.2)
minitar (~> 0.5.4)
retryable (~> 1.3.3)
ridley (~> 1.0.2)
solve (>= 0.4.4)
test-kitchen (>= 1.0.0.alpha7)
thor (~> 0.18.0)
yajl-ruby
builder (3.2.2)
celluloid (0.14.1)
timers (>= 1.0.0)
celluloid-io (0.14.1)
celluloid (>= 0.14.1)
nio4r (>= 0.4.5)
chef (11.4.4)
erubis
highline (>= 1.6.9)
@ -42,7 +41,7 @@ GEM
ohai (>= 0.6.0)
rest-client (>= 1.0.4, < 1.7.0)
yajl-ruby (~> 1.1)
chefspec (1.3.0)
chefspec (1.3.1)
chef (>= 10.0)
erubis
fauxhai (>= 0.1.1, < 2.0)
@ -54,6 +53,7 @@ GEM
multi_json (>= 1.3.0)
ci_reporter (1.8.4)
builder (>= 2.1.2)
coderay (1.0.9)
diff-lcs (1.2.4)
erubis (2.7.0)
faraday (0.8.7)
@ -62,7 +62,7 @@ GEM
httparty
net-ssh
ohai
ffi (1.8.1)
ffi (1.9.0)
foodcritic (2.1.0)
erubis
gherkin (~> 2.11.7)
@ -91,6 +91,7 @@ GEM
log_switch (0.4.0)
logging (1.6.2)
little-plugger (>= 1.1.3)
method_source (0.8.1)
mime-types (1.23)
minitar (0.5.4)
minitest (4.7.4)
@ -108,12 +109,15 @@ GEM
multi_xml (0.5.4)
multipart-post (1.2.0)
net-http-persistent (2.8)
net-scp (1.1.1)
net-ssh (>= 2.6.5)
net-ssh (2.6.7)
net-ssh-gateway (1.2.0)
net-ssh (>= 2.6.5)
net-ssh-multi (1.1)
net-ssh (>= 2.1.4)
net-ssh-gateway (>= 0.99.0)
nio4r (0.4.6)
nokogiri (1.5.10)
nori (1.1.5)
ohai (6.16.0)
@ -125,22 +129,24 @@ GEM
systemu
yajl-ruby
polyglot (0.3.3)
pry (0.9.12.2)
coderay (~> 1.0.5)
method_source (~> 0.8)
slop (~> 3.4)
rack (1.5.2)
rak (1.4)
rest-client (1.6.7)
mime-types (>= 1.16)
retryable (1.3.3)
ridley (0.12.4)
ridley (1.0.2)
addressable
celluloid (~> 0.14.0)
celluloid-io (~> 0.14.0)
chozo (>= 0.6.0)
erubis
faraday (>= 0.8.4)
hashie (>= 2.0.2)
mixlib-authentication (>= 1.3.0)
mixlib-config (>= 1.1.0)
mixlib-log (>= 1.3.0)
mixlib-shellout (>= 1.1.0)
net-http-persistent (>= 2.8)
net-ssh
retryable
@ -155,6 +161,7 @@ GEM
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.13.1)
rubyntlm (0.1.1)
safe_yaml (0.9.3)
savon (0.9.5)
akami (~> 1.0)
builder (>= 2.1.2)
@ -163,10 +170,11 @@ GEM
nokogiri (>= 1.4.0)
nori (~> 1.0)
wasabi (~> 1.0)
slop (3.4.5)
solve (0.4.4)
json
strainer (2.1.0)
berkshelf (~> 1.3)
strainer (3.0.1)
berkshelf (~> 2.0)
systemu (2.5.2)
tailor (1.2.1)
log_switch (>= 0.3.0)
@ -174,6 +182,14 @@ GEM
text-table (>= 1.2.2)
term-ansicolor (1.2.2)
tins (~> 0.8)
test-kitchen (1.0.0.alpha.7)
celluloid
mixlib-shellout
net-scp
net-ssh
pry
safe_yaml
thor
text-table (1.2.3)
thor (0.18.1)
timers (1.1.0)
@ -198,7 +214,7 @@ PLATFORMS
ruby
DEPENDENCIES
berkshelf (~> 1.4.5)
berkshelf (~> 2.0.3)
chef (~> 11.4.4)
chefspec (~> 1.3.0)
foodcritic

View File

@ -3,132 +3,89 @@ require_relative "spec_helper"
describe "openstack-image::identity_registration" do
before do
image_stubs
@identity_register_mock = double "identity_register"
@chef_run = ::ChefSpec::ChefRunner.new ::UBUNTU_OPTS
@chef_run.converge "openstack-image::identity_registration"
end
it "registers image service" do
::Chef::Recipe.any_instance.stub(:openstack_identity_register)
::Chef::Recipe.any_instance.should_receive(:openstack_identity_register).
with("Register Image Service") do |&arg|
@identity_register_mock.should_receive(:auth_uri).
with "https://127.0.0.1:35357/v2.0"
@identity_register_mock.should_receive(:bootstrap_token).
with "bootstrap-token"
@identity_register_mock.should_receive(:service_name).
with "glance"
@identity_register_mock.should_receive(:service_type).
with "image"
@identity_register_mock.should_receive(:service_description).
with "Glance Image Service"
@identity_register_mock.should_receive(:action).
with :create_service
resource = @chef_run.find_resource(
"openstack-identity_register",
"Register Image Service"
).to_hash
@identity_register_mock.instance_eval &arg
end
chef_run = ::ChefSpec::ChefRunner.new ::UBUNTU_OPTS
chef_run.converge "openstack-image::identity_registration"
expect(resource).to include(
:auth_uri => "https://127.0.0.1:35357/v2.0",
:bootstrap_token => "bootstrap-token",
:service_type => "image",
:service_description => "Glance Image Service",
:action => [:create_service]
)
end
it "registers image endpoint" do
::Chef::Recipe.any_instance.stub(:openstack_identity_register)
::Chef::Recipe.any_instance.should_receive(:openstack_identity_register).
with("Register Image Endpoint") do |&arg|
@identity_register_mock.should_receive(:auth_uri).
with "https://127.0.0.1:35357/v2.0"
@identity_register_mock.should_receive(:bootstrap_token).
with "bootstrap-token"
@identity_register_mock.should_receive(:service_type).
with "image"
@identity_register_mock.should_receive(:endpoint_region).
with "RegionOne"
@identity_register_mock.should_receive(:endpoint_adminurl).
with "https://127.0.0.1:9292/v2"
@identity_register_mock.should_receive(:endpoint_internalurl).
with "https://127.0.0.1:9292/v2"
@identity_register_mock.should_receive(:endpoint_publicurl).
with "https://127.0.0.1:9292/v2"
@identity_register_mock.should_receive(:action).
with :create_endpoint
resource = @chef_run.find_resource(
"openstack-identity_register",
"Register Image Endpoint"
).to_hash
@identity_register_mock.instance_eval &arg
end
chef_run = ::ChefSpec::ChefRunner.new ::UBUNTU_OPTS
chef_run.converge "openstack-image::identity_registration"
expect(resource).to include(
:auth_uri => "https://127.0.0.1:35357/v2.0",
:bootstrap_token => "bootstrap-token",
:service_type => "image",
:endpoint_region => "RegionOne",
:endpoint_adminurl => "https://127.0.0.1:9292/v2",
:endpoint_internalurl => "https://127.0.0.1:9292/v2",
:endpoint_publicurl => "https://127.0.0.1:9292/v2",
:action => [:create_endpoint]
)
end
it "registers service tenant" do
::Chef::Recipe.any_instance.stub(:openstack_identity_register)
::Chef::Recipe.any_instance.should_receive(:openstack_identity_register).
with("Register Service Tenant") do |&arg|
@identity_register_mock.should_receive(:auth_uri).
with "https://127.0.0.1:35357/v2.0"
@identity_register_mock.should_receive(:bootstrap_token).
with "bootstrap-token"
@identity_register_mock.should_receive(:tenant_name).
with "service"
@identity_register_mock.should_receive(:tenant_description).
with "Service Tenant"
@identity_register_mock.should_receive(:tenant_enabled).
with true
@identity_register_mock.should_receive(:action).
with :create_tenant
resource = @chef_run.find_resource(
"openstack-identity_register",
"Register Service Tenant"
).to_hash
@identity_register_mock.instance_eval &arg
end
chef_run = ::ChefSpec::ChefRunner.new ::UBUNTU_OPTS
chef_run.converge "openstack-image::identity_registration"
expect(resource).to include(
:auth_uri => "https://127.0.0.1:35357/v2.0",
:bootstrap_token => "bootstrap-token",
:tenant_name => "service",
:tenant_description => "Service Tenant",
:tenant_enabled => true,
:action => [:create_tenant]
)
end
it "registers service user" do
::Chef::Recipe.any_instance.stub(:openstack_identity_register)
::Chef::Recipe.any_instance.should_receive(:openstack_identity_register).
with("Register glance User") do |&arg|
@identity_register_mock.should_receive(:auth_uri).
with "https://127.0.0.1:35357/v2.0"
@identity_register_mock.should_receive(:bootstrap_token).
with "bootstrap-token"
@identity_register_mock.should_receive(:tenant_name).
with "service"
@identity_register_mock.should_receive(:user_name).
with "glance"
@identity_register_mock.should_receive(:user_pass).
with "glance-pass"
@identity_register_mock.should_receive(:user_enabled).
with true
@identity_register_mock.should_receive(:action).
with :create_user
resource = @chef_run.find_resource(
"openstack-identity_register",
"Register glance User"
).to_hash
@identity_register_mock.instance_eval &arg
end
chef_run = ::ChefSpec::ChefRunner.new ::UBUNTU_OPTS
chef_run.converge "openstack-image::identity_registration"
expect(resource).to include(
:auth_uri => "https://127.0.0.1:35357/v2.0",
:bootstrap_token => "bootstrap-token",
:tenant_name => "service",
:user_name => "glance",
:user_pass => "glance-pass",
:user_enabled => true,
:action => [:create_user]
)
end
it "grants admin role to service user for service tenant" do
::Chef::Recipe.any_instance.stub(:openstack_identity_register)
::Chef::Recipe.any_instance.should_receive(:openstack_identity_register).
with("Grant 'admin' Role to glance User for service Tenant") do |&arg|
@identity_register_mock.should_receive(:auth_uri).
with "https://127.0.0.1:35357/v2.0"
@identity_register_mock.should_receive(:bootstrap_token).
with "bootstrap-token"
@identity_register_mock.should_receive(:tenant_name).
with "service"
@identity_register_mock.should_receive(:role_name).
with "admin"
@identity_register_mock.should_receive(:user_name).
with "glance"
@identity_register_mock.should_receive(:action).
with :grant_role
resource = @chef_run.find_resource(
"openstack-identity_register",
"Grant 'admin' Role to glance User for service Tenant"
).to_hash
@identity_register_mock.instance_eval &arg
end
chef_run = ::ChefSpec::ChefRunner.new ::UBUNTU_OPTS
chef_run.converge "openstack-image::identity_registration"
expect(resource).to include(
:auth_uri => "https://127.0.0.1:35357/v2.0",
:bootstrap_token => "bootstrap-token",
:tenant_name => "service",
:role_name => "admin",
:user_name => "glance",
:action => [:grant_role]
)
end
end