Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added waiting based on status for restore, reset, and create_and_atta…

…ch_volumes.
  • Loading branch information...
commit df60d26db9144e988c0cee793eac5c90bb3753a9 1 parent 5c2b78b
@douglaswth douglaswth authored
View
42 lib/right_api_client/instance_facing.rb
@@ -56,6 +56,10 @@ def backup(options)
:volume_attachment_hrefs => backup_hrefs}}
new_backup = @client.backups.create(params)
# TODO: backups need to be a separate call .. for tight chef integration
+ while (completed = new_backup.show.completed) != true
+ puts "waiting for backup to complete - completed is #{completed}"
+ sleep 2
+ end
new_backup.update(:backup => {:committed => "true"})
@client.backups.cleanup(:lineage => options[:lineage],
:keep_last => options[:max_snapshots],
@@ -64,6 +68,26 @@ def backup(options)
:monthlies => options[:keep_monthlies],
:yearlies => options[:keep_yearlies]
)
+
+ new_backup
+ end
+
+ # restores and waits for restore to finish
+ # current statuses observed:
+ # - pending
+ # - failed
+ # - in-progress
+ # - completed
+ def restore(backup)
+ restore = backup.restore(:instance_href => href)
+
+ while (status = restore.show.summary.split(':').first) != 'completed'
+ raise "restore failed!" if status == 'failed'
+ puts "waiting for restore to complete - status is #{status}"
+ sleep 2
+ end
+
+ restore
end
# Returns latest backup as RightApiClient::Resource
@@ -111,23 +135,22 @@ def create_and_attach_volumes(volname, numvols, volume_size)
params[:volume][:volume_type_href] = @client.volume_types.index.first.show.href
# euca requires size
else
- params[:volume][:size] = '1'
+ params[:volume][:size] = volume_size.to_s
end
new_vol = @client.volumes.create(params)
puts "waiting for volume to create - initial current status = #{new_vol.show.status}"
- while (new_vol.show.status != "available")
- puts "waiting for volume to create - status is #{new_vol.show.status}"
+ while ((status = new_vol.show.status) != "available")
+ puts "waiting for volume to create - status is #{status}"
sleep 2
end
# attach the new volume
params = {:volume_attachment => {:volume_href => new_vol.show.href, :instance_href => instance.href, :device => physical_device_names[index] } }
new_attachment = @client.volume_attachments.create(params)
-
puts "waiting for volume to attach - initial current status = #{new_vol.show.status}"
- while (new_vol.show.status != "in-use") do
- puts "waiting for volume to attach - status is #{new_vol.show.status}"
+ while ((status = new_vol.show.status) != "in-use") && ((state = new_attachment.show.state) != "attached") do
+ puts "attaching - waiting for volume to attach - status is #{status} / #{state}"
sleep 2
end
attached_volumes << new_attachment
@@ -151,7 +174,6 @@ def sanitize_device_list(device_list)
# Returns list of volume attachments for THIS instance
def volume_attachments
- instance = @client.get_instance
va = @client.volume_attachments.index(:filter => ["instance_href==#{href}"])
myattachments = []
va.each do |a|
@@ -164,8 +186,14 @@ def volume_attachments
def reset
delete_these = []
# Detach
+
myattachments = volume_attachments
myattachments.each do |attachment|
+ while ((state = @client.volume_attachments(:id => attachment.href.split('/').last).show.state) != "attached") do
+
+ puts "resetting - waiting for volume to attach - status is #{state}"
+ sleep 2
+ end
delete_these << attachment.show.volume
attachment.destroy
end
View
2  login_instance.rb
@@ -15,7 +15,7 @@
api_url = ENV['RS_SERVER']
puts account_id, token, api_url
-@client = RightApi::InstanceFacing.new( :instance_token => token,
+@instance = RightApi::InstanceFacing.new( :instance_token => token,
:account_id => account_id,
:api_url => "https://#{api_url}" )
View
81 spec/right_api_white_spec.rb
@@ -11,34 +11,33 @@
@instance = RightApi::InstanceFacing.new(:instance_token => token, :account_id => account_id, :api_url => "https://#{ENV['RS_SERVER']}")
end
-# it "returns correct device naming" do
-# @instance.reset
-#
-# @volname = "spec_test_correct_device_naming_#{$$}"
-#
-# @instance.create_and_attach_volumes(@volname, 1, "1")
-# api_name = @instance.volume_attachments.first.show.device
-# api_name.gsub!(/^\/dev\//,"")
-# IO.read("/proc/partitions").should include(api_name)
-# end
-#
-# it "will backup" do
-# @instance.reset
-#
-# @volname = "spec_test_will_backup"
-# @lineage = "#{@volname}_test_lineage"
-# @backup_options = { :lineage => @lineage,
-# :name => @volname,
-# :max_snapshots => 1,
-# :keep_dailies => 1,
-# :keep_weeklies => 1,
-# :keep_monthlies => 1,
-# :keep_yearlies => 1 }
-#
-# @instance.create_and_attach_volumes(@volname, 2, "1")
-# @instance.backup(@backup_options)
-# end
+ it "returns correct device naming" do
+ @instance.reset
+
+ @volname = "spec_test_correct_device_naming_#{$$}"
+
+ @instance.create_and_attach_volumes(@volname, 1, "1")
+ api_name = @instance.volume_attachments.first.show.device
+ api_name.gsub!(/^\/dev\//,"")
+ IO.read("/proc/partitions").should include(api_name)
+ end
+
+ it "will backup" do
+ @instance.reset
+ @volname = "spec_test_will_backup"
+ @lineage = "#{@volname}_test_lineage"
+ @backup_options = { :lineage => @lineage,
+ :name => @volname,
+ :max_snapshots => 1,
+ :keep_dailies => 1,
+ :keep_weeklies => 1,
+ :keep_monthlies => 1,
+ :keep_yearlies => 1 }
+
+ @instance.create_and_attach_volumes(@volname, 2, "1")
+ @instance.backup(@backup_options)
+ end
it "will restore" do
@instance.reset
@@ -56,14 +55,14 @@
puts "VOLNAME = #{@volname}"
- @instance.create_and_attach_volumes(@volname, 1, "5")
- puts "waiting 60 seconds after sending creating and attaching volumes command"
- sleep(60)
+ @instance.create_and_attach_volumes(@volname, 1, 1)
+ #puts "waiting 60 seconds after sending creating and attaching volumes command"
+ #sleep(60)
# get device id just attached
device_name = @instance.volume_attachments.first.show.device
- puts "waiting 60 seconds after sending creating attaching volumes command"
- sleep(60)
+ #puts "waiting 60 seconds after sending creating attaching volumes command"
+ #sleep(60)
# Writing data to device
sfdisk_cmd = "sfdisk #{device_name} << EOF\n"
@@ -77,23 +76,23 @@
system("dd if=/dev/zero of=/mnt/200m bs=1M count=200")
system("umount /mnt")
- puts "waiting 30 seconds after writing to volumes"
- sleep(30)
+ #puts "waiting 30 seconds after writing to volumes"
+ #sleep(30)
@instance.backup(@backup_options)
- puts "waiting 120 seconds after sending backup command"
- sleep(120)
+ #puts "waiting 120 seconds after sending backup command"
+ #sleep(120)
@instance.reset
- puts "waiting 120 seconds after sending reset command"
- sleep(120)
+ #puts "waiting 120 seconds after sending reset command"
+ #sleep(120)
backup = @instance.find_latest_backup(@lineage)
puts "Backup found"
- puts "waiting 120 seconds after finding lastest backup"
- sleep(120)
+ #puts "waiting 120 seconds after finding lastest backup"
+ #sleep(120)
- backup.restore(:instance_href => @instance.href)
+ @instance.restore(backup)
puts "marker after restore command"
end
Please sign in to comment.
Something went wrong with that request. Please try again.