Skip to content
This repository was archived by the owner on Dec 19, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions bin/haproxyctl
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ begin
printf "%-30s %-30s %-7s %3s\n", data[0], data[1], data[17], data[18]
end
when /disable all EXCEPT (.+)/
servername = Regexp.last_match[ 1]
servername = Regexp.last_match(1)
status = unixsock('show stat')
backend = status.grep(/#{servername}/)
backend.each do |line|
Expand All @@ -127,7 +127,7 @@ begin
end
end
when /disable all (.+)/
servername = Regexp.last_match[ 1]
servername = Regexp.last_match(1)
status = unixsock('show stat')
status.each do |line|
data = line.split(',')
Expand All @@ -136,7 +136,7 @@ begin
end
end
when /enable all EXCEPT (.+)/
servername = Regexp.last_match[ 1]
servername = Regexp.last_match(1)
status = unixsock('show stat')
backend = status.grep(/#{servername}/)
backend.each do |line|
Expand All @@ -149,7 +149,7 @@ begin
end
end
when /show stat (.+)/
fieldnames = Regexp.last_match[ 1]
fieldnames = Regexp.last_match(1)
status = unixsock('show stat')
indices = fieldnames.split(' ').map do |name|
status.first.split(',').index(name) || begin
Expand All @@ -164,7 +164,7 @@ begin
puts (row[0...2] + filtered).compact.join(',')
end
when /enable all (.+)/
servername = Regexp.last_match[ 1]
servername = Regexp.last_match(1)
status = unixsock('show stat')
status.each do |line|
data = line.split(',')
Expand Down
6 changes: 3 additions & 3 deletions lib/haproxyctl/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def exec
def nbproc
@nbproc ||= begin
config.match /nbproc \s*(\d*)\s*/
Regexp.last_match[1].to_i || 1
Regexp.last_match(1).to_i || 1
end
end

Expand All @@ -54,13 +54,13 @@ def socket
else
config.match /stats\s+socket \s*([^\s]*)/
end
Regexp.last_match[1] || fail("Expecting 'stats socket <UNIX_socket_path>' in #{config_path}")
Regexp.last_match(1) || fail("Expecting 'stats socket <UNIX_socket_path>' in #{config_path}")
end
end

def pidfile
if config.match(/pidfile \s*([^\s]*)/)
@pidfile = Regexp.last_match[1]
@pidfile = Regexp.last_match(1)
else
std_pid = '/var/run/haproxy.pid'
if File.exists?(std_pid)
Expand Down
4 changes: 2 additions & 2 deletions rhapr/lib/rhapr/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def socket
def socket_path
@socket_path ||= begin
config.match /stats\s+socket\s+([^\s]*)/
Regexp.last_match[1] || fail(RuntimeError.new "Expecting 'stats socket <UNIX_socket_path>' in #{config_path}")
Regexp.last_match(1) || fail(RuntimeError.new "Expecting 'stats socket <UNIX_socket_path>' in #{config_path}")
end
end

Expand All @@ -81,7 +81,7 @@ def socket_path
def pid
@pid ||= begin
config.match /pidfile ([^\s]*)/
Regexp.last_match[1] || '/var/run/haproxy.pid'
Regexp.last_match(1) || '/var/run/haproxy.pid'
end
end

Expand Down
2 changes: 1 addition & 1 deletion rhapr/lib/rhapr/interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def get_weight(backend, server)
resp = send "get weight #{backend}/#{server}"

resp.match /([[:digit:]]+) \(initial ([[:digit:]]+)\)/
weight, initial = Regexp.last_match[1], Regexp.last_match[2]
weight, initial = Regexp.last_match(1), Regexp.last_match(2)

return [weight.to_i, initial.to_i] if weight and initial

Expand Down
20 changes: 10 additions & 10 deletions rhapr/spec/rhapr/environment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,29 @@ class EnvTest
end

it 'should go down a list of pre-defined file names' do
File.stub!(:exists?).and_return(false)
File.stub(:exists?).and_return(false)
File.should_receive(:exists?).with('/etc/haproxy.cfg').and_return(true)

@env_test.config_path.should == '/etc/haproxy.cfg'
end

it 'should select the first configuration found, from the pre-defined list' do
File.stub!(:exists?).and_return(false)
File.stub(:exists?).and_return(false)
File.should_receive(:exists?).with('/etc/haproxy/haproxy.cfg').and_return(true)
File.should_receive(:exists?).with('/etc/haproxy.cfg').and_return(true)

@env_test.config_path.should == '/etc/haproxy/haproxy.cfg'
end

it 'should be nil if config files do not exist and $HAPROXY_CONFIG is not set' do
File.stub!(:exists?).and_return(false)
File.stub(:exists?).and_return(false)
@env_test.config_path.should be_nil
end
end

describe '#config' do
before(:each) do
File.stub!(:exists?).and_return(false)
File.stub(:exists?).and_return(false)
File.should_receive(:exists?).with('/etc/haproxy.cfg').and_return(true)
end

Expand All @@ -55,7 +55,7 @@ class EnvTest
end

it 'should read and return the contents of a file' do
File.should_receive(:read).and_return { "I can haz cfg ?\n" }
File.should_receive(:read).and_return("I can haz cfg ?\n")

@env_test.config.should == "I can haz cfg ?\n"
end
Expand Down Expand Up @@ -98,13 +98,13 @@ class EnvTest

describe '#socket_path' do
it 'should parse out the io socket from the config file' do
@env_test.should_receive(:config).and_return { config_for(:basic_haproxy) }
@env_test.should_receive(:config).and_return(config_for(:basic_haproxy))

@env_test.socket_path.should == '/tmp/haproxy'
end

it 'should raise an error if it cannot derive an io socket from the config file' do
@env_test.should_receive(:config).and_return { config_for(:crappy_haproxy) }
@env_test.should_receive(:config).and_return(config_for(:crappy_haproxy))

lambda do
@env_test.socket_path
Expand All @@ -114,19 +114,19 @@ class EnvTest

describe '#pid' do
it 'should parse out the pidfile from the config file' do
@env_test.should_receive(:config).and_return { config_for(:pid_test_haproxy) }
@env_test.should_receive(:config).and_return(config_for(:pid_test_haproxy))

@env_test.pid.should == '/some/other/run/haproxy.pid'
end

it 'should return a default path if it cannot derive an io socket from the config file' do
@env_test.should_receive(:config).and_return { config_for(:crappy_haproxy) }
@env_test.should_receive(:config).and_return(config_for(:crappy_haproxy))

@env_test.pid.should == '/var/run/haproxy.pid'
end
end

describe '#check_running, #pidof' do
pending 'TBD'
skip 'TBD'
end
end
2 changes: 1 addition & 1 deletion rhapr/spec/rhapr/interface_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
it 'should send the "clear counters" message to HAProxy' do
subject.should_receive(:send).with('clear counters').and_return("\n")

subject.clear_counters.should be_true
subject.clear_counters.should be true
end
end

Expand Down