move from bundler to chefdk

- deprecated Gemfile
- updated TESTING and README
- updated Rakefile to use chef exec instead of bundle exec
- refactored specs to work with new chefspec version

Change-Id: I8fe06d02043b084484142d4e575f25003ed127af
This commit is contained in:
Jan Klare 2015-04-28 18:15:37 +02:00
parent 57f2b23d35
commit 103b626560
12 changed files with 102 additions and 163 deletions

View File

@ -1,3 +1,7 @@
## THIS GEMFILE IS DEPRECATED AND WILL BE REMOVED AFTER THE NEXT RELEASE
## THERE WON'T BE ANY UPDATES TO THIS FILE DURING THIS RELEASE CYCLE
## WE SWITCHED TO CHEFDK AS THE BUNDLE FOR THE NEEDED GEMS
source 'https://rubygems.org'
gem 'chef', '~> 11.18.6'

View File

@ -253,6 +253,7 @@ Author:: Eric Zhou (zyouzhou@cn.ibm.com)
Author:: Jian Hua Geng (gengjh@cn.ibm.com)
Author:: Ionut Artarisi (iartarisi@suse.cz)
Author:: Imtiaz Chowdhury (<imtiaz.chowdhury@workday.com>)
Author:: Jan Klare (j.klare@x-ion.de)
Copyright 2012, Rackspace US, Inc.
Copyright 2012-2013, Opscode, Inc.

View File

@ -2,32 +2,25 @@ task default: ["test"]
task :test => [:lint, :style, :unit]
task :bundler_prep do
mkdir_p '.bundle'
sh %{bundle install --path=.bundle --jobs 1 --retry 3 --verbose}
task :berks_prep do
sh %{chef exec berks vendor}
end
task :berks_prep => :bundler_prep do
sh %{bundle exec berks vendor}
task :lint do
sh %{chef exec foodcritic --epic-fail any --tags ~FC003 --tags ~FC023 .}
end
task :lint => :bundler_prep do
sh %{bundle exec foodcritic --epic-fail any --tags ~FC003 --tags ~FC023 .}
end
task :style => :bundler_prep do
sh %{bundle exec rubocop}
task :style do
sh %{chef exec rubocop}
end
task :unit => :berks_prep do
sh %{bundle exec rspec --format documentation}
sh %{chef exec rspec --format documentation}
end
task :clean do
rm_rf [
'.bundle',
'berks-cookbooks',
'Gemfile.lock',
'Berksfile.lock'
]
end

View File

@ -1,18 +1,18 @@
# Testing the Cookbook #
This cookbook uses [bundler](http://gembundler.com/) and [berkshelf](http://berkshelf.com/) to isolate dependencies. Make sure you have `ruby 1.9.x`, `bundler`, `rake`, build essentials and the header files for `gecode` installed before continuing. Make sure that you're using gecode version 3. More info [here](https://github.com/opscode/dep-selector-libgecode/tree/0bad63fea305ede624c58506423ced697dd2545e#using-a-system-gecode-instead).
This cookbook uses [chefdk](https://downloads.chef.io/chef-dk/) and [berkshelf](http://berkshelf.com/) to isolate dependencies. Make sure you have chefdk and the header files for `gecode` installed before continuing. Make sure that you're using gecode version 3. More info [here](https://github.com/opscode/dep-selector-libgecode/tree/0bad63fea305ede624c58506423ced697dd2545e#using-a-system-gecode-instead). For more detailed information on what needs to be installed, you can have a quick look into the bootstrap.sh file in this repository, which does install all the needed things to get going on ubuntu trusty. The tests defined in the Rakefile include lint, style and unit. For integration testing please refere to the [openstack-chef-repo](https://github.com/stackforge/openstack-chef-repo).
We have three test suites which you can run individually (there are three rake tasks):
We have three test suites which you can run either, individually (there are three rake tasks):
$ rake lint
$ rake style
$ rake unit
$ chef exec rake lint
$ chef exec rake style
$ chef exec rake unit
or altogether:
$ rake test
$ chef exec rake
The `rake` tasks will take care of installing the needed gem dependencies and cookbooks with `berkshelf`.
The `rake` tasks will take care of installing the needed cookbooks with `berkshelf`.
## Rubocop ##
@ -27,4 +27,4 @@ The `rake` tasks will take care of installing the needed gem dependencies and co
## Chefspec
[ChefSpec](https://github.com/sethvargo/chefspec/) is a unit testing framework for testing Chef cookbooks. ChefSpec makes it easy to write examples and get fast feedback on cookbook changes without the need for virtual machines or cloud servers.
[ChefSpec](https://github.com/sethvargo/chefspec) is a unit testing framework for testing Chef cookbooks. ChefSpec makes it easy to write examples and get fast feedback on cookbook changes without the need for virtual machines or cloud servers.

View File

@ -3,7 +3,7 @@ require_relative 'spec_helper'
describe 'openstack-image::api' do
describe 'redhat' do
let(:runner) { ChefSpec::Runner.new(REDHAT_OPTS) }
let(:runner) { ChefSpec::SoloRunner.new(REDHAT_OPTS) }
let(:node) { runner.node }
let(:chef_run) do
runner.converge(described_recipe)

View File

@ -21,7 +21,7 @@ end
describe 'openstack-image::api' do
describe 'ubuntu' do
let(:runner) { ChefSpec::Runner.new(UBUNTU_OPTS) }
let(:runner) { ChefSpec::SoloRunner.new(UBUNTU_OPTS) }
let(:node) { runner.node }
let(:chef_run) do
runner.converge(described_recipe)

View File

@ -5,7 +5,7 @@ describe 'openstack-image::client' do
describe 'redhat' do
let(:runner) { ChefSpec::Runner.new(REDHAT_OPTS) }
let(:runner) { ChefSpec::SoloRunner.new(REDHAT_OPTS) }
let(:node) { runner.node }
let(:chef_run) do
runner.converge(described_recipe)

View File

@ -5,7 +5,7 @@ describe 'openstack-image::client' do
describe 'ubuntu' do
let(:runner) { ChefSpec::Runner.new(UBUNTU_OPTS) }
let(:runner) { ChefSpec::SoloRunner.new(UBUNTU_OPTS) }
let(:node) { runner.node }
let(:chef_run) do
runner.converge(described_recipe)

View File

@ -2,7 +2,7 @@
require_relative 'spec_helper'
describe 'openstack-image::identity_registration' do
let(:runner) { ChefSpec::Runner.new(UBUNTU_OPTS) }
let(:runner) { ChefSpec::SoloRunner.new(UBUNTU_OPTS) }
let(:node) { runner.node }
let(:chef_run) do
runner.converge(described_recipe)
@ -11,111 +11,76 @@ describe 'openstack-image::identity_registration' do
include_context 'image-stubs'
it 'registers image service' do
resource = chef_run.find_resource(
'openstack-identity_register',
'Register Image Service'
).to_hash
expect(resource).to include(
auth_uri: 'http://127.0.0.1:35357/v2.0',
bootstrap_token: 'bootstrap-token',
service_type: 'image',
service_description: 'Glance Image Service',
action: [:create_service]
)
expect(chef_run).to create_service_openstack_identity_register('Register Image Service')
.with(auth_uri: 'http://127.0.0.1:35357/v2.0',
bootstrap_token: 'bootstrap-token',
service_type: 'image',
service_description: 'Glance Image Service'
)
end
context 'registers compute endpoint' do
it 'with default values' do
resource = chef_run.find_resource(
'openstack-identity_register',
'Register Image Endpoint'
).to_hash
expect(resource).to include(
auth_uri: 'http://127.0.0.1:35357/v2.0',
bootstrap_token: 'bootstrap-token',
service_type: 'image',
endpoint_region: 'RegionOne',
endpoint_adminurl: 'http://127.0.0.1:9292',
endpoint_internalurl: 'http://127.0.0.1:9292',
endpoint_publicurl: 'http://127.0.0.1:9292',
action: [:create_endpoint]
)
expect(chef_run).to create_endpoint_openstack_identity_register('Register Image Endpoint')
.with(auth_uri: 'http://127.0.0.1:35357/v2.0',
bootstrap_token: 'bootstrap-token',
service_type: 'image',
endpoint_region: 'RegionOne',
endpoint_adminurl: 'http://127.0.0.1:9292',
endpoint_internalurl: 'http://127.0.0.1:9292',
endpoint_publicurl: 'http://127.0.0.1:9292'
)
end
it 'with custom region override' do
node.set['openstack']['image']['region'] = 'imageRegion'
resource = chef_run.find_resource(
'openstack-identity_register',
'Register Image Endpoint'
).to_hash
expect(resource).to include(
endpoint_region: 'imageRegion',
action: [:create_endpoint]
)
expect(chef_run).to create_endpoint_openstack_identity_register('Register Image Endpoint')
.with(endpoint_region: 'imageRegion')
end
it 'with different public url' do
public_url = 'https://public.host:123/public_path'
node.set['openstack']['endpoints']['public']['image-api']['uri'] = public_url
resource = chef_run.find_resource(
'openstack-identity_register',
'Register Image Endpoint'
).to_hash
expect(resource).to include(
auth_uri: 'http://127.0.0.1:35357/v2.0',
bootstrap_token: 'bootstrap-token',
service_type: 'image',
endpoint_region: 'RegionOne',
endpoint_adminurl: 'http://127.0.0.1:9292',
endpoint_internalurl: 'http://127.0.0.1:9292',
endpoint_publicurl: public_url,
action: [:create_endpoint]
)
expect(chef_run).to create_endpoint_openstack_identity_register('Register Image Endpoint')
.with(auth_uri: 'http://127.0.0.1:35357/v2.0',
bootstrap_token: 'bootstrap-token',
service_type: 'image',
endpoint_region: 'RegionOne',
endpoint_adminurl: 'http://127.0.0.1:9292',
endpoint_internalurl: 'http://127.0.0.1:9292',
endpoint_publicurl: public_url
)
end
it 'with different admin url' do
admin_url = 'http://admin.host:456/admin_path'
node.set['openstack']['endpoints']['admin']['image-api']['uri'] = admin_url
node.set['openstack']['endpoints']['identity-admin']['uri'] = 'http://127.0.0.1:35357/v2.0'
resource = chef_run.find_resource(
'openstack-identity_register',
'Register Image Endpoint'
).to_hash
expect(resource).to include(
auth_uri: 'http://127.0.0.1:35357/v2.0',
bootstrap_token: 'bootstrap-token',
service_type: 'image',
endpoint_region: 'RegionOne',
endpoint_adminurl: admin_url,
endpoint_internalurl: 'http://127.0.0.1:9292',
endpoint_publicurl: 'http://127.0.0.1:9292',
action: [:create_endpoint]
)
expect(chef_run).to create_endpoint_openstack_identity_register('Register Image Endpoint')
.with(auth_uri: 'http://127.0.0.1:35357/v2.0',
bootstrap_token: 'bootstrap-token',
service_type: 'image',
endpoint_region: 'RegionOne',
endpoint_adminurl: admin_url,
endpoint_internalurl: 'http://127.0.0.1:9292',
endpoint_publicurl: 'http://127.0.0.1:9292'
)
end
it 'with different internal url' do
internal_url = 'http://internal.host:789/internal_path'
node.set['openstack']['endpoints']['internal']['image-api']['uri'] = internal_url
resource = chef_run.find_resource(
'openstack-identity_register',
'Register Image Endpoint'
).to_hash
expect(resource).to include(
auth_uri: 'http://127.0.0.1:35357/v2.0',
bootstrap_token: 'bootstrap-token',
service_type: 'image',
endpoint_region: 'RegionOne',
endpoint_adminurl: 'http://127.0.0.1:9292',
endpoint_internalurl: internal_url,
endpoint_publicurl: 'http://127.0.0.1:9292',
action: [:create_endpoint]
expect(chef_run).to create_endpoint_openstack_identity_register('Register Image Endpoint')
.with(auth_uri: 'http://127.0.0.1:35357/v2.0',
bootstrap_token: 'bootstrap-token',
service_type: 'image',
endpoint_region: 'RegionOne',
endpoint_adminurl: 'http://127.0.0.1:9292',
endpoint_internalurl: internal_url,
endpoint_publicurl: 'http://127.0.0.1:9292'
)
end
@ -126,72 +91,48 @@ describe 'openstack-image::identity_registration' do
node.set['openstack']['endpoints']['internal']['image-api']['uri'] = internal_url
node.set['openstack']['endpoints']['admin']['image-api']['uri'] = admin_url
node.set['openstack']['endpoints']['identity-admin']['uri'] = 'http://127.0.0.1:35357/v2.0'
node.set['openstack']['endpoints']['public']['image-api']['uri'] = public_url
resource = chef_run.find_resource(
'openstack-identity_register',
'Register Image Endpoint'
).to_hash
expect(resource).to include(
auth_uri: 'http://127.0.0.1:35357/v2.0',
bootstrap_token: 'bootstrap-token',
service_type: 'image',
endpoint_region: 'RegionOne',
endpoint_adminurl: admin_url,
endpoint_internalurl: internal_url,
endpoint_publicurl: public_url,
action: [:create_endpoint]
)
expect(chef_run).to create_endpoint_openstack_identity_register('Register Image Endpoint')
.with(auth_uri: 'http://127.0.0.1:35357/v2.0',
bootstrap_token: 'bootstrap-token',
service_type: 'image',
endpoint_region: 'RegionOne',
endpoint_adminurl: admin_url,
endpoint_internalurl: internal_url,
endpoint_publicurl: public_url
)
end
end
it 'registers service tenant' do
resource = chef_run.find_resource(
'openstack-identity_register',
'Register Service Tenant'
).to_hash
expect(resource).to include(
auth_uri: 'http://127.0.0.1:35357/v2.0',
bootstrap_token: 'bootstrap-token',
tenant_name: 'service',
tenant_description: 'Service Tenant',
tenant_enabled: true,
action: [:create_tenant]
)
expect(chef_run).to create_tenant_openstack_identity_register('Register Service Tenant')
.with(auth_uri: 'http://127.0.0.1:35357/v2.0',
bootstrap_token: 'bootstrap-token',
tenant_name: 'service',
tenant_description: 'Service Tenant',
tenant_enabled: true
)
end
it 'registers service user' do
resource = chef_run.find_resource(
'openstack-identity_register',
'Register glance User'
).to_hash
expect(resource).to include(
auth_uri: 'http://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]
)
expect(chef_run).to create_user_openstack_identity_register('Register glance User')
.with(auth_uri: 'http://127.0.0.1:35357/v2.0',
bootstrap_token: 'bootstrap-token',
tenant_name: 'service',
user_name: 'glance',
user_pass: 'glance-pass',
user_enabled: true
)
end
it 'grants service role to service user for service tenant' do
resource = chef_run.find_resource(
'openstack-identity_register',
"Grant 'service' Role to glance User for service Tenant"
).to_hash
expect(resource).to include(
auth_uri: 'http://127.0.0.1:35357/v2.0',
bootstrap_token: 'bootstrap-token',
tenant_name: 'service',
role_name: 'service',
user_name: 'glance',
action: [:grant_role]
)
expect(chef_run).to grant_role_openstack_identity_register("Grant 'service' Role to glance User for service Tenant")
.with(auth_uri: 'http://127.0.0.1:35357/v2.0',
bootstrap_token: 'bootstrap-token',
tenant_name: 'service',
role_name: 'service',
user_name: 'glance'
)
end
end

View File

@ -3,7 +3,7 @@ require_relative 'spec_helper'
describe 'openstack-image::image_upload' do
describe 'ubuntu' do
let(:runner) { ChefSpec::Runner.new(UBUNTU_OPTS.merge(step_into: ['openstack_image_image'])) }
let(:runner) { ChefSpec::SoloRunner.new(UBUNTU_OPTS.merge(step_into: ['openstack_image_image'])) }
let(:node) { runner.node }
let(:chef_run) do
runner.converge(described_recipe)

View File

@ -3,7 +3,7 @@ require_relative 'spec_helper'
describe 'openstack-image::registry' do
describe 'redhat' do
let(:runner) { ChefSpec::Runner.new(REDHAT_OPTS) }
let(:runner) { ChefSpec::SoloRunner.new(REDHAT_OPTS) }
let(:node) { runner.node }
let(:chef_run) do
runner.converge(described_recipe)

View File

@ -9,7 +9,7 @@ describe 'openstack-image::registry' do
stub_command('glance-manage db_version').and_return(true)
end
let(:runner) { ChefSpec::Runner.new(UBUNTU_OPTS) }
let(:runner) { ChefSpec::SoloRunner.new(UBUNTU_OPTS) }
let(:node) { runner.node }
let(:chef_run) do
runner.converge(described_recipe)