jenkins_api_client 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,87 @@
1
+ #
2
+ # Copyright (c) 2012 Kannan Manickam <arangamani.kannan@gmail.com>
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ # of this software and associated documentation files (the "Software"), to deal
6
+ # in the Software without restriction, including without limitation the rights
7
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the Software is
9
+ # furnished to do so, subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in
12
+ # all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ # THE SOFTWARE.
21
+ #
22
+
23
+ require 'timeout'
24
+
25
+ module JenkinsApi
26
+ class Client
27
+ class System
28
+
29
+ # Initializes a new System object.
30
+ #
31
+ # @param [Object] client a reference to Client
32
+ #
33
+ def initialize(client)
34
+ @client = client
35
+ end
36
+
37
+ # Returns a string representation of System class.
38
+ #
39
+ def to_s
40
+ "#<JenkinsApi::Client::System>"
41
+ end
42
+
43
+ # Sends a quiet down request to the server.
44
+ #
45
+ def quiet_down
46
+ @client.api_post_request("/quietDown")
47
+ end
48
+
49
+ # Cancels the quiet doen request sent to the server.
50
+ #
51
+ def cancel_quiet_down
52
+ @client.api_post_request("/cancelQuietDown")
53
+ end
54
+
55
+ # Restarts the Jenkins server
56
+ #
57
+ # @param [Bool] force whether to force restart or wait till all jobs are completed.
58
+ #
59
+ def restart(force = false)
60
+ if force
61
+ @client.api_post_request("/restart")
62
+ else
63
+ @client.api_post_request("/safeRestart")
64
+ end
65
+ end
66
+
67
+ # This method waits till the server becomes ready after a start or restart.
68
+ #
69
+ def wait_for_ready
70
+ Timeout::timeout(120) do
71
+ while true do
72
+ response = @client.get_root
73
+ puts "[INFO] Waiting for jenkins to restart..." if @client.debug
74
+ if (response.body =~ /Please wait while Jenkins is restarting/ || response.body =~ /Please wait while Jenkins is getting ready to work/)
75
+ sleep 15
76
+ redo
77
+ else
78
+ return true
79
+ end
80
+ end
81
+ end
82
+ false
83
+ end
84
+
85
+ end
86
+ end
87
+ end
@@ -22,6 +22,10 @@
22
22
 
23
23
  module JenkinsApi
24
24
  class Client
25
- VERSION = "0.2.1"
25
+ MAJOR = 0
26
+ MINOR = 3
27
+ TINY = 0
28
+ PRE = nil
29
+ VERSION = [MAJOR, MINOR, TINY, PRE].compact.join('.')
26
30
  end
27
31
  end
data/spec/client_spec.rb CHANGED
@@ -20,6 +20,11 @@ describe JenkinsApi::Client do
20
20
  end
21
21
  end
22
22
 
23
+ it "Should be able to toggle the debug value" do
24
+ value = @client.debug
25
+ @client.toggle_debug.should_not == value
26
+ end
27
+
23
28
  it "Should be able to initialize with valid credentials" do
24
29
  client1 = JenkinsApi::Client.new(YAML.load_file(File.expand_path(@creds_file, __FILE__)))
25
30
  client1.class.should == JenkinsApi::Client
data/spec/node_spec.rb ADDED
@@ -0,0 +1,48 @@
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/login.yml'
13
+ @node_name = 'master'
14
+ begin
15
+ @client = JenkinsApi::Client.new(YAML.load_file(File.expand_path(@creds_file, __FILE__)))
16
+ rescue Exception => e
17
+ puts "WARNING: Credentials are not set properly."
18
+ puts e.message
19
+ end
20
+ end
21
+
22
+ it "Should be able to list all nodes" do
23
+ @client.node.list.class.should == Array
24
+ end
25
+
26
+ it "Should be able to list all general attributes" do
27
+ node_attributes = JenkinsApi::Client::Node::GENERAL_ATTRIBUTES
28
+ node_attributes.each do |attr|
29
+ @client.node.method("get_#{attr}").call
30
+ end
31
+ end
32
+
33
+ it "Should be able to list all node properties" do
34
+ node_properties = JenkinsApi::Client::Node::NODE_PROPERTIES
35
+ node_properties.each do |property|
36
+ @client.node.method("is_#{property}?").call(@node_name)
37
+ end
38
+ end
39
+
40
+ it "Should be able to list all node attributes" do
41
+ node_attributes = JenkinsApi::Client::Node::NODE_ATTRIBUTES
42
+ node_attributes.each do |attr|
43
+ @client.node.method("get_node_#{attr}").call(@node_name)
44
+ end
45
+ end
46
+
47
+ end
48
+ end
data/spec/spec_helper.rb CHANGED
@@ -10,9 +10,9 @@ require 'pp'
10
10
  require 'yaml'
11
11
  require 'nokogiri'
12
12
 
13
- RSpec.configure do |config|
14
- config.mock_with :flexmock
15
- end
13
+ #RSpec.configure do |config|
14
+ # config.mock_with :flexmock
15
+ #end
16
16
 
17
17
  module JenkinsApiSpecHelper
18
18
  class Helper
@@ -0,0 +1,46 @@
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/login.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
+ it "Should be able to quiet down a Jenkins server" do
22
+ @client.system.quiet_down.to_i.should == 302
23
+ end
24
+
25
+ it "Should be able to cancel the quiet down a Jenkins server" do
26
+ @client.system.cancel_quiet_down.to_i.should == 302
27
+ end
28
+
29
+ it "Should be able to restart a Jenkins server safely" do
30
+ @client.system.restart.to_i.should == 302
31
+ end
32
+
33
+ it "Should be able to wait after a safe restart" do
34
+ @client.system.wait_for_ready.should == true
35
+ end
36
+
37
+ it "Should be able to force restart a Jenkins server" do
38
+ @client.system.restart(true).to_i.should == 302
39
+ end
40
+
41
+ it "Should be able to wait after a force restart" do
42
+ @client.system.wait_for_ready.should == true
43
+ end
44
+
45
+ end
46
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jenkins_api_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,24 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-02 00:00:00.000000000 Z
12
+ date: 2012-11-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - ~>
19
+ - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: 1.5.5
21
+ version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - ~>
27
+ - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
- version: 1.5.5
29
+ version: '0'
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: activesupport
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -75,28 +75,44 @@ dependencies:
75
75
  - - ! '>='
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: terminal-table
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: 1.4.0
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: 1.4.0
78
94
  - !ruby/object:Gem::Dependency
79
95
  name: bundler
80
96
  requirement: !ruby/object:Gem::Requirement
81
97
  none: false
82
98
  requirements:
83
- - - ~>
99
+ - - ! '>='
84
100
  - !ruby/object:Gem::Version
85
- version: 1.2.1
101
+ version: '1.0'
86
102
  type: :development
87
103
  prerelease: false
88
104
  version_requirements: !ruby/object:Gem::Requirement
89
105
  none: false
90
106
  requirements:
91
- - - ~>
107
+ - - ! '>='
92
108
  - !ruby/object:Gem::Version
93
- version: 1.2.1
109
+ version: '1.0'
94
110
  - !ruby/object:Gem::Dependency
95
111
  name: jeweler
96
112
  requirement: !ruby/object:Gem::Requirement
97
113
  none: false
98
114
  requirements:
99
- - - ~>
115
+ - - ! '>='
100
116
  - !ruby/object:Gem::Version
101
117
  version: 1.6.4
102
118
  type: :development
@@ -104,7 +120,7 @@ dependencies:
104
120
  version_requirements: !ruby/object:Gem::Requirement
105
121
  none: false
106
122
  requirements:
107
- - - ~>
123
+ - - ! '>='
108
124
  - !ruby/object:Gem::Version
109
125
  version: 1.6.4
110
126
  - !ruby/object:Gem::Dependency
@@ -139,6 +155,22 @@ dependencies:
139
155
  - - ! '>='
140
156
  - !ruby/object:Gem::Version
141
157
  version: '0'
158
+ - !ruby/object:Gem::Dependency
159
+ name: rspec
160
+ requirement: !ruby/object:Gem::Requirement
161
+ none: false
162
+ requirements:
163
+ - - ! '>='
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ type: :development
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
142
174
  description: ! '
143
175
 
144
176
  This is a simple and easy-to-use Jenkins Api client with features focused on
@@ -151,27 +183,34 @@ executables:
151
183
  extensions: []
152
184
  extra_rdoc_files:
153
185
  - CHANGELOG.rdoc
154
- - README.rdoc
155
186
  files:
156
187
  - .gitignore
188
+ - .travis.yml
157
189
  - CHANGELOG.rdoc
158
190
  - Gemfile
159
191
  - LICENCE
160
- - README.rdoc
192
+ - README.md
161
193
  - Rakefile
162
194
  - bin/jenkinscli
163
195
  - config/login.yml.example
164
196
  - lib/jenkins_api_client.rb
165
197
  - lib/jenkins_api_client/cli/base.rb
198
+ - lib/jenkins_api_client/cli/helper.rb
166
199
  - lib/jenkins_api_client/cli/job.rb
200
+ - lib/jenkins_api_client/cli/node.rb
201
+ - lib/jenkins_api_client/cli/system.rb
167
202
  - lib/jenkins_api_client/client.rb
168
203
  - lib/jenkins_api_client/exceptions.rb
169
204
  - lib/jenkins_api_client/job.rb
205
+ - lib/jenkins_api_client/node.rb
206
+ - lib/jenkins_api_client/system.rb
170
207
  - lib/jenkins_api_client/version.rb
171
208
  - scripts/login_with_irb.rb
172
209
  - spec/client_spec.rb
173
210
  - spec/job_spec.rb
211
+ - spec/node_spec.rb
174
212
  - spec/spec_helper.rb
213
+ - spec/system_spec.rb
175
214
  homepage: https://github.com/arangamani/jenkins_api_client
176
215
  licenses: []
177
216
  post_install_message:
@@ -186,7 +225,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
186
225
  version: '0'
187
226
  segments:
188
227
  - 0
189
- hash: 2332251850265397219
228
+ hash: -1111690897825719008
190
229
  required_rubygems_version: !ruby/object:Gem::Requirement
191
230
  none: false
192
231
  requirements: