From eef87291d508c18d05296d47d681ff569232fb81 Mon Sep 17 00:00:00 2001 From: Eugene Howe Date: Tue, 22 Sep 2015 14:28:41 -0400 Subject: [PATCH] mock instance stop and start properly --- lib/fog/aws/requests/compute/describe_instances.rb | 2 +- lib/fog/aws/requests/compute/start_instances.rb | 1 + lib/fog/aws/requests/compute/stop_instances.rb | 1 + tests/models/compute/server_tests.rb | 11 +++++++++++ tests/requests/compute/instance_tests.rb | 13 +++++++++++-- 5 files changed, 25 insertions(+), 3 deletions(-) diff --git a/lib/fog/aws/requests/compute/describe_instances.rb b/lib/fog/aws/requests/compute/describe_instances.rb index 82a8611e0..3528e6ab8 100644 --- a/lib/fog/aws/requests/compute/describe_instances.rb +++ b/lib/fog/aws/requests/compute/describe_instances.rb @@ -199,7 +199,7 @@ module Fog when 'rebooting' instance['instanceState'] = { 'code' => 16, 'name' => 'running' } when 'stopping' - instance['instanceState'] = { 'code' => 0, 'name' => 'stopping' } + instance['instanceState'] = { 'code' => 0, 'name' => 'stopped' } instance['stateReason'] = { 'code' => 0 } when 'shutting-down' if Time.now - self.data[:deleted_at][instance['instanceId']] >= Fog::Mock.delay * 2 diff --git a/lib/fog/aws/requests/compute/start_instances.rb b/lib/fog/aws/requests/compute/start_instances.rb index d1df4f46a..d764e2262 100644 --- a/lib/fog/aws/requests/compute/start_instances.rb +++ b/lib/fog/aws/requests/compute/start_instances.rb @@ -41,6 +41,7 @@ module Fog response.status = 200 response.body = { + 'requestId' => Fog::AWS::Mock.request_id, 'instancesSet' => instance_set.reduce([]) do |ia, instance| ia << {'currentState' => { 'code' => 0, 'name' => 'pending' }, 'previousState' => instance['instanceState'], diff --git a/lib/fog/aws/requests/compute/stop_instances.rb b/lib/fog/aws/requests/compute/stop_instances.rb index bb49a53d4..5b3ce2235 100644 --- a/lib/fog/aws/requests/compute/stop_instances.rb +++ b/lib/fog/aws/requests/compute/stop_instances.rb @@ -42,6 +42,7 @@ module Fog response.status = 200 response.body = { + 'requestId' => Fog::AWS::Mock.request_id, 'instancesSet' => instance_set.reduce([]) do |ia, instance| instance['classicLinkSecurityGroups'] = nil instance['classicLinkVpcId'] = nil diff --git a/tests/models/compute/server_tests.rb b/tests/models/compute/server_tests.rb index 6ed018946..b2814c7bf 100644 --- a/tests/models/compute/server_tests.rb +++ b/tests/models/compute/server_tests.rb @@ -60,6 +60,17 @@ Shindo.tests("Fog::Compute[:aws] | monitor", ['aws']) do @instance.associate_public_ip == false end + test('#stop') do + @instance.stop + @instance.wait_for { state == "stopped" } + @instance.state == "stopped" + end + + test("#start") do + @instance.start + @instance.wait_for { ready? } + @instance.state == "running" + end end @instance.destroy diff --git a/tests/requests/compute/instance_tests.rb b/tests/requests/compute/instance_tests.rb index 14967fbd8..411b6ed68 100644 --- a/tests/requests/compute/instance_tests.rb +++ b/tests/requests/compute/instance_tests.rb @@ -81,7 +81,7 @@ Shindo.tests('Fog::Compute[:aws] | instance requests', ['aws']) do 'timestamp' => Time } - @terminate_instances_format = { + @instance_state_change_format = { 'instancesSet' => [{ 'currentState' => {'code' => Integer, 'name' => String}, 'instanceId' => String, @@ -161,6 +161,7 @@ Shindo.tests('Fog::Compute[:aws] | instance requests', ['aws']) do 'eventsSet' => [Fog::Nullable::Hash], }] } + tests('success') do @instance_id = nil @@ -246,7 +247,15 @@ Shindo.tests('Fog::Compute[:aws] | instance requests', ['aws']) do Fog::Compute[:aws].reboot_instances(@instance_id).body end - tests("#terminate_instances('#{@instance_id}')").formats(@terminate_instances_format) do + tests("#stop_instances('#{@instance_id}')").formats(@instance_state_change_format) do + Fog::Compute[:aws].stop_instances(@instance_id).body + end + + tests("#start_instances('#{@instance_id}')").formats(@instance_state_change_format) do + Fog::Compute[:aws].start_instances(@instance_id).body + end + + tests("#terminate_instances('#{@instance_id}')").formats(@instance_state_change_format) do Fog::Compute[:aws].terminate_instances(@instance_id).body end