-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #359 from tumblr/will-consolr-allow-safe-actions-o…
…n-dangerous-assets Consolr dangerous asset behavior and unit tests
- Loading branch information
Showing
21 changed files
with
419 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
coverage/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--color | ||
--format documentation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
end | ||
end |
24 changes: 24 additions & 0 deletions
24
support/ruby/consolr/spec/fixtures/assets/dangerous-allocated-tag.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.