Puppet: System Administration Automated

Support

Ticket #695 (closed defect: fixed)

Opened 2 years ago

Last modified 1 year ago

Resource references get converted to strings in the database

Reported by: DavidS Assigned to: luke
Priority: normal Milestone: beaker
Component: library Version: 0.23.0
Severity: normal Keywords:
Cc: Triage Stage: Accepted
Attached Patches: None Complexity: Unknown

Description

I'm experiencing weird errors when collecting with current SVN:

info: /File/var/lib/puppet/modules/ntp/ntp.client.d/server_diode.black.co.at: Adding aliases "cf_part_server_diode.black.co.at" err: Could not create /var/lib/puppet/modules/ntp/ntp.client.d/server_diode.black.co.at: Parameter before failed: Relationships must be resource references at line 49 err: Parameter before failed: Relationships must be resource references at line 49

I have traced this error message to ./lib/puppet/metatype/metaparams.rb:109:

def store_relationship(param, values)
        ...
        unless values.is_a?(Array)
                devfail "Relationships must be resource references"  # #109

If I puts values before the devfail, "File/etc/ntp.puppet.conf" is printed. This is the dependency which is set on (the define containing) the failing resource.

The manifest in question looked like this:

define blah() { file { "muh": ...}  }

node a { @@blah{ "xx": before => File["/etc/ntp.puppet.conf"] } }

node b { File<<||>> }

Node b throws the error after node a was configured.

Regards, David

Change History

07/04/07 21:29:16 changed by luke

  • status changed from new to assigned.
  • stage changed from Unreviewed to Accepted.
  • milestone set to beaker.

The configuration storage step is converting resource references into strings for some reason. I thought I'd fixed all of these, but apparently not.

07/04/07 21:36:20 changed by luke

  • summary changed from err: Parameter before failed: Relationships must be resource references to Resource references get converted to strings in the database.

Retitling and marking #700 as a duplicate.

07/12/07 11:06:38 changed by DavidS

Here is a --trace from the error. Perhaps this helps.

err: Could not create chip.mariatreu.at: Parameter require failed: Relationships must be resource references at line 51
err: Parameter require failed: Relationships must be resource references at line 51
/home/david/trunk/lib/puppet/util/errors.rb:51:in `fail'
/home/david/trunk/lib/puppet/util/errors.rb:5:in `devfail'
/home/david/trunk/lib/puppet/metatype/metaparams.rb:101:in `store_relationship'
/home/david/trunk/lib/puppet/metatype/metaparams.rb:243:in `munge'
/home/david/trunk/lib/puppet/parameter.rb:454:in `value='
/home/david/trunk/lib/puppet/util/methodhelper.rb:16:in `send'
/home/david/trunk/lib/puppet/util/methodhelper.rb:16:in `set_options'
/home/david/trunk/lib/puppet/util/methodhelper.rb:13:in `each'
/home/david/trunk/lib/puppet/util/methodhelper.rb:13:in `set_options'
/home/david/trunk/lib/puppet/parameter.rb:297:in `initialize'
/home/david/trunk/lib/puppet/metatype/attributes.rb:576:in `new'
/home/david/trunk/lib/puppet/metatype/attributes.rb:576:in `newattr'
/home/david/trunk/lib/puppet/metatype/attributes.rb:512:in `[]='
/home/david/trunk/lib/puppet/type.rb:251:in `initialize'
/home/david/trunk/lib/puppet/type.rb:248:in `each'
/home/david/trunk/lib/puppet/type.rb:248:in `initialize'
/home/david/trunk/lib/puppet/metatype/instances.rb:165:in `new'
/home/david/trunk/lib/puppet/metatype/instances.rb:165:in `create'
/home/david/trunk/lib/puppet/transportable.rb:72:in `to_type'
/home/david/trunk/lib/puppet/transportable.rb:268:in `to_type'
/home/david/trunk/lib/puppet/transportable.rb:130:in `each'
/home/david/trunk/lib/puppet/transportable.rb:130:in `each'
/home/david/trunk/lib/puppet/transportable.rb:255:in `to_type'
/home/david/trunk/lib/puppet/transportable.rb:268:in `to_type'
/home/david/trunk/lib/puppet/transportable.rb:130:in `each'
/home/david/trunk/lib/puppet/transportable.rb:130:in `each'
/home/david/trunk/lib/puppet/transportable.rb:255:in `to_type'
/home/david/trunk/lib/puppet/transportable.rb:268:in `to_type'
/home/david/trunk/lib/puppet/transportable.rb:130:in `each'
/home/david/trunk/lib/puppet/transportable.rb:130:in `each'
/home/david/trunk/lib/puppet/transportable.rb:255:in `to_type'
/home/david/trunk/lib/puppet/transportable.rb:268:in `to_type'
/home/david/trunk/lib/puppet/transportable.rb:130:in `each'
/home/david/trunk/lib/puppet/transportable.rb:130:in `each'
/home/david/trunk/lib/puppet/transportable.rb:255:in `to_type'
/home/david/trunk/lib/puppet/transportable.rb:268:in `to_type'
/home/david/trunk/lib/puppet/transportable.rb:130:in `each'
/home/david/trunk/lib/puppet/transportable.rb:130:in `each'
/home/david/trunk/lib/puppet/transportable.rb:255:in `to_type'
/home/david/trunk/lib/puppet/network/client/master.rb:230:in `getconfig'
/home/david/trunk/lib/puppet/network/client/master.rb:308:in `run'
/home/david/trunk/lib/puppet/util.rb:419:in `thinmark'
/usr/lib/ruby/1.8/benchmark.rb:293:in `measure'
/usr/lib/ruby/1.8/benchmark.rb:307:in `realtime'
/home/david/trunk/lib/puppet/util.rb:418:in `thinmark'
/home/david/trunk/lib/puppet/network/client/master.rb:307:in `run'
/usr/lib/ruby/1.8/sync.rb:229:in `synchronize'
/home/david/trunk/lib/puppet/network/client/master.rb:300:in `run'
/home/david/trunk/bin/puppetd:426

The dependency is stored as Package[openssh-client] in the database as well as in the localconfig.yaml file, but should be stored as the array ['package', 'openssh-client'].

07/12/07 11:17:16 changed by DavidS

Interestingly enough, locally defined resources are stored in the database as Type[title] too. So this seems to be a problem when reading from the DBMS.

07/12/07 11:34:33 changed by DavidS

After playing with it a bit further, it seems like the current code cannot handle multiple dependencies at all:

This trace happens, when trying to collect a sshkey with require => [ Package["openssh-client"], Package["apt"] ] set:

/home/david/trunk/lib/puppet/rails/resource.rb:110:in `to_resource'
/usr/share/rails/activerecord/lib/active_record/associations/association_proxy.rb:123:in `each'
/usr/share/rails/activerecord/lib/active_record/associations/association_proxy.rb:123:in `send'
/usr/share/rails/activerecord/lib/active_record/associations/association_proxy.rb:123:in `method_missing'
/usr/share/rails/activerecord/lib/active_record/associations/has_many_through_association.rb:108:in `method_missing'
/home/david/trunk/lib/puppet/rails/resource.rb:109:in `to_resource'
/home/david/trunk/lib/puppet/parser/collector.rb:163:in `export_resource'
/home/david/trunk/lib/puppet/parser/collector.rb:39:in `collect_exported'
/home/david/trunk/lib/puppet/parser/collector.rb:36:in `each'
/home/david/trunk/lib/puppet/parser/collector.rb:36:in `collect_exported'
/home/david/trunk/lib/puppet/util.rb:419:in `thinmark'
/usr/lib/ruby/1.8/benchmark.rb:293:in `measure'
/usr/lib/ruby/1.8/benchmark.rb:307:in `realtime'
/home/david/trunk/lib/puppet/util.rb:418:in `thinmark'
/home/david/trunk/lib/puppet/parser/collector.rb:35:in `collect_exported'
/home/david/trunk/lib/puppet/parser/collector.rb:109:in `send'
/home/david/trunk/lib/puppet/parser/collector.rb:109:in `evaluate'
/home/david/trunk/lib/puppet/parser/interpreter.rb:126:in `evaliterate'
/home/david/trunk/lib/puppet/parser/interpreter.rb:123:in `each'
/home/david/trunk/lib/puppet/parser/interpreter.rb:123:in `evaliterate'
/home/david/trunk/lib/puppet/util/errors.rb:25:in `exceptwrap'
/home/david/trunk/lib/puppet/parser/interpreter.rb:122:in `evaliterate'
/home/david/trunk/lib/puppet/parser/interpreter.rb:117:in `loop'
/home/david/trunk/lib/puppet/parser/interpreter.rb:117:in `evaliterate'
/home/david/trunk/lib/puppet/parser/interpreter.rb:217:in `evaluate'
/home/david/trunk/lib/puppet/parser/interpreter.rb:764:in `run'
/home/david/trunk/lib/puppet/network/handler/master.rb:185:in `getconfig'
/home/david/trunk/lib/puppet/util.rb:212:in `benchmark'
/usr/lib/ruby/1.8/benchmark.rb:293:in `measure'
/usr/lib/ruby/1.8/benchmark.rb:307:in `realtime'
/home/david/trunk/lib/puppet/util.rb:211:in `benchmark'
/home/david/trunk/lib/puppet/network/handler/master.rb:183:in `getconfig'
/usr/share/rails/activerecord/lib/../../activesupport/lib/active_support/inflector.rb:250:in `to_proc'
/home/david/trunk/lib/puppet/network/xmlrpc/processor.rb:52:in `call'
/home/david/trunk/lib/puppet/network/xmlrpc/processor.rb:52:in `protect_service'
/home/david/trunk/lib/puppet/network/xmlrpc/processor.rb:85:in `setup_processor'
/usr/lib/ruby/1.8/xmlrpc/server.rb:336:in `call'
[...]
err: Parameter 'require' is already set on Sshkey[ic.black.co.at] by ssh::client; cannot redefine at line 51

This lead me to lib/puppet/rails/resource.rb:110, which fills an object with values from the database:

        self.param_names.each do |pname|
            obj.set(pname.to_resourceparam(self, scope.source))
        end

Following this to lib/puppet/rails/param_name.rb, I think I have found the culprit for the original problem: to_resourceparam doesn't create resource references out of the loaded strings.

07/12/07 12:11:55 changed by DavidS

Here is something that works at least for the single-dependency case:

Index: puppet/rails/param_name.rb
===================================================================
--- puppet/rails/param_name.rb  (revision 2680)
+++ puppet/rails/param_name.rb  (working copy)
@@ -10,6 +10,14 @@
         hash[:name] = self.name.to_sym
         hash[:source] = source
         hash[:value] = resource.param_values.find(:all, :conditions => [ "param_name_id = ?", self]).collect { |v| v.value }
+        # Resource references have to be parsed out here
+        hash[:value] = hash[:value].collect do |v|
+            if not (matches = v.match(/\A([[:upper:]][[:alpha:]_]*)\[(.*)\]\Z/)).nil?
+                # convert to array, someone else creates a real reference from that for us
+                v = [ matches[1].downcase, matches[2] ]
+            end
+            v
+        end
         if hash[:value].length == 1
             hash[:value] = hash[:value].shift
         end

Using this patch, I can collect exported resources with one dependency.

07/18/07 21:48:00 changed by luke

  • status changed from assigned to closed.
  • resolution set to fixed.

Fixed in [2706].