Jira (PUP-11167) Provider redhat must have features 'maskable' to set 'enable' to 'mask' during rspec-puppet testing

19 views
Skip to first unread message

Alexander Fisher (Jira)

unread,
Jul 9, 2021, 11:53:01 AM7/9/21
to puppe...@googlegroups.com
Alexander Fisher created an issue
 
Puppet / Bug PUP-11167
Provider redhat must have features 'maskable' to set 'enable' to 'mask' during rspec-puppet testing
Issue Type: Bug Bug
Affects Versions: PUP 7.8.0, PUP 6.23.0
Assignee: Unassigned
Created: 2021/07/09 8:52 AM
Priority: Normal Normal
Reporter: Alexander Fisher

Puppet Version: 6.23.0
Puppet Server Version: N/A
OS Name/Version:

After the release of Puppet 6.23.0 I've had to modify my manifests to workaround an issue affecting testing with rspec-puppet.

In my testing environment (a jenkins agent in an unprivileged docker container), the following code (intended for RHEL7 running systemd)

 

 if versioncmp($facts['operatingsystemmajrelease'], '7') >= 0 {
   service { 'mcollective':
     ensure => 'stopped',
     enable => 'mask',
   }
 }

has started throwing

Provider redhat must have features 'maskable' to set 'enable' to 'mask'

due to the changes made in https://github.com/puppetlabs/puppet/commit/8d6c5ba92076babba07a42d8f82c9e6f86f8ef8b

This line https://github.com/puppetlabs/puppet/blob/aa1df95ab3c8ee5bd8f007ba45cca422b1de2498/lib/puppet/provider/service/systemd.rb#L14

is executed to help determine the default service provider. During rspec-puppet testing this code is being executed on the test environment platform, which may or may not be detected as systemd. (In my case, it isn't because I'm in a docker container, but equally the default service provider of eg. Mac OS is also not systemd).

Not sure what the solution to this could be.  The new validation code isn't 'wrong', but rspec-puppet wants to test code against various OSes by using stubbed facts.  Since the systemd service provider is confined based on the actual presence of systemd and not facts, this no longer works.

 

 

Add Comment Add Comment
 
This message was sent by Atlassian Jira (v8.13.2#813002-sha1:c495a97)
Atlassian logo

Jake Spain (Jira)

unread,
Aug 27, 2021, 11:16:03 PM8/27/21
to puppe...@googlegroups.com
Jake Spain commented on Bug PUP-11167
 
Re: Provider redhat must have features 'maskable' to set 'enable' to 'mask' during rspec-puppet testing

FWIW, I ran across this issue as well when using onceover with a control-repo, which leverages rspec-puppet, and was able to resolve it by mocking the service type (restricted to the RedHat osfamily for my use case) with the maskable feature enable like:

Puppet::Type.type(:service).defaultprovider.has_feature :maskable if node_facts['osfamily'] == 'RedHat'

 

I added the above to the "before" block as described in https://github.com/dylanratcliffe/onceover#advanced-settings

 

  • Jake

Ciprian Badescu (Jira)

unread,
Sep 21, 2021, 6:22:03 AM9/21/21
to puppe...@googlegroups.com

Steve Traylen (Jira)

unread,
Oct 11, 2021, 7:35:03 AM10/11/21
to puppe...@googlegroups.com

Ciprian Badescu (Jira)

unread,
Oct 11, 2021, 7:44:02 AM10/11/21
to puppe...@googlegroups.com

Steve Traylen, can you provide more info on the case where the mocks from this and the linked tickets are not enough?

Jarret Lavallee (Jira)

unread,
Nov 18, 2021, 1:41:02 PM11/18/21
to puppe...@googlegroups.com

The method Jake posted above also worked for me. You can also add the lines below to a before block to mock the filesystem calls for /proc/1/comm. You could add these for OSes with systemd with some conditional statements.

  allow(Puppet::FileSystem).to receive(:exist?).and_call_original
  allow(Puppet::FileSystem).to receive(:exist?).with('/proc/1/comm').and_return(true)
  allow(Puppet::FileSystem).to receive(:read).and_call_original
  allow(Puppet::FileSystem).to receive(:read).with('/proc/1/comm').and_return(['systemd'])

If you use custom fact sets with the service_provider fact from [puppetlabs-stdlib|https://github.com/puppetlabs/puppetlabs-stdlib/blob/main/lib/facter/service_provider.rb,] you could use node_facts['service_provider'] in the conditional statement.

Reply all
Reply to author
Forward
0 new messages