Table of contents
1.
Introduction
2.
ChefDkGenerators
2.1.
Examples
3.
Cheffile
4.
ChefHandlerRecipe
4.1.
Examples
5.
ChefHandlerUsesSupports
5.1.
Examples
6.
ChefRewind
6.1.
Examples
7.
ChefShellOut
7.1.
Examples
8.
ChefSpecCoverageReport
8.1.
Examples
9.
ChefSpecLegacyRunner
9.1.
Examples
10.
ChefSugarHelpers
10.1.
Examples
11.
ChefWindowsPlatformHelper
11.1.
Examples
12.
ChocolateyPackageUninstallAction
12.1.
Examples
13.
CookbookDependsOnCompatResource
13.1.
Examples
14.
CookbookDependsOnPartialSearch
14.1.
Examples
15.
CookbookDependsOnPoise
15.1.
Examples
16.
Frequently Asked Questions
16.1.
What are Cops?
16.2.
What are Policyfiles?
16.3.
What to do if the Policyfiles model isn’t compatible with your workflow?
17.
Conclusion
Last Updated: Mar 27, 2024

CookStyle Cops - Chef/Deprecations Section

Author Anmol Punetha
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?
OG Image

Introduction

Chef Automatee Architecture

Source: Chef

ChefDkGenerators

The complete name of the cop is: Chef/Correctness/ChefDKGenerators

ChefDKGenerators is a cookstyle cop that is enabled by Default and supports autocorrection. It is a cop that can be used in all chef versions. 

ChefDk (formerly called Chef Workstation 8.0) module is used to write custom cookbook generators from ChefDk to ChefCLI. We will reference the new class names for compatibility with the latest workstations.

Examples

Incorrect:

ChefDK::CLI
ChefDK::Generator::TemplateHelper
module ChefDK
 # some additional code
end

 

Correct:

ChefCLI::CLI
ChefCLI::Generator::TemplateHelper
module ChefCLI
 # some additional code
end

 

Configurable Attributes:

Configurable Attributes  of ChefDkGenerators

 

Cheffile

The complete name of the cop is: Chef/Correctness/Cheffile

Cheffile is a cookstyle cop that is enabled by Default and does not support autocorrection. It is a cop that can be used in all chef versions. 

A Cheffile should no longer be used for cookbook depsolving since the librarian-chef project is no longer maintained; use Policyfiles instead. 

Configurable Attributes:

 

Configurable Attributes  of Cheffile

 

ChefHandlerRecipe

The complete name of the cop is: Chef/Correctness/ChefHandlerRecipe

ChefHandlerRecipe is a cookstyle cop that is enabled by Default and supports autocorrection. It is a cop that can be used in all chef versions. 

There’s no requirement to include the deprecated and empty chef_handler::default recipe to use the ChefHandler.

Examples

Incorrect:

include_recipe 'chef_handler'
include_recipe 'chef_handler::default'

 

Configurable Attributes:

Configurable Attributes  of ChefHandlerRecipe

ChefHandlerUsesSupports

The complete name of the cop is: Chef/Correctness/ChefHandlerUsesSupports

ChefHandlerUsesSupport is a cookstyle cop that is enabled by Default and supports autocorrection. It is a cop that can be used in all chef versions. 

This property of supports was removed in chef_handler cookbook version 3.0; instead, we use the type property in the chef_handler resource.

Examples

Incorrect:

chef_handler 'whatever' do
supports start: true, report: true, exception: true
end0

 

Correct:

chef_handler 'whatever' do
  type start: true, report: true, exception: true
end

 

Configurable Attributes:

 

Configurable Attributes  of ChefHandlerUsesSupports

ChefRewind

The complete name of the cop is: Chef/Correctness/ChefRewind

ChefRewind is a cookstyle cop that is enabled by Default and supports autocorrection. It is a cop that can be used in all chef versions that are above 12.10 

This property of supports was removed in chef_handler cookbook version 3.0; instead, we use the type property in the chef_handler resource.

Examples

chef_gem ‘chef-rewind’
require ‘chef/rewind’
rewind “user[postgres]” do home ‘/var/lib/pgsql/9.2’ cookbook ‘my-postgresql’ end
unwind “user[postgres]”

 

Configurable Attributes:

 

Configurable Attributes  of ChefRewind

 

ChefShellOut

The complete name of the cop is: Chef/Correctness/ChefShellOut

ChefShellOut is a cookstyle cop that is enabled by Default and supports autocorrection. It is a cop that can be used in all chef versions. 

ChefShellOut is a deprecated class that got removed in Chef Infra Client 13. So, we use the Mixlib::ShellOut class instead.

Examples

Incorrect:

include Chef::ShellOut
require 'chef/shellout'
Chef::ShellOut.new('some_command')

 

Correct:

include Mixlib::ShellOut
require 'mixlib/shellout'
Mixlib::ShellOut.new('some_command')

 

Configurable Attributes:

Configurable Attributes  of ChefShellOut

ChefSpecCoverageReport

The complete name of the cop is: Chef/Correctness/ChefSpecCoverageReport

ChefSpecCoverageReport is a cookstyle cop that is enabled by Default and supports autocorrection. It is a cop that can be used in all chef versions. 

ChefSpecCoverageReport is a deprecated class that got removed as it encouraged cookbook authors to write ineffective specs.

Examples

Incorrect:

at_exit { ChefSpec::Coverage.report! }

 

Configurable Attributes:

Configurable Attributes  of ChefSpecCoverageReport

ChefSpecLegacyRunner

The complete name of the cop is: Chef/Correctness/ChefSpecLegacyRunner

ChefSpecLegacyRunner is a cookstyle cop that is enabled by Default and supports autocorrection. It is a cop that can be used in all chef versions. 

ChefSpecLegacyRunner is a deprecated class; instead, we use the ChefSpec::SoloRunner or the ChefSpec::Runner that were introduced in ChefSpec 4.1

Examples

Incorrect:

describe 'foo::default' do
 subject { ChefSpec::Runner.new.converge(described_recipe) }
 # some spec code
end

 

Correct:

describe 'foo::default' do
 subject { ChefSpec::ServerRunner.new.converge(described_recipe) }
 # some spec code
end

 

Configurable Attributes:

Configurable Attributes  of ChefSpecLegacyRunner

ChefSugarHelpers

The complete name of the cop is: Chef/Correctness/ChefSugarHelpers

ChefSugarHelpers is a cookstyle cop that is enabled by Default and does not support autocorrection. It is a cop that can be used in all chef versions. 

We don’t use the chef-sugar methods as they won’t be moved into the Chef Infra Client.

Examples

Incorrect: 

vagrant_key?
vagrant_domain?
vagrant_user?
require_chef_gem
best_ip_for(node)
nexus?
ios_xr?
ruby_20?
ruby_19?
includes_recipe?('foo::bar')
wrlinux?
dev_null
nexentacore_platform?
opensolaris_platform?
nexentacore?
opensolaris?

 

Configurable Attributes:

Configurable Attributes  of ChefSugarHelpers

 

ChefWindowsPlatformHelper

The complete name of the cop is: Chef/Correctness/ChefWindowsPlatformHelper

ChefWindowsPlatformHelper is a cookstyle cop that is enabled by default and supports autocorrection. It is a cop that can be used in all chef versions. 

We now use platform? (‘windows) instead of the Chef::Platform.windows? 

Examples

Incorrect:

Chef::Platform.windows?

 

Correct:

platform?('windows')
platform_family?('windows')

 

Configurable Attributes:

Configurable Attributes  of ChefWindowsPlatformHelper

ChocolateyPackageUninstallAction

The complete name of the cop is: Chef/Correctness/ChocolateyPackageUninstallAction

ChocolateyPackageUninstallAction is a cookstyle cop that is enabled by Default and supports autocorrection. It is a cop that can be used in all chef versions. 

We use the :remove from the chocolatey_package resource instead of the :uninstall, which got removed in Chef Infra Client 14+

Examples

Incorrect:

chocolatey_package 'nginx' do
 action :uninstall
end

 

Correct:

chocolatey_package 'nginx' do
 action :remove
end

 

Configurable Attributes:

Configurable Attributes  of ChocolateyPackageUninstallAction

CookbookDependsOnCompatResource

The complete name of the cop is: Chef/Correctness/CookbookDependsOnCompatResource

CookbookDependsOnCompatResource is a cookstyle cop that is enabled by Default and supports autocorrection. It is a cop that can be used in all chef versions that are above 12.19

Compact_resource is deprecated and was made obsolete by Chef Infra Client 12.19+

Examples

Incorrect:

depends 'compat_resource'

 

Configurable Attributes:

Configurable Attributes  of CookbookDependsOnCompatResource

 

CookbookDependsOnPartialSearch

The complete name of the cop is: Chef/Correctness/CookbookDependsOnPartialSearch

CookbookDependsOnPartialSearch is a cookstyle cop that is enabled by Default and supports autocorrection. It is a cop that can be used in all chef versions that are above 13.0

Partial_search  is deprecated and was made obsolete by Chef Infra Client 13.

Examples

Incorrect:

depends 'partial_search'

 

Configurable Attributes:

Configurable Attributes  of CookbookDependsOnPartialSearch

CookbookDependsOnPoise

The complete name of the cop is: Chef/Correctness/CookbookDependsOnPoise

CookbookDependsOnPoise is a cookstyle cop that is enabled by default and does not support autocorrection. It is a cop that can be used in all chef versions.

The poise frameworks are deprecated and must be refactored to utilize standard Chef Infra custom resources.

Examples

Incorrect:

depends 'poise'
depends 'poise-service'
depends 'poise-hoist'

 

Configurable Attributes:

Configurable Attributes  of CookbookDependsOnPoise

Frequently Asked Questions

What are Cops?

Cops are the checks performed on the code responsible for detecting one particular offense. There are several cop sections grouped based on the offense.

What are Policyfiles?

Policyfiles are a way to create an immutable collection of cookbooks, their dependencies, and attributes that are defined in a single document uploaded to the Chef Infra server.

What to do if the Policyfiles model isn’t compatible with your workflow?

If the Policyfiles isn’t compatible, we may find that Berkshelf offers a similar (and still supported) experience to Librarian-Chef.

Conclusion

So, with this, we saw about the Deprecations section of the CookStyle tool. I hope that the blog was informative.

See Basics of C++ with Data StructureDBMS, and Operating System by Coding Ninjas, and keep practicing on our platform Coding Ninjas Studio.

If you think you are ready for the tech giants company, check out the mock test series on code studio.

You can also refer to our Guided Path on Coding Ninjas Studio to upskill yourself in domains like Data Structures and AlgorithmsCompetitive ProgrammingAptitude, and many more! You can also prepare for tech giants companies like Amazon, Microsoft, Uber, etc., by looking for the questions asked by them in recent interviews. If you want to prepare for placements, refer to the interview bundle. If you are nervous about your interviews, you can see interview experiences to get ideas about these companies' questions.

Nevertheless, you may consider our premium courses to give your career an edge over others!

Do upvote our blogs if you find them helpful and engaging!

Happy Learning!

THank you image

 

Live masterclass