Chef automate v1 using deprecated knife cookbook test

I am running from AWS Marketplace chef automate v1.8.85 which has workflow feature.

I am trying to run the learn_chef_httpd cookbook from the learn chef rally examples.

I was able to get a runner installed and I started a workflow but I am getting errors during the verify/approval stage.

STDERR: FATAL: Cannot find subcommand for: 'cookbook test -o /var/opt/delivery/workspace/
---- End output of knife cookbook test -o /var/opt/delivery

It looks like its trying to run knife cookbook test but that looks to be deprecated according to this git post

Here is the version of software as seen on my runner instance that was (I'm assuming) installed from the automate-ctl install-runner command

ChefDK version: 4.6.35
Chef Infra Client version: 15.5.17
Chef InSpec version: 4.18.39
Test Kitchen version: 2.3.4
Foodcritic version: 16.2.0
Cookstyle version: 5.13.7

Here is the version running off my workstation

Chef Workstation version: 0.13.35
Chef Infra Client version: 15.6.10
Chef InSpec version: 4.18.39
Chef CLI version: 2.0.0
Test Kitchen version: 2.3.4
Cookstyle version: 5.16.11

Not sure what else to try other than specifying the ChefDK version when running the install-runner command but I'm not sure which version to use. Any help would be greatly appreciated.

Thanks

Hi,

knife cookbook test is no longer available to use. It's because foodcritic is deprecated and become a part of cookstyle.

There are a few ways to go, to fix that:

  1. you need to edit the syntax.rb of you "cookbook internal" build_cookbook
  • OR
  1. you create a new (your own) delivery-truck cookbook and update the build_cookbook references (includes) to use it.

This is the old block of the delivery-truck cookbook - syntax.rb:

# Run `knife cookbook test` against the modified cookbook
  execute "syntax_check_#{cookbook.name}" do
    command "knife cookbook test -o #{cookbook.path} -a"
  end
end

The new one could be look like that:

execute "syntax_check_#{cookbook.name}" do
    command "cookstyle #{cookbook.path} --display-cop-names --extra-details"
    live_stream true
  end
end

Hope that helps.

Thanks that resolved the problem

First, my syntax.rb file has just a single line for including the delivery-truck cookbook.

include_recipe 'delivery-truck::syntax'

Here's how I was able to modify the delivery-truck cookbook to resolve my issue with chef automate using the code you shared. I downloaded the cookbooks using berks install and copied the contents of the delivery-trucks syntax.rb into my local syntax.rb file. the sed commands delete the deprecated line containing knife cookbook test and it adds the 2 lines you shared

cd learn_chef_htptd/.delivery/build_cookbook/
berks install
cd ../../
cat ~/.berkshelf/cookbooks/delivery-truck-848b98e26106d1c7d3b06d0121a20cfee7f4c5b0/recipes/syntax.rb > ./.delivery/build_cookbook/recipes/syntax.rb
IFS=
echo $(sed '43d' ./.delivery/build_cookbook/recipes/syntax.rb | sed '43i\ \ \ \ command "cookstyle #{cookbook.path} --display-cop-names --extra-details"' | sed '44i\ \ \ \ live_stream true') > ./.delivery/build_cookbook/recipes/syntax.rb

If you start out with a fresh copy of learn_chef_httpd, make sure you perform that fix plus the config.json to ensure that Cookstyle is used instead of robocop - which I was having issues with.

   {
  "version": "2",
  "build_cookbook": {
    "name": "build_cookbook",
    "path": ".delivery/build_cookbook"
  },
  "skip_phases": [],
  "job_dispatch": {
    "version": "v2"
  },
  "dependencies": [],
  "delivery-truck": {
    "lint": {
      "enable_cookstyle": true
    },
    "publish": {
      "chef_server": true
    }
  }
}

okay,

step one is done! Now you need a file called .rubocop.yml in your <cookbook_name> folder.

In this file you have to exclude/deactivate no needed rules.

Checkout this Websites to find the right rules:

[https://github.com/chef/cookstyle/blob/master/docs/cops.md]
[https://rubocop.readthedocs.io/en/latest/cops/]

Here an example of my .rubocop.yml file:

Layout/EndOfLine:
  Enabled: false
Metrics/LineLength:
  Max: 500
Metrics/BlockLength:
  Enabled: false
Style/TrailingCommaInArrayLiteral:  
  Enabled: true
ChefDeprecations/LongDescriptionMetadata:
  Enabled: false
ChefCorrectness/NodeNormal:
  Enabled: false

After this step you can use

cookstyle -a

in you cookbook_name folder to autocorrect some issues.