Skip to content

Requires and autorequires do not seem to be evaluated #628

@glennsarti

Description

@glennsarti

I was writing some tests for the puppetlabs-registry module and I found I could not test that the autorequires was working. I have created a minimal repro case at https://github.com/glennsarti/rspec_issue

For the sake of the issue I'll copy the pertinent bits here:

Given a test manifest of (https://github.com/glennsarti/rspec_issue/blob/master/spec/fixtures/testmodule/manifests/init.pp)

class testmodule {

  notify { 'notify1': }

  notify { 'notify2':
    require => Notify['notify1']
  }

  dummy { 'Test':
    path => 'test',
  }
}

Note - Dummy is a custom type created at https://github.com/glennsarti/rspec_issue/blob/master/lib/puppet/type/dummy.rb which is used for debugging.

Given a spec file of:

describe 'testmodule' do

  # ------------------------------------------- Just using notify resources

  # This expectation succeeds
  it { is_expected.to compile }

  # This expectation succeeds
  it { is_expected.to contain_notify('notify1') }

  # This expectation succeeds
  it { is_expected.to contain_notify('notify2') }

  # This expectation fails!
  it { is_expected.to contain_notify('notify2').that_requires(["Notify['notify1']"]) }

  # Even with an explicit cataloge compile, this expectation fails!
  it {
    is_expected.to compile

    is_expected.to contain_notify('notify2').that_requires(["Notify['notify1']"])
  }
  it {
    is_expected.to compile.with_all_deps

    is_expected.to contain_notify('notify2').that_requires(["Notify['notify1']"])
  }

  # ------------------------------------------- Using the custom Dummy type
  it { is_expected.to contain_dummy('Test') }

  # This expectation fails!
  # Also note that the '!!!!! Autorequire for Dummy Type called for the test below' is never output so
  # Autorequires is NEVER called
  it { is_expected.to contain_notify('Test').that_requires(["Notify['notify1']"]) }

  # Even with an explicit cataloge compile, this expectation fails!
  it {
    is_expected.to compile

    is_expected.to contain_notify('Test').that_requires(["Notify['notify1']"])
  }
  it {
    is_expected.to compile.with_all_deps

    is_expected.to contain_notify('Test').that_requires(["Notify['notify1']"])
  }
end
  • The explicit requires never appears in the catalogue
  • The implicit autorequire on the Dummy type never appears in the catalogue

Also, using a simple puts statement it can be shown that the autorequire method is never called during the ... .that_requires(...) matcher. It only gets called during the explicit compile call. This is due to the cyclical checks which converts the catalogue into a graph. This is where the requires and autorequires are evaluated (https://github.com/puppetlabs/puppet/blob/0ff9cf7ff3a96b14c677ccaec73d48465a18c9c9/lib/puppet/graph/relationship_graph.rb#L22-L32)

Looking at this, there's no way I can test explicit or implicit requires using rspec-puppet.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions