Project

General

Profile

Actions

Bug #14987

open

foreman_chef-0.3.1 fact_importer failed with IndexError: string not matched

Added by Sebastian Lehn almost 8 years ago. Updated almost 8 years ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
foreman_chef
Target version:
-
Difficulty:
Triaged:
Fixed in Releases:
Found in Releases:

Description

Facts import failed with following message:

2016-05-10T17:32:29 [app] [W] Action failed
 | IndexError: string not matched
 | /usr/share/foreman/vendor/ruby/2.1.0/gems/foreman_chef-0.3.1/app/models/forema
n_chef/fact_importer.rb:125:in `[]='
 | /usr/share/foreman/vendor/ruby/2.1.0/gems/foreman_chef-0.3.1/app/models/forema
n_chef/fact_importer.rb:125:in `block in unsparse'
 | /usr/share/foreman/vendor/ruby/2.1.0/gems/foreman_chef-0.3.1/app/models/forema
n_chef/fact_importer.rb:121:in `each'
 | /usr/share/foreman/vendor/ruby/2.1.0/gems/foreman_chef-0.3.1/app/models/forema
n_chef/fact_importer.rb:121:in `unsparse'
 | /usr/share/foreman/vendor/ruby/2.1.0/gems/foreman_chef-0.3.1/app/models/forema
n_chef/fact_importer.rb:27:in `add_new_facts'

After altering fact_importer.rb with (added logging):

    class Sparser
      def sparse(hash, options={})
        hash.map do |k, v|
          prefix = (options.fetch(:prefix, [])+[k])
          next sparse(v, options.merge(:prefix => prefix)) if v.is_a? Hash
          { prefix.join(options.fetch(:separator, FactName::SEPARATOR)) => v }
        end.reduce(:merge) || Hash.new
      end

      def logger
        Foreman::Logging.logger('foreman_chef')
      end

      def unsparse(hash, options={})
        ret = Hash.new
        sparse(hash).each do |k, v|
          current            = ret
          key                = k.to_s.split(options.fetch(:separator, FactName::SEPARATOR))
          current            = (current[key.shift] ||= Hash.new) until (key.size<=1)
          begin
                current[key.first] = v
          rescue IndexError
                logger.warn("IndexError occured")
          end
        end
        return ret
      end
    end

i got:


2016-05-10T17:43:02 [foreman_chef] [W] IndexError occured
2016-05-10T17:43:02 [foreman_chef] [W] IndexError occured
2016-05-10T17:43:02 [foreman_chef] [W] IndexError occured
2016-05-10T17:43:02 [foreman_chef] [W] IndexError occured
2016-05-10T17:43:57 [foreman_chef] [I] Import facts for...

My workaround with rescue was useful to me, because i got some of my facts reported which is better than nothing ;-)

Actions #1

Updated by Marek Hulán almost 8 years ago

Thanks for the detailed report, I haven't seen this error yet, sounds like facts structure might get corrupted somehow. Is there a chance that some of your attribute contains '::' in its value? Could you maybe add more debugging output to the logger, something like

logger.warn("IndexError occured on #{key.inspect} with value #{v.inspect}")

and if it's not sensitive information paste it here? I might incorporate this workaround anyway. If you're interested in contributing, you can send a patch through github pull-request. Instructions can be found at http://theforeman.org/contribute.html#Code-relatedcontributions (it's the same just for https://github.com/theforeman/foreman_chef repository)

Actions #2

Updated by Sebastian Lehn almost 8 years ago

I've changed the logging according your example and got following output:

2016-05-11T10:12:32 [foreman_chef] [W] IndexError occured on ["-security"] with value "true" 
2016-05-11T10:12:32 [foreman_chef] [W] IndexError occured on ["-updates"] with value "true" 
2016-05-11T10:12:32 [foreman_chef] [W] IndexError occured on ["-proposed"] with value "false" 
2016-05-11T10:12:32 [foreman_chef] [W] IndexError occured on ["-backports"] with value "false" 

I will have a look for related ohai facts and post them later.

Actions #3

Updated by Sebastian Lehn almost 8 years ago

I got more details with:

logger.warn("IndexError occured on #{key.inspect} with value #{v.inspect} from #{k.inspect}")

2016-05-11T12:30:42 [foreman_chef] [W] IndexError occured on ["-security"] with value "true" from "unattended-upgrades::allowed_origins::-security" 
2016-05-11T12:30:42 [foreman_chef] [W] IndexError occured on ["-updates"] with value "true" from "unattended-upgrades::allowed_origins::-updates" 
2016-05-11T12:30:42 [foreman_chef] [W] IndexError occured on ["-proposed"] with value "false" from "unattended-upgrades::allowed_origins::-proposed" 
2016-05-11T12:30:42 [foreman_chef] [W] IndexError occured on ["-backports"] with value "false" from "unattended-upgrades::allowed_origins::-backports" 

I hope that helps!

Actions #4

Updated by Marek Hulán almost 8 years ago

Thanks, that gives me some ideas, I'll try to reproduce locally. Note that we are not importing only ohai facts but all node attributes. This seems as chef-handler-foreman wrongly creates the structure.

Actions #5

Updated by Sebastian Lehn almost 8 years ago

Marek Hulán wrote:

Thanks, that gives me some ideas, I'll try to reproduce locally. Note that we are not importing only ohai facts but all node attributes. This seems as chef-handler-foreman wrongly creates the structure.

Ah.. okay. That explains why i wasn't able to find "-backports" in my ohai-output.

Actions

Also available in: Atom PDF