simple_deploy 0.5.6 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +4 -0
- data/CHANGELOG +8 -0
- data/README.md +2 -0
- data/lib/simple_deploy/cli/execute.rb +57 -0
- data/lib/simple_deploy/cli.rb +5 -2
- data/lib/simple_deploy/logger.rb +7 -0
- data/lib/simple_deploy/stack/deployment/status.rb +4 -4
- data/lib/simple_deploy/stack/deployment.rb +50 -86
- data/lib/simple_deploy/stack/execute.rb +36 -0
- data/lib/simple_deploy/stack/ssh.rb +93 -0
- data/lib/simple_deploy/stack.rb +15 -1
- data/lib/simple_deploy/version.rb +1 -1
- data/simple_deploy.gemspec +6 -5
- data/spec/logger_spec.rb +29 -23
- data/spec/stack/deployment/status_spec.rb +63 -1
- data/spec/stack/deployment_spec.rb +120 -90
- data/spec/stack/execute_spec.rb +27 -0
- data/spec/stack/ssh_spec.rb +86 -0
- data/spec/stack_spec.rb +67 -15
- metadata +47 -18
- data/script/ci_setup +0 -16
data/.travis.yml
ADDED
data/CHANGELOG
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
## v0.6.0
|
2
|
+
|
3
|
+
* Updated so it no longer caches simpledb attributes so it works better with stackster changes
|
4
|
+
* Upgraded to stackster 0.3.2
|
5
|
+
* Added execute subcommand to run arbitray commands against stack
|
6
|
+
* Refactored deployment to use ssh library
|
7
|
+
* Added specs
|
8
|
+
|
1
9
|
## v0.5.6
|
2
10
|
|
3
11
|
* Corrected the instances command so it returns all instances
|
data/README.md
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
[![Build Status](https://secure.travis-ci.org/intuit/simple_deploy.png)](http://travis-ci.org/intuit/simple_deploy)
|
2
|
+
|
1
3
|
I use the stackster to manage stacks, however I understand how to connect to different regions / accounts as well as kick off a deployment on instances.
|
2
4
|
|
3
5
|
Getting Started
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'trollop'
|
2
|
+
|
3
|
+
module SimpleDeploy
|
4
|
+
module CLI
|
5
|
+
class Execute
|
6
|
+
def execute
|
7
|
+
opts = Trollop::options do
|
8
|
+
version SimpleDeploy::VERSION
|
9
|
+
banner <<-EOS
|
10
|
+
|
11
|
+
Execute command on given stack(s).
|
12
|
+
|
13
|
+
simple_deploy execute -n STACK_NAME -n STACK_NAME -e ENVIRONMENT -c "COMMAND"
|
14
|
+
|
15
|
+
Using Internal IP for SSH:
|
16
|
+
|
17
|
+
Simple deploy defaults to using the public IP when ssh'ng to stacks. This option instructs it
|
18
|
+
to use the private IP, which is needed when ssh'ng from one stack to another.
|
19
|
+
|
20
|
+
simple_deploy deploy -n STACK_NAME -n STACK_NAME -e ENVIRONMENT -i
|
21
|
+
|
22
|
+
EOS
|
23
|
+
opt :help, "Display Help"
|
24
|
+
opt :attributes, "= seperated attribute and it's value", :type => :string,
|
25
|
+
:multi => true
|
26
|
+
opt :command, "Command to execute.", :type => :string
|
27
|
+
opt :environment, "Set the target environment", :type => :string
|
28
|
+
opt :internal, "Use internal IP for ssh commands"
|
29
|
+
opt :log_level, "Log level: debug, info, warn, error", :type => :string,
|
30
|
+
:default => 'info'
|
31
|
+
opt :name, "Stack name(s) of stack to deploy", :type => :string,
|
32
|
+
:multi => true
|
33
|
+
opt :sudo, "Execute command with sudo"
|
34
|
+
end
|
35
|
+
|
36
|
+
CLI::Shared.valid_options? :provided => opts,
|
37
|
+
:required => [:environment, :name]
|
38
|
+
|
39
|
+
logger = SimpleDeployLogger.new :log_level => opts[:log_level]
|
40
|
+
|
41
|
+
opts[:name].each do |name|
|
42
|
+
notifier = Notifier.new :stack_name => name,
|
43
|
+
:environment => opts[:environment],
|
44
|
+
:logger => logger
|
45
|
+
|
46
|
+
stack = Stack.new :environment => opts[:environment],
|
47
|
+
:name => name,
|
48
|
+
:logger => logger,
|
49
|
+
:internal => opts[:internal]
|
50
|
+
|
51
|
+
stack.execute :command => opts[:command],
|
52
|
+
:sudo => opts[:sudo]
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/lib/simple_deploy/cli.rb
CHANGED
@@ -8,6 +8,7 @@ require 'simple_deploy/cli/create'
|
|
8
8
|
require 'simple_deploy/cli/deploy'
|
9
9
|
require 'simple_deploy/cli/destroy'
|
10
10
|
require 'simple_deploy/cli/events'
|
11
|
+
require 'simple_deploy/cli/execute'
|
11
12
|
require 'simple_deploy/cli/instances'
|
12
13
|
require 'simple_deploy/cli/list'
|
13
14
|
require 'simple_deploy/cli/outputs'
|
@@ -39,6 +40,8 @@ module SimpleDeploy
|
|
39
40
|
CLI::List.new.environments
|
40
41
|
when 'events'
|
41
42
|
CLI::Events.new.show
|
43
|
+
when 'execute'
|
44
|
+
CLI::Execute.new.execute
|
42
45
|
when 'instances'
|
43
46
|
CLI::Instances.new.list
|
44
47
|
when 'list'
|
@@ -60,13 +63,13 @@ module SimpleDeploy
|
|
60
63
|
when 'update'
|
61
64
|
CLI::Update.new.update
|
62
65
|
when '-h'
|
63
|
-
puts "simple_deploy [attributes|clone|create|destroy|environments|events|instances|list|template|outputs|parameters|protect|resources|ssh|status|update] [options]"
|
66
|
+
puts "simple_deploy [attributes|clone|create|destroy|environments|events|execute|instances|list|template|outputs|parameters|protect|resources|ssh|status|update] [options]"
|
64
67
|
puts "Append -h for help on specific subcommand."
|
65
68
|
when '-v'
|
66
69
|
puts SimpleDeploy::VERSION
|
67
70
|
else
|
68
71
|
puts "Unknown command: '#{cmd}'."
|
69
|
-
puts "simple_deploy [attributes|clone|create|destroy|environments|events|instances|list|template|outputs|parameters|protect|resources|ssh|status|update] [options]"
|
72
|
+
puts "simple_deploy [attributes|clone|create|destroy|environments|events|execute|instances|list|template|outputs|parameters|protect|resources|ssh|status|update] [options]"
|
70
73
|
puts "Append -h for help on specific subcommand."
|
71
74
|
exit 1
|
72
75
|
end
|
data/lib/simple_deploy/logger.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
1
3
|
module SimpleDeploy
|
2
4
|
class SimpleDeployLogger
|
3
5
|
|
@@ -22,6 +24,11 @@ module SimpleDeploy
|
|
22
24
|
Logger.const_get @log_level.upcase
|
23
25
|
end
|
24
26
|
|
27
|
+
# Added to support capistrano version 2.13.5
|
28
|
+
def tty?
|
29
|
+
nil
|
30
|
+
end
|
31
|
+
|
25
32
|
private
|
26
33
|
|
27
34
|
def new_logger(args)
|
@@ -4,11 +4,11 @@ module SimpleDeploy
|
|
4
4
|
class Status
|
5
5
|
|
6
6
|
def initialize(args)
|
7
|
-
@config
|
8
|
-
@stack
|
7
|
+
@config = args[:config]
|
8
|
+
@stack = args[:stack]
|
9
9
|
@ssh_user = args[:ssh_user]
|
10
|
-
@name
|
11
|
-
@logger
|
10
|
+
@name = args[:name]
|
11
|
+
@logger = @config.logger
|
12
12
|
end
|
13
13
|
|
14
14
|
def clear_for_deployment?
|
@@ -2,54 +2,36 @@ require 'capistrano'
|
|
2
2
|
require 'capistrano/cli'
|
3
3
|
|
4
4
|
require 'simple_deploy/stack/deployment/status'
|
5
|
+
require 'simple_deploy/stack/execute'
|
5
6
|
|
6
7
|
module SimpleDeploy
|
7
8
|
class Stack
|
9
|
+
|
8
10
|
class Deployment
|
11
|
+
|
9
12
|
def initialize(args)
|
10
|
-
@config
|
11
|
-
@instances
|
13
|
+
@config = args[:config]
|
14
|
+
@instances = args[:instances]
|
12
15
|
@environment = args[:environment]
|
13
|
-
@ssh_user
|
14
|
-
@ssh_key
|
15
|
-
@stack
|
16
|
-
@name
|
17
|
-
@
|
18
|
-
@
|
19
|
-
@region = @config.region @environment
|
20
|
-
end
|
21
|
-
|
22
|
-
def create_deployment
|
23
|
-
if @instances.nil? || @instances.empty?
|
24
|
-
raise "There are no running instances to deploy to"
|
25
|
-
end
|
26
|
-
|
27
|
-
@deployment = Capistrano::Configuration.new :output => @logger
|
28
|
-
@deployment.logger.level = 3
|
29
|
-
@logger.info "Creating deployment to #{@name}."
|
30
|
-
|
31
|
-
set_ssh_gateway
|
32
|
-
set_ssh_user
|
33
|
-
set_ssh_options
|
34
|
-
set_instances
|
35
|
-
set_deploy_command
|
16
|
+
@ssh_user = args[:ssh_user]
|
17
|
+
@ssh_key = args[:ssh_key]
|
18
|
+
@stack = args[:stack]
|
19
|
+
@name = args[:name]
|
20
|
+
@logger = @config.logger
|
21
|
+
@region = @config.region @environment
|
36
22
|
end
|
37
23
|
|
38
|
-
def execute(force
|
39
|
-
|
40
|
-
clear_deployment_lock true
|
41
|
-
|
42
|
-
Backoff.exp_periods do |p|
|
43
|
-
sleep p
|
44
|
-
break if clear_for_deployment?
|
45
|
-
end
|
46
|
-
end
|
24
|
+
def execute(force=false)
|
25
|
+
wait_for_clear_to_deploy(force)
|
47
26
|
|
48
27
|
if clear_for_deployment?
|
49
28
|
status.set_deployment_in_progress
|
29
|
+
|
50
30
|
@logger.info 'Starting deployment.'
|
51
|
-
|
31
|
+
executer.execute :sudo => true,
|
32
|
+
:command => deploy_command
|
52
33
|
@logger.info 'Deployment complete.'
|
34
|
+
|
53
35
|
status.unset_deployment_in_progress
|
54
36
|
true
|
55
37
|
else
|
@@ -58,50 +40,44 @@ module SimpleDeploy
|
|
58
40
|
end
|
59
41
|
end
|
60
42
|
|
43
|
+
def clear_deployment_lock(force = false)
|
44
|
+
status.clear_deployment_lock force
|
45
|
+
end
|
46
|
+
|
61
47
|
def clear_for_deployment?
|
62
48
|
status.clear_for_deployment?
|
63
49
|
end
|
64
50
|
|
65
|
-
|
66
|
-
|
67
|
-
|
51
|
+
private
|
52
|
+
|
53
|
+
def wait_for_clear_to_deploy(force)
|
54
|
+
if !clear_for_deployment? && force
|
55
|
+
clear_deployment_lock true
|
68
56
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
if info['vpcId']
|
73
|
-
gw = @attributes['ssh_gateway']
|
74
|
-
"\nssh -i #{@ssh_key} -l #{@ssh_user} -L 9998:#{info['privateIpAddress']}:22 -N #{gw} &\nssh -p 9998 localhost"
|
75
|
-
else
|
76
|
-
"\nssh -i #{@ssh_key} -l #{@ssh_user} #{info['ipAddress']}"
|
57
|
+
Backoff.exp_periods do |p|
|
58
|
+
sleep p
|
59
|
+
break if clear_for_deployment?
|
77
60
|
end
|
78
61
|
end
|
79
62
|
end
|
80
63
|
|
81
|
-
|
82
|
-
|
83
|
-
def set_deploy_command
|
64
|
+
def deploy_command
|
84
65
|
cmd = 'env '
|
85
66
|
get_artifact_endpoints.each_pair do |key,value|
|
86
67
|
cmd += "#{key}=#{value} "
|
87
68
|
end
|
88
69
|
cmd += "PRIMARY_HOST=#{primary_instance} #{deploy_script}"
|
89
|
-
|
90
|
-
@logger.info "Deploy command: '#{cmd}'."
|
91
|
-
@deployment.load :string => "task :simpledeploy do
|
92
|
-
sudo '#{cmd}'
|
93
|
-
end"
|
94
70
|
end
|
95
71
|
|
96
72
|
def get_artifact_endpoints
|
97
73
|
h = {}
|
98
74
|
@config.artifacts.each do |artifact|
|
99
|
-
variable
|
100
|
-
bucket_prefix =
|
101
|
-
domain
|
75
|
+
variable = @config.artifact_deploy_variable artifact
|
76
|
+
bucket_prefix = attributes["#{artifact}_bucket_prefix"]
|
77
|
+
domain = attributes["#{artifact}_domain"]
|
102
78
|
|
103
79
|
artifact = Artifact.new :name => artifact,
|
104
|
-
:id =>
|
80
|
+
:id => attributes[artifact],
|
105
81
|
:region => @region,
|
106
82
|
:domain => domain,
|
107
83
|
:bucket_prefix => bucket_prefix
|
@@ -111,34 +87,6 @@ module SimpleDeploy
|
|
111
87
|
h
|
112
88
|
end
|
113
89
|
|
114
|
-
def set_instances
|
115
|
-
@instances.each do |instance|
|
116
|
-
@logger.debug "Deploying to instance #{instance}."
|
117
|
-
@deployment.server instance, :instances
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
def set_ssh_options
|
122
|
-
@logger.debug "Setting key to #{@ssh_key}."
|
123
|
-
@deployment.variables[:ssh_options] = { :keys => @ssh_key,
|
124
|
-
:paranoid => false }
|
125
|
-
end
|
126
|
-
|
127
|
-
def set_ssh_gateway
|
128
|
-
ssh_gateway = @attributes['ssh_gateway']
|
129
|
-
if ssh_gateway && !ssh_gateway.empty?
|
130
|
-
@deployment.set :gateway, ssh_gateway
|
131
|
-
@logger.info "Proxying via gateway #{ssh_gateway}."
|
132
|
-
else
|
133
|
-
@logger.debug "Not using an ssh gateway."
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
def set_ssh_user
|
138
|
-
@logger.debug "Setting user to #{@ssh_user}."
|
139
|
-
@deployment.set :user, @ssh_user
|
140
|
-
end
|
141
|
-
|
142
90
|
def primary_instance
|
143
91
|
if @stack.instances.any?
|
144
92
|
@stack.instances.first['instancesSet'].first['privateIpAddress']
|
@@ -149,6 +97,17 @@ module SimpleDeploy
|
|
149
97
|
@config.deploy_script
|
150
98
|
end
|
151
99
|
|
100
|
+
def executer
|
101
|
+
options = { :config => @config,
|
102
|
+
:instances => @instances,
|
103
|
+
:environment => @environment,
|
104
|
+
:ssh_user => @ssh_user,
|
105
|
+
:ssh_key => @ssh_key,
|
106
|
+
:stack => @stack,
|
107
|
+
:name => @name }
|
108
|
+
@executer ||= SimpleDeploy::Stack::Execute.new options
|
109
|
+
end
|
110
|
+
|
152
111
|
def status
|
153
112
|
options = { :name => @name,
|
154
113
|
:environment => @environment,
|
@@ -158,7 +117,12 @@ module SimpleDeploy
|
|
158
117
|
@status ||= SimpleDeploy::Stack::Deployment::Status.new options
|
159
118
|
end
|
160
119
|
|
120
|
+
def attributes
|
121
|
+
@stack.attributes
|
122
|
+
end
|
123
|
+
|
161
124
|
end
|
125
|
+
|
162
126
|
end
|
163
127
|
end
|
164
128
|
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'simple_deploy/stack/ssh'
|
2
|
+
|
3
|
+
module SimpleDeploy
|
4
|
+
class Stack
|
5
|
+
class Execute
|
6
|
+
def initialize(args)
|
7
|
+
@config = args[:config]
|
8
|
+
@instances = args[:instances]
|
9
|
+
@environment = args[:environment]
|
10
|
+
@ssh_user = args[:ssh_user]
|
11
|
+
@ssh_key = args[:ssh_key]
|
12
|
+
@stack = args[:stack]
|
13
|
+
@name = args[:name]
|
14
|
+
end
|
15
|
+
|
16
|
+
def execute(args)
|
17
|
+
ssh.execute args
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def ssh
|
23
|
+
options = { :config => @config,
|
24
|
+
:instances => @instances,
|
25
|
+
:environment => @environment,
|
26
|
+
:ssh_user => @ssh_user,
|
27
|
+
:ssh_key => @ssh_key,
|
28
|
+
:stack => @stack,
|
29
|
+
:name => @name }
|
30
|
+
@ssh ||= SimpleDeploy::Stack::SSH.new options
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'capistrano'
|
2
|
+
require 'capistrano/cli'
|
3
|
+
|
4
|
+
module SimpleDeploy
|
5
|
+
class Stack
|
6
|
+
class SSH
|
7
|
+
|
8
|
+
def initialize(args)
|
9
|
+
@config = args[:config]
|
10
|
+
@instances = args[:instances]
|
11
|
+
@environment = args[:environment]
|
12
|
+
@ssh_user = args[:ssh_user]
|
13
|
+
@ssh_key = args[:ssh_key]
|
14
|
+
@stack = args[:stack]
|
15
|
+
@name = args[:name]
|
16
|
+
@logger = @config.logger
|
17
|
+
@region = @config.region @environment
|
18
|
+
end
|
19
|
+
|
20
|
+
def execute(args)
|
21
|
+
create_execute_task args
|
22
|
+
@task.execute
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def create_execute_task(args)
|
28
|
+
if @instances.nil? || @instances.empty?
|
29
|
+
raise "There are no running instances to execute this command."
|
30
|
+
end
|
31
|
+
|
32
|
+
@task = Capistrano::Configuration.new :output => @logger
|
33
|
+
@task.logger.level = 3
|
34
|
+
|
35
|
+
set_ssh_gateway
|
36
|
+
set_ssh_user
|
37
|
+
set_ssh_options
|
38
|
+
set_instances
|
39
|
+
set_execute_command args
|
40
|
+
end
|
41
|
+
|
42
|
+
def set_execute_command(args)
|
43
|
+
command = args[:command]
|
44
|
+
sudo = args[:sudo]
|
45
|
+
|
46
|
+
@logger.info "Setting command: '#{command}'."
|
47
|
+
if sudo
|
48
|
+
@task.load :string => "task :execute do
|
49
|
+
sudo '#{command}'
|
50
|
+
end"
|
51
|
+
else
|
52
|
+
@task.load :string => "task :execute do
|
53
|
+
run '#{command}'
|
54
|
+
end"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def set_instances
|
59
|
+
@instances.each do |instance|
|
60
|
+
@logger.debug "Executing command on instance #{instance}."
|
61
|
+
@task.server instance, :instances
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def set_ssh_options
|
66
|
+
@logger.debug "Setting key to #{@ssh_key}."
|
67
|
+
@task.variables[:ssh_options] = { :keys => @ssh_key,
|
68
|
+
:paranoid => false }
|
69
|
+
end
|
70
|
+
|
71
|
+
def set_ssh_gateway
|
72
|
+
ssh_gateway = attributes['ssh_gateway']
|
73
|
+
if ssh_gateway && !ssh_gateway.empty?
|
74
|
+
@task.set :gateway, ssh_gateway
|
75
|
+
@logger.info "Proxying via gateway #{ssh_gateway}."
|
76
|
+
else
|
77
|
+
@logger.debug "Not using an ssh gateway."
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def set_ssh_user
|
82
|
+
@logger.debug "Setting user to #{@ssh_user}."
|
83
|
+
@task.set :user, @ssh_user
|
84
|
+
end
|
85
|
+
|
86
|
+
def attributes
|
87
|
+
@stack.attributes
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
data/lib/simple_deploy/stack.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'stackster'
|
2
2
|
require 'simple_deploy/stack/deployment'
|
3
|
+
require 'simple_deploy/stack/execute'
|
3
4
|
require 'simple_deploy/stack/stack_attribute_formater'
|
4
5
|
|
5
6
|
module SimpleDeploy
|
@@ -43,10 +44,13 @@ module SimpleDeploy
|
|
43
44
|
end
|
44
45
|
|
45
46
|
def deploy(force = false)
|
46
|
-
deployment.create_deployment
|
47
47
|
deployment.execute force
|
48
48
|
end
|
49
49
|
|
50
|
+
def execute(args)
|
51
|
+
executer.execute args
|
52
|
+
end
|
53
|
+
|
50
54
|
def ssh
|
51
55
|
deployment.ssh
|
52
56
|
end
|
@@ -118,6 +122,16 @@ module SimpleDeploy
|
|
118
122
|
:main_attributes => attributes
|
119
123
|
end
|
120
124
|
|
125
|
+
def executer
|
126
|
+
@executer ||= Stack::Execute.new :config => @config,
|
127
|
+
:environment => @environment,
|
128
|
+
:name => @name,
|
129
|
+
:stack => stack,
|
130
|
+
:instances => instances,
|
131
|
+
:ssh_user => ssh_user,
|
132
|
+
:ssh_key => ssh_key
|
133
|
+
end
|
134
|
+
|
121
135
|
def deployment
|
122
136
|
@deployment ||= Stack::Deployment.new :config => @config,
|
123
137
|
:environment => @environment,
|
data/simple_deploy.gemspec
CHANGED
@@ -18,10 +18,11 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
|
21
|
-
s.add_development_dependency "
|
21
|
+
s.add_development_dependency "rake"
|
22
|
+
s.add_development_dependency "rspec", "~> 2.11.0"
|
22
23
|
|
23
|
-
s.add_runtime_dependency "capistrano"
|
24
|
-
s.add_runtime_dependency "stackster", '= 0.3.
|
25
|
-
s.add_runtime_dependency "tinder"
|
26
|
-
s.add_runtime_dependency "trollop"
|
24
|
+
s.add_runtime_dependency "capistrano", "= 2.13.5"
|
25
|
+
s.add_runtime_dependency "stackster", '= 0.3.2'
|
26
|
+
s.add_runtime_dependency "tinder", "= 1.9.1"
|
27
|
+
s.add_runtime_dependency "trollop", "= 2.0"
|
27
28
|
end
|
data/spec/logger_spec.rb
CHANGED
@@ -2,33 +2,39 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe SimpleDeploy do
|
4
4
|
|
5
|
-
|
6
|
-
logger_mock = mock 'logger'
|
7
|
-
logger_mock.should_receive(:info).with 'a message'
|
8
|
-
logger = SimpleDeploy::SimpleDeployLogger.new :logger => logger_mock
|
9
|
-
logger.info 'a message'
|
5
|
+
before do
|
6
|
+
@logger_mock = mock 'logger'
|
10
7
|
end
|
11
8
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
9
|
+
context "with new logger" do
|
10
|
+
before do
|
11
|
+
@logger_mock.should_receive(:datetime_format=).with '%Y-%m-%dT%H:%M:%S%z'
|
12
|
+
@logger_mock.should_receive(:formatter=)
|
13
|
+
@logger_mock.should_receive(:level=).with 1
|
14
|
+
Logger.should_receive(:new).with(STDOUT).and_return @logger_mock
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should create a new logger object when one is not passed" do
|
18
|
+
@logger = SimpleDeploy::SimpleDeployLogger.new
|
19
|
+
@logger_mock.should_receive(:info).with 'a message'
|
20
|
+
@logger.info 'a message'
|
21
|
+
end
|
22
|
+
|
23
|
+
it "accept puts with msg and pass it to debug" do
|
24
|
+
@logger = SimpleDeploy::SimpleDeployLogger.new
|
25
|
+
@logger_mock.should_receive(:debug).with 'a message'
|
26
|
+
@logger.puts 'a message'
|
27
|
+
end
|
28
|
+
|
29
|
+
it "tty? return false" do
|
30
|
+
@logger = SimpleDeploy::SimpleDeployLogger.new
|
31
|
+
@logger.tty?.should be_false
|
32
|
+
end
|
21
33
|
end
|
22
34
|
|
23
|
-
it "
|
24
|
-
|
25
|
-
|
26
|
-
logger_mock.should_receive(:debug).with 'a message'
|
27
|
-
logger_mock.should_receive(:datetime_format=).with '%Y-%m-%dT%H:%M:%S%z'
|
28
|
-
logger_mock.should_receive(:formatter=)
|
29
|
-
logger_mock.should_receive(:level=).with 1
|
30
|
-
logger = SimpleDeploy::SimpleDeployLogger.new
|
31
|
-
logger.puts 'a message'
|
35
|
+
it "should create a new logger object from the hash passed as :logger" do
|
36
|
+
Logger.should_receive(:new).exactly(0).times
|
37
|
+
@logger = SimpleDeploy::SimpleDeployLogger.new :logger => @logger_mock
|
32
38
|
end
|
33
39
|
|
34
40
|
end
|
@@ -2,6 +2,68 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe SimpleDeploy do
|
4
4
|
|
5
|
-
|
5
|
+
before do
|
6
|
+
@logger_stub = stub 'logger', :debug => true,
|
7
|
+
:info => true
|
8
|
+
@config_mock = mock 'config'
|
9
|
+
@config_mock.stub :logger => @logger_stub
|
10
|
+
@stack_mock = mock 'stack'
|
11
|
+
|
12
|
+
options = { :config => @config_mock,
|
13
|
+
:stack => @stack_mock,
|
14
|
+
:ssh_user => 'user',
|
15
|
+
:name => 'dastack' }
|
16
|
+
@status = SimpleDeploy::Stack::Deployment::Status.new options
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "clear_for_deployment?" do
|
20
|
+
it "should return true if clear for deployment" do
|
21
|
+
@stack_mock.stub :attributes => { 'deployment_in_progress' => 'false' }
|
22
|
+
@status.clear_for_deployment?.should be_true
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should return false if not clear for deployment" do
|
26
|
+
@stack_mock.stub :attributes => { 'deployment_in_progress' => 'true' }
|
27
|
+
@status.clear_for_deployment?.should be_false
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "deployment_in_progress?" do
|
32
|
+
it "should return false if no deployment in progress" do
|
33
|
+
@stack_mock.stub :attributes => { 'deployment_in_progress' => 'false' }
|
34
|
+
@status.deployment_in_progress?.should be_false
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should return true if deployment in progress" do
|
38
|
+
@stack_mock.stub :attributes => { 'deployment_in_progress' => 'true' }
|
39
|
+
@status.deployment_in_progress?.should be_true
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "clear_deployment_lock" do
|
44
|
+
it "should unset deploy in progress if force & deploy in progress" do
|
45
|
+
@stack_mock.stub :attributes => { 'deployment_in_progress' => 'true' }
|
46
|
+
@stack_mock.should_receive(:update).
|
47
|
+
with( { :attributes => [ { 'deployment_in_progress' => 'false'} ] })
|
48
|
+
@status.clear_deployment_lock(true)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "set_deployment_in_prgoress" do
|
53
|
+
it "set deployment as in progress" do
|
54
|
+
Time.stub :now => 'thetime'
|
55
|
+
@stack_mock.should_receive(:update).
|
56
|
+
with( { :attributes => [ { "deployment_in_progress" => "true", "deployment_user" => "user", "deployment_datetime" => "thetime" } ] })
|
57
|
+
@status.set_deployment_in_progress
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "unset_deployment_in_prgoress" do
|
62
|
+
it "clears deployment in progress" do
|
63
|
+
@stack_mock.should_receive(:update).
|
64
|
+
with( { :attributes => [ { 'deployment_in_progress' => 'false'} ] })
|
65
|
+
@status.unset_deployment_in_progress
|
66
|
+
end
|
67
|
+
end
|
6
68
|
|
7
69
|
end
|