haproxyctl 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,82 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rhapr::Interface do
4
+ let(:basic_info) {
5
+ "Name: HAProxy\nVersion: 1.4.15\nRelease_date: 2011/04/08\nNbproc: 1\nProcess_num: 1\nPid: 97413\nUptime: 0d 18h43m53s\n" <<
6
+ "Uptime_sec: 67433\nMemmax_MB: 0\nUlimit-n: 2066\nMaxsock: 2066\nMaxconn: 1024\nMaxpipes: 0\nCurrConns: 1\nPipesUsed: 0\n" <<
7
+ "PipesFree: 0\nTasks: 7\nRun_queue: 1\nnode: skg.local\ndescription: \n"
8
+ }
9
+
10
+ let(:basic_stat) {
11
+ "# pxname,svname,qcur,qmax,scur,smax,slim,stot,bin,bout,dreq,dresp,ereq,econ,eresp,wretr,wredis,status,weight,act,bck,chkfail," <<
12
+ "chkdown,lastchg,downtime,qlimit,pid,iid,sid,throttle,lbtot,tracked,type,rate,rate_lim,rate_max,check_status,check_code,check_duration," <<
13
+ "hrsp_1xx,hrsp_2xx,hrsp_3xx,hrsp_4xx,hrsp_5xx,hrsp_other,hanafail,req_rate,req_rate_max,req_tot,cli_abrt,srv_abrt,\nsrv,FRONTEND," <<
14
+ ",,0,0,2000,0,0,0,0,0,0,,,,,OPEN,,,,,,,,,1,1,0,,,,0,0,0,0,,,,,,,,,,,0,0,0,,,\nsrv,srv1,0,0,0,0,20,0,0,0,,0,,0,0,0,0,DOWN,1,1,0," <<
15
+ "0,1,72468,72468,,1,1,1,,0,,2,0,,0,L4CON,,0,,,,,,,0,,,,0,0,\nsrv,srv2,0,0,0,0,20,0,0,0,,0,,0,0,0,0,DOWN,1,1,0,0,1,72465,72465,," <<
16
+ "1,1,2,,0,,2,0,,0,L4CON,,0,,,,,,,0,,,,0,0,\n"
17
+ }
18
+
19
+
20
+ subject { Rhapr::Interface.new }
21
+
22
+ describe '#clear_counters' do
23
+ it 'should send the "clear counters" message to HAProxy' do
24
+ subject.should_receive(:send).with('clear counters').and_return("\n")
25
+
26
+ subject.clear_counters.should be_true
27
+ end
28
+ end
29
+
30
+ describe '#show_info' do
31
+ it 'should parse and return a Hash of HAProxy\'s info attributes' do
32
+ subject.should_receive(:send).with('show info').and_return(basic_info)
33
+
34
+ subject.show_info.should be_a(Hash)
35
+ end
36
+
37
+ it 'should normalize the attribute names into lower-case and underscore-ized form'
38
+ end
39
+
40
+ describe '#show_stat' do
41
+ before(:each) do
42
+ subject.should_receive(:send).with('show stat').and_return(basic_stat)
43
+ end
44
+
45
+ it 'should return an Array of Hashes, returned from HAProxy\'s "show stats" request' do
46
+ stats = subject.show_stat
47
+
48
+ stats.should be_a(Array)
49
+ stats.each{|stat| stat.should be_a(Hash) }
50
+ end
51
+
52
+ it 'should strip the "# " from the beginning of the headers, before calling CSV.parse' do
53
+ stats = subject.show_stat
54
+
55
+ stats.first.should_not have_key('# pxname')
56
+ stats.first.should have_key('pxname')
57
+ end
58
+ end
59
+
60
+ describe '#show_errors'
61
+ describe '#show_sess'
62
+
63
+ describe '#get_weight' do
64
+ it 'should parse the weight into an Array, with two elements: The weight and the initial weight' do
65
+ subject.should_receive(:send).with('get weight test/test1').and_return('1 (initial 1)')
66
+
67
+ subject.get_weight('test', 'test1').should == [1, 1]
68
+ end
69
+
70
+ it 'should raise an error if the specific backend+server is not known to HAProxy' do
71
+ subject.should_receive(:send).with('get weight test/test9').and_return('No such server.')
72
+
73
+ lambda {
74
+ subject.get_weight('test', 'test9')
75
+ }.should raise_error(ArgumentError, "HAProxy did not recognize the specified Backend/Server. Response from HAProxy: No such server.")
76
+ end
77
+ end
78
+
79
+ describe '#set_weight'
80
+ describe '#disable'
81
+ describe '#enable'
82
+ end
@@ -0,0 +1,11 @@
1
+ require 'bundler/setup'
2
+
3
+ Bundler.require :default
4
+ Bundler.require :development
5
+
6
+ Dir[ Bundler.root.join('spec/support/**/*.rb') ].each{|f| require f}
7
+
8
+ RSpec.configure do |c|
9
+ c.include CustomMatchers
10
+ c.include ConfigFixtures
11
+ end
@@ -0,0 +1,53 @@
1
+ require 'bundler'
2
+
3
+ module ConfigFixtures
4
+ attr_reader :config_fixtures
5
+
6
+ # @param [Symbol]
7
+ # @return [String]
8
+ def fixture_for(sym)
9
+ config_fixtures[sym][:fixture]
10
+ end
11
+ alias :config_for :fixture_for
12
+
13
+ def path_for(sym)
14
+ config_fixtures[sym][:path]
15
+ end
16
+
17
+ # @see ConfigFixtures#create_fixture_hash
18
+ def config_fixtures
19
+ @config_fixtures ||= begin
20
+ hash = Hash.new {|k,v| k[v] = {}}
21
+ hash.merge!(create_fixture_hash)
22
+ end
23
+ end
24
+
25
+ # @return [Hash{Symbol => String}]
26
+ def create_fixture_hash
27
+ Hash[ find_fixtures.map{|fpath| map_fixture(fpath) } ]
28
+ end
29
+
30
+ # @param [String]
31
+ # @return [Array<Symbol, String>]
32
+ def map_fixture(fpath)
33
+ [symbolize_filename(fpath), {:path => fpath, :fixture => read_file(fpath)}]
34
+ end
35
+
36
+ # @return [Array<String>]
37
+ def find_fixtures
38
+ Dir.glob Bundler.root.join('spec/config_fixtures/**.cfg')
39
+ end
40
+
41
+ # @param [String]
42
+ # @return [Symbol]
43
+ def symbolize_filename(fpath)
44
+ fname = File.basename(fpath)
45
+ fname.split(/\W/).shift.to_sym
46
+ end
47
+
48
+ # @param [String]
49
+ # @return [String]
50
+ def read_file(fpath)
51
+ File.read(fpath)
52
+ end
53
+ end
@@ -0,0 +1,44 @@
1
+ module CustomMatchers
2
+ class BeWellFormed
3
+ def matches?(files)
4
+ @errors = files.map {|filename|
5
+ [
6
+ check_for_tabs(filename),
7
+ excessive_spacing(filename),
8
+ newline_precedes_eof(filename)
9
+ ]
10
+ }.flatten.compact
11
+
12
+ @errors.empty?
13
+ end
14
+
15
+ def failure_message_for_should
16
+ @errors.join("\n")
17
+ end
18
+
19
+ private
20
+ def check_for_tabs(filename)
21
+ bad_lines = File.readlines(filename).each_with_index.map do |line, line_no|
22
+ line_no + 1 if line["\t"] and line !~ /^\s+#.*\s+\n$/
23
+ end.flatten.compact
24
+
25
+ "#{filename} has tab characters on lines #{bad_lines.join(', ')}" if bad_lines.any?
26
+ end
27
+
28
+ def excessive_spacing(filename)
29
+ bad_lines = File.readlines(filename).each_with_index.map do |line, line_no|
30
+ line_no + 1 if line =~ /\s+\n$/ and line !~ /^\s+#.*\s+\n$/
31
+ end.flatten.compact
32
+
33
+ "#{filename} has spaces on the EOL on lines #{bad_lines.join(', ')}" if bad_lines.any?
34
+ end
35
+
36
+ def newline_precedes_eof(filename)
37
+ "#{filename} does not have a newline (\\n) before EOF" if File.read(filename) !~ /\n$/
38
+ end
39
+ end
40
+
41
+ def be_well_formed
42
+ BeWellFormed.new
43
+ end
44
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: haproxyctl
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Carlo Flores
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-08-15 00:00:00 -07:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: This is a simple wrapper to make life with HAProxy a little more convenient. Acts as an init script for start, stop, reload, restart, etc. Leverages 'socket' to enable and disable servers on the fly. Formats server weight and backends in a readable way. Provides Nagios and Cloudkick health checks. Compatible with RHEL chkconfig/service.
23
+ email:
24
+ - github@petalphile.com
25
+ executables:
26
+ - haproxyctl
27
+ extensions: []
28
+
29
+ extra_rdoc_files: []
30
+
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - LICENSE
35
+ - README.md
36
+ - Rakefile
37
+ - bin/haproxyctl
38
+ - haproxyctl
39
+ - haproxyctl.gemspec
40
+ - install-haproxy/haproxy_src_install.sh
41
+ - lib/haproxyctl.rb
42
+ - lib/haproxyctl/environment.rb
43
+ - lib/haproxyctl/version.rb
44
+ - rhapr/.gitignore
45
+ - rhapr/.rspec
46
+ - rhapr/Gemfile
47
+ - rhapr/Rakefile
48
+ - rhapr/lib/rhapr.rb
49
+ - rhapr/lib/rhapr/environment.rb
50
+ - rhapr/lib/rhapr/interface.rb
51
+ - rhapr/lib/rhapr/version.rb
52
+ - rhapr/rhapr.gemspec
53
+ - rhapr/spec/config_fixtures/basic_haproxy.cfg
54
+ - rhapr/spec/config_fixtures/crappy_haproxy.cfg
55
+ - rhapr/spec/config_fixtures/pid_test_haproxy.cfg
56
+ - rhapr/spec/quality_spec.rb
57
+ - rhapr/spec/rhapr/environment_spec.rb
58
+ - rhapr/spec/rhapr/interface_spec.rb
59
+ - rhapr/spec/spec_helper.rb
60
+ - rhapr/spec/support/config_fixtures.rb
61
+ - rhapr/spec/support/custom_matchers.rb
62
+ has_rdoc: true
63
+ homepage: https://github.com/flores/haproxyctl
64
+ licenses:
65
+ - MIT
66
+ post_install_message:
67
+ rdoc_options: []
68
+
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ hash: 3
77
+ segments:
78
+ - 0
79
+ version: "0"
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ hash: 3
86
+ segments:
87
+ - 0
88
+ version: "0"
89
+ requirements: []
90
+
91
+ rubyforge_project: haproxyctl
92
+ rubygems_version: 1.3.7
93
+ signing_key:
94
+ specification_version: 3
95
+ summary: Wrapper to talk to the HAProxy socket, as well as regular init (start|stop|status|etc)
96
+ test_files: []
97
+