Skip to content

Commit

Permalink
Merge pull request #37 from rightscale-cookbooks/ST-375_azure_shares_ips
Browse files Browse the repository at this point in the history
St 375 azure shares ips
  • Loading branch information
douglaswth committed Jun 11, 2015
2 parents 5113dcd + 7ddeeba commit d2542dd
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 71 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ rs-mysql Cookbook CHANGELOG

This file is used to list changes made in each version of the rs-mysql cookbook.

v1.1.9
------

- No longer use IP address to create server_id since some clouds use the same IP but forward using ports.

v1.1.8
------

Expand Down
24 changes: 0 additions & 24 deletions libraries/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,6 @@ module RsMysql
module Helper
extend Chef::Mixin::ShellOut

# Gets the first public IP address of the server if present, or else
# returns its first private IP address.
#
# @param node [Chef::Node] the chef node
#
# @return [IPAddr] the IP address of the server
#
def self.get_server_ip(node)
instance_ips = Array.new

if node['cloud']['public_ips']
instance_ips += node['cloud']['public_ips']
end

if node['cloud']['private_ips']
instance_ips += node['cloud']['private_ips']
end

server_ip = instance_ips.detect { |ip| !ip.nil? && !ip.empty? }

Chef::Log.info "Server IP: #{server_ip}"
IPAddr.new(server_ip)
end

# Gets the IP address that the MySQL server will bind to. If `node['rs-mysql']['bind_address']` is set to an IP
# address or host name, the IP address value of the attribute will be used instead.
#
Expand Down
2 changes: 1 addition & 1 deletion metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
license 'Apache 2.0'
description 'Installs and configures a MySQL server'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version '1.1.8'
version '1.1.9'

depends 'chef_handler', '~> 1.1.6'
depends 'marker', '~> 1.0.1'
Expand Down
7 changes: 5 additions & 2 deletions recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,11 @@
Chef::Log.info "Overriding mysql/tunable/binlog_format to 'MIXED'"
node.override['mysql']['tunable']['binlog_format'] = 'MIXED'

# Convert the server IP to an integer and use it for the server-id attribute in my.cnf
server_id = RsMysql::Helper.get_server_ip(node).to_i
# Drop first 2 hex numbers from MAC address to have a 32-bit integer and use it for the server-id attribute in my.cnf.
# This is used since MAC addresses within the same network must be different to correctly talk to each other.
# Some clouds use the same public IP with different ports for multiple instances, so IP is not unique.
server_id = node['macaddress'].split(/\W/)[2..-1].join.to_i(16)

Chef::Log.info "Overriding mysql/tunable/server_id to '#{server_id}'"
node.override['mysql']['tunable']['server_id'] = server_id

Expand Down
44 changes: 0 additions & 44 deletions spec/empty_public_ips_spec.rb

This file was deleted.

26 changes: 26 additions & 0 deletions spec/server_id_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require_relative 'spec_helper'

describe 'rs-mysql::default' do

before do
stub_command("/usr/bin/mysql -u root -e 'show databases;'").and_return(true)
end

let(:chef_run) do
ChefSpec::Runner.new do |node|
node.set['cloud']['public_ips'] = ['', '10.1.1.1']
node.set['cloud']['private_ips'] = ['10.0.2.15', '10.0.2.16']
node.set['memory']['total'] = '1011228kB'
node.set['rs-mysql']['application_database_name'] = 'apptest'
node.set['rs-mysql']['backup']['lineage'] = 'testing'
node.set['rs-mysql']['server_repl_password'] = 'replpass'
node.set['rs-mysql']['server_root_password'] = 'rootpass'
end.converge(described_recipe)

# Chefspec by default sets node['macaddress'] to '11:11:11:11:11:11'
# In generating the server_id, we remove the first 2 octets - we do the same here to verify
it 'sets server_id based on macaddress' do
expect(chef_run.node['mysql']['tunable']['server_id']).to eq(0x11111111)
end
end
end

0 comments on commit d2542dd

Please sign in to comment.