rest_connection 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.7
1
+ 0.0.8
@@ -0,0 +1 @@
1
+ For an example of how rest_connection is used for acceptance testing with cucumber take a look at the cucumber directory. The step-definitions files are where we turn this stuff into human readable tests.
@@ -0,0 +1,61 @@
1
+ @mysql_5.x
2
+ Feature: mysql 5.x v2 (beta) promote operations test image
3
+ Tests the RightScale premium ServerTemplate Mysql v2 (beta)
4
+
5
+ Scenario: Setup 2 server deployment and run basic cluster failover operations
6
+ #
7
+ # PHASE 1) Bootstrap a backup lineage from scratch
8
+ #
9
+ Given A deployment.
10
+ And A set of RightScripts for MySQL promote operations.
11
+ Then I should stop the mysql servers.
12
+ Then I should set an oldschool variation lineage.
13
+ Then I should set a variation stripe count of "1".
14
+ Then I should set a variation MySQL DNS.
15
+ Then all servers should go operational.
16
+ Then I should create a MySQL EBS stripe on server "1".
17
+ Then the rightscript should complete successfully.
18
+ Then I should run a mysql query "create database mynewtest" on server "1".
19
+ Then I should setup master dns to point at server "1".
20
+ # This sleep is to wait for DNS to settle
21
+ Then I should sleep 120 seconds.
22
+ When I run a rightscript named "backup" on server "1".
23
+ Then the rightscript should complete successfully.
24
+
25
+ #
26
+ # PHASE 2) Relaunch and run restore operations
27
+ #
28
+ Then I should stop the mysql servers.
29
+ Then all servers should go operational.
30
+ And A set of RightScripts for MySQL promote operations.
31
+
32
+ # This sleep is required for the EBS snapshot to settle from prior backup.
33
+ # Assuming 5 minutes already passed while booting.
34
+ Then I should sleep 500 seconds.
35
+ When I run a rightscript named "restore" on server "1".
36
+ Then the rightscript should complete successfully.
37
+ Then the servers should have monitoring enabled.
38
+
39
+ # This sleep is required for the EBS volume snapshot to settle.
40
+ # The sleep time can vary so if slave init fails with no snapshot, this is a likely culprit.
41
+ Then I should sleep 900 seconds.
42
+ When I run a rightscript named "slave_init" on server "2".
43
+ Then the rightscript should complete successfully.
44
+ When I run a rightscript named "promote" on server "2".
45
+ Then the rightscript should complete successfully.
46
+
47
+ #
48
+ # PHASE 3)
49
+ #
50
+
51
+ Then I should reboot the servers.
52
+ Then I should wait for the servers to be operational with dns.
53
+
54
+ When I run a rightscript named "backup" on server "1".
55
+ Then the rightscript should complete successfully.
56
+ #
57
+ # PHASE 4) cleanup
58
+ #
59
+ Then I should release the dns records for use with other deployments.
60
+
61
+ #TODO: spot check for operational mysql
@@ -0,0 +1,140 @@
1
+ require "rubygems"
2
+ require "rest_connection"
3
+ require "net/ssh"
4
+
5
+ Given /A deployment./ do
6
+ raise "FATAL: Please set the environment variable $DEPLOYMENT" unless ENV['DEPLOYMENT']
7
+ @all_servers = Array.new
8
+ @all_servers_os = Array.new
9
+ @all_responses = Array.new
10
+ @deployment = Deployment.find_by_nickname_speed(ENV['DEPLOYMENT']).first
11
+ @servers = @deployment.servers
12
+
13
+ if ENV['SERVER_TAG']
14
+ puts "found SERVER_TAG environment variable. Scoping server list with tag: #{ENV['SERVER_TAG']}"
15
+ @servers = @servers.select { |s| s.nickname =~ /#{ENV['SERVER_TAG']}/ }
16
+ end
17
+
18
+ raise "FATAL: Couldn't find a deployment with the name #{ENV['DEPLOYMENT']}!" unless @deployment
19
+ puts "found deployment to use: #{@deployment.nickname}, #{@deployment.href}"
20
+ end
21
+
22
+ Given /^with ssh private key$/ do
23
+ raise "FATAL: Please set the environment $SSH_KEY_PATH to the private ssh key of the server that you want to test!" unless ENV['SSH_KEY_PATH']
24
+ @deployment.connection.settings[:ssh_key] = ENV['SSH_KEY_PATH']
25
+ end
26
+
27
+ Given /^with a known OS$/ do
28
+ @all_servers.each do |server|
29
+ puts "server.spot_check_command?(\"lsb_release -is | grep Ubuntu\") = #{server.spot_check_command?("lsb_release -is | grep Ubuntu")}"
30
+ if server.spot_check_command?("lsb_release -is | grep Ubuntu")
31
+ puts "setting server to ubuntu"
32
+ @all_servers_os << "ubuntu"
33
+ else
34
+ puts "setting server to centos"
35
+ @all_servers_os << "centos"
36
+ end
37
+ end
38
+ end
39
+
40
+ Given /^"([^\"]*)" operational servers./ do |num|
41
+ servers = @deployment.servers_no_reload
42
+ @servers = servers.select { |s| s.nickname =~ /#{ENV['SERVER_TAG']}/ }
43
+ # only want 2 even if we matched more than that.
44
+ @servers = @servers.slice(0,2)
45
+ raise "need at least #{num} servers to start, only have: #{@servers.size}" if @servers.size < num.to_i
46
+ @servers.each { |s| s.start }
47
+ @servers.each { |s| s.wait_for_operational_with_dns }
48
+ end
49
+
50
+ Given /A deployment named "(.*)"/ do | deployment |
51
+ @all_servers = Array.new
52
+ @all_responses = Array.new
53
+ @deployment = Deployment.find_by_nickname_speed(deployment).first
54
+ raise "FATAL: Couldn't find a deployment with the name #{deployment}!" unless deployment
55
+ end
56
+
57
+ Given /A server named "(.*)"/ do |server|
58
+ servers = @deployment.servers_no_reload
59
+ @server = servers.detect { |s| s.nickname =~ /#{server}/ }
60
+ @server.start
61
+ @server.wait_for_state("operational")
62
+ raise "FATAL: couldn't find a server named #{server}" unless server
63
+ end
64
+
65
+ Given /^"([^\"]*)" operational servers named "([^\"]*)"$/ do |num, server_name|
66
+ servers = @deployment.servers_no_reload
67
+ @servers = servers.select { |s| s.nickname =~ /#{server_name}/ }
68
+ @servers.each do |s|
69
+ @all_servers.push s
70
+ end
71
+ #@all_servers.push { |s| s.nickname =~ /#{server_name}/ }
72
+ raise "need at least #{num} servers to start, only have: #{@servers.size}" if @servers.size < num.to_i
73
+ @servers.each { |s| s.start }
74
+ @servers.each { |s| s.wait_for_operational_with_dns }
75
+ end
76
+
77
+ Then /^I should sleep (\d+) seconds\.$/ do |seconds|
78
+ sleep seconds.to_i
79
+ end
80
+
81
+ Then /^I should set rs_agent_dev:package to "(.*)"\.$/ do |package|
82
+ @deployment.servers_no_reload.each do |s|
83
+ s.tags << {"name"=>"rs_agent_dev:package=#{package}"}
84
+ s.save
85
+ end
86
+ end
87
+
88
+ Then /^I should set un-set all tags on all servers in the deployment\.$/ do
89
+ @deployment.servers_no_reload.each do |s|
90
+ # can't unset ALL tags, so we must set a bogus one
91
+ s.tags = [{"name"=>"removeme:now=1"}]
92
+ s.save
93
+ end
94
+ end
95
+
96
+ Then /^the servers should have monitoring enabled\.$/ do
97
+ @servers.each do |server|
98
+ server.monitoring
99
+ end
100
+ end
101
+
102
+ Then /I should set a variation bucket./ do
103
+ bucket = "text:testingcandelete#{@deployment.href.split(/\//).last}"
104
+ @deployment.set_input('remote_storage/default/container', bucket)
105
+ # unset all server level inputs in the deployment to ensure use of
106
+ # the setting from the deployment level
107
+ @deployment.servers_no_reload.each do |s|
108
+ s.set_input('remote_storage/default/container', "text:")
109
+ end
110
+ end
111
+ Then /I should wait for the servers to be operational with dns\.$/ do
112
+ @servers.each { |s| s.wait_for_operational_with_dns }
113
+ end
114
+ Then /all servers should go operational./ do
115
+ raise "ERROR: no servers found in deployment '#{ENV['DEPLOYMENT']}'" if @servers.size == 0
116
+
117
+ @servers.each { |s| s.start }
118
+ @servers.each { |s| s.wait_for_operational_with_dns }
119
+ end
120
+
121
+ Then /all servers should shutdown./ do
122
+ servers = @deployment.servers_no_reload
123
+ server_tag = ENV['SERVER_TAG']
124
+ @servers = servers.select { |s| s.nickname =~ /#{server_tag}/ }
125
+ raise "ERROR: no servers with tag '#{server_tag}' found in deployment '#{ENV['DEPLOYMENT']}'" if @servers.size == 0
126
+ @servers.each { |s| s.stop }
127
+ @servers.each { |s| s.wait_for_state("terminated") }
128
+ end
129
+
130
+ Then /I should reboot the servers\.$/ do
131
+ @servers.each { |s| s.reboot }
132
+ @servers.each { |s| s.wait_for_state_change }
133
+ end
134
+
135
+ Then /I should stop the servers\.$/ do
136
+ @servers.each { |s| s.stop }
137
+ @servers.each { |s| s.wait_for_state("stopped") }
138
+ # need to unset dns ?
139
+ @servers.each { |s| s.dns_name = "" }
140
+ end
@@ -0,0 +1,147 @@
1
+ require 'rubygems'
2
+ require 'sqlite3'
3
+
4
+ Given /A set of RightScripts for MySQL promote operations\.$/ do
5
+ st = ServerTemplate.find(@servers[1].server_template_href)
6
+ @scripts_to_run = {}
7
+ @scripts_to_run['restore'] = st.executables.detect { |ex| ex.name =~ /restore and become/i }
8
+ @scripts_to_run['slave_init'] = st.executables.detect { |ex| ex.name =~ /slave init v2/ }
9
+ @scripts_to_run['promote'] = st.executables.detect { |ex| ex.name =~ /promote to master/ }
10
+ @scripts_to_run['backup'] = st.executables.detect { |ex| ex.name =~ /EBS backup/ }
11
+ @scripts_to_run['terminate'] = st.executables.detect { |ex| ex.name =~ /TERMINATE/ }
12
+ # hardwired script! hax! (this is an 'anyscript' that users typically use to setup the master dns)
13
+ @scripts_to_run['master_init'] = RightScript.new('href' => "/api/acct/2901/right_scripts/195053")
14
+ @scripts_to_run['create_stripe'] = RightScript.new('href' => "/api/acct/2901/right_scripts/198381")
15
+ @scripts_to_run['create_mysql_ebs_stripe'] = RightScript.new('href' => "/api/acct/2901/right_scripts/212492")
16
+ end
17
+
18
+ Then /^I should run a mysql query "([^\"]*)" on server "([^\"]*)"\.$/ do |query, server_index|
19
+ human_index = server_index.to_i - 1
20
+ query_command = "echo -e \"#{query}\"| mysql"
21
+ @servers[human_index].spot_check(query_command) { |result| puts result }
22
+ end
23
+
24
+ Then /^I should setup admin and replication privileges on server "([^\"]*)"\.$/ do |server_index|
25
+ human_index = server_index.to_i - 1
26
+ admin_grant = "grant all privileges on *.* to admin_user@\'%\' identified by \'admin_passwd\'"
27
+ rep_grant = "grant replication slave on *.* to replication_user@\'%\' identified by \'replication_passwd\'"
28
+ admin_grant2 = "grant all privileges on *.* to admin_user@\'localhost\' identified by \'admin_passwd\'"
29
+ rep_grant2 = "grant replication slave on *.* to replication_user@\'localhost\' identified by \'replication_passwd\'"
30
+ [admin_grant, rep_grant, admin_grant2, rep_grant2].each do |query|
31
+ query_command = "echo -e \"#{query}\"| mysql"
32
+ puts @servers[human_index].spot_check_command(query_command)
33
+ end
34
+ end
35
+
36
+ Then /I should set a variation lineage./ do
37
+ @lineage = "text:testlineage#{rand(1000000)}"
38
+ @deployment.set_input('db/backup/lineage', @lineage)
39
+ # unset all server level inputs in the deployment to ensure use of
40
+ # the setting from the deployment level
41
+ @deployment.servers_no_reload.each do |s|
42
+ s.set_input('db/backup/lineage', "text:")
43
+ end
44
+ end
45
+
46
+ Then /I should set a variation backup prefix./ do
47
+ @lineage = "text:testlineage#{rand(1000000)}"
48
+ @deployment.set_input('DB_EBS_PREFIX', @lineage)
49
+ # unset all server level inputs in the deployment to ensure use of
50
+ # the setting from the deployment level
51
+ @deployment.servers_no_reload.each do |s|
52
+ s.set_input('DB_EBS_PREFIX', "text:")
53
+ end
54
+ end
55
+
56
+ Then /I should set an oldschool variation lineage./ do
57
+ @lineage = "text:testlineage#{rand(1000000)}"
58
+ @deployment.set_input('DB_LINEAGE_NAME', @lineage)
59
+ # unset all server level inputs in the deployment to ensure use of
60
+ # the setting from the deployment level
61
+ @deployment.servers_no_reload.each do |s|
62
+ s.set_input('DB_LINEAGE_NAME', "text:")
63
+ end
64
+ puts "Using Lineage: #{@lineage}"
65
+ end
66
+
67
+ Then /^I should create a MySQL EBS stripe on server "([^\"]*)"\.$/ do |server_index|
68
+ human_index = server_index.to_i - 1
69
+ # this needs to match the deployments inputs for lineage and stripe count.
70
+ options = { "EBS_MOUNT_POINT" => "text:/mnt/mysql",
71
+ "EBS_STRIPE_COUNT" => "text:#{@stripe_count}",
72
+ "EBS_VOLUME_SIZE_GB" => "text:1",
73
+ "DBAPPLICATION_USER" => "text:someuser",
74
+ "DBAPPLICATION_PASSWORD" => "text:somepass",
75
+ "EBS_VOLUME_SIZE_GB" => "text:1",
76
+ "EBS_LINEAGE" => @lineage }
77
+ @status = @servers[human_index].run_executable(@scripts_to_run['create_mysql_ebs_stripe'], options)
78
+ end
79
+
80
+ Then /^I should create an EBS stripe on server "([^\"]*)"\.$/ do |server_index|
81
+ human_index = server_index.to_i - 1
82
+ # this needs to match the deployments inputs for lineage and stripe count.
83
+ options = { "EBS_MOUNT_POINT" => "text:/mnt/mysql",
84
+ "EBS_STRIPE_COUNT" => "text:#{@stripe_count}",
85
+ "EBS_VOLUME_SIZE_GB" => "text:1",
86
+ "EBS_LINEAGE" => @lineage }
87
+ @status = @servers[human_index].run_executable(@scripts_to_run['create_stripe'], options)
88
+ end
89
+
90
+ Then /^I should set a variation stripe count of "([^\"]*)"\.$/ do |stripe|
91
+ @stripe_count = stripe
92
+ @deployment.set_input("EBS_STRIPE_COUNT", "text:#{@stripe_count}")
93
+ end
94
+
95
+ Then /^I should set a variation MySQL DNS\./ do
96
+ mydb = File.join(File.dirname(__FILE__),"..","shared.db")
97
+ @dns_result = nil
98
+ rowid = nil
99
+ success = nil
100
+ SQLite3::Database.new(mydb) do |db|
101
+ while(1)
102
+ db.query("SELECT rowid FROM mysql_dns WHERE owner IS NULL") do |result|
103
+ rowid = result.entries.first
104
+ end
105
+ raise "FATAL: unable to find available DNS_IDs to use!" unless rowid
106
+ handle = db.query("UPDATE OR IGNORE mysql_dns SET owner='#{@deployment.nickname}' WHERE rowid = '#{rowid}'")
107
+ handle.close
108
+ success = db.get_first_row("SELECT owner FROM mysql_dns WHERE rowid = '#{rowid}'").first == @deployment.nickname
109
+ break if success
110
+ puts "retrying for lock on DNSIDs"
111
+ end
112
+ db.query("SELECT MASTER_DB_DNSNAME,MASTER_DB_DNSID,SLAVE_DB_DNSNAME,SLAVE_DB_DNSID FROM mysql_dns WHERE owner = '#{@deployment.nickname}'") do |result|
113
+ @dns_result = result.entries.first
114
+ end
115
+ end
116
+ @deployment.set_input("MASTER_DB_DNSNAME", @dns_result[0])
117
+ @deployment.set_input("MASTER_DB_DNSID", @dns_result[1])
118
+ @deployment.set_input("SLAVE_DB_DNSNAME", @dns_result[2])
119
+ @deployment.set_input("SLAVE_DB_DNSID", @dns_result[3])
120
+ end
121
+
122
+ Then /^I should release the dns records for use with other deployments\.$/ do
123
+ require 'sqlite3'
124
+ SQLite3::Database.new(File.join(File.dirname(__FILE__), "..", "shared.db")) do |db|
125
+ q = db.query("UPDATE mysql_dns SET owner=NULL where owner LIKE '#{@deployment.nickname}%'")
126
+ q.close
127
+ end
128
+ end
129
+
130
+ Then /^I should setup master dns to point at server "([^\"]*)"\.$/ do |server_index|
131
+ human_index = server_index.to_i - 1
132
+ audit = @servers[human_index].run_executable(@scripts_to_run['master_init']) #, {'DB_TEST_MASTER_DNSID' => @dns_result[1]})
133
+ audit.wait_for_completed
134
+ #@servers[human_index].run_script(@scripts_to_run['master_init']) #, {'DB_TEST_MASTER_DNSID' => @dns_result[1]})
135
+ end
136
+
137
+ Then /I should stop the mysql servers\.$/ do
138
+ if @scripts_to_run['terminate']
139
+ @servers.each { |s| s.run_executable(@scripts_to_run['terminate']) unless s.state == 'stopped' }
140
+ else
141
+ @servers.each { |s| s.stop }
142
+ end
143
+
144
+ @servers.each { |s| s.wait_for_state("stopped") }
145
+ # unset dns in our local cached copy..
146
+ @servers.each { |s| s.dns_name = "" }
147
+ end
@@ -0,0 +1,54 @@
1
+ When /^I run a recipe named "([^\"]*)" on server "([^\"]*)"\.$/ do |recipe, server_index|
2
+ human_index = server_index.to_i - 1
3
+ STDOUT.puts "#{recipe} -> root@#{@servers[human_index].dns_name}"
4
+ @response = @servers[human_index].run_recipe(recipe)
5
+ end
6
+
7
+ Then /I should successfully run a recipe named "(.*)"/ do |recipe|
8
+ @server.run_recipe(recipe)
9
+ end
10
+
11
+ Then /^I should run a recipe named "([^\"]*)" on server "([^\"]*)"\.$/ do |recipe, server_index|
12
+ human_index = server_index.to_i - 1
13
+ @servers[human_index].run_recipe(recipe)
14
+ end
15
+
16
+ Then /^it should converge successfully\.$/ do
17
+ @response[:status].should == true
18
+ end
19
+
20
+ When /^I clear the log on server "(.*)".$/ do |server_index|
21
+ human_index = server_index.to_i - 1
22
+ cmd = "rm -f /var/log/messages; touch /var/log/messages ; chown root:root /var/log/messages ; chmod 600 /var/log/messages"
23
+ @response = @servers[human_index].spot_check(cmd) do |result|
24
+ puts result
25
+ end
26
+ end
27
+
28
+ Then /^I should see "(.*)" in the log on server "(.*)"\.$/ do |message, server_index|
29
+ human_index = server_index.to_i - 1
30
+ @servers[human_index].spot_check("grep '#{message}' /var/log/messages") do |result|
31
+ result.should_not == nil
32
+ end
33
+ end
34
+
35
+ Then /^the audit entry should NOT contain "([^\"]*)"\.$/ do |st_match|
36
+ @response[:output].should_not include(st_match)
37
+ end
38
+
39
+ Then /^all servers should successfully run a recipe named "(.*)"\.$/ do |recipe|
40
+ @servers.each do |s|
41
+ response = s.run_recipe(recipe)
42
+ response[:status].should == true
43
+ end
44
+ end
45
+
46
+ When /^I run a rightscript named "([^\"]*)" on server "([^\"]*)"\.$/ do |script, server_index|
47
+ human_index = server_index.to_i - 1
48
+ @status = @servers[human_index].run_executable(@scripts_to_run[script])
49
+ @audit_link = @servers[human_index].audit_link
50
+ end
51
+
52
+ Then /^the rightscript should complete successfully\.$/ do
53
+ @status.wait_for_completed(@audit_link)
54
+ end
@@ -0,0 +1,35 @@
1
+ Then /^I should run a command "([^\"]*)" on server "([^\"]*)"\.$/ do |command, server_index|
2
+ human_index = server_index.to_i - 1
3
+ @servers[human_index].spot_check(command) { |result| puts result }
4
+ end
5
+
6
+ When /^I run "([^\"]*)"$/ do |command|
7
+ @response = @server.spot_check_command?(command)
8
+ end
9
+
10
+ When /^I run "([^\"]*)" on all servers$/ do |command|
11
+ @all_servers.each_with_index do |s,i|
12
+ @all_responses[i] = s.spot_check_command?(command)
13
+ end
14
+ end
15
+
16
+
17
+ #
18
+ # Checking for request sucess/error
19
+ #
20
+ Then /^it should exit successfully$/ do
21
+ @response.should be true
22
+ end
23
+
24
+ Then /^it should exit successfully on all servers$/ do
25
+ @all_responses.each do |response|
26
+ response.should be true
27
+ end
28
+ end
29
+
30
+ Then /^it should not exit successfully on any server$/ do
31
+ @all_responses.each do |response|
32
+ response.should_not be true
33
+ end
34
+ end
35
+
@@ -6,40 +6,22 @@ require 'rest_connection'
6
6
  opts = Trollop::options do
7
7
  opt :deployment, "deployment nickname", :type => :string, :required => false
8
8
  opt :only, "regex string matching the nickname of the servers you want to relaunch. This excludes servers that do not match\nExample --only ubuntu", :type => :string, :required => false
9
- opt :growl, "use growl notification (string) when servers are all operational, requires ruby-growl gem", :type => :string, :required => false
10
9
  opt :id, "deployment id", :type => :string, :required => false
11
10
  end
12
11
 
13
12
  # find all servers in the deployment (the fast way)
14
13
  if opts[:id]
15
- deployment = Deployment.find_by_id(opts[:id])
14
+ deployment = Deployment.find(opts[:id])
16
15
  else
17
16
  deployment = Deployment.find_by_nickname_speed(opts[:deployment]).first
18
17
  end
19
18
  servers = deployment.servers_no_reload
20
19
  servers = servers.select { |s| s.nickname =~ /#{opts[:only]}/ } if opts[:only]
21
20
  servers.each do |s|
22
- # send stop
23
- s.relaunch
21
+ s.stop
22
+ end
23
+ servers.each do |s|
24
+ s.wait_for_state("stopped")
25
+ s.start
24
26
  end
25
27
 
26
- # wait for termination
27
- #servers.each do |s|
28
- # s.wait_for_state('stopped')
29
- #end
30
-
31
- # relaunch
32
- #servers.each do |s|
33
- # s.start
34
- #end
35
-
36
- #if opts[:growl]
37
- # require 'ruby-growl'
38
- # servers.each do |s|
39
- # s.wait_for_state('booting')
40
- # end
41
- # g = Growl.new "localhost", "ruby-growl",
42
- # ["ruby-growl Notification"]
43
- #g.notify "ruby-growl Notification", "It Came From Ruby-Growl",
44
- # "Greetings!"
45
- #end
@@ -197,7 +197,7 @@ module RestConnection
197
197
  elsif prefix.nil?
198
198
  parameters
199
199
  else
200
- "#{CGI.escape(prefix)}=#{CGI.escape(parameters.to_s)}"
200
+ "#{prefix}=#{CGI.escape(parameters.to_s)}"
201
201
  end
202
202
  end
203
203
 
@@ -22,14 +22,26 @@
22
22
  class Ec2ServerArray
23
23
  include RightScale::Api::Base
24
24
  extend RightScale::Api::BaseExtend
25
+
25
26
  def run_script_on_all(script, server_template_hrefs, inputs=nil)
26
27
  serv_href = URI.parse(self.href)
27
28
  options = Hash.new
28
29
  options[:ec2_server_array] = Hash.new
29
- options[:ec2_server_array][:right_script_href] = self.href
30
+ options[:ec2_server_array][:right_script_href] = script.href
30
31
  options[:ec2_server_array][:parameters] = inputs unless inputs.nil?
31
32
  options[:ec2_server_array][:server_template_hrefs] = server_template_hrefs
32
- connection.post(serv_href.path, options)
33
+ # bug, this only returns work units if using xml, for json all we get is nil. scripts still run though ..
34
+ connection.post("#{serv_href.path}/run_script_on_all", options)
35
+ end
36
+
37
+ def instances
38
+ serv_href = URI.parse(self.href)
39
+ connection.get("#{serv_href.path}/instances")
40
+ end
41
+
42
+ def terminate_all
43
+ serv_href = URI.parse(self.href)
44
+ connection.post("#{serv_href.path}/terminate_all")
33
45
  end
34
46
  end
35
47
 
@@ -45,6 +45,14 @@ module RightScale
45
45
  return a
46
46
  end
47
47
 
48
+ def self.find_by_cloud_id(cloud_id)
49
+ a = Array.new
50
+ connection.get(self.resource_plural_name, "cloud_id" => cloud_id).each do |object|
51
+ a << self.new(object)
52
+ end
53
+ return a
54
+ end
55
+
48
56
  def find_by_nickname(nickname)
49
57
  connection.logger("DEPRICATION WARNING: use of find_by_nickname is depricated, please use find_by(:nickname) { |n| n == '#{nickname}' } ")
50
58
  self.find_by(:nickname) { |n| n == nickname }
@@ -144,15 +152,22 @@ module RightScale
144
152
  assignment = mn.gsub!(/=/,"")
145
153
  mn_dash = mn.gsub(/_/,"-")
146
154
  if @params[mn]
147
- @params[mn] = args[0] if assignment
155
+ if assignment
156
+ @params[mn] = args[0]
157
+ @params[mn_dash] = args[0]
158
+ end
148
159
  return @params[mn]
149
160
  elsif @params[mn_dash]
150
- @params[mn_dash] = args[0] if assignment
161
+ if assignment
162
+ @params[mn_dash] = args[0]
163
+ @params[mn] = args[0]
164
+ end
151
165
  return @params[mn_dash]
152
166
  elsif @params[mn.to_sym]
153
167
  return @params[mn.to_sym]
154
168
  elsif assignment
155
169
  @params[mn] = args[0]
170
+ @params[mn_dash] = args[0]
156
171
  return @params[mn]
157
172
  else
158
173
  return nil
@@ -36,3 +36,4 @@ require 'rest_connection/rightscale/ec2_ssh_key_internal'
36
36
  require 'rest_connection/rightscale/server_template_internal'
37
37
  require 'rest_connection/rightscale/multi_cloud_image_internal'
38
38
  require 'rest_connection/rightscale/multi_cloud_image_cloud_setting_internal'
39
+ require 'rest_connection/rightscale/ec2_server_array'
@@ -18,12 +18,24 @@ class ServerTemplate
18
18
  extend RightScale::Api::BaseExtend
19
19
  def initialize(params)
20
20
  @params = params
21
- fetch_executables
22
21
  end
23
-
22
+
23
+ def executables
24
+ unless @params["executables"]
25
+ fetch_executables
26
+ end
27
+ @params["executables"]
28
+ end
29
+
30
+ def multi_cloud_images
31
+ unless @params["multi_cloud_images"]
32
+ fetch_multi_cloud_images
33
+ end
34
+ @params["multi_cloud_images"]
35
+ end
36
+
24
37
  def fetch_executables
25
38
  my_href = URI.parse(self.href)
26
- #@params.merge! :executables =? connection.get(my_href.path + "/executables")
27
39
  ex = []
28
40
  connection.get(my_href.path + "/executables").each do |e|
29
41
  ex << Executable.new(e)
@@ -18,6 +18,18 @@ class Tag
18
18
  extend RightScale::Api::BaseExtend
19
19
 
20
20
  def self.search(resource_name, tags)
21
- result = connection.get("/tags/search", :resource_type => resource_name.to_s, :tags => tags )
21
+ result = connection.get("tags/search", :resource_type => resource_name.to_s, :tags => tags )
22
+ end
23
+
24
+ #TAGGABLE_RESOURCES = [ 'Server', 'Ec2EbsSnapshot', 'Ec2EbsVolume', 'Ec2Image', 'Image', 'ServerArray', 'Ec2Instance',
25
+ # 'Instance', 'Deployment', 'ServerTemplate', 'Ec2ServerTemplate' ]
26
+ #
27
+ # Tag.set( resource_href, tags ) where tags is an array of tags to set on the resource.
28
+ def self.set(resource_href, tags)
29
+ connection.put("tags/set", :resource_href => resource_href, :tags => tags)
30
+ end
31
+
32
+ def self.unset(resource_href, tags)
33
+ connection.put("tags/unset", :resource_href => resource_href, :tags => tags)
22
34
  end
23
35
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rest_connection}
8
- s.version = "0.0.7"
8
+ s.version = "0.0.8"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jeremy Deininger"]
12
- s.date = %q{2010-05-24}
12
+ s.date = %q{2010-06-22}
13
13
  s.description = %q{provides rest_connection}
14
14
  s.email = %q{jeremy@rubyonlinux.org}
15
15
  s.extra_rdoc_files = [
@@ -21,16 +21,15 @@ Gem::Specification.new do |s|
21
21
  "Rakefile",
22
22
  "VERSION",
23
23
  "config/rest_api_config.yaml.sample",
24
+ "examples/README.txt",
24
25
  "examples/console.rb",
25
- "examples/dev_setup.rb",
26
+ "examples/cucumber/2mysql_5.x_v2_beta_from_scratch.feature",
27
+ "examples/cucumber/step_definitions/deployment_steps.rb",
28
+ "examples/cucumber/step_definitions/mysql_steps.rb",
29
+ "examples/cucumber/step_definitions/recipe_steps.rb",
30
+ "examples/cucumber/step_definitions/spot_check_steps.rb",
26
31
  "examples/relaunch_deployment.rb",
27
- "examples/restart_instance_agent.rb",
28
32
  "examples/right_scale_ec2_instances_api_test.rb",
29
- "examples/run_ebs_sequence.rb",
30
- "examples/run_ebs_terminate.rb",
31
- "examples/run_mysql_chef_sequence.rb",
32
- "examples/run_php_chef_sequence.rb",
33
- "examples/set_deployment_template_href.rb",
34
33
  "lib/rest_connection.rb",
35
34
  "lib/rest_connection/rightscale/audit_entry.rb",
36
35
  "lib/rest_connection/rightscale/deployment.rb",
@@ -58,12 +57,14 @@ Gem::Specification.new do |s|
58
57
  "lib/rest_connection/rightscale/tag.rb",
59
58
  "lib/rest_connection/ssh_hax.rb",
60
59
  "rest_connection.gemspec",
60
+ "spec/ec2_server_array_spec.rb",
61
61
  "spec/ec2_ssh_key_internal_spec.rb",
62
62
  "spec/image_jockey.rb",
63
63
  "spec/method_missing_spec.rb",
64
64
  "spec/rs_internal_spec.rb",
65
65
  "spec/server_internal_spec.rb",
66
- "spec/server_spec.rb"
66
+ "spec/server_spec.rb",
67
+ "spec/tag_spec.rb"
67
68
  ]
68
69
  s.homepage = %q{http://github.com/jeremyd/rest_connection}
69
70
  s.rdoc_options = ["--charset=UTF-8"]
@@ -71,22 +72,21 @@ Gem::Specification.new do |s|
71
72
  s.rubygems_version = %q{1.3.7}
72
73
  s.summary = %q{lib for restful connections to the rightscale api}
73
74
  s.test_files = [
74
- "spec/ec2_ssh_key_internal_spec.rb",
75
+ "spec/ec2_server_array_spec.rb",
76
+ "spec/ec2_ssh_key_internal_spec.rb",
75
77
  "spec/image_jockey.rb",
76
78
  "spec/method_missing_spec.rb",
77
79
  "spec/rs_internal_spec.rb",
78
80
  "spec/server_internal_spec.rb",
79
81
  "spec/server_spec.rb",
82
+ "spec/tag_spec.rb",
80
83
  "examples/console.rb",
81
- "examples/dev_setup.rb",
84
+ "examples/cucumber/step_definitions/deployment_steps.rb",
85
+ "examples/cucumber/step_definitions/mysql_steps.rb",
86
+ "examples/cucumber/step_definitions/recipe_steps.rb",
87
+ "examples/cucumber/step_definitions/spot_check_steps.rb",
82
88
  "examples/relaunch_deployment.rb",
83
- "examples/restart_instance_agent.rb",
84
- "examples/right_scale_ec2_instances_api_test.rb",
85
- "examples/run_ebs_sequence.rb",
86
- "examples/run_ebs_terminate.rb",
87
- "examples/run_mysql_chef_sequence.rb",
88
- "examples/run_php_chef_sequence.rb",
89
- "examples/set_deployment_template_href.rb"
89
+ "examples/right_scale_ec2_instances_api_test.rb"
90
90
  ]
91
91
 
92
92
  if s.respond_to? :specification_version then
@@ -0,0 +1,67 @@
1
+ require 'rubygems'
2
+ require 'rest_connection'
3
+ require 'spec'
4
+ require 'ruby-debug'
5
+
6
+ describe Ec2ServerArray, "takes over the world with some server arrays" do
7
+ before(:all) do
8
+ # store temporary resources in @t_resources so we can tear down afterwards
9
+ @t_resources = Hash.new
10
+ @t_resources[:deployment] = Deployment.create(:nickname => "testdeploymentcandelete123")
11
+ @default_sec_group = Ec2SecurityGroup.find(:first) { |g| g.aws_group_name == 'default' }
12
+ @mci = MultiCloudImage.find(:first)
13
+ # Need to hardcode a server template with a script with no inputs, for the test of run on all
14
+ @server_template = ServerTemplate.find(63400)
15
+ #@t_resources[:server_template] = ServerTemplate.create( :nickname => "Nickname of the ServerTemplate",
16
+ # :description => "Description of the ServerTemplate",
17
+ # :multi_cloud_image_href => @mci.href
18
+ # )
19
+
20
+ # SSH Keys index call is 403 forbidden so lookup is not possible.
21
+ # Hardcoded for a default key.
22
+ @ssh_key = Ec2SshKey.find(7053)
23
+ @t_resources[:ec2_server_array] = Ec2ServerArray.create(:nickname => "testarraycandelete123",
24
+ :description => "created by specs run, you can delete this if you want",
25
+ :array_type => "alert",
26
+ #:elasticity_params => ,
27
+ :active => 'true',
28
+ :deployment_href => @t_resources[:deployment].href,
29
+ :server_template_href => @server_template.href,
30
+ #:indicator_href,
31
+ #:audit_queue_href,
32
+ :ec2_ssh_key_href => @ssh_key.href,
33
+ :ec2_security_group_href => @default_sec_group.href,
34
+ #:ec2_security_groups_href => ,
35
+ #:elasticity_function,
36
+ :elasticity => { :min_count => "1", :max_count => "2" },
37
+ #:parameters,
38
+ #:tags,
39
+ :collect_audit_entries => "1"
40
+ )
41
+ @my_array = @t_resources[:ec2_server_array]
42
+ end
43
+
44
+ it "should get all the instances in the array" do
45
+ my_instances = @my_array.instances
46
+ my_instances.class.should == Array
47
+ end
48
+
49
+ it "should run a script on all the servers in the array" do
50
+ right_script = @server_template.executables.first
51
+ result = @my_array.run_script_on_all(right_script, [@server_template.href])
52
+ puts "hello"
53
+ puts "blah"
54
+ end
55
+
56
+ it "should terminate all instances in the array" do
57
+ @my_array.active = "false"
58
+ @my_array.save
59
+ @my_array.terminate_all
60
+ end
61
+
62
+ after(:all) do
63
+ @t_resources.each do |key,val|
64
+ val.destroy
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,19 @@
1
+ require 'rubygems'
2
+ require 'rest_connection'
3
+ require 'spec'
4
+ require 'ruby-debug'
5
+
6
+ describe Tag, "tags" do
7
+ it "a server" do
8
+ mytags = ["provides:rs_blah=blah"]
9
+ search = ["provides:rs_blah"]
10
+ #mytags = ["blah", "blah2"]
11
+ s = Server.find(:first)
12
+ t = Tag.set(s.href, mytags)
13
+ t.response.code.should == "204"
14
+ f = Tag.search("server", mytags)
15
+ f.size.should > 0
16
+ t2 = Tag.unset(s.href, mytags)
17
+ t2.response.code.should == "204"
18
+ end
19
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rest_connection
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 7
10
- version: 0.0.7
9
+ - 8
10
+ version: 0.0.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jeremy Deininger
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-05-24 00:00:00 -07:00
18
+ date: 2010-06-22 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -74,16 +74,15 @@ files:
74
74
  - Rakefile
75
75
  - VERSION
76
76
  - config/rest_api_config.yaml.sample
77
+ - examples/README.txt
77
78
  - examples/console.rb
78
- - examples/dev_setup.rb
79
+ - examples/cucumber/2mysql_5.x_v2_beta_from_scratch.feature
80
+ - examples/cucumber/step_definitions/deployment_steps.rb
81
+ - examples/cucumber/step_definitions/mysql_steps.rb
82
+ - examples/cucumber/step_definitions/recipe_steps.rb
83
+ - examples/cucumber/step_definitions/spot_check_steps.rb
79
84
  - examples/relaunch_deployment.rb
80
- - examples/restart_instance_agent.rb
81
85
  - examples/right_scale_ec2_instances_api_test.rb
82
- - examples/run_ebs_sequence.rb
83
- - examples/run_ebs_terminate.rb
84
- - examples/run_mysql_chef_sequence.rb
85
- - examples/run_php_chef_sequence.rb
86
- - examples/set_deployment_template_href.rb
87
86
  - lib/rest_connection.rb
88
87
  - lib/rest_connection/rightscale/audit_entry.rb
89
88
  - lib/rest_connection/rightscale/deployment.rb
@@ -111,12 +110,14 @@ files:
111
110
  - lib/rest_connection/rightscale/tag.rb
112
111
  - lib/rest_connection/ssh_hax.rb
113
112
  - rest_connection.gemspec
113
+ - spec/ec2_server_array_spec.rb
114
114
  - spec/ec2_ssh_key_internal_spec.rb
115
115
  - spec/image_jockey.rb
116
116
  - spec/method_missing_spec.rb
117
117
  - spec/rs_internal_spec.rb
118
118
  - spec/server_internal_spec.rb
119
119
  - spec/server_spec.rb
120
+ - spec/tag_spec.rb
120
121
  has_rdoc: true
121
122
  homepage: http://github.com/jeremyd/rest_connection
122
123
  licenses: []
@@ -152,19 +153,18 @@ signing_key:
152
153
  specification_version: 3
153
154
  summary: lib for restful connections to the rightscale api
154
155
  test_files:
156
+ - spec/ec2_server_array_spec.rb
155
157
  - spec/ec2_ssh_key_internal_spec.rb
156
158
  - spec/image_jockey.rb
157
159
  - spec/method_missing_spec.rb
158
160
  - spec/rs_internal_spec.rb
159
161
  - spec/server_internal_spec.rb
160
162
  - spec/server_spec.rb
163
+ - spec/tag_spec.rb
161
164
  - examples/console.rb
162
- - examples/dev_setup.rb
165
+ - examples/cucumber/step_definitions/deployment_steps.rb
166
+ - examples/cucumber/step_definitions/mysql_steps.rb
167
+ - examples/cucumber/step_definitions/recipe_steps.rb
168
+ - examples/cucumber/step_definitions/spot_check_steps.rb
163
169
  - examples/relaunch_deployment.rb
164
- - examples/restart_instance_agent.rb
165
170
  - examples/right_scale_ec2_instances_api_test.rb
166
- - examples/run_ebs_sequence.rb
167
- - examples/run_ebs_terminate.rb
168
- - examples/run_mysql_chef_sequence.rb
169
- - examples/run_php_chef_sequence.rb
170
- - examples/set_deployment_template_href.rb
@@ -1,26 +0,0 @@
1
- #!/usr/bin/ruby
2
- require 'rubygems'
3
- require 'trollop'
4
- require 'rest_connection'
5
- require 'net/ssh'
6
-
7
- opts = Trollop::options do
8
- opt :deployment, "deployment nickname", :type => :string, :required => true
9
- opt :only, "regex string matching the nickname of the servers you want to relaunch. This excludes servers that do not match\nExample --only ubuntu", :type => :string, :required => false
10
- opt :growl, "use growl notification (string) when servers are all operational, requires ruby-growl gem", :type => :string, :required => false
11
- end
12
-
13
- # find all servers in the deployment (the fast way)
14
- deployment = Deployment.find_by_nickname_speed(opts[:deployment]).first
15
- servers = deployment.servers_no_reload
16
- servers = servers.select { |s| s.nickname =~ /#{opts[:only]}/ } if opts[:only]
17
-
18
- servers.each do |s|
19
- s.wait_for_operational_with_dns
20
-
21
- Net::SSH.start(s.dns_name, 'root', :keys => ['~/.ssh/publish-test']) do |ssh|
22
- puts "setting up devmode: dropbox::install && devmode::setup_cookbooks"
23
- puts ssh.exec!("rs_run_recipe -n 'dropbox::install'")
24
- puts ssh.exec!("rs_run_recipe -n 'devmode::setup_cookbooks'")
25
- end
26
- end
@@ -1,29 +0,0 @@
1
- #!/usr/bin/ruby
2
- require 'rubygems'
3
- require 'trollop'
4
- require 'rest_connection'
5
- require 'net/ssh'
6
-
7
- opts = Trollop::options do
8
- opt :deployment, "deployment nickname", :type => :string, :required => true
9
- opt :only, "regex string matching the nickname of the servers you want to relaunch. This excludes servers that do not match\nExample --only ubuntu", :type => :string, :required => false
10
- opt :hard, "hard reset, uninstalls right_resources premium gem (for code update), and restarts the instance agent", :type => :bool, :required => false
11
- end
12
-
13
- # find all servers in the deployment (the fast way)
14
- deployment = Deployment.find_by_nickname_speed(opts[:deployment]).first
15
- servers = deployment.servers_no_reload
16
- servers = servers.select { |s| s.nickname =~ /#{opts[:only]}/ } if opts[:only]
17
-
18
- servers.each do |s|
19
- s.wait_for_operational_with_dns
20
- if opts[:hard]
21
- s.spot_check("gem uninstall right_resources_premium") do |result|
22
- puts result
23
- end
24
- s.spot_check("monit restart instance") do |result|
25
- puts result
26
- end
27
- end
28
- s.run_recipe("database_test::dev_pristine_restore")
29
- end
@@ -1,95 +0,0 @@
1
- #!/usr/bin/ruby
2
- require 'rubygems'
3
- require 'trollop'
4
- require 'rest_connection'
5
- #
6
- # EBS regression test
7
- #
8
- # prerequirements: run the macro for EBS stripe deployment
9
- # enter the deployment name below
10
- #
11
-
12
- opts = Trollop::options do
13
- opt :deployment, "deployment nickname", :type => :string, :required => true
14
- end
15
-
16
- #ebs_deployment = Deployment.find_by_nickname_speed("Regression Test - MySQL -STRIPE").first
17
- ebs_deployment = Deployment.find_by_nickname_speed(opts[:deployment]).first
18
-
19
- # select servers by nickname!
20
- mysql_s3 = ebs_deployment.servers.detect { |s| s.nickname =~ /MySQL S3 US db1/i }
21
- mysql_db1 = ebs_deployment.servers.detect { |s| s.nickname =~ /MySQL EBS db1/i }
22
- mysql_db2 = ebs_deployment.servers.detect { |s| s.nickname =~ /MySQL EBS Stripe db1/i }
23
- mysql_db3 = ebs_deployment.servers.detect { |s| s.nickname =~ /MySQL EBS Stripe db2/i }
24
-
25
- # we must reload, so the server can populate it's state. we took a shortcut
26
- # by grabbing the servers from the deployment's json (the rightscale default response)
27
- mysql_s3.reload
28
- mysql_db1.reload
29
- mysql_db2.reload
30
- mysql_db3.reload
31
-
32
- # tweak: (this is closer to an actual user story) setup mysql_db1 for regular EBS
33
- # the rest of the deployment is normally set to text:2
34
- # mysql_db1 is [rev 13] so it needs the old input name
35
-
36
- #mysql_db1.set_input("OPT_EBS_STRIPE_COUNT", "ignore:$ignore")
37
- #mysql_db1.set_input("DB_EBS_PREFIX", "text:shouldnotmatter-candelete652")
38
- #mysql_db1.set_input("DB_LINEAGE_NAME", "text:shouldnotmatter-candelete652")
39
- #mysql_db2.set_input("DB_LINEAGE_NAME", "text:shouldnotmatter-candelete652")
40
- #mysql_db3.set_input("DB_LINEAGE_NAME", "text:shouldnotmatter-candelete652")
41
-
42
- # launch all
43
- mysql_s3.start
44
- mysql_db1.start
45
- mysql_db2.start
46
- mysql_db3.start
47
-
48
- # wait for operational
49
- mysql_s3.wait_for_state('operational')
50
- mysql_db1.wait_for_state('operational')
51
- mysql_db2.wait_for_state('operational')
52
- mysql_db3.wait_for_state('operational')
53
-
54
- sleep 10 #make sure they are operational
55
-
56
- # we need better api support, but for now we can get our RightScripts from info.yml on an instance (or in the current dir)
57
- template_scripts = RightScript.from_instance_info
58
-
59
- # scripts from EBS [rev13]
60
- slave_init_non_ebs_rev4 = RightScript.new('href' => 'right_scripts/45320')
61
- slave_init_non_ebs_v1_rev6 = RightScript.new('href' => 'right_scripts/41484')
62
- restore_rev4 = RightScript.new('href' => 'right_scripts/45319')
63
-
64
- # see how easy this is to cherry pick the scripts by name? this means no resetting of ids across different templates
65
- restore_script = template_scripts.detect { |script| script.name =~ /restore/i }
66
- slave_init_non_ebs = template_scripts.detect { |script| script.name =~ /DB EBS slave init from non-EBS master v1/ }
67
- slave_init_non_stripe = template_scripts.detect { |script| script.name =~ /DB EBS stripe slave init from EBS non-stripe master/i }
68
- promote = template_scripts.detect { |script| script.name =~ /promote/i }
69
- slave_init = template_scripts.detect { |script| script.name == "DB EBS slave init (Stripe alpha)" }
70
- backup = template_scripts.detect { |script| script.name =~ /DB EBS backup/i }
71
-
72
- # breathing room is needed below *only to let the servers
73
- # settle after fail-over operations. wait_for_completed returns
74
- # when the right_script status is 'success' or 'fail'
75
-
76
- status = mysql_db1.run_script(slave_init_non_ebs_v1_rev6)
77
- status = mysql_db1.run_script(slave_init_non_ebs_rev4)
78
- status.wait_for_completed(mysql_db1.audit_link)
79
- sleep 220 #breathing room
80
-
81
- status = mysql_db1.run_script(promote)
82
- status.wait_for_completed(mysql_db1.audit_link)
83
- sleep 220 #breathing room
84
-
85
- status = mysql_db2.run_script(slave_init_non_stripe)
86
- status.wait_for_completed(mysql_db2.audit_link)
87
- sleep 220 # breathing room
88
-
89
- status = mysql_db2.run_script(promote)
90
- status.wait_for_completed(mysql_db2.audit_link)
91
- sleep 220 #breathing room
92
-
93
- status = mysql_db3.run_script(slave_init)
94
- status.wait_for_completed(mysql_db3.audit_link)
95
- puts "done!"
@@ -1,40 +0,0 @@
1
- #!/usr/bin/ruby
2
- require 'rubygems'
3
- require 'trollop'
4
- require File.join(File.dirname(__FILE__), '..', 'lib', 'rightscale_api_resources')
5
-
6
- #
7
- # EBS regression test
8
- #
9
- # prerequirements: run the macro for EBS stripe deployment
10
- # enter the deployment name below
11
- #
12
-
13
- opts = Trollop::options do
14
- opt :deployment, "deployment nickname", :type => :string, :required => true
15
- end
16
-
17
- ebs_deployment = Deployment.find_by_nickname_speed(opts[:deployment]).first
18
- # select servers by nickname!
19
- mysql_s3 = ebs_deployment.servers.detect { |s| s.nickname =~ /MySQL S3 US db1/i }
20
- mysql_db1 = ebs_deployment.servers.detect { |s| s.nickname =~ /MySQL EBS db1/i }
21
- mysql_db2 = ebs_deployment.servers.detect { |s| s.nickname =~ /MySQL EBS Stripe db1/i }
22
- mysql_db3 = ebs_deployment.servers.detect { |s| s.nickname =~ /MySQL EBS Stripe db2/i }
23
-
24
- # we must reload, so the server can populate it's state
25
- mysql_s3.reload
26
- mysql_db1.reload
27
- mysql_db2.reload
28
- mysql_db3.reload
29
-
30
- # stop all
31
- mysql_s3.stop
32
- mysql_db1.stop
33
- mysql_db2.stop
34
- mysql_db3.stop
35
-
36
- # wait for stopped
37
- mysql_s3.wait_for_state('stopped')
38
- mysql_db1.wait_for_state('stopped')
39
- mysql_db2.wait_for_state('stopped')
40
- mysql_db3.wait_for_state('stopped')
@@ -1,43 +0,0 @@
1
- #!/usr/bin/ruby
2
- require 'rubygems'
3
- require 'trollop'
4
- require 'rest_connection'
5
- require 'net/ssh'
6
-
7
- opts = Trollop::options do
8
- opt :deployment, "deployment nickname", :type => :string, :required => false
9
- opt :only, "regex string matching the nickname of the servers you want to relaunch. This excludes servers that do not match\nExample --only ubuntu", :type => :string, :required => false
10
- opt :id, "deployment id", :type => :string, :required => false
11
- end
12
-
13
- # find all servers in the deployment (the fast way)
14
- if opts[:id]
15
- deployment = Deployment.find_by_id(opts[:id])
16
- else
17
- deployment = Deployment.find_by_nickname_speed(opts[:deployment]).first
18
- end
19
- servers = deployment.servers_no_reload
20
- servers = servers.select { |s| s.nickname =~ /#{opts[:only]}/ } if opts[:only]
21
-
22
- raise "need at least 2 servers to start, only have: #{servers.size}" if servers.size < 2
23
-
24
- # wait for servers to be ready
25
- servers.each do |s|
26
- s.start
27
- while(1)
28
- puts "waiting for dns-name for #{s.nickname}"
29
- break if s['dns-name'] && !s['dns-name'].empty?
30
- s.reload
31
- sleep 2
32
- end
33
- puts "DNS: #{s['dns-name']}"
34
-
35
- s.wait_for_state('operational')
36
- end
37
-
38
- servers[0].run_recipe("db_mysql::do_restore_and_become_master")
39
-
40
- sleep(10)
41
-
42
- servers[1].run_recipe("db_mysql::do_init_slave")
43
- servers[1].run_recipe("db_mysql::do_promote_to_master")
@@ -1,109 +0,0 @@
1
- #!/usr/bin/ruby
2
- require 'rubygems'
3
- require 'trollop'
4
- require 'rest_connection'
5
- require 'net/ssh'
6
-
7
- def run_recipe(recipe, host_dns, continue=false)
8
- STDOUT.puts "sshing to #{host_dns}"
9
- result = nil
10
- tail_command ="tail -f -n1 /var/log/messages"
11
- expect = /RightLink.*RS> ([completed|failed]+: < #{recipe} >)/
12
-
13
- Net::SSH.start(host_dns, 'root', :keys => ['~/.ssh/publish-test']) do |ssh|
14
- STDOUT.puts ssh.exec!("rs_run_recipe -n '#{recipe}'")
15
- log_channel = ssh.open_channel do |ch|
16
- ch.exec tail_command do |ch, success|
17
- raise "could not execute command" unless success
18
- # "on_data" is called when the process writes something to stdout
19
- ch.on_data do |c, data|
20
- STDOUT.print data
21
- if data =~ expect
22
- STDOUT.puts "FOUND EXPECTED DATA, closing channel"
23
- result = $1
24
- end
25
- end
26
- # "on_extended_data" is called when the process writes something to stderr
27
- ch.on_extended_data do |c, type, data|
28
- STDERR.print data
29
- end
30
- ch.on_close do
31
- STDOUT.puts "closed channel"
32
- end
33
- ch.on_process do |c|
34
- if result
35
- STDOUT.puts "attempting close"
36
- ch.close
37
- ssh.exec("killall tail")
38
- end
39
- end
40
- end
41
- end
42
- log_channel.wait
43
- end
44
- raise "FATAL: halting execution, script #{result}" if result.include?('failed') && continue == false
45
- return result
46
- end
47
-
48
- def spot_check(command, host_dns, &block)
49
- Net::SSH.start(host_dns, 'root', :keys => ['~/.ssh/publish-test']) do |ssh|
50
- result = ssh.exec!(command)
51
- yield result
52
- end
53
- end
54
-
55
- opts = Trollop::options do
56
- opt :deployment, "deployment nickname", :type => :string, :required => false
57
- opt :id, "deployment id", :type => :string, :required => false
58
- opt :only, "regex string matching the nickname of the servers you want to relaunch. This excludes servers that do not match\nExample --only ubuntu", :type => :string, :required => false
59
- end
60
- if opts[:id]
61
- deployment = Deployment.find_by_id(opts[:id])
62
- else
63
- deployment = Deployment.find_by_nickname_speed(opts[:deployment]).first
64
- end
65
- servers = deployment.servers_no_reload
66
- servers = servers.select { |s| s.nickname =~ /#{opts[:only]}/ } if opts[:only]
67
-
68
- raise "need at least 4 servers to start, only have: #{servers.size}" if servers.size < 4
69
- # wait for servers to be ready
70
- servers.each do |s|
71
- while(1)
72
- puts "waiting for dns-name for #{s.nickname}"
73
- break if s['dns-name'] && !s['dns-name'].empty?
74
- s.reload
75
- sleep 2
76
- end
77
- puts "DNS: #{s['dns-name']}"
78
-
79
- s.wait_for_state('operational')
80
- end
81
-
82
- servers.each do |s|
83
- puts run_recipe("lb_haproxy::do_attach_request", s.dns_name)
84
- end
85
- sleep 20
86
-
87
- a_frontend = servers.detect {|d| d.nickname.include?("FE")}
88
- a_frontend.reload
89
- raise "couldn't find a frontend with FE in the nickname!" unless a_frontend
90
- puts a_frontend.dns_name
91
- spot_check("cat /home/haproxy/rightscale_lb.cfg |grep server|grep -v '#'|wc -l", a_frontend.dns_name) do |result|
92
- puts "found attached servers: #{result}"
93
- raise "not enough servers #{result}" unless result.to_i == 4
94
- end
95
-
96
- servers.each do |s|
97
- run_recipe("app_php::do_update_code", s.dns_name)
98
- end
99
-
100
- servers.each do |s|
101
- run_recipe("lb_haproxy::do_detach_request", s.dns_name)
102
- end
103
- sleep 20
104
- spot_check("cat /home/haproxy/rightscale_lb.cfg |grep server|grep -v '#'|wc -l", a_frontend.dns_name) do |result|
105
- puts "found attached servers: #{result}"
106
- raise "should be zero servers but was #{result}" unless result.to_i == 0
107
- end
108
-
109
-
@@ -1,14 +0,0 @@
1
- require 'rubygems'
2
- require 'rest_connection'
3
- require 'trollop'
4
-
5
- opts = Trollop::options do
6
- opt :deployment, "deployment nickname", :type => :string, :required => true
7
- opt :template, "server template href to set for all servers", :type => :string, :required => true
8
- end
9
-
10
- deployment = Deployment.find_by_nickname_speed(opts[:deployment]).first
11
-
12
- deployment.servers.each do |s|
13
- s.set_template(opts[:template])
14
- end