jenkins_api_client 0.6.2 → 0.7.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/.gitignore +3 -0
- data/.jenkins.yml +9 -0
- data/.travis.yml +11 -15
- data/CHANGELOG.md +15 -0
- data/Gemfile +2 -2
- data/README.md +7 -9
- data/Rakefile +27 -14
- data/lib/jenkins_api_client.rb +36 -6
- data/lib/jenkins_api_client/build_queue.rb +213 -0
- data/lib/jenkins_api_client/cli/base.rb +10 -6
- data/lib/jenkins_api_client/cli/helper.rb +13 -4
- data/lib/jenkins_api_client/cli/job.rb +6 -9
- data/lib/jenkins_api_client/cli/node.rb +6 -4
- data/lib/jenkins_api_client/cli/system.rb +2 -1
- data/lib/jenkins_api_client/client.rb +31 -25
- data/lib/jenkins_api_client/job.rb +248 -95
- data/lib/jenkins_api_client/node.rb +128 -10
- data/lib/jenkins_api_client/system.rb +4 -2
- data/lib/jenkins_api_client/version.rb +2 -2
- data/lib/jenkins_api_client/view.rb +17 -4
- data/scripts/login_with_irb.rb +4 -3
- data/spec/func_tests/client_spec.rb +90 -0
- data/spec/func_tests/job_spec.rb +348 -0
- data/spec/func_tests/node_spec.rb +174 -0
- data/spec/{spec_helper.rb → func_tests/spec_helper.rb} +2 -2
- data/spec/func_tests/system_spec.rb +55 -0
- data/spec/func_tests/view_spec.rb +53 -0
- data/spec/unit_tests/client_spec.rb +211 -0
- data/spec/unit_tests/fixtures/files/computer_sample.xml +17 -0
- data/spec/unit_tests/fixtures/files/job_sample.xml +16 -0
- data/spec/unit_tests/job_spec.rb +355 -0
- data/spec/unit_tests/node_spec.rb +192 -0
- data/spec/unit_tests/spec_helper.rb +8 -0
- data/spec/unit_tests/system_spec.rb +54 -0
- data/spec/unit_tests/view_spec.rb +127 -0
- metadata +34 -23
- data/spec/client_spec.rb +0 -52
- data/spec/job_spec.rb +0 -158
- data/spec/node_spec.rb +0 -48
- data/spec/system_spec.rb +0 -46
@@ -0,0 +1,174 @@
|
|
1
|
+
#
|
2
|
+
# Specifying JenkinsApi::Client::Node class capabilities
|
3
|
+
# Author Kannan Manickam <arangamani.kannan@gmail.com>
|
4
|
+
#
|
5
|
+
|
6
|
+
require File.expand_path('../spec_helper', __FILE__)
|
7
|
+
require 'yaml'
|
8
|
+
|
9
|
+
describe JenkinsApi::Client::Node do
|
10
|
+
context "With properly initialized client" do
|
11
|
+
before(:all) do
|
12
|
+
@creds_file = '~/.jenkins_api_client/spec.yml'
|
13
|
+
@node_name = 'master'
|
14
|
+
begin
|
15
|
+
@client = JenkinsApi::Client.new(
|
16
|
+
YAML.load_file(File.expand_path(@creds_file, __FILE__))
|
17
|
+
)
|
18
|
+
rescue Exception => e
|
19
|
+
puts "WARNING: Credentials are not set properly."
|
20
|
+
puts e.message
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "InstanceMethods" do
|
25
|
+
|
26
|
+
describe "#initialize" do
|
27
|
+
it "Initializes without any exception" do
|
28
|
+
expect(
|
29
|
+
lambda{ node = JenkinsApi::Client::Node.new(@client) }
|
30
|
+
).not_to raise_error
|
31
|
+
end
|
32
|
+
it "Raises an error if a reference of client is not passed" do
|
33
|
+
expect(
|
34
|
+
lambda{ node JenkinsApi::Client::Node.new() }
|
35
|
+
).to raise_error
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "#create_dump_slave" do
|
40
|
+
it "accepts required params and creates the slave on jenkins" do
|
41
|
+
params = {
|
42
|
+
:name => "func_test_slave",
|
43
|
+
:slave_host => "10.10.10.10",
|
44
|
+
:private_key_file => "/root/.ssh/id_rsa"
|
45
|
+
}
|
46
|
+
@client.node.create_dump_slave(params).to_i.should == 302
|
47
|
+
@client.node.delete(params[:name]).to_i.should == 302
|
48
|
+
end
|
49
|
+
it "fails if name is missing" do
|
50
|
+
params = {
|
51
|
+
:slave_host => "10.10.10.10",
|
52
|
+
:private_key_file => "/root/.ssh/id_rsa"
|
53
|
+
}
|
54
|
+
expect(
|
55
|
+
lambda{ @client.node.create_dump_slave(params) }
|
56
|
+
).to raise_error
|
57
|
+
end
|
58
|
+
it "fails if slave_host is missing" do
|
59
|
+
params = {
|
60
|
+
:name => "func_test_slave",
|
61
|
+
:private_key_file => "/root/.ssh/id_rsa"
|
62
|
+
}
|
63
|
+
expect(
|
64
|
+
lambda{ @client.node.create_dump_slave(params) }
|
65
|
+
).to raise_error
|
66
|
+
end
|
67
|
+
it "fails if private_key_file is missing" do
|
68
|
+
params = {
|
69
|
+
:name => "func_test_slave",
|
70
|
+
:slave_host => "10.10.10.10"
|
71
|
+
}
|
72
|
+
expect(
|
73
|
+
lambda{ @client.node.create_dump_slave(params) }
|
74
|
+
).to raise_error
|
75
|
+
end
|
76
|
+
it "fails if the slave already exists in Jenkins" do
|
77
|
+
params = {
|
78
|
+
:name => "func_test_slave",
|
79
|
+
:slave_host => "10.10.10.10",
|
80
|
+
:private_key_file => "/root/.ssh/id_rsa"
|
81
|
+
}
|
82
|
+
@client.node.create_dump_slave(params).to_i.should == 302
|
83
|
+
expect(
|
84
|
+
lambda{ @client.node.create_dump_slave(params) }
|
85
|
+
).to raise_error
|
86
|
+
@client.node.delete(params[:name]).to_i.should == 302
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe "#delete" do
|
91
|
+
it "deletes the node given the name" do
|
92
|
+
params = {
|
93
|
+
:name => "func_test_slave",
|
94
|
+
:slave_host => "10.10.10.10",
|
95
|
+
:private_key_file => "/root/.ssh/id_rsa"
|
96
|
+
}
|
97
|
+
@client.node.create_dump_slave(params).to_i.should == 302
|
98
|
+
@client.node.delete(params[:name]).to_i.should == 302
|
99
|
+
end
|
100
|
+
it "raises an error if the slave doesn't exist in Jenkins" do
|
101
|
+
expect(
|
102
|
+
lambda{ @client.node.delete("not_there") }
|
103
|
+
).to raise_error
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
describe "#list" do
|
108
|
+
it "Should be able to list all nodes" do
|
109
|
+
@client.node.list.class.should == Array
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
describe "GeneralAttributes" do
|
114
|
+
general_attributes = JenkinsApi::Client::Node::GENERAL_ATTRIBUTES
|
115
|
+
general_attributes.each do |attribute|
|
116
|
+
describe "#get_#{attribute}" do
|
117
|
+
it "should get the #{attribute} attribute" do
|
118
|
+
@client.node.method("get_#{attribute}").call
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
describe "NodeProperties" do
|
125
|
+
node_properties = JenkinsApi::Client::Node::NODE_PROPERTIES
|
126
|
+
node_properties.each do |property|
|
127
|
+
describe "#is_#{property}" do
|
128
|
+
it "should get the #{property} property" do
|
129
|
+
@client.node.method("is_#{property}?").call(@node_name)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
describe "NodeAttributes" do
|
136
|
+
node_attributes = JenkinsApi::Client::Node::NODE_ATTRIBUTES
|
137
|
+
node_attributes.each do |attribute|
|
138
|
+
describe "#get_node_#{attribute}" do
|
139
|
+
it "Should be able to list all node attributes" do
|
140
|
+
@client.node.method("get_node_#{attribute}").call(@node_name)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
describe "#change_mode" do
|
147
|
+
it "changes the mode of the given slave to the given mode" do
|
148
|
+
@client.node.change_mode("slave", "exclusive").to_i.should == 200
|
149
|
+
@client.node.change_mode("slave", "normal").to_i.should == 200
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
describe "#get_config" do
|
154
|
+
it "obtaines the node config.xml from the server" do
|
155
|
+
expect(
|
156
|
+
lambda { @client.node.get_config("slave") }
|
157
|
+
).not_to raise_error
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
describe "#post_config" do
|
162
|
+
it "posts the given config.xml to the jenkins server's node" do
|
163
|
+
expect(
|
164
|
+
lambda {
|
165
|
+
xml = @client.node.get_config("slave")
|
166
|
+
@client.node.post_config("slave", xml)
|
167
|
+
}
|
168
|
+
).not_to raise_error
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
require 'simplecov'
|
7
7
|
SimpleCov.start if ENV["COVERAGE"]
|
8
|
-
require File.expand_path('
|
8
|
+
require File.expand_path('../../../lib/jenkins_api_client', __FILE__)
|
9
9
|
require 'pp'
|
10
10
|
require 'yaml'
|
11
11
|
require 'nokogiri'
|
@@ -33,7 +33,7 @@ module JenkinsApiSpecHelper
|
|
33
33
|
xml.concurrentBuild "false"
|
34
34
|
xml.builders {
|
35
35
|
xml.send("hudson.tasks.Shell") {
|
36
|
-
xml.command "\necho 'going to take a nice nap'\nsleep
|
36
|
+
xml.command "\necho 'going to take a nice nap'\nsleep 10\necho 'took a nice nap'"
|
37
37
|
}
|
38
38
|
}
|
39
39
|
xml.publishers
|
@@ -0,0 +1,55 @@
|
|
1
|
+
#
|
2
|
+
# Specifying JenkinsApi::Client::System class capabilities
|
3
|
+
# Author: Kannan Manickam <arangamani.kannan@gmail.com>
|
4
|
+
#
|
5
|
+
|
6
|
+
require File.expand_path('../spec_helper', __FILE__)
|
7
|
+
require 'yaml'
|
8
|
+
|
9
|
+
describe JenkinsApi::Client::System do
|
10
|
+
context "With properly initialized client" do
|
11
|
+
before(:all) do
|
12
|
+
@creds_file = '~/.jenkins_api_client/spec.yml'
|
13
|
+
begin
|
14
|
+
@client = JenkinsApi::Client.new(YAML.load_file(File.expand_path(@creds_file, __FILE__)))
|
15
|
+
rescue Exception => e
|
16
|
+
puts "WARNING: Credentials are not set properly."
|
17
|
+
puts e.message
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "InstanceMethods" do
|
22
|
+
|
23
|
+
describe "#quiet_down" do
|
24
|
+
it "Should be able to quiet down a Jenkins server" do
|
25
|
+
@client.system.quiet_down.to_i.should == 302
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "#cancel_quiet_down" do
|
30
|
+
it "Should be able to cancel the quiet down a Jenkins server" do
|
31
|
+
@client.system.cancel_quiet_down.to_i.should == 302
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "#restart" do
|
36
|
+
it "Should be able to restart a Jenkins server safely" do
|
37
|
+
@client.system.restart.to_i.should == 302
|
38
|
+
end
|
39
|
+
|
40
|
+
it "Should be able to wait after a safe restart" do
|
41
|
+
@client.system.wait_for_ready.should == true
|
42
|
+
end
|
43
|
+
|
44
|
+
it "Should be able to force restart a Jenkins server" do
|
45
|
+
@client.system.restart(true).to_i.should == 302
|
46
|
+
end
|
47
|
+
|
48
|
+
it "Should be able to wait after a force restart" do
|
49
|
+
@client.system.wait_for_ready.should == true
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
#
|
2
|
+
# Specifying JenkinsApi::Client::View class capabilities
|
3
|
+
# Author Kannan Manickam <arangamani.kannan@gmail.com>
|
4
|
+
#
|
5
|
+
|
6
|
+
require File.expand_path('../spec_helper', __FILE__)
|
7
|
+
require 'yaml'
|
8
|
+
|
9
|
+
describe JenkinsApi::Client::View do
|
10
|
+
context "With properly initialized client" do
|
11
|
+
before(:all) do
|
12
|
+
@creds_file = '~/.jenkins_api_client/spec.yml'
|
13
|
+
@node_name = 'master'
|
14
|
+
begin
|
15
|
+
@client = JenkinsApi::Client.new(
|
16
|
+
YAML.load_file(File.expand_path(@creds_file, __FILE__))
|
17
|
+
)
|
18
|
+
rescue Exception => e
|
19
|
+
puts "WARNING: Credentials are not set properly."
|
20
|
+
puts e.message
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "InstanceMethods" do
|
25
|
+
|
26
|
+
describe "#list" do
|
27
|
+
it "Should be able to list all views" do
|
28
|
+
@client.view.list.class.should == Array
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "#get_config" do
|
33
|
+
it "obtaines the view config.xml from the server" do
|
34
|
+
#expect(
|
35
|
+
#lambda { @client.view.get_config("slave") }
|
36
|
+
#).not_to raise_error
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "#post_config" do
|
41
|
+
it "posts the given config.xml to the jenkins server's view" do
|
42
|
+
#expect(
|
43
|
+
#lambda {
|
44
|
+
#xml = @client.view.get_config("slave")
|
45
|
+
#@client.view.post_config("slave", xml)
|
46
|
+
#}
|
47
|
+
#).not_to raise_error
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,211 @@
|
|
1
|
+
require File.expand_path('../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe JenkinsApi::Client do
|
4
|
+
context "With valid credentials given" do
|
5
|
+
before do
|
6
|
+
@client = JenkinsApi::Client.new(
|
7
|
+
:server_ip => '127.0.0.1',
|
8
|
+
:server_port => 8080,
|
9
|
+
:username => 'username',
|
10
|
+
:password => 'password'
|
11
|
+
)
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#initialize" do
|
15
|
+
it "initializes without exception" do
|
16
|
+
expect(
|
17
|
+
lambda do
|
18
|
+
JenkinsApi::Client.new(
|
19
|
+
:server_ip => '127.0.0.1',
|
20
|
+
:server_port => 8080,
|
21
|
+
:username => 'username',
|
22
|
+
:password => 'password'
|
23
|
+
)
|
24
|
+
end
|
25
|
+
).not_to raise_error
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "#debug" do
|
30
|
+
it "The default for debug should be false" do
|
31
|
+
client = JenkinsApi::Client.new(
|
32
|
+
:server_ip => '127.0.0.1',
|
33
|
+
:server_port => 8080,
|
34
|
+
:username => 'username',
|
35
|
+
:password => 'password'
|
36
|
+
)
|
37
|
+
client.debug.should == false
|
38
|
+
end
|
39
|
+
|
40
|
+
it "Should be able to set the debug value" do
|
41
|
+
client = JenkinsApi::Client.new(
|
42
|
+
:server_ip => '127.0.0.1',
|
43
|
+
:server_port => 8080,
|
44
|
+
:username => 'username',
|
45
|
+
:password => 'password',
|
46
|
+
:debug => true
|
47
|
+
)
|
48
|
+
client.debug.should == true
|
49
|
+
end
|
50
|
+
|
51
|
+
it "Should be able to toggle the debug value" do
|
52
|
+
client = JenkinsApi::Client.new(
|
53
|
+
:server_ip => '127.0.0.1',
|
54
|
+
:server_port => 8080,
|
55
|
+
:username => 'username',
|
56
|
+
:password => 'password',
|
57
|
+
:debug => true
|
58
|
+
)
|
59
|
+
client.toggle_debug
|
60
|
+
client.debug.should == false
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "#SubClassAccessorMethods" do
|
65
|
+
describe "#job" do
|
66
|
+
it "Should return a Client::Job object" do
|
67
|
+
client = JenkinsApi::Client.new(
|
68
|
+
:server_ip => '127.0.0.1',
|
69
|
+
:server_port => 8080,
|
70
|
+
:username => 'username',
|
71
|
+
:password => 'password'
|
72
|
+
)
|
73
|
+
client.job.class.should == JenkinsApi::Client::Job
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "#node" do
|
78
|
+
it "Should return a Client::Node object" do
|
79
|
+
client = JenkinsApi::Client.new(
|
80
|
+
:server_ip => '127.0.0.1',
|
81
|
+
:server_port => 8080,
|
82
|
+
:username => 'username',
|
83
|
+
:password => 'password'
|
84
|
+
)
|
85
|
+
client.node.class.should == JenkinsApi::Client::Node
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "#view" do
|
90
|
+
it "Should return a Client::View object" do
|
91
|
+
client = JenkinsApi::Client.new(
|
92
|
+
:server_ip => '127.0.0.1',
|
93
|
+
:server_port => 8080,
|
94
|
+
:username => 'username',
|
95
|
+
:password => 'password'
|
96
|
+
)
|
97
|
+
client.view.class.should == JenkinsApi::Client::View
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe "#system" do
|
102
|
+
it "Should return a Client::System object" do
|
103
|
+
client = JenkinsApi::Client.new(
|
104
|
+
:server_ip => '127.0.0.1',
|
105
|
+
:server_port => 8080,
|
106
|
+
:username => 'username',
|
107
|
+
:password => 'password'
|
108
|
+
)
|
109
|
+
client.system.class.should == JenkinsApi::Client::System
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
describe "#queue" do
|
114
|
+
it "Should return a Client::BuildQueue object" do
|
115
|
+
client = JenkinsApi::Client.new(
|
116
|
+
:server_ip => '127.0.0.1',
|
117
|
+
:server_port => 8080,
|
118
|
+
:username => 'username',
|
119
|
+
:password => 'password'
|
120
|
+
)
|
121
|
+
client.queue.class.should == JenkinsApi::Client::BuildQueue
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
describe "InstanceMethods" do
|
127
|
+
describe "#getroot" do
|
128
|
+
it "is defined with no parameters" do
|
129
|
+
expect(
|
130
|
+
lambda { @client.get_root }
|
131
|
+
).not_to raise_error(NoMethodError)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
describe "#api_get_request" do
|
136
|
+
it "defined and should accept url_prefix, tree, and url_suffix" do
|
137
|
+
expect(
|
138
|
+
lambda { @client.api_get_request("/some/prefix", "tree", "/json") }
|
139
|
+
).not_to raise_error(NoMethodError)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
describe "#api_post_request" do
|
144
|
+
it "is defined and should accept url_prefix" do
|
145
|
+
expect(
|
146
|
+
lambda { @client.api_post_request("/some/prefix") }
|
147
|
+
).not_to raise_error(NoMethodError)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
describe "#get_config" do
|
152
|
+
it "is defined and should accept url_prefix" do
|
153
|
+
expect(
|
154
|
+
lambda { @client.get_config("/some/prefix") }
|
155
|
+
).not_to raise_error(NoMethodError)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
describe "#post_config" do
|
160
|
+
it "is defined and should accept url_prefix and xml" do
|
161
|
+
expect(
|
162
|
+
lambda { @client.post_config("/some/prefix", "<tag></tag>") }
|
163
|
+
).not_to raise_error(NoMethodError)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
context "With some required parameters missing" do
|
170
|
+
context "#initialize" do
|
171
|
+
it "Should fail if server_ip is missing" do
|
172
|
+
expect(
|
173
|
+
lambda do
|
174
|
+
JenkinsApi::Client.new({
|
175
|
+
:bogus => '127.0.0.1',
|
176
|
+
:server_port => 8080,
|
177
|
+
:username => 'username',
|
178
|
+
:password => 'password'
|
179
|
+
})
|
180
|
+
end
|
181
|
+
).to raise_error
|
182
|
+
end
|
183
|
+
|
184
|
+
it "Should fail if username is missing" do
|
185
|
+
expect(
|
186
|
+
lambda do
|
187
|
+
JenkinsApi::Client.new({
|
188
|
+
:server_ip => '127.0.0.1',
|
189
|
+
:server_port => 8080,
|
190
|
+
:bogus => 'username',
|
191
|
+
:password => 'password'
|
192
|
+
})
|
193
|
+
end
|
194
|
+
).to raise_error
|
195
|
+
end
|
196
|
+
|
197
|
+
it "Should fail if password is missing" do
|
198
|
+
expect(
|
199
|
+
lambda do
|
200
|
+
JenkinsApi::Client.new({
|
201
|
+
:server_ip => '127.0.0.1',
|
202
|
+
:server_port => 8080,
|
203
|
+
:username => 'username',
|
204
|
+
:bogus => 'password'
|
205
|
+
})
|
206
|
+
end
|
207
|
+
).to raise_error
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|