ant_hill 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/Rakefile +1 -0
- data/ant_hill.gemspec +29 -0
- data/bin/spawn_queen +14 -0
- data/lib/ant_hill.rb +36 -0
- data/lib/ant_hill/ant.rb +126 -0
- data/lib/ant_hill/ant_colony.rb +212 -0
- data/lib/ant_hill/configuration.rb +154 -0
- data/lib/ant_hill/connection_pool.rb +98 -0
- data/lib/ant_hill/connections/ssh_connection.rb +67 -0
- data/lib/ant_hill/creep.rb +301 -0
- data/lib/ant_hill/creep_modifier.rb +150 -0
- data/lib/ant_hill/log.rb +35 -0
- data/lib/ant_hill/queen.rb +334 -0
- data/lib/ant_hill/version.rb +4 -0
- data/lib/tasks/ant_hill.rake +48 -0
- data/spec/ant_hill/ant_colony_spec.rb +118 -0
- data/spec/ant_hill/ant_spec.rb +101 -0
- data/spec/ant_hill/configuration_spec.rb +201 -0
- data/spec/ant_hill/creep_modifier_spec.rb +30 -0
- data/spec/ant_hill/creep_spec.rb +165 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/support/config.yml +43 -0
- metadata +117 -0
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module AntHill
|
4
|
+
describe CreepModifier do
|
5
|
+
context "#initialize" do
|
6
|
+
it "should set @creep instance variable" do
|
7
|
+
creep = double("creep")
|
8
|
+
cm = CreepModifier.new(creep)
|
9
|
+
cm.instance_variable_get(:@creep).should be_equal(creep)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
context "#find_diff" do
|
13
|
+
let(:creep) {
|
14
|
+
creep=double("creep")
|
15
|
+
creep.stub(:current_params){ {'a' => '1', 'b' => '2', 'c'=> '3'} }
|
16
|
+
creep
|
17
|
+
}
|
18
|
+
let(:ant){
|
19
|
+
ant=double("ant")
|
20
|
+
ant.stub(:params) { {'a'=>'2', "b" => '2', "d" => '5'} }
|
21
|
+
ant.stub(:type) { 'a' }
|
22
|
+
ant
|
23
|
+
}
|
24
|
+
it "should find params difference between creep and ant" do
|
25
|
+
cm = CreepModifier.new(creep)
|
26
|
+
cm.find_diff(ant).should eql({'a' => '2', 'd' => '5'})
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,165 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module AntHill
|
4
|
+
describe Creep do
|
5
|
+
let(:creep){ Creep.new }
|
6
|
+
let(:logger) {double("logger")}
|
7
|
+
before :each do
|
8
|
+
q = double("queen")
|
9
|
+
Queen.stub(:queen){ q }
|
10
|
+
c = double("configuration")
|
11
|
+
Configuration.stub(:config){ c }
|
12
|
+
c.stub(:get_connection_class){ con = double("connection"); con.stub(:new); con}
|
13
|
+
creep.configure({})
|
14
|
+
creep.stub(:logger){ logger }
|
15
|
+
[:fatal, :error, :warn, :info, :debug].each do |m|
|
16
|
+
logger.stub(m)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context "#initialize" do
|
21
|
+
it "should set current_params to {}" do
|
22
|
+
creep.current_params.should == {}
|
23
|
+
end
|
24
|
+
it "should set status to :wait" do
|
25
|
+
creep.status.should == :wait
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "#require_ant" do
|
30
|
+
before :each do
|
31
|
+
Queen.queen.stub(:find_ant){ |params| params }
|
32
|
+
end
|
33
|
+
it "should return ant for current_params" do
|
34
|
+
Queen.stub(:locked?){false}
|
35
|
+
params = {:a => 1, :b => 2}
|
36
|
+
creep.instance_variable_set(:@current_params, params)
|
37
|
+
creep.require_ant.should == params
|
38
|
+
end
|
39
|
+
it "should sleep if queen is locked" do
|
40
|
+
var = -1
|
41
|
+
Queen.stub(:locked?){ var+=1; var < 2 ? true : false }
|
42
|
+
params = {:a => 1, :b => 2}
|
43
|
+
creep.instance_variable_set(:@current_params, params)
|
44
|
+
creep.stub(:sleep)
|
45
|
+
creep.should_receive(:sleep).twice
|
46
|
+
creep.require_ant
|
47
|
+
end
|
48
|
+
end
|
49
|
+
context "#setup_and_process_ant" do
|
50
|
+
let(:ant) { double("ant") }
|
51
|
+
let(:creep_modifier) { double('creep_modifier') }
|
52
|
+
let(:params){{:aaa => 1, :bbb => 2}}
|
53
|
+
|
54
|
+
before :each do
|
55
|
+
|
56
|
+
cmc = double('creep_modifier_class')
|
57
|
+
cmc.stub(:new){|creep| creep_modifier }
|
58
|
+
creep_modifier.stub(:before_process)
|
59
|
+
creep_modifier.stub(:before_setup)
|
60
|
+
creep_modifier.stub(:before_run)
|
61
|
+
creep_modifier.stub(:after_run)
|
62
|
+
creep_modifier.stub(:after_setup)
|
63
|
+
creep_modifier.stub(:after_process)
|
64
|
+
ac = double("ant_colony")
|
65
|
+
ac.stub(:creep_modifier_class) { cmc }
|
66
|
+
ant.stub(:colony){ac}
|
67
|
+
ant.stub(:ant_colony){ac}
|
68
|
+
ant.stub(:params) { params }
|
69
|
+
ant.stub(:execution_status){ 'passed' }
|
70
|
+
ant.stub(:type)
|
71
|
+
ant.stub(:start)
|
72
|
+
ant.stub(:finish)
|
73
|
+
creep.stub(:setup){true}
|
74
|
+
creep.stub(:run){true}
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should increase processed count by 1" do
|
78
|
+
lambda{
|
79
|
+
creep.setup_and_process_ant(ant)
|
80
|
+
}.should change(creep, :processed).by(1)
|
81
|
+
end
|
82
|
+
it "should increase passed count by 1 if ant status passed" do
|
83
|
+
lambda{
|
84
|
+
creep.setup_and_process_ant(ant)
|
85
|
+
}.should change(creep, :passed).by(1)
|
86
|
+
ant.stub(:execution_status){'failed'}
|
87
|
+
lambda{
|
88
|
+
creep.setup_and_process_ant(ant)
|
89
|
+
}.should_not change(creep, :passed).by(1)
|
90
|
+
end
|
91
|
+
it "should call setup method" do
|
92
|
+
creep.should_receive(:setup).with(creep_modifier, ant).and_return(true)
|
93
|
+
creep.setup_and_process_ant(ant)
|
94
|
+
end
|
95
|
+
context "setup ok" do
|
96
|
+
it "should call run method" do
|
97
|
+
creep.should_receive(:run).with(creep_modifier, ant)
|
98
|
+
creep.setup_and_process_ant(ant)
|
99
|
+
end
|
100
|
+
it "should change current_params to ant params " do
|
101
|
+
creep.setup_and_process_ant(ant)
|
102
|
+
creep.current_params.should eql(params)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
context "priority" do
|
106
|
+
it "should reset priority if creep params changed" do
|
107
|
+
creep_modifier.stub(:creep_params){ [:aaa, :bbb]}
|
108
|
+
creep.stub(:current_params){ {:aaa => 2, :bbb => 2}}
|
109
|
+
Queen.queen.should_receive(:reset_priority_for_creep).with(creep)
|
110
|
+
creep.setup_and_process_ant(ant)
|
111
|
+
creep.force_priority.should be_false
|
112
|
+
end
|
113
|
+
it "should reset priority if it set manually" do
|
114
|
+
creep_modifier.stub(:creep_params){ [:aaa, :bbb]}
|
115
|
+
creep.stub(:current_params){ params }
|
116
|
+
creep.force_priority = true
|
117
|
+
Queen.queen.should_receive(:reset_priority_for_creep).with(creep)
|
118
|
+
creep.setup_and_process_ant(ant)
|
119
|
+
creep.force_priority.should be_false
|
120
|
+
end
|
121
|
+
it "should not reset priority if params are same and isn't set manually" do
|
122
|
+
creep_modifier.stub(:creep_params){ [:aaa, :bbb]}
|
123
|
+
creep.stub(:current_params){ params }
|
124
|
+
Queen.queen.should_not_receive(:reset_priority_for_creep)
|
125
|
+
creep.setup_and_process_ant(ant)
|
126
|
+
creep.force_priority.should be_false
|
127
|
+
end
|
128
|
+
end
|
129
|
+
context "setup failed" do
|
130
|
+
before :each do
|
131
|
+
creep.stub(:setup){false}
|
132
|
+
end
|
133
|
+
it "should not call run method" do
|
134
|
+
creep.should_not_receive(:run).with(creep_modifier, ant)
|
135
|
+
creep.setup_and_process_ant(ant)
|
136
|
+
end
|
137
|
+
it "should clean up current params" do
|
138
|
+
creep.instance_variable_set(:@current_params, {:c => 3})
|
139
|
+
creep.setup_and_process_ant(ant)
|
140
|
+
creep.current_params.should eql({})
|
141
|
+
end
|
142
|
+
it "should change status to error" do
|
143
|
+
creep.stub(:change_status)
|
144
|
+
creep.should_receive(:change_status).with(:error)
|
145
|
+
creep.setup_and_process_ant(ant)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
it "should log error and change status to :error if exception happen during setup" do
|
149
|
+
creep.stub(:setup){raise}
|
150
|
+
creep.should_receive(:change_status).with(:error)
|
151
|
+
logger.should_receive(:error)
|
152
|
+
creep.setup_and_process_ant(ant)
|
153
|
+
end
|
154
|
+
it "should log error and change status to :error if exception happen during run" do
|
155
|
+
creep.stub(:run){raise}
|
156
|
+
creep.should_receive(:change_status).with(:error)
|
157
|
+
logger.should_receive(:error)
|
158
|
+
creep.setup_and_process_ant(ant)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
context "#setup" do
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "ant_hill"
|
@@ -0,0 +1,43 @@
|
|
1
|
+
#Base dir of project
|
2
|
+
basedir: /export/web/ant_hill
|
3
|
+
|
4
|
+
#AntHillExtension libriries
|
5
|
+
lib_path: spec/support/ant_hill_libs.rb
|
6
|
+
|
7
|
+
# Time to sleep before next request of ant
|
8
|
+
sleep_interval: 1
|
9
|
+
|
10
|
+
log_dir: /tmp/ant_hill
|
11
|
+
log_level:
|
12
|
+
|
13
|
+
types:
|
14
|
+
first:
|
15
|
+
ant_colony_class: AntHill::FirstAntColony
|
16
|
+
creep_modifier_class: AntHill::FirstCreepModifier
|
17
|
+
|
18
|
+
second:
|
19
|
+
ant_colony_class: AntHill::SecondAntColony
|
20
|
+
creep_modifier_class: AntHill::SecondCreepModifier
|
21
|
+
|
22
|
+
default_type: first
|
23
|
+
|
24
|
+
|
25
|
+
#Test nodes
|
26
|
+
|
27
|
+
creeps:
|
28
|
+
-
|
29
|
+
name: one
|
30
|
+
host: ivan.test.com
|
31
|
+
login: test
|
32
|
+
-
|
33
|
+
name: two
|
34
|
+
host: sel01.test.com
|
35
|
+
login: test
|
36
|
+
-
|
37
|
+
name: three
|
38
|
+
host: sel02.test.com
|
39
|
+
login: test
|
40
|
+
-
|
41
|
+
name: four
|
42
|
+
host: sel03.test.com
|
43
|
+
login: test
|
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ant_hill
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ivan Neverov
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-07-09 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: net-ssh
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: ! 'Application for running stuff with same purpose on several nodes
|
47
|
+
|
48
|
+
It find "best matching job" (based on setup time) for particular node and setup
|
49
|
+
node
|
50
|
+
|
51
|
+
Then it run job on this node
|
52
|
+
|
53
|
+
|
54
|
+
Originally it was desined for CI.'
|
55
|
+
email:
|
56
|
+
- ineverov@sphereconsultinginc.com
|
57
|
+
executables:
|
58
|
+
- spawn_queen
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- Gemfile
|
64
|
+
- Rakefile
|
65
|
+
- ant_hill.gemspec
|
66
|
+
- bin/spawn_queen
|
67
|
+
- lib/ant_hill.rb
|
68
|
+
- lib/ant_hill/ant.rb
|
69
|
+
- lib/ant_hill/ant_colony.rb
|
70
|
+
- lib/ant_hill/configuration.rb
|
71
|
+
- lib/ant_hill/connection_pool.rb
|
72
|
+
- lib/ant_hill/connections/ssh_connection.rb
|
73
|
+
- lib/ant_hill/creep.rb
|
74
|
+
- lib/ant_hill/creep_modifier.rb
|
75
|
+
- lib/ant_hill/log.rb
|
76
|
+
- lib/ant_hill/queen.rb
|
77
|
+
- lib/ant_hill/version.rb
|
78
|
+
- lib/tasks/ant_hill.rake
|
79
|
+
- spec/ant_hill/ant_colony_spec.rb
|
80
|
+
- spec/ant_hill/ant_spec.rb
|
81
|
+
- spec/ant_hill/configuration_spec.rb
|
82
|
+
- spec/ant_hill/creep_modifier_spec.rb
|
83
|
+
- spec/ant_hill/creep_spec.rb
|
84
|
+
- spec/spec_helper.rb
|
85
|
+
- spec/support/config.yml
|
86
|
+
homepage: ''
|
87
|
+
licenses: []
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ! '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubyforge_project: ant_hill
|
106
|
+
rubygems_version: 1.8.24
|
107
|
+
signing_key:
|
108
|
+
specification_version: 3
|
109
|
+
summary: Run tests in grid
|
110
|
+
test_files:
|
111
|
+
- spec/ant_hill/ant_colony_spec.rb
|
112
|
+
- spec/ant_hill/ant_spec.rb
|
113
|
+
- spec/ant_hill/configuration_spec.rb
|
114
|
+
- spec/ant_hill/creep_modifier_spec.rb
|
115
|
+
- spec/ant_hill/creep_spec.rb
|
116
|
+
- spec/spec_helper.rb
|
117
|
+
- spec/support/config.yml
|