lib/chef-workflow/support/vm/knife.rb
#
# Checks that the nodes have made it into the search index. Will block until
# all nodes in this server group are found, or a 60 second timeout is
# reached, at which point it will raise.
#
Checks that the nodes have made it into the search index. Will block until
all nodes in this server group are found, or a 60 second timeout is
reached, at which point it will raise.
Checks that the nodes have made it into the search index . Will block until all nodes in this server group are found or a 60 second timeout is reached at which point it will raise .
def check_nodes
    q = Chef::Search::Query.new
    unchecked_node_names = @node_names.dup
    search_query = run_list.
      map { |s| s.gsub(/\[/, 's:"').gsub(/\]/, '"') }.
      join(" AND ")
    Timeout.timeout(60) do
      until unchecked_node_names.empty?
        node_name = unchecked_node_names.shift
        if_debug(3) do
          $stderr.puts "Checking search validity for node #{node_name}"
        end
        result = q.search(
          :node, 
          search_query + %Q[ AND name:"#{node_name}"]
        ).first
        unless result and result.count == 1 and result.first.name == node_name
          unchecked_node_names << node_name
        end
        sleep 0.3
      end
    end
    return true
  rescue Timeout::Error
    raise "Bootstrapped nodes for #{name} did not appear in Chef search index after 60 seconds."
  end
def check_nodes q = Chef :: Search :: Query . new unchecked_node_names = @node_names . dup search_query = run_list . map { | s | s . gsub ( / \[ / , 's:"' ) . gsub ( / \] / , '"' ) } . join ( " AND " ) Timeout . timeout ( 60 ) do until unchecked_node_names . empty? node_name = unchecked_node_names . shift if_debug ( 3 ) do $stderr . puts "Checking search validity for node #{node_name}" end result = q . search ( :node , search_query + %Q[ AND name:"#{node_name}"] ) . first unless result and result . count == 1 and result . first . name == node_name unchecked_node_names << node_name end sleep 0.3 end end return true rescue Timeout :: Error raise "Bootstrapped nodes for #{name} did not appear in Chef search index after 60 seconds." end
Checks that the nodes have made it into the search index.
Checks that the nodes have made it into the search index .
# this dirty hack turns 'role[foo]' into 'roles:foo', but also works on # recipe[] too. Then joins the whole thing with AND # unfortunately if this isn't here you might as well issue kill -9 to the # rake process