mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[digitalocean|compute] Implement Server.power_cycle
- Added power_cycle_server request - Added required tests
This commit is contained in:
parent
06467aeec7
commit
21b28ee589
6 changed files with 74 additions and 1 deletions
|
@ -29,6 +29,7 @@ module Fog
|
|||
request :create_server
|
||||
request :destroy_server
|
||||
request :reboot_server
|
||||
request :power_cycle_server
|
||||
|
||||
# request :digitalocean_resize
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ module Fog
|
|||
#
|
||||
# Powers the server off and then powers it on again.
|
||||
def power_cycle
|
||||
raise NotImplementedError
|
||||
service.power_cycle_server id
|
||||
end
|
||||
|
||||
# Shutdown the server
|
||||
|
|
25
lib/fog/digitalocean/requests/compute/power_cycle_server.rb
Normal file
25
lib/fog/digitalocean/requests/compute/power_cycle_server.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class DigitalOcean
|
||||
class Real
|
||||
|
||||
def power_cycle_server( id )
|
||||
request(
|
||||
:expects => [200],
|
||||
:method => 'GET',
|
||||
:path => "droplets/#{id}/power_cycle"
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def power_cycle_server( id )
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -9,6 +9,7 @@ Shindo.tests("Fog::Compute[:digitalocean] | server model", ['digitalocean', 'com
|
|||
%w{
|
||||
shutdown
|
||||
reboot
|
||||
power_cycle
|
||||
}.each do |action|
|
||||
test(action) { server.respond_to? action }
|
||||
end
|
||||
|
@ -35,6 +36,12 @@ Shindo.tests("Fog::Compute[:digitalocean] | server model", ['digitalocean', 'com
|
|||
server.wait_for { server.status == 'off' }
|
||||
server.status == 'off'
|
||||
end
|
||||
test('power_cycle the server') do
|
||||
server.wait_for { server.ready? }
|
||||
server.power_cycle
|
||||
server.wait_for { server.status == 'off' }
|
||||
server.status == 'off'
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
20
tests/digitalocean/requests/compute/destroy_server_tests.rb
Normal file
20
tests/digitalocean/requests/compute/destroy_server_tests.rb
Normal file
|
@ -0,0 +1,20 @@
|
|||
Shindo.tests('Fog::Compute[:digitalocean] | reboot_server request', ['digitalocean', 'compute']) do
|
||||
|
||||
service = Fog::Compute[:digitalocean]
|
||||
data = Fog::Compute[:digitalocean].create_server 'fog-test',
|
||||
service.flavors.first.id,
|
||||
service.images.first.id,
|
||||
service.regions.first.id
|
||||
|
||||
tests('success') do
|
||||
|
||||
test('#reboot_server') do
|
||||
sleep 120
|
||||
data.body['status'] == 'OK' and \
|
||||
(service.destroy_server(data.body['droplet']['id']).body['status'] == 'OK')
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
end
|
|
@ -0,0 +1,20 @@
|
|||
Shindo.tests('Fog::Compute[:digitalocean] | power_cycle_server request', ['digitalocean', 'compute']) do
|
||||
|
||||
server = fog_test_server
|
||||
|
||||
tests('success') do
|
||||
|
||||
tests('#power_cycle_server') do
|
||||
test('returns 200') do
|
||||
service.power_cycle_server(server.id).status == 200
|
||||
end
|
||||
test('state is off') do
|
||||
server.wait_for { server.status == 'off' }
|
||||
server.status == 'off'
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
end
|
Loading…
Reference in a new issue