Age | Commit message (Collapse) | Author |
|
|
|
defined_with_params() now returns false for defined types, causing
duplicate resources when using ensure_resources().
Introduced by 4f19c27 in PE-20308.
|
|
|
|
- `defined_with_params` calls `findresource(reference.to_s)`
- `findresource` is
https://github.com/puppetlabs/puppet/blob/4.8.1/lib/puppet/parser/compiler.rb#L407
and points to
https://github.com/puppetlabs/puppet/blob/4.8.1/lib/puppet/resource/catalog.rb#L352
- This calls `Puppet::Resource.new` with the type
https://github.com/puppetlabs/puppet/blob/4.8.1/lib/puppet/resource/catalog.rb#L366
- This ends up calling `resource_type` via
https://github.com/puppetlabs/puppet/blob/4.8.1/lib/puppet/resource.rb#L317-L319
and that ends up declaring the type via the autoloader api at
https://github.com/puppetlabs/puppet/blob/4.8.1/lib/puppet/resource.rb#L390
- But why does the autoloader API fail to find it in the current
environment?
- Okay, so when the autoloader is trying to find the type, it uses the
typeloader to look it up in the current environment
https://github.com/puppetlabs/puppet/blob/4.8.1/lib/puppet/metatype/manager.rb#L171
- this calls `get_file` and `mark_loaded`
https://github.com/puppetlabs/puppet/blob/4.8.1/lib/puppet/util/autoload.rb#L64-L67
Suggested workaround is to pass a literal type instead of a string to
`findresource` to fix in stdlib, and also to fix loading/requiring of
type in core puppet.
This seems to affect more recent versions of puppet, so fallback to
original behavior on pre-4.5
|
|
|
|
|
|
As described in PUP-6422,
ensure_resources('File[/tmp/a]', { owner => undef })
would not actually create the file. This fixes it, and adds tests to prove
it.
|
|
Tests in the new style produces the following documentation output:
abs
should not eq nil
should run abs() and raise an Puppet::ParseError
should run abs(-34) and return 34
should run abs("-34") and return 34
should run abs(34) and return 34
should run abs("34") and return 34
|
|
This conversion is done by Transpec 2.2.1 with the following command:
transpec spec/functions
* 345 conversions
from: obj.should
to: expect(obj).to
* 122 conversions
from: == expected
to: eq(expected)
* 85 conversions
from: lambda { }.should
to: expect { }.to
* 22 conversions
from: be_true
to: be_truthy
* 16 conversions
from: be_false
to: be_falsey
* 11 conversions
from: pending
to: skip
* 9 conversions
from: it { should ... }
to: it { is_expected.to ... }
* 5 conversions
from: =~ [1, 2]
to: match_array([1, 2])
* 2 conversions
from: =~ /pattern/
to: match(/pattern/)
* 2 conversions
from: obj.should_not
to: expect(obj).not_to
For more details: https://github.com/yujinakayama/transpec#supported-conversions
|
|
rspec-puppet matchers are defined for tests which exist in
spec/functions, but the function unit tests lived in
spec/unit/puppet/parser/functions. This moves them to the correct place
for using rspec-puppet
|
|
|
|
This reverts commit 1e0983362464e8f2832239b09cdbc9175a51e6ec.
|
|
This reverts commit 42ddd7fe54f37b84e34b4a005de2249e53f07469, reversing
changes made to 53243605b28fc31618d079155c86b37b4e88a6ca.
|
|
This commit refactors to ensure 80 character lines.
|
|
This commit adds better handling of the case where
undef is passed as the parameter value.
This works by converting '' into []
|
|
This commit adds 2 new functions with unit tests.
defined_with_params works similarily to puppet's defined
function, except it allows you to also specify a hash of
params. defined_with_params will return true if a resource
also exists that matches the specified type/title (just like
with defined) as well as all of the specified params.
ensure_resource is a function that basically combines defined_with_params
with create_resources to conditionally create resources only if the
specified resource (title, type, params) does not already exist.
These functions are created to serve as an alternative to using
defined as follows:
if ! defined(Package['some_package']) {
package { 'some_package': ensure => present,
}
The issue with this usage is that there is no guarentee about
what parameters were set in the previous definition of the package
that made its way into the catalog.
ensure_resource could be used instead, as:
ensure_resource('package', 'some_package', { 'ensure' => 'present' })
This will creat the package resources only if another resource does
not exist with the specified parameters.
|