-
Notifications
You must be signed in to change notification settings - Fork 99
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
Consolr dangerous asset behavior and unit tests #359
Changes from all commits
1902548
23ff0c2
7dc350f
93d8796
1f71775
502de88
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
coverage/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--color | ||
--format documentation |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
ruby=ruby-2.2.1 | ||
ruby-gemset=consolr | ||
#ruby-gem-install=bundler rake | ||
#ruby-bundle-install=true |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module Consolr | ||
VERSION = "1.0.1" | ||
VERSION = "1.0.2" | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
host: https://collins.example.net | ||
username: "collins_user" | ||
password: "collins_pass" | ||
timeout: 30 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how come these log commands are considered safe and tested via that mechanism? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps adding "safe" in the it description would be clearer and symmetric with how danger is done.