Metaparams break rake tests - how to avoid it ?

30 views
Skip to first unread message

Jakov Sosic

unread,
Oct 15, 2016, 8:18:45 AM10/15/16
to puppet-users
Is there a way to disable metaparam checks, so that it won't break CI
for my module?

I have something along these lines:

my/manifests/init.pp:
class my {
stage {'mystage': before => Stage['main'] }
}

my/manifests/conf.pp:
class my::conf (
$stage = 'mystage',
) {
...
}


So, when I run:

bundle exec rake validate

I get this:

---> syntax:manifests
stage is a metaparam; this value will inherit to all contained resources
in the my::conf definition
rake aborted!

...


Is there a way to avoid aborting tests in case metaparams are used?

Martin Alfke

unread,
Oct 22, 2016, 10:32:51 AM10/22/16
to puppet...@googlegroups.com
Hi Jakov,

> On 15 Oct 2016, at 05:18, Jakov Sosic <jso...@gmail.com> wrote:
>
> Is there a way to disable metaparam checks, so that it won't break CI for my module?
>
> I have something along these lines:
>
> my/manifests/init.pp:
> class my {
> stage {'mystage': before => Stage['main'] }
> }

This code is fine.
You just declare a stage resource type.
Except for: why do you want to make use of stages?
Stages have been introduced as a high level ordering concept which is no longer best practice.
You should use standard ordering instead (require, before, subscribe, notify or chaining pattern.

>
> my/manifests/conf.pp:
> class my::conf (
> $stage = 'mystage',
> ) {
> …
> }

As the syntax validation states:
“stage” is a metaparameter and a reserved word in Puppet.
Your code example shows a parameterized class with “stage” as a parameter.

Not think about the following declaration

class { ‘my::conf’:
stage => ‘foo’,
}

What should puppet now use?
The stage metaparameter which uses the declared stage resource type or the parameter from the class definition?

You should rename the parameter in the class definition to a non reserved word.
see: https://docs.puppet.com/puppet/latest/reference/lang_reserved.html

Best,
Martin


>
>
> So, when I run:
>
> bundle exec rake validate
>
> I get this:
>
> ---> syntax:manifests
> stage is a metaparam; this value will inherit to all contained resources in the my::conf definition
> rake aborted!
>
> ...
>
>
> Is there a way to avoid aborting tests in case metaparams are used?
>
> --
> You received this message because you are subscribed to the Google Groups "Puppet Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/232c216b-2573-8712-4c61-51d45751257a%40gmail.com.
> For more options, visit https://groups.google.com/d/optout.

Jakov Sosic

unread,
Oct 26, 2016, 8:36:16 PM10/26/16
to puppet...@googlegroups.com
On 10/22/2016 04:32 PM, Martin Alfke wrote:

> This code is fine.
> You just declare a stage resource type.
> Except for: why do you want to make use of stages?
> Stages have been introduced as a high level ordering concept which is no longer best practice.
> You should use standard ordering instead (require, before, subscribe, notify or chaining pattern.

I divided my manifests into two parts:

First part sets up yum and repositories (before main), and

second part sets up everything else.


This frees me from depending my modules on some specific yum repository,
and enables me to manage repositories separately from everything else.


>> my/manifests/conf.pp:
>> class my::conf (
>> $stage = 'mystage',
>> ) {
>> …
>> }
>
> As the syntax validation states:
> “stage” is a metaparameter and a reserved word in Puppet.
> Your code example shows a parameterized class with “stage” as a parameter.

What I tried to achieve with this is to run class in a stage, without
trying to define it in a resource-type definition...


> Not think about the following declaration
>
> class { ‘my::conf’:
> stage => ‘foo’,
> }
>
> What should puppet now use?

It should use 'foo' because params in class definition only define
"default" value...

Rob Nelson

unread,
Oct 26, 2016, 9:58:14 PM10/26/16
to puppet...@googlegroups.com
I believe what Martin was saying is, try `$stage_name` instead of `$stage` (or similar), because `$stage_name` would not be a reserved word/metaparameter name.
--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/30be6196-e183-63a4-8f00-d8404a7289ea%40gmail.com.

Martin Alfke

unread,
Oct 27, 2016, 2:04:01 AM10/27/16
to puppet...@googlegroups.com

> On 27 Oct 2016, at 02:35, Jakov Sosic <jso...@gmail.com> wrote:
>
> On 10/22/2016 04:32 PM, Martin Alfke wrote:
>
>> This code is fine.
>> You just declare a stage resource type.
>> Except for: why do you want to make use of stages?
>> Stages have been introduced as a high level ordering concept which is no longer best practice.
>> You should use standard ordering instead (require, before, subscribe, notify or chaining pattern.
>
> I divided my manifests into two parts:
>
> First part sets up yum and repositories (before main), and
>
> second part sets up everything else.
>
>
> This frees me from depending my modules on some specific yum repository, and enables me to manage repositories separately from everything else.

Are you aware of the collector and chaining?

Yumrepo <| tag == ‘myrepos_first’ |> -> Package <| tag == ‘mypackages_afterwards’ |>

This ensures that all yumrepos (with tag) are declared prior the package (with tag) gets managed.

>
>
>>> my/manifests/conf.pp:
>>> class my::conf (
>>> $stage = 'mystage',
>>> ) {
>>> …
>>> }
>>
>> As the syntax validation states:
>> “stage” is a metaparameter and a reserved word in Puppet.
>> Your code example shows a parameterized class with “stage” as a parameter.
>
> What I tried to achieve with this is to run class in a stage, without trying to define it in a resource-type definition…

AFAIK this is not possible.
stage is a metaparameter so you can not use it as a parameter in a class.
Attaching classes to a stage must be done via class declaration as resource type.

hth,
Martin


>
>
>> Not think about the following declaration
>>
>> class { ‘my::conf’:
>> stage => ‘foo’,
>> }
>>
>> What should puppet now use?
>
> It should use 'foo' because params in class definition only define "default" value...
>
> --
> You received this message because you are subscribed to the Google Groups "Puppet Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/30be6196-e183-63a4-8f00-d8404a7289ea%40gmail.com.
Reply all
Reply to author
Forward
0 new messages