Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4afbc55

Browse files
author
Joshua Timberman
committed
Merge pull request poise#31 from opscode-cookbooks/COOK-2468
COOK-2468 - Chef 11 compat fixes
2 parents b92d5ca + 3e15959 commit 4afbc55

File tree

9 files changed

+128
-48
lines changed

9 files changed

+128
-48
lines changed

.gitignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.vagrant
2+
Berksfile.lock
3+
*~
4+
*#
5+
.#*
6+
\#*#
7+
.*.sw[a-z]
8+
*.un~
9+
/cookbooks
10+
11+
# Bundler
12+
Gemfile.lock
13+
bin/*
14+
.bundle/*
15+
.kitchen/
16+
.kitchen.local.yml

.kitchen.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
driver_plugin: vagrant
3+
platforms:
4+
- name: ubuntu-12.10
5+
driver_config:
6+
box: canonical-ubuntu-12.10
7+
box_url: http://cloud-images.ubuntu.com/vagrant/quantal/current/quantal-server-cloudimg-amd64-vagrant-disk1.box
8+
require_chef_omnibus: 11.4.0
9+
- name: ubuntu-12.04
10+
driver_config:
11+
box: canonical-ubuntu-12.04
12+
box_url: http://cloud-images.ubuntu.com/vagrant/precise/current/precise-server-cloudimg-amd64-vagrant-disk1.box
13+
require_chef_omnibus: 11.4.0
14+
- name: ubuntu-10.04
15+
driver_config:
16+
box: opscode-ubuntu-10.04
17+
box_url: http://opscode-vm.s3.amazonaws.com/vagrant/opscode_ubuntu-10.04_chef-11.2.0.box
18+
require_chef_omnibus: 11.4.0
19+
- name: centos-5.8
20+
driver_config:
21+
box: opscode-centos-5.8
22+
box_url: http://opscode-vm.s3.amazonaws.com/vagrant/opscode_centos-5.8_chef-11.2.0.box
23+
require_chef_omnibus: 11.4.0
24+
- name: centos-6.3
25+
driver_config:
26+
box: opscode-centos-6.3
27+
box_url: http://opscode-vm.s3.amazonaws.com/vagrant/opscode_centos-6.3_chef-11.2.0.box
28+
require_chef_omnibus: 11.4.0
29+
suites:
30+
- name: default
31+
run_list:
32+
- recipe[python]
33+
attributes: {}

Berksfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
site :opscode
2+
3+
metadata
4+
5+
group :integration do
6+
cookbook "apt"
7+
cookbook "yum"
8+
end

Gemfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
source 'https://rubygems.org'
2+
3+
gem 'foodcritic'
4+
gem 'berkshelf'
5+
gem 'thor-foodcritic'
6+
gem 'vagrant', '~> 1.0.6'
7+
8+
group :integration do
9+
gem 'test-kitchen', :git => "git://github.com/opscode/test-kitchen.git", :branch => '1.0'
10+
gem 'kitchen-vagrant', :git => "git://github.com/opscode/kitchen-vagrant.git"
11+
gem 'kitchen-ec2', :git => "git://github.com/opscode/kitchen-ec2.git"
12+
end

Vagrantfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
require 'kitchen/vagrant'
2+
require 'berkshelf/vagrant'
3+
4+
Vagrant::Config.run do |config|
5+
Kitchen::Vagrant.define_vms(config)
6+
end

providers/pip.rb

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -32,56 +32,56 @@ def whyrun_supported?
3232

3333
action :install do
3434
# If we specified a version, and it's not the current version, move to the specified version
35-
if @new_resource.version != nil && @new_resource.version != @current_resource.version
36-
install_version = @new_resource.version
35+
if new_resource.version != nil && new_resource.version != current_resource.version
36+
install_version = new_resource.version
3737
# If it's not installed at all, install it
38-
elsif @current_resource.version == nil
38+
elsif current_resource.version == nil
3939
install_version = candidate_version
4040
end
4141

4242
if install_version
43-
description = "install package #{@new_resource} version #{install_version}"
43+
description = "install package #{new_resource} version #{install_version}"
4444
converge_by(description) do
45-
Chef::Log.info("Installing #{@new_resource} version #{install_version}")
45+
Chef::Log.info("Installing #{new_resource} version #{install_version}")
4646
status = install_package(install_version)
4747
if status
48-
@new_resource.updated_by_last_action(true)
48+
new_resource.updated_by_last_action(true)
4949
end
5050
end
5151
end
5252
end
5353

5454
action :upgrade do
55-
if @current_resource.version != candidate_version
56-
orig_version = @current_resource.version || "uninstalled"
57-
description = "upgrade #{@current_resource} version from #{@current_resource.version} to #{candidate_version}"
55+
if current_resource.version != candidate_version
56+
orig_version = current_resource.version || "uninstalled"
57+
description = "upgrade #{current_resource} version from #{current_resource.version} to #{candidate_version}"
5858
converge_by(description) do
59-
Chef::Log.info("Upgrading #{@new_resource} version from #{orig_version} to #{candidate_version}")
59+
Chef::Log.info("Upgrading #{new_resource} version from #{orig_version} to #{candidate_version}")
6060
status = upgrade_package(candidate_version)
6161
if status
62-
@new_resource.updated_by_last_action(true)
62+
new_resource.updated_by_last_action(true)
6363
end
6464
end
6565
end
6666
end
6767

6868
action :remove do
6969
if removing_package?
70-
description = "remove package #{@new_resource}"
70+
description = "remove package #{new_resource}"
7171
converge_by(description) do
72-
Chef::Log.info("Removing #{@new_resource}")
73-
remove_package(@new_resource.version)
74-
@new_resource.updated_by_last_action(true)
72+
Chef::Log.info("Removing #{new_resource}")
73+
remove_package(new_resource.version)
74+
new_resource.updated_by_last_action(true)
7575
end
7676
end
7777
end
7878

7979
def removing_package?
80-
if @current_resource.version.nil?
80+
if current_resource.version.nil?
8181
false # nothing to remove
82-
elsif @new_resource.version.nil?
82+
elsif new_resource.version.nil?
8383
true # remove any version of a package
84-
elsif @new_resource.version == @current_resource.version
84+
elsif new_resource.version == current_resource.version
8585
true # remove the version we have
8686
else
8787
false # we don't have the version we want to remove
@@ -93,8 +93,8 @@ def removing_package?
9393
# so refactoring into core Chef should be easy
9494

9595
def load_current_resource
96-
@current_resource = Chef::Resource::PythonPip.new(@new_resource.name)
97-
@current_resource.package_name(@new_resource.package_name)
96+
@current_resource = Chef::Resource::PythonPip.new(new_resource.name)
97+
@current_resource.package_name(new_resource.package_name)
9898
@current_resource.version(nil)
9999

100100
unless current_installed_version.nil?
@@ -108,16 +108,14 @@ def current_installed_version
108108
@current_installed_version ||= begin
109109
delimeter = /==/
110110

111-
version_check_cmd = "#{which_pip(@new_resource)} freeze | grep -i '^#{@new_resource.package_name}=='"
111+
version_check_cmd = "#{which_pip(new_resource)} freeze | grep -i '^#{new_resource.package_name}=='"
112112
# incase you upgrade pip with pip!
113-
if @new_resource.package_name.eql?('pip')
113+
if new_resource.package_name.eql?('pip')
114114
delimeter = /\s/
115115
version_check_cmd = "pip --version"
116116
end
117-
p = shell_out!(version_check_cmd)
118-
p.stdout.split(delimeter)[1].strip
119-
rescue Chef::Exceptions::ShellCommandFailed
120-
rescue Mixlib::ShellOut::ShellCommandFailed
117+
result = shell_out(version_check_cmd)
118+
(result.exitstatus == 0) ? result.stdout.split(delimeter)[1].strip : nil
121119
end
122120
end
123121

@@ -126,14 +124,14 @@ def candidate_version
126124
# `pip search` doesn't return versions yet
127125
# `pip list` may be coming soon:
128126
# https://bitbucket.org/ianb/pip/issue/197/option-to-show-what-version-would-be
129-
@new_resource.version||'latest'
127+
new_resource.version||'latest'
130128
end
131129
end
132130

133131
def install_package(version)
134132
# if a version isn't specified (latest), is a source archive (ex. http://my.package.repo/SomePackage-1.0.4.zip),
135133
# or from a VCS (ex. git+https://git.repo/some_pkg.git) then do not append a version as this will break the source link
136-
if version == 'latest' || @new_resource.name.downcase.start_with?('http:', 'https:') || ['git', 'hg', 'svn'].include?(@new_resource.name.downcase.split('+')[0])
134+
if version == 'latest' || new_resource.name.downcase.start_with?('http:', 'https:') || ['git', 'hg', 'svn'].include?(new_resource.name.downcase.split('+')[0])
137135
version = ''
138136
else
139137
version = "==#{version}"
@@ -142,28 +140,28 @@ def install_package(version)
142140
end
143141

144142
def upgrade_package(version)
145-
@new_resource.options "#{@new_resource.options} --upgrade"
143+
new_resource.options "#{new_resource.options} --upgrade"
146144
install_package(version)
147145
end
148146

149147
def remove_package(version)
150-
@new_resource.options "#{@new_resource.options} --yes"
148+
new_resource.options "#{new_resource.options} --yes"
151149
pip_cmd('uninstall')
152150
end
153151

154152
def pip_cmd(subcommand, version='')
155-
options = { :timeout => @new_resource.timeout, :user => @new_resource.user, :group => @new_resource.group }
156-
options[:environment] = { 'HOME' => ::File.expand_path("~#{@new_resource.user}") } if @new_resource.user
157-
shell_out!("#{which_pip(@new_resource)} #{subcommand} #{@new_resource.options} #{@new_resource.name}#{version}", options)
153+
options = { :timeout => new_resource.timeout, :user => new_resource.user, :group => new_resource.group }
154+
options[:environment] = { 'HOME' => ::File.expand_path("~#{new_resource.user}") } if new_resource.user
155+
shell_out!("#{which_pip(new_resource)} #{subcommand} #{new_resource.options} #{new_resource.name}#{version}", options)
158156
end
159157

160158
# TODO remove when provider is moved into Chef core
161159
# this allows PythonPip to work with Chef::Resource::Package
162160
def which_pip(nr)
163161
if (nr.respond_to?("virtualenv") && nr.virtualenv)
164162
::File.join(nr.virtualenv,'/bin/pip')
165-
elsif "#{node['python']['install_method']}".eql?("source")
166-
::File.join("#{node['python']['prefix_dir']}","/bin/pip")
163+
elsif node['python']['install_method'].eql?("source")
164+
::File.join(node['python']['prefix_dir'], "/bin/pip")
167165
else
168166
'pip'
169167
end

providers/virtualenv.rb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ def whyrun_supported?
2828

2929
action :create do
3030
unless exists?
31-
Chef::Log.info("Creating virtualenv #{@new_resource} at #{@new_resource.path}")
32-
execute "#{virtualenv_cmd} --python=#{@new_resource.interpreter} #{@new_resource.options} #{@new_resource.path}" do
31+
Chef::Log.info("Creating virtualenv #{new_resource} at #{new_resource.path}")
32+
execute "#{virtualenv_cmd} --python=#{new_resource.interpreter} #{new_resource.options} #{new_resource.path}" do
3333
user new_resource.owner if new_resource.owner
3434
group new_resource.group if new_resource.group
3535
end
@@ -39,36 +39,36 @@ def whyrun_supported?
3939

4040
action :delete do
4141
if exists?
42-
description = "delete virtualenv #{@new_resource} at #{@new_resource.path}"
42+
description = "delete virtualenv #{new_resource} at #{new_resource.path}"
4343
converge_by(description) do
44-
Chef::Log.info("Deleting virtualenv #{@new_resource} at #{@new_resource.path}")
45-
FileUtils.rm_rf(@new_resource.path)
44+
Chef::Log.info("Deleting virtualenv #{new_resource} at #{new_resource.path}")
45+
FileUtils.rm_rf(new_resource.path)
4646
end
4747
end
4848
end
4949

5050
def load_current_resource
51-
@current_resource = Chef::Resource::PythonVirtualenv.new(@new_resource.name)
52-
@current_resource.path(@new_resource.path)
51+
@current_resource = Chef::Resource::PythonVirtualenv.new(new_resource.name)
52+
@current_resource.path(new_resource.path)
5353

5454
if exists?
55-
cstats = ::File.stat(@current_resource.path)
55+
cstats = ::File.stat(current_resource.path)
5656
@current_resource.owner(cstats.uid)
5757
@current_resource.group(cstats.gid)
5858
end
5959
@current_resource
6060
end
6161

6262
def virtualenv_cmd()
63-
if "#{node['python']['install_method']}".eql?("source")
64-
::File.join("#{node['python']['prefix_dir']}","/bin/virtualenv")
63+
if node['python']['install_method'].eql?("source")
64+
::File.join(node['python']['prefix_dir'], "/bin/virtualenv")
6565
else
6666
"virtualenv"
6767
end
6868
end
6969

7070
private
7171
def exists?
72-
::File.exist?(@current_resource.path) && ::File.directory?(@current_resource.path) \
73-
&& ::File.exists?("#{@current_resource.path}/bin/activate")
72+
::File.exist?(current_resource.path) && ::File.directory?(current_resource.path) \
73+
&& ::File.exists?("#{current_resource.path}/bin/activate")
7474
end

recipes/package.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
if platform_family?('rhel') && major_version < 6
2626
include_recipe 'yum::epel'
2727
python_pkgs = ["python26", "python26-devel"]
28-
node['python']['binary'] = "/usr/bin/python26"
28+
node.set['python']['binary'] = "/usr/bin/python26"
2929
else
3030
python_pkgs = value_for_platform_family(
3131
"debian" => ["python","python-dev"],

resources/virtualenv.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@
1919
#
2020

2121
actions :create, :delete
22+
default_action :create if defined?(default_action) # Chef > 10.8
23+
24+
# Default action for Chef <= 10.8
25+
def initialize(*args)
26+
super
27+
@action = :create
28+
end
2229

2330
attribute :path, :kind_of => String, :name_attribute => true
2431
attribute :interpreter, :default => 'python'

0 commit comments

Comments
 (0)