hansel 0.1.7 → 0.2.0
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.
- data/README.md +103 -0
- data/Rakefile +9 -1
- data/VERSION +1 -1
- data/bin/hansel +2 -5
- data/hansel.gemspec +23 -11
- data/lib/hansel/arg_parser.rb +84 -0
- data/lib/{csv_formatter.rb → hansel/formatting/csv_formatter.rb} +8 -13
- data/lib/hansel/formatting/formatting.rb +51 -0
- data/lib/{octave_formatter.rb → hansel/formatting/octave_formatter.rb} +1 -1
- data/lib/hansel/formatting/yaml_formatter.rb +10 -0
- data/lib/hansel/hansel.rb +77 -0
- data/lib/hansel/httperf/httperf.rb +36 -0
- data/lib/{httperf_result.rb → hansel/httperf_result.rb} +1 -1
- data/lib/{httperf_result_parser.rb → hansel/httperf_result_parser.rb} +1 -1
- data/lib/hansel/job_queue/job_queue.rb +27 -0
- data/lib/hansel.rb +9 -124
- data/spec/arg_parser_spec.rb +91 -34
- data/spec/hansel_spec.rb +134 -0
- data/spec/httperf_result_parser_spec.rb +3 -3
- data/spec/jobs.yml +8 -0
- data/spec/spec_helper.rb +1 -2
- metadata +44 -15
- data/README.rdoc +0 -22
- data/lib/arg_parser.rb +0 -143
- data/lib/config.rb +0 -60
- data/lib/yaml_formatter.rb +0 -14
data/lib/arg_parser.rb
DELETED
@@ -1,143 +0,0 @@
|
|
1
|
-
module Hansel
|
2
|
-
#
|
3
|
-
# Parse the command configuration file options and command line arguments.
|
4
|
-
# Command line arguments override those from the configuration file
|
5
|
-
# See http://www.ruby-doc.org/stdlib/libdoc/optparse/rdoc/classes/OptionParser.html
|
6
|
-
#
|
7
|
-
class ArgParser
|
8
|
-
#
|
9
|
-
# Setup default values for the parsed options
|
10
|
-
#
|
11
|
-
def initialize args
|
12
|
-
@args = args
|
13
|
-
@options = OpenStruct.new(
|
14
|
-
:verbose => false,
|
15
|
-
:server => 'localhost',
|
16
|
-
:port => '80',
|
17
|
-
:uri => '/',
|
18
|
-
:num_conns => 1,
|
19
|
-
:rate => 1,
|
20
|
-
:cookie => nil,
|
21
|
-
:low_rate => 1,
|
22
|
-
:high_rate => 2,
|
23
|
-
:rate_step => 1,
|
24
|
-
:output_format => :yaml,
|
25
|
-
:output => nil,
|
26
|
-
:output_dir => File.join(ENV['HOME'], 'hansel_output'),
|
27
|
-
:template_path => 'templates',
|
28
|
-
:template => nil,
|
29
|
-
:exit => false
|
30
|
-
)
|
31
|
-
end
|
32
|
-
|
33
|
-
#
|
34
|
-
# Uses OptionParser to return an OpenStruct object describing the options.
|
35
|
-
#
|
36
|
-
def parse
|
37
|
-
# The options specified on the command line will be collected in *options*.
|
38
|
-
# We set default values here.
|
39
|
-
OptionParser.new { |options| parse_options options}.parse!(@args)
|
40
|
-
@options
|
41
|
-
end
|
42
|
-
|
43
|
-
private
|
44
|
-
|
45
|
-
def server_options options
|
46
|
-
options.on("-s", "--server=S",
|
47
|
-
"Specifies the IP hostname of the server.") do |server|
|
48
|
-
@options.server = server
|
49
|
-
end
|
50
|
-
|
51
|
-
options.on("-p", "--port=N",
|
52
|
-
"Specifies the port number on which the server is listening.") do |port|
|
53
|
-
@options.port = port.to_i
|
54
|
-
end
|
55
|
-
|
56
|
-
options.on("-u", "--uri=S",
|
57
|
-
"Specifies that URI S should be accessed on the server.") do |uri|
|
58
|
-
@options.uri = uri
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def httperf_options options
|
63
|
-
options.on("-n", "--num_conns=N",
|
64
|
-
"Specifies the total number of connections to create.") do |num_conns|
|
65
|
-
@options.num_conns = num_conns.to_i
|
66
|
-
end
|
67
|
-
|
68
|
-
options.on("-l", "--low_rate=S",
|
69
|
-
"Specifies the starting fixed rate at which connections are created.") do |low_rate|
|
70
|
-
@options.low_rate = low_rate.to_i
|
71
|
-
end
|
72
|
-
|
73
|
-
options.on("-l", "--high_rate=S",
|
74
|
-
"Specifies the ending fixed rate at which connections are created.") do |high_rate|
|
75
|
-
@options.high_rate = high_rate.to_i
|
76
|
-
end
|
77
|
-
|
78
|
-
options.on("-l", "--rate_step=S",
|
79
|
-
"Specifies the fixed rate step at which connections are created.") do |rate_step|
|
80
|
-
@options.rate_step = rate_step.to_i
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
def output_options options
|
85
|
-
options.on("-f", "--format=FORMAT [yaml|csv|octave]",
|
86
|
-
"Specify an output format.") do |format|
|
87
|
-
@options.output_format = format.to_sym
|
88
|
-
end
|
89
|
-
|
90
|
-
options.on("-o", "--output=FILE", "Specify an output file.") do |output|
|
91
|
-
@options.output = !!output
|
92
|
-
end
|
93
|
-
|
94
|
-
options.on("-d", "--output_dir=PATH",
|
95
|
-
"Specify an output directory.") do |output_dir|
|
96
|
-
@options.output_dir = output_dir
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
def template_options options
|
101
|
-
options.on("-m", "--template_path=PATH", "Specify template path.") do |template_path|
|
102
|
-
@options.template_path = template_path
|
103
|
-
end
|
104
|
-
|
105
|
-
options.on("-t", "--template=TEMPLATE_NAME",
|
106
|
-
"Specify a template for output.") do |template|
|
107
|
-
@options.template = template
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
def other_options options
|
112
|
-
options.on("-c", "--cookie=C", "Specify a cookie.") do |cookie|
|
113
|
-
@options.cookie = cookie
|
114
|
-
end
|
115
|
-
|
116
|
-
options.on("-v", "--[no-]verbose", "Run verbosely") do |verbose|
|
117
|
-
@options.verbose = verbose
|
118
|
-
end
|
119
|
-
|
120
|
-
options.on_tail("-h", "--help", "Show this message") do
|
121
|
-
puts options
|
122
|
-
@options.exit = true
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
def version options
|
127
|
-
options.on_tail("--version", "Show version") do
|
128
|
-
puts "Hansel version #{IO.foreach('VERSION').first.strip}"
|
129
|
-
@options.exit = true
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
def parse_options options
|
134
|
-
options.banner = "Usage: hansel [options]"
|
135
|
-
options.separator "Options:"
|
136
|
-
%w(server_options httperf_options output_options
|
137
|
-
other_options version).map(&:to_sym).each do |method|
|
138
|
-
self.send method, options
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
end
|
143
|
-
end
|
data/lib/config.rb
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
module Hansel
|
2
|
-
#
|
3
|
-
# Loads and parses the configuration file
|
4
|
-
#
|
5
|
-
class Config
|
6
|
-
def initialize(argv)
|
7
|
-
@argv = argv
|
8
|
-
@args = []
|
9
|
-
end
|
10
|
-
|
11
|
-
#
|
12
|
-
# The main configuration directory: defaults to ~/.hansel
|
13
|
-
# Creates the configuration directory if it doesn't exist.
|
14
|
-
#
|
15
|
-
def config_path
|
16
|
-
@config_path ||= File.join [ENV['HOME'], '.hansel']
|
17
|
-
FileUtils.mkdir_p @config_path unless File.exists? @config_path
|
18
|
-
@config_path
|
19
|
-
end
|
20
|
-
|
21
|
-
#
|
22
|
-
# The options file located in the configuration directory
|
23
|
-
#
|
24
|
-
def options_path
|
25
|
-
@options_path ||= File.join config_path, 'options'
|
26
|
-
end
|
27
|
-
|
28
|
-
def read_lines file
|
29
|
-
file.read.split("\n").each do |line|
|
30
|
-
next if line =~ /#+/
|
31
|
-
@args += line.split(' ')
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def read_file path
|
36
|
-
File.open path do |file|
|
37
|
-
read_lines file
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
#
|
42
|
-
# Reads the options file and returns an Array of String objects.
|
43
|
-
# Line starting with '#' are skipped.
|
44
|
-
#
|
45
|
-
def read_config_file
|
46
|
-
path = options_path
|
47
|
-
if File.exists? path
|
48
|
-
read_file path
|
49
|
-
end
|
50
|
-
@args
|
51
|
-
end
|
52
|
-
|
53
|
-
#
|
54
|
-
# Returns an OpenStruct object with the options
|
55
|
-
#
|
56
|
-
def options
|
57
|
-
@options ||= ArgParser.new(read_config_file + @argv).parse
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|