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: I21c1c000581f2d3c94ff2f9628f0cea0f6536013
This commit is contained in:
John Dewey
2013-06-08 21:56:38 -07:00
parent 1b08dc7153
commit 2f7915360a
5 changed files with 165 additions and 122 deletions

1
.gitignore vendored
View File

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

68
Berksfile.lock Normal file
View File

@@ -0,0 +1,68 @@
{
"sha": "ba71763fac936d414bd4a63f004357f86f6e1bfb",
"sources": {
"openstack-block-storage": {
"locked_version": "7.0.0",
"constraint": "= 7.0.0",
"path": "."
},
"openstack-image": {
"locked_version": "7.0.0",
"git": "git://github.com/stackforge/cookbook-openstack-image.git",
"ref": "5cc19cee1cb0becba653cdf7781e492bbe5f84e7"
},
"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"
},
"apt": {
"locked_version": "1.10.0"
},
"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"
},
"aws": {
"locked_version": "0.101.0"
},
"xfs": {
"locked_version": "1.1.0"
},
"openssh": {
"locked_version": "1.1.4"
},
"rabbitmq": {
"locked_version": "2.1.0"
},
"erlang": {
"locked_version": "1.3.0",
"constraint": ">= 0.9.0"
},
"yum": {
"locked_version": "2.2.2",
"constraint": ">= 0.5.0"
},
"selinux": {
"locked_version": "0.5.6"
}
}
}

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,13 +109,16 @@ 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)
nokogiri (1.5.9)
nio4r (0.4.6)
nokogiri (1.5.10)
nori (1.1.5)
ohai (6.16.0)
ipaddress
@@ -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,120 +3,80 @@ require_relative "spec_helper"
describe "openstack-block-storage::identity_registration" do
before do
block_storage_stubs
@identity_register_mock = double "identity_register"
@chef_run = ::ChefSpec::ChefRunner.new ::UBUNTU_OPTS
@chef_run.converge "openstack-block-storage::identity_registration"
end
it "registers cinder volume service" do
::Chef::Recipe.any_instance.stub(:openstack_identity_register)
::Chef::Recipe.any_instance.should_receive(:openstack_identity_register).
with("Register Cinder Volume 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 "cinder"
@identity_register_mock.should_receive(:service_type).
with "volume"
@identity_register_mock.should_receive(:service_description).
with "Cinder Volume Service"
@identity_register_mock.should_receive(:endpoint_region).
with "RegionOne"
@identity_register_mock.should_receive(:endpoint_adminurl).
with "https://127.0.0.1:8776/v1/%(tenant_id)s"
@identity_register_mock.should_receive(:endpoint_internalurl).
with "https://127.0.0.1:8776/v1/%(tenant_id)s"
@identity_register_mock.should_receive(:endpoint_publicurl).
with "https://127.0.0.1:8776/v1/%(tenant_id)s"
@identity_register_mock.should_receive(:action).
with :create_service
resource = @chef_run.find_resource(
"openstack-identity_register",
"Register Cinder Volume Service"
).to_hash
@identity_register_mock.instance_eval &arg
end
chef_run = ::ChefSpec::ChefRunner.new ::UBUNTU_OPTS
chef_run.converge "openstack-block-storage::identity_registration"
expect(resource).to include(
:auth_uri => "https://127.0.0.1:35357/v2.0",
:bootstrap_token => "bootstrap-token",
:service_name => "cinder",
:service_type => "volume",
:service_description => "Cinder Volume Service",
:endpoint_region => "RegionOne",
:endpoint_adminurl => "https://127.0.0.1:8776/v1/%(tenant_id)s",
:endpoint_internalurl => "https://127.0.0.1:8776/v1/%(tenant_id)s",
:endpoint_publicurl => "https://127.0.0.1:8776/v1/%(tenant_id)s",
:action => [:create_service]
)
end
it "registers cinder volume endpoint" do
::Chef::Recipe.any_instance.stub(:openstack_identity_register)
::Chef::Recipe.any_instance.should_receive(:openstack_identity_register).
with("Register Cinder Volume 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_name).
with "cinder"
@identity_register_mock.should_receive(:service_type).
with "volume"
@identity_register_mock.should_receive(:service_description).
with "Cinder Volume Service"
@identity_register_mock.should_receive(:endpoint_region).
with "RegionOne"
@identity_register_mock.should_receive(:endpoint_adminurl).
with "https://127.0.0.1:8776/v1/%(tenant_id)s"
@identity_register_mock.should_receive(:endpoint_internalurl).
with "https://127.0.0.1:8776/v1/%(tenant_id)s"
@identity_register_mock.should_receive(:endpoint_publicurl).
with "https://127.0.0.1:8776/v1/%(tenant_id)s"
@identity_register_mock.should_receive(:action).
with :create_endpoint
resource = @chef_run.find_resource(
"openstack-identity_register",
"Register Cinder Volume Endpoint"
).to_hash
@identity_register_mock.instance_eval &arg
end
chef_run = ::ChefSpec::ChefRunner.new ::UBUNTU_OPTS
chef_run.converge "openstack-block-storage::identity_registration"
expect(resource).to include(
:auth_uri => "https://127.0.0.1:35357/v2.0",
:bootstrap_token => "bootstrap-token",
:service_name => "cinder",
:service_type => "volume",
:service_description => "Cinder Volume Service",
:endpoint_region => "RegionOne",
:endpoint_adminurl => "https://127.0.0.1:8776/v1/%(tenant_id)s",
:endpoint_internalurl => "https://127.0.0.1:8776/v1/%(tenant_id)s",
:endpoint_publicurl => "https://127.0.0.1:8776/v1/%(tenant_id)s",
:action => [:create_endpoint]
)
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 Cinder Service 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 "cinder"
@identity_register_mock.should_receive(:user_pass).
with "cinder-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 Cinder Service User"
).to_hash
@identity_register_mock.instance_eval &arg
end
chef_run = ::ChefSpec::ChefRunner.new ::UBUNTU_OPTS
chef_run.converge "openstack-block-storage::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 => "cinder",
:user_pass => "cinder-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 service Role to Cinder Service User for Cinder 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(:user_name).
with "cinder"
@identity_register_mock.should_receive(:role_name).
with "admin"
@identity_register_mock.should_receive(:action).
with :grant_role
resource = @chef_run.find_resource(
"openstack-identity_register",
"Grant service Role to Cinder Service User for Cinder Service Tenant"
).to_hash
@identity_register_mock.instance_eval &arg
end
chef_run = ::ChefSpec::ChefRunner.new ::UBUNTU_OPTS
chef_run.converge "openstack-block-storage::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 => "cinder",
:role_name => "admin",
:action => [:grant_role]
)
end
end