Skip to content

Commit

Permalink
Test maintenance page commands for real
Browse files Browse the repository at this point in the history
This now runs maintenance tests against a deployed release
  • Loading branch information
Daniela Wellisz & Martin Emde committed Sep 18, 2014
1 parent 0574866 commit 509b6dd
Show file tree
Hide file tree
Showing 11 changed files with 116 additions and 83 deletions.
2 changes: 0 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
source 'https://rubygems.org'
gemspec

gem 'pry'
2 changes: 1 addition & 1 deletion engineyard-serverside.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Gem::Specification.new do |s|
s.add_development_dependency('timecop', '0.6.1')
s.add_development_dependency('simplecov')
s.add_development_dependency('engineyard-cloud-client', '~>1.0.14')
s.add_development_dependency('engineyard-serverside-adapter', '~>2.2.0')
s.add_development_dependency('engineyard-serverside-adapter', '~>2.3.1')
s.add_development_dependency('sqlite3')
s.add_development_dependency('mime-types', '~>1.25')

Expand Down
6 changes: 0 additions & 6 deletions lib/engineyard-serverside/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ def deploy(default_task=:deploy)
verbose_option
desc "enable_maintenance", "Enable maintenance page (disables web access)"
def enable_maintenance
options = self.options.dup
options[:release_path] = Pathname.new("/data/#{options[:app]}/current").realpath.to_s

init_and_propagate(options, 'enable_maintenance') do |servers, config, shell|
EY::Serverside::Maintenance.new(servers, config, shell).manually_enable
end
Expand All @@ -71,9 +68,6 @@ def enable_maintenance
verbose_option
desc "disable_maintenance", "Disable maintenance page (enables web access)"
def disable_maintenance
options = self.options.dup
options[:release_path] = Pathname.new("/data/#{options[:app]}/current").realpath.to_s

init_and_propagate(options, 'disable_maintenance') do |servers, config, shell|
EY::Serverside::Maintenance.new(servers, config, shell).manually_disable
end
Expand Down
1 change: 1 addition & 0 deletions lib/engineyard-serverside/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ def new_release(&block)

# task
def copy_repository_cache
paths.new_release!
shell.status "Copying to #{paths.active_release}"
exclusions = Array(config.copy_exclude).map { |e| %|--exclude="#{e}"| }.join(' ')
run("mkdir -p #{paths.active_release} #{paths.shared_config} && rsync -aq #{exclusions} #{paths.repository_cache}/ #{paths.active_release}")
Expand Down
6 changes: 3 additions & 3 deletions lib/engineyard-serverside/maintenance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module EY
module Serverside
class Maintenance

attr_reader :config, :shell

def initialize(servers, config, shell)
@servers, @config, @shell = servers, config, shell
end
Expand Down Expand Up @@ -50,8 +52,6 @@ def conditionally_disable

protected

attr_reader :config, :shell

def using_maintenance_page?
config.maintenance_on_restart? || (config.migrate? && config.maintenance_on_migrate?)
end
Expand Down Expand Up @@ -109,7 +109,7 @@ def explain_not_enabling
end

def public_system_symlink_warning
if paths.public_system.realpath != maintenance_page_dirname.realpath
if paths.active_release.join('public','system').realpath != maintenance_page_dirname.realpath
shell.warning <<-WARN
Current repository layout does not allow for maintenance pages!
Web traffic may still be served to your application.
Expand Down
17 changes: 13 additions & 4 deletions lib/engineyard-serverside/paths.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,19 @@ def initialize(opts)
@deploy_root = Pathname.new(@opts[:deploy_root] || "/data/#{@app_name}")
end

def release_dirname
Time.now.utc.strftime("%Y%m%d%H%M%S")
end

def new_release!
@active_release = path(:releases, release_dirname)
end

# If no active release is defined, use current
def active_release
@active_release || latest_release
end

def deploy_key
path(:home, '.ssh', "#{@app_name}-deploy-key")
end
Expand All @@ -116,10 +129,6 @@ def repository_cache
@repository_cache ||= default_repository_cache
end

def active_release
@active_release ||= path(:releases, Time.now.utc.strftime("%Y%m%d%H%M%S"))
end

def all_releases
@all_releases ||= Pathname.glob(releases.join('*')).sort
end
Expand Down
1 change: 0 additions & 1 deletion spec/archive_deploy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def fetch_command
args.serverside_version = Gem::Version.create(EY::Serverside::VERSION.dup).release
args.config = {
"deploy_to" => deploy_dir,
"release_path" => release_path.to_s,
"group" => GROUP
}
end
Expand Down
55 changes: 21 additions & 34 deletions spec/custom_deploy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,37 @@
describe "the EY::Serverside::Deploy API" do
it "calls tasks in the right order" do
class TestDeploy < FullTestDeploy
# This happens before require_custom_tasks, so it's not
# overrideable. That's why it's not in @call_order.
def update_repository_cache() end
def check_repository() end

# cheat a bit; we don't actually want to do these things
def require_custom_tasks() end
def callback(*_) end

attr_reader :call_order
def initialize(*a)
super
@call_order = []
end

def run(*)
end

def sudo(*)
end

def push_code() @call_order << 'push_code' end
def copy_repository_cache() @call_order << 'copy_repository_cache' end
def create_revision_file() @call_order << 'create_revision_file' end
def bundle() @call_order << 'bundle' end
def setup_services() @call_order << 'setup_services' end
def symlink_configs() @call_order << 'symlink_configs' end
def migrate() @call_order << 'migrate' end
def compile_assets() @call_order << 'compile_assets' end
def symlink() @call_order << 'symlink' end
def restart() @call_order << 'restart' end
def cleanup_old_releases() @call_order << 'cleanup_old_releases' end
def enable_maintenance_page() @call_order << 'enable_maintenance_page' end
def disable_maintenance_page() @call_order << 'disable_maintenance_page' end
def gc_repository_cache() @call_order << 'gc_repository_cache' end
def push_code() @call_order << 'push_code' ; super end
def copy_repository_cache() @call_order << 'copy_repository_cache' ; super end
def create_revision_file() @call_order << 'create_revision_file' ; super end
def bundle() @call_order << 'bundle' ; super end
def setup_services() @call_order << 'setup_services' ; super end
def symlink_configs() @call_order << 'symlink_configs' ; super end
def migrate() @call_order << 'migrate' ; super end
def compile_assets() @call_order << 'compile_assets' ; super end
def symlink() @call_order << 'symlink' ; super end
def restart() @call_order << 'restart' ; super end
def cleanup_old_releases() @call_order << 'cleanup_old_releases' ; super end
def enable_maintenance_page() @call_order << 'enable_maintenance_page' ; super end
def disable_maintenance_page() @call_order << 'disable_maintenance_page'; super end
def gc_repository_cache() @call_order << 'gc_repository_cache' ; super end
end

config = EY::Serverside::Deploy::Configuration.new({
'app' => 'app_name',
'framework_env' => 'staging',
})
config = EY::Serverside::Deploy::Configuration.new(default_configuration)

td = TestDeploy.realnew(test_servers, config, test_shell)
td.deploy
mock_bundler
with_mocked_commands do
capture do
td.deploy
end
end

############################# IMPORTANT ####################################
#
Expand Down
19 changes: 11 additions & 8 deletions spec/deploy_hook_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

it "prints the failure to the log even when non-verbose" do
out = read_output
expect(out).to match(%r|FATAL: Exception raised in deploy hook .*/before_deploy.rb.|)
expect(out).to match(%r|FATAL: Exception raised in deploy hook .*/deploy/before_deploy.rb.|)
expect(out).to match(%r|RuntimeError:.*Hook failing in \(eval\)|)
expect(out).to match(%r|Please fix this error before retrying.|)
end
Expand Down Expand Up @@ -68,13 +68,16 @@
end

context "deploy hook API" do

def deploy_hook(options={})
config = EY::Serverside::Deploy::Configuration.new({
'app' => 'app_name',
'framework_env' => 'staging',
'current_roles' => ['solo'],
'deploy_to' => deploy_dir.to_s,
}.merge(options))
# setup to run hooks since a deploy hasn't happened
config.paths.new_release!
config.paths.active_release.mkpath
EY::Serverside::DeployHook.new(config, test_shell, 'fake_test_hook')
end

Expand Down Expand Up @@ -102,7 +105,7 @@ def deploy_hook(options={})
deploy_hook.eval_hook('run!("false")')
}.to raise_error(RuntimeError)
out = read_output
expect(out).to match(%r|FATAL: Exception raised in deploy hook /data/app_name/releases/\d+/deploy/fake_test_hook.rb.|)
expect(out).to match(%r|FATAL: Exception raised in deploy hook .*/deploy/fake_test_hook.rb.|)
expect(out).to match(%r|RuntimeError: .*run!.*Command failed. false|)
expect(out).to match(%r|Please fix this error before retrying.|)
end
Expand All @@ -128,7 +131,7 @@ def deploy_hook(options={})
}.to raise_error(RuntimeError)
end
out = read_output
expect(out).to match(%r|FATAL: Exception raised in deploy hook /data/app_name/releases/\d+/deploy/fake_test_hook.rb.|)
expect(out).to match(%r|FATAL: Exception raised in deploy hook .*/deploy/fake_test_hook.rb.|)
expect(out).to match(%r|RuntimeError: .*sudo!.*Command failed. false|)
expect(out).to match(%r|Please fix this error before retrying.|)
end
Expand All @@ -150,7 +153,7 @@ def deploy_hook(options={})
expect(deploy_hook.eval_hook('shared_path.nil?')).to be_false
out = read_output
expect(out).to include("Use of `shared_path` (via method_missing) is deprecated in favor of `config.shared_path` for improved error messages and compatibility.")
expect(out).to match(%r|in /data/app_name/releases/\d+/deploy/fake_test_hook.rb|)
expect(out).to match(%r|in .*/deploy/fake_test_hook.rb|)
end
end

Expand Down Expand Up @@ -190,7 +193,7 @@ def deploy_hook(options={})
out = read_output
expect(out).to match(%r|Use of `@node` in deploy hooks is deprecated.|)
expect(out).to match(%r|Please use `config.node`, which provides access to the same object.|)
expect(out).to match(%r|/data/app_name/releases/\d+/deploy/fake_test_hook.rb|)
expect(out).to match(%r|.*/deploy/fake_test_hook.rb|)
end

it "is available" do
Expand Down Expand Up @@ -219,7 +222,7 @@ def deploy_hook(options={})
out = read_output
expect(out).to match(%r|Use of `@configuration` in deploy hooks is deprecated.|)
expect(out).to match(%r|Please use `config`, which provides access to the same object.|)
expect(out).to match(%r|/data/app_name/releases/\d+/deploy/fake_test_hook.rb|)
expect(out).to match(%r|.*/deploy/fake_test_hook.rb|)
end

it "has the configuration in it" do
Expand Down Expand Up @@ -336,7 +339,7 @@ def where_code_runs_with(code)
deploy_hook.eval_hook('methedo_no_existo')
}.to raise_error(NameError)
out = read_output
expect(out).to match(%r|FATAL: Exception raised in deploy hook /data/app_name/releases/\d+/deploy/fake_test_hook.rb.|)
expect(out).to match(%r|FATAL: Exception raised in deploy hook .*/deploy/fake_test_hook.rb.|)
expect(out).to match(%r|NameError: undefined local variable or method `methedo_no_existo' for|)
expect(out).to match(%r|Please fix this error before retrying.|)
end
Expand Down
23 changes: 23 additions & 0 deletions spec/maintenance_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require 'spec_helper'

describe EY::Serverside::Maintenance do
let(:maintenance_path) { deploy_dir.join('shared', 'system', 'maintenance.html') }

context "deployed application" do
before do
deploy_test_application
end

it "enables the maintenance page" do
enable_maintenance
expect(maintenance_path).to exist
end

it "disables an enabled maintenance page" do
enable_maintenance
expect(maintenance_path).to exist
disable_maintenance
expect(maintenance_path).to_not exist
end
end
end
Loading

0 comments on commit 509b6dd

Please sign in to comment.