Jira (PUP-10784) Augeas don't handle Deferred values

6 views
Skip to first unread message

Frank (Jira)

unread,
Nov 17, 2020, 6:09:03 AM11/17/20
to puppe...@googlegroups.com
Frank created an issue
 
Puppet / Bug PUP-10784
Augeas don't handle Deferred values
Issue Type: Bug Bug
Assignee: Unassigned
Components: Functions
Created: 2020/11/17 3:08 AM
Priority: Critical Critical
Reporter: Frank

Puppet Version: puppet-agent-6.19.1-1.el7.x86_64
Puppet Server Version: puppetserver-6.14.1-1.el7.noarch
OS Name/Version: CentOS 7.9

The augeas module don't handle Deferred values correct.

Desired Behavior: That the value of the deferred function in inserted.

Actual Behavior: Not the value, but the text ''Deferred({" is inserted.

sample:

$db_host = Deferred(load_file,[$db_host_file])
$db_name = Deferred(load_file,[$db_name_file])
$settings = [
  "set session-factory/property[#attribute/name='hibernate.connection.url']/#text 'jdbc:postgresql://${db_host}/${db_name}'"
]
augeas { 'sql':
 lens => 'Xml.lns',
 incl => "/usr/share/tomcat9/webapps/xwiki/WEB-INF/hibernate.cfg.xml",
 context => "/files/usr/share/tomcat9/webapps/xwiki/WEB-INF/hibernate.cfg.xml/hibernate-configuration",
 changes => $settings,
 require => ...,
 notify => ...
 }

The used function in Deferred itself will work, because using it for ini_setting it will work there.

 

 

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

Josh Cooper (Jira)

unread,
Nov 17, 2020, 7:02:04 PM11/17/20
to puppe...@googlegroups.com
Josh Cooper commented on Bug PUP-10784
 
Re: Augeas don't handle Deferred values

Frank the interpolation also needs to be deferred for that to work. One way to handle that is call inline_epp as a deferred function, using variables that are also deferred:

$variables = {
  'db_host' => Deferred(load_file,[$db_host_file]),
  'db_name' => Deferred(load_file,[$db_name_file])
}
augeas { 'sql':
  ...
  changes => Deferred('inline_epp', ["set session-factory/property[#attribute/name='hibernate.connection.url']/#text 'jdbc:postgresql://<%= \$db_host %>/<%= \$db_name %>'", $variables])
}

The quoting starts to become complicated (note I had to escape $db_host), so it's better to put that in an EPP template.

Frank (Jira)

unread,
Nov 18, 2020, 4:45:01 AM11/18/20
to puppe...@googlegroups.com
Frank commented on Bug PUP-10784

Hi Josh,

yes will work, but that augeas muss be called many times, because changes of augeas needs an array.

  $con_data = {
    'host'     => Deferred(load_file,[$db_host_file]),
    'name'     => Deferred(load_file,[$db_name_file]),
    'user'     => Deferred(load_file,[$db_user_file]),
    'password' => Sensitive(Deferred(load_file,[$db_password_file]))
  }
  $settings = [
    "set session-factory/property[#attribute/name='hibernate.connection.driver_class']/#text 'org.postgresql.Driver'",
    "set session-factory/property[#attribute/name='hibernate.dialect']/#attribute/name 'hibernate.dialect'",
    "set session-factory/property[#attribute/name='hibernate.dialect']/#text 'org.hibernate.dialect.PostgreSQLDialect'",
    "set session-factory/property[#attribute/name='hibernate.jdbc.use_streams_for_binary']/#attribute/name 'hibernate.jdbc.use_streams_for_binary'",
    "set session-factory/property[#attribute/name='hibernate.jdbc.use_streams_for_binary']/#text 'false'",
    "set session-factory/property[#attribute/name='xwiki.virtual_mode']/#attribute/name 'xwiki.virtual_mode'",
    "set session-factory/property[#attribute/name='xwiki.virtual_mode']/#text 'schema'",
    "rm session-factory/mapping[#attribute/resource='xwiki.hbm.xml']",
    "set session-factory/mapping[#attribute/resource='xwiki.postgresql.hbm.xml']/#attribute/resource 'xwiki.postgresql.hbm.xml'",
  ]
$augeags_default = {
    lens    => 'Xml.lns',
    incl    => "/usr/share/tomcat9/webapps/xwiki/WEB-INF/hibernate.cfg.xml",
    context => "/files/usr/share/tomcat9/webapps/xwiki/WEB-INF/hibernate.cfg.xml/hibernate-configuration",
    require => ...,
    notify  => ..,
  }
  $external_settings = [
    "set session-factory/property[#attribute/name='hibernate.connection.url']/#text 'jdbc:postgresql://<%= \$host %>/<%= \$name %>'",
    "set session-factory/property[#attribute/name='hibernate.connection.username']/#text '<%= \$user %>'",
    "set session-factory/property[#attribute/name='hibernate.connection.password']/#text '<%= unwrap(\$password) %>'"
  ]
  augeas { 'sql':
    changes => $settings,
    *       => $augeags_default
  }
  $external_settings.each |String $s| {
    augeas { $s:
      changes   => Deferred('inline_epp',[$s, $con_data]),
      show_diff => false,
      *         => $augeags_default
    }
  }

 

Reply all
Reply to author
Forward
0 new messages