<commit_before># Copyright (c) 2009-2011 RightScale, Inc, All Rights Reserved Worldwide.
#
# THIS PROGRAM IS CONFIDENTIAL AND PROPRIETARY TO RIGHTSCALE
# AND CONSTITUTES A VALUABLE TRADE SECRET.  Any unauthorized use,
# reproduction, modification, or disclosure of this program is
# strictly prohibited.  Any use of this program by an authorized
# licensee is strictly subject to the terms and conditions,
# including confidentiality obligations, set forth in the applicable
# License Agreement between RightScale.com, Inc. and
# the licensee.

require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'scripts', 'reenroller'))

module RightScale
  describe Reenroller do
    def run_reenroller(argv)
      replace_argv(argv)
      subject.run(subject.parse_args)
      return 0
    rescue SystemExit => e
      return e.status
    end

    def reenroll(resume=false)
      if RightScale::Platform::windows?
        flexmock(subject).should_receive(:cleanup_certificates).once
        flexmock(File).should_receive(:open).with(Reenroller::STATE_FILE, "w", Proc).once
        flexmock(subject).should_receive(:system).with('net start RightScale')
      else
        flexmock(subject).should_receive(:system).with('/opt/rightscale/sandbox/bin/monit -c /opt/rightscale/etc/monitrc stop checker').once
        flexmock(subject).should_receive(:system).with('/opt/rightscale/sandbox/bin/monit -c /opt/rightscale/etc/monitrc stop instance').once
        flexmock(subject).should_receive(:system).with('/opt/rightscale/sandbox/bin/monit -c /opt/rightscale/etc/monitrc quit').once
        flexmock(subject).should_receive(:cleanup_certificates).once
        if resume
          flexmock(subject).should_receive(:system).with("/etc/init.d/rightlink resume > /dev/null").once
        else
          flexmock(subject).should_receive(:system).with("/etc/init.d/rightlink start > /dev/null").once
        end
      end
      run_reenroller(resume ? '--resume': [])
    end

    before(:all) do
      # preserve old ARGV for posterity (although it's unlikely that anything
      # would consume it after startup).
      @old_argv = ARGV
    end

    after(:all) do
      # restore old ARGV
      replace_argv(@old_argv)
      @error = nil
      @output = nil<commit_msg>fix rs_reenroll spec hang on CI<commit_after># Copyright (c) 2009-2011 RightScale, Inc, All Rights Reserved Worldwide.
#
# THIS PROGRAM IS CONFIDENTIAL AND PROPRIETARY TO RIGHTSCALE
# AND CONSTITUTES A VALUABLE TRADE SECRET.  Any unauthorized use,
# reproduction, modification, or disclosure of this program is
# strictly prohibited.  Any use of this program by an authorized
# licensee is strictly subject to the terms and conditions,
# including confidentiality obligations, set forth in the applicable
# License Agreement between RightScale.com, Inc. and
# the licensee.

require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'scripts', 'reenroller'))

module RightScale
  describe Reenroller do
    def run_reenroller(argv)
      replace_argv(argv)
      subject.run(subject.parse_args)
      return 0
    rescue SystemExit => e
      return e.status
    end

    def reenroll(resume=false)
      if RightScale::Platform::windows?
        flexmock(subject).should_receive(:cleanup_certificates).once
        flexmock(File).should_receive(:open).with(Reenroller::STATE_FILE, "w", Proc).once
        flexmock(subject).should_receive(:system).with('net start RightScale')
      else
        flexmock(subject).should_receive(:process_running?).and_return(false)
        flexmock(subject).should_receive(:system).with('/opt/rightscale/sandbox/bin/monit -c /opt/rightscale/etc/monitrc stop checker').once
        flexmock(subject).should_receive(:system).with('/opt/rightscale/sandbox/bin/monit -c /opt/rightscale/etc/monitrc stop instance').once
        flexmock(subject).should_receive(:system).with('/opt/rightscale/sandbox/bin/monit -c /opt/rightscale/etc/monitrc quit').once
        flexmock(subject).should_receive(:cleanup_certificates).once
        if resume
          flexmock(subject).should_receive(:system).with("/etc/init.d/rightlink resume > /dev/null").once
        else
          flexmock(subject).should_receive(:system).with("/etc/init.d/rightlink start > /dev/null").once
        end
      end
      run_reenroller(resume ? '--resume': [])
    end

    before(:all) do
      # preserve old ARGV for posterity (although it's unlikely that anything
      # would consume it after startup).
      @old_argv = ARGV
    end

    after(:all) do
      # restore old ARGV
      replace_argv(@old_argv)
      @error = nil
      @output = nil
{'fraction_non_alphanumeric': 0.1137974155898291, 'fraction_numerical': 0.003751563151313047, 'mean_word_length': 3.6367149758454107, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '948640', 'n_tokens_mistral': 1455, 'n_tokens_neox': 1385, 'n_words': 335}