New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cluster resource : possible bug in running_nodes method #285

Closed
alexpop opened this Issue Jul 14, 2015 · 1 comment

Comments

Projects
None yet
2 participants
@alexpop
Contributor

alexpop commented Jul 14, 2015

I suspect a bug in the running_nodes method since #274.
If cluster_status returns only one running node, running_nodes throws this exception:

Recipe: rabbitmq::cluster
  * rabbitmq_cluster[[{"name":"rabbit@host-1.example.com","type":"disc"},{"name":"rabbit@host-2.example.com","type":"ram"}]] action join

    ================================================================================
    Error executing action `join` on resource 'rabbitmq_cluster[[{"name":"rabbit@host-1.example.com","type":"disc"},{"name":"rabbit@host-2.example.com","type":"ram"}]]'
    ================================================================================

    NoMethodError
    -------------
    undefined method `split' for nil:NilClass

    Cookbook Trace:
    ---------------
    /var/chef/cache/cookbooks/rabbitmq/providers/cluster.rb:83:in `running_nodes'
    /var/chef/cache/cookbooks/rabbitmq/providers/cluster.rb:138:in `joined_cluster?'
    /var/chef/cache/cookbooks/rabbitmq/providers/cluster.rb:201:in `block in class_from_file'

    Resource Declaration:
    ---------------------
    # In /var/chef/cache/cookbooks/rabbitmq/recipes/cluster.rb

     31:     rabbitmq_cluster cluster_nodes do
     32:       action :join
     33:     end
     34:   end

My test node runlist:

    "recipe[rabbitmq::default]",
    "recipe[rabbitmq::user_management]",
    "recipe[rabbitmq::cluster]",
    "recipe[rabbitmq::mgmt_console]"

My masked attributes:

  "override_attributes": {
     "rabbitmq": {
       "version": "3.4.4",
       "default_user": "aaaaaaaa",
       "default_pass": "bbbbbbbb",
       "enabled_users":[{"name":"ccccccccccc","password":"dddddddddd","rights":[{"vhost":null,"conf":".*","write":".*","read":".*"}]}],
       "cluster": true,
       "erlang_cookie": "EEEEEEEEEEEEEEEEEEE",
       "additional_env_settings": ["RABBITMQ_USE_LONGNAME=true"],
       "clustering": {
         "cluster_name": "test1",
         "use_auto_clustering": false,
         "cluster_nodes":[{"name":"rabbit@host-1.example.com","type":"disc"},{"name":"rabbit@host-2.example.com","type":"ram"}]
       }
     }

The exception is caused by gsub!(/'/, '') returning nil if no quotes are found in the match variable.
Based on the chef-shell output, I believe this line:

result = match && match.gsub!(/'/, '').split(',')

with:

result = match && match.gsub(/'/, '')

chef-shell output:

chef (12.4.1)> pattern = '({running_nodes,\[\'*)(.*?)(\'*\]})'
 => "({running_nodes,\\['*)(.*?)('*\\]})" 
chef (12.4.1)>   match = match_pattern_cluster_status(cluster_status, pattern)
 => "rabbit@host-1.example.com" 
chef (12.4.1)> result = match && match.gsub!(/'/, '').split(',')
NoMethodError: undefined method `split' for nil:NilClass
  from (irb):40
  from /opt/chef/embedded/apps/chef/lib/chef/shell.rb:76:in `block in start'
  from /opt/chef/embedded/apps/chef/lib/chef/shell.rb:75:in `catch'
  from /opt/chef/embedded/apps/chef/lib/chef/shell.rb:75:in `start'
  from /opt/chef/embedded/apps/chef/bin/chef-shell:37:in `<top (required)>'
  from /usr/bin/chef-shell:55:in `load'
  from /usr/bin/chef-shell:55:in `<main>'
chef (12.4.1)> match = match_pattern_cluster_status(cluster_status, pattern)
 => "rabbit@host-1.example.com" 
chef (12.4.1)> result = match && match.gsub!(/'/, '')
 => nil 
chef (12.4.1)> match = match_pattern_cluster_status(cluster_status, pattern)
 => "rabbit@host-1.example.com" 
chef (12.4.1)> result = match && match.gsub(/'/, '')
 => "rabbit@host-1.example.com" 
chef (12.4.1)>   Chef::Log.debug("[rabbitmq_cluster] running_nodes : #{result}")
 => [#<Logger:0x000000056fc840 @progname=nil, @level=2, @default_formatter=#<Logger::Formatter:0x000000056fc7c8 @datetime_format=nil>, @formatter=#<Mixlib::Log::Formatter:0x000000056fc638 @datetime_format=nil>, @logdev=#<Logger::LogDevice:0x000000056fc728 @shift_size=nil, @shift_age=nil, @filename=nil, @dev=#<IO:<STDERR>>, @mutex=#<Logger::LogDevice::LogDeviceMutex:0x000000056fc700 @mon_owner=nil, @mon_count=0, @mon_mutex=#<Mutex:0x000000056fc660>>>>] 
chef (12.4.1)>   !result.nil? ? result.split(',') : []
 => ["rabbit@host-1.example.com"]

PR in progress...

@alexpop

This comment has been minimized.

Show comment
Hide comment
@alexpop

alexpop Jul 14, 2015

Contributor

Also fixed by PR #284

Contributor

alexpop commented Jul 14, 2015

Also fixed by PR #284

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment