I'm no developer and a newbie with Chef.
I created a simple recipe and tested it on a test Kitchen and it works well but when I upload it to Jenkins it won't pass.
Can you help me point out what I'm missing?
Recipe:
# Recipe:: default
# Download VerneMQ
remote_file "#{Chef::Config[:file_cache_path]}/vernemq_1.4.0-1_amd64.deb" do
source 'https://bintray.com/artifact/download/erlio/vernemq/deb/trusty/vernemq_1.4.0-1_amd64.deb'
end
# Install
dpkg_package 'vernemq_1.4.0-1_amd64.deb' do
source "#{Chef::Config[:file_cache_path]}/vernemq_1.4.0-1_amd64.deb"
action :install
end
# Service Start
service 'vernemq' do
action [:enable, :start]
end
# Configurations
template '/etc/vernemq/vernemq.conf' do
source 'vernemq.conf.erb'
owner 'root'
group 'root'
mode '0644'
end
template '/etc/vernemq/vmq.passwd' do
source 'vmq.passwd.erb'
end
This is my unit test.
Unit Test:
require 'spec_helper'
require 'chefspec'
describe 'vernemq::default' do
let(:chef_run) { ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '14.04').converge(described_recipe) }
it 'downloads the remote_file' do
expect(chef_run).to create_remote_file('#{Chef::Config[:file_cache_path]}/vernemq_1.4.0-1_amd64.deb')
end
it 'installs a dpkg_package' do
expect(chef_run).to install_dpkg_package('vernemq')
end
it 'executes both actions' do
expect(chef_run).to enable_service('vernemq')
expect(chef_run).to start_service('vernemq')
end
it 'creates a file' do
expect(chef_run).to create_directory('/etc/vernemq/vernemq.conf')
end
it 'creates a file' do
expect(chef_run).to create_directory('/etc/vernemq/vmq.passwd')
end
end
errors from Jenkins
01:06:57 tm_vernemq::default
01:06:58 [2018-07-19T01:06:58-07:00] WARN: Chef::Provider::AptRepository already exists! Cannot create deprecation class for LWRP provider apt_repository from cookbook apt
01:06:58 [2018-07-19T01:06:58-07:00] WARN: Property sensitive
of resource apt_repository
overwrites an existing method. Please use a different property name. This will raise an exception in Chef 13. (CHEF-11)/tmp/d20180719-10648-933ma2/cookbooks/apt/resources/repository.rb:54:in class_from_file'.
01:06:58 Please see https://docs.chef.io/deprecations_property_name_collision.html for further details and information on how to correct this problem. at /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/chef-12.19.36/lib/chef/event_dispatch/dispatcher.rb:43:in
call'
01:06:58 [2018-07-19T01:06:58-07:00] WARN: AptRepository already exists! Deprecation class overwrites Custom resource apt_repository from cookbook apt
01:06:58 executes both actions
01:06:58 installs a dpkg_package (FAILED - 1)
01:06:58 creates a file (FAILED - 2)
01:06:58 creates a file (FAILED - 3)
01:06:58 downloads the remote_file (FAILED - 4)
01:06:58
01:06:58 Failures:
01:06:58
01:06:58 1) vernemq::default installs a dpkg_package
01:06:58 Failure/Error: expect(chef_run).to install_dpkg_package('vernemq')
01:06:58
01:06:58 expected "dpkg_package[vernemq]" with action :install to be in Chef run. Other dpkg_package resources:
01:06:58
01:06:58 dpkg_package[vernemq_1.4.0-1_amd64.deb]
01:06:58
01:06:58 # ./test/unit/recipes/default_spec.rb:18:in `block (2 levels) in <top (required)>'
01:06:58
01:06:58 2) tm_vernemq::default creates a file
01:06:58 Failure/Error: expect(chef_run).to create_directory('/etc/vernemq/vmq.passwd')
01:06:58
01:06:58 expected "directory[/etc/vernemq/vmq.passwd]" with action :create to be in Chef run. Other directory resources:
01:06:58