<commit_before>require 'pushy_client'
require 'timeout'

shared_context "end_to_end_util" do
  SLEEP_TIME = 0.2

  def echo_yahoo
    'sh ' + File.expand_path('../../support/echo_yahoo_to_tmp_pushytest', __FILE__)
  end

  # Method to start up a new client that will be reaped when
  # the test finishes
  def start_new_clients(*names)
    @clients = {} if !@clients
    names.each do |name|
      raise "Client #{name} already created" if @clients[name]
      @clients[name] = {
        :states => []
      }
    end

    start_clients(*names)
  end

  def start_client(name)
    start_clients(name)
  end

  def start_clients(*names)
    names.each do |name|
      raise "Client #{name} already started" if @clients[name][:client]

      # Delete chef client if it exists
      delete(api_url("/clients/#{name}"), admin_user)

      # Create chef client and save key for pushy client
      response = post(api_url("/clients"), superuser, :payload => {"name" => name})
      key = parse(response)["private_key"]

      @clients[name][:key_file] = file = Tempfile.new([name, '.pem'])
      key_path = file.path

      file.write(key)
      file.flush

      # Create pushy client
      new_client = PushyClient.new(
        :chef_server_url => "#{Pedant.config[:chef_server]}/organizations/#{org}",
        :client_key      => key_path,
        :node_name       => name,
        :whitelist       => {
          echo_yahoo => echo_yahoo,
          'chef-client' => {
            :command_line => 'echo true',
            :lock => true
          },
          'ruby -e "ENV[\'PUSHY_NODE_NAME\'] == \'DONKEY\' ? exit(1) : exit(0)"' => 'ruby -e "ENV[\'PUSHY_NODE_NAME\'] == \'DONKEY\' ? exit(1) : exit(0)"',
          'ruby -e "exit 1"' => 'ruby -e "exit 1"',
          'sleep 1' => 'sleep 1',
          'sleep 2' => 'sleep 2',
          'sleep 5' => 'sleep 3',
          'sleep 10' => 'sleep 10',
          'sleep 20' => 'sleep 20',
          'this_oughta_succeed' => 'echo true',
          'this_oughta_fail' => 'ruby -e "exit 1"'
        }
      )<commit_msg>Work with new opscode-pushy-client :hostname parameter<commit_after>require 'pushy_client'
require 'timeout'

shared_context "end_to_end_util" do
  SLEEP_TIME = 0.2

  def echo_yahoo
    'sh ' + File.expand_path('../../support/echo_yahoo_to_tmp_pushytest', __FILE__)
  end

  # Method to start up a new client that will be reaped when
  # the test finishes
  def start_new_clients(*names)
    @clients = {} if !@clients
    names.each do |name|
      raise "Client #{name} already created" if @clients[name]
      @clients[name] = {
        :states => []
      }
    end

    start_clients(*names)
  end

  def start_client(name)
    start_clients(name)
  end

  def start_clients(*names)
    names.each do |name|
      raise "Client #{name} already started" if @clients[name][:client]

      # Delete chef client if it exists
      delete(api_url("/clients/#{name}"), admin_user)

      # Create chef client and save key for pushy client
      response = post(api_url("/clients"), superuser, :payload => {"name" => name})
      key = parse(response)["private_key"]

      @clients[name][:key_file] = file = Tempfile.new([name, '.pem'])
      key_path = file.path

      file.write(key)
      file.flush

      # Create pushy client
      new_client = PushyClient.new(
        :chef_server_url => "#{Pedant.config[:chef_server]}/organizations/#{org}",
        :client_key      => key_path,
        :node_name       => name,
        :hostname        => name,
        :whitelist       => {
          echo_yahoo => echo_yahoo,
          'chef-client' => {
            :command_line => 'echo true',
            :lock => true
          },
          'ruby -e "ENV[\'PUSHY_NODE_NAME\'] == \'DONKEY\' ? exit(1) : exit(0)"' => 'ruby -e "ENV[\'PUSHY_NODE_NAME\'] == \'DONKEY\' ? exit(1) : exit(0)"',
          'ruby -e "exit 1"' => 'ruby -e "exit 1"',
          'sleep 1' => 'sleep 1',
          'sleep 2' => 'sleep 2',
          'sleep 5' => 'sleep 3',
          'sleep 10' => 'sleep 10',
          'sleep 20' => 'sleep 20',
          'this_oughta_succeed' => 'echo true',
          'this_oughta_fail' => 'ruby -e "exit 1"'
        }
      )
{'fraction_non_alphanumeric': 0.15254237288135594, 'fraction_numerical': 0.01098114108379088, 'mean_word_length': 2.3201267828843104, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 44, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1884470', 'n_tokens_mistral': 1485, 'n_tokens_neox': 1396, 'n_words': 341}