diff --git a/README.md b/README.md index bedbce4..2d03de4 100644 --- a/README.md +++ b/README.md @@ -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 ========== diff --git a/libraries/matchers.rb b/libraries/matchers.rb new file mode 100644 index 0000000..9450704 --- /dev/null +++ b/libraries/matchers.rb @@ -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 diff --git a/spec/image_upload_spec.rb b/spec/image_upload_spec.rb index 324081c..94060a6 100644 --- a/spec/image_upload_spec.rb +++ b/spec/image_upload_spec.rb @@ -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