Update users cookbook and poise cookbooks

The poise cookbooks were incompatible with Chef 13
This commit is contained in:
Greg Karékinian
2017-06-16 15:50:13 +02:00
parent f93070c4c0
commit ff3d062c73
65 changed files with 238 additions and 130 deletions

View File

@@ -1,5 +1,10 @@
# Changelog
## v2.1.1
* Fix the SCL repository enable command for RHEL.
* Internal refactoring of the system package installer.
## v2.1.0
* Allow customizing properties on the system package install resource via a block

View File

@@ -108,7 +108,7 @@ module PoiseLanguages
# KNOW BY FILING A GITHUB ISSUE AT http://github.com/poise/poise-languages/issues/new.
repo_name = "rhel-server-rhscl-#{node['platform_version'][0]}-rpms"
execute "subscription-manager repos --enable #{repo_name}" do
not_if { shell_out!('subscription-manager repos --list').stdout.include?(repo_name) }
not_if { shell_out!('subscription-manager repos --list-enabled').stdout.include?(repo_name) }
end
else
package 'centos-release-scl-rh' do

View File

@@ -97,60 +97,86 @@ module PoiseLanguages
#
# @return [void]
def action_install
run_package_action(:install)
notifying_block do
install_packages
run_action_hack
end
end
# The `upgrade` action for the `poise_languages_system` resource.
#
# @return [void]
def action_upgrade
run_package_action(:upgrade)
notifying_block do
upgrade_packages
run_action_hack
end
end
# The `uninstall` action for the `poise_languages_system` resource.
#
# @return [void]
def action_uninstall
action = node.platform_family?('debian') ? :purge : :remove
package_resources(action).each do |resource|
resource.run_action(action)
new_resource.updated_by_last_action(true) if resource.updated_by_last_action?
notifying_block do
uninstall_packages
end
end
private
# Create package resource objects for all needed packages. These are created
# directly and not added to the resource collection.
# Install the needed language packages.
#
# @return [Array<Chef::Resource::Package>]
def package_resources(action)
# @api private
# @return [Array<Chef::Resource>]
def install_packages
packages = {new_resource.package_name => new_resource.package_version}
# If we are supposed to install the dev package, grab it using the same
# version as the main package.
if new_resource.dev_package
packages[new_resource.dev_package] = new_resource.package_version
end
Chef::Log.debug("[#{new_resource.parent}] Building package resource using #{packages.inspect}.")
# Check for multi-package support.
package_resource_class = Chef::Resource.resource_for_node(:package, node)
@package_resource ||= if node.platform_family?('rhel', 'fedora', 'amazon', 'mac_os_x')
# @todo Can't use multi-package mode with yum pending https://github.com/chef/chef/issues/3476.
packages.map do |name, version|
package_resource_class.new(name, run_context).tap do |r|
r.version(version)
r.action(action)
r.declared_type = :package
r.retries(5)
end
package_provider_class = package_resource_class.new('multipackage_check', run_context).provider_for_action(:install)
package_resources = if package_provider_class.respond_to?(:use_multipackage_api?) && package_provider_class.use_multipackage_api?
package packages.keys do
version packages.values
end
else
[package_resource_class.new(packages.keys, run_context).tap do |r|
r.version(packages.values)
r.action(action)
r.declared_type = :package
r.retries(5)
end]
# Fallback for non-multipackage.
packages.map do |pkg_name, pkg_version|
package pkg_name do
version pkg_version
end
end
end
# Apply some settings to all of the resources.
Array(package_resources).each do |res|
res.retries(5)
res.define_singleton_method(:apply_action_hack?) { true }
end
end
# Upgrade the needed language packages.
#
# @api private
# @return [Array<Chef::Resource>]
def upgrade_packages
install_packages.each do |res|
res.action(:upgrade)
end
end
# Uninstall the needed language packages.
#
# @api private
# @return [Array<Chef::Resource>]
def uninstall_packages
install_packages.each do |res|
res.action(node.platform_family?('debian') ? :purge : :remove)
end
end
@@ -161,21 +187,34 @@ module PoiseLanguages
#
# @param action [Symbol] Action to run on all package resources.
# @return [void]
def run_package_action(action)
package_resources(action).each do |resource|
# Reset it so we have a clean baseline.
resource.updated_by_last_action(false)
# Grab the provider.
provider = resource.provider_for_action(action)
provider.action = action
# Check the candidate version if needed. With a manual package_version
# you get whatever you asked for.
patch_load_current_resource!(provider, new_resource.version) unless new_resource.package_version
# Run our action.
Chef::Log.debug("[#{new_resource.parent}] Running #{provider} with #{action}")
provider.run_action(action)
# Check updated flag.
new_resource.updated_by_last_action(true) if resource.updated_by_last_action?
def run_action_hack
# If new_resource.package_version is set, skip this madness.
return if new_resource.package_version
# Process every resource in the current collection, which is bounded
# by notifying_block.
run_context.resource_collection.each do |resource|
# Only apply to things we tagged above.
next unless resource.respond_to?(:apply_action_hack?) && resource.apply_action_hack?
Array(resource.action).each do |action|
# Reset it so we have a clean baseline.
resource.updated_by_last_action(false)
# Grab the provider.
provider = resource.provider_for_action(action)
provider.action = action
# Inject our check for the candidate version. This will actually
# get run during run_action below.
patch_load_current_resource!(provider, new_resource.version)
# Run our action.
Chef::Log.debug("[#{new_resource.parent}] Running #{provider} with #{action}")
provider.run_action(action)
# Check updated flag.
new_resource.updated_by_last_action(true) if resource.updated_by_last_action?
end
# Make sure the resource doesn't run again when notifying_block ends.
resource.action(:nothing)
end
end

View File

@@ -16,5 +16,5 @@
module PoiseLanguages
VERSION = '2.1.0'
VERSION = '2.1.1'
end

View File

@@ -1 +1 @@
{"name":"poise-languages","version":"2.1.0","description":"A Chef cookbook to help writing language cookbooks.","long_description":"# Poise-Languages Cookbook\n\n[![Build Status](https://img.shields.io/travis/poise/poise-languages.svg)](https://travis-ci.org/poise/poise-languages)\n[![Gem Version](https://img.shields.io/gem/v/poise-languages.svg)](https://rubygems.org/gems/poise-languages)\n[![Cookbook Version](https://img.shields.io/cookbook/v/poise-languages.svg)](https://supermarket.chef.io/cookbooks/poise-languages)\n[![Coverage](https://img.shields.io/codecov/c/github/poise/poise-languages.svg)](https://codecov.io/github/poise/poise-languages)\n[![Gemnasium](https://img.shields.io/gemnasium/poise/poise-languages.svg)](https://gemnasium.com/poise/poise-languages)\n[![License](https://img.shields.io/badge/license-Apache_2-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)\n\nShared support code for Poise's language cookbooks like poise-ruby and\npoise-python.\n\n## License\n\nCopyright 2015-2017, Noah Kantrowitz\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\nhttp://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n","maintainer":"Noah Kantrowitz","maintainer_email":"noah@coderanger.net","license":"Apache 2.0","platforms":{},"dependencies":{"poise":"~> 2.5","poise-archive":"~> 1.0"},"recommendations":{},"suggestions":{},"conflicting":{},"providing":{},"replacing":{},"attributes":{},"groupings":{},"recipes":{},"source_url":"https://github.com/poise/poise-languages","issues_url":"https://github.com/poise/poise-languages/issues","chef_version":[["< 14",">= 12.1"],[]],"ohai_version":[[]]}
{"name":"poise-languages","version":"2.1.1","description":"A Chef cookbook to help writing language cookbooks.","long_description":"# Poise-Languages Cookbook\n\n[![Build Status](https://img.shields.io/travis/poise/poise-languages.svg)](https://travis-ci.org/poise/poise-languages)\n[![Gem Version](https://img.shields.io/gem/v/poise-languages.svg)](https://rubygems.org/gems/poise-languages)\n[![Cookbook Version](https://img.shields.io/cookbook/v/poise-languages.svg)](https://supermarket.chef.io/cookbooks/poise-languages)\n[![Coverage](https://img.shields.io/codecov/c/github/poise/poise-languages.svg)](https://codecov.io/github/poise/poise-languages)\n[![Gemnasium](https://img.shields.io/gemnasium/poise/poise-languages.svg)](https://gemnasium.com/poise/poise-languages)\n[![License](https://img.shields.io/badge/license-Apache_2-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)\n\nShared support code for Poise's language cookbooks like poise-ruby and\npoise-python.\n\n## License\n\nCopyright 2015-2017, Noah Kantrowitz\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\nhttp://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n","maintainer":"Noah Kantrowitz","maintainer_email":"noah@coderanger.net","license":"Apache-2.0","platforms":{"aix":">= 0.0.0","amazon":">= 0.0.0","arch":">= 0.0.0","centos":">= 0.0.0","chefspec":">= 0.0.0","debian":">= 0.0.0","dragonfly4":">= 0.0.0","fedora":">= 0.0.0","freebsd":">= 0.0.0","gentoo":">= 0.0.0","ios_xr":">= 0.0.0","mac_os_x":">= 0.0.0","nexus":">= 0.0.0","omnios":">= 0.0.0","openbsd":">= 0.0.0","opensuse":">= 0.0.0","oracle":">= 0.0.0","raspbian":">= 0.0.0","redhat":">= 0.0.0","slackware":">= 0.0.0","smartos":">= 0.0.0","solaris2":">= 0.0.0","suse":">= 0.0.0","ubuntu":">= 0.0.0","windows":">= 0.0.0"},"dependencies":{"poise":"~> 2.5","poise-archive":"~> 1.0"},"recommendations":{},"suggestions":{},"conflicting":{},"providing":{},"replacing":{},"attributes":{},"groupings":{},"recipes":{},"source_url":"https://github.com/poise/poise-languages","issues_url":"https://github.com/poise/poise-languages/issues","chef_version":[["< 14",">= 12.1"]],"ohai_version":[]}