buzz 0.0.5 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - "1.8.7"
4
+ - "1.9.2"
5
+ - "1.9.3"
6
+
7
+ script: bundle exec cucumber
data/Gemfile CHANGED
@@ -16,4 +16,5 @@ group :test do
16
16
  gem 'vcr'
17
17
  gem 'rspec'
18
18
  gem 'aruba'
19
+ gem 'fakeweb'
19
20
  end
@@ -17,6 +17,7 @@ GEM
17
17
  multi_json (~> 1.3)
18
18
  diff-lcs (1.2.1)
19
19
  extensions (0.6.0)
20
+ fakeweb (1.3.0)
20
21
  ffi (1.7.0)
21
22
  gherkin (2.11.8)
22
23
  multi_json (~> 1.3)
@@ -53,6 +54,7 @@ DEPENDENCIES
53
54
  aruba
54
55
  bundler
55
56
  extensions
57
+ fakeweb
56
58
  jeweler (~> 1.8.4)
57
59
  rake
58
60
  rspec
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # buzz
2
2
 
3
+ [![Build Status](https://travis-ci.org/georgecodes/buzz.png?branch=master)](https://travis-ci.org/georgecodes/buzz)
4
+
3
5
  Buzz is a command-line interface into Spacewalk/RHN Satellite, written in Ruby. It will work with Ruby 1.8, which is the default Ruby on a lot of systems.
4
6
 
5
7
  ## Introduction
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.5
1
+ 0.1.0
data/bin/buzz CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  require 'buzz'
4
4
 
5
- Buzz.start(ARGV)
5
+ BuzzLoader.start(ARGV)
data/buzz CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  require './lib/buzz'
4
4
 
5
- Buzz.start(ARGV)
5
+ BuzzLoader.start(ARGV)
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "buzz"
8
- s.version = "0.0.5"
8
+ s.version = "0.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["George McIntosh"]
12
- s.date = "2013-04-22"
12
+ s.date = "2013-05-07"
13
13
  s.description = "A growing suite of tools for doing handy admin tasks etc with Spacewalk"
14
14
  s.email = "george@georgemcintosh.com"
15
15
  s.executables = ["buzz"]
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
19
19
  ]
20
20
  s.files = [
21
21
  ".document",
22
+ ".travis.yml",
22
23
  "Gemfile",
23
24
  "Gemfile.lock",
24
25
  "LICENSE.txt",
@@ -29,13 +30,26 @@ Gem::Specification.new do |s|
29
30
  "buzz",
30
31
  "buzz.gemspec",
31
32
  "conf/.buzz",
32
- "features/exit.feature",
33
- "features/help.feature",
34
- "features/step_definitions/terminal_steps.rb",
33
+ "features/channel_api.feature",
34
+ "features/fixtures/vcr_cassettes/delete_system.yml",
35
+ "features/fixtures/vcr_cassettes/list_systems.yml",
36
+ "features/fixtures/vcr_cassettes/list_systems_by_regex.yml",
37
+ "features/fixtures/vcr_cassettes/refresh_channel.yml",
38
+ "features/step_definitions/buzz_steps.rb",
39
+ "features/step_definitions/spacewalk_steps.rb",
35
40
  "features/support/env.rb",
41
+ "features/support/vcr.rb",
42
+ "features/system_api.feature",
36
43
  "lib/buzz.rb",
44
+ "lib/buzz/api_base.rb",
45
+ "lib/buzz/channel_api.rb",
46
+ "lib/buzz/system_api.rb",
47
+ "lib/buzz_api.rb",
48
+ "lib/buzz_main.rb",
37
49
  "lib/channel.rb",
50
+ "lib/sif.rb",
38
51
  "lib/system.rb",
52
+ "sample_config/complete.yaml",
39
53
  "spec/channel_spec.rb",
40
54
  "spec/spec_helper.rb",
41
55
  "test/helper.rb",
@@ -0,0 +1,16 @@
1
+ Feature: A set of API calls relating to Spacewalk channels
2
+ As a user of Spacewalk
3
+ In order to manage channels
4
+ I want to use the buzz API
5
+
6
+ Background: Use the "Channel" API
7
+ Given I have provided username "admin" password "admin" and server "spacewalk.elevenware.com"
8
+ And want to use the "Channel" API
9
+
10
+ Scenario: Refresh a channel
11
+ When I call the "refresh_channel" method with the arguments "my-awesome-channel" and the cassette "refresh_channel" is in place
12
+ Then the result contains:
13
+ """
14
+ 1
15
+ """
16
+
@@ -0,0 +1,85 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://spacewalk.elevenware.com/rpc/api
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ! '<?xml version="1.0" ?><methodCall><methodName>auth.login</methodName><params><param><value><string>admin</string></value></param><param><value><string>admin</string></value></param></params></methodCall>
9
+
10
+ '
11
+ headers:
12
+ user-agent:
13
+ - XMLRPC::Client (Ruby 1.9.3)
14
+ content-type:
15
+ - text/xml; charset=utf-8
16
+ content-length:
17
+ - '217'
18
+ connection:
19
+ - keep-alive
20
+ accept:
21
+ - ! '*/*'
22
+ response:
23
+ status:
24
+ code: 200
25
+ message: OK
26
+ headers:
27
+ date:
28
+ - Wed, 01 May 2013 11:32:42 GMT
29
+ content-type:
30
+ - text/xml;charset=ISO-8859-1
31
+ content-length:
32
+ - '175'
33
+ set-cookie:
34
+ - JSESSIONID=577FB4B22072EABD07B9F608B5D7CA8A; Path=/rhn
35
+ keep-alive:
36
+ - timeout=15, max=400
37
+ connection:
38
+ - Keep-Alive
39
+ body:
40
+ encoding: US-ASCII
41
+ string: <?xml version="1.0" encoding="UTF-8"?><methodResponse><params><param><value><string>1664321x77235c35e15b4c025afdcd959914a5c3</string></value></param></params></methodResponse>
42
+ http_version: '1.1'
43
+ recorded_at: Wed, 01 May 2013 11:32:45 GMT
44
+ - request:
45
+ method: post
46
+ uri: http://spacewalk.elevenware.com/rpc/api
47
+ body:
48
+ encoding: US-ASCII
49
+ string: ! '<?xml version="1.0" ?><methodCall><methodName>system.deleteSystems</methodName><params><param><value><string>1664321x77235c35e15b4c025afdcd959914a5c3</string></value></param><param><value><array><data><value><i4>1000021466</i4></value></data></array></value></param></params></methodCall>
50
+
51
+ '
52
+ headers:
53
+ user-agent:
54
+ - XMLRPC::Client (Ruby 1.9.3)
55
+ content-type:
56
+ - text/xml; charset=utf-8
57
+ content-length:
58
+ - '289'
59
+ connection:
60
+ - keep-alive
61
+ cookie:
62
+ - JSESSIONID=577FB4B22072EABD07B9F608B5D7CA8A
63
+ accept:
64
+ - ! '*/*'
65
+ response:
66
+ status:
67
+ code: 200
68
+ message: OK
69
+ headers:
70
+ date:
71
+ - Wed, 01 May 2013 11:32:42 GMT
72
+ content-type:
73
+ - text/xml;charset=ISO-8859-1
74
+ content-length:
75
+ - '128'
76
+ keep-alive:
77
+ - timeout=15, max=400
78
+ connection:
79
+ - Keep-Alive
80
+ body:
81
+ encoding: US-ASCII
82
+ string: <?xml version="1.0" encoding="UTF-8"?><methodResponse><params><param><value><i4>1</i4></value></param></params></methodResponse>
83
+ http_version: '1.1'
84
+ recorded_at: Wed, 01 May 2013 11:32:45 GMT
85
+ recorded_with: VCR 2.4.0
@@ -0,0 +1,177 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://spacewalk.elevenware.com/rpc/api
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ! '<?xml version="1.0" ?><methodCall><methodName>auth.login</methodName><params><param><value><string>admin</string></value></param><param><value><string>admin</string></value></param></params></methodCall>
9
+
10
+ '
11
+ headers:
12
+ user-agent:
13
+ - XMLRPC::Client (Ruby 1.9.3)
14
+ content-type:
15
+ - text/xml; charset=utf-8
16
+ content-length:
17
+ - '204'
18
+ connection:
19
+ - keep-alive
20
+ accept:
21
+ - ! '*/*'
22
+ response:
23
+ status:
24
+ code: 200
25
+ message: OK
26
+ headers:
27
+ date:
28
+ - Tue, 23 Apr 2013 01:14:39 GMT
29
+ content-type:
30
+ - text/xml
31
+ content-length:
32
+ - '171'
33
+ keep-alive:
34
+ - timeout=15, max=400
35
+ connection:
36
+ - Keep-Alive
37
+ body:
38
+ encoding: US-ASCII
39
+ string: <?xml version="1.0" encoding="UTF-8"?><methodResponse><params><param><value><string>291x4fced64491ef2c8e34032e797bb6c9bc</string></value></param></params></methodResponse>
40
+ http_version: '1.1'
41
+ recorded_at: Wed, 24 Apr 2013 09:05:10 GMT
42
+ - request:
43
+ method: post
44
+ uri: http://spacewalk.elevenware.com/rpc/api
45
+ body:
46
+ encoding: US-ASCII
47
+ string: ! '<?xml version="1.0" ?><methodCall><methodName>system.listSystems</methodName><params><param><value><string>291x4fced64491ef2c8e34032e797bb6c9bc</string></value></param></params></methodCall>
48
+
49
+ '
50
+ headers:
51
+ user-agent:
52
+ - XMLRPC::Client (Ruby 1.9.3)
53
+ content-type:
54
+ - text/xml; charset=utf-8
55
+ content-length:
56
+ - '191'
57
+ connection:
58
+ - keep-alive
59
+ accept:
60
+ - ! '*/*'
61
+ response:
62
+ status:
63
+ code: 200
64
+ message: OK
65
+ headers:
66
+ date:
67
+ - Tue, 23 Apr 2013 01:14:39 GMT
68
+ content-type:
69
+ - text/xml
70
+ content-length:
71
+ - '3752'
72
+ keep-alive:
73
+ - timeout=15, max=400
74
+ connection:
75
+ - Keep-Alive
76
+ body:
77
+ encoding: US-ASCII
78
+ string: ! '<?xml version="1.0" encoding="UTF-8"?><methodResponse><params><param><value><array><data><value><struct><member><name>id</name><value><i4>1000010010</i4></value></member>
79
+
80
+ <member><name>name</name><value><string>localhost.localdomain</string></value></member>
81
+
82
+ <member><name>last_checkin</name><value><dateTime.iso8601>20130423T01:11:36</dateTime.iso8601></value></member>
83
+
84
+ </struct>
85
+
86
+ </value><value><struct><member><name>id</name><value><i4>1000010011</i4></value></member>
87
+
88
+ <member><name>name</name><value><string>localhost.localdomain</string></value></member>
89
+
90
+ <member><name>last_checkin</name><value><dateTime.iso8601>20130423T01:11:39</dateTime.iso8601></value></member>
91
+
92
+ </struct>
93
+
94
+ </value><value><struct><member><name>id</name><value><i4>1000010012</i4></value></member>
95
+
96
+ <member><name>name</name><value><string>localhost.localdomain</string></value></member>
97
+
98
+ <member><name>last_checkin</name><value><dateTime.iso8601>20130423T01:11:42</dateTime.iso8601></value></member>
99
+
100
+ </struct>
101
+
102
+ </value><value><struct><member><name>id</name><value><i4>1000010013</i4></value></member>
103
+
104
+ <member><name>name</name><value><string>localhost.localdomain</string></value></member>
105
+
106
+ <member><name>last_checkin</name><value><dateTime.iso8601>20130423T01:11:44</dateTime.iso8601></value></member>
107
+
108
+ </struct>
109
+
110
+ </value><value><struct><member><name>id</name><value><i4>1000010014</i4></value></member>
111
+
112
+ <member><name>name</name><value><string>localhost.localdomain</string></value></member>
113
+
114
+ <member><name>last_checkin</name><value><dateTime.iso8601>20130423T01:11:46</dateTime.iso8601></value></member>
115
+
116
+ </struct>
117
+
118
+ </value><value><struct><member><name>id</name><value><i4>1000010015</i4></value></member>
119
+
120
+ <member><name>name</name><value><string>localhost.localdomain</string></value></member>
121
+
122
+ <member><name>last_checkin</name><value><dateTime.iso8601>20130423T01:11:48</dateTime.iso8601></value></member>
123
+
124
+ </struct>
125
+
126
+ </value><value><struct><member><name>id</name><value><i4>1000010016</i4></value></member>
127
+
128
+ <member><name>name</name><value><string>localhost.localdomain</string></value></member>
129
+
130
+ <member><name>last_checkin</name><value><dateTime.iso8601>20130423T01:11:50</dateTime.iso8601></value></member>
131
+
132
+ </struct>
133
+
134
+ </value><value><struct><member><name>id</name><value><i4>1000010017</i4></value></member>
135
+
136
+ <member><name>name</name><value><string>localhost.localdomain</string></value></member>
137
+
138
+ <member><name>last_checkin</name><value><dateTime.iso8601>20130423T01:11:51</dateTime.iso8601></value></member>
139
+
140
+ </struct>
141
+
142
+ </value><value><struct><member><name>id</name><value><i4>1000010018</i4></value></member>
143
+
144
+ <member><name>name</name><value><string>localhost.localdomain</string></value></member>
145
+
146
+ <member><name>last_checkin</name><value><dateTime.iso8601>20130423T01:11:53</dateTime.iso8601></value></member>
147
+
148
+ </struct>
149
+
150
+ </value><value><struct><member><name>id</name><value><i4>1000010019</i4></value></member>
151
+
152
+ <member><name>name</name><value><string>localhost.localdomain</string></value></member>
153
+
154
+ <member><name>last_checkin</name><value><dateTime.iso8601>20130423T01:11:55</dateTime.iso8601></value></member>
155
+
156
+ </struct>
157
+
158
+ </value><value><struct><member><name>id</name><value><i4>1000010001</i4></value></member>
159
+
160
+ <member><name>name</name><value><string>spacewalk.elevenware.com</string></value></member>
161
+
162
+ <member><name>last_checkin</name><value><dateTime.iso8601>20130317T21:25:39</dateTime.iso8601></value></member>
163
+
164
+ </struct>
165
+
166
+ </value><value><struct><member><name>id</name><value><i4>1000010002</i4></value></member>
167
+
168
+ <member><name>name</name><value><string>spacewalk.elevenware.com</string></value></member>
169
+
170
+ <member><name>last_checkin</name><value><dateTime.iso8601>20130420T16:04:37</dateTime.iso8601></value></member>
171
+
172
+ </struct>
173
+
174
+ </value></data></array></value></param></params></methodResponse>'
175
+ http_version: '1.1'
176
+ recorded_at: Wed, 24 Apr 2013 09:05:10 GMT
177
+ recorded_with: VCR 2.4.0
@@ -0,0 +1,117 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://spacewalk.elevenware.com/rpc/api
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ! '<?xml version="1.0" ?><methodCall><methodName>auth.login</methodName><params><param><value><string>admin</string></value></param><param><value><string>admin</string></value></param></params></methodCall>
9
+
10
+ '
11
+ headers:
12
+ user-agent:
13
+ - XMLRPC::Client (Ruby 1.9.3)
14
+ content-type:
15
+ - text/xml; charset=utf-8
16
+ content-length:
17
+ - '217'
18
+ connection:
19
+ - keep-alive
20
+ accept:
21
+ - ! '*/*'
22
+ response:
23
+ status:
24
+ code: 200
25
+ message: OK
26
+ headers:
27
+ date:
28
+ - Wed, 01 May 2013 13:14:55 GMT
29
+ content-type:
30
+ - text/xml;charset=ISO-8859-1
31
+ content-length:
32
+ - '175'
33
+ set-cookie:
34
+ - JSESSIONID=78C404894E5A8D8F249F1D905952D2F1; Path=/rhn
35
+ keep-alive:
36
+ - timeout=15, max=400
37
+ connection:
38
+ - Keep-Alive
39
+ body:
40
+ encoding: US-ASCII
41
+ string: <?xml version="1.0" encoding="UTF-8"?><methodResponse><params><param><value><string>1664343x4b4779ffcf1b0d827290fe801d6e2182</string></value></param></params></methodResponse>
42
+ http_version: '1.1'
43
+ recorded_at: Wed, 01 May 2013 13:14:56 GMT
44
+ - request:
45
+ method: post
46
+ uri: http://spacewalk.elevenware.com/rpc/api
47
+ body:
48
+ encoding: US-ASCII
49
+ string: ! '<?xml version="1.0" ?><methodCall><methodName>system.searchByName</methodName><params><param><value><string>1664343x4b4779ffcf1b0d827290fe801d6e2182</string></value></param><param><value><string>^store3</string></value></param></params></methodCall>
50
+
51
+ '
52
+ headers:
53
+ user-agent:
54
+ - XMLRPC::Client (Ruby 1.9.3)
55
+ content-type:
56
+ - text/xml; charset=utf-8
57
+ content-length:
58
+ - '250'
59
+ connection:
60
+ - keep-alive
61
+ cookie:
62
+ - JSESSIONID=78C404894E5A8D8F249F1D905952D2F1
63
+ accept:
64
+ - ! '*/*'
65
+ response:
66
+ status:
67
+ code: 200
68
+ message: OK
69
+ headers:
70
+ date:
71
+ - Wed, 01 May 2013 13:14:55 GMT
72
+ content-type:
73
+ - text/xml;charset=ISO-8859-1
74
+ content-length:
75
+ - '1374'
76
+ keep-alive:
77
+ - timeout=15, max=400
78
+ connection:
79
+ - Keep-Alive
80
+ body:
81
+ encoding: US-ASCII
82
+ string: ! '<?xml version="1.0" encoding="UTF-8"?><methodResponse><params><param><value><array><data><value><struct><member><name>id</name><value><i4>1000021430</i4></value></member>
83
+
84
+ <member><name>name</name><value><string>store3.eng.uk.specsavers.com</string></value></member>
85
+
86
+ <member><name>last_checkin</name><value><dateTime.iso8601>20130422T12:57:58</dateTime.iso8601></value></member>
87
+
88
+ </struct>
89
+
90
+ </value><value><struct><member><name>id</name><value><i4>1000021494</i4></value></member>
91
+
92
+ <member><name>name</name><value><string>store3.eng.uk.specsavers.com</string></value></member>
93
+
94
+ <member><name>last_checkin</name><value><dateTime.iso8601>20130424T13:15:09</dateTime.iso8601></value></member>
95
+
96
+ </struct>
97
+
98
+ </value><value><struct><member><name>id</name><value><i4>1000021418</i4></value></member>
99
+
100
+ <member><name>name</name><value><string>store3.eng.uk.specsavers.com</string></value></member>
101
+
102
+ <member><name>last_checkin</name><value><dateTime.iso8601>20130419T16:46:16</dateTime.iso8601></value></member>
103
+
104
+ </struct>
105
+
106
+ </value><value><struct><member><name>id</name><value><i4>1000021563</i4></value></member>
107
+
108
+ <member><name>name</name><value><string>store3.eng.uk.specsavers.com</string></value></member>
109
+
110
+ <member><name>last_checkin</name><value><dateTime.iso8601>20130501T12:59:36</dateTime.iso8601></value></member>
111
+
112
+ </struct>
113
+
114
+ </value></data></array></value></param></params></methodResponse>'
115
+ http_version: '1.1'
116
+ recorded_at: Wed, 01 May 2013 13:15:00 GMT
117
+ recorded_with: VCR 2.4.0
@@ -0,0 +1,85 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://spacewalk.elevenware.com/rpc/api
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ! '<?xml version="1.0" ?><methodCall><methodName>auth.login</methodName><params><param><value><string>admin</string></value></param><param><value><string>admin</string></value></param></params></methodCall>
9
+
10
+ '
11
+ headers:
12
+ user-agent:
13
+ - XMLRPC::Client (Ruby 1.9.3)
14
+ content-type:
15
+ - text/xml; charset=utf-8
16
+ content-length:
17
+ - '217'
18
+ connection:
19
+ - keep-alive
20
+ accept:
21
+ - ! '*/*'
22
+ response:
23
+ status:
24
+ code: 200
25
+ message: OK
26
+ headers:
27
+ date:
28
+ - Wed, 01 May 2013 14:53:54 GMT
29
+ content-type:
30
+ - text/xml;charset=ISO-8859-1
31
+ content-length:
32
+ - '175'
33
+ set-cookie:
34
+ - JSESSIONID=9265DFB1EC362ADB452377614A7364AD; Path=/rhn
35
+ keep-alive:
36
+ - timeout=15, max=400
37
+ connection:
38
+ - Keep-Alive
39
+ body:
40
+ encoding: US-ASCII
41
+ string: <?xml version="1.0" encoding="UTF-8"?><methodResponse><params><param><value><string>1665209xa54c21fd8581ddc7a326f9664944c323</string></value></param></params></methodResponse>
42
+ http_version: '1.1'
43
+ recorded_at: Wed, 01 May 2013 14:53:58 GMT
44
+ - request:
45
+ method: post
46
+ uri: http://spacewalk.elevenware.com/rpc/api
47
+ body:
48
+ encoding: US-ASCII
49
+ string: ! '<?xml version="1.0" ?><methodCall><methodName>channel.software.regenerateYumCache</methodName><params><param><value><string>1665209xa54c21fd8581ddc7a326f9664944c323</string></value></param><param><value><string>my-awesome-channel</string></value></param></params></methodCall>
50
+
51
+ '
52
+ headers:
53
+ user-agent:
54
+ - XMLRPC::Client (Ruby 1.9.3)
55
+ content-type:
56
+ - text/xml; charset=utf-8
57
+ content-length:
58
+ - '301'
59
+ connection:
60
+ - keep-alive
61
+ cookie:
62
+ - JSESSIONID=9265DFB1EC362ADB452377614A7364AD
63
+ accept:
64
+ - ! '*/*'
65
+ response:
66
+ status:
67
+ code: 200
68
+ message: OK
69
+ headers:
70
+ date:
71
+ - Wed, 01 May 2013 14:53:54 GMT
72
+ content-type:
73
+ - text/xml;charset=ISO-8859-1
74
+ content-length:
75
+ - '128'
76
+ keep-alive:
77
+ - timeout=15, max=400
78
+ connection:
79
+ - Keep-Alive
80
+ body:
81
+ encoding: US-ASCII
82
+ string: <?xml version="1.0" encoding="UTF-8"?><methodResponse><params><param><value><i4>1</i4></value></param></params></methodResponse>
83
+ http_version: '1.1'
84
+ recorded_at: Wed, 01 May 2013 14:53:58 GMT
85
+ recorded_with: VCR 2.4.0
@@ -0,0 +1,15 @@
1
+ Given /^I have buzz installed$/ do
2
+ add_to_lib_path(BUZZ_LIB_PATH)
3
+ end
4
+
5
+ Given(/^the config is "(.*?)"$/) do |config_file|
6
+ put_config_in_place config_file
7
+ end
8
+
9
+ When(/^the cassette "(.*?)" is in place$/) do |cassette_name|
10
+ VCR.use_cassette(cassette_name)
11
+ end
12
+
13
+ When(/^I run `([^`]*)` using the cassette "(.*?)"$/) do |command, cassette_name|
14
+ VCR.use_cassette(cassette_name) { run_simple(unescape(command), false) }
15
+ end
@@ -0,0 +1,30 @@
1
+ Given(/^I have provided username "(.*?)" password "(.*?)" and server "(.*?)"$/) do |username, password, server|
2
+ @username = username
3
+ @password = password
4
+ @server = server
5
+ end
6
+
7
+ Given(/^want to use the "(.*?)" API$/) do |api_name|
8
+ clazz = eval("Buzz::Api::#{api_name}")
9
+ @api = clazz.new(@server, @username, @password)
10
+ end
11
+
12
+ When(/^I call the "(.*?)" method and the cassette "(.*?)" is in place$/) do |method_name, cassette_name|
13
+ VCR.use_cassette(cassette_name) { @result = @api.send( method_name ) }
14
+ end
15
+
16
+ When(/^I call the "(.*?)" method with the arguments "(.*?)" and the cassette "(.*?)" is in place$/) do |method_name, args, cassette_name|
17
+ split_args = args.split(/ /)
18
+ args = split_args.length <= 1 ? args : split_args
19
+ VCR.use_cassette(cassette_name) { @result = @api.send( method_name, args ) }
20
+ end
21
+
22
+ Then(/^the result contains:$/) do |expected_result|
23
+ @result.to_s.should eq(expected_result)
24
+ end
25
+
26
+
27
+ Then(/^the result contains the array:$/) do |string|
28
+ expected_result = eval(string).to_json
29
+ @result.to_json.should eq(expected_result)
30
+ end
@@ -1,2 +1,37 @@
1
- require File.dirname(__FILE__) + '/../../lib/buzz'
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
2
2
  require 'aruba/cucumber'
3
+ require 'fileutils'
4
+ require 'rspec/expectations'
5
+ require 'buzz/system_api'
6
+ require 'buzz/channel_api'
7
+ require 'aruba/in_process'
8
+
9
+ BUZZ_LIB_PATH = File.expand_path(File.join(File.dirname(__FILE__),'..','..','lib'))
10
+
11
+ Before do
12
+ @aruba_timeout_seconds = 5
13
+ @original_path = ENV['PATH'].split(File::PATH_SEPARATOR)
14
+ @original_home = ENV['HOME']
15
+ new_home = "/tmp/fakehome"
16
+ FileUtils.rm_rf new_home
17
+ FileUtils.mkdir new_home
18
+ ENV['HOME'] = new_home
19
+ end
20
+
21
+ After do |scenario|
22
+ ENV['RUBYLIB'] = ''
23
+ ENV['PATH'] = @original_path.join(File::PATH_SEPARATOR)
24
+ ENV['HOME'] = @original_home
25
+ end
26
+
27
+ def put_config_in_place(config_file)
28
+ FileUtils.cp config_file, "#{ENV['HOME']}/.buzz"
29
+ end
30
+
31
+ def add_to_lib_path(path)
32
+ ENV["RUBYLIB"] = (String(ENV["RUBYLIB"]).split(File::PATH_SEPARATOR) + [path]).join(File::PATH_SEPARATOR)
33
+ end
34
+
35
+ def remove_from_lib_path(path)
36
+ ENV["RUBYLIB"] = (String(ENV["RUBYLIB"]).split(File::PATH_SEPARATOR) - [path]).join(File::PATH_SEPARATOR)
37
+ end
@@ -0,0 +1,18 @@
1
+ require 'vcr'
2
+
3
+ VCR.configure do |c|
4
+ # INFO: This is relative to the Rails.root
5
+ c.cassette_library_dir = 'features/fixtures/vcr_cassettes'
6
+ c.hook_into :fakeweb
7
+ c.ignore_localhost = true
8
+ c.default_cassette_options = { :record => :new_episodes }
9
+ end
10
+
11
+ #VCR.cucumber_tags do |t|
12
+ # t.tag '@tag1'
13
+ # t.tags '@tag2', '@tag3'
14
+
15
+ # t.tag '@tag3', :cassette => :options
16
+ # puts "OPTONS #{t}"
17
+ # t.tags '@tag4', '@tag5'
18
+ #end
@@ -0,0 +1,29 @@
1
+ Feature: A set of API calls relating to Spacewalk systems
2
+ As a user of Spacewalk
3
+ In order to manage registered systems
4
+ I want to use the buzz API
5
+
6
+ Background: I configure the library
7
+ Given I have provided username "admin" password "admin" and server "spacewalk.elevenware.com"
8
+ And want to use the "System" API
9
+
10
+ Scenario: Listing systems
11
+ When I call the "list" method and the cassette "list_systems" is in place
12
+ Then the result contains the array:
13
+ """
14
+ [{:id=>"1000010010", :name=>"localhost.localdomain", :last_checkin=>"Tue Apr 23 01:11:36 2013"}, {:id=>"1000010011", :name=>"localhost.localdomain", :last_checkin=>"Tue Apr 23 01:11:39 2013"}, {:id=>"1000010012", :name=>"localhost.localdomain", :last_checkin=>"Tue Apr 23 01:11:42 2013"}, {:id=>"1000010013", :name=>"localhost.localdomain", :last_checkin=>"Tue Apr 23 01:11:44 2013"}, {:id=>"1000010014", :name=>"localhost.localdomain", :last_checkin=>"Tue Apr 23 01:11:46 2013"}, {:id=>"1000010015", :name=>"localhost.localdomain", :last_checkin=>"Tue Apr 23 01:11:48 2013"}, {:id=>"1000010016", :name=>"localhost.localdomain", :last_checkin=>"Tue Apr 23 01:11:50 2013"}, {:id=>"1000010017", :name=>"localhost.localdomain", :last_checkin=>"Tue Apr 23 01:11:51 2013"}, {:id=>"1000010018", :name=>"localhost.localdomain", :last_checkin=>"Tue Apr 23 01:11:53 2013"}, {:id=>"1000010019", :name=>"localhost.localdomain", :last_checkin=>"Tue Apr 23 01:11:55 2013"}, {:id=>"1000010001", :name=>"spacewalk.elevenware.com", :last_checkin=>"Sun Mar 17 21:25:39 2013"}, {:id=>"1000010002", :name=>"spacewalk.elevenware.com", :last_checkin=>"Sat Apr 20 16:04:37 2013"}]
15
+ """
16
+
17
+ Scenario: Deleting a system by ID
18
+ When I call the "delete_systems" method with the arguments "1000021466" and the cassette "delete_system" is in place
19
+ Then the result contains:
20
+ """
21
+ 1
22
+ """
23
+
24
+ Scenario: Listing systems by regex
25
+ When I call the "list_by_regex" method with the arguments "^store3" and the cassette "list_systems_by_regex" is in place
26
+ Then the result contains the array:
27
+ """
28
+ [{:id=>"1000021430", :name=>"store3.eng.uk.specsavers.com", :last_checkin=>"Mon Apr 22 12:57:58 2013"}, {:id=>"1000021494", :name=>"store3.eng.uk.specsavers.com", :last_checkin=>"Wed Apr 24 13:15:09 2013"}, {:id=>"1000021418", :name=>"store3.eng.uk.specsavers.com", :last_checkin=>"Fri Apr 19 16:46:16 2013"}, {:id=>"1000021563", :name=>"store3.eng.uk.specsavers.com", :last_checkin=>"Wed May 1 12:59:36 2013"}]
29
+ """
@@ -4,11 +4,12 @@ require 'thor'
4
4
  require 'extensions/kernel' unless Kernel.respond_to? 'require_relative'
5
5
  require_relative 'channel'
6
6
  require_relative 'system'
7
- require 'sif'
7
+ require_relative 'sif'
8
8
 
9
- class Buzz < Sif::Loader
9
+ class BuzzLoader < Sif::Loader
10
10
 
11
11
  config_file '.buzz'
12
+ gem_name 'buzz'
12
13
 
13
14
  class_option :host, :aliases => ['-h']
14
15
  class_option :username, :aliases => ['-u']
@@ -26,3 +27,4 @@ class Buzz < Sif::Loader
26
27
  x.instance_variable_set "@password", x.options[:password] unless x.options[:password].nil?
27
28
  end
28
29
  end
30
+
@@ -0,0 +1,46 @@
1
+ require "xmlrpc/client"
2
+ require 'extensions/kernel' unless Kernel.respond_to? 'require_relative'
3
+
4
+ module Buzz
5
+ module Api
6
+ class ApiBase
7
+
8
+ def initialize(server, username, password)
9
+ @server = server
10
+ @username = username
11
+ @password = password
12
+ @spacewalk = XMLRPC::Client.new(@server, "/rpc/api", 80)
13
+ end
14
+
15
+ def get_key
16
+ @key = @spacewalk.call("auth.login", @username, @password) unless @key
17
+ @key
18
+ end
19
+
20
+ def make_call(method_name, *args)
21
+
22
+ begin
23
+ if ( args.length == 0 )
24
+
25
+ response = @spacewalk.call(method_name,
26
+ get_key
27
+ )
28
+ else
29
+ args.unshift(get_key)
30
+
31
+ response = @spacewalk.call(method_name,
32
+
33
+ *args
34
+ )
35
+ end
36
+ response
37
+ rescue XMLRPC::FaultException => e
38
+ puts "Error:"
39
+ puts e.faultCode
40
+ puts e.faultString
41
+ end
42
+ end
43
+
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,21 @@
1
+ require 'rexml/document'
2
+ require 'rexml/xpath'
3
+ require 'extensions/kernel' unless Kernel.respond_to? 'require_relative'
4
+ require 'buzz/api_base'
5
+
6
+ module Buzz
7
+ module Api
8
+ class Channel < ApiBase
9
+
10
+ def initialize(server, username, password)
11
+ super(server, username, password)
12
+ end
13
+
14
+ def refresh_channel(channel_label)
15
+ out = make_call("channel.software.regenerateYumCache", channel_label)
16
+ out
17
+ end
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,45 @@
1
+ require 'rexml/document'
2
+ require 'rexml/xpath'
3
+ require 'extensions/kernel' unless Kernel.respond_to? 'require_relative'
4
+ require 'buzz/api_base'
5
+
6
+ module Buzz
7
+ module Api
8
+ class System < ApiBase
9
+
10
+ def initialize(server, username, password)
11
+ super(server, username, password)
12
+ end
13
+
14
+ def list
15
+ response = make_call("system.listSystems")
16
+ parse_system_list(response)
17
+ end
18
+
19
+ def list_by_regex(regex)
20
+ response = make_call("system.searchByName", regex)
21
+ parse_system_list(response)
22
+
23
+ end
24
+
25
+ def delete_systems(system_ids)
26
+ system_ids = system_ids.respond_to?('collect') ? system_ids.collect { |id| id.to_i} : system_ids.to_i
27
+ out = make_call("system.deleteSystems", system_ids)
28
+ out
29
+ end
30
+
31
+ private
32
+ def parse_system_list(response)
33
+ systems = []
34
+ response.each do |system|
35
+ id = system['id']
36
+ name = system['name']
37
+ last_checkin = system['last_checkin'].to_time.ctime
38
+ systems << { :id => "#{id}", :name => "#{name}", :last_checkin => "#{last_checkin}" }
39
+ end
40
+ systems
41
+ end
42
+
43
+ end
44
+ end
45
+ end
File without changes
@@ -0,0 +1,14 @@
1
+ require_relative 'buzz'
2
+
3
+ class BuzzMain
4
+ def initialize(argv, stdin=STDIN, stdout=STDOUT, stderr=STDERR, kernel=Kernel)
5
+ @argv, @stdin, @stdout, @stderr, @kernel = argv, stdin, stdout, stderr, kernel
6
+ end
7
+
8
+ def execute!
9
+ # your code here, assign a value to exitstatus
10
+ Buzz.start @argv
11
+ puts "SHIT #{@argv}"
12
+ @kernel.exit(0)
13
+ end
14
+ end
@@ -2,27 +2,19 @@
2
2
  require 'sif'
3
3
 
4
4
  require "xmlrpc/client"
5
+ require 'extensions/kernel' unless Kernel.respond_to? 'require_relative'
6
+ require 'buzz/channel_api'
5
7
 
6
8
  class Channel < Sif::Loader
7
9
 
8
- desc "Regenerate YUM cache", "This call allows you to force the re-generation of the YUM cache for the specified channel"
10
+ desc "refresh CHANNEL_LABEL", "This call allows you to force the re-generation of the YUM cache for the specified channel"
9
11
  def refresh(channel_label)
10
- server = XMLRPC::Client.new(@spacewalk_server, "/rpc/api", 80)
12
+
11
13
  puts "Regenerating YUM cache for #{channel_label}"
12
-
13
- begin
14
- key = server.call("auth.login", @username, @password)
15
- puts "Using session key #{key}"
16
- out = server.call("channel.software.regenerateYumCache",
17
- key,
18
- channel_label
19
- )
20
- puts out
21
- rescue XMLRPC::FaultException => e
22
- puts "Error:"
23
- puts e.faultCode
24
- puts e.faultString
25
- end
14
+ channel_api = Buzz::Api::Channel.new(@spacewalk_server, @username, @password)
15
+ response = channel_api.refresh_channel(channel_label)
16
+ puts "RES #{response}"
17
+
26
18
  end
27
19
 
28
20
  option :name, :aliases => ['-n']
@@ -30,7 +22,7 @@ class Channel < Sif::Loader
30
22
  option :arch, :aliases => ['-a']
31
23
  option :parent, :default => '', :aliases => ['-p']
32
24
  option :checksum, :default => 'sha256'
33
- desc "Create channel", "Creates a new channel"
25
+ desc "create CHANNELNAME [options]", "Creates a new channel"
34
26
  def create(channel_label)
35
27
  server = XMLRPC::Client.new(@spacewalk_server, "/rpc/api", 80)
36
28
  puts "Creating #{channel_label}"
@@ -0,0 +1,63 @@
1
+ require 'thor'
2
+ require 'yaml'
3
+
4
+ module Sif
5
+ class Loader < Thor
6
+
7
+ def initialize(args=[], options={}, config={})
8
+ super
9
+ if (options[0] == '--version')
10
+ version = Gem.loaded_specs[@@gem_name].version
11
+ rel_date = Gem.loaded_specs[@@gem_name].date.strftime("%A %d %B %Y")
12
+ puts "#{@@gem_name } version #{version} (released #{rel_date})"
13
+ exit 0
14
+ end
15
+ load_configuration
16
+ end
17
+
18
+ class_option :version
19
+
20
+ class_option :config, :aliases => ['-c']
21
+ @@config_file = '.config'
22
+
23
+ @@post_config = nil
24
+
25
+ no_tasks do
26
+ def load_configuration
27
+
28
+ config_file = options[:config] || "#{ENV['HOME']}/#{@@config_file}"
29
+
30
+ if (!File.exists?(config_file) )
31
+ puts "Unable to find config file #{config_file} - can't continue"
32
+ exit
33
+ end
34
+
35
+ config = YAML::load_file config_file
36
+
37
+ config.each do |k,v|
38
+ instance_variable_set "@#{k}",v
39
+ end
40
+
41
+ if ( @@post_config )
42
+ @@post_config.call self
43
+ end
44
+
45
+ end
46
+
47
+ def self.gem_name(gem_name)
48
+ @@gem_name = gem_name
49
+ end
50
+
51
+ def self.config_file(filename)
52
+ @@config_file = filename
53
+ end
54
+
55
+ def self.further_config(&block)
56
+ @@post_config = block
57
+ end
58
+
59
+
60
+ end
61
+
62
+ end
63
+ end
@@ -3,10 +3,12 @@ require 'sif'
3
3
  require 'rexml/document'
4
4
  require 'rexml/xpath'
5
5
  require "xmlrpc/client"
6
+ require 'extensions/kernel' unless Kernel.respond_to? 'require_relative'
7
+ require 'buzz/system_api'
6
8
 
7
9
  class System < Sif::Loader
8
10
 
9
- desc "Delete self", "Delete this system from Spacewalk"
11
+ desc "deleteself", "Delete this system from Spacewalk"
10
12
  def deleteself
11
13
  server = XMLRPC::Client.new(@spacewalk_server, "/rpc/api", 80)
12
14
  systemid_file_path = '/etc/sysconfig/rhn/systemid'
@@ -23,11 +25,13 @@ class System < Sif::Loader
23
25
 
24
26
  end
25
27
 
26
- desc "Delete specific machine", "Delete the specified system from Spacewalk"
27
- def delete(systemid)
28
+ desc "delete SYSTEM_ID", "Delete the specified system from Spacewalk"
29
+ def delete(*systemid)
28
30
 
29
31
  puts "Delete this system from spacewalk - ID #{systemid}"
30
- delete_systems [systemid.to_i]
32
+ system_api = Buzz::Api::System.new(@spacewalk_server, @username, @password)
33
+ response = system_api.delete_systems(systemid)
34
+ puts "RESP #{response}"
31
35
 
32
36
  end
33
37
 
@@ -37,7 +41,7 @@ class System < Sif::Loader
37
41
  puts "HOST #{@spacewalk_server} #{parent_options} #{@lol}"
38
42
  end
39
43
 
40
- desc "List systems", "List all subscribed systems"
44
+ desc "list", "List all subscribed systems"
41
45
  def list
42
46
  server = XMLRPC::Client.new(@spacewalk_server, "/rpc/api", 80)
43
47
  begin
@@ -47,6 +51,7 @@ class System < Sif::Loader
47
51
  key
48
52
  )
49
53
  systems = []
54
+ puts "REP #{response}"
50
55
  response.each do |system|
51
56
  id = system['id']
52
57
  name = system['name']
@@ -60,20 +65,20 @@ class System < Sif::Loader
60
65
  end
61
66
  end
62
67
 
63
- desc "List by regex", "list"
68
+ desc "list_by_regex", "list"
64
69
  def list_by_regex(regex)
65
70
 
66
71
  systems = find_systems_by_regex(regex)
67
72
  systems.each do |system|
68
73
  id = system['id']
69
74
  name = system['name']
70
- last_checkin = system['last_checkin'].to_time
75
+ last_checkin = system['last_checkin'].to_time.ctime
71
76
  puts "System: ID: #{id} name: #{name} last checked in: #{last_checkin}"
72
77
  end
73
78
 
74
79
  end
75
80
 
76
- desc "Delete by regex", "Delete all systems whose name matches the regex supplied"
81
+ desc "delete_by_regex", "Delete all systems whose name matches the regex supplied"
77
82
  def delete_by_regex(regex)
78
83
  systems_to_delete = find_systems_by_regex regex
79
84
  system_ids = systems_to_delete.collect { |system| system['id']}
@@ -122,4 +127,4 @@ class System < Sif::Loader
122
127
 
123
128
  end
124
129
 
125
- end
130
+ end
@@ -0,0 +1,3 @@
1
+ spacewalk_server: spacewalk.elevenware.com
2
+ username : admin
3
+ password : admin
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
- require 'buzz'
2
+ require 'buzz_api'
3
3
 
4
4
  describe Channel do
5
5
  describe "#create" do
@@ -1,16 +1 @@
1
- $0 = "buzz"
2
- ARGV.clear
3
-
4
- def capture(stream)
5
- begin
6
- stream = stream.to_s
7
- eval "$#{stream} = StringIO.new"
8
- yield
9
- result = eval("$#{stream}").string
10
- ensure
11
- eval("$#{stream} = $#{stream.upcase}")
12
- end
13
-
14
- result
15
- end
16
-
1
+ require 'vcr'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: buzz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-22 00:00:00.000000000 Z
12
+ date: 2013-05-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: webmock
@@ -149,6 +149,7 @@ extra_rdoc_files:
149
149
  - README.md
150
150
  files:
151
151
  - .document
152
+ - .travis.yml
152
153
  - Gemfile
153
154
  - Gemfile.lock
154
155
  - LICENSE.txt
@@ -159,13 +160,26 @@ files:
159
160
  - buzz
160
161
  - buzz.gemspec
161
162
  - conf/.buzz
162
- - features/exit.feature
163
- - features/help.feature
164
- - features/step_definitions/terminal_steps.rb
163
+ - features/channel_api.feature
164
+ - features/fixtures/vcr_cassettes/delete_system.yml
165
+ - features/fixtures/vcr_cassettes/list_systems.yml
166
+ - features/fixtures/vcr_cassettes/list_systems_by_regex.yml
167
+ - features/fixtures/vcr_cassettes/refresh_channel.yml
168
+ - features/step_definitions/buzz_steps.rb
169
+ - features/step_definitions/spacewalk_steps.rb
165
170
  - features/support/env.rb
171
+ - features/support/vcr.rb
172
+ - features/system_api.feature
166
173
  - lib/buzz.rb
174
+ - lib/buzz/api_base.rb
175
+ - lib/buzz/channel_api.rb
176
+ - lib/buzz/system_api.rb
177
+ - lib/buzz_api.rb
178
+ - lib/buzz_main.rb
167
179
  - lib/channel.rb
180
+ - lib/sif.rb
168
181
  - lib/system.rb
182
+ - sample_config/complete.yaml
169
183
  - spec/channel_spec.rb
170
184
  - spec/spec_helper.rb
171
185
  - test/helper.rb
@@ -185,7 +199,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
185
199
  version: '0'
186
200
  segments:
187
201
  - 0
188
- hash: 4403716605840679846
202
+ hash: -244473495629815018
189
203
  required_rubygems_version: !ruby/object:Gem::Requirement
190
204
  none: false
191
205
  requirements:
@@ -1,13 +0,0 @@
1
- Feature: exit statuses
2
-
3
- In order to specify expected exit statuws
4
- As a developer using Cucumber
5
- I want to use the "the exit status should be" step
6
-
7
- Scenario: exit status of 0
8
- When I run "ruby -h"
9
- Then the exit status should be 0
10
-
11
- Scenario: non-zero exit status
12
- When I run "ruby -e 'exit 55'"
13
- Then the exit status should be 55
@@ -1,18 +0,0 @@
1
- Feature: Get help
2
-
3
-
4
- Scenario: Help
5
- Given I provide no options
6
- Then I should see
7
- """
8
- Commands:
9
- buzz channel # Manipulate Spacewalk channels
10
- buzz help [COMMAND] # Describe available commands or one specific command
11
- buzz system # Manipulate Spacewalk systems
12
-
13
- Options:
14
- -c, [--config=CONFIG]
15
- -h, [--host=HOST]
16
- -u, [--username=USERNAME]
17
- -p, [--password=PASSWORD]
18
- """
@@ -1,16 +0,0 @@
1
- Given /^I start the app with "([^\"]*)"$/ do |command|
2
- @io = StringIO.new
3
- @app = Buzz.start(command.split(/\s+/), @io)
4
- end
5
-
6
- Given(/^I provide no options$/) do
7
- @app = Buzz.start([])
8
- end
9
-
10
- Then(/^I should see$/) do |string|
11
- pending # express the regexp above with the code you wish you had
12
- end
13
-
14
- Then /^the exit status should be (\d+)$/ do |exit_status|
15
- @last_exit_status.should == exit_status.to_i
16
- end