Module: VirtualMonkey::Mysql

Includes:
DeploymentRunner, EBS
Included in:
LampRunner, MysqlRunner, MysqlToolboxRunner
Defined in:
lib/virtualmonkey/mysql.rb

Instance Attribute Summary collapse

Attributes included from EBS

#lineage, #mount_point, #stripe_count, #volume_size

Attributes included from DeploymentRunner

#deployment, #servers

Instance Method Summary collapse

Methods included from EBS

#create_backup, #create_stripe_volume, #find_snapshot_timestamp, #find_snapshots, #populate_volume, #restore_and_grow, #restore_from_backup, #set_variation_mount_point, #set_variation_stripe_count, #set_variation_volume_size, #terminate_server, #test_restore, #test_restore_grow, #test_volume_data, #test_volume_size, #wait_for_snapshots

Methods included from DeploymentRunner

#initialize

Methods included from TestCaseInterface

#behavior, #probe, #set_var, #verify

Instance Attribute Details

#db_ebs_prefixObject

Returns the value of attribute db_ebs_prefix.



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

def db_ebs_prefix
  @db_ebs_prefix
end

#scripts_to_runObject

Returns the value of attribute scripts_to_run.



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

def scripts_to_run
  @scripts_to_run
end

Instance Method Details

#config_master_from_scratch(server) ⇒ Object

Performs steps necessary to bootstrap a MySQL Master server from a pristine state.

  • server<~Server> the server to use as MASTER



71
72
73
74
75
76
77
78
79
80
81
# File 'lib/virtualmonkey/mysql.rb', line 71

def config_master_from_scratch(server)
  behavior(:create_stripe, server)
  object_behavior(server, :spot_check_command, "service mysqld start")
#TODO the service name depends on the OS
#      server.spot_check_command("service mysql start")
  behavior(:run_query, "create database mynewtest", server)
  behavior(:set_master_dns, server)
  # This sleep is to wait for DNS to settle - must sleep
  sleep 120
  behavior(:run_script, "backup", server)
end

#create_migration_scriptObject



138
139
140
141
142
143
# File 'lib/virtualmonkey/mysql.rb', line 138

def create_migration_script
  options = { "DB_EBS_PREFIX" => "text:regmysql",
          "DB_EBS_SIZE_MULTIPLIER" => "text:1",
          "EBS_STRIPE_COUNT" => "text:#{@stripe_count}" }
  s_one.run_executable(@scripts_to_run['create_migrate_script'], options)
end

#create_stripe(server) ⇒ Object

creates a MySQL enabled EBS stripe on the server

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



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/virtualmonkey/mysql.rb', line 52

def create_stripe(server)
  options = { "EBS_MOUNT_POINT" => "text:/mnt/mysql", 
          "EBS_STRIPE_COUNT" => "text:#{@stripe_count}", 
          "EBS_VOLUME_SIZE" => "text:1", 
          "DBAPPLICATION_USER" => "text:someuser", 
          "DB_MYSQLDUMP_BUCKET" => "ignore:$ignore",
          "DB_MYSQLDUMP_FILENAME" => "ignore:$ignore",
          "AWS_ACCESS_KEY_ID" => "ignore:$ignore",
          "AWS_SECRET_ACCESS_KEY" => "ignore:$ignore",
          "DB_SCHEMA_NAME" => "ignore:$ignore",
          "DBAPPLICATION_PASSWORD" => "text:somepass", 
          "EBS_TOTAL_VOLUME_GROUP_SIZE" => "text:1",
          "EBS_LINEAGE" => "text:#{@lineage}" }
  audit = server.run_executable(@scripts_to_run['create_mysql_ebs_stripe'], options)
  audit.wait_for_completed
end

#promote_server(server) ⇒ Object



126
127
128
# File 'lib/virtualmonkey/mysql.rb', line 126

def promote_server(server)
  run_script("promote", server)
end

#release_dnsObject

releases records back into the shared DNS pool



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

def release_dns
  @dns.release_dns
end

#restore_server(server) ⇒ Object



134
135
136
# File 'lib/virtualmonkey/mysql.rb', line 134

def restore_server(server)
  run_script("restore", server)
end

#run_checksObject

These are mysql specific checks (used by mysql_runner and lamp_runner)



146
147
148
149
150
151
152
153
# File 'lib/virtualmonkey/mysql.rb', line 146

def run_checks
  # check that mysql tmpdir is custom setup on all servers
  query = "show variables like 'tmpdir'"
  query_command = "echo -e \"#{query}\"| mysql"
  @servers.each do |server|
    server.spot_check(query_command) { |result| raise "Failure: tmpdir was unset#{result}" unless result.include?("/mnt/mysqltmp") }
  end
end

#run_mysqlslap_checkObject

check that mysql can handle 5000 concurrent connections (file limits, etc.)



156
157
158
159
160
161
# File 'lib/virtualmonkey/mysql.rb', line 156

def run_mysqlslap_check
  @servers.each do |server|
    result = server.spot_check_command("mysqlslap  --concurrency=5000 --iterations=10 --number-int-cols=2 --number-char-cols=3 --auto-generate-sql --csv=/tmp/mysqlslap_q1000_innodb.csv --engine=innodb --auto-generate-sql-add-autoincrement --auto-generate-sql-load-type=mixed --number-of-queries=1000 --user=root")
    raise "FATAL: mysqlslap check failed" unless result[:output].empty?
  end
end

#run_query(query, server) ⇒ Object

Runs a mysql query on specified server.

  • query<~String> a SQL query string to execute

  • server<~Server> the server to run the query on



86
87
88
89
# File 'lib/virtualmonkey/mysql.rb', line 86

def run_query(query, server)
  query_command = "echo -e \"#{query}\"| mysql"
  server.spot_check_command(query_command)
end

#set_master_dns(server) ⇒ Object

Sets DNS record for the Master server to point at server

  • server<~Server> the server to use as MASTER



93
94
95
96
# File 'lib/virtualmonkey/mysql.rb', line 93

def set_master_dns(server)
  audit = server.run_executable(@scripts_to_run['master_init'])
  audit.wait_for_completed
end

#set_variation_backup_prefixObject



30
31
32
33
34
35
36
37
38
# File 'lib/virtualmonkey/mysql.rb', line 30

def set_variation_backup_prefix
  @lineage = "text:testlineage#{rand(1000000)}"
  @deployment.set_input('DB_EBS_PREFIX', @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('DB_EBS_PREFIX', "text:")
  end
end

#set_variation_bucketObject



40
41
42
43
44
45
46
47
48
# File 'lib/virtualmonkey/mysql.rb', line 40

def set_variation_bucket
   bucket = "text:testingcandelete#{@deployment.href.split(/\//).last}"
  @deployment.set_input('remote_storage/default/container', bucket)
  # 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('remote_storage/default/container', "text:")
  end
end

#set_variation_lineage(kind = nil) ⇒ Object

sets the lineage for the deployment

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



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/virtualmonkey/mysql.rb', line 11

def set_variation_lineage(kind = nil)
  @lineage = "testlineage#{@deployment.href.split(/\//).last}"
  if kind == "chef"
    @deployment.set_input('db/backup/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('db/backup/lineage', "text:")
    end
  else
    @deployment.set_input('DB_LINEAGE_NAME', "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('DB_LINEAGE_NAME', "text:")
    end
  end
end

#setup_dns(domain) ⇒ Object

uses SharedDns to find an available set of DNS records and sets them on the deployment



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

def setup_dns(domain)
# TODO should we just use the ID instead of the full href?
  owner=@deployment.href
  @dns = SharedDns.new(domain)
  raise "Unable to reserve DNS" unless @dns.reserve_dns(owner)
  @dns.set_dns_inputs(@deployment)
end

#slave_init_server(server) ⇒ Object



130
131
132
# File 'lib/virtualmonkey/mysql.rb', line 130

def slave_init_server(server)
  run_script("slave_init", server)
end

#stop_all(wait = true) ⇒ Object

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



99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/virtualmonkey/mysql.rb', line 99

def stop_all(wait=true)
  if @scripts_to_run['terminate']
    options = { "DB_TERMINATE_SAFETY" => "text:off" }
    @servers.each { |s| s.run_executable(@scripts_to_run['terminate'], options) unless s.state == 'stopped' }
  else
    @servers.each { |s| s.stop }
  end

  wait_for_all("stopped") if wait
  # unset dns in our local cached copy..
  @servers.each { |s| s.params['dns-name'] = nil } 
end

#ulimit_checkObject

check that ulimit has been set correctly XXX: DEPRECATED



165
166
167
168
169
170
# File 'lib/virtualmonkey/mysql.rb', line 165

def ulimit_check
  @servers.each do |server|
    result = server.spot_check_command("su - mysql -s /bin/bash -c \"ulimit -n\"")
    raise "FATAL: ulimit wasn't set correctly" unless result[:output].to_i >= 1024
  end
end