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/ .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 "chef", "~> 11.4.4"
gem "json", "<= 1.7.7" # chef 11 dependency gem "json", "<= 1.7.7" # chef 11 dependency
gem "berkshelf", "~> 1.4.5" gem "berkshelf", "~> 2.0.3"
gem "chefspec", "~> 1.3.0" gem "chefspec", "~> 1.3.0"
gem "foodcritic" gem "foodcritic"
gem "strainer" gem "strainer"

View File

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

View File

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