Change image_upload spec to not test the LWRP

Before this change, the image_upload recipe was kind of used to test the
LWRP that is defined by this cookbook.  Now, it only checks the
resources that appear in that recipe.

To make that work, a libraries/matchers.rb was added that helps ChefSpec
cope with the dash in the cookbook name.

Change-Id: I632556c9924d1be946b033a8759c0f3de15d91e0
This commit is contained in:
Stephan Renatus 2014-06-12 11:53:15 +02:00
parent 41241a8916
commit 78803f2456
3 changed files with 17 additions and 39 deletions

View File

@ -93,6 +93,8 @@ Action: `:upload`
- `:identity_tenant`: Name of the Keystone admin user's tenant.
- `:identity_uri`: URI of the Identity API endpoint.
For testing this provider with ChefSpec, a custom matcher was added to `libraries/matchers.rb`.
Attributes
==========

6
libraries/matchers.rb Normal file
View File

@ -0,0 +1,6 @@
# encoding: UTF-8
if defined?(ChefSpec)
def upload_openstack_image_image(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:openstack_image_image, :upload, resource_name)
end
end

View File

@ -3,8 +3,7 @@ require_relative 'spec_helper'
describe 'openstack-image::image_upload' do
describe 'ubuntu' do
let(:runner) { ChefSpec::Runner.new(options) }
let(:options) { UBUNTU_OPTS.merge(step_into: 'openstack_image_image') }
let(:runner) { ChefSpec::Runner.new(UBUNTU_OPTS) }
let(:node) { runner.node }
let(:chef_run) do
runner.converge(described_recipe)
@ -12,46 +11,17 @@ describe 'openstack-image::image_upload' do
include_context 'image-stubs'
it 'uploads qcow image when one does not exist' do
node.set['openstack']['image'] = {
'upload_images' => ['image1'],
'upload_image' => {
'image1' => 'http://example.com/image.qcow2'
}
}
include_examples 'common-logging-recipe'
list_cmd = 'glance --insecure ' \
'--os-username glance ' \
'--os-password glance-pass ' \
'--os-tenant-name service '\
'--os-image-url http://127.0.0.1:9292 ' \
'--os-auth-url http://127.0.0.1:5000/v2.0 ' \
'image-list | grep image1'
stub_command(list_cmd).and_return(false)
expect(chef_run).to run_execute('Uploading QCOW2 image image1')
it 'upgrades the client packages' do
expect(chef_run).to upgrade_package('python-glanceclient')
end
it 'does not upload qcow image if it already exists' do
node.set['openstack']['image'] = {
'upload_images' => ['image1'],
'upload_image' => {
'image1' => 'http://example.com/image.qcow2'
}
}
list_cmd = "glance --insecure " \
"--os-username glance " \
"--os-password glance-pass " \
"--os-tenant-name service "\
"--os-image-url http://127.0.0.1:9292 " \
"--os-auth-url http://127.0.0.1:5000/v2.0 " \
"image-list | grep image1"
stub_command(list_cmd).and_return(true)
expect(chef_run).to_not run_execute('Uploading QCOW2 image image1')
it 'uploads the cirros image' do
expect(chef_run).to upload_openstack_image_image('Image setup for cirros').with(
image_url: 'http://download.cirros-cloud.net/0.3.2/cirros-0.3.2-x86_64-disk.img',
image_name: 'cirros'
)
end
end
end