diff --git a/.travis.yml b/.travis.yml index 4d8ad7587..05c1a4a31 100644 --- a/.travis.yml +++ b/.travis.yml @@ -35,6 +35,8 @@ matrix: env: RUN_RUBY=true RUN_SCALA=false GEM_NAME=collins-client - jdk: oraclejdk7 env: RUN_RUBY=true RUN_SCALA=false GEM_NAME=collins-state + - jdk: oraclejdk7 + env: RUN_RUBY=true RUN_SCALA=false GEM_NAME=consolr script: - if $RUN_SCALA; then activator-1.3.4-minimal/activator test; fi - if $RUN_RUBY; then cd support/ruby/$GEM_NAME; bundle install --path ./vendor/bundle; bundle exec rake; fi diff --git a/support/ruby/consolr/.gitignore b/support/ruby/consolr/.gitignore new file mode 100644 index 000000000..404abb221 --- /dev/null +++ b/support/ruby/consolr/.gitignore @@ -0,0 +1 @@ +coverage/ diff --git a/support/ruby/consolr/.rspec b/support/ruby/consolr/.rspec new file mode 100644 index 000000000..16f9cdb01 --- /dev/null +++ b/support/ruby/consolr/.rspec @@ -0,0 +1,2 @@ +--color +--format documentation diff --git a/support/ruby/consolr/.versions.conf b/support/ruby/consolr/.versions.conf new file mode 100644 index 000000000..20408990f --- /dev/null +++ b/support/ruby/consolr/.versions.conf @@ -0,0 +1,4 @@ +ruby=ruby-2.2.1 +ruby-gemset=consolr +#ruby-gem-install=bundler rake +#ruby-bundle-install=true diff --git a/support/ruby/consolr/Rakefile b/support/ruby/consolr/Rakefile new file mode 100644 index 000000000..73d7aec3f --- /dev/null +++ b/support/ruby/consolr/Rakefile @@ -0,0 +1,8 @@ +require 'rspec/core' +require 'rspec/core/rake_task' +RSpec::Core::RakeTask.new(:spec) do |spec| + spec.fail_on_error = true + spec.pattern = FileList['spec/**/*_spec.rb'] +end + +task :default => :spec diff --git a/support/ruby/consolr/bin/consolr b/support/ruby/consolr/bin/consolr index 30d322650..f0a72234f 100755 --- a/support/ruby/consolr/bin/consolr +++ b/support/ruby/consolr/bin/consolr @@ -1,6 +1,31 @@ #!/usr/bin/env ruby require 'consolr' +require 'consolr/version' + +options = {} +opt_parser = OptionParser.new do |opt| + opt.banner = 'Usage: consolr [OPTIONS]' + opt.separator '' + opt.separator 'Options' + + opt.on('-c', '--console', 'console into node via SOL') { options[:console] = true } + opt.on('-d', '--dangerous', 'list dangerous stuff') { options[:dangerous] = true } + opt.on('-f', '--force', 'force run dangerous actions') { options[:force] = true } + opt.on('-H', '--hostname ASSET', 'asset hostname') { |hostname| options[:hostname] = hostname } + opt.on('-i', '--identify', 'turn on chassis UID') { options[:identify] = true } + opt.on('-k', '--kick', 'kick if someone is hogging the console') { options[:kick] = true } + opt.on('-l', '--log LOG', 'System Event Log (SEL) [list|clear]') { |log| options[:log] = log } + opt.on('-o', '--on', 'turn on node') { options[:on] = true } + opt.on('-r', '--reboot', 'restart node') { options[:reboot] = true } + opt.on('-s', '--sdr', 'Sensor Data Repository (SDR)') { options[:sdr] = true } + opt.on('-t', '--tag ASSET', 'asset tag') { |tag| options[:tag] = tag } + opt.on('-x', '--off', 'turn off node') { options[:off] = true } + + opt.on_tail('-h', '--help', 'help') { puts opt; exit 0 } + opt.on_tail('-v', '--version', 'version') { puts Consolr::VERSION; exit 0 } +end +opt_parser.parse! console = Consolr::Console.new -console.start +console.start options diff --git a/support/ruby/consolr/consolr.gemspec b/support/ruby/consolr/consolr.gemspec index 3ed8078cc..64d65df2b 100644 --- a/support/ruby/consolr/consolr.gemspec +++ b/support/ruby/consolr/consolr.gemspec @@ -19,4 +19,10 @@ Gem::Specification.new do |spec| spec.require_paths = ["lib"] spec.add_runtime_dependency "collins_auth", "~> 0.1.2" + spec.add_runtime_dependency "net-ping", "~> 1.7.7" + + spec.add_development_dependency "rake", "~> 10.4.2" + spec.add_development_dependency "rspec", "~> 3.3.0" + spec.add_development_dependency "simplecov", "~> 0.10.0" + spec.add_development_dependency "webmock", "~> 1.21.0" end diff --git a/support/ruby/consolr/lib/consolr.rb b/support/ruby/consolr/lib/consolr.rb index d8919b6f4..329ff5856 100755 --- a/support/ruby/consolr/lib/consolr.rb +++ b/support/ruby/consolr/lib/consolr.rb @@ -1,9 +1,10 @@ $LOAD_PATH.unshift('./lib/') +require 'consolr/version' require 'collins_auth' +require 'net/ping' require 'optparse' require 'yaml' -require 'consolr/version' module Consolr class Console @@ -35,7 +36,7 @@ def initialize puts "------" exit 1 end - + begin @ipmitool_exec = config_params['ipmitool'] # ipmitool absolute path rescue Exception => e @@ -45,7 +46,7 @@ def initialize puts "-------" exit 1 end - + # Will be ignored for dangerous actions, no matter what, even with --force begin @dangerous_assets = config_params['dangerous_assets'] @@ -72,50 +73,22 @@ def initialize end @dangerous_actions = [:off, :reboot] # Must match the symbol in options{} - - @options = {} - @opt_parser = OptionParser.new do |opt| - opt.banner = 'Usage: consolr [OPTIONS]' - opt.separator '' - opt.separator 'Options' - - opt.on('-c', '--console', 'console into node via SOL') { options[:console] = true } - opt.on('-d', '--dangerous', 'list dangerous stuff') { options[:dangerous] = true } - opt.on('-f', '--force', 'force run dangerous actions') { options[:force] = true } - opt.on('-H', '--hostname ASSET', 'asset hostname') { |hostname| options[:hostname] = hostname } - opt.on('-i', '--identify', 'turn on chassis UID') { options[:identify] = true } - opt.on('-k', '--kick', 'kick if someone is hogging the console') { options[:kick] = true } - opt.on('-l', '--log LOG', 'System Event Log (SEL) [list|clear]') { |log| options[:log] = log } - opt.on('-o', '--on', 'turn on node') { options[:on] = true } - opt.on('-r', '--reboot', 'restart node') { options[:reboot] = true } - opt.on('-s', '--sdr', 'Sensor Data Repository (SDR)') { options[:sdr] = true } - opt.on('-t', '--tag ASSET', 'asset tag') { |tag| options[:tag] = tag } - opt.on('-x', '--off', 'turn off node') { options[:off] = true } - opt.on_tail('-h', '--help', 'help') { puts opt; exit 0 } - opt.on_tail('-v', '--version', 'version') { puts Consolr::VERSION; exit 0 } - end - end - - def ipmitool_cmd action - system("#{@ipmitool_exec} -I lanplus -H #{@node.ipmi.address} -U #{@node.ipmi.username} -P #{@node.ipmi.password} #{action}") - return $?.exitstatus == 0 ? "SUCCESS" : "FAILED" end - def start - @opt_parser.parse! # extract from ARGV[] + def start options abort("Please pass either the asset tag or hostname") if options[:tag].nil? and options[:hostname].nil? - + abort("Cannot find #{@ipmitool_exec}") unless File.exist?(@ipmitool_exec) dangerous_body = "Dangerous actions: #{dangerous_actions.join(', ')}\n"\ "Dangerous status: #{dangerous_status.join(', ')} (override with --force)\n"\ "Dangerous assets: #{dangerous_assets.join(', ')} (ignored no matter what, even with --force)" - + if options[:dangerous] puts dangerous_body exit 1 end - + begin collins = Collins::Authenticator.setup_client rescue Exception => e @@ -125,25 +98,24 @@ def start puts "-------" exit 1 end - + if options[:tag] and options[:hostname] abort("Please pass either the hostname OR the tag but not both.") end - + # match assets like vm-67f5eh, zt-*, etc. nodes = options[:tag] ? (collins.find :tag => options[:tag]) : (collins.find :hostname => options[:hostname]) @node = nodes.length == 1 ? nodes.first : abort("Found #{nodes.length} assets, aborting.") - - %x(/bin/ping -c 1 #{@node.ipmi.address}) - abort("Cannot ping IP #{@node.ipmi.address} (#{@node.tag})") unless $?.exitstatus == 0 - - if dangerous_assets.include?(@node.tag) and dangerous_actions.any? - puts "Asset #{@node.tag} is a crucial asset. Can't execute dangerous actions on this asset." + + abort("Cannot ping IP #{@node.ipmi.address} (#{@node.tag})") unless Net::Ping::External.new(@node.ipmi.address).ping? + + selected_dangerous_actions = dangerous_actions.select { |o| options[o] } + if dangerous_assets.include?(@node.tag) and selected_dangerous_actions.any? + abort "Asset #{@node.tag} is a crucial asset. Can't ever execute dangerous actions on this asset.\n#{dangerous_body}" end - - if options[:force].nil? and dangerous_actions.any? and dangerous_status.include?(@node.status) - puts "Cannot run dangerous commands on #{@node.hostname} (#{@node.tag} - #{@node.status})" - abort dangerous_body + + if options[:force].nil? and selected_dangerous_actions.any? and dangerous_status.include?(@node.status) + abort "Cannot run dangerous commands on #{@node.hostname} (#{@node.tag} - #{@node.status}) because it is in a protected status. This can be overridden with the --force flag\n#{dangerous_body}" end case @@ -171,12 +143,18 @@ def start raise OptionParser::MissingArgument, "specify an action" rescue OptionParser::MissingArgument => e puts e - puts @opt_parser - exit 0 + exit 1 end end end + private + + def ipmitool_cmd action + system("#{@ipmitool_exec} -I lanplus -H #{@node.ipmi.address} -U #{@node.ipmi.username} -P #{@node.ipmi.password} #{action}") + return $?.exitstatus == 0 ? "SUCCESS" : "FAILED" + end + end end diff --git a/support/ruby/consolr/lib/consolr/version.rb b/support/ruby/consolr/lib/consolr/version.rb index f3b3e49db..da5e04f56 100644 --- a/support/ruby/consolr/lib/consolr/version.rb +++ b/support/ruby/consolr/lib/consolr/version.rb @@ -1,3 +1,3 @@ module Consolr - VERSION = "1.0.1" + VERSION = "1.0.2" end diff --git a/support/ruby/consolr/spec/configs/collins_rspec.yml b/support/ruby/consolr/spec/configs/collins_rspec.yml new file mode 100644 index 000000000..0ddcceb58 --- /dev/null +++ b/support/ruby/consolr/spec/configs/collins_rspec.yml @@ -0,0 +1,4 @@ +host: https://collins.example.net +username: "collins_user" +password: "collins_pass" +timeout: 30 diff --git a/support/ruby/consolr/spec/configs/consolr_rspec.yml b/support/ruby/consolr/spec/configs/consolr_rspec.yml new file mode 100644 index 000000000..3688295fa --- /dev/null +++ b/support/ruby/consolr/spec/configs/consolr_rspec.yml @@ -0,0 +1,7 @@ +# this is a dummy config for the unit tests +ipmitool: spec/rspec_ipmi +dangerous_assets: + - "dangerous-allocated-tag" + - "dangerous-maintenance-tag" +dangerous_status: + - "Allocated" diff --git a/support/ruby/consolr/spec/consolr_spec.rb b/support/ruby/consolr/spec/consolr_spec.rb new file mode 100644 index 000000000..188368d47 --- /dev/null +++ b/support/ruby/consolr/spec/consolr_spec.rb @@ -0,0 +1,133 @@ +require 'spec_helper' + +describe Consolr::Console do + + before (:each) do + @console = Consolr::Console.new + end + + it 'fails if no hostname is provided' do + expect { @console.start( {:hostname => nil}) }.to raise_error(SystemExit, /asset tag or hostname/) + end + + it 'fails if both tag and hostname are passed' do + expect { @console.start({:hostname => 'host.dc.net', :tag => '001234' }) }.to raise_error(SystemExit, /not both/) + end + + it 'fails if tag cannot be found' do + expect { @console.start({:tag => 'bogus_tag'}) }.to raise_error(SystemExit, /Found 0 assets/) + end + + it 'fails if hostname cannot be found' do + expect { @console.start({:hostname => 'bogus_hostname'}) }.to raise_error(SystemExit, /Found 0 assets/) + end + + it 'fails if multiple hosts are found' do + expect { @console.start({:hostname => 'hostname-with-multiple-assets.dc.net'}) }.to raise_error(SystemExit, /Found \d+ assets/) + end + + safe_boolean_actions = {:console => "--> Opening SOL session (type ~~. to quit)\nsol activate", :kick => 'sol deactivate', :identify => 'chassis identify', :sdr => 'sdr elist all', :on => 'power on'} + dangerous_boolean_actions = {:off => 'power off', :reboot => 'power cycle'} + + describe 'safe allocated asset' do + safe_allocated_tag = 'safe-allocated-tag' + safe_boolean_actions.each do |action, response| + it "does #{action}" do + expect { @console.start({:tag => safe_allocated_tag, action => true}) }.to output("#{response}\nSUCCESS\n").to_stdout_from_any_process + end + end + + dangerous_boolean_actions.each do |action, response| + it "refuses to do dangerous action #{action}" do + expect { @console.start({:tag => safe_allocated_tag, action => true}) }.to raise_error(SystemExit, /Cannot run dangerous command/) + end + it "can force dangerous action #{action}" do + expect { @console.start({:tag => safe_allocated_tag, action => true, :force => true}) }.to output("#{response}\nSUCCESS\n").to_stdout_from_any_process + end + end + + it 'does log list' do + expect { @console.start({:tag => safe_allocated_tag, :log => 'list'}) }.to output("sel list\nSUCCESS\n").to_stdout_from_any_process + end + + it 'does log clear' do + expect { @console.start({:tag => safe_allocated_tag, :log => 'clear'}) }.to output("sel clear\nSUCCESS\n").to_stdout_from_any_process + end + end + + describe 'safe maintenance asset' do + safe_maintenance_tag= 'safe-maintenance-tag' + safe_boolean_actions.each do |action, response| + it "does #{action}" do + expect { @console.start({:tag => safe_maintenance_tag, action => true}) }.to output("#{response}\nSUCCESS\n").to_stdout_from_any_process + end + end + + dangerous_boolean_actions.each do |action, response| + it "does dangerous action #{action}" do + expect { @console.start({:tag => safe_maintenance_tag, action => true, :force => true}) }.to output("#{response}\nSUCCESS\n").to_stdout_from_any_process + end + end + + it 'does log list' do + expect { @console.start({:tag => safe_maintenance_tag, :log => 'list'}) }.to output("sel list\nSUCCESS\n").to_stdout_from_any_process + end + + it 'does log clear' do + expect { @console.start({:tag => safe_maintenance_tag, :log => 'clear'}) }.to output("sel clear\nSUCCESS\n").to_stdout_from_any_process + end + end + + describe 'dangerous allocated asset' do + dangerous_allocated_tag= 'dangerous-allocated-tag' + safe_boolean_actions.each do |action, response| + it "does #{action}" do + expect { @console.start({:tag => dangerous_allocated_tag, action => true}) }.to output("#{response}\nSUCCESS\n").to_stdout_from_any_process + end + end + + dangerous_boolean_actions.each do |action, response| + it "refuses to do dangerous action #{action}" do + expect { @console.start({:tag => dangerous_allocated_tag, action => true}) }.to raise_error(SystemExit, /Asset .* is a crucial asset/) + end + it "refuses to do dangerous action #{action} with force" do + expect { @console.start({:tag => dangerous_allocated_tag, action => true, :force => true}) }.to raise_error(SystemExit, /Asset .* is a crucial asset/) + end + end + + it 'does log list' do + expect { @console.start({:tag => dangerous_allocated_tag, :log => 'list'}) }.to output("sel list\nSUCCESS\n").to_stdout_from_any_process + end + + it 'does log clear' do + expect { @console.start({:tag => dangerous_allocated_tag, :log => 'clear'}) }.to output("sel clear\nSUCCESS\n").to_stdout_from_any_process + end + end + + describe 'dangerous maintenance asset' do + dangerous_maintenance_tag= 'dangerous-maintenance-tag' + safe_boolean_actions.each do |action, response| + it "does #{action}" do + expect { @console.start({:tag => dangerous_maintenance_tag, action => true}) }.to output("#{response}\nSUCCESS\n").to_stdout_from_any_process + end + end + + dangerous_boolean_actions.each do |action, response| + it "refuses to do dangerous action #{action}" do + expect { @console.start({:tag => dangerous_maintenance_tag, action => true}) }.to raise_error(SystemExit, /Asset .* is a crucial asset/) + end + it "refuses to do dangerous action #{action} with force" do + expect { @console.start({:tag => dangerous_maintenance_tag, action => true, :force=> true}) }.to raise_error(SystemExit, /Asset .* is a crucial asset/) + end + + end + + it 'does log list' do + expect { @console.start({:tag => dangerous_maintenance_tag, :log => 'list'}) }.to output("sel list\nSUCCESS\n").to_stdout_from_any_process + end + + it 'does log clear' do + expect { @console.start({:tag => dangerous_maintenance_tag, :log => 'clear'}) }.to output("sel clear\nSUCCESS\n").to_stdout_from_any_process + end + end +end diff --git a/support/ruby/consolr/spec/fixtures/assets/dangerous-allocated-tag.yml b/support/ruby/consolr/spec/fixtures/assets/dangerous-allocated-tag.yml new file mode 100644 index 000000000..2f16dfe4a --- /dev/null +++ b/support/ruby/consolr/spec/fixtures/assets/dangerous-allocated-tag.yml @@ -0,0 +1,24 @@ +--- !ruby/object:Collins::Asset +extras: + ATTRIBS: + '0': + HOSTNAME: web-dc0ce734.ewr01.tumblr.net +id: 1 +status: Allocated +tag: dangerous-allocated-tag +type: SERVER_NODE +state: !ruby/object:Collins::AssetState + description: A service in this state is operational. + id: 3 + label: Running + name: RUNNING + status: !ruby/object:OpenStruct + table: {} +ipmi: !ruby/object:Collins::Ipmi + address: 1.2.3.4 + asset_id: 3812 + gateway: 1.2.3.1 + id: 2 + netmask: 255.255.240.0 + password: ipmi-test-tag-password + username: ipmi-test-tag-user diff --git a/support/ruby/consolr/spec/fixtures/assets/dangerous-maintenance-tag.yml b/support/ruby/consolr/spec/fixtures/assets/dangerous-maintenance-tag.yml new file mode 100644 index 000000000..2056bcb15 --- /dev/null +++ b/support/ruby/consolr/spec/fixtures/assets/dangerous-maintenance-tag.yml @@ -0,0 +1,24 @@ +--- !ruby/object:Collins::Asset +extras: + ATTRIBS: + '0': + HOSTNAME: web-dc0ce734.ewr01.tumblr.net +id: 1 +status: Maintenance +tag: dangerous-maintenance-tag +type: SERVER_NODE +state: !ruby/object:Collins::AssetState + description: A service in this state is operational. + id: 3 + label: Running + name: RUNNING + status: !ruby/object:OpenStruct + table: {} +ipmi: !ruby/object:Collins::Ipmi + address: 1.2.3.4 + asset_id: 3812 + gateway: 1.2.3.1 + id: 2 + netmask: 255.255.240.0 + password: ipmi-test-tag-password + username: ipmi-test-tag-user diff --git a/support/ruby/consolr/spec/fixtures/assets/safe-allocated-tag.yml b/support/ruby/consolr/spec/fixtures/assets/safe-allocated-tag.yml new file mode 100644 index 000000000..99377c5d9 --- /dev/null +++ b/support/ruby/consolr/spec/fixtures/assets/safe-allocated-tag.yml @@ -0,0 +1,24 @@ +--- !ruby/object:Collins::Asset +extras: + ATTRIBS: + '0': + HOSTNAME: web-dc0ce734.ewr01.tumblr.net +id: 1 +status: Allocated +tag: safe-allocated-tag +type: SERVER_NODE +state: !ruby/object:Collins::AssetState + description: A service in this state is operational. + id: 3 + label: Running + name: RUNNING + status: !ruby/object:OpenStruct + table: {} +ipmi: !ruby/object:Collins::Ipmi + address: 1.2.3.4 + asset_id: 3812 + gateway: 1.2.3.1 + id: 2 + netmask: 255.255.240.0 + password: ipmi-test-tag-password + username: ipmi-test-tag-user diff --git a/support/ruby/consolr/spec/fixtures/assets/safe-maintenance-tag.yml b/support/ruby/consolr/spec/fixtures/assets/safe-maintenance-tag.yml new file mode 100644 index 000000000..a44e23142 --- /dev/null +++ b/support/ruby/consolr/spec/fixtures/assets/safe-maintenance-tag.yml @@ -0,0 +1,24 @@ +--- !ruby/object:Collins::Asset +extras: + ATTRIBS: + '0': + HOSTNAME: web-dc0ce734.ewr01.tumblr.net +id: 1 +status: Maintenance +tag: safe-maintenance-tag +type: SERVER_NODE +state: !ruby/object:Collins::AssetState + description: A service in this state is operational. + id: 3 + label: Running + name: RUNNING + status: !ruby/object:OpenStruct + table: {} +ipmi: !ruby/object:Collins::Ipmi + address: 1.2.3.4 + asset_id: 3812 + gateway: 1.2.3.1 + id: 2 + netmask: 255.255.240.0 + password: ipmi-test-tag-password + username: ipmi-test-tag-user diff --git a/support/ruby/consolr/spec/mocks/collins.rb b/support/ruby/consolr/spec/mocks/collins.rb new file mode 100644 index 000000000..ec7066b80 --- /dev/null +++ b/support/ruby/consolr/spec/mocks/collins.rb @@ -0,0 +1,31 @@ +module MockCollinsMixin + require 'collins_client' + + def test_assets + Dir.glob('spec/fixtures/assets/*.yml').map do |f| + YAML.load(File.read(f)) + end + end + + def get_test_asset tag + test_assets.select { |a| a.tag == tag } + end + + def mock_collins + allow_any_instance_of(Collins::Client).to receive(:find). + with(Hash). + and_return([]) + + allow_any_instance_of(Collins::Client).to receive(:find). + with(hash_including(:hostname => 'hostname-with-multiple-assets.dc.net')). + and_return(['asset1', 'asset2']) + + + ['safe-allocated-tag', 'safe-maintenance-tag', 'dangerous-allocated-tag', 'dangerous-maintenance-tag'].each do |tag| + allow_any_instance_of(Collins::Client).to receive(:find). + with(hash_including(:tag => tag)). + and_return(get_test_asset(tag)) + end + end + +end diff --git a/support/ruby/consolr/spec/mocks/collins_auth.rb b/support/ruby/consolr/spec/mocks/collins_auth.rb new file mode 100644 index 000000000..d728235ba --- /dev/null +++ b/support/ruby/consolr/spec/mocks/collins_auth.rb @@ -0,0 +1,11 @@ +module MockCollinsAuthMixin + require 'collins_auth' + require 'collins_client' + + def mock_collins_auth + allow_any_instance_of(Collins::Authenticator).to receive(:setup_client). + and_return(Collins::Client) + + end + +end diff --git a/support/ruby/consolr/spec/mocks/ping.rb b/support/ruby/consolr/spec/mocks/ping.rb new file mode 100644 index 000000000..68532709a --- /dev/null +++ b/support/ruby/consolr/spec/mocks/ping.rb @@ -0,0 +1,10 @@ +module MockPingMixin + require 'net/ping' + + def mock_ping + allow_any_instance_of(Net::Ping::External).to receive(:ping?). + and_return(true) + + end + +end diff --git a/support/ruby/consolr/spec/rspec_ipmi b/support/ruby/consolr/spec/rspec_ipmi new file mode 100755 index 000000000..9462e21e9 --- /dev/null +++ b/support/ruby/consolr/spec/rspec_ipmi @@ -0,0 +1,19 @@ +#!/usr/bin/env ruby +# mock impitool script + +require 'optparse' + +options = {} +OptionParser.new do |opts| + opts.banner = "Usage: example.rb [options]" + + # compatibility arguments that are ignored + opts.on("-I", "--interface [INTERFACE]", "compatibility with real tool. Ignored") + opts.on("-H", "--hostname [HOSTNAME]", "compatibility with real tool. Ignored") + opts.on("-U", "--user [USERNAME]", "compatibility with real tool. Ignored") + opts.on("-P", "--password [PASSWORD]", "compatibility with real tool. Ignored") +end.parse! + +# ARGV options is the action to take +# for testing, just return the action taken +puts ARGV.join(' ') diff --git a/support/ruby/consolr/spec/spec_helper.rb b/support/ruby/consolr/spec/spec_helper.rb new file mode 100644 index 000000000..b5f06a804 --- /dev/null +++ b/support/ruby/consolr/spec/spec_helper.rb @@ -0,0 +1,31 @@ +require 'simplecov' +SimpleCov.start do + add_filter "/spec/" +end + +require 'consolr' + +# require our mocks +require 'mocks/collins_auth' +require 'mocks/collins' +require 'mocks/ping' +require 'webmock/rspec' + +WebMock.disable_net_connect!() + +# make sure we use the rspec config file +ENV['CONSOLR_CONFIG'] = "#{File.dirname(__FILE__)}/configs/consolr_rspec.yml" +ENV['COLLINS_CLIENT_CONFIG'] = "#{File.dirname(__FILE__)}/configs/collins_rspec.yml" + +RSpec.configure do |config| + config.include MockCollinsAuthMixin + config.include MockCollinsMixin + config.include MockPingMixin + + config.before(:example) do |example| + mock_collins_auth + mock_collins + mock_ping + end + +end