In what order is a Chef cookbook executed - ruby

I'm trying to get a grasp on chef and for the life of me I cannot find how cook books are run
If I have the file structure
chef-repo
├── cookbooks
│   └── test
│   ├── attributes
│   │   ├── default.rb
│   │   └── test.rb
│   ├── files...
│   ├── metadata.rb
│   ├── recipes
│   │   ├── default.rb
│   │   └── test.rb
│   └── templates...
├── roles
│   └── starter.rb
└── Vagrantfile
How are the attributes loaded and in what order? eg it loads all the attributes (default.rb and test.rb) with default.rb always loaded first
How are the recipes run? eg only default.rb is run and everything , or all are run in alphabetical order.
I've found http://docs.opscode.com/essentials_nodes_chef_run.html but it doesn't explain cookbook execution only node level execution. Any resources or links to chef docs would be appreciated
Cheers

Recipes are run in the order they occur in the runlist. Only recipes that occur in the run list will be executed (plus any recipes that are included in place using include_recipe. Note that each recipe will only run once, even if it occurs multiple times in the runlist.
Attribute files from cookbooks are loaded in this order:
Attributes of dependencies (i.e. cookbooks declared with depends in metadata.rb
attributes/default.rb
all other attributes files in alphabetical order.
Note that all attribute files in a cookbook are loaded, regardless of their name. Only attributes of cookbooks which either explicitly occur in the resolved runlist (i.e. recipes loaded by roles or explicit inclusion into the runlist) or which are dependencies of their cookbooks will be loaded.

Related

Correct directory structure for Puppet RSpec testing

I'm having some issues creating unit tests for my Puppet control repository.
I mostly work with roles and profiles with the following directory structure:
[root#puppet]# tree site
site
├── profile
│   ├── files
│   │   └── demo-website
│   │   └── index.html
│   └── manifests
│   ├── base.pp
│   ├── ci_runner.pp
│   ├── docker.pp
│   ├── gitlab.pp
│   ├── logrotate.pp
│   └── website.pp
├── role
│   └── manifests
│   ├── gitlab_server.pp
│   └── nginx_webserver.pp
Where do I need to place my spec files and what are the correct filenames?
I tried placing them here:
[root#puppet]# cat spec/classes/profile_ci_runner_spec.rb
require 'spec_helper'
describe 'profile::ci_runner' do
...
But I get an error:
Could not find class ::profile::ci_runner
The conventional place for a module's spec tests is in the module, with the spec/ directory in the module root. So site/profile/spec/classes/ci_runner_spec.rb, for example.
You could consider installing PDK, which can help you set up the structure and run tests, among other things.

devtool clones the wrong repository for recipe development

I am using krogoth and recently I have been observing that everytime I do the following:
Add a recipe
devtool add buttonflux https://github.com/shantanoo-desai/buttonflux/archive/v1.0.tar.gz
I get the a previous recipe which I worked up.
here is the recipe-tool generated recipe of the above repository:
# Recipe created by recipetool
# This is the basis of a recipe and may need further editing in order to be fully functional.
# (Feel free to remove these comments when editing.)
#
# WARNING: the following LICENSE and LIC_FILES_CHKSUM values are best guesses - it is
# your responsibility to verify that the values are complete and correct.
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://LICENSE;md5=7e8b8d2e60aca564edd8578b5f1f4951"
HOMEPAGE = "https://github.com/shantanoo-desai/bnoflux"
SUMMARY = "Extract IMU Values from BNO055 and store them in InfluxDB via UDP"
SRC_URI = "https://github.com/shantanoo-desai/buttonflux/archive/v${PV}.tar.gz"
SRC_URI[md5sum] = "1c897adf29ed058315d23d3a79f9c532"
SRC_URI[sha256sum] = "1c5611a579ee169a611fc5b401eb1aa6ad8cb4c168722df0dba7d61bb8fd2d2b"
S = "${WORKDIR}/bnoflux-${PV}"
inherit setuptools
# WARNING: the following rdepends are from setuptools install_requires. These
# upstream names may not correspond exactly to bitbake package names.
RDEPENDS_${PN} += "python-influxdb"
# WARNING: the following rdepends are determined through basic analysis of the
# python sources, and might not be 100% accurate.
RDEPENDS_${PN} += "python-argparse python-core python-logging"
# WARNING: We were unable to map the following python package/module
# dependencies to the bitbake packages which include them:
# influxdb.client
# smbus
It is worth noting the the HOMEPAGE is false and so are the SRC_URI hashes. (I want to use buttonflux and not bnoflux which was my previously worked upon recipe)
I tried reseting the recipes but this problem is still persistent.
my workspace clones also the wrong repository:
workspace/
├── appends
│   └── buttonflux_1.0.bbappend
├── attic
├── conf
│   └── layer.conf
├── README
├── recipes
│   └── buttonflux
│   └── buttonflux_1.0.bb
└── sources
└── buttonflux
├── bin
│   ├── bnoflux
│   └── calibrate
├── bnoflux
│   ├── BNO055.py
│   ├── bnoflux.py
│   ├── calibrate.py
│   └── __init__.py
├── LICENSE
├── MANIFEST.in
├── README.md
└── setup.py
even though the source is called buttonflux the code within it belongs to bnoflux repository.
I do not understand why this is happening.

How to provide attribute value in the template .erb file

How to provide attribute value in a template .erb file
qradar_logs/
├── Berksfile
├── LICENSE
├── README.md
├── attributes
│   └── default.rb
├── chefignore
├── files
│   └── default
│   └── default
├── metadata.rb
├── recipes
│   └── default.rb
├── spec
│   ├── spec_helper.rb
│   └── unit
│   └── recipes
│   └── default_spec.rb
├── templates
│   └── rsyslog.conf.erb
└── test
└── integration
└── default
└── default_test.rb
11 directories, 12 files
In attribute.rb file, I have the following contents:
default['logs']['hostname'] = "169.67.89.72:514"
In my recipe, I provided the following:
hostname = node['logs']['hostname']
In my templates rsyslog.conf file, I would like to use this value based on the value changed in attributes file.
I tried giving:
<%= "#{hostname}" %>
It errors out as:
FATAL: Chef::Mixin::Template::TemplateError: undefined local variable or method `hostname'
How can I access the attributes defined in attribute file in template.erb file?
Thank you
So a few things. First you should use the variables property in your template resource to expose the data to the template:
template '/whatever' do
# ...
variables hostname: node['logs']['hostname']
end
Then you need to use Erb formatting, which you kind of did but not really:
<%= #hostname %>
The variable name matches the key you used with variables.

Yocto: how to add out-of-tree Device driver?

First of all I should say I am a complete newbie to the Yocto world.
I have a working environment that produces my uboot+kernel+rootfs.
I need to add a (complex) driver I have as a subdirectory.
This driver can be compiled natively in the standard way:
here=$(pwd)
make -C /lib/modules/$(uname -r)/build M=$here/bcmdhd modules CONFIG_BCMDHD_PCIE=y CONFIG_BCMDHD=m CONFIG_BCM4359=y
I have seen Integrate out-of-tree driver in kernel and rebuild yocto project image and I have read Yocto Kernel Development Manual.
I tried to follow directions:
Created a directory in .../recipes-kernel beside linux dir.
Copied the source directory in it.
Created a .bb file.
The resulting source tree is:
recipes-kernel/
├── kernel-modules
│   ├── kernel-module-bcmdhd
│   │   └── bcmdhd
│   │   ├── include
│   │   │   ├── include files
│   │   ├── Kconfig
│   │   ├── Makefile
│   │   └── other source files
│   └── kernel-module-bcmdhd_0.1.bb
└── linux
├── linux-imx-4.1.15
│   └── imx
│   └── defconfig
└── linux-imx_4.1.15.bbappend
My BCM89359-mod_0.1.bb contains:
SUMMARY = "Integration of Cypress BCMDHD external Linux kernel module"
LICENSE = "Proprietary"
inherit module
SRC_URI = "file://bcmdhd"
S = "${WORKDIR}"
Unfortunately this doesn't seem to be enough as running bitbake results in no compilation attempted.
I am quite plainly missing something, but I'm unable to understand what.
Any help welcome.
You should have the following source tree:
recipes-kernel/
├── kernel-modules
│   ├── kernel-module-bcm89359_0.1.bb
│ └── kernel-module-bcm89359
│ └ bcmdhd
│ ├ Kconfig
└── linux
├── ...
(For the record)
You can add your module to MACHINE_ESSENTIAL_EXTRA_RDEPENDS += "kernel-module-bcm89359" to local.conf or machine configuration. Also, you can add KERNEL_MODULE_AUTOLOAD = "bcm89359" to load your module automatically.

Gradle plugin packaging - Why is plugin unexpectedly applied?

So I have:
buildSrc/
├── build.gradle
└── src
├── main
│   ├── groovy
│   │   └── build
│   │   ├── ExamplePlugin.groovy
│   │   └── ExampleTask.groovy
│   └── resources
│   └── META-INF
│   └── gradle-plugins
│   └── build.ExamplePlugin.properties
└── test
└── groovy
└── build
├── ExamplePluginTest.groovy
└── ExampleTaskTest.groovy
Question:
It seems like build.ExamplePlugin.properties maps directly to the build.ExamplePlugin.groovy. Is this the case? Seems terribly inefficient to have only one property in the file. Does it have to be fully qualified, i.e. does the name have to exactly match the full qualification of the class?
Now in the example, I see:
project.pluginManager.apply 'build.ExamplePlugin'
...however if I have that in my test, I get an error to the effect that the simple task the plugin defines, is already defined.
Why bother with test examples that require 'apply' when that is inappropriate for packaging?

Resources