@@ -14,14 +14,18 @@ def gather_diagnostics(script_output, msg = "")
14
14
{ 'error_code' => InstanceAgent ::Plugins ::CodeDeployPlugin ::ScriptError ::SUCCEEDED_CODE , 'script_name' => "" , 'message' => "Succeeded: #{ msg } " , 'log' => script_output } . to_json
15
15
end
16
16
17
+ def get_ack_diagnostics ( is_command_noop )
18
+ return { :format => "JSON" , :payload => { 'IsCommandNoop' => is_command_noop } . to_json ( ) }
19
+ end
20
+
17
21
context 'The command poller' do
18
22
19
23
setup do
20
24
@host_identifier = "i-123"
21
25
@aws_region = 'us-east-1'
22
26
@deploy_control_endpoint = "my-deploy-control.amazon.com"
23
- @deploy_control_client = mock ( )
24
- @deploy_control_api = mock ( )
27
+ @deploy_control_client = mock ( 'deploy-control-client' )
28
+ @deploy_control_api = mock ( 'deploy-control-api' )
25
29
@executor = stub ( :execute_command => "test this is not returned" ,
26
30
:deployment_system => "CodeDeploy" )
27
31
@@ -107,6 +111,7 @@ def gather_diagnostics(script_output, msg = "")
107
111
starts_as ( 'setup' )
108
112
@executor . stubs ( :execute_command ) .
109
113
when ( @execute_command_state . is ( 'setup' ) )
114
+ @executor . stubs ( :is_command_noop? ) . returns ( false )
110
115
111
116
@put_host_command_complete_state = states ( 'put_host_command_complete_state' ) .
112
117
starts_as ( 'setup' )
@@ -115,7 +120,7 @@ def gather_diagnostics(script_output, msg = "")
115
120
@deployment_id = stub ( :deployment_id => "D-1234" )
116
121
InstanceAgent ::Config . config [ :root_dir ] = File . join ( Dir . tmpdir ( ) , "CodeDeploy" )
117
122
InstanceAgent ::Config . config [ :ongoing_deployment_tracking ] = "ongoing-deployment"
118
- InstanceAgent ::Plugins ::CodeDeployPlugin ::DeploymentSpecification . stubs ( :parse ) . returns ( @deployment_id )
123
+ InstanceAgent ::Plugins ::CodeDeployPlugin ::DeploymentSpecification . stubs ( :parse ) . returns ( @deployment_id )
119
124
InstanceAgent ::Plugins ::CodeDeployPlugin ::DeploymentCommandTracker . stubs ( :delete_deployment_command_tracking_file ) . returns ( true )
120
125
InstanceAgent ::Plugins ::CodeDeployPlugin ::DeploymentCommandTracker . stubs ( :create_ongoing_deployment_tracking_file ) . returns ( true )
121
126
end
@@ -257,7 +262,7 @@ def gather_diagnostics(script_output, msg = "")
257
262
258
263
should 'call PutHostCommandAcknowledgement with host_command_identifier returned by PollHostCommand' do
259
264
@deploy_control_client . expects ( :put_host_command_acknowledgement ) .
260
- with ( :diagnostics => nil ,
265
+ with ( :diagnostics => get_ack_diagnostics ( false ) ,
261
266
:host_command_identifier => @command . host_command_identifier ) .
262
267
returns ( @poll_host_command_acknowledgement_output )
263
268
@@ -266,13 +271,10 @@ def gather_diagnostics(script_output, msg = "")
266
271
267
272
should 'return when Succeeded command status is given by PutHostCommandAcknowledgement' do
268
273
@deploy_control_client . expects ( :put_host_command_acknowledgement ) .
269
- with ( :diagnostics => nil ,
274
+ with ( :diagnostics => get_ack_diagnostics ( false ) ,
270
275
:host_command_identifier => @command . host_command_identifier ) .
271
276
returns ( stub ( :command_status => "Succeeded" ) )
272
277
273
- @get_deployment_specification_state . become ( 'never' )
274
- @deploy_control_client . expects ( :get_deployment_specification ) . never .
275
- when ( @get_deployment_specification_state . is ( 'never' ) )
276
278
@put_host_command_complete_state . become ( 'never' )
277
279
@deploy_control_client . expects ( :put_host_command_complete ) . never .
278
280
when ( @put_host_command_complete_state . is ( 'never' ) )
@@ -281,39 +283,50 @@ def gather_diagnostics(script_output, msg = "")
281
283
end
282
284
283
285
context 'when Failed command status is given by PutHostCommandAcknowledgement' do
284
- setup do
285
- @deploy_control_client . expects ( :put_host_command_acknowledgement ) .
286
- with ( :diagnostics => nil ,
287
- :host_command_identifier => @command . host_command_identifier ) .
288
- returns ( stub ( :command_status => "Failed" ) )
286
+ context 'when the command is not a noop' do
287
+ setup do
288
+ @deploy_control_client . expects ( :put_host_command_acknowledgement ) .
289
+ with ( :diagnostics => get_ack_diagnostics ( false ) ,
290
+ :host_command_identifier => @command . host_command_identifier ) .
291
+ returns ( stub ( :command_status => "Failed" ) )
292
+
293
+ @executor . expects ( :is_command_noop? ) .
294
+ with ( @command . command_name , @deployment_specification . generic_envelope ) . returns ( false )
295
+ end
289
296
290
- @deploy_control_client . expects ( :get_deployment_specification ) .
291
- with ( :deployment_execution_id => @command . deployment_execution_id ,
292
- :host_identifier => @host_identifier ) .
293
- returns ( @get_deploy_specification_output )
294
- end
297
+ should 'do nothing' do
298
+ @put_host_command_complete_state . become ( 'never' )
299
+ @deploy_control_client . expects ( :put_host_command_complete ) . never .
300
+ when ( @put_host_command_complete_state . is ( 'never' ) )
295
301
296
- should "return when the command is not a noop" do
297
- @executor . expects ( :is_command_noop? ) .
298
- with ( @command . command_name , @deployment_specification . generic_envelope ) . returns ( false )
302
+ @poller . acknowledge_and_process_command ( @ command)
303
+ end
304
+ end
299
305
300
- @put_host_command_complete_state . become ( 'never' )
301
- @deploy_control_client . expects ( :put_host_command_complete ) . never .
302
- when ( @put_host_command_complete_state . is ( 'never' ) )
306
+ context 'when the command is a noop' do
307
+ setup do
308
+ @deploy_control_client . expects ( :put_host_command_acknowledgement ) .
309
+ with ( :diagnostics => get_ack_diagnostics ( true ) ,
310
+ :host_command_identifier => @command . host_command_identifier ) .
311
+ returns ( stub ( :command_status => "Failed" ) )
303
312
304
- @poller . acknowledge_and_process_command ( @command )
305
- end
313
+ @deploy_control_client . expects ( :get_deployment_specification ) .
314
+ with ( :deployment_execution_id => @command . deployment_execution_id ,
315
+ :host_identifier => @host_identifier ) .
316
+ returns ( @get_deploy_specification_output )
306
317
307
- should "PutHostCommandComplete when the command is a noop" do
308
- @executor . expects ( :is_command_noop? ) .
309
- with ( @command . command_name , @deployment_specification . generic_envelope ) . returns ( true )
318
+ @executor . expects ( :is_command_noop? ) .
319
+ with ( @command . command_name , @deployment_specification . generic_envelope ) . returns ( true ) . twice
320
+ end
310
321
311
- @deploy_control_client . expects ( :put_host_command_complete ) .
312
- with ( :command_status => "Succeeded" ,
313
- :diagnostics => { :format => "JSON" , :payload => gather_diagnostics ( "" , "CompletedNoopCommand" ) } ,
314
- :host_command_identifier => @command . host_command_identifier )
322
+ should 'call PutHostCommandComplete with Succeeded' do
323
+ @deploy_control_client . expects ( :put_host_command_complete ) .
324
+ with ( :command_status => "Succeeded" ,
325
+ :diagnostics => { :format => "JSON" , :payload => gather_diagnostics ( "" , "CompletedNoopCommand" ) } ,
326
+ :host_command_identifier => @command . host_command_identifier )
315
327
316
- @poller . acknowledge_and_process_command ( @command )
328
+ @poller . acknowledge_and_process_command ( @command )
329
+ end
317
330
end
318
331
end
319
332
0 commit comments