Module: VirtualMonkey::EBS

Includes:
DeploymentRunner
Included in:
EBSRunner, Mysql, MysqlRunner, MysqlToolboxRunner
Defined in:
lib/virtualmonkey/ebs.rb

Instance Attribute Summary collapse

Attributes included from DeploymentRunner

#deployment, #scripts_to_run, #servers

Instance Method Summary collapse

Methods included from DeploymentRunner

#initialize

Methods included from TestCaseInterface

#behavior, #probe, #set_var, #verify

Instance Attribute Details

#lineageObject

Returns the value of attribute lineage.



7
8
9
# File 'lib/virtualmonkey/ebs.rb', line 7

def lineage
  @lineage
end

#mount_pointObject

Returns the value of attribute mount_point.



6
7
8
# File 'lib/virtualmonkey/ebs.rb', line 6

def mount_point
  @mount_point
end

#stripe_countObject

Returns the value of attribute stripe_count.



4
5
6
# File 'lib/virtualmonkey/ebs.rb', line 4

def stripe_count
  @stripe_count
end

#volume_sizeObject

Returns the value of attribute volume_size.



5
6
7
# File 'lib/virtualmonkey/ebs.rb', line 5

def volume_size
  @volume_size
end

Instance Method Details

#create_backupObject



155
156
157
158
# File 'lib/virtualmonkey/ebs.rb', line 155

def create_backup
  behavior(:run_script, "backup", s_one)
  behavior(:wait_for_snapshots)
end

#create_stripe_volume(server) ⇒ Object

creates a EBS stripe on the server

  • server<~Server> the server to create stripe on



78
79
80
81
82
83
84
85
# File 'lib/virtualmonkey/ebs.rb', line 78

def create_stripe_volume(server)
  options = { "EBS_MOUNT_POINT" => "text:#{@mount_point}",
          "EBS_STRIPE_COUNT" => "text:#{@stripe_count}",
          "EBS_TOTAL_VOLUME_GROUP_SIZE" => "text:#{@volume_size}",
          "EBS_LINEAGE" => "text:#{@lineage}" }
  audit = server.run_executable(@scripts_to_run['create_stripe'], options)
  audit.wait_for_completed
end

#find_snapshot_timestampObject

Returns the timestamp of the latest snapshot for testing OPT_DB_RESTORE_TIMESTAMP_OVERRIDE



70
71
72
73
74
# File 'lib/virtualmonkey/ebs.rb', line 70

def find_snapshot_timestamp
  last_snap = behavior(:find_snapshots).last
  last_snap.tags.detect { |t| t["name"] =~ /timestamp=(\d+)$/ }
  timestamp = $1
end

#find_snapshotsObject

Find all snapshots associated with this deployment’s lineage



60
61
62
63
64
65
66
67
# File 'lib/virtualmonkey/ebs.rb', line 60

def find_snapshots
  unless @lineage
    s = @servers.first
    kind_params = s.transform_parameters(s.parameters)
    @lineage = kind_params['DB_LINEAGE_NAME'].gsub(/text:/, "")
  end
  snapshots = Ec2EbsSnapshot.find_by_cloud_id(@servers.first.cloud_id).select { |n| n.nickname =~ /#{@lineage}.*$/ }
end

#populate_volume(server) ⇒ Object

Writes data to the EBS volume so snapshot restores can be verified Not sure what to write.….. Maybe pass a string to write to a file??..



122
123
124
# File 'lib/virtualmonkey/ebs.rb', line 122

def populate_volume(server)
   server.spot_check_command(" echo \"blah blah blah\" > #{@mount_point}/data.txt")
end

#restore_and_grow(server, new_size, force) ⇒ Object

  • server<~Server> the server to restore to



97
98
99
100
101
102
103
104
# File 'lib/virtualmonkey/ebs.rb', line 97

def restore_and_grow(server,new_size,force)
  options = { "EBS_MOUNT_POINT" => "text:#{@mount_point}",
          "EBS_TOTAL_VOLUME_GROUP_SIZE" => "text:#{new_size}",
          "OPT_DB_FORCE_RESTORE" => "text:#{force}",
          "EBS_LINEAGE" => "text:#{@lineage}" }
  audit = server.run_executable(@scripts_to_run['grow_volume'], options)
  audit.wait_for_completed
end

#restore_from_backup(server, force) ⇒ Object

  • server<~Server> the server to restore to



88
89
90
91
92
93
94
# File 'lib/virtualmonkey/ebs.rb', line 88

def restore_from_backup(server,force)
  options = { "EBS_MOUNT_POINT" => "text:#{@mount_point}",
          "OPT_DB_FORCE_RESTORE" => "text:#{force}",
          "EBS_LINEAGE" => "text:#{@lineage}" }
  audit = server.run_executable(@scripts_to_run['restore'], options)
  audit.wait_for_completed
end

#set_variation_lineage(kind = nil) ⇒ Object

sets the lineage for the deployment

  • kind<~String> can be “chef” or nil



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/virtualmonkey/ebs.rb', line 30

def set_variation_lineage(kind = nil)
  @lineage = "testlineage#{@deployment.href.split(/\//).last}"
  if kind
    raise "Only support nil kind for ebs lineage"
  else
    @deployment.set_input('EBS_LINEAGE', "text:#{@lineage}")
    # unset all server level inputs in the deployment to ensure use of 
    # the setting from the deployment level
    @deployment.servers_no_reload.each do |s|
      s.set_input('EBS_LINEAGE', "text:")
    end
  end
end

#set_variation_mount_point(mnt) ⇒ Object

sets the EBS mount point for the runner

  • kind<~String>



24
25
26
# File 'lib/virtualmonkey/ebs.rb', line 24

def set_variation_mount_point(mnt)
  @mount_point = mnt
end

#set_variation_stripe_count(count) ⇒ Object

sets the stripe count for the deployment

  • count<~String> eg. “3”



11
12
13
14
# File 'lib/virtualmonkey/ebs.rb', line 11

def set_variation_stripe_count(count)
  @stripe_count = count
  @deployment.set_input("EBS_STRIPE_COUNT", "text:#{@stripe_count}")
end

#set_variation_volume_size(size) ⇒ Object

sets the volume size n GB for the runner

  • kind<~Num>



18
19
20
# File 'lib/virtualmonkey/ebs.rb', line 18

def set_variation_volume_size(size)
  @volume_size = size
end

#stop_allObject

Use the termination script to stop all the servers (this cleans up the volumes)



135
136
137
138
139
140
141
142
# File 'lib/virtualmonkey/ebs.rb', line 135

def stop_all
  @servers.each do |s|
    terminate_server(s) if s.state == 'operational' || s.state == 'stranded'
  end
  @servers.each { |s| s.wait_for_state("stopped") }
  # unset dns in our local cached copy..
  @servers.each { |s| s.params['dns-name'] = nil }
end

#terminate_server(server) ⇒ Object

  • server<~Server> the server to terminate



127
128
129
130
131
132
# File 'lib/virtualmonkey/ebs.rb', line 127

def terminate_server(server)
  options = { "EBS_MOUNT_POINT" => "text:#{@mount_point}",
          "EBS_TERMINATE_SAFETY" => "text:off" }
  audit = server.run_executable(@scripts_to_run['terminate'], options)
  audit.wait_for_completed
end

#test_restoreObject



150
151
152
153
# File 'lib/virtualmonkey/ebs.rb', line 150

def test_restore
  behavior(:restore_from_backup, s_two, false)
  behavior(:test_volume_data, s_two)
end

#test_restore_growObject



143
144
145
146
147
148
# File 'lib/virtualmonkey/ebs.rb', line 143

def test_restore_grow
  grow_to_size=100
  behavior(:restore_and_grow, s_three, grow_to_size, false)
  behavior(:test_volume_data, s_three)
  behavior(:test_volume_size, s_three, grow_to_size)
end

#test_volume_data(server) ⇒ Object

Verify that the volume has special data on it.



107
108
109
# File 'lib/virtualmonkey/ebs.rb', line 107

def test_volume_data(server)
  server.spot_check_command("test -f #{@mount_point}/data.txt")
end

#test_volume_size(server, expected_size) ⇒ Object

Verify that the volume is the expected size



112
113
114
115
116
117
118
# File 'lib/virtualmonkey/ebs.rb', line 112

def test_volume_size(server,expected_size)
  puts "Testing with: #{@mount_point} #{expected_size}"
puts "THIS DOES NOT WORK - cause of rounding errors during volume size determination, FS overhead  and df's output"
puts "Need to query the volumes attached to the server and verify that they #{expected_size}/#{@stripe_count}"
puts "Check that the server's volumes are #{expected_size}"
#      server.spot_check_command("df -kh | awk -F\" \" -v -v size=#{expected_size}G '/#{@mount_point}/ {exit $2!=size}'")
end

#wait_for_snapshotsObject

take the lineage name, find all snapshots and sleep until none are in the pending state.



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/virtualmonkey/ebs.rb', line 45

def wait_for_snapshots
  timeout=1500
  step=10
  while timeout > 0
    puts "Checking for snapshot completed"
    snapshots = behavior(:find_snapshots)
    status= snapshots.map { |x| x.aws_status } 
    break unless status.include?("pending")
    sleep step
    timeout -= step
  end
  raise "FATAL: timed out waiting for all snapshots in lineage #{@lineage} to complete" if timeout == 0
end