Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

renames project to boucher

  • Loading branch information...
commit 5be6c6c4f9ca2f56d1c519d152335e69493f4398 1 parent 80e84fb
@slagyr slagyr authored
Showing with 482 additions and 482 deletions.
  1. +1 −1  .gitmodules
  2. +1 −1  .rvmrc
  3. +2 −2 README.md
  4. +3 −3 butcher.gemspec
  5. +4 −4 lib/{butcher → boucher}/ci.rb
  6. +7 −7 lib/{butcher → boucher}/classes.rb
  7. +15 −15 lib/{butcher → boucher}/compute.rb
  8. +6 −6 lib/{butcher → boucher}/env.rb
  9. +1 −1  lib/{butcher → boucher}/io.rb
  10. +8 −8 lib/{butcher → boucher}/nagios.rb
  11. +26 −26 lib/{butcher → boucher}/provision.rb
  12. +11 −11 lib/{butcher → boucher}/servers.rb
  13. +8 −8 lib/{butcher → boucher}/storage.rb
  14. 0  lib/{butcher → boucher}/tasks.rb
  15. +21 −0 lib/boucher/tasks/console.rake
  16. +42 −0 lib/boucher/tasks/env.rake
  17. +2 −2 lib/{butcher → boucher}/tasks/nagios.rake
  18. +35 −35 lib/{butcher → boucher}/tasks/servers.rake
  19. +8 −8 lib/{butcher → boucher}/tasks/storage.rake
  20. +4 −4 lib/{butcher → boucher}/tasks/volumes.rake
  21. +1 −1  lib/{butcher → boucher}/util.rb
  22. +7 −7 lib/{butcher → boucher}/volumes.rb
  23. +0 −21 lib/butcher/tasks/console.rake
  24. +0 −42 lib/butcher/tasks/env.rake
  25. +8 −8 spec/{butcher → boucher}/classes_spec.rb
  26. +75 −0 spec/boucher/compute_spec.rb
  27. +8 −8 spec/{butcher → boucher}/env_spec.rb
  28. +6 −6 spec/{butcher → boucher}/io_spec.rb
  29. +77 −0 spec/boucher/provision_spec.rb
  30. +79 −0 spec/boucher/servers_spec.rb
  31. +11 −11 spec/{butcher → boucher}/storage_spec.rb
  32. +0 −75 spec/butcher/compute_spec.rb
  33. +0 −77 spec/butcher/provision_spec.rb
  34. +0 −79 spec/butcher/servers_spec.rb
  35. +5 −5 spec/spec_helper.rb
View
2  .gitmodules
@@ -1,3 +1,3 @@
[submodule "template"]
path = template
- url = git@github.com:8thlight/butcher_template.git
+ url = git@github.com:8thlight/boucher_template.git
View
2  .rvmrc
@@ -1,2 +1,2 @@
-rvm use 1.9.3-p125@butcher --create
+rvm use 1.9.3-p125@boucher --create
View
4 README.md
@@ -1,5 +1,5 @@
-<img src="" alt="butcher logo" title="Butcher" align="right"/>
-# Butcher
+<img src="" alt="boucher logo" title="Boucher" align="right"/>
+# Boucher
...
View
6 butcher.gemspec
@@ -1,18 +1,18 @@
# -*- encoding: utf-8 -*-
Gem::Specification.new do |s|
- s.name = "butcher"
+ s.name = "boucher"
s.version = "0.1"
s.authors = ["'Micah Micah'"]
s.email = ["'micah@8thlight.com'"]
- s.homepage = "http://github.com/8thlight/butcher"
+ s.homepage = "http://github.com/8thlight/boucher"
s.summary = "AWS system deployment and management"
s.description = "AWS system deployment and management"
s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = []
s.require_paths = ["lib"]
- s.autorequire = 'butcher/tasks'
+ s.autorequire = 'boucher/tasks'
s.add_dependency('rake', '>= 0.9.2.2')
s.add_dependency('fog', '>= 1.6.0')
View
8 lib/butcher/ci.rb → lib/boucher/ci.rb
@@ -1,8 +1,8 @@
-module Butcher
+module Boucher
module CI
def self.each_server(&block)
threads = []
- Butcher.each_required_server do |server, server_class|
+ Boucher.each_required_server do |server, server_class|
thread = Thread.new { block.yield(server, server_class) }
threads << thread
end
@@ -10,8 +10,8 @@ def self.each_server(&block)
end
def self.terminate_server(server_class)
- server = Butcher.get_server(server_class, "ci", "running")
- Butcher.change_server_state server.id, :destroy, "terminated" if server
+ server = Boucher.get_server(server_class, "ci", "running")
+ Boucher.change_server_state server.id, :destroy, "terminated" if server
end
end
end
View
14 lib/butcher/classes.rb → lib/boucher/classes.rb
@@ -1,13 +1,13 @@
-require 'butcher/env'
-require 'butcher/util'
+require 'boucher/env'
+require 'boucher/util'
require 'json'
-module Butcher
+module Boucher
def self.json_to_class(json)
parser = JSON.parser.new(json, :symbolize_names => true)
config = parser.parse
- config[:butcher]
+ config[:boucher]
end
def self.server_classes
@@ -23,15 +23,15 @@ def self.server_classes
end
def self.classify(server, class_spec)
- server.image_id = class_spec[:base_image_id] || Butcher::Config[:base_image_id]
+ server.image_id = class_spec[:base_image_id] || Boucher::Config[:base_image_id]
server.flavor_id = class_spec[:flavor_id] || 'm1.small'
server.groups = class_spec[:groups] || ["SSH"]
- server.key_name = class_spec[:key_name] || Butcher::Config[:aws_key_filename]
+ server.key_name = class_spec[:key_name] || Boucher::Config[:aws_key_filename]
server.tags = {}
server.tags["Class"] = class_spec[:class_name] || "base"
server.tags["Name"] = Time.new.strftime("%Y%m%d%H%M%S")
server.tags["Creator"] = current_user
- server.tags["Env"] = Butcher::Config[:env]
+ server.tags["Env"] = Boucher::Config[:env]
server.tags["Volumes"] = class_spec[:volumes]
end
View
30 lib/butcher/compute.rb → lib/boucher/compute.rb
@@ -1,16 +1,16 @@
-require 'butcher/env'
-require 'butcher/classes'
-require 'butcher/io'
+require 'boucher/env'
+require 'boucher/classes'
+require 'boucher/io'
require 'fog'
require 'retryable'
-module Butcher
+module Boucher
EC2_CONFIG = {
:provider => 'AWS',
- :aws_secret_access_key => Butcher::Config[:aws_secret_access_key],
- :aws_access_key_id => Butcher::Config[:aws_access_key_id],
- :region => Butcher::Config[:aws_region]
+ :aws_secret_access_key => Boucher::Config[:aws_secret_access_key],
+ :aws_access_key_id => Boucher::Config[:aws_access_key_id],
+ :region => Boucher::Config[:aws_region]
}
def self.compute
@@ -28,25 +28,25 @@ def self.ssh(server, command=nil)
command_arg = "\"#{command}\""
end
- command = "#{ssh_command} #{Butcher::Config[:username]}@#{server.dns_name} #{command_arg}"
+ command = "#{ssh_command} #{Boucher::Config[:username]}@#{server.dns_name} #{command_arg}"
verbose command
Kernel.system command
raise "command failed with code #{$?.exitstatus}" unless $?.success?
end
def self.ssh_command
- "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i #{Butcher::Config[:aws_key_filename]}.pem"
+ "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i #{Boucher::Config[:aws_key_filename]}.pem"
end
def self.download(server, remote_filepath, local_filepath)
- command = ["rsync", "-azb", "-e", ssh_command, "--delete-after", "#{Butcher::Config[:username]}@#{server.dns_name}:#{remote_filepath}", local_filepath]
+ command = ["rsync", "-azb", "-e", ssh_command, "--delete-after", "#{Boucher::Config[:username]}@#{server.dns_name}:#{remote_filepath}", local_filepath]
Kernel.system(*command)
raise "command failed with code #{$?.exitstatus}: #{command.inspect}" unless $?.success?
end
def self.rsync(server, from, to)
command = ["rsync", "-azb", "-e", ssh_command, "--delete-after",
- from, "#{Butcher::Config[:username]}@#{server.dns_name}:#{to}"]
+ from, "#{Boucher::Config[:username]}@#{server.dns_name}:#{to}"]
Kernel.system(*command)
raise "command failed with code #{$?.exitstatus}: #{command.inspect}" unless $?.success?
end
@@ -61,12 +61,12 @@ def self.update_recipes(server)
end
def self.cook_meal(server, meal)
- Butcher::Nagios.remove_host(server)
+ Boucher::Nagios.remove_host(server)
update_recipes(server)
- ssh server, "cd infrastructure && sudo BUTCHER_ENV=#{Butcher::Config[:env]} BRANCH=#{Butcher::Config[:branch]} chef-solo -c config/solo.rb -j config/#{meal}.json"
+ ssh server, "cd infrastructure && sudo BUTCHER_ENV=#{Boucher::Config[:env]} BRANCH=#{Boucher::Config[:branch]} chef-solo -c config/solo.rb -j config/#{meal}.json"
- Butcher::Nagios.add_host(server)
+ Boucher::Nagios.add_host(server)
end
def self.ssh_open?(server)
@@ -82,7 +82,7 @@ def self.change_server_state(server_id, command, new_state)
server.send(command.to_sym)
server.wait_for { print "."; state == new_state }
puts
- Butcher.print_servers [server]
+ Boucher.print_servers [server]
puts
puts "The server has been #{command}-ed."
end
View
12 lib/butcher/env.rb → lib/boucher/env.rb
@@ -1,8 +1,8 @@
-module Butcher
+module Boucher
Config = {
:branch => ENV["BRANCH"] || "master"
- } unless defined?(Butcher::Config)
+ } unless defined?(Boucher::Config)
def self.env_name
ENV["BUTCHER_ENV"] ? ENV["BUTCHER_ENV"] : :dev
@@ -12,7 +12,7 @@ def self.env_name
valid_envs = Dir[File.join(env_dir, "**", "*.rb")].map { |path| File.basename(path, ".rb") }
env_path = File.expand_path("#{env_name}.rb", env_dir)
- unless defined?(Butcher::NO_LOAD_CONFIG)
+ unless defined?(Boucher::NO_LOAD_CONFIG)
unless File.exists?(env_path)
raise "Config file #{env_path} doesn't exist.\nYou need to change your BUTCHER_ENV environment variable to a valid environment name.\nValid environments: #{valid_envs.join(", ")}"
end
@@ -22,10 +22,10 @@ def self.env_name
def self.force_env!(name)
env = name.to_sym
- Butcher::Config[:branch] = ENV["BRANCH"] || "master"
- load File.expand_path(File.dirname(__FILE__) + "/../../config/env/shared.rb") unless defined?(Butcher::NO_LOAD_CONFIG)
+ Boucher::Config[:branch] = ENV["BRANCH"] || "master"
+ load File.expand_path(File.dirname(__FILE__) + "/../../config/env/shared.rb") unless defined?(Boucher::NO_LOAD_CONFIG)
file = File.expand_path(File.dirname(__FILE__) + "/../../config/env/#{env}.rb")
- unless defined?(Butcher::NO_LOAD_CONFIG)
+ unless defined?(Boucher::NO_LOAD_CONFIG)
if File.exist?(file)
load file
else
View
2  lib/butcher/io.rb → lib/boucher/io.rb
@@ -1,4 +1,4 @@
-module Butcher
+module Boucher
module IO
View
16 lib/butcher/nagios.rb → lib/boucher/nagios.rb
@@ -1,18 +1,18 @@
-require 'butcher/servers'
-require 'butcher/compute'
+require 'boucher/servers'
+require 'boucher/compute'
-module Butcher
+module Boucher
module Nagios
def self.remove_host(host)
return if host.tags["Class"] == "nagios_server"
monitors_for(host.tags["Env"]).each do |monitor|
commands = [
- "cd /home/#{Butcher::Config[:username]}/infrastructure",
+ "cd /home/#{Boucher::Config[:username]}/infrastructure",
"sudo rake nagios:remove_host[#{host.id}]",
"sudo /etc/init.d/nagios3 restart"
]
- Butcher.ssh(monitor, commands.join(" && "))
+ Boucher.ssh(monitor, commands.join(" && "))
end
end
@@ -21,12 +21,12 @@ def self.add_host(host)
monitors_for(host.tags["Env"]).each do |monitor|
commands = [
- "cd /home/#{Butcher::Config[:username]}/infrastructure",
+ "cd /home/#{Boucher::Config[:username]}/infrastructure",
"sudo rake nagios:add_host[#{host.id},#{host.public_ip_address},#{host.tags["Class"]}]",
"sudo /etc/init.d/nagios3 restart"
]
- Butcher.ssh(monitor, commands.join(" && "))
+ Boucher.ssh(monitor, commands.join(" && "))
end
end
@@ -40,7 +40,7 @@ def self.checks_for(server_class)
private
def self.monitors_for(env)
- Butcher::Servers.all.select do |monitor|
+ Boucher::Servers.all.select do |monitor|
monitor.tags["Class"] == "nagios_server" &&
monitor.tags["Env"] == env &&
monitor.dns_name
View
52 lib/butcher/provision.rb → lib/boucher/provision.rb
@@ -1,22 +1,22 @@
-require 'butcher/compute'
-require 'butcher/io'
-require 'butcher/servers'
-require 'butcher/volumes'
-require 'butcher/nagios'
+require 'boucher/compute'
+require 'boucher/io'
+require 'boucher/servers'
+require 'boucher/volumes'
+require 'boucher/nagios'
require 'retryable'
-module Butcher
+module Boucher
def self.each_required_server(&block)
- Butcher::Config[:servers].each do |server_class|
- server = find_server(server_class, Butcher::Config[:env])
+ Boucher::Config[:servers].each do |server_class|
+ server = find_server(server_class, Boucher::Config[:env])
block.yield(server, server_class)
end
end
def self.get_server(server_class, environment, state)
begin
- Butcher::Servers.find(:env => environment.to_s, :class => server_class, :state => state)
- rescue Butcher::Servers::NotFound
+ Boucher::Servers.find(:env => environment.to_s, :class => server_class, :state => state)
+ rescue Boucher::Servers::NotFound
nil
end
end
@@ -26,25 +26,25 @@ def self.find_server(server_class, environment)
end
def self.establish_all_servers
- Butcher.each_required_server do |server, server_class|
+ Boucher.each_required_server do |server, server_class|
# Retries after 2, 4, 8, 16, 32, and 64 seconds
retryable(:tries => 6, :sleep => lambda { |n| 2**n }) do
# A RuntimeError will sometimes be thrown here, with a message of:
# "command failed with code 255"
- Butcher.establish_server(server, server_class)
+ Boucher.establish_server(server, server_class)
end
end
end
def self.establish_server(server, server_class)
if server.nil?
- Butcher.provision(server_class, Butcher.server_classes[server_class.to_sym])
+ Boucher.provision(server_class, Boucher.server_classes[server_class.to_sym])
elsif server.state == "stopped"
- Butcher::Servers.start(server.id)
+ Boucher::Servers.start(server.id)
server.reload
- Butcher.cook_meals_on_server(server_class, Butcher.server_classes[server_class.to_sym], server)
+ Boucher.cook_meals_on_server(server_class, Boucher.server_classes[server_class.to_sym], server)
else
- Butcher.cook_meals_on_server(server_class, Butcher.server_classes[server_class.to_sym], server)
+ Boucher.cook_meals_on_server(server_class, Boucher.server_classes[server_class.to_sym], server)
end
end
@@ -61,10 +61,10 @@ def self.provision(class_name, class_map)
def self.attach_elastic_ips(class_name, server)
puts "Attaching elastic IPs..."
- return unless Butcher::Config[:elastic_ips] && Butcher::Config[:elastic_ips][class_name]
+ return unless Boucher::Config[:elastic_ips] && Boucher::Config[:elastic_ips][class_name]
- puts "Associating #{server.id} with #{Butcher::Config[:elastic_ips][class_name]}"
- compute.associate_address(server.id, Butcher::Config[:elastic_ips][class_name])
+ puts "Associating #{server.id} with #{Boucher::Config[:elastic_ips][class_name]}"
+ compute.associate_address(server.id, Boucher::Config[:elastic_ips][class_name])
end
private
@@ -74,7 +74,7 @@ def self.cook_meals_on_server(class_name, class_map, server)
class_map[:meals].each do |meal|
meal = meal.call if meal.is_a?(Proc)
- Butcher.cook_meal(server, meal)
+ Boucher.cook_meal(server, meal)
end
attach_elastic_ips(class_name, server)
@@ -90,30 +90,30 @@ def self.wait_for_server_to_boot(server)
print "Waiting for server to boot..."
server.wait_for { print "."; server.ready? }
puts
- Butcher.print_servers([server])
+ Boucher.print_servers([server])
end
def self.create_classified_server(class_map)
server = compute.servers.new(:tags => {})
- Butcher.classify(server, class_map)
+ Boucher.classify(server, class_map)
server.save
- Butcher.print_servers([server])
+ Boucher.print_servers([server])
server
end
def self.create_volumes(class_map, server)
Array(class_map[:volumes]).map do |volume_name|
- attributes = Butcher.volume_configs[volume_name]
+ attributes = Boucher.volume_configs[volume_name]
snapshot = snapshots.get(attributes[:snapshot])
puts "Creating volume from snapshot #{snapshot.id}..."
- Butcher::Volumes.create(server.availability_zone, snapshot, attributes[:device])
+ Boucher::Volumes.create(server.availability_zone, snapshot, attributes[:device])
end
end
def self.attach_volumes(volumes, server)
volumes.each do |volume|
print "Attaching volume #{volume.id} to #{server.id}..."
- Butcher::Volumes.attach(volume, server)
+ Boucher::Volumes.attach(volume, server)
volume.wait_for { print "."; state == "in-use" }
puts
end
View
22 lib/butcher/servers.rb → lib/boucher/servers.rb
@@ -1,6 +1,6 @@
-require 'butcher/compute'
+require 'boucher/compute'
-module Butcher
+module Boucher
module Servers
NotFound = Class.new(StandardError)
@@ -11,7 +11,7 @@ def instance
end
def reload
- @instance = Butcher.compute.servers
+ @instance = Boucher.compute.servers
@instance.each {} # Wake up you lazy list!
cultivate(@instance)
end
@@ -21,7 +21,7 @@ def reload
end
def cultivate(thing)
- thing.extend(Butcher::Servers) if thing
+ thing.extend(Boucher::Servers) if thing
thing
end
end
@@ -42,7 +42,7 @@ def find(options={})
servers = search(options)
first = servers.first
if first.nil?
- raise Butcher::Servers::NotFound.new("No server matches criteria: #{options.inspect}")
+ raise Boucher::Servers::NotFound.new("No server matches criteria: #{options.inspect}")
end
first
end
@@ -60,24 +60,24 @@ def of_class(klass)
end
def self.start(server_id)
- Butcher.change_server_state(server_id, :start, "running")
+ Boucher.change_server_state(server_id, :start, "running")
end
def self.stop(server_id)
- Butcher.change_server_state(server_id, :stop, "stopped")
+ Boucher.change_server_state(server_id, :stop, "stopped")
end
def self.terminate(server)
- Butcher::Nagios.remove_host(server)
+ Boucher::Nagios.remove_host(server)
volumes = server.volumes
volumes_to_destroy = volumes.select {|v| !v.delete_on_termination}
- Butcher.change_server_state server.id, :destroy, "terminated"
+ Boucher.change_server_state server.id, :destroy, "terminated"
volumes_to_destroy.each do |volume|
volume.wait_for { volume.state == 'available' }
puts "Destroying volume #{volume.id}..."
- Butcher::Volumes.destroy(volume)
+ Boucher::Volumes.destroy(volume)
end
end
@@ -86,7 +86,7 @@ def with_id(server_id)
end
def [](klass)
- find(:env => Butcher::Config[:env], :class => klass, :state => "running")
+ find(:env => Boucher::Config[:env], :class => klass, :state => "running")
end
end
end
View
16 lib/butcher/storage.rb → lib/boucher/storage.rb
@@ -1,13 +1,13 @@
-require 'butcher/env'
-require 'butcher/classes'
+require 'boucher/env'
+require 'boucher/classes'
require 'fog'
-module Butcher
+module Boucher
S3_CONFIG = {
:provider => 'AWS',
- :aws_secret_access_key => Butcher::Config[:aws_secret_access_key],
- :aws_access_key_id => Butcher::Config[:aws_access_key_id]
+ :aws_secret_access_key => Boucher::Config[:aws_secret_access_key],
+ :aws_access_key_id => Boucher::Config[:aws_access_key_id]
}
def self.storage
@@ -18,13 +18,13 @@ def self.storage
module Storage
def self.list(dir_name)
- dir = Butcher.storage.directories.get(dir_name)
+ dir = Boucher.storage.directories.get(dir_name)
result = dir.files.select {|f| f.key[-1] != "/" }.to_a
result
end
def self.put(dir_name, key, filename)
- dir = Butcher.storage.directories.get(dir_name)
+ dir = Boucher.storage.directories.get(dir_name)
body = File.open(filename)
file = dir.files.new(:key => key, :body => body)
file.save
@@ -33,7 +33,7 @@ def self.put(dir_name, key, filename)
end
def self.get(dir_name, key, filename)
- dir = Butcher.storage.directories.get(dir_name)
+ dir = Boucher.storage.directories.get(dir_name)
url = dir.files.get_https_url(key, Time.now + 3600)
Kernel.system("curl", url, "-o", filename)
dir.files.detect{|f| f.key == key}
View
0  lib/butcher/tasks.rb → lib/boucher/tasks.rb
File renamed without changes
View
21 lib/boucher/tasks/console.rake
@@ -0,0 +1,21 @@
+require 'boucher/compute'
+require 'boucher/env'
+require 'boucher/io'
+require 'boucher/classes'
+require 'boucher/provision'
+require 'boucher/servers'
+require 'boucher/volumes'
+require 'boucher/nagios'
+
+desc "Starts a console with the Boucher modules loaded"
+task :console do
+ require 'pry'
+
+ Dir[File.expand_path("../../lib/boucher/**/*.rb", __FILE__)].each do |filename|
+ require filename
+ end
+
+ include Boucher
+
+ pry
+end
View
42 lib/boucher/tasks/env.rake
@@ -0,0 +1,42 @@
+require 'boucher/env'
+require 'boucher/provision'
+require 'retryable'
+
+namespace :env do
+
+ desc "Attaches elastic IPs"
+ task :elastic_ips, [:env] do |t, args|
+ Boucher.force_env!(args.env)
+ Boucher.each_required_server do |server, server_class|
+ Boucher.attach_elastic_ips(server_class, server)
+ end
+ end
+
+ desc "Starts and deploys all the servers for the specified environment"
+ task :start, [:env] do |t, args|
+ Boucher.force_env!(args.env)
+ Boucher.assert_env!
+ Boucher.establish_all_servers
+ end
+
+ desc "Stops all the servers for the specified environment"
+ task :stop, [:env] do |t, args|
+ Boucher.force_env!(args.env)
+
+ Boucher.each_required_server do |server, server_class|
+ if server
+ Boucher::Servers.stop(server.id)
+ else
+ puts "No #{server_class} server found for #{Boucher::Config[:env]} environment."
+ end
+ end
+ end
+
+ desc "Terminates all servers for the specified environment"
+ task :terminate, [:env] do |t, args|
+ Boucher.force_env!(args.env)
+ Boucher.each_required_server do |server, server_class|
+ Boucher::Servers.terminate(server) if server
+ end
+ end
+end
View
4 lib/butcher/tasks/nagios.rake → lib/boucher/tasks/nagios.rake
@@ -48,7 +48,7 @@ namespace :nagios do
desc "Adds a nagios host to be monitored by this machine"
task :add_host, [:name, :ip, :klass] do |t, args|
- checks = Butcher::Nagios.checks_for(args.klass)
+ checks = Boucher::Nagios.checks_for(args.klass)
return if checks.empty?
File.open(make_config_path(args.name), "w") do |file|
@@ -65,7 +65,7 @@ namespace :nagios do
desc "Opens the nagios web console"
task :open do
- server = Butcher::Servers["nagios_server"]
+ server = Boucher::Servers["nagios_server"]
url = "http://#{server.public_ip_address}/nagios3"
puts "Nagios lives at #{url}"
puts "Login using nagiosadmin / 'we are many lonely souls'"
View
70 lib/butcher/tasks/servers.rake → lib/boucher/tasks/servers.rake
@@ -1,11 +1,11 @@
-require 'butcher/compute'
-require 'butcher/env'
-require 'butcher/io'
-require 'butcher/classes'
-require 'butcher/provision'
-require 'butcher/servers'
-require 'butcher/volumes'
-require 'butcher/nagios'
+require 'boucher/compute'
+require 'boucher/env'
+require 'boucher/io'
+require 'boucher/classes'
+require 'boucher/provision'
+require 'boucher/servers'
+require 'boucher/volumes'
+require 'boucher/nagios'
require 'retryable'
def meals
@@ -16,7 +16,7 @@ end
def server_listing(description, servers)
puts "Listing all AWS server #{description}..."
- Butcher.print_servers servers
+ Boucher.print_servers servers
puts
puts "#{servers.size} server(s)"
end
@@ -24,30 +24,30 @@ end
namespace :servers do
desc "List all volumes for a given server"
task :volumes, [:server_id] do |t, args|
- volumes = Butcher::Servers.with_id(args.server_id).volumes
- Butcher.print_volumes(volumes)
+ volumes = Boucher::Servers.with_id(args.server_id).volumes
+ Boucher.print_volumes(volumes)
end
desc "List ALL AWS servers, with optional [env] param."
task :list, [:env] do |t, args|
- servers = Butcher::Servers.all
+ servers = Boucher::Servers.all
servers = args.env ? servers.in_env(args.env) : servers
server_listing("", servers)
end
desc "List AWS servers in specified environment"
task :in_env, [:env] do |t, args|
- server_listing("in the '#{args.env}' environment", Butcher::Servers.in_env(args.env))
+ server_listing("in the '#{args.env}' environment", Boucher::Servers.in_env(args.env))
end
desc "List AWS servers in specified class"
task :of_class, [:klass] do |t, args|
- server_listing("of class '#{args.klass}'", Butcher::Servers.of_class(args.klass))
+ server_listing("of class '#{args.klass}'", Boucher::Servers.of_class(args.klass))
end
desc "Terminates the specified server"
task :terminate, [:server_id] do |t, args|
- server = Butcher::Servers.with_id(args.server_id)
+ server = Boucher::Servers.with_id(args.server_id)
if !server
puts "Server #{args.server_id} does not exist"
@@ -55,7 +55,7 @@ namespace :servers do
end
begin
- Butcher::Servers.terminate(server)
+ Boucher::Servers.terminate(server)
rescue => e
puts "\nTermination failed. This may be due to termination protection. If
you're sure you wish to disable this protection, select the instance in the AWS
@@ -66,34 +66,34 @@ web console and click Instance Actions -> Change Termination Protection -> Yes."
desc "Stops the specified server"
task :stop, [:server_id] do |t, args|
- server = Butcher.compute.servers.get(args.server_id)
- Butcher::Nagios.remove_host(server)
- Butcher::Servers.stop(args.server_id)
+ server = Boucher.compute.servers.get(args.server_id)
+ Boucher::Nagios.remove_host(server)
+ Boucher::Servers.stop(args.server_id)
end
desc "Starts the specified server"
task :start, [:server_id] do |t, args|
- Butcher::Servers.start(args.server_id)
- server = Butcher.compute.servers.get(args.server_id)
- Butcher::Nagios.add_host(server)
+ Boucher::Servers.start(args.server_id)
+ server = Boucher.compute.servers.get(args.server_id)
+ Boucher::Nagios.add_host(server)
end
desc "Open an SSH session with the specified server"
task :ssh, [:server_id] do |t, args|
puts "Opening SSH session to #{args.server_id}"
- server = Butcher.compute.servers.get(args.server_id)
- Butcher.ssh server
+ server = Boucher.compute.servers.get(args.server_id)
+ Boucher.ssh server
end
desc "Download a file from the server"
task :download, [:server_id, :filepath] do |t, args|
puts "Downloading #{args.filepath}"
- server = Butcher.compute.servers.get(args.server_id)
+ server = Boucher.compute.servers.get(args.server_id)
remote_path = args.filepath
local_path = File.expand_path(File.join("..", "..", File.basename(args.filepath)), __FILE__)
- Butcher.download(server, remote_path, local_path)
+ Boucher.download(server, remote_path, local_path)
end
desc "Fix permissions on key files"
@@ -101,26 +101,26 @@ web console and click Instance Actions -> Change Termination Protection -> Yes."
system "chmod 0600 *.pem"
end
- desc "Provision new server [#{Butcher.server_classes.keys.sort.join(', ')}]"
+ desc "Provision new server [#{Boucher.server_classes.keys.sort.join(', ')}]"
task :provision, [:klass] do |t, args|
- class_map = Butcher.server_classes[args.klass.to_sym]
- Butcher.provision(args.klass, class_map)
+ class_map = Boucher.server_classes[args.klass.to_sym]
+ Boucher.provision(args.klass, class_map)
end
desc "Provision new, or chef existing server of the specified class"
task :establish, [:klass] do |t, args|
- Butcher.assert_env!
- server = Butcher.find_server(args.klass, ENV['BUTCHER_ENV'])
- Butcher.establish_server(server, args.klass)
+ Boucher.assert_env!
+ server = Boucher.find_server(args.klass, ENV['BUTCHER_ENV'])
+ Boucher.establish_server(server, args.klass)
end
namespace :chef do
meals.each do |s_class|
desc "Cook #{s_class} meal"
task s_class, [:server_id] do |t, args|
- Butcher.assert_env!
- server = Butcher.compute.servers.get(args.server_id)
- Butcher.cook_meal(server, s_class)
+ Boucher.assert_env!
+ server = Boucher.compute.servers.get(args.server_id)
+ Boucher.cook_meal(server, s_class)
end
end
end
View
16 lib/butcher/tasks/storage.rake → lib/boucher/tasks/storage.rake
@@ -1,12 +1,12 @@
-require 'butcher/storage'
-require 'butcher/io'
+require 'boucher/storage'
+require 'boucher/io'
namespace :storage do
desc "Lists all the files in the infrastructure bucket on S3"
task :list do
- files = Butcher::Storage.list("infrastructure")
- Butcher.print_files files
+ files = Boucher::Storage.list("infrastructure")
+ Boucher.print_files files
end
desc "Puts a file in the infrastructure bucket"
@@ -14,8 +14,8 @@ namespace :storage do
filename = args.file
key = File.basename(filename)
puts "Storing file #{filename} as #{key}"
- file = Butcher::Storage.put("infrastructure", key, filename)
- Butcher.print_files [file]
+ file = Boucher::Storage.put("infrastructure", key, filename)
+ Boucher.print_files [file]
puts "File uploaded as #{key}."
end
@@ -24,8 +24,8 @@ namespace :storage do
key = args.file
filename = File.basename(key)
puts "Getting file #{key} and saving to #{filename}"
- file = Butcher::Storage.get("infrastructure", key, filename)
- Butcher.print_files [file]
+ file = Boucher::Storage.get("infrastructure", key, filename)
+ Boucher.print_files [file]
puts "File saved locally as #{filename}."
end
View
8 lib/butcher/tasks/volumes.rake → lib/boucher/tasks/volumes.rake
@@ -1,14 +1,14 @@
-require 'butcher/volumes'
-require 'butcher/io'
+require 'boucher/volumes'
+require 'boucher/io'
namespace :volumes do
desc "List provisioned volumes"
task :list do
- Butcher.print_volumes(Butcher::Volumes.all)
+ Boucher.print_volumes(Boucher::Volumes.all)
end
desc "Destroy the specified volume"
task :destroy, [:volume_id] do |t, args|
- Butcher.destroy_volume(args.volume_id)
+ Boucher.destroy_volume(args.volume_id)
end
end
View
2  lib/butcher/util.rb → lib/boucher/util.rb
@@ -1,4 +1,4 @@
-module Butcher
+module Boucher
def self.current_user
`git config user.name`.strip
View
14 lib/butcher/volumes.rb → lib/boucher/volumes.rb
@@ -1,14 +1,14 @@
-require 'butcher/compute'
+require 'boucher/compute'
-module Butcher
+module Boucher
def self.destroy_volume(volume_id)
- volume = Butcher::Volumes.with_id(volume_id)
+ volume = Boucher::Volumes.with_id(volume_id)
Volumes.destroy(volume)
end
module Volumes
def self.all
- @volumes ||= Butcher.compute.volumes
+ @volumes ||= Boucher.compute.volumes
end
def self.destroy(volumes)
@@ -23,9 +23,9 @@ def self.with_id(volume_id)
end
def self.create(zone, snapshot, device)
- response = Butcher.compute.create_volume(zone, snapshot.volume_size.to_i, snapshot.id)
+ response = Boucher.compute.create_volume(zone, snapshot.volume_size.to_i, snapshot.id)
volume_id = response.body["volumeId"]
- volume = Butcher.compute.volumes.get(volume_id)
+ volume = Boucher.compute.volumes.get(volume_id)
volume.wait_for { ready? }
volume.device = device
@@ -34,7 +34,7 @@ def self.create(zone, snapshot, device)
def self.attach(volumes, server)
Array(volumes).each do |volume|
- Butcher.compute.attach_volume(server.id, volume.id, volume.device)
+ Boucher.compute.attach_volume(server.id, volume.id, volume.device)
end
end
end
View
21 lib/butcher/tasks/console.rake
@@ -1,21 +0,0 @@
-require 'butcher/compute'
-require 'butcher/env'
-require 'butcher/io'
-require 'butcher/classes'
-require 'butcher/provision'
-require 'butcher/servers'
-require 'butcher/volumes'
-require 'butcher/nagios'
-
-desc "Starts a console with the Butcher modules loaded"
-task :console do
- require 'pry'
-
- Dir[File.expand_path("../../lib/butcher/**/*.rb", __FILE__)].each do |filename|
- require filename
- end
-
- include Butcher
-
- pry
-end
View
42 lib/butcher/tasks/env.rake
@@ -1,42 +0,0 @@
-require 'butcher/env'
-require 'butcher/provision'
-require 'retryable'
-
-namespace :env do
-
- desc "Attaches elastic IPs"
- task :elastic_ips, [:env] do |t, args|
- Butcher.force_env!(args.env)
- Butcher.each_required_server do |server, server_class|
- Butcher.attach_elastic_ips(server_class, server)
- end
- end
-
- desc "Starts and deploys all the servers for the specified environment"
- task :start, [:env] do |t, args|
- Butcher.force_env!(args.env)
- Butcher.assert_env!
- Butcher.establish_all_servers
- end
-
- desc "Stops all the servers for the specified environment"
- task :stop, [:env] do |t, args|
- Butcher.force_env!(args.env)
-
- Butcher.each_required_server do |server, server_class|
- if server
- Butcher::Servers.stop(server.id)
- else
- puts "No #{server_class} server found for #{Butcher::Config[:env]} environment."
- end
- end
- end
-
- desc "Terminates all servers for the specified environment"
- task :terminate, [:env] do |t, args|
- Butcher.force_env!(args.env)
- Butcher.each_required_server do |server, server_class|
- Butcher::Servers.terminate(server) if server
- end
- end
-end
View
16 spec/butcher/classes_spec.rb → spec/boucher/classes_spec.rb
@@ -1,32 +1,32 @@
require_relative "../spec_helper"
-require 'butcher/classes'
+require 'boucher/classes'
require 'ostruct'
-describe "Butcher Server Classes" do
+describe "Boucher Server Classes" do
before do
- Butcher.stub(:current_user).and_return("joe")
+ Boucher.stub(:current_user).and_return("joe")
@server = OpenStruct.new
end
it "pull classification from json" do
- json = "{\"butcher\": {\"foo\": 1,\n \"bar\": 2}}"
- Butcher.json_to_class(json).should == {:foo => 1, :bar => 2}
+ json = "{\"boucher\": {\"foo\": 1,\n \"bar\": 2}}"
+ Boucher.json_to_class(json).should == {:foo => 1, :bar => 2}
end
it "can classify base server" do
some_class = {:class_name => "base",
:meals => ["base"]}
- Butcher.classify(@server, some_class)
+ Boucher.classify(@server, some_class)
- @server.image_id.should == Butcher::Config[:base_image_id]
+ @server.image_id.should == Boucher::Config[:base_image_id]
@server.flavor_id.should == 'm1.small'
@server.groups.should == ["SSH"]
@server.key_name.should == "test_key"
@server.tags["Class"].should == "base"
@server.tags["Name"].should_not == nil
@server.tags["Creator"].should == "joe"
- @server.tags["Env"].should == Butcher::Config[:env]
+ @server.tags["Env"].should == Boucher::Config[:env]
end
end
View
75 spec/boucher/compute_spec.rb
@@ -0,0 +1,75 @@
+require_relative "../spec_helper"
+require 'boucher/compute'
+require 'boucher/nagios'
+require 'ostruct'
+
+describe "Boucher Cloud" do
+
+ after do
+ Boucher::Config[:env] = "dev"
+ end
+
+ it "knows connections options" do
+ connection = Boucher.compute
+ connection.should_not == nil
+ Boucher::EC2_CONFIG[:aws_secret_access_key].should == "secret key"
+ Boucher::EC2_CONFIG[:aws_access_key_id].should == "public id"
+ end
+
+ it "ssh's a command" do
+ server = OpenStruct.new(:dns_name => "test_dns")
+
+ system "echo > /dev/null" # to populate $?
+ Kernel.should_receive(:system).with("ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i #{Boucher::Config[:aws_key_filename]}.pem #{Boucher::Config[:username]}@test_dns \"some command\"")
+
+ Boucher.ssh(server, "some command")
+ end
+
+ it "downloads a file" do
+ server = stub(:dns_name => "test_dns")
+ Kernel.should_receive(:system).with("rsync", "-azb", "-e", Boucher.ssh_command, "--delete-after", "#{Boucher::Config[:username]}@test_dns:/usr/lib/a_file.txt", "/usr/local/local_file.txt")
+ Boucher.download(server, "/usr/lib/a_file.txt", "/usr/local/local_file.txt")
+ end
+
+ it "rsyncs files" do
+ server = stub(:dns_name => "test_dns")
+
+ system "echo > /dev/null" # to populate $?
+ Kernel.should_receive(:system).with("rsync", "-azb", "-e", Boucher.ssh_command,
+ "--delete-after", "foo", "#{Boucher::Config[:username]}@test_dns:bar")
+
+ Boucher.rsync(server, "foo", "bar")
+ end
+
+ it "opens an ssh shell" do
+ server = OpenStruct.new(:dns_name => "test_dns")
+
+ system "echo > /dev/null" # to populate $?
+ Kernel.should_receive(:system).with("ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i #{Boucher::Config[:aws_key_filename]}.pem #{Boucher::Config[:username]}@test_dns ")
+
+ Boucher.ssh(server)
+ end
+
+ it "updates recipes and rsyncs local changes" do
+ server = OpenStruct.new(:id => "test_id")
+ Boucher.should_receive(:ssh).with(server, "cd infrastructure && git checkout . && git clean -d -f && git pull && bundle")
+ Boucher.should_receive(:rsync).with(server, "cookbooks/", "infrastructure/cookbooks/")
+ Boucher.should_receive(:rsync).with(server, "config/", "infrastructure/config/")
+ Boucher.should_receive(:rsync).with(server, "tasks/", "infrastructure/tasks/")
+
+ Boucher.update_recipes(server)
+ end
+
+ it "cooks a meal" do
+ server = OpenStruct.new(:id => "test_id")
+
+ Boucher.should_receive(:update_recipes).with(server)
+ Boucher.should_receive(:ssh).with(server, "cd infrastructure && sudo BUTCHER_ENV=env_name BRANCH=branch_name chef-solo -c config/solo.rb -j config/meal_name.json")
+ Boucher::Nagios.should_receive(:remove_host).with(server)
+ Boucher::Nagios.should_receive(:add_host).with(server)
+ Boucher::Config[:branch] = "branch_name"
+ Boucher::Config[:env] = "env_name"
+
+ Boucher.cook_meal(server, "meal_name")
+ end
+end
View
16 spec/butcher/env_spec.rb → spec/boucher/env_spec.rb
@@ -12,14 +12,14 @@
it "defaults to :dev" do
ENV.delete('BUTCHER_ENV')
- #load File.expand_path(File.dirname(__FILE__) + "/../../lib/butcher/env.rb")
- Butcher::env_name.should == :dev
+ #load File.expand_path(File.dirname(__FILE__) + "/../../lib/boucher/env.rb")
+ Boucher::env_name.should == :dev
end
it "can be set via an environment variable" do
ENV['BUTCHER_ENV'] = "ci"
- load File.expand_path(File.dirname(__FILE__) + "/../../lib/butcher/env.rb")
- Butcher::env_name.should == "ci"
+ load File.expand_path(File.dirname(__FILE__) + "/../../lib/boucher/env.rb")
+ Boucher::env_name.should == "ci"
end
end
@@ -34,14 +34,14 @@
end
it "defaults to master" do
- Butcher.force_env!(:dev)
- Butcher::Config[:branch].should == "master"
+ Boucher.force_env!(:dev)
+ Boucher::Config[:branch].should == "master"
end
it "can be set via an environment variable" do
ENV['BRANCH'] = "some_branch"
- Butcher.force_env!(:dev)
- Butcher::Config[:branch].should == "some_branch"
+ Boucher.force_env!(:dev)
+ Boucher::Config[:branch].should == "some_branch"
end
end
end
View
12 spec/butcher/io_spec.rb → spec/boucher/io_spec.rb
@@ -1,15 +1,15 @@
require_relative "../spec_helper"
-require "butcher/io"
+require "boucher/io"
require 'ostruct'
-describe "Butcher IO" do
+describe "Boucher IO" do
before do
- Butcher::IO.mock!
+ Boucher::IO.mock!
end
it "prints server table header" do
- Butcher.print_server_table_header
+ Boucher.print_server_table_header
output = $stdout.string
puts "output: #{output}"
@@ -25,7 +25,7 @@
:state => "test_state",
:public_ip_address => "1.2.3.4")
- Butcher.print_server server
+ Boucher.print_server server
output = $stdout.string
output.should include("test_id")
@@ -55,7 +55,7 @@
:state => "test_state",
:public_ip_address => "1.2.3.6")
- Butcher.print_servers([server_1, server_2, server_3])
+ Boucher.print_servers([server_1, server_2, server_3])
output = $stdout.string
lines = output.split("\n")
View
77 spec/boucher/provision_spec.rb
@@ -0,0 +1,77 @@
+require_relative "../spec_helper"
+require 'boucher/provision'
+
+describe "Boucher Provisioning" do
+
+ before do
+ Boucher::Config[:elastic_ips] = nil
+ end
+
+ after do
+ Boucher::Config[:env] = "test"
+ end
+
+ describe "establish server" do
+ it "provisions a server if one does not exist" do
+ Boucher.stub(:server_classes).and_return({:class_of_server => "server details"})
+ Boucher.should_receive(:provision).with("class_of_server", "server details")
+
+ Boucher.establish_server nil, "class_of_server"
+ end
+
+ it "starts a server if it is stopped" do
+ server = mock(:id => "the id", :state => "stopped")
+ Boucher.stub(:server_classes).and_return({:class_of_server => "server details"})
+ Boucher.should_receive(:change_server_state).with("the id", :start, "running")
+ server.should_receive(:reload)
+ Boucher.should_receive(:cook_meals_on_server).with("class_of_server", "server details", server)
+
+ Boucher.establish_server server, "class_of_server"
+ end
+
+ it "attaches elastic IPs if the server was stopped" do
+ Boucher::Config[:elastic_ips] = { "class_of_server" => "1.2.3.4" }
+ server = mock(:id => "the id", :state => "stopped", :reload => nil)
+ Boucher.stub(:server_classes).and_return({:class_of_server => {:meals => []}})
+ Boucher.stub(:change_server_state)
+ Boucher.compute.should_receive(:associate_address).with(anything, "1.2.3.4")
+
+ Boucher.establish_server server, "class_of_server"
+ end
+
+ it "cooks meals on server if it is up and running" do
+ running_server = mock(:id => "the id", :state => "running")
+ Boucher.stub(:server_classes).and_return({:class_of_server => "server details"})
+ Boucher.should_receive(:cook_meals_on_server).with("class_of_server", "server details", running_server)
+
+ Boucher.establish_server running_server, "class_of_server"
+ end
+ end
+
+ describe "provision" do
+ it "provisions a server" do
+ Boucher.stub!(:ssh)
+ Boucher.should_receive(:classify)
+ Boucher.should_receive(:cook_meal).with(anything, "foo")
+
+ Boucher.provision "foo", {:meals => ["foo"]}
+ end
+
+ it "provisions a server with Procs as meals" do
+ Boucher.stub!(:ssh)
+ Boucher.should_receive(:classify)
+ Boucher.should_receive(:cook_meal).with(anything, "foo")
+
+ Boucher.provision "foo", {:meals => [lambda{"foo"}]}
+ end
+
+ it "provisions a server with elastic IP" do
+ Boucher.stub!(:ssh)
+ Boucher::Config[:elastic_ips] = { "foo" => "1.2.3.4" }
+ Boucher.should_receive(:classify)
+ Boucher.compute.should_receive(:associate_address).with(anything, "1.2.3.4")
+
+ Boucher.provision "foo", {:meals => []}
+ end
+ end
+end
View
79 spec/boucher/servers_spec.rb
@@ -0,0 +1,79 @@
+require_relative "../spec_helper"
+require 'boucher/servers'
+require 'ostruct'
+
+describe "Boucher::Servers" do
+
+ let(:remote_servers) {
+ [OpenStruct.new(:id => "s1", :tags => {"Env" => "test", "Class" => "foo"}, :state => "stopped"),
+ OpenStruct.new(:id => "s2", :tags => {"Env" => "test", "Class" => "bar"}, :state => "pending"),
+ OpenStruct.new(:id => "s3", :tags => {"Env" => "dev", "Class" => "foo"}, :state => "terminated"),
+ OpenStruct.new(:id => "s4", :tags => {"Env" => "dev", "Class" => "bar"}, :state => "running")]
+ }
+
+ before do
+ @env = Boucher::Config[:env]
+ Boucher.compute.stub(:servers).and_return(remote_servers)
+ end
+
+ after do
+ Boucher::Config[:env] = @env
+ end
+
+ it "finds all servers" do
+ Boucher::Servers.all.size.should == 4
+ Boucher::Servers.all.should == remote_servers
+ end
+
+ it "finds classed servers" do
+ Boucher::Servers.of_class("blah").should == []
+ Boucher::Servers.of_class(:foo).map(&:id).should == ["s1", "s3"]
+ Boucher::Servers.of_class("bar").map(&:id).should == ["s2", "s4"]
+ end
+
+ it "finds with env servers" do
+ Boucher::Servers.in_env("blah").should == []
+ Boucher::Servers.in_env("test").map(&:id).should == ["s1", "s2"]
+ Boucher::Servers.in_env("dev").map(&:id).should == ["s3", "s4"]
+ end
+
+ it "finds servers in a given state" do
+ Boucher::Servers.in_state("running").map(&:id).should == ["s4"]
+ Boucher::Servers.in_state("terminated").map(&:id).should == ["s3"]
+ Boucher::Servers.in_state("pending").map(&:id).should == ["s2"]
+ Boucher::Servers.in_state("stopped").map(&:id).should == ["s1"]
+ end
+
+ it "finds the first matching server" do
+ Boucher::Servers.find.id.should == "s1"
+ Boucher::Servers.find(:class => "foo").id.should == "s1"
+ Boucher::Servers.find(:class => "bar").id.should == "s2"
+ Boucher::Servers.find(:env => "test").id.should == "s1"
+ Boucher::Servers.find(:env => "dev").id.should == "s3"
+ Boucher::Servers.find(:class => "foo", :env => "test").id.should == "s1"
+ Boucher::Servers.find(:class => "foo", :env => "dev").id.should == "s3"
+ Boucher::Servers.find(:class => "bar", :env => "test").id.should == "s2"
+ Boucher::Servers.find(:class => "bar", :env => "dev").id.should == "s4"
+ expect { Boucher::Servers.find(:class => "blah", :env => "dev") }.to raise_error
+ expect { Boucher::Servers.find(:class => "foo", :env => "blah") }.to raise_error
+ end
+
+ it "raises an error if find returns no results" do
+ expect { Boucher::Servers.find(:class => "blah") }.to raise_error(Boucher::Servers::NotFound)
+ end
+
+ it "gets a server based on current env when all the servers are running" do
+ Boucher::Config[:env] = "test"
+ expect { Boucher::Servers["foo"] }.to raise_error
+ expect { Boucher::Servers["bar"] }.to raise_error
+
+ Boucher::Config[:env] = "dev"
+ expect { Boucher::Servers["foo"] }.to raise_error
+ Boucher::Servers["bar"].id.should == "s4"
+ end
+
+ it "stops a server" do
+ Boucher.should_receive(:change_server_state).with("the id", :stop, "stopped")
+ Boucher::Servers.stop("the id")
+ end
+end
View
22 spec/butcher/storage_spec.rb → spec/boucher/storage_spec.rb
@@ -1,19 +1,19 @@
require_relative "../spec_helper"
-require 'butcher/storage'
+require 'boucher/storage'
require 'ostruct'
-describe "Butcher Storage" do
+describe "Boucher Storage" do
it "knows connections options" do
- connection = Butcher.storage
+ connection = Boucher.storage
connection.should_not == nil
- Butcher::S3_CONFIG[:aws_secret_access_key].should == Butcher::Config[:aws_secret_access_key]
- Butcher::S3_CONFIG[:aws_access_key_id].should == Butcher::Config[:aws_access_key_id]
+ Boucher::S3_CONFIG[:aws_secret_access_key].should == Boucher::Config[:aws_secret_access_key]
+ Boucher::S3_CONFIG[:aws_access_key_id].should == Boucher::Config[:aws_access_key_id]
end
context "with dir" do
before do
- Butcher.storage.directories.create(:key => "test_bucket")
+ Boucher.storage.directories.create(:key => "test_bucket")
File.open("test_file.txt", "w") { |f| f.write "wakka wakka" }
end
@@ -23,24 +23,24 @@
end
it "puts a file" do
- Butcher::Storage.put("test_bucket", "test_file", "test_file.txt")
- dir = Butcher.storage.directories.get("test_bucket")
+ Boucher::Storage.put("test_bucket", "test_file", "test_file.txt")
+ dir = Boucher.storage.directories.get("test_bucket")
file = dir.files.get("test_file")
file.body.should == "wakka wakka"
end
it "gets a file" do
- Butcher::Storage.put("test_bucket", "test_file", "test_file.txt")
+ Boucher::Storage.put("test_bucket", "test_file", "test_file.txt")
time = Time.now
Time.stub!(:now).and_return(time)
Kernel.should_receive(:system) do |*args|
args[0].should == "curl"
- args[1].should == Butcher.storage.directories.get("test_bucket").files.get_https_url("test_file", time + 3600)
+ args[1].should == Boucher.storage.directories.get("test_bucket").files.get_https_url("test_file", time + 3600)
args[2].should == "-o"
args[3].should == "test_file2.txt"
end
- Butcher::Storage.get("test_bucket", "test_file", "test_file2.txt")
+ Boucher::Storage.get("test_bucket", "test_file", "test_file2.txt")
end
end
View
75 spec/butcher/compute_spec.rb
@@ -1,75 +0,0 @@
-require_relative "../spec_helper"
-require 'butcher/compute'
-require 'butcher/nagios'
-require 'ostruct'
-
-describe "Butcher Cloud" do
-
- after do
- Butcher::Config[:env] = "dev"
- end
-
- it "knows connections options" do
- connection = Butcher.compute
- connection.should_not == nil
- Butcher::EC2_CONFIG[:aws_secret_access_key].should == "secret key"
- Butcher::EC2_CONFIG[:aws_access_key_id].should == "public id"
- end
-
- it "ssh's a command" do
- server = OpenStruct.new(:dns_name => "test_dns")
-
- system "echo > /dev/null" # to populate $?
- Kernel.should_receive(:system).with("ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i #{Butcher::Config[:aws_key_filename]}.pem #{Butcher::Config[:username]}@test_dns \"some command\"")
-
- Butcher.ssh(server, "some command")
- end
-
- it "downloads a file" do
- server = stub(:dns_name => "test_dns")
- Kernel.should_receive(:system).with("rsync", "-azb", "-e", Butcher.ssh_command, "--delete-after", "#{Butcher::Config[:username]}@test_dns:/usr/lib/a_file.txt", "/usr/local/local_file.txt")
- Butcher.download(server, "/usr/lib/a_file.txt", "/usr/local/local_file.txt")
- end
-
- it "rsyncs files" do
- server = stub(:dns_name => "test_dns")
-
- system "echo > /dev/null" # to populate $?
- Kernel.should_receive(:system).with("rsync", "-azb", "-e", Butcher.ssh_command,
- "--delete-after", "foo", "#{Butcher::Config[:username]}@test_dns:bar")
-
- Butcher.rsync(server, "foo", "bar")
- end
-
- it "opens an ssh shell" do
- server = OpenStruct.new(:dns_name => "test_dns")
-
- system "echo > /dev/null" # to populate $?
- Kernel.should_receive(:system).with("ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i #{Butcher::Config[:aws_key_filename]}.pem #{Butcher::Config[:username]}@test_dns ")
-
- Butcher.ssh(server)
- end
-
- it "updates recipes and rsyncs local changes" do
- server = OpenStruct.new(:id => "test_id")
- Butcher.should_receive(:ssh).with(server, "cd infrastructure && git checkout . && git clean -d -f && git pull && bundle")
- Butcher.should_receive(:rsync).with(server, "cookbooks/", "infrastructure/cookbooks/")
- Butcher.should_receive(:rsync).with(server, "config/", "infrastructure/config/")
- Butcher.should_receive(:rsync).with(server, "tasks/", "infrastructure/tasks/")
-
- Butcher.update_recipes(server)
- end
-
- it "cooks a meal" do
- server = OpenStruct.new(:id => "test_id")
-
- Butcher.should_receive(:update_recipes).with(server)
- Butcher.should_receive(:ssh).with(server, "cd infrastructure && sudo BUTCHER_ENV=env_name BRANCH=branch_name chef-solo -c config/solo.rb -j config/meal_name.json")
- Butcher::Nagios.should_receive(:remove_host).with(server)
- Butcher::Nagios.should_receive(:add_host).with(server)
- Butcher::Config[:branch] = "branch_name"
- Butcher::Config[:env] = "env_name"
-
- Butcher.cook_meal(server, "meal_name")
- end
-end
View
77 spec/butcher/provision_spec.rb
@@ -1,77 +0,0 @@
-require_relative "../spec_helper"
-require 'butcher/provision'
-
-describe "Butcher Provisioning" do
-
- before do
- Butcher::Config[:elastic_ips] = nil
- end
-
- after do
- Butcher::Config[:env] = "test"
- end
-
- describe "establish server" do
- it "provisions a server if one does not exist" do
- Butcher.stub(:server_classes).and_return({:class_of_server => "server details"})
- Butcher.should_receive(:provision).with("class_of_server", "server details")
-
- Butcher.establish_server nil, "class_of_server"
- end
-
- it "starts a server if it is stopped" do
- server = mock(:id => "the id", :state => "stopped")
- Butcher.stub(:server_classes).and_return({:class_of_server => "server details"})
- Butcher.should_receive(:change_server_state).with("the id", :start, "running")
- server.should_receive(:reload)
- Butcher.should_receive(:cook_meals_on_server).with("class_of_server", "server details", server)
-
- Butcher.establish_server server, "class_of_server"
- end
-
- it "attaches elastic IPs if the server was stopped" do
- Butcher::Config[:elastic_ips] = { "class_of_server" => "1.2.3.4" }
- server = mock(:id => "the id", :state => "stopped", :reload => nil)
- Butcher.stub(:server_classes).and_return({:class_of_server => {:meals => []}})
- Butcher.stub(:change_server_state)
- Butcher.compute.should_receive(:associate_address).with(anything, "1.2.3.4")
-
- Butcher.establish_server server, "class_of_server"
- end
-
- it "cooks meals on server if it is up and running" do
- running_server = mock(:id => "the id", :state => "running")
- Butcher.stub(:server_classes).and_return({:class_of_server => "server details"})
- Butcher.should_receive(:cook_meals_on_server).with("class_of_server", "server details", running_server)
-
- Butcher.establish_server running_server, "class_of_server"
- end
- end
-
- describe "provision" do
- it "provisions a server" do
- Butcher.stub!(:ssh)
- Butcher.should_receive(:classify)
- Butcher.should_receive(:cook_meal).with(anything, "foo")
-
- Butcher.provision "foo", {:meals => ["foo"]}
- end
-
- it "provisions a server with Procs as meals" do
- Butcher.stub!(:ssh)
- Butcher.should_receive(:classify)
- Butcher.should_receive(:cook_meal).with(anything, "foo")
-
- Butcher.provision "foo", {:meals => [lambda{"foo"}]}
- end
-
- it "provisions a server with elastic IP" do
- Butcher.stub!(:ssh)
- Butcher::Config[:elastic_ips] = { "foo" => "1.2.3.4" }
- Butcher.should_receive(:classify)
- Butcher.compute.should_receive(:associate_address).with(anything, "1.2.3.4")
-
- Butcher.provision "foo", {:meals => []}
- end
- end
-end
View
79 spec/butcher/servers_spec.rb
@@ -1,79 +0,0 @@
-require_relative "../spec_helper"
-require 'butcher/servers'
-require 'ostruct'
-
-describe "Butcher::Servers" do
-
- let(:remote_servers) {
- [OpenStruct.new(:id => "s1", :tags => {"Env" => "test", "Class" => "foo"}, :state => "stopped"),
- OpenStruct.new(:id => "s2", :tags => {"Env" => "test", "Class" => "bar"}, :state => "pending"),
- OpenStruct.new(:id => "s3", :tags => {"Env" => "dev", "Class" => "foo"}, :state => "terminated"),
- OpenStruct.new(:id => "s4", :tags => {"Env" => "dev", "Class" => "bar"}, :state => "running")]
- }
-
- before do
- @env = Butcher::Config[:env]
- Butcher.compute.stub(:servers).and_return(remote_servers)
- end
-
- after do
- Butcher::Config[:env] = @env
- end
-
- it "finds all servers" do
- Butcher::Servers.all.size.should == 4
- Butcher::Servers.all.should == remote_servers
- end
-
- it "finds classed servers" do
- Butcher::Servers.of_class("blah").should == []
- Butcher::Servers.of_class(:foo).map(&:id).should == ["s1", "s3"]
- Butcher::Servers.of_class("bar").map(&:id).should == ["s2", "s4"]
- end
-
- it "finds with env servers" do
- Butcher::Servers.in_env("blah").should == []
- Butcher::Servers.in_env("test").map(&:id).should == ["s1", "s2"]
- Butcher::Servers.in_env("dev").map(&:id).should == ["s3", "s4"]
- end
-
- it "finds servers in a given state" do
- Butcher::Servers.in_state("running").map(&:id).should == ["s4"]
- Butcher::Servers.in_state("terminated").map(&:id).should == ["s3"]
- Butcher::Servers.in_state("pending").map(&:id).should == ["s2"]
- Butcher::Servers.in_state("stopped").map(&:id).should == ["s1"]
- end
-
- it "finds the first matching server" do
- Butcher::Servers.find.id.should == "s1"
- Butcher::Servers.find(:class => "foo").id.should == "s1"
- Butcher::Servers.find(:class => "bar").id.should == "s2"
- Butcher::Servers.find(:env => "test").id.should == "s1"
- Butcher::Servers.find(:env => "dev").id.should == "s3"
- Butcher::Servers.find(:class => "foo", :env => "test").id.should == "s1"
- Butcher::Servers.find(:class => "foo", :env => "dev").id.should == "s3"
- Butcher::Servers.find(:class => "bar", :env => "test").id.should == "s2"
- Butcher::Servers.find(:class => "bar", :env => "dev").id.should == "s4"
- expect { Butcher::Servers.find(:class => "blah", :env => "dev") }.to raise_error
- expect { Butcher::Servers.find(:class => "foo", :env => "blah") }.to raise_error
- end
-
- it "raises an error if find returns no results" do
- expect { Butcher::Servers.find(:class => "blah") }.to raise_error(Butcher::Servers::NotFound)
- end
-
- it "gets a server based on current env when all the servers are running" do
- Butcher::Config[:env] = "test"
- expect { Butcher::Servers["foo"] }.to raise_error
- expect { Butcher::Servers["bar"] }.to raise_error
-
- Butcher::Config[:env] = "dev"
- expect { Butcher::Servers["foo"] }.to raise_error
- Butcher::Servers["bar"].id.should == "s4"
- end
-
- it "stops a server" do
- Butcher.should_receive(:change_server_state).with("the id", :stop, "stopped")
- Butcher::Servers.stop("the id")
- end
-end
View
10 spec/spec_helper.rb
@@ -1,5 +1,5 @@
# MDM - Need to set config because it's never loaded in test
-module Butcher
+module Boucher
NO_LOAD_CONFIG = true
Config = {
:aws_secret_access_key => "secret key",
@@ -9,13 +9,13 @@ module Butcher
end
require 'fog'
-require 'butcher/io'
-require 'butcher/env'
+require 'boucher/io'
+require 'boucher/env'
-Butcher.force_env!("dev")
+Boucher.force_env!("dev")
Fog.mock!
-Butcher::IO.mock!
+Boucher::IO.mock!
# MDM - Monkey patch wait_for methods so the tests are FASTER!

0 comments on commit 5be6c6c

Please sign in to comment.
Something went wrong with that request. Please try again.