Force a rspec-puppet recompile

Back to Listing

Hanover, MD, 04 June 2018


I was recently testing some puppet code that required a modification to the server_facts inbuilt variables.

This led me to discover that the puppet catalog is not recompiled at each run of compile.

WORKAROUND

Unfortunately, even switching context scopes did not force a catalog recompile. The only way to do this is apparently to modify the parameters that are passed into the class in order to invalidate the cache.

The following code provides an example of what would need to be done to trigger a full recompile.

Puppet Class Under Test

class test (
  Boolean $param1 = true,
  Boolean $param2 = true
) {
  notify { 'testing': }
}

RSpec Code

describe 'test' do
  # The first full compile
  it { is_expected.to compile.with_all_deps }

  context 'with no changes' do
    # This will not recompile
    it { is_expected.to compile.with_all_deps }
  end

  context 'repeating the default params' do
    let(:params) do
      {
        :param1 => true,
        :param2 => true
      }
    end

    # This will not recompile
    it { is_expected.to compile.with_all_deps }
  end

  context 'with one param changed' do
    let(:params) do
      {
        :param1 => false
      }
    end

    # This WILL recompile
    it { is_expected.to compile.with_all_deps }
  end

end

At this time, it only takes a single parameter change to force a cache invalidation and hopefully there will be a way to explicitly invalidate the cache in the future.

Trevor has worked in a variety of IT fields over the last decade, including systems engineering, operating system automation, security engineering, and various levels of development.

At OP his responsibilities include maintaining overall technical oversight for Onyx Point solutions, providing technical leadership and mentorship to the DevOps teams. He is also responsible for leading OP’s solutions and intellectual property development efforts, setting the technical focus of the company, and managing OP products and related services. In this regard, he oversees product development and delivery as well as developing the strategic roadmap for OP’s product line.

At Onyx Point, our engineers focus on Security, System Administration, Automation, Dataflow, and DevOps consulting for government and commercial clients. We offer professional services for Puppet, RedHat, SIMP, NiFi, GitLab, and the other solutions in place that keep your systems running securely and efficiently. We offer Open Source Software support and Engineering and Consulting services through GSA IT Schedule 70. As Open Source contributors and advocates, we encourage the use of FOSS products in Government as part of an overarching IT Efficiencies plan to reduce ongoing IT expenditures attributed to software licensing. Our support and contributions to Open Source, are just one of our many guiding principles

  • Customer First.
  • Security in All We Do.
  • Pursue Innovation with Integrity.
  • Communicate Openly and Respectfully.
  • Offer Your Talents, and Appreciate the Talents of Others

Onyx Point™, SIMP™, SIMP Enterprise Edition™, SIMP EE™, SIMP Compliance Engine™, and SIMP +SUPPORT™ are trademarks of Onyx Point, Inc. All other company and product names mentioned are used only for identification purposes and may be trademarks or registered trademarks of their respective companies.

puppet, testing, rspec-puppet, programming

Share this story

We work with these Technologies + Partners

puppet
gitlab
simp
beaker
redhat
`
AFCEA
GitHub
FOSSFeb