Jira (PUP-10428) Puppet parser only consider first element of array for properties in custom provider

51 views
Skip to first unread message

Dan33l (Jira)

unread,
Apr 20, 2020, 9:51:04 AM4/20/20
to puppe...@googlegroups.com
Dan33l created an issue
 
Puppet / Bug PUP-10428
Puppet parser only consider first element of array for properties in custom provider
Issue Type: Bug Bug
Affects Versions: PUP 5.5.19
Assignee: Unassigned
Created: 2020/04/20 6:50 AM
Priority: Normal Normal
Reporter: Dan33l

Puppet Version: Tested with 5.5.19
Puppet Server Version: Without server, puppet apply
OS Name/Version: Ubuntu 1804

I am working on this custom provider : https://gitlab.adullact.net/adullact/puppet-nextcloud/-/blob/36-add-nextcloud_config-type-provider/lib/puppet/provider/nextcloud_config/php.rb

When the Puppet manifest have an Array as with setting  trusted_domains,  the setter receive the first element of the Array as a String and not an Array.

To reproduce you can run acceptance tests like here :

https://gitlab.adullact.net/adullact/puppet-nextcloud/-/blob/36-add-nextcloud_config-type-provider/spec/acceptance/nextcloud_spec.rb

Nextcloud is a PHP app. It requires a webserver and a database server before, like with spec helper acceptance : https://gitlab.adullact.net/adullact/puppet-nextcloud/-/blob/36-add-nextcloud_config-type-provider/spec/spec_helper_acceptance.rb

The module take care of PHP.

Desired Behavior:

Puppet take care of Array with following output :

Notice: /Stage[main]/Nextcloud::Config/Nextcloud_config[trusted_domains]/value: value changed ['localhost'] to 'localhost','[cloud.example.com

{{}}
Actual Behavior:

The Nextcloud's configuration is done in a config.php file like this one (have a look to setting trusted_domains that is array :

<?php
$CONFIG = array (
'passwordsalt' => 'XqxWppqWQ0/zMN/ur4wHn6SFTHhYLb',
'secret' => '+XEHiU8/1tfVkFL43QRepi5ev6i+vzU5jD3ZZjDd5MKuGEB8',
'trusted_domains' =>
array(
0 => 'localhost',
),
'datadirectory' => '/var/nextcloud-data',
'dbtype' => 'mysql',
'version' => '18.0.3.0',
'overwrite.cli.url' => 'http://localhost',
'dbname' => 'nextcloud_example',
'dbhost' => '127.0.0.1',
'dbport' => '',
'dbtableprefix' => 'oc_',
'mysql.utf8mb4' => true,
'dbuser' => 'user_example',
'dbpassword' => 'secret',
'installed' => true,
'instanceid' => 'ocrdo3b60mb3',
'memcache.local' => '\\OC\\Memcache
Redis',
'memcache.distributed' => '\\OC\\Memcache
Redis',
'memcache.locking' => '\\OC\\Memcache
Redis',
'filelocking.enabled' => 'true',
'redis' =>
array (
'host' => '127.0.0.1',
'port' => '6379',
'timeout' => '1.5',
),
'mail_smtpmode' => 'smtp',
'mail_smtphost' => 'smtp.example.com',
'mail_smtpport' => '425',
'mail_smtpsecure' => 'tls',
'mail_smtpauth' => 'true',
'mail_smtpauthtype' => 'LOGIN',
'mail_smtpname' => 'username',
'mail_smtppassword' => 'password',
);

The manifests is
class { 'nextcloud' :
database_name => 'nextcloud_example',
database_user => 'user_example',
database_password => 'secret',
system_user => 'www-data',
config =>

{ 'trusted_domains' => [ 'localhost', '[cloud.example.com|http://cloud.example.com/] ', ], }

}
The output when applyed is :

Notice: /Stage[main]/Nextcloud::Config/Nextcloud_config[trusted_domains]/value: value changed ['localhost'] to 'localhost'

 The expected output is :

Notice: /Stage[main]/Nextcloud::Config/Nextcloud_config[trusted_domains]/value: value changed ['localhost'] to 'localhost','[cloud.example.com
{{}}

 

Add Comment Add Comment
 
This message was sent by Atlassian Jira (v8.5.2#805002-sha1:a66f935)
Atlassian logo

Dan33l (Jira)

unread,
Apr 20, 2020, 10:05:03 AM4/20/20
to puppe...@googlegroups.com
Dan33l updated an issue
Change By: Dan33l
*Puppet Version: Tested with 5.5.19*
*Puppet Server Version: Without server, puppet apply*
*OS Name/Version: Ubuntu 1804*


I am working on this custom provider : [https://gitlab.adullact.net/adullact/puppet-nextcloud/-/blob/36-add-nextcloud_config-type-provider/lib/puppet/provider/nextcloud_config/php.rb]

When the Puppet manifest have an Array as with setting  trusted_domains,  the setter receive the first element of the Array as a String and not an Array.

To reproduce you can run acceptance tests like here :

[https://gitlab.adullact.net/adullact/puppet-nextcloud/-/blob/36-add-nextcloud_config-type-provider/spec/acceptance/nextcloud_spec.rb]

Nextcloud is a PHP app. It requires a webserver and a database server before, like with spec helper acceptance : [https://gitlab.adullact.net/adullact/puppet-nextcloud/-/blob/36-add-nextcloud_config-type-provider/spec/spec_helper_acceptance.rb]

The module take care of PHP.

*Desired Behavior:*


Puppet take care of Array with following output :
{quote}{{Notice: /Stage[main]/Nextcloud::Config/Nextcloud_config[trusted_domains]/value: value changed ['localhost'] to ['localhost','[cloud.example.com|http://cloud.example.com/]']}}
{quote}
{{}}
*Actual Behavior:*


The Nextcloud's configuration is done in a config.php file like this one (have a look to setting trusted_domains that is array :
{quote}<?php
\\
{quote}

The manifests is
      class { 'nextcloud' :
        database_name     => 'nextcloud_example',
        database_user     => 'user_example',
        database_password => 'secret',
        system_user       => 'www-data',
        config            =>
{

{
          'trusted_domains'   => [
            'localhost',
            '[cloud.example.com|http://cloud.example.com/]
',
          ],
        }

      }
The output when applyed is :
{quote}{{Notice: /Stage[main]/Nextcloud::Config/Nextcloud_config[trusted_domains]/value: value changed ['localhost'] to 'localhost'}}
{quote}
 The expected output is :
{quote}{{Notice: /Stage[main]/Nextcloud::Config/Nextcloud_config[trusted_domains]/value: value changed ['localhost'] to ['localhost','[cloud.example.com|http://cloud.example.com/]']}}
\ {{}}
{quote}
 
With pry :
{quote}From: /etc/puppetlabs/code/modules/nextcloud/lib/puppet/provider/nextcloud_config/php.rb:78 php#value=:

77: def value=(val)
=> 78: binding.pry
79: set_config_system(resource[:name], val)
80: end

[1] pry(#<Puppet::Type::Nextcloud_config::ProviderPhp>)> val
=> "localhost"
[2] pry(#<Puppet::Type::Nextcloud_config::ProviderPhp>)> val.class
=> String
{quote}

Dan33l (Jira)

unread,
Apr 20, 2020, 10:06:04 AM4/20/20
to puppe...@googlegroups.com

Dan33l (Jira)

unread,
Apr 20, 2020, 10:09:03 AM4/20/20
to puppe...@googlegroups.com
The manifests is to reproduce (apply helper before) :
{quote}
class { 'nextcloud' :
database_name => 'nextcloud_example',
database_user => 'user_example',
database_password => 'secret',
system_user => 'www-data',
config =>

  { 'trusted_domains' =>

   
[

     
'localhost',

     
' [ cloud.example.com |http://cloud.example.com/] ',

   
],

 
}

}
{quote}

The output when applyed is :
{quote}{{Notice: /Stage[main]/Nextcloud::Config/Nextcloud_config[trusted_domains]/value: value changed ['localhost'] to 'localhost'}}
{quote}
 The expected output is :
{quote}{{Notice: /Stage[main]/Nextcloud::Config/Nextcloud_config[trusted_domains]/value: value changed ['localhost'] to [['localhost','cloud.example.com']|http://cloud.example.com/]
'] }}
\ { {}}
{
quote}
 With pry :
{quote}From: /etc/puppetlabs/code/modules/nextcloud/lib/puppet/provider/nextcloud_config/php.rb:78 php#value=:

77: def value=(val)
=> 78: binding.pry
79: set_config_system(resource[:name], val)
80: end

[1] pry(#<Puppet::Type::Nextcloud_config::ProviderPhp>)> val
=> "localhost"
[2] pry(#<Puppet::Type::Nextcloud_config::ProviderPhp>)> val.class
=> String
{quote}

Dan33l (Jira)

unread,
Apr 20, 2020, 10:10:03 AM4/20/20
to puppe...@googlegroups.com
The manifests to reproduce (apply helper before) :
{quote}

class { 'nextcloud' :
database_name => 'nextcloud_example',
database_user => 'user_example',
database_password => 'secret',
system_user => 'www-data',
config =>


 
{ 'trusted_domains' =>

    [

      'localhost',

      'cloud.example.com',

    ],

  }

}
{quote}

The output when applyed is :
{quote}{{Notice: /Stage[main]/Nextcloud::Config/Nextcloud_config[trusted_domains]/value: value changed ['localhost'] to 'localhost'}}
{quote}
 The expected output is :
{quote}{{Notice: /Stage[main]/Nextcloud::Config/Nextcloud_config[trusted_domains]/value: value changed ['localhost'] to [['localhost','cloud.example.com']|http://cloud.example.com/]}}
{quote}
 With pry :
{quote}From: /etc/puppetlabs/code/modules/nextcloud/lib/puppet/provider/nextcloud_config/php.rb:78 php#value=:

77: def value=(val)
=> 78: binding.pry
79: set_config_system(resource[:name], val)
80: end

[1] pry(#<Puppet::Type::Nextcloud_config::ProviderPhp>)> val
=> "localhost"
[2] pry(#<Puppet::Type::Nextcloud_config::ProviderPhp>)> val.class
=> String
{quote}

Dan33l (Jira)

unread,
Apr 20, 2020, 10:13:04 AM4/20/20
to puppe...@googlegroups.com

Dan33l (Jira)

unread,
Apr 20, 2020, 10:14:03 AM4/20/20
to puppe...@googlegroups.com
Dan33l updated an issue
<?php
'version' => '18 See attached file . 0.3.0',

Unknown macro: \
{ 'trusted_domains' =>     [       'localhost',       'cloud.example.com',     ],   }

}
{quote}
The output when applyed is :
{quote}{{Notice: /Stage[main]/Nextcloud::Config/Nextcloud_config[trusted_domains]/value: value changed ['localhost'] to 'localhost'}}
{quote}
 The expected output is :
{quote}{{Notice: /Stage[main]/Nextcloud::Config/Nextcloud_config[trusted_domains]/value: value changed ['localhost'] to [['localhost','cloud.example.com']|http://cloud.example.com/]}}
{quote}
 With pry :
{quote}From: /etc/puppetlabs/code/modules/nextcloud/lib/puppet/provider/nextcloud_config/php.rb:78 php#value=:

77: def value=(val)
=> 78: binding.pry
79: set_config_system(resource[:name], val)
80: end

[1] pry(#<Puppet::Type::Nextcloud_config::ProviderPhp>)> val
=> "localhost"
[2] pry(#<Puppet::Type::Nextcloud_config::ProviderPhp>)> val.class
=> String
{quote}

Dan33l (Jira)

unread,
Apr 20, 2020, 10:23:05 AM4/20/20
to puppe...@googlegroups.com
Dan33l updated an issue
*Puppet Version: Tested with 5.5.19*
*Puppet Server Version: Without server, puppet apply*
*OS Name/Version: Ubuntu 1804*

I am working on this custom provider : [https://gitlab.adullact.net/adullact/puppet-nextcloud/-/blob/36-add-nextcloud_config-type-provider/lib/puppet/provider/nextcloud_config/php.rb]

When the Puppet manifest have an Array as with setting  trusted_domains,  the setter receive the first element of the Array as a String and not an Array.

To reproduce you can run acceptance tests like here :

[https://gitlab.adullact.net/adullact/puppet-nextcloud/-/blob/36-add-nextcloud_config-type-provider/spec/acceptance/nextcloud_spec.rb]

Nextcloud is a PHP app. It requires a webserver and a database server before, like with spec helper acceptance : [https://gitlab.adullact.net/adullact/puppet-nextcloud/-/blob/36-add-nextcloud_config-type-provider/spec/spec_helper_acceptance.rb]

The module take care of PHP.

*Desired Behavior:*

Puppet take care of Array with following output :
{quote}{{Notice: /Stage[main]/Nextcloud::Config/Nextcloud_config[trusted_domains]/value: value changed ['localhost'] to [['localhost','cloud.example.com']|http://cloud.example.com/]}}
{quote}
*Actual Behavior:*

The Nextcloud's configuration is done in a config.php file like this one (have a look to setting trusted_domains that is array :
{quote}See attached file.

{quote}
The manifests to reproduce (apply helper before) :
{quote} class See attached file { 'nextcloud' :
quote}

Dan33l (Jira)

unread,
Apr 20, 2020, 10:23:05 AM4/20/20
to puppe...@googlegroups.com
Dan33l updated an issue
Change By: Dan33l
Attachment: apply_1_helper.pp
Attachment: apply_2_module.pp

Dan33l (Jira)

unread,
Apr 20, 2020, 11:33:03 AM4/20/20
to puppe...@googlegroups.com

Dan33l (Jira)

unread,
Apr 20, 2020, 11:34:03 AM4/20/20
to puppe...@googlegroups.com
Dan33l updated an issue
*Puppet Version: Tested with 5.5.19 , 6.14.0 *

*Puppet Server Version: Without server, puppet apply*
*OS Name/Version: Ubuntu 1804*

I am working on this custom provider : [https://gitlab.adullact.net/adullact/puppet-nextcloud/-/blob/36-add-nextcloud_config-type-provider/lib/puppet/provider/nextcloud_config/php.rb]

When the Puppet manifest have an Array as with setting  trusted_domains,  the setter receive the first element of the Array as a String and not an Array.

To reproduce you can run acceptance tests like here :

[https://gitlab.adullact.net/adullact/puppet-nextcloud/-/blob/36-add-nextcloud_config-type-provider/spec/acceptance/nextcloud_spec.rb]

Nextcloud is a PHP app. It requires a webserver and a database server before, like with spec helper acceptance : [https://gitlab.adullact.net/adullact/puppet-nextcloud/-/blob/36-add-nextcloud_config-type-provider/spec/spec_helper_acceptance.rb]

The module take care of PHP.

*Desired Behavior:*

Puppet take care of Array with following output :
{quote}{{Notice: /Stage[main]/Nextcloud::Config/Nextcloud_config[trusted_domains]/value: value changed ['localhost'] to [['localhost','cloud.example.com']|http://cloud.example.com/]}}
{quote}
*Actual Behavior:*

The Nextcloud's configuration is done in a config.php file like this one (have a look to setting trusted_domains that is array :
{quote}See attached file.
{quote}
The manifests to reproduce (apply helper before) :
{quote}See attached file
{quote}

The output when applyed is :
{quote}{{Notice: /Stage[main]/Nextcloud::Config/Nextcloud_config[trusted_domains]/value: value changed ['localhost'] to 'localhost'}}
{quote}
 The expected output is :
{quote}{{Notice: /Stage[main]/Nextcloud::Config/Nextcloud_config[trusted_domains]/value: value changed ['localhost'] to [['localhost','cloud.example.com']|http://cloud.example.com/]}}
{quote}
 With pry :
{quote}From: /etc/puppetlabs/code/modules/nextcloud/lib/puppet/provider/nextcloud_config/php.rb:78 php#value=:

77: def value=(val)
=> 78: binding.pry
79: set_config_system(resource[:name], val)
80: end

[1] pry(#<Puppet::Type::Nextcloud_config::ProviderPhp>)> val
=> "localhost"
[2] pry(#<Puppet::Type::Nextcloud_config::ProviderPhp>)> val.class
=> String
{quote}

Rob Braden (Jira)

unread,
Apr 20, 2020, 1:48:03 PM4/20/20
to puppe...@googlegroups.com
Rob Braden commented on Bug PUP-10428
 
Re: Puppet parser only consider first element of array for properties in custom provider

Hi Dan33l, I think in your type you have to declare that you are using an Array. Look at the members property of the Group type for an example.

Josh Cooper (Jira)

unread,
Apr 20, 2020, 2:15:03 PM4/20/20
to puppe...@googlegroups.com
Josh Cooper commented on Bug PUP-10428

Yeah you have to pass :array_matching => :all in the options hash to the newproperty DSL method in order for it to be multi-valued. You might also want to look at the resource API https://puppet.com/docs/puppet/latest/about_the_resource_api.html

Dan33l (Jira)

unread,
Apr 20, 2020, 3:53:03 PM4/20/20
to puppe...@googlegroups.com
Dan33l commented on Bug PUP-10428

When array_matching, all settings are considered as an Array. But only one setting is an Array (trusted_domains). Others are String or Hash. So it does not look possible to use array_matching .

I confirmed this buy testing the suggested solution.  It breaks the config.php file.

Josh Cooper (Jira)

unread,
Apr 20, 2020, 4:58:03 PM4/20/20
to puppe...@googlegroups.com
Josh Cooper commented on Bug PUP-10428

Ah I didn't realize you were trying to declare a generic property and then "pass thru" values. Puppet's newproperty method isn't designed for that really. It's intended to be used a specific type of property. I'd double-recommend the resource API in that case. David Schmitt may have thoughts about this.

Dan33l (Jira)

unread,
Apr 20, 2020, 5:28:03 PM4/20/20
to puppe...@googlegroups.com
Dan33l commented on Bug PUP-10428

I know that exists resource API.  I already said to doc team and David that i need something like was done in the chapter 3 of the Book written by Nan Liu and Dan Bod.

But the documentation is too short and so sibylline 

Dan33l (Jira)

unread,
Apr 21, 2020, 2:58:02 AM4/21/20
to puppe...@googlegroups.com
Dan33l commented on Bug PUP-10428

Question : Is it possible to forge a generic property with resource API ?

David Schmitt (Jira)

unread,
Apr 21, 2020, 10:33:09 AM4/21/20
to puppe...@googlegroups.com

To answer the question for the Resource API side, I've enhanced the tests in https://github.com/puppetlabs/puppet-resource_api/pull/269 to show that even with an Any-typed attribute, the handling of array-valued arguments works.

Given the complexity of interactions between Resource API and the low-level APIs, I can't say that the behaviour shown in the tests gives any indication for what should or would be happening in a manual implementation of the low-level API.

Dan33l as I already said on slack yesterday, I'm happy to answer specific questions there, and if they're recurring question I'll also make sure the answers get integrated into the existing docs, and that's all I can currently promise given staffing levels and company priorities.

Dan33l (Jira)

unread,
Apr 21, 2020, 11:12:11 AM4/21/20
to puppe...@googlegroups.com

Dan33l (Jira)

unread,
Apr 21, 2020, 11:36:06 AM4/21/20
to puppe...@googlegroups.com
Dan33l commented on Bug PUP-10428
 
Re: Puppet parser only consider first element of array for properties in custom provider

So it is not a bug, just using the function newproperty in a way unexpected. This issue can be closed.

Josh Cooper (Jira)

unread,
Apr 28, 2020, 11:52:05 AM4/28/20
to puppe...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages