rhn_satellite 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +1 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +30 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +94 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/lib/rhn_satellite.rb +25 -0
- data/lib/rhn_satellite/activation_key.rb +5 -0
- data/lib/rhn_satellite/api.rb +36 -0
- data/lib/rhn_satellite/channel.rb +5 -0
- data/lib/rhn_satellite/channel_access.rb +20 -0
- data/lib/rhn_satellite/channel_software.rb +20 -0
- data/lib/rhn_satellite/common/collection.rb +15 -0
- data/lib/rhn_satellite/common/debug.rb +35 -0
- data/lib/rhn_satellite/common/misc.rb +24 -0
- data/lib/rhn_satellite/connection/base.rb +25 -0
- data/lib/rhn_satellite/connection/handler.rb +116 -0
- data/lib/rhn_satellite/package.rb +15 -0
- data/lib/rhn_satellite/system.rb +83 -0
- data/lib/rhn_satellite/systemgroup.rb +34 -0
- data/rhn_satellite.gemspec +87 -0
- data/spec/spec.opts +6 -0
- data/spec/spec_helper.rb +12 -0
- data/spec/unit/rhn_satellite/activation_key_spec.rb +58 -0
- data/spec/unit/rhn_satellite/api_spec.rb +94 -0
- data/spec/unit/rhn_satellite/channel_access_spec.rb +61 -0
- data/spec/unit/rhn_satellite/channel_software_spec.rb +65 -0
- data/spec/unit/rhn_satellite/channel_spec.rb +58 -0
- data/spec/unit/rhn_satellite/common/debug_spec.rb +42 -0
- data/spec/unit/rhn_satellite/common/misc_spec.rb +33 -0
- data/spec/unit/rhn_satellite/connection/base_spec.rb +44 -0
- data/spec/unit/rhn_satellite/connection/handler_spec.rb +229 -0
- data/spec/unit/rhn_satellite/package_spec.rb +52 -0
- data/spec/unit/rhn_satellite/system_spec.rb +320 -0
- data/spec/unit/rhn_satellite/systemgroup_spec.rb +127 -0
- metadata +180 -0
@@ -0,0 +1,52 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
3
|
+
|
4
|
+
describe RhnSatellite::Package do
|
5
|
+
before(:each) do
|
6
|
+
RhnSatellite::Package.reset
|
7
|
+
conn = Object.new
|
8
|
+
conn.stubs(:call)
|
9
|
+
|
10
|
+
XMLRPC::Client.stubs(:new2).returns(conn)
|
11
|
+
|
12
|
+
RhnSatellite::Package.username = 'user'
|
13
|
+
RhnSatellite::Package.password = 'pwd'
|
14
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with("auth.login",'user','pwd').returns("token")
|
15
|
+
end
|
16
|
+
|
17
|
+
describe ".details" do
|
18
|
+
before(:each) do
|
19
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with("auth.logout",'token')
|
20
|
+
end
|
21
|
+
it "should return details" do
|
22
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with("package.getDetails",'token',1).returns({"name" => 'foo'})
|
23
|
+
|
24
|
+
RhnSatellite::Package.details(1).should eql({"name" => 'foo'})
|
25
|
+
end
|
26
|
+
it "should convert the id" do
|
27
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with("package.getDetails",'token',1).returns({"name" => 'foo'})
|
28
|
+
|
29
|
+
RhnSatellite::Package.details('1').should eql({"name" => 'foo'})
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe ".exists?" do
|
34
|
+
it "should return true if we get a result" do
|
35
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with("auth.logout",'token')
|
36
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with("package.getDetails",'token',1).returns({"name" => 'foo'})
|
37
|
+
|
38
|
+
RhnSatellite::Package.exists?(1).should be_true
|
39
|
+
end
|
40
|
+
it "should return false if we don't get a result" do
|
41
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with("auth.logout",'token')
|
42
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with("package.getDetails",'token',1).returns(nil)
|
43
|
+
|
44
|
+
RhnSatellite::Package.exists?(1).should be_false
|
45
|
+
end
|
46
|
+
it "should return false if am exception is raised" do
|
47
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with("package.getDetails",'token',1).raises(XMLRPC::FaultException.new(500,"blub"))
|
48
|
+
|
49
|
+
RhnSatellite::Package.exists?(1).should be_false
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,320 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
3
|
+
|
4
|
+
describe RhnSatellite::System do
|
5
|
+
context "standard invocation" do
|
6
|
+
before(:each) do
|
7
|
+
RhnSatellite::Systemgroup.reset
|
8
|
+
conn = Object.new
|
9
|
+
conn.stubs(:call)
|
10
|
+
|
11
|
+
XMLRPC::Client.stubs(:new2).returns(conn)
|
12
|
+
|
13
|
+
RhnSatellite::System.username = 'user'
|
14
|
+
RhnSatellite::System.password = 'pwd'
|
15
|
+
RhnSatellite::Connection::Handler.any_instance.stubs(:make_call).with("auth.login",'user','pwd').returns("token")
|
16
|
+
RhnSatellite::Connection::Handler.any_instance.stubs(:make_call).with("auth.logout",'token')
|
17
|
+
end
|
18
|
+
|
19
|
+
describe ".all" do
|
20
|
+
it "logins and returns a bunch of systems" do
|
21
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with('system.listUserSystems',"token").returns(["123","234"])
|
22
|
+
|
23
|
+
RhnSatellite::System.all.should eql(["123","234"])
|
24
|
+
end
|
25
|
+
|
26
|
+
it "returns an empty array on an empty answer" do
|
27
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with('system.listUserSystems',"token").returns(nil)
|
28
|
+
|
29
|
+
RhnSatellite::System.all.should eql([])
|
30
|
+
end
|
31
|
+
|
32
|
+
it "iterates the items over the block" do
|
33
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with('system.listUserSystems',"token").returns(["123","234"])
|
34
|
+
RhnSatellite::System.all{|i| ["123","234"].include?(i).should be_true }.should eql(["123","234"])
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe ".get" do
|
39
|
+
context "with systems" do
|
40
|
+
before :each do
|
41
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with('system.listUserSystems',"token").returns([{'name' => "123"},{'name' => "234"}])
|
42
|
+
end
|
43
|
+
it "finds a system in all systems" do
|
44
|
+
RhnSatellite::System.get('123').should eql({'name' => '123'})
|
45
|
+
end
|
46
|
+
|
47
|
+
it "returns nil on an non-existant system" do
|
48
|
+
RhnSatellite::System.get('12333').should eql(nil)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
context "without any systems" do
|
52
|
+
before :each do
|
53
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with('system.listUserSystems',"token").returns([])
|
54
|
+
end
|
55
|
+
it "returns nil" do
|
56
|
+
RhnSatellite::System.get('12333').should eql(nil)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe ".relevant_erratas" do
|
62
|
+
it "logins and returns a bunch of activation keys" do
|
63
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with('system.getRelevantErrata',"token","1").returns(["errata1","errata2"])
|
64
|
+
|
65
|
+
RhnSatellite::System.relevant_erratas("1").should eql(["errata1","errata2"])
|
66
|
+
end
|
67
|
+
|
68
|
+
it "returns an empty array on an empty answer" do
|
69
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with('system.getRelevantErrata',"token","1").returns(nil)
|
70
|
+
|
71
|
+
RhnSatellite::System.relevant_erratas("1").should eql([])
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe ".latest_installable_packages" do
|
76
|
+
it "logins and returns a bunch of packages" do
|
77
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with('system.listLatestInstallablePackages',"token","1").returns(["package1","package2"])
|
78
|
+
|
79
|
+
RhnSatellite::System.latest_installable_packages("1").should eql(["package1","package2"])
|
80
|
+
end
|
81
|
+
|
82
|
+
it "returns an empty array on an empty answer" do
|
83
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with('system.listLatestInstallablePackages',"token","1").returns(nil)
|
84
|
+
|
85
|
+
RhnSatellite::System.latest_installable_packages("1").should eql([])
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe ".latest_available_packages" do
|
90
|
+
it "logins and returns a bunch of packages per system" do
|
91
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with('system.listLatestAvailablePackages',"token",["1",'2']).returns([['sys1','sysname1',"package1","package2"], ['sys2','sysname2','package3']])
|
92
|
+
|
93
|
+
RhnSatellite::System.latest_available_packages(["1",'2']).should eql([['sys1','sysname1',"package1","package2"], ['sys2','sysname2','package3']])
|
94
|
+
end
|
95
|
+
|
96
|
+
it "returns an empty array on an empty answer" do
|
97
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with('system.listLatestAvailablePackages',"token",["1",'2']).returns(nil)
|
98
|
+
|
99
|
+
RhnSatellite::System.latest_available_packages(["1",'2']).should eql([])
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
describe ".latest_upgradable_packages" do
|
104
|
+
it "logins and returns a bunch of packages" do
|
105
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with('system.listLatestUpgradablePackages',"token","1").returns(["package1","package2"])
|
106
|
+
|
107
|
+
RhnSatellite::System.latest_upgradable_packages("1").should eql(["package1","package2"])
|
108
|
+
end
|
109
|
+
|
110
|
+
it "returns an empty array on an empty answer" do
|
111
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with('system.listLatestUpgradablePackages',"token","1").returns(nil)
|
112
|
+
|
113
|
+
RhnSatellite::System.latest_upgradable_packages("1").should eql([])
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe ".uptodate?" do
|
118
|
+
it "returns true if no packages are upgradeable and no erratas are available" do
|
119
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with('system.getRelevantErrata',"token","1").returns(nil)
|
120
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with('system.listLatestUpgradablePackages',"token","1").returns(nil)
|
121
|
+
|
122
|
+
RhnSatellite::System.uptodate?("1").should eql(true)
|
123
|
+
end
|
124
|
+
|
125
|
+
it "returns false if packages are upgradeable" do
|
126
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with('system.listLatestUpgradablePackages',"token","1").returns(['package2'])
|
127
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with('system.getRelevantErrata',"token","1").never
|
128
|
+
|
129
|
+
RhnSatellite::System.uptodate?("1").should eql(false)
|
130
|
+
end
|
131
|
+
|
132
|
+
it "returns false if erratas are available" do
|
133
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with('system.getRelevantErrata',"token","1").returns(["errata2"])
|
134
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with('system.listLatestUpgradablePackages',"token","1").returns(nil)
|
135
|
+
|
136
|
+
RhnSatellite::System.uptodate?("1").should eql(false)
|
137
|
+
end
|
138
|
+
|
139
|
+
it "returns false if erratas and packages are available" do
|
140
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with('system.getRelevantErrata',"token","1").never
|
141
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with('system.listLatestUpgradablePackages',"token","1").returns(['package2'])
|
142
|
+
|
143
|
+
RhnSatellite::System.uptodate?("1").should eql(false)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
describe ".active_systems" do
|
148
|
+
it "logins and returns a bunch of activation keys" do
|
149
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with('system.listActiveSystems',"token").returns(["123","234"])
|
150
|
+
|
151
|
+
RhnSatellite::System.active_systems.should eql(["123","234"])
|
152
|
+
end
|
153
|
+
|
154
|
+
it "returns an empty array on an empty answer" do
|
155
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with('system.listActiveSystems',"token").returns(nil)
|
156
|
+
|
157
|
+
RhnSatellite::System.active_systems.should eql([])
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
describe ".active?" do
|
162
|
+
it "returns true if system is list of active systems" do
|
163
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with('system.listActiveSystems',"token").returns([{'name' => "123"},{'name' => "234"}])
|
164
|
+
|
165
|
+
RhnSatellite::System.active?("123").should eql(true)
|
166
|
+
end
|
167
|
+
|
168
|
+
it "returns false if not in list" do
|
169
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with('system.listActiveSystems',"token").returns([{'name' => "123"},{'name' => "234"}])
|
170
|
+
|
171
|
+
RhnSatellite::System.active?("1233").should eql(false)
|
172
|
+
end
|
173
|
+
it "returns false if list is empty" do
|
174
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with('system.listActiveSystems',"token").returns(nil)
|
175
|
+
|
176
|
+
RhnSatellite::System.active?("1233").should eql(false)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
describe ".detail" do
|
181
|
+
it "logins and returns details of a system" do
|
182
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with('system.getDetails',"token",1).returns("foo")
|
183
|
+
|
184
|
+
RhnSatellite::System.details('1').should eql("foo")
|
185
|
+
end
|
186
|
+
|
187
|
+
it "returns nothing on an inexistant system" do
|
188
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with('system.getDetails',"token",1).returns(nil)
|
189
|
+
|
190
|
+
RhnSatellite::System.details("1").should eql(nil)
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
describe ".online?" do
|
195
|
+
it "should return true if the system is in the satellite and listed as active" do
|
196
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with('system.listUserSystems',"token").returns([{'name' => "123", 'id' => "1"},{'name' => "234", "id" => "2"}])
|
197
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with('system.getDetails',"token",1).returns({"osa_status" => 'online'})
|
198
|
+
|
199
|
+
RhnSatellite::System.online?('123').should be_true
|
200
|
+
end
|
201
|
+
|
202
|
+
it "should return false if the system is not active" do
|
203
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with('system.listUserSystems',"token").returns([{'name' => "123", 'id' => "1"},{'name' => "234", "id" => "2"}])
|
204
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with('system.getDetails',"token",1).returns({"osa_status" => 'offline'})
|
205
|
+
|
206
|
+
RhnSatellite::System.online?('123').should be_false
|
207
|
+
end
|
208
|
+
|
209
|
+
it "should return false if the system is not in the satellite" do
|
210
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with('system.listUserSystems',"token").returns([{'name' => "123", 'id' => "1"},{'name' => "234", "id" => "2"}])
|
211
|
+
RhnSatellite::System.online?('333123').should be_false
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
describe ".set_base_channel" do
|
216
|
+
it "should set the base channel" do
|
217
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with('system.setBaseChannel','token',1,'channel').returns(1)
|
218
|
+
|
219
|
+
RhnSatellite::System.set_base_channel('1','channel').should eql(1)
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
describe ".subscribed_base_channel" do
|
224
|
+
it "should get the subscribed base channel" do
|
225
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with('system.getSubscribedBaseChannel','token',1).returns({ 'label' => 'some_channel' })
|
226
|
+
|
227
|
+
RhnSatellite::System.subscribed_base_channel('1').should eql({ 'label' => 'some_channel' })
|
228
|
+
end
|
229
|
+
end
|
230
|
+
describe ".subscribable_base_channels" do
|
231
|
+
it "should get the subscribable base channels" do
|
232
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with('system.listSubscribableBaseChannels','token',1).returns([{ 'label' => 'some_channel' }])
|
233
|
+
|
234
|
+
RhnSatellite::System.subscribable_base_channels('1').should eql([{ 'label' => 'some_channel' }])
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
describe ".set_child_channels" do
|
239
|
+
it "should set the child channels" do
|
240
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with('system.setChildChannels','token',1,['channel1','channel2']).returns(1)
|
241
|
+
|
242
|
+
RhnSatellite::System.set_child_channels('1',['channel1','channel2']).should eql(1)
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
describe ".subscribed_child_channels" do
|
247
|
+
it "lists all the subscribed child channels" do
|
248
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with('system.listSubscribedChildChannels','token',1).returns([{ 'label' => 'some_child_channel' }])
|
249
|
+
|
250
|
+
RhnSatellite::System.subscribed_child_channels('1').should eql([{ 'label' => 'some_child_channel' }])
|
251
|
+
end
|
252
|
+
end
|
253
|
+
describe ".subscribable_child_channels" do
|
254
|
+
it "should get the subscribable child channels" do
|
255
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with('system.listSubscribableChildChannels','token',1).returns([{ 'label' => 'some_child_channel' }])
|
256
|
+
|
257
|
+
RhnSatellite::System.subscribable_child_channels('1').should eql([{ 'label' => 'some_child_channel' }])
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
describe ".schedule_apply_errata" do
|
262
|
+
it "should handle single ids correctly" do
|
263
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with('system.scheduleApplyErrata','token',[1],[9]).returns(1)
|
264
|
+
|
265
|
+
RhnSatellite::System.schedule_apply_errata(1,9).should eql(1)
|
266
|
+
end
|
267
|
+
context "immeditalely" do
|
268
|
+
it "should schedule the list of errata immediately" do
|
269
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with('system.scheduleApplyErrata','token',[1,2],[9,22]).returns(1)
|
270
|
+
|
271
|
+
RhnSatellite::System.schedule_apply_errata([1,2],[9,22]).should eql(1)
|
272
|
+
end
|
273
|
+
end
|
274
|
+
context "later" do
|
275
|
+
it "should schedule the list of errata to a later point" do
|
276
|
+
now = DateTime.now.to_s
|
277
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with('system.scheduleApplyErrata','token',[1,2],[9,22],now).returns(1)
|
278
|
+
|
279
|
+
RhnSatellite::System.schedule_apply_errata([1,2],[9,22],now).should eql(1)
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
end
|
284
|
+
describe ".schedule_reboot" do
|
285
|
+
it "should schedule a reboot immediately by default" do
|
286
|
+
now = Time.now
|
287
|
+
Time.expects(:now).once.returns(now)
|
288
|
+
XMLRPC::DateTime.expects(:new).once.returns('foo')
|
289
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with('system.scheduleReboot','token',1,'foo').returns(1)
|
290
|
+
RhnSatellite::System.schedule_reboot(1).should eql(1)
|
291
|
+
end
|
292
|
+
|
293
|
+
it "should schedule a reboot to a certain time" do
|
294
|
+
later = DateTime.now+600
|
295
|
+
XMLRPC::DateTime.expects(:new).once.returns('foo')
|
296
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with('system.scheduleReboot','token',1,'foo').returns(1)
|
297
|
+
RhnSatellite::System.schedule_reboot(1,later).should eql(1)
|
298
|
+
|
299
|
+
end
|
300
|
+
end
|
301
|
+
|
302
|
+
describe ".schedule_package_install" do
|
303
|
+
it "should schedule a package install immediately by default" do
|
304
|
+
now = Time.now
|
305
|
+
Time.expects(:now).once.returns(now)
|
306
|
+
XMLRPC::DateTime.expects(:new).once.returns('foo')
|
307
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with('system.schedulePackageInstall','token',1,[1,2],'foo').returns(1)
|
308
|
+
RhnSatellite::System.schedule_package_install(1,[1,2]).should eql(1)
|
309
|
+
end
|
310
|
+
|
311
|
+
it "should schedule a reboot to a certain time" do
|
312
|
+
later = DateTime.now+600
|
313
|
+
XMLRPC::DateTime.expects(:new).once.returns('foo')
|
314
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with('system.schedulePackageInstall','token',1,[1,2],'foo').returns(1)
|
315
|
+
RhnSatellite::System.schedule_package_install(1,[1,2],later).should eql(1)
|
316
|
+
|
317
|
+
end
|
318
|
+
end
|
319
|
+
end
|
320
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
3
|
+
|
4
|
+
describe RhnSatellite::Systemgroup do
|
5
|
+
context "standard invocation" do
|
6
|
+
before(:each) do
|
7
|
+
RhnSatellite::Systemgroup.reset
|
8
|
+
conn = Object.new
|
9
|
+
conn.stubs(:call)
|
10
|
+
|
11
|
+
XMLRPC::Client.stubs(:new2).returns(conn)
|
12
|
+
|
13
|
+
RhnSatellite::Systemgroup.username = 'user'
|
14
|
+
RhnSatellite::Systemgroup.password = 'pwd'
|
15
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with("auth.login",'user','pwd').returns("token")
|
16
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with("auth.logout",'token')
|
17
|
+
end
|
18
|
+
|
19
|
+
describe ".all" do
|
20
|
+
it "logins and returns a bunch of systemgroups" do
|
21
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with('systemgroup.listAllGroups',"token").returns(["123","234"])
|
22
|
+
|
23
|
+
RhnSatellite::Systemgroup.all.should eql(["123","234"])
|
24
|
+
end
|
25
|
+
|
26
|
+
it "returns an empty array on an empty answer" do
|
27
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with('systemgroup.listAllGroups',"token").returns(nil)
|
28
|
+
|
29
|
+
RhnSatellite::Systemgroup.all.should eql([])
|
30
|
+
end
|
31
|
+
|
32
|
+
it "iterates the items over the block" do
|
33
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with('systemgroup.listAllGroups',"token").returns(["123","234"])
|
34
|
+
RhnSatellite::Systemgroup.all{|i| ["123","234"].include?(i).should be_true }.should eql(["123","234"])
|
35
|
+
end
|
36
|
+
end
|
37
|
+
describe ".get" do
|
38
|
+
context "with systems" do
|
39
|
+
before :each do
|
40
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with('systemgroup.listAllGroups',"token").returns([{'name' => "123"},{'name' => "234"}])
|
41
|
+
end
|
42
|
+
it "finds a system in all systems" do
|
43
|
+
RhnSatellite::Systemgroup.get('123').should eql({'name' => '123'})
|
44
|
+
end
|
45
|
+
|
46
|
+
it "returns nil on an non-existant system" do
|
47
|
+
RhnSatellite::Systemgroup.get('12333').should eql(nil)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
context "without any systems" do
|
51
|
+
before :each do
|
52
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with('systemgroup.listAllGroups',"token").returns([])
|
53
|
+
end
|
54
|
+
it "returns nil" do
|
55
|
+
RhnSatellite::Systemgroup.get('12333').should eql(nil)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe ".delete" do
|
61
|
+
it "deletes on the api" do
|
62
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with('systemgroup.delete',"token",'foogroup').returns(true)
|
63
|
+
|
64
|
+
RhnSatellite::Systemgroup.delete('foogroup').should eql(true)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe ".create" do
|
69
|
+
it "creates on the api" do
|
70
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with('systemgroup.create',"token",'foogroup','somedesc').returns("foogroup")
|
71
|
+
|
72
|
+
RhnSatellite::Systemgroup.create('foogroup','somedesc').should eql("foogroup")
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe ".remove_systems" do
|
77
|
+
it "removes systems from a group" do
|
78
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with('systemgroup.addOrRemoveSystems',"token",'foogroup',['1','2'],false).returns(true)
|
79
|
+
|
80
|
+
RhnSatellite::Systemgroup.remove_systems('foogroup',['1','2']).should eql(true)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe ".add_systems" do
|
85
|
+
it "adds systems to a group" do
|
86
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with('systemgroup.addOrRemoveSystems',"token",'foogroup',['1','2'],true).returns(true)
|
87
|
+
|
88
|
+
RhnSatellite::Systemgroup.add_systems('foogroup',['1','2']).should eql(true)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
[:systems, :systems_safe].each do |m|
|
93
|
+
describe ".#{m.to_s}" do
|
94
|
+
it "should list the systems" do
|
95
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with('systemgroup.listSystems',"token",'foogroup').returns(["system2","system3"])
|
96
|
+
|
97
|
+
RhnSatellite::Systemgroup.send(m,'foogroup').should eql(['system2','system3'])
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
context "special invocation" do
|
104
|
+
before(:each) do
|
105
|
+
RhnSatellite::Systemgroup.reset
|
106
|
+
conn = Object.new
|
107
|
+
conn.stubs(:call)
|
108
|
+
|
109
|
+
XMLRPC::Client.stubs(:new2).returns(conn)
|
110
|
+
|
111
|
+
RhnSatellite::Systemgroup.username = 'user'
|
112
|
+
RhnSatellite::Systemgroup.password = 'pwd'
|
113
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with("auth.login",'user','pwd').returns("token")
|
114
|
+
RhnSatellite::Connection::Handler.any_instance.expects(:make_call).with('systemgroup.listSystems',"token",'emptygroup').raises XMLRPC::FaultException.new("500","foo")
|
115
|
+
end
|
116
|
+
describe ".systems" do
|
117
|
+
it "raises a XMLRPC::FaultException on an empty group" do
|
118
|
+
lambda { RhnSatellite::Systemgroup.systems('emptygroup') }.should raise_error(XMLRPC::FaultException,'foo')
|
119
|
+
end
|
120
|
+
end
|
121
|
+
describe ".systems_safe" do
|
122
|
+
it "returns an empty array on an empty group" do
|
123
|
+
RhnSatellite::Systemgroup.systems_safe('emptygroup').should eql([])
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|