Trouble with ntp-cookbook

Hi folks,

I created a small wrapper-cookbook for the ntp-cookbook. This wrapper
searches for non-virtual machines in the current environment that have
the wrapper-cookbook applied. Then it uses these machines as peers for
ntp if itself is a non-virtual machine or as servers for ntp if itself
is a virtual machine. Works great except for some slight problem: The
list of peers/servers is in the order the search returned the machines,
which changes with each call. I tried to sort my resulting list, but
still the lists in the ntp.conf are not ordered. And the ordering in
the ntp.conf changes with almost every chef-client run, resulting in
fcheck finding lots of changes.

So I took a quick hack and added ordering in the ntp.conf-template in
the ntp-cookbook. Works nicely in reality but is untested.

So I tried to prepare a real patch for the ntp-cookbook with
corresponding rspec-test. But when I try to check
"create_file_with_content" I get an error:

Failure/Error: expect(chef_run).to
create_file_with_content(’/etc/ntp.conf’, /.Chef./)
Chef::Mixin::Template::TemplateError: undefined method `[]’ for
nil:NilClass

And I don’t know why that error is happening. It looks as if the rspec
tests don’t set all the attributes the template needs. But its only the
default tests, so if that fails, either there is an error in
chef/chefspec/tests or the cookbook wouldn’t be able to run on any
machine (without setting attributes). The later I doubt…

Anyway, what I did is patch spec/unit/recipes/default_spec.rb in the
ntp-cookbook with:

diff --git a/spec/unit/recipes/default_spec.rb
b/spec/unit/recipes/default_spec.rb index fa9b4f7…4e2ce71 100644
— a/spec/unit/recipes/default_spec.rb
+++ b/spec/unit/recipes/default_spec.rb
@@ -1,4 +1,5 @@
require ‘spec_helper’
+require ‘chefspec’

describe ‘ntp::default’ do
let(:chef_run) { ChefSpec::ChefRunner.new.converge(‘ntp::default’) }
@@ -69,6 +70,10 @@ describe ‘ntp::default’ do
expect(chef_run).to create_file(’/etc/ntp.conf’)
end

  • it ‘creates the template with peer content’ do
  •  expect(chef_run).to
    

create_file_with_content(’/etc/ntp.conf’, /.Chef./)

  • end
  • it ‘is owned by ntp:ntp’ do
    expect(template.owner).to eq(‘root’)
    expect(template.group).to eq(‘root’)

Anybody got an idea? Anybody can reproduce my findings?

I use ruby-2.0.0-p247 and everything else according to the Gemfile of
the ntp-cookbook.

Thanks in advance,

  • Arnold

Hi,

I haven't solved this but created a fork+branch at

  • Arnold

Am Wed, 11 Dec 2013 13:54:34 +0100 schrieb Arnold Krille
arnold@arnoldarts.de:

I created a small wrapper-cookbook for the ntp-cookbook. This wrapper
searches for non-virtual machines in the current environment that have
the wrapper-cookbook applied. Then it uses these machines as peers for
ntp if itself is a non-virtual machine or as servers for ntp if itself
is a virtual machine. Works great except for some slight problem: The
list of peers/servers is in the order the search returned the
machines, which changes with each call. I tried to sort my resulting
list, but still the lists in the ntp.conf are not ordered. And the
ordering in the ntp.conf changes with almost every chef-client run,
resulting in fcheck finding lots of changes.

So I took a quick hack and added ordering in the ntp.conf-template in
the ntp-cookbook. Works nicely in reality but is untested.

So I tried to prepare a real patch for the ntp-cookbook with
corresponding rspec-test. But when I try to check
"create_file_with_content" I get an error:

Failure/Error: expect(chef_run).to
create_file_with_content('/etc/ntp.conf', /.Chef./)
Chef::Mixin::Template::TemplateError: undefined method `' for
nil:NilClass

And I don't know why that error is happening. It looks as if the rspec
tests don't set all the attributes the template needs. But its only
the default tests, so if that fails, either there is an error in
chef/chefspec/tests or the cookbook wouldn't be able to run on any
machine (without setting attributes). The later I doubt...

Anyway, what I did is patch spec/unit/recipes/default_spec.rb in the
ntp-cookbook with:

diff --git a/spec/unit/recipes/default_spec.rb
b/spec/unit/recipes/default_spec.rb index fa9b4f7..4e2ce71 100644
--- a/spec/unit/recipes/default_spec.rb
+++ b/spec/unit/recipes/default_spec.rb
@@ -1,4 +1,5 @@
require 'spec_helper'
+require 'chefspec'

describe 'ntp::default' do
let(:chef_run)
{ ChefSpec::ChefRunner.new.converge('ntp::default') } @@ -69,6 +70,10
@@ describe 'ntp::default' do expect(chef_run).to
create_file('/etc/ntp.conf') end

  • it 'creates the template with peer content' do
  •  expect(chef_run).to
    

create_file_with_content('/etc/ntp.conf', /.Chef./)

  • end
  • it 'is owned by ntp:ntp' do
    expect(template.owner).to eq('root')
    expect(template.group).to eq('root')

Anybody got an idea? Anybody can reproduce my findings?

I use ruby-2.0.0-p247 and everything else according to the Gemfile of
the ntp-cookbook.

Thanks in advance,

  • Arnold

Bump, anybody can look at this and tell me what I did wrong?

Am Wed, 11 Dec 2013 14:40:39 +0100
schrieb Arnold Krille arnold@arnoldarts.de:

I haven't solved this but created a fork+branch at
GitHub - kampfschlaefer/ntp at spec_check_for_content

Am Wed, 11 Dec 2013 13:54:34 +0100 schrieb Arnold Krille
arnold@arnoldarts.de:

I created a small wrapper-cookbook for the ntp-cookbook. This
wrapper searches for non-virtual machines in the current
environment that have the wrapper-cookbook applied. Then it uses
these machines as peers for ntp if itself is a non-virtual machine
or as servers for ntp if itself is a virtual machine. Works great
except for some slight problem: The list of peers/servers is in the
order the search returned the machines, which changes with each
call. I tried to sort my resulting list, but still the lists in the
ntp.conf are not ordered. And the ordering in the ntp.conf changes
with almost every chef-client run, resulting in fcheck finding lots
of changes.

So I took a quick hack and added ordering in the ntp.conf-template
in the ntp-cookbook. Works nicely in reality but is untested.

So I tried to prepare a real patch for the ntp-cookbook with
corresponding rspec-test. But when I try to check
"create_file_with_content" I get an error:

Failure/Error: expect(chef_run).to
create_file_with_content('/etc/ntp.conf', /.Chef./)
Chef::Mixin::Template::TemplateError: undefined method `' for
nil:NilClass

And I don't know why that error is happening. It looks as if the
rspec tests don't set all the attributes the template needs. But
its only the default tests, so if that fails, either there is an
error in chef/chefspec/tests or the cookbook wouldn't be able to
run on any machine (without setting attributes). The later I
doubt...

Anyway, what I did is patch spec/unit/recipes/default_spec.rb in the
ntp-cookbook with:

diff --git a/spec/unit/recipes/default_spec.rb
b/spec/unit/recipes/default_spec.rb index fa9b4f7..4e2ce71 100644
--- a/spec/unit/recipes/default_spec.rb
+++ b/spec/unit/recipes/default_spec.rb
@@ -1,4 +1,5 @@
require 'spec_helper'
+require 'chefspec'

describe 'ntp::default' do
let(:chef_run)
{ ChefSpec::ChefRunner.new.converge('ntp::default') } @@ -69,6
+70,10 @@ describe 'ntp::default' do expect(chef_run).to
create_file('/etc/ntp.conf') end

  • it 'creates the template with peer content' do
  •  expect(chef_run).to
    

create_file_with_content('/etc/ntp.conf', /.Chef./)

  • end
  • it 'is owned by ntp:ntp' do
    expect(template.owner).to eq('root')
    expect(template.group).to eq('root')

Anybody got an idea? Anybody can reproduce my findings?

I use ruby-2.0.0-p247 and everything else according to the Gemfile
of the ntp-cookbook.

Thanks in advance,

  • Arnold

On Dec 13, 2013, at 8:36 AM, Arnold Krille arnold@arnoldarts.de wrote:

Bump, anybody can look at this and tell me what I did wrong?

I'm just getting into chefspec, but I'll take a look at this over the weekend and early next week and see if I can spot anything that might be useful.

BTW -- I know that the company-formerly-known-as-opscode has been looking for new people to take over a lot of the cookbooks that they have maintained in the past.

As a long-time contributor to the NTP Public Support Project and now a contributor to the Network Time Foundation, I'm wondering if maybe we can help provide some sponsorship in this area? I don't know that we would want to commit to taking sole ownership of the cookbook, but I think we would be happy to be the lead maintainer of a group who would share the responsibility. This kind of thing is something we care about, and we would want to do whatever we can to try to make this maximally robust and compliant with best practices.

Thanks!

--
Brad Knowles brad@shub-internet.org
LinkedIn Profile: http://tinyurl.com/y8kpxu

On Fri, Dec 13, 2013 at 10:47 AM, Brad Knowles brad@shub-internet.org wrote:

On Dec 13, 2013, at 8:36 AM, Arnold Krille arnold@arnoldarts.de wrote:

Bump, anybody can look at this and tell me what I did wrong?

I'm just getting into chefspec, but I'll take a look at this over the weekend and early next week and see if I can spot anything that might be useful.

I tried to run the tests and they're all written for an old version of
ChefSpec so unfortunately I can't help :frowning: But my suspicion is that
there's some platform mocking with Fauxhai that's missing, and the
template uses Ohai data, which, if not mocked, returns nil.

BTW -- I know that the company-formerly-known-as-opscode has been looking for new people to take over a lot of the cookbooks that they have maintained in the past.

As a long-time contributor to the NTP Public Support Project and now a contributor to the Network Time Foundation, I'm wondering if maybe we can help provide some sponsorship in this area? I don't know that we would want to commit to taking sole ownership of the cookbook, but I think we would be happy to be the lead maintainer of a group who would share the responsibility. This kind of thing is something we care about, and we would want to do whatever we can to try to make this maximally robust and compliant with best practices.

That'd be great, Brad -- get in touch with Sean O'Meara at
Opscode^WChef (someara@getchef.com) and he'll be happy to arrange
something. We need to update the tests, as above, and go from there.

  • Julian

--
[ Julian C. Dunn jdunn@aquezada.com * Sorry, I'm ]
[ WWW: Julian Dunn's Blog - Commentary on media, technology, and everything in between. * only Web 1.0 ]
[ gopher://sdf.org/1/users/keymaker/ * compliant! ]
[ PGP: 91B3 7A9D 683C 7C16 715F 442C 6065 D533 FDC2 05B9 ]

Am Fri, 13 Dec 2013 09:47:20 -0600
schrieb Brad Knowles brad@shub-internet.org:

On Dec 13, 2013, at 8:36 AM, Arnold Krille arnold@arnoldarts.de
wrote:

Bump, anybody can look at this and tell me what I did wrong?

I'm just getting into chefspec, but I'll take a look at this over the
weekend and early next week and see if I can spot anything that might
be useful.

BTW -- I know that the company-formerly-known-as-opscode has been
looking for new people to take over a lot of the cookbooks that they
have maintained in the past.

As a long-time contributor to the NTP Public Support Project and now
a contributor to the Network Time Foundation, I'm wondering if maybe
we can help provide some sponsorship in this area? I don't know that
we would want to commit to taking sole ownership of the cookbook, but
I think we would be happy to be the lead maintainer of a group who
would share the responsibility. This kind of thing is something we
care about, and we would want to do whatever we can to try to make
this maximally robust and compliant with best practices.

If I understand the comments about testing in the ntp-cookbook
correctly, Chef[Inc] will keep this cookbook because its one of their
simple examples for all the useful testing steps.

Have fun,

Arnold

On Fri, 13 Dec 2013 11:46:55 -0500 "Julian C. Dunn"
jdunn@aquezada.com wrote:

On Fri, Dec 13, 2013 at 10:47 AM, Brad Knowles
brad@shub-internet.org wrote:

On Dec 13, 2013, at 8:36 AM, Arnold Krille arnold@arnoldarts.de
wrote:

Bump, anybody can look at this and tell me what I did wrong?

I'm just getting into chefspec, but I'll take a look at this over
the weekend and early next week and see if I can spot anything that
might be useful.

I tried to run the tests and they're all written for an old version of
ChefSpec so unfortunately I can't help :frowning:

Hm, isn't it the purpose of bundler+gem to fix the version-hell?

But my suspicion is that
there's some platform mocking with Fauxhai that's missing, and the
template uses Ohai data, which, if not mocked, returns nil.

Okay, I think I will disable and enable parts of the template to see
what is missing in the ohai data.

Have fun,

Arnold