Saturday, July 29, 2017

How to test the Cookbook?(using kitchen and chef-client --local-mode)

You can verify the Cookbook,that means verifying the recipe(like,we have to make sure the ruby chef code was written properly with all the correct syntax).

We can use the Kitchen,which is also called as the test kitchen,to test the runlist attached to the node.
We can also locally analyse the cookbook,by running the chef-client in the local-mode.

How to setup a Test Kitchen?
first and foremost we have to install the Vagrant and Virtualbox

kitchen acts as a provisioner,
(by default it takes the vagrant, basic requirements to test the kitchen, that is we have to install the vagrant and vagrant depends on the virtual box).
so we need to install vagrant and virtual box.

coming to docker, once when you install virtual box ,automatically the docker instance will setup on the virtual box.

step1:Install virtual box
step2:Download Vagrant
(https://www.vagrantup.com/downloads.html)
step3:vagrant -v (to check the version of vagrant).
step4:vagrant init hashicorp/precise64 b)vagrant up
first command creates a file and the second starts it
step5:we can ssh in to that box also, using the:
vagrant ssh.
—————————————————————————
Examples for the kitchen:
http://kitchen.ci/docs/getting-started/creating-cookbook
1)chef exec kitchen list
2)chef exec kitchen int
3)chef exec kitchen login
(or)
kitchen init --driver=kitchen-vagrant
(it includes the .kitchen.yml,chefignore).
once the above command is done, we have to do kitchen list
then we get the list of machines.
then select the required machine, we can create or converge the machines, the following are the commands for that:
1)kitchen create default-ubuntu-1204
the machine was created.
(or)
2) kitchen converge default-ubuntu-1204
login commands:
kitchen login default-ubuntu-1204




Or we can execute the Kitchen commands in the Following manner:
General Approach
 Once,we finished our cookbook writing,we need to go under two steps:
1)rubocop  -a   .
(everyone has to follow the single standard that is meaning of rubocop -a) 
A cookbook will be modified by several ppl in the organsation,inorder to bring everyone's modification in to the single-standard format rubocop -a  .  will help us to maintain the standard.
we are making uniform among the code.
offenses  =  standard where ruby chef script should be followed).

2)foodcritic  .
(to check the syntax’s and functionality of the code)
http://www.foodcritic.io/#FC008

(it is mainly to correct the code )
to correct the cookbook to to the standard for the ruby developers.
Steps of execution:

kitchen test
kitchen converge
kicthen verify
kitchen login

Note:
Make sure you perform all the command in the cookbook directory you want to test.
and make sure  you have the .kitchen.yml file to test with the kitchen commands.

No comments:

Post a Comment