diff --git a/cookbooks/chef-sugar/.expeditor/config.yml b/cookbooks/chef-sugar/.expeditor/config.yml new file mode 100644 index 00000000..be4e820d --- /dev/null +++ b/cookbooks/chef-sugar/.expeditor/config.yml @@ -0,0 +1,51 @@ +# Documentation available at https://expeditor.chef.io/docs/getting-started/ +--- + +# Slack channel in Chef Software slack to send notifications about build failures, etc +slack: + notify_channel: chef-infra-notify + +# This publish is triggered by the `built_in:publish_rubygems` artifact_action. +rubygems: + - chef-sugar + - chef-sugar-ng + +github: + # This deletes the GitHub PR branch after successfully merged into the release branch + delete_branch_on_merge: true + # The tag format to use (e.g. v1.0.0) + version_tag_format: "v{{version}}" + # allow bumping the minor release via label + minor_bump_labels: + - "Expeditor: Bump Version Minor" + # allow bumping the major release via label + major_bump_labels: + - "Expeditor: Bump Version Major" + +changelog: + rollup_header: Changes not yet released to rubygems.org + +# These actions are taken, in order they are specified, anytime a Pull Request is merged. +merge_actions: + - built_in:bump_version: + ignore_labels: + - "Expeditor: Skip Version Bump" + - "Expeditor: Skip All" + - bash:.expeditor/update_version.sh: + only_if: built_in:bump_version + - built_in:update_changelog: + ignore_labels: + - "Expeditor: Skip Changelog" + - "Expeditor: Skip All" + - built_in:build_gem: + only_if: built_in:bump_version + +pipelines: + - verify: + description: Pull Request validation tests + public: true + +promote: + actions: + - built_in:rollover_changelog + - built_in:publish_rubygems \ No newline at end of file diff --git a/cookbooks/chef-sugar/.expeditor/run_linux_tests.sh b/cookbooks/chef-sugar/.expeditor/run_linux_tests.sh new file mode 100755 index 00000000..04d0734d --- /dev/null +++ b/cookbooks/chef-sugar/.expeditor/run_linux_tests.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# +# This script runs a passed in command, but first setups up the bundler caching on the repo + +set -ue + +export USER="root" +export LANG=C.UTF-8 LANGUAGE=C.UTF-8 + +echo "--- bundle install" + +bundle config --local path vendor/bundle +bundle install --jobs=7 --retry=3 --without docs debug kitchen + +echo "+++ bundle exec task" +bundle exec $@ diff --git a/cookbooks/chef-sugar/.expeditor/update_version.sh b/cookbooks/chef-sugar/.expeditor/update_version.sh new file mode 100755 index 00000000..f027ea15 --- /dev/null +++ b/cookbooks/chef-sugar/.expeditor/update_version.sh @@ -0,0 +1,12 @@ +#!/bin/bash +# +# After a PR merge, Chef Expeditor will bump the PATCH version in the VERSION file. +# It then executes this file to update any other files/components with that new version. +# + +set -evx + +sed -i -r "s/^(\s*)VERSION = \".+\"/\1VERSION = \"$(cat VERSION)\"/" lib/chef/sugar/version.rb +sed -i -r "s/^version '.*'/version '$(cat VERSION)'/" metadata.rb +# Once Expeditor finshes executing this script, it will commit the changes and push +# the commit as a new tag corresponding to the value in the VERSION file. diff --git a/cookbooks/chef-sugar/.expeditor/verify.pipeline.yml b/cookbooks/chef-sugar/.expeditor/verify.pipeline.yml new file mode 100644 index 00000000..dfa367f9 --- /dev/null +++ b/cookbooks/chef-sugar/.expeditor/verify.pipeline.yml @@ -0,0 +1,62 @@ +--- +expeditor: + cached_folders: + - vendor + defaults: + buildkite: + retry: + automatic: + limit: 1 + timeout_in_minutes: 30 + +steps: + +- label: run-specs-ruby-2.3 + command: + - .expeditor/run_linux_tests.sh "rake" + expeditor: + executor: + docker: + image: ruby:2.3 + +- label: run-specs-ruby-2.4 + command: + - .expeditor/run_linux_tests.sh "rake" + expeditor: + executor: + docker: + image: ruby:2.4-buster + +- label: run-specs-ruby-2.5 + command: + - .expeditor/run_linux_tests.sh "rake" + expeditor: + executor: + docker: + image: ruby:2.5-buster + +- label: run-specs-ruby-2.6 + command: + - .expeditor/run_linux_tests.sh "rake" + expeditor: + executor: + docker: + image: ruby:2.6-buster + +- label: run-specs-ruby-2.7 + command: + - .expeditor/run_linux_tests.sh "rake" + expeditor: + executor: + docker: + image: ruby:2.7-buster + +- label: run-specs-windows + command: + - bundle config --local path vendor/bundle + - bundle install --jobs=7 --retry=3 --without=debug + - bundle exec rake spec + expeditor: + executor: + docker: + host_os: windows diff --git a/cookbooks/chef-sugar/.github/CODEOWNERS b/cookbooks/chef-sugar/.github/CODEOWNERS new file mode 100644 index 00000000..ab984170 --- /dev/null +++ b/cookbooks/chef-sugar/.github/CODEOWNERS @@ -0,0 +1,5 @@ +# Order is important. The last matching pattern has the most precedence. + +* @chef/chef-infra-reviewers @chef/chef-infra-approvers @chef/chef-infra-owners +.expeditor/ @chef/jex-team +*.md @chef/docs-team diff --git a/cookbooks/chef-sugar/.github/ISSUE_TEMPLATE/BUG_TEMPLATE.md b/cookbooks/chef-sugar/.github/ISSUE_TEMPLATE/BUG_TEMPLATE.md new file mode 100644 index 00000000..9b62551d --- /dev/null +++ b/cookbooks/chef-sugar/.github/ISSUE_TEMPLATE/BUG_TEMPLATE.md @@ -0,0 +1,43 @@ +--- +name: 🐛 Bug Report +about: If something isn't working as expected 🤔. +labels: "Status: Untriaged" +--- + + + +## Description + + +## Chef Version + + +## Platform Version + + +## Replication Case + + +## Client Output + + +``` + +``` + +## Stacktrace + diff --git a/cookbooks/chef-sugar/.github/ISSUE_TEMPLATE/DESIGN_PROPOSAL.md b/cookbooks/chef-sugar/.github/ISSUE_TEMPLATE/DESIGN_PROPOSAL.md new file mode 100644 index 00000000..9f4a958f --- /dev/null +++ b/cookbooks/chef-sugar/.github/ISSUE_TEMPLATE/DESIGN_PROPOSAL.md @@ -0,0 +1,40 @@ +--- +name: Design Proposal +about: I have a significant change I would like to propose and discuss before starting +labels: "Status: Untriaged" +--- + +### When a Change Needs a Design Proposal + +A design proposal should be opened any time a change meets one of the following qualifications: + +- Significantly changes the user experience of a project in a way that impacts users. +- Significantly changes the underlying architecture of the project in a way that impacts other developers. +- Changes the development or testing process of the project such as a change of CI systems or test frameworks. + +### Why We Use This Process + +- Allows all interested parties (including any community member) to discuss large impact changes to a project. +- Serves as a durable paper trail for discussions regarding project architecture. +- Forces design discussions to occur before PRs are created. +- Reduces PR refactoring and rejected PRs. + +--- + + + +## Motivation + + + +## Specification + + + +## Downstream Impact + + diff --git a/cookbooks/chef-sugar/.github/ISSUE_TEMPLATE/ENHANCEMENT_REQUEST_TEMPLATE.md b/cookbooks/chef-sugar/.github/ISSUE_TEMPLATE/ENHANCEMENT_REQUEST_TEMPLATE.md new file mode 100644 index 00000000..65bf5a06 --- /dev/null +++ b/cookbooks/chef-sugar/.github/ISSUE_TEMPLATE/ENHANCEMENT_REQUEST_TEMPLATE.md @@ -0,0 +1,17 @@ +--- +name: 🚀 Enhancement Request +about: I have a suggestion (and may want to implement it 🙂)! +labels: "Status: Untriaged" +--- + +### Describe the Enhancement: + + +### Describe the Need: + + +### Current Alternative + + +### Can We Help You Implement This?: + diff --git a/cookbooks/chef-sugar/.github/ISSUE_TEMPLATE/SUPPORT_QUESTION.md b/cookbooks/chef-sugar/.github/ISSUE_TEMPLATE/SUPPORT_QUESTION.md new file mode 100644 index 00000000..68c56647 --- /dev/null +++ b/cookbooks/chef-sugar/.github/ISSUE_TEMPLATE/SUPPORT_QUESTION.md @@ -0,0 +1,12 @@ +--- +name: 🤗 Support Question +about: If you have a question 💬, please check out our Slack! +--- + +We use GitHub issues to track bugs and feature requests. If you need help please post to our Mailing List or join the Chef Community Slack. + + * Chef Community Slack at http://community-slack.chef.io/. + * Chef Mailing List https://discourse.chef.io/ + + + Support issues opened here will be closed and redirected to Slack or Discourse. diff --git a/cookbooks/chef-sugar/.github/lock.yml b/cookbooks/chef-sugar/.github/lock.yml new file mode 100644 index 00000000..71865afb --- /dev/null +++ b/cookbooks/chef-sugar/.github/lock.yml @@ -0,0 +1,3 @@ +daysUntilLock: 90 +lockLabel: false +lockComment: false diff --git a/cookbooks/chef-sugar/.kitchen.yml b/cookbooks/chef-sugar/.kitchen.yml index 619e2cd2..b2492e78 100644 --- a/cookbooks/chef-sugar/.kitchen.yml +++ b/cookbooks/chef-sugar/.kitchen.yml @@ -8,8 +8,8 @@ provisioner: platforms: - name: centos-6 - name: centos-7 - - name: ubuntu-14.04 - name: ubuntu-16.04 + - name: ubuntu-18.04 suites: - name: default diff --git a/cookbooks/chef-sugar/.travis.yml b/cookbooks/chef-sugar/.travis.yml deleted file mode 100644 index 1bd6ac93..00000000 --- a/cookbooks/chef-sugar/.travis.yml +++ /dev/null @@ -1,17 +0,0 @@ -sudo: false - -rvm: - - 2.2.9 - - 2.3.6 - - 2.4.3 - - 2.5.0 - -branches: - only: - - master - -cache: bundler - -bundler_args: --jobs 7 - -script: bundle exec rake diff --git a/cookbooks/chef-sugar/CHANGELOG.md b/cookbooks/chef-sugar/CHANGELOG.md index 5a12cd98..d698a4f1 100644 --- a/cookbooks/chef-sugar/CHANGELOG.md +++ b/cookbooks/chef-sugar/CHANGELOG.md @@ -2,6 +2,44 @@ This file is used to list changes made in each version of the chef-sugar cookbook and gem. + + + + + + + +## [v5.1.12](https://github.com/chef/chef-sugar/tree/v5.1.12) (2020-11-11) + +#### Merged Pull Requests +- Don't define which helper on Chef 16+ to avoid conflicts [#21](https://github.com/chef/chef-sugar/pull/21) ([tas50](https://github.com/tas50)) + + +## [v5.1.11](https://github.com/chef/chef-sugar/tree/v5.1.11) (2020-08-14) + +#### Merged Pull Requests +- Fix Ruby 2.3 tests [#19](https://github.com/chef/chef-sugar/pull/19) ([tas50](https://github.com/tas50)) +- Only require libs if we haven't already loaded them [#20](https://github.com/chef/chef-sugar/pull/20) ([tas50](https://github.com/tas50)) + +## [v5.1.9](https://github.com/chef/chef-sugar/tree/v5.1.9) (2019-11-13) + +#### Merged Pull Requests +- Don't fail if Chef::VERSION isn't defined [#18](https://github.com/chef/chef-sugar/pull/18) ([lamont-granquist](https://github.com/lamont-granquist)) + +## [v5.1.8](https://github.com/chef/chef-sugar/tree/v5.1.8) (2019-11-13) + +#### Merged Pull Requests +- Wire up Expeditor and support both chef-sugar and chef-sugar-ng [#8](https://github.com/chef/chef-sugar/pull/8) ([tas50](https://github.com/tas50)) +- Add github templates and a code of conduct [#9](https://github.com/chef/chef-sugar/pull/9) ([tas50](https://github.com/tas50)) +- Beginning of chef-sugar deprecation [#10](https://github.com/chef/chef-sugar/pull/10) ([lamont-granquist](https://github.com/lamont-granquist)) +- Use Expeditor to set the version in the metadata.rb file [#11](https://github.com/chef/chef-sugar/pull/11) ([tas50](https://github.com/tas50)) +- Switch gemfile back to chef-sugar [#12](https://github.com/chef/chef-sugar/pull/12) ([tas50](https://github.com/tas50)) +- Fix metadata.rb version updatig logic and use SPDX compliant license strings [#14](https://github.com/chef/chef-sugar/pull/14) ([tas50](https://github.com/tas50)) +- Additional Chef-15 greenification [#13](https://github.com/chef/chef-sugar/pull/13) ([lamont-granquist](https://github.com/lamont-granquist)) +- Move test deps to the Gemfile [#15](https://github.com/chef/chef-sugar/pull/15) ([tas50](https://github.com/tas50)) +- Get the tests green [#17](https://github.com/chef/chef-sugar/pull/17) ([tas50](https://github.com/tas50)) +- Deprecate chef-sugar node API [#16](https://github.com/chef/chef-sugar/pull/16) ([lamont-granquist](https://github.com/lamont-granquist)) + ## v5.0.1 (2019-03-13) - Modifies the behavior of `systemd?` so that it works equally well on physical/virtual @@ -268,4 +306,4 @@ machines as well as within containers. ## v1.0.0 (2013-10-15) -- First public release +- First public release \ No newline at end of file diff --git a/cookbooks/chef-sugar/CODE_OF_CONDUCT.md b/cookbooks/chef-sugar/CODE_OF_CONDUCT.md new file mode 100644 index 00000000..980c1341 --- /dev/null +++ b/cookbooks/chef-sugar/CODE_OF_CONDUCT.md @@ -0,0 +1 @@ +Please refer to the Chef Community Code of Conduct at https://www.chef.io/code-of-conduct/ diff --git a/cookbooks/chef-sugar/DEPRECATION_TODO.md b/cookbooks/chef-sugar/DEPRECATION_TODO.md new file mode 100644 index 00000000..22a9f17b --- /dev/null +++ b/cookbooks/chef-sugar/DEPRECATION_TODO.md @@ -0,0 +1,84 @@ +### Chef Sugar is being deprecated, this is the internal list of the TODO tasks + +TASKS in order: + +* ~~pull cloud.rb into core-chef~~ +* pull data_bag.rb into core-chef +* ~~pull run_context.rb into core-chef~~ +* ~~pull vagrant.rb into core-chef~~ +* ~~pull virtualization.rb into core-chef~~ +* deprecate ip.rb with no replacement (although maybe a new ohai attribute?) +* deprecate kernel.rb with no replacement +* ~~deprecate node.rb with no replacement~~ +* deprecate ruby.rb with no replacement +* determine what to do about filters.rb +* determine what to do about remaining platform.rb +* determine what to do about shell.rb +* determine what to do about core_extensions + +NOTES on files: + +architecture.rb is COMPLETED + +cloud.rb is COMPLETED + +constraint.rb / constraint_dsl.rb tasks: + +* replace with Chef::VersionString objects + +core_extensions + +* pile of monkeypatches that makes my eyes twitch a little bit. how much do we want to become activerecord? counter-argument is + that some activerecord-ish helpers are SUUUPER useful. but we should probably copy them from activerecord since those are more + likely to get pulled directly into core-chef. + +data_bag + +* we should pull this into core-chef or something comparable (TBD) + +docker.rb is COMPLETED + +filters.rb tasks + +* incorporate the before/after syntax into the find_resource/edit_resource API (probably renamed, with deprecation done here) +* deprecate the at_compile_time helper in favor of moving the `compile_time true` property into Chef::Resource directly + +init.rb is COMPLETED + +* unless we get user complaints, runit is dead to us and this is done + +ip.rb + +* needs to be deprecated with no replacement (could push this into another ohai attribute -- or have we done it already?) + +kernel.rb (the require_chef_gem trivial helper) + +* needs to be deprecated with no replacement. + +kitchen.rb is COMPLETED + +node.rb (the method_missing syntax) + +* needs to be deprecated with no replacement. + +platform.rb tasks: + +* decide what to do about the `debian_before_squeeze` platform version helpers. +* decide what to do about the `platform_version` helper (can we wire this up to a Chef::VersionString object instead?) + +platform_family.rb is COMPLETED + +ruby.rb tasks: + +* needs to be deprecated with no replacement (nobody has used it since ruby 2.0, so its clearly not being used) + +run_context.rb is COMPLETED + +shell.rb: (collection of helpers including `which`) + +* TBD + +vagrant.rb is COMPLETED + +virtualization.rb is COMPLETED + diff --git a/cookbooks/chef-sugar/Gemfile b/cookbooks/chef-sugar/Gemfile index 851fabc2..205f8086 100644 --- a/cookbooks/chef-sugar/Gemfile +++ b/cookbooks/chef-sugar/Gemfile @@ -1,2 +1,34 @@ -source 'https://rubygems.org' -gemspec +source "https://rubygems.org" +gemspec name: "chef-sugar" + +group :debug do + gem "pry" + gem "pry-byebug" unless Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.4") + gem "pry-stack_explorer", "~> 0.4.0" # pin until we drop ruby < 2.6 +end + +group :test do + if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.5") + gem "chefspec", "~> 7.4.0" # supports Chef 13+ aka ruby 2.3+ + gem "chef", "~> 13" # also needed to support Ruby 2.3 + elsif Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.6") + gem "chefspec" + gem "chef-zero", "~> 14" + gem "chef", "~> 15" # also needed to support Ruby 2.3 + else + gem "chefspec" + end + if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.4") + gem "rubyzip", "< 2" + else + gem "rubyzip" + end + gem "rake" + gem "rspec" +end + +group :kitchen do + gem "kitchen-vagrant" + gem "license-acceptance", "~> 1.0" if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.4") + gem "test-kitchen" +end diff --git a/cookbooks/chef-sugar/README.md b/cookbooks/chef-sugar/README.md index 6b9948b8..7c4138e6 100644 --- a/cookbooks/chef-sugar/README.md +++ b/cookbooks/chef-sugar/README.md @@ -1,8 +1,11 @@ # Chef Sugar -[![Gem Version](http://img.shields.io/gem/v/chef-sugar.svg?style=flat-square)][gem] [![Build Status](http://img.shields.io/travis/sethvargo/chef-sugar.svg?style=flat-square)][travis] +[![Gem Version](http://img.shields.io/gem/v/chef-sugar.svg?style=flat-square)][gem] +[![Build status](https://badge.buildkite.com/f44140e4898b4935bfc3bba523efc2a7592d7c9a1bae3faf5c.svg?branch=master)](https://buildkite.com/chef-oss/chef-chef-sugar-master-verify) -Chef Sugar is a Gem & Chef Recipe that includes series of helpful syntactic sugars on top of the Chef core and other resources to make a cleaner, more lean recipe DSL, enforce DRY principles, and make writing Chef recipes an awesome and fun experience! +# CHEF SUGAR DEPRECATION WARNING + +Chef Sugar functionality has been migrated into Chef Infra Client 16. There is no longer a need for this cookbook and gem for most use cases and we will not be maintaining the project further at this point. No issues or patches are being accepted at this time. ## Requirements @@ -10,7 +13,6 @@ Chef Sugar is a Gem & Chef Recipe that includes series of helpful syntactic suga - any platform - ### Chef - Chef 13.0+ @@ -537,4 +539,3 @@ limitations under the License. ``` [gem]: https://rubygems.org/gems/chef-sugar -[travis]: http://travis-ci.org/sethvargo/chef-sugar diff --git a/cookbooks/chef-sugar/Rakefile b/cookbooks/chef-sugar/Rakefile index 0b7739b3..6d80342a 100644 --- a/cookbooks/chef-sugar/Rakefile +++ b/cookbooks/chef-sugar/Rakefile @@ -1,5 +1,3 @@ -require 'bundler/gem_tasks' - require 'rspec/core/rake_task' RSpec::Core::RakeTask.new do |t| t.rspec_opts = [ diff --git a/cookbooks/chef-sugar/VERSION b/cookbooks/chef-sugar/VERSION new file mode 100644 index 00000000..b3fc6969 --- /dev/null +++ b/cookbooks/chef-sugar/VERSION @@ -0,0 +1 @@ +5.1.12 \ No newline at end of file diff --git a/cookbooks/chef-sugar/chef-sugar-ng.gemspec b/cookbooks/chef-sugar/chef-sugar-ng.gemspec index 20fa5c64..81f44801 100644 --- a/cookbooks/chef-sugar/chef-sugar-ng.gemspec +++ b/cookbooks/chef-sugar/chef-sugar-ng.gemspec @@ -15,18 +15,10 @@ Gem::Specification.new do |spec| spec.summary = 'A collection of helper methods and modules that ' \ 'make working with Chef recipes awesome.' spec.homepage = 'https://github.com/chef/chef-sugar' - spec.license = 'Apache 2.0' + spec.license = 'Apache-2.0' - - spec.required_ruby_version = '>= 2.2.2' + spec.required_ruby_version = '>= 2.3' spec.files = %w{LICENSE} + Dir.glob("lib/**/*", File::FNM_DOTMATCH).reject { |f| File.directory?(f) } spec.require_paths = ['lib'] - - spec.add_development_dependency 'bundler' - spec.add_development_dependency 'rake' - - spec.add_development_dependency 'chefspec' - spec.add_development_dependency 'test-kitchen' - spec.add_development_dependency 'kitchen-vagrant' end diff --git a/cookbooks/chef-sugar/chef-sugar.gemspec b/cookbooks/chef-sugar/chef-sugar.gemspec new file mode 100644 index 00000000..cff92ca2 --- /dev/null +++ b/cookbooks/chef-sugar/chef-sugar.gemspec @@ -0,0 +1,24 @@ +# coding: utf-8 +lib = File.expand_path('../lib', __FILE__) +$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) +require 'chef/sugar/version' + +Gem::Specification.new do |spec| + spec.name = 'chef-sugar' + spec.version = Chef::Sugar::VERSION + spec.authors = ['Seth Vargo'] + spec.email = ['sethvargo@gmail.com'] + spec.description = 'A series of helpful sugar of the Chef core and ' \ + 'other resources to make a cleaner, more lean recipe ' \ + 'DSL, enforce DRY principles, and make writing Chef ' \ + 'recipes an awesome experience!' + spec.summary = 'A collection of helper methods and modules that ' \ + 'make working with Chef recipes awesome.' + spec.homepage = 'https://github.com/chef/chef-sugar' + spec.license = 'Apache-2.0' + + spec.required_ruby_version = '>= 2.3' + + spec.files = %w{LICENSE} + Dir.glob("lib/**/*", File::FNM_DOTMATCH).reject { |f| File.directory?(f) } + spec.require_paths = ['lib'] +end diff --git a/cookbooks/chef-sugar/lib/chef/sugar/architecture.rb b/cookbooks/chef-sugar/lib/chef/sugar/architecture.rb index 621415e2..5ea28fc7 100644 --- a/cookbooks/chef-sugar/lib/chef/sugar/architecture.rb +++ b/cookbooks/chef-sugar/lib/chef/sugar/architecture.rb @@ -19,153 +19,158 @@ module Sugar module Architecture extend self - # - # Determine if the current architecture is 64-bit - # - # @return [Boolean] - # - def _64_bit?(node) - %w(amd64 x86_64 ppc64 ppc64le s390x ia64 sparc64 aarch64 arch64 arm64 sun4v sun4u s390x) - .include?(node['kernel']['machine']) || ( node['kernel']['bits'] == '64' ) - end - - # - # Determine if the current architecture is 32-bit - # - # @todo Make this more than "not 64-bit" - # - # @return [Boolean] - # - def _32_bit?(node) - !_64_bit?(node) - end - - # - # Determine if the current architecture is i386 - # - # @return [Boolean] - # - def i386?(node) - _32_bit?(node) && intel?(node) - end - - # - # Determine if the current architecture is Intel. - # - # @return [Boolean] - # - def intel?(node) - %w(i86pc i386 x86_64 amd64 i686) - .include?(node['kernel']['machine']) - end - - # - # Determine if the current architecture is SPARC. - # - # @return [Boolean] - # - def sparc?(node) - %w(sun4u sun4v) - .include?(node['kernel']['machine']) - end - - # - # Determine if the current architecture is Powerpc64 Big Endian - # - # @return [Boolean] - # - def ppc64?(node) - %w(ppc64) - .include?(node['kernel']['machine']) - end - - # - # Determine if the current architecture is Powerpc64 Little Endian - # - # @return [Boolean] - # - def ppc64le?(node) - %w(ppc64le) - .include?(node['kernel']['machine']) - end - - # - # Determine if the current architecture is PowerPC - # - # @return [Boolean] - # - def powerpc?(node) - %w(powerpc) - .include?(node['kernel']['machine']) - end - - # - # Determine if the current architecture is ARM with Hard Float - # - # @return [Boolean] - # - def armhf?(node) - # Add more arm variants as needed here - %w(armv6l armv7l) - .include?(node['kernel']['machine']) - end - - # - # Determine if the current architecture is AArch64 - # - # @return [Boolean] - # - def aarch64?(node) - # Add more arm variants as needed here - %w(aarch64) - .include?(node['kernel']['machine']) - end - - # - # Determine if the current architecture is s390x - # - # @return [Boolean] - # - def s390x?(node) - %w(s390x) - .include?(node['kernel']['machine']) + # these helpers have been moved to core-chef + if !defined?(Chef::VERSION) || Gem::Requirement.new("< 15.4.70").satisfied_by?(Gem::Version.new(Chef::VERSION)) + # + # Determine if the current architecture is 64-bit + # + # @return [Boolean] + # + def _64_bit?(node) + %w(amd64 x86_64 ppc64 ppc64le s390x ia64 sparc64 aarch64 arch64 arm64 sun4v sun4u s390x) + .include?(node['kernel']['machine']) || ( node['kernel']['bits'] == '64' ) + end + + # + # Determine if the current architecture is 32-bit + # + # @todo Make this more than "not 64-bit" + # + # @return [Boolean] + # + def _32_bit?(node) + !_64_bit?(node) + end + + # + # Determine if the current architecture is i386 + # + # @return [Boolean] + # + def i386?(node) + _32_bit?(node) && intel?(node) + end + + # + # Determine if the current architecture is Intel. + # + # @return [Boolean] + # + def intel?(node) + %w(i86pc i386 x86_64 amd64 i686) + .include?(node['kernel']['machine']) + end + + # + # Determine if the current architecture is SPARC. + # + # @return [Boolean] + # + def sparc?(node) + %w(sun4u sun4v) + .include?(node['kernel']['machine']) + end + + # + # Determine if the current architecture is Powerpc64 Big Endian + # + # @return [Boolean] + # + def ppc64?(node) + %w(ppc64) + .include?(node['kernel']['machine']) + end + + # + # Determine if the current architecture is Powerpc64 Little Endian + # + # @return [Boolean] + # + def ppc64le?(node) + %w(ppc64le) + .include?(node['kernel']['machine']) + end + + # + # Determine if the current architecture is PowerPC + # + # @return [Boolean] + # + def powerpc?(node) + %w(powerpc) + .include?(node['kernel']['machine']) + end + + # + # Determine if the current architecture is ARM with Hard Float + # + # @return [Boolean] + # + def armhf?(node) + # Add more arm variants as needed here + %w(armv6l armv7l) + .include?(node['kernel']['machine']) + end + + # + # Determine if the current architecture is AArch64 + # + # @return [Boolean] + # + def aarch64?(node) + # Add more arm variants as needed here + %w(aarch64) + .include?(node['kernel']['machine']) + end + + # + # Determine if the current architecture is s390x + # + # @return [Boolean] + # + def s390x?(node) + %w(s390x) + .include?(node['kernel']['machine']) + end end end module DSL - # @see Chef::Sugar::Architecture#_64_bit? - def _64_bit?; Chef::Sugar::Architecture._64_bit?(node); end + if !defined?(Chef::VERSION) || Gem::Requirement.new("< 15.4.70").satisfied_by?(Gem::Version.new(Chef::VERSION)) + # @see Chef::Sugar::Architecture#_64_bit? + def _64_bit?; Chef::Sugar::Architecture._64_bit?(node); end - # @see Chef::Sugar::Architecture#_32_bit? - def _32_bit?; Chef::Sugar::Architecture._32_bit?(node); end + # @see Chef::Sugar::Architecture#_32_bit? + def _32_bit?; Chef::Sugar::Architecture._32_bit?(node); end - # @see Chef::Sugar::Architecture#intel? - def i386?; Chef::Sugar::Architecture.i386?(node); end + # @see Chef::Sugar::Architecture#intel? + def i386?; Chef::Sugar::Architecture.i386?(node); end - # @see Chef::Sugar::Architecture#intel? - def intel?; Chef::Sugar::Architecture.intel?(node); end + # @see Chef::Sugar::Architecture#intel? + def intel?; Chef::Sugar::Architecture.intel?(node); end - # @see Chef::Sugar::Architecture#sparc? - def sparc?; Chef::Sugar::Architecture.sparc?(node); end + # @see Chef::Sugar::Architecture#sparc? + def sparc?; Chef::Sugar::Architecture.sparc?(node); end - # @see Chef::Sugar::Architecture#ppc64? - def ppc64?; Chef::Sugar::Architecture.ppc64?(node); end + # @see Chef::Sugar::Architecture#ppc64? + def ppc64?; Chef::Sugar::Architecture.ppc64?(node); end - # @see Chef::Sugar::Architecture#ppc64le? - def ppc64le?; Chef::Sugar::Architecture.ppc64le?(node); end + # @see Chef::Sugar::Architecture#ppc64le? + def ppc64le?; Chef::Sugar::Architecture.ppc64le?(node); end - # @see Chef::Sugar::Architecture#powerpc? - def powerpc?; Chef::Sugar::Architecture.powerpc?(node); end + # @see Chef::Sugar::Architecture#powerpc? + def powerpc?; Chef::Sugar::Architecture.powerpc?(node); end - # @see Chef::Sugar::Architecture#arm? - def armhf?; Chef::Sugar::Architecture.armhf?(node); end + # @see Chef::Sugar::Architecture#arm? + def armhf?; Chef::Sugar::Architecture.armhf?(node); end - # @see Chef::Sugar::Architecture#aarch64? - def aarch64?; Chef::Sugar::Architecture.aarch64?(node); end + # @see Chef::Sugar::Architecture#aarch64? + def aarch64?; Chef::Sugar::Architecture.aarch64?(node); end - # @see Chef::Sugar::Architecture#s390x? - def s390x?; Chef::Sugar::Architecture.s390x?(node); end + # @see Chef::Sugar::Architecture#s390x? + def s390x?; Chef::Sugar::Architecture.s390x?(node); end + end end end end diff --git a/cookbooks/chef-sugar/lib/chef/sugar/deprecation.rb b/cookbooks/chef-sugar/lib/chef/sugar/deprecation.rb new file mode 100644 index 00000000..caaccc8d --- /dev/null +++ b/cookbooks/chef-sugar/lib/chef/sugar/deprecation.rb @@ -0,0 +1,45 @@ +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +if defined?(Chef::Deprecated::Base) + class Chef + class Deprecated + class ChefSugar < Base + def id + 28 + end + def target + "chef_sugar.html" + end + end + end + end +end + +class Chef + module Sugar + module Deprecation + if defined?(Chef::Deprecated::Base) + def deprecated(message) + Chef.deprecated(:chef_sugar, message) + end + else + def deprecated(message) + Chef::Log.warn(message) + end + end + extend self + end + end +end diff --git a/cookbooks/chef-sugar/lib/chef/sugar/docker.rb b/cookbooks/chef-sugar/lib/chef/sugar/docker.rb index e48d3f84..1205912c 100644 --- a/cookbooks/chef-sugar/lib/chef/sugar/docker.rb +++ b/cookbooks/chef-sugar/lib/chef/sugar/docker.rb @@ -19,22 +19,27 @@ module Sugar module Docker extend self - # - # Returns true if the current node is a docker container. - # - # @param [Chef::Node] node - # the node to check - # - # @return [Boolean] - # - def docker?(node) - File.exist?('/.dockerinit') || File.exist?('/.dockerenv') + # these helpers have been moved to core chef + if !defined?(Chef::VERSION) || Gem::Requirement.new("< 15.4.70").satisfied_by?(Gem::Version.new(Chef::VERSION)) + # + # Returns true if the current node is a docker container. + # + # @param [Chef::Node] node + # the node to check + # + # @return [Boolean] + # + def docker?(node) + File.exist?('/.dockerinit') || File.exist?('/.dockerenv') + end end end module DSL - # @see Chef::Sugar::Docker#docker? - def docker?; Chef::Sugar::Docker.docker?(node); end + if !defined?(Chef::VERSION) || Gem::Requirement.new("< 15.4.70").satisfied_by?(Gem::Version.new(Chef::VERSION)) + # @see Chef::Sugar::Docker#docker? + def docker?; Chef::Sugar::Docker.docker?(node); end + end end end end diff --git a/cookbooks/chef-sugar/lib/chef/sugar/kitchen.rb b/cookbooks/chef-sugar/lib/chef/sugar/kitchen.rb index 2d34e336..55f5d6ae 100644 --- a/cookbooks/chef-sugar/lib/chef/sugar/kitchen.rb +++ b/cookbooks/chef-sugar/lib/chef/sugar/kitchen.rb @@ -19,22 +19,27 @@ module Sugar module Kitchen extend self - # - # Returns true if the current node is provisioned by Test Kitchen. - # - # @param [Chef::Node] node - # the node to check - # - # @return [Boolean] - # - def kitchen?(node) - !ENV['TEST_KITCHEN'].nil? + # these helpers have been moved to core-chef + if !defined?(Chef::VERSION) || Gem::Requirement.new("< 15.4.70").satisfied_by?(Gem::Version.new(Chef::VERSION)) + # + # Returns true if the current node is provisioned by Test Kitchen. + # + # @param [Chef::Node] node + # the node to check + # + # @return [Boolean] + # + def kitchen?(node) + !ENV['TEST_KITCHEN'].nil? + end end end module DSL - # @see Chef::Sugar::Kitchen#kitchen? - def kitchen?; Chef::Sugar::Kitchen.kitchen?(node); end + if !defined?(Chef::VERSION) || Gem::Requirement.new("< 15.4.70").satisfied_by?(Gem::Version.new(Chef::VERSION)) + # @see Chef::Sugar::Kitchen#kitchen? + def kitchen?; Chef::Sugar::Kitchen.kitchen?(node); end + end end end end diff --git a/cookbooks/chef-sugar/lib/chef/sugar/node.rb b/cookbooks/chef-sugar/lib/chef/sugar/node.rb index aec8627c..70730c05 100644 --- a/cookbooks/chef-sugar/lib/chef/sugar/node.rb +++ b/cookbooks/chef-sugar/lib/chef/sugar/node.rb @@ -14,6 +14,8 @@ # limitations under the License. # +require_relative "deprecation" + class Chef class Node class AttributeDoesNotExistError < StandardError @@ -36,6 +38,7 @@ def initialize(keys, key) # @return [Boolean] # def in?(environment) + Chef::Sugar::Deprecation.deprecated "the chef-sugar node.in? method is deprecated" environment === chef_environment end @@ -49,6 +52,7 @@ def in?(environment) # @see [Node#deep_fetch!] # def deep_fetch(*keys) + Chef::Sugar::Deprecation.deprecated "the chef-sugar deep_fetch method is deprecated and should be replaced by node.read" deep_fetch!(*keys) rescue NoMethodError, AttributeDoesNotExistError nil @@ -71,6 +75,7 @@ def deep_fetch(*keys) # @return [Object] # def deep_fetch!(*keys) + Chef::Sugar::Deprecation.deprecated "the chef-sugar deep_fetch method is deprecated and should be replaced by node.read!" keys.map!(&:to_s) keys.inject(attributes.to_hash) do |hash, key| @@ -133,6 +138,7 @@ def deep_fetch!(*keys) # to prevent accidential method chaining if the block isn't closed # def namespace(*args, &block) + Chef::Sugar::Deprecation.deprecated "the chef-sugar attribute namespace setting is deprecated, please use traditional chef attribute notation" @namespace_options = namespace_options.merge(args.last.is_a?(Hash) ? args.pop : {}) keys = args.map(&:to_s) diff --git a/cookbooks/chef-sugar/lib/chef/sugar/platform.rb b/cookbooks/chef-sugar/lib/chef/sugar/platform.rb index c1592ecd..12cfdd53 100644 --- a/cookbooks/chef-sugar/lib/chef/sugar/platform.rb +++ b/cookbooks/chef-sugar/lib/chef/sugar/platform.rb @@ -121,186 +121,190 @@ module Platform end end - # - # Determine if the current node is linux mint. - # - # @param [Chef::Node] node - # - # @return [Boolean] - # - def linux_mint?(node) - node['platform'] == 'linuxmint' - end - alias_method :mint?, :linux_mint? + # these helpers have been moved to core chef + if !defined?(Chef::VERSION) || Gem::Requirement.new("< 15.4.70").satisfied_by?(Gem::Version.new(Chef::VERSION)) + # + # Determine if the current node is linux mint. + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def linux_mint?(node) + node['platform'] == 'linuxmint' + end + alias_method :mint?, :linux_mint? - # - # Determine if the current node is ubuntu. - # - # @param [Chef::Node] node - # - # @return [Boolean] - # - def ubuntu?(node) - node['platform'] == 'ubuntu' - end + # + # Determine if the current node is ubuntu. + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def ubuntu?(node) + node['platform'] == 'ubuntu' + end - # - # Determine if the current node is debian (platform, not platform_family). - # - # @param [Chef::Node] node - # - # @return [Boolean] - # - def debian_platform?(node) - node['platform'] == 'debian' - end + # + # Determine if the current node is debian (platform, not platform_family). + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def debian_platform?(node) + node['platform'] == 'debian' + end - # - # Determine if the current node is amazon linux. - # - # @param [Chef::Node] node - # - # @return [Boolean] - # - def amazon_linux?(node) - node['platform'] == 'amazon' - end - alias_method :amazon?, :amazon_linux? + # + # Determine if the current node is amazon linux. + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def amazon_linux?(node) + node['platform'] == 'amazon' + end + alias_method :amazon?, :amazon_linux? - # - # Determine if the current node is centos. - # - # @param [Chef::Node] node - # - # @return [Boolean] - # - def centos?(node) - node['platform'] == 'centos' - end + # + # Determine if the current node is centos. + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def centos?(node) + node['platform'] == 'centos' + end - # - # Determine if the current node is oracle linux. - # - # @param [Chef::Node] node - # - # @return [Boolean] - # - def oracle_linux?(node) - node['platform'] == 'oracle' - end - alias_method :oracle?, :oracle_linux? + # + # Determine if the current node is oracle linux. + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def oracle_linux?(node) + node['platform'] == 'oracle' + end + alias_method :oracle?, :oracle_linux? - # - # Determine if the current node is scientific linux. - # - # @param [Chef::Node] node - # - # @return [Boolean] - # - def scientific_linux?(node) - node['platform'] == 'scientific' - end - alias_method :scientific?, :scientific_linux? + # + # Determine if the current node is scientific linux. + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def scientific_linux?(node) + node['platform'] == 'scientific' + end + alias_method :scientific?, :scientific_linux? - # - # Determine if the current node is redhat enterprise. - # - # @param [Chef::Node] node - # - # @return [Boolean] - # - def redhat_enterprise_linux?(node) - node['platform'] == 'redhat' - end - alias_method :redhat_enterprise?, :redhat_enterprise_linux? + # + # Determine if the current node is redhat enterprise. + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def redhat_enterprise_linux?(node) + node['platform'] == 'redhat' + end + alias_method :redhat_enterprise?, :redhat_enterprise_linux? - # - # Determine if the current node is fedora (platform, not platform_family). - # - # @param [Chef::Node] node - # - # @return [Boolean] - # - def fedora_platform?(node) - node['platform'] == 'fedora' - end + # + # Determine if the current node is fedora (platform, not platform_family). + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def fedora_platform?(node) + node['platform'] == 'fedora' + end - # - # Determine if the current node is solaris2 - # - # @param [Chef::Node] node - # - # @return [Boolean] - # - def solaris2?(node) - node['platform'] == 'solaris2' - end - alias_method :solaris?, :solaris2? + # + # Determine if the current node is solaris2 + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def solaris2?(node) + node['platform'] == 'solaris2' + end + alias_method :solaris?, :solaris2? - # - # Determine if the current node is aix - # - # @param [Chef::Node] node - # - # @return [Boolean] - # - def aix?(node) - node['platform'] == 'aix' - end + # + # Determine if the current node is aix + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def aix?(node) + node['platform'] == 'aix' + end - # - # Determine if the current node is smartos - # - # @param [Chef::Node] node - # - # @return [Boolean] - # - def smartos?(node) - node['platform'] == 'smartos' - end + # + # Determine if the current node is smartos + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def smartos?(node) + node['platform'] == 'smartos' + end - # - # Determine if the current node is omnios - # - # @param [Chef::Node] node - # - # @return [Boolean] - # - def omnios?(node) - node['platform'] == 'omnios' - end + # + # Determine if the current node is omnios + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def omnios?(node) + node['platform'] == 'omnios' + end - # - # Determine if the current node is raspbian - # - # @param [Chef::Node] node - # - # @return [Boolean] - # - def raspbian?(node) - node['platform'] == 'raspbian' - end + # + # Determine if the current node is raspbian + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def raspbian?(node) + node['platform'] == 'raspbian' + end - # - # Determine if the current node is a Cisco nexus device - # - # @param [Chef::Node] node - # - # @return [Boolean] - # - def nexus?(node) - node['platform'] == 'nexus' - end + # + # Determine if the current node is a Cisco nexus device + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def nexus?(node) + node['platform'] == 'nexus' + end + + # + # Determine if the current node is a Cisco IOS-XR device + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def ios_xr?(node) + node['platform'] == 'ios_xr' + end - # - # Determine if the current node is a Cisco IOS-XR device - # - # @param [Chef::Node] node - # - # @return [Boolean] - # - def ios_xr?(node) - node['platform'] == 'ios_xr' end # diff --git a/cookbooks/chef-sugar/lib/chef/sugar/platform_family.rb b/cookbooks/chef-sugar/lib/chef/sugar/platform_family.rb index 64b4761f..af41f64f 100644 --- a/cookbooks/chef-sugar/lib/chef/sugar/platform_family.rb +++ b/cookbooks/chef-sugar/lib/chef/sugar/platform_family.rb @@ -19,152 +19,157 @@ module Sugar module PlatformFamily extend self - # - # Determine if the current node is a member of the arch family. - # - # @param [Chef::Node] node - # - # @return [Boolean] - # - def arch_linux?(node) - node['platform_family'] == 'arch' - end - alias_method :arch?, :arch_linux? - - # - # Determine if the current node is a member of the debian family. - # - # @param [Chef::Node] node - # - # @return [Boolean] - # - def debian?(node) - node['platform_family'] == 'debian' - end + # these helpers have been moved to core chef + if !defined?(Chef::VERSION) || Gem::Requirement.new("< 15.4.70").satisfied_by?(Gem::Version.new(Chef::VERSION)) - # - # Determine if the current node is a member of the fedora family. - # - # @param [Chef::Node] node - # - # @return [Boolean] - # - def fedora?(node) - node['platform_family'] == 'fedora' - end + # + # Determine if the current node is a member of the arch family. + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def arch_linux?(node) + node['platform_family'] == 'arch' + end + alias_method :arch?, :arch_linux? - # - # Determine if the current node is a member of the freebsd family. - # - # @param [Chef::Node] node - # - # @return [Boolean] - # - def freebsd?(node) - node['platform_family'] == 'freebsd' - end + # + # Determine if the current node is a member of the debian family. + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def debian?(node) + node['platform_family'] == 'debian' + end - # - # Determine if the current node is a member of the arch family. - # - # @param [Chef::Node] node - # - # @return [Boolean] - # - def gentoo?(node) - node['platform_family'] == 'gentoo' - end + # + # Determine if the current node is a member of the fedora family. + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def fedora?(node) + node['platform_family'] == 'fedora' + end - # - # Determine if the current node is a member of the OSX family. - # - # @param [Chef::Node] node - # - # @return [Boolean] - # - def mac_os_x?(node) - node['platform_family'] == 'mac_os_x' - end - alias_method :osx?, :mac_os_x? - alias_method :mac?, :mac_os_x? - - # - # Determine if the current node is a member of the openbsd family. - # - # @param [Chef::Node] node - # - # @return [Boolean] - # - def openbsd?(node) - node['platform_family'] == 'openbsd' - end + # + # Determine if the current node is a member of the freebsd family. + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def freebsd?(node) + node['platform_family'] == 'freebsd' + end - # - # Determine if the current node is a member of the redhat family. - # - # @param [Chef::Node] node - # - # @return [Boolean] - # - def rhel?(node) - node['platform_family'] == 'rhel' - end - alias_method :redhat?, :rhel? - alias_method :el?, :rhel? - - # - # Determine if the current node is a member of the slackware family. - # - # @param [Chef::Node] node - # - # @return [Boolean] - # - def slackware?(node) - node['platform_family'] == 'slackware' - end + # + # Determine if the current node is a member of the arch family. + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def gentoo?(node) + node['platform_family'] == 'gentoo' + end - # - # Determine if the current node is a member of the suse family. - # - # @param [Chef::Node] node - # - # @return [Boolean] - # - def suse?(node) - node['platform_family'] == 'suse' - end + # + # Determine if the current node is a member of the OSX family. + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def mac_os_x?(node) + node['platform_family'] == 'mac_os_x' + end + alias_method :osx?, :mac_os_x? + alias_method :mac?, :mac_os_x? - # - # Determine if the current node is a member of the windows family. - # - # @param [Chef::Node] node - # - # @return [Boolean] - # - def windows?(node) - node['platform_family'] == 'windows' - end + # + # Determine if the current node is a member of the openbsd family. + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def openbsd?(node) + node['platform_family'] == 'openbsd' + end - # - # Determine if the current node is a member of the wrlinux family. - # - # @param [Chef::Node] node - # - # @return [Boolean] - # - def wrlinux?(node) - node['platform_family'] == 'wrlinux' - end + # + # Determine if the current node is a member of the redhat family. + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def rhel?(node) + node['platform_family'] == 'rhel' + end + alias_method :redhat?, :rhel? + alias_method :el?, :rhel? + + # + # Determine if the current node is a member of the slackware family. + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def slackware?(node) + node['platform_family'] == 'slackware' + end + + # + # Determine if the current node is a member of the suse family. + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def suse?(node) + node['platform_family'] == 'suse' + end + + # + # Determine if the current node is a member of the windows family. + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def windows?(node) + node['platform_family'] == 'windows' + end + + # + # Determine if the current node is a member of the wrlinux family. + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def wrlinux?(node) + node['platform_family'] == 'wrlinux' + end + + # + # Determine if the current system is a linux derivative + # + # @param [Chef::Node] node + # + # @return [Boolean] + # + def linux?(node) + node['os'] == 'linux' + end - # - # Determine if the current system is a linux derivative - # - # @param [Chef::Node] node - # - # @return [Boolean] - # - def linux?(node) - node['os'] == 'linux' end end diff --git a/cookbooks/chef-sugar/lib/chef/sugar/shell.rb b/cookbooks/chef-sugar/lib/chef/sugar/shell.rb index dcffb572..2c0ba8e0 100644 --- a/cookbooks/chef-sugar/lib/chef/sugar/shell.rb +++ b/cookbooks/chef-sugar/lib/chef/sugar/shell.rb @@ -14,34 +14,37 @@ # limitations under the License. # -require 'mixlib/shellout' -require 'pathname' +require 'mixlib/shellout' unless defined?(Mixlib::ShellOut) +require 'pathname' unless defined?(Pathname) class Chef module Sugar module Shell extend self - # - # Finds a command in $PATH - # - # @param [String] cmd - # the command to find - # - # @return [String, nil] - # - def which(cmd) - if Pathname.new(cmd).absolute? - File.executable?(cmd) ? cmd : nil - else - paths = ENV['PATH'].split(::File::PATH_SEPARATOR) + %w(/bin /usr/bin /sbin /usr/sbin) - - paths.each do |path| - possible = File.join(path, cmd) - return possible if File.executable?(possible) + # this helper has been moved to core chef + if !defined?(Chef::VERSION) || Gem::Requirement.new("< 16.0.257").satisfied_by?(Gem::Version.new(Chef::VERSION)) + # + # Finds a command in $PATH + # + # @param [String] cmd + # the command to find + # + # @return [String, nil] + # + def which(cmd) + if Pathname.new(cmd).absolute? + File.executable?(cmd) ? cmd : nil + else + paths = ENV['PATH'].split(::File::PATH_SEPARATOR) + %w(/bin /usr/bin /sbin /usr/sbin) + + paths.each do |path| + possible = File.join(path, cmd) + return possible if File.executable?(possible) + end + + nil end - - nil end end @@ -51,7 +54,11 @@ def which(cmd) # @return [String] # def dev_null(node) - Chef::Sugar::PlatformFamily.windows?(node) ? 'NUL' : '/dev/null' + if defined?(ChefUtils) + ChefUtils.windows?(node) ? 'NUL' : '/dev/null' + else + Chef::Sugar::PlatformFamily.windows?(node) ? 'NUL' : '/dev/null' + end end # @@ -124,8 +131,11 @@ def version_for(cmd, flag = '--version') end module DSL - # @see Chef::Sugar::Shell#which - def which(cmd); Chef::Sugar::Shell.which(cmd); end + # this helper has been moved to core chef + if !defined?(Chef::VERSION) || Gem::Requirement.new("< 16.0.257").satisfied_by?(Gem::Version.new(Chef::VERSION)) + # @see Chef::Sugar::Shell#which + def which(cmd); Chef::Sugar::Shell.which(cmd); end + end # @see Chef::Sugar::Shell#dev_null def dev_null; Chef::Sugar::Shell.dev_null(node); end diff --git a/cookbooks/chef-sugar/lib/chef/sugar/version.rb b/cookbooks/chef-sugar/lib/chef/sugar/version.rb index 07e2357e..be8faed6 100644 --- a/cookbooks/chef-sugar/lib/chef/sugar/version.rb +++ b/cookbooks/chef-sugar/lib/chef/sugar/version.rb @@ -16,6 +16,6 @@ class Chef module Sugar - VERSION = '5.0.4' + VERSION = "5.1.12" end end diff --git a/cookbooks/chef-sugar/metadata.json b/cookbooks/chef-sugar/metadata.json deleted file mode 100644 index a629cd1b..00000000 --- a/cookbooks/chef-sugar/metadata.json +++ /dev/null @@ -1,37 +0,0 @@ -{ - "name": "chef-sugar", - "description": "Installs chef-sugar. Please see the chef-sugar Ruby gem for more information.", - "long_description": "Chef Sugar is a Gem & Chef Recipe that includes series of helpful syntactic\nsugars on top of the Chef core and other resources to make a cleaner, more lean\nrecipe DSL, enforce DRY principles, and make writing Chef recipes an awesome and\nfun experience!\n\nFor the most up-to-date information and documentation, please visit the [Chef\nSugar project page on GitHub](https://github.com/chef/chef-sugar).\n", - "maintainer": "Chef Software, Inc", - "maintainer_email": "cookbooks@chef.io", - "license": "Apache-2.0", - "platforms": { - "any": ">= 0.0.0" - }, - "dependencies": { - - }, - "providing": { - - }, - "recipes": { - - }, - "version": "5.0.4", - "source_url": "https://github.com/chef/chef-sugar", - "issues_url": "https://github.com/chef/chef-sugar/issues", - "privacy": false, - "chef_versions": [ - [ - ">= 13.0" - ] - ], - "ohai_versions": [ - - ], - "gems": [ - [ - "chef-sugar-ng" - ] - ] -} diff --git a/cookbooks/chef-sugar/metadata.rb b/cookbooks/chef-sugar/metadata.rb index 5013724d..4052c4e6 100644 --- a/cookbooks/chef-sugar/metadata.rb +++ b/cookbooks/chef-sugar/metadata.rb @@ -2,8 +2,7 @@ maintainer 'Chef Software, Inc' maintainer_email 'cookbooks@chef.io' license 'Apache-2.0' -description 'Installs chef-sugar. Please see the chef-sugar ' \ - 'Ruby gem for more information.' +description 'Installs chef-sugar. Please see the chef-sugar Ruby gem for more information.' long_description <<-EOH Chef Sugar is a Gem & Chef Recipe that includes series of helpful syntactic sugars on top of the Chef core and other resources to make a cleaner, more lean @@ -14,11 +13,10 @@ Sugar project page on GitHub](https://github.com/chef/chef-sugar). EOH -require File.expand_path('../lib/chef/sugar/version', __FILE__) -version Chef::Sugar::VERSION +version '5.1.12' supports 'any' issues_url 'https://github.com/chef/chef-sugar/issues' source_url 'https://github.com/chef/chef-sugar' chef_version '>= 13.0' -gem 'chef-sugar-ng' +gem 'chef-sugar' diff --git a/cookbooks/chef-sugar/spec/spec_helper.rb b/cookbooks/chef-sugar/spec/spec_helper.rb index 3f1e1cd8..bf13d893 100644 --- a/cookbooks/chef-sugar/spec/spec_helper.rb +++ b/cookbooks/chef-sugar/spec/spec_helper.rb @@ -1,6 +1,7 @@ require 'rspec' require 'chefspec' require 'chef/sugar' +require 'chef/version' require_relative 'support/shared_examples' @@ -22,4 +23,6 @@ # ChefSpec configuration config.log_level = :fatal + + config.filter_run_excluding pre_chef16_only: Gem::Requirement.new(">= 16.0.257").satisfied_by?(Gem::Version.new(Chef::VERSION)) end diff --git a/cookbooks/chef-sugar/spec/unit/chef/sugar/architecture_spec.rb b/cookbooks/chef-sugar/spec/unit/chef/sugar/architecture_spec.rb deleted file mode 100644 index 292e5ec7..00000000 --- a/cookbooks/chef-sugar/spec/unit/chef/sugar/architecture_spec.rb +++ /dev/null @@ -1,129 +0,0 @@ -require 'spec_helper' - -describe Chef::Sugar::Architecture do - it_behaves_like 'a chef sugar' - - _64_bit_machines = %w(amd64 x86_64 ppc64 ppc64le s390x ia64 sparc64 aarch64 arch64 arm64 sun4u sun4v) - _intel_machines = %w(i86pc i386 x86_64 amd64 i686) - - describe '#_64_bit?' do - _64_bit_machines.each do |arch| - it "returns true when the system is #{arch}" do - node = { 'kernel' => { 'machine' => arch } } - expect(described_class._64_bit?(node)).to be true - end - end - - it 'returns true when ohai provides the bittiness' do - node = { 'kernel' => { 'bits' => '64' } } - expect(described_class._64_bit?(node)).to be true - end - - it 'returns false when ohai provides the bittiness' do - node = { 'kernel' => { 'bits' => '32' } } - expect(described_class._64_bit?(node)).to be false - end - - it 'returns false when the system is not 64 bit' do - node = { 'kernel' => { 'machine' => 'i386' } } - expect(described_class._64_bit?(node)).to be false - end - end - - describe '#_32_bit?' do - it 'returns true when the system is 32 bit' do - node = { 'kernel' => { 'machine' => 'i386' } } - expect(described_class._32_bit?(node)).to be true - end - - _64_bit_machines.each do |arch| - it "returns false when the system is #{arch}" do - node = { 'kernel' => { 'machine' => arch } } - expect(described_class._32_bit?(node)).to be false - end - end - end - - describe '#i386?' do - it 'returns true when the system is 32 bit' do - node = { 'kernel' => { 'machine' => 'i386' } } - expect(described_class.i386?(node)).to be true - end - - _64_bit_machines.each do |arch| - it "returns false when the system is #{arch}" do - node = { 'kernel' => { 'machine' => arch } } - expect(described_class.i386?(node)).to be false - end - end - end - - describe '#intel?' do - _intel_machines.each do |arch| - it "returns true when the system is #{arch}" do - node = { 'kernel' => { 'machine' => arch } } - expect(described_class.intel?(node)).to be true - end - - it 'returns false when the system is non Intel' do - node = { 'kernel' => { 'machine' => 'sun4u' } } - expect(described_class.intel?(node)).to be false - end - end - end - - describe '#powerpc?' do - it 'returns true when the system is IBM POWER or powerpc' do - node = { 'kernel' => { 'machine' => 'powerpc' } } - end - end - - describe '#armhf?' do - it 'returns true when the system is ARM' do - node = { 'kernel' => { 'machine' => 'armv7l' } } - expect(described_class.intel?(node)).to be false - expect(described_class.armhf?(node)).to be true - end - end - - describe '#aarch64?' do - it 'returns true when the system is AArch64' do - node = { 'kernel' => { 'machine' => 'aarch64' } } - expect(described_class.intel?(node)).to be false - expect(described_class.aarch64?(node)).to be true - end - end - - describe '#sparc?' do - it 'returns true when the system is SPARC sun4u' do - node = { 'kernel' => { 'machine' => 'sun4u' } } - expect(described_class.sparc?(node)).to be true - end - - it 'returns true when the system is SPARC sun4v' do - node = { 'kernel' => { 'machine' => 'sun4v' } } - expect(described_class.sparc?(node)).to be true - end - end - - describe '#ppc64?' do - it 'returns true when the system is PowerPC64 Big Endian' do - node = { 'kernel' => { 'machine' => 'ppc64' } } - expect(described_class.ppc64?(node)).to be true - end - end - - describe '#ppc64le?' do - it 'returns true when the system is PowerPC64 Little Endian' do - node = { 'kernel' => { 'machine' => 'ppc64le' } } - expect(described_class.ppc64le?(node)).to be true - end - end - - describe '#s390x?' do - it 'returns true when the system is s390x' do - node = { 'kernel' => { 'machine' => 's390x' } } - expect(described_class.s390x?(node)).to be true - end - end -end diff --git a/cookbooks/chef-sugar/spec/unit/chef/sugar/docker_spec.rb b/cookbooks/chef-sugar/spec/unit/chef/sugar/docker_spec.rb deleted file mode 100644 index 5c18618d..00000000 --- a/cookbooks/chef-sugar/spec/unit/chef/sugar/docker_spec.rb +++ /dev/null @@ -1,39 +0,0 @@ -require 'spec_helper' - -describe Chef::Sugar::Docker do - it_behaves_like 'a chef sugar' - - before(:each) do - allow(File).to receive(:exist?) - .with("/.dockerenv") - .and_return(false) - allow(File).to receive(:exist?) - .with("/.dockerinit") - .and_return(false) - end - - describe '#docker?' do - it 'is true when the file /.dockerenv is present' do - allow(File).to receive(:exist?) - .with("/.dockerenv") - .and_return(true) - - node = { 'docker' => nil } - expect(described_class.docker?(node)).to be true - end - - it 'is true when the file /.dockerinit is present' do - allow(File).to receive(:exist?) - .with("/.dockerinit") - .and_return(true) - - node = { 'docker' => nil } - expect(described_class.docker?(node)).to be true - end - - it 'is false when the node is not on cloud' do - node = { 'docker' => nil } - expect(described_class.docker?(node)).to be false - end - end -end diff --git a/cookbooks/chef-sugar/spec/unit/chef/sugar/kitchen_spec.rb b/cookbooks/chef-sugar/spec/unit/chef/sugar/kitchen_spec.rb deleted file mode 100644 index 5e9d2cc0..00000000 --- a/cookbooks/chef-sugar/spec/unit/chef/sugar/kitchen_spec.rb +++ /dev/null @@ -1,18 +0,0 @@ -require 'spec_helper' - -describe Chef::Sugar::Kitchen do - it_behaves_like 'a chef sugar' - - describe '#kitchen?' do - it 'is true when the TEST_KITCHEN environment variable is set' do - allow(ENV).to receive(:[]).with('TEST_KITCHEN').and_return('1') - node = {} - expect(described_class.kitchen?(node)).to be true - end - - it 'is false when the TEST_KITCHEN environment variable is unset' do - node = {} - expect(described_class.kitchen?(node)).to be false - end - end -end diff --git a/cookbooks/chef-sugar/spec/unit/chef/sugar/platform_family_spec.rb b/cookbooks/chef-sugar/spec/unit/chef/sugar/platform_family_spec.rb deleted file mode 100644 index 3f1a1d05..00000000 --- a/cookbooks/chef-sugar/spec/unit/chef/sugar/platform_family_spec.rb +++ /dev/null @@ -1,166 +0,0 @@ -require 'spec_helper' - -describe Chef::Sugar::PlatformFamily do - it_behaves_like 'a chef sugar' - - describe '#arch_linux?' do - it 'returns true when the platform_family is arch linux' do - node = { 'platform_family' => 'arch' } - expect(described_class.arch_linux?(node)).to be true - end - - it 'returns false when the platform_family is not arch linux' do - node = { 'platform_family' => 'windows' } - expect(described_class.arch_linux?(node)).to be false - end - end - - describe '#debian?' do - it 'returns true when the platform_family is debian' do - node = { 'platform_family' => 'debian' } - expect(described_class.debian?(node)).to be true - end - - it 'returns false when the platform_family is not debian' do - node = { 'platform_family' => 'windows' } - expect(described_class.debian?(node)).to be false - end - end - - describe '#fedora?' do - it 'returns true when the platform_family is fedora' do - node = { 'platform_family' => 'fedora' } - expect(described_class.fedora?(node)).to be true - end - - it 'returns false when the platform_family is not fedora' do - node = { 'platform_family' => 'windows' } - expect(described_class.fedora?(node)).to be false - end - end - - describe '#freebsd?' do - it 'returns true when the platform_family is freebsd' do - node = { 'platform_family' => 'freebsd' } - expect(described_class.freebsd?(node)).to be true - end - - it 'returns false when the platform_family is not freebsd' do - node = { 'platform_family' => 'windows' } - expect(described_class.freebsd?(node)).to be false - end - end - - describe '#gentoo?' do - it 'returns true when the platform_family is gentoo' do - node = { 'platform_family' => 'gentoo' } - expect(described_class.gentoo?(node)).to be true - end - - it 'returns false when the platform_family is not gentoo' do - node = { 'platform_family' => 'windows' } - expect(described_class.gentoo?(node)).to be false - end - end - - describe '#mac_os_x?' do - it 'returns true when the platform_family is mac_os_x' do - node = { 'platform_family' => 'mac_os_x' } - expect(described_class.mac_os_x?(node)).to be true - end - - it 'returns false when the platform_family is not mac_os_x' do - node = { 'platform_family' => 'windows' } - expect(described_class.mac_os_x?(node)).to be false - end - end - - describe '#openbsd?' do - it 'returns true when the platform_family is openbsd' do - node = { 'platform_family' => 'openbsd' } - expect(described_class.openbsd?(node)).to be true - end - - it 'returns false when the platform_family is not openbsd' do - node = { 'platform_family' => 'windows' } - expect(described_class.openbsd?(node)).to be false - end - end - - describe '#rhel?' do - it 'returns true when the platform_family is rhel' do - node = { 'platform_family' => 'rhel' } - expect(described_class.rhel?(node)).to be true - end - - it 'returns false when the platform_family is not rhel' do - node = { 'platform_family' => 'windows' } - expect(described_class.rhel?(node)).to be false - end - end - - describe '#slackware?' do - it 'returns true when the platform_family is slackware' do - node = { 'platform_family' => 'slackware' } - expect(described_class.slackware?(node)).to be true - end - - it 'returns false when the platform_family is not slackware' do - node = { 'platform_family' => 'windows' } - expect(described_class.slackware?(node)).to be false - end - end - - describe '#suse?' do - it 'returns true when the platform_family is suse' do - node = { 'platform_family' => 'suse' } - expect(described_class.suse?(node)).to be true - end - - it 'returns false when the platform_family is not suse' do - node = { 'platform_family' => 'windows' } - expect(described_class.suse?(node)).to be false - end - end - - describe '#windows?' do - it 'returns true when the platform_family is windows' do - node = { 'platform_family' => 'windows' } - expect(described_class.windows?(node)).to be true - end - - it 'returns false when the platform_family is not windows' do - node = { 'platform_family' => 'debian' } - expect(described_class.windows?(node)).to be false - end - end - - describe '#wrlinux?' do - it 'returns true when the platform_family is wrlinux' do - node = { 'platform_family' => 'wrlinux' } - expect(described_class.wrlinux?(node)).to be true - end - - it 'returns false when the platform_family is not wrlinux' do - node = { 'platform_family' => 'debian' } - expect(described_class.wrlinux?(node)).to be false - end - end - - describe '#linux?' do - it 'returns true when the os is Linux' do - node = { 'os' => 'linux' } - expect(described_class.linux?(node)).to be true - end - - it 'returns false when the os is Windows' do - node = { 'os' => 'windows' } - expect(described_class.linux?(node)).to be false - end - - it 'returns false when the os is Windows' do - node = { 'os' => 'darwin' } - expect(described_class.linux?(node)).to be false - end - end -end diff --git a/cookbooks/chef-sugar/spec/unit/chef/sugar/platform_spec.rb b/cookbooks/chef-sugar/spec/unit/chef/sugar/platform_spec.rb index c30bc330..41cc0b97 100644 --- a/cookbooks/chef-sugar/spec/unit/chef/sugar/platform_spec.rb +++ b/cookbooks/chef-sugar/spec/unit/chef/sugar/platform_spec.rb @@ -3,174 +3,6 @@ describe Chef::Sugar::Platform do it_behaves_like 'a chef sugar' - describe '#linux_mint?' do - it 'returns true when the platform is linux mint' do - node = { 'platform' => 'linuxmint' } - expect(described_class.linux_mint?(node)).to be true - end - - it 'returns false when the platform is not linux mint' do - node = { 'platform' => 'windows' } - expect(described_class.linux_mint?(node)).to be false - end - end - - describe '#ubuntu?' do - it 'returns true when the platform is ubuntu' do - node = { 'platform' => 'ubuntu' } - expect(described_class.ubuntu?(node)).to be true - end - - it 'returns false when the platform is not ubuntu' do - node = { 'platform' => 'windows' } - expect(described_class.ubuntu?(node)).to be false - end - end - - describe '#amazon_linux?' do - it 'returns true when the platform is amazon linux' do - node = { 'platform' => 'amazon' } - expect(described_class.amazon_linux?(node)).to be true - end - - it 'returns false when the platform is not amazon linux' do - node = { 'platform' => 'windows' } - expect(described_class.amazon_linux?(node)).to be false - end - end - - describe '#centos?' do - it 'returns true when the platform is centos' do - node = { 'platform' => 'centos' } - expect(described_class.centos?(node)).to be true - end - - it 'returns false when the platform is not centos' do - node = { 'platform' => 'windows' } - expect(described_class.centos?(node)).to be false - end - end - - describe '#oracle_linux?' do - it 'returns true when the platform is oracle linux' do - node = { 'platform' => 'oracle' } - expect(described_class.oracle_linux?(node)).to be true - end - - it 'returns false when the platform is not oracle linux' do - node = { 'platform' => 'windows' } - expect(described_class.oracle_linux?(node)).to be false - end - end - - describe '#scientific_linux?' do - it 'returns true when the platform is scientific linux' do - node = { 'platform' => 'scientific' } - expect(described_class.scientific_linux?(node)).to be true - end - - it 'returns false when the platform is not scientific linux' do - node = { 'platform' => 'windows' } - expect(described_class.scientific_linux?(node)).to be false - end - end - - describe '#redhat_enterprise_linux?' do - it 'returns true when the platform is redhat enterprise linux' do - node = { 'platform' => 'redhat' } - expect(described_class.redhat_enterprise_linux?(node)).to be true - end - - it 'returns false when the platform is not redhat enterprise linux' do - node = { 'platform' => 'enterprise' } - expect(described_class.redhat_enterprise_linux?(node)).to be false - end - end - - describe '#solaris2?' do - it 'returns true when the platform is solaris2' do - node = { 'platform' => 'solaris2' } - expect(described_class.solaris2?(node)).to be true - end - - it 'returns false when the platform is not solaris2' do - node = { 'platform' => 'windows' } - expect(described_class.solaris2?(node)).to be false - end - end - - describe '#aix?' do - it 'returns true when the platform is aix' do - node = { 'platform' => 'aix' } - expect(described_class.aix?(node)).to be true - end - - it 'returns false when the platform is not aix' do - node = { 'platform' => 'windows' } - expect(described_class.aix?(node)).to be false - end - end - - describe '#smartos?' do - it 'returns true when the platform is smartos' do - node = { 'platform' => 'smartos' } - expect(described_class.smartos?(node)).to be true - end - - it 'returns false when the platform is not smartos' do - node = { 'platform' => 'windows' } - expect(described_class.smartos?(node)).to be false - end - end - - describe '#omnios?' do - it 'returns true when the platform is omnios' do - node = { 'platform' => 'omnios' } - expect(described_class.omnios?(node)).to be true - end - - it 'returns false when the platform is not omnios' do - node = { 'platform' => 'windows' } - expect(described_class.omnios?(node)).to be false - end - end - - describe '#raspbian?' do - it 'returns true when platform is raspbian' do - node = { 'platform' => 'raspbian' } - expect(described_class.raspbian?(node)).to be true - end - - it 'returns false when the platform is not raspbian' do - node = { 'platform' => 'windows' } - expect(described_class.raspbian?(node)).to be false - end - end - - describe '#nexus' do - it 'returns true when the platform is nexus' do - node = { 'platform' => 'nexus' } - expect(described_class.nexus?(node)).to be true - end - - it 'returns false when the platform is not nexus' do - node = { 'platform' => 'windows' } - expect(described_class.nexus?(node)).to be false - end - end - - describe '#ios_xr' do - it 'returns true when the platform is ios_xr' do - node = { 'platform' => 'ios_xr' } - expect(described_class.ios_xr?(node)).to be true - end - - it 'returns false when the platform is not ios_xr' do - node = { 'platform' => 'windows' } - expect(described_class.ios_xr?(node)).to be false - end - end - describe '#platform_version' do it 'returns the platform version' do node = { 'platform_version' => '1.2.3' } diff --git a/cookbooks/chef-sugar/spec/unit/chef/sugar/shell_spec.rb b/cookbooks/chef-sugar/spec/unit/chef/sugar/shell_spec.rb index afb6351f..1ab89ee1 100644 --- a/cookbooks/chef-sugar/spec/unit/chef/sugar/shell_spec.rb +++ b/cookbooks/chef-sugar/spec/unit/chef/sugar/shell_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe Chef::Sugar::Shell do - describe '#which' do + describe '#which', :pre_chef16_only do it 'returns the first executable matching the command' do allow(File).to receive(:executable?).and_return(false) allow(File).to receive(:executable?).with('/usr/bin/mongo').and_return(true) @@ -46,7 +46,7 @@ end it 'returns false if the given binary does not exist' do - allow(File).to receive(:executable?).and_return(false) + allow(described_class).to receive(:which).with('node').and_return(nil) expect(described_class.installed?('node')).to be false end end