brocadesan 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. data/README +113 -0
  2. data/Rakefile +46 -0
  3. data/brocadesan.gemspec +14 -0
  4. data/lib/brocadesan.rb +8 -0
  5. data/lib/brocadesan/alias.rb +64 -0
  6. data/lib/brocadesan/config/brocade/san/switch_cmd_mapping.yml +116 -0
  7. data/lib/brocadesan/config/parser_mapping.yml +21 -0
  8. data/lib/brocadesan/device.rb +296 -0
  9. data/lib/brocadesan/monkey/string.rb +11 -0
  10. data/lib/brocadesan/provisioning.rb +894 -0
  11. data/lib/brocadesan/switch.rb +882 -0
  12. data/lib/brocadesan/wwn.rb +63 -0
  13. data/lib/brocadesan/zone.rb +60 -0
  14. data/lib/brocadesan/zone_configuration.rb +38 -0
  15. data/lib/meta_methods.rb +263 -0
  16. data/test/alias_test.rb +68 -0
  17. data/test/device_test.rb +203 -0
  18. data/test/output_helpers.rb +308 -0
  19. data/test/outputs/agshow_1.txt +7 -0
  20. data/test/outputs/agshow_1.yml +31 -0
  21. data/test/outputs/agshow_2.txt +4 -0
  22. data/test/outputs/agshow_2.yml +3 -0
  23. data/test/outputs/apt_policy_1.txt +6 -0
  24. data/test/outputs/apt_policy_1.yml +3 -0
  25. data/test/outputs/cfgshow_1.txt +5 -0
  26. data/test/outputs/cfgshow_1.yml +7 -0
  27. data/test/outputs/cfgshow_2.txt +31 -0
  28. data/test/outputs/cfgshow_2.yml +32 -0
  29. data/test/outputs/cfgshow_3.txt +9 -0
  30. data/test/outputs/cfgshow_3.yml +12 -0
  31. data/test/outputs/cfgtransshow_1.txt +2 -0
  32. data/test/outputs/cfgtransshow_1.yml +5 -0
  33. data/test/outputs/cfgtransshow_2.txt +3 -0
  34. data/test/outputs/cfgtransshow_2.yml +4 -0
  35. data/test/outputs/cfgtransshow_3.txt +3 -0
  36. data/test/outputs/cfgtransshow_3.yml +4 -0
  37. data/test/outputs/chassisname_1.txt +2 -0
  38. data/test/outputs/chassisname_1.yml +3 -0
  39. data/test/outputs/dlsshow_1.txt +4 -0
  40. data/test/outputs/dlsshow_1.yml +4 -0
  41. data/test/outputs/dlsshow_2.txt +4 -0
  42. data/test/outputs/dlsshow_2.yml +4 -0
  43. data/test/outputs/fabricshow_1.txt +10 -0
  44. data/test/outputs/fabricshow_1.yml +34 -0
  45. data/test/outputs/iodshow_1.txt +4 -0
  46. data/test/outputs/iodshow_1.yml +4 -0
  47. data/test/outputs/islshow_1.txt +6 -0
  48. data/test/outputs/islshow_1.yml +62 -0
  49. data/test/outputs/islshow_2.txt +2 -0
  50. data/test/outputs/islshow_2.yml +2 -0
  51. data/test/outputs/lscfg_show_1.txt +71 -0
  52. data/test/outputs/lscfg_show_1.yml +5 -0
  53. data/test/outputs/ns_1.txt +80 -0
  54. data/test/outputs/ns_1.yml +39 -0
  55. data/test/outputs/ns_2.txt +37 -0
  56. data/test/outputs/ns_2.yml +21 -0
  57. data/test/outputs/putty.log +1867 -0
  58. data/test/outputs/switch_1.txt +25 -0
  59. data/test/outputs/switch_1.yml +73 -0
  60. data/test/outputs/switch_2.txt +18 -0
  61. data/test/outputs/switch_2.yml +42 -0
  62. data/test/outputs/switch_3.txt +14 -0
  63. data/test/outputs/switch_3.yml +46 -0
  64. data/test/outputs/switchstatusshow_1.txt +21 -0
  65. data/test/outputs/switchstatusshow_1.yml +19 -0
  66. data/test/outputs/trunkshow_1.txt +8 -0
  67. data/test/outputs/trunkshow_1.yml +44 -0
  68. data/test/outputs/trunkshow_2.txt +2 -0
  69. data/test/outputs/trunkshow_2.yml +2 -0
  70. data/test/outputs/version_1.txt +6 -0
  71. data/test/outputs/version_1.yml +8 -0
  72. data/test/outputs/vf_switch_1.txt +25 -0
  73. data/test/outputs/vf_switch_1.yml +73 -0
  74. data/test/provisioning_test.rb +1043 -0
  75. data/test/switch_test.rb +476 -0
  76. data/test/wwn_test.rb +41 -0
  77. data/test/zone_configuration_test.rb +65 -0
  78. data/test/zone_test.rb +73 -0
  79. metadata +170 -0
@@ -0,0 +1,1043 @@
1
+ require 'brocadesan'
2
+ require 'minitest/autorun'
3
+ require 'output_helpers'
4
+
5
+ module Brocade module SAN
6
+
7
+ class ProvisioningTest < MiniTest::Test
8
+ include OutputReader
9
+ include Mock::Net::SSH
10
+ patch_set
11
+
12
+ def setup
13
+ init_dev
14
+ end
15
+
16
+ def init_dev
17
+ @agent = Provisioning::Agent.create("test","test","test")
18
+ @response=new_mock_response
19
+ end
20
+
21
+ def test_device_setup
22
+ assert_instance_of Provisioning::Agent, @agent
23
+ assert_equal nil, @agent.instance_variable_get(:@transaction)
24
+
25
+ # this hack ensures I can test verify false inside create
26
+ Provisioning::Agent.class_eval do
27
+ alias_method :old_verify, :verify
28
+ def verify
29
+ false
30
+ end
31
+ end
32
+ exp = assert_raises Provisioning::Agent::Error do
33
+ @agent = Provisioning::Agent.create("test","test","test")
34
+ end
35
+ assert_equal Provisioning::Agent::Error::BAD_USER, exp.message
36
+ Provisioning::Agent.class_eval do
37
+ alias_method :verify, :old_verify
38
+ undef_method :old_verify
39
+ end
40
+ end
41
+
42
+
43
+ def test_verify
44
+ @response.data="> configshow |grep \"RBAC\"\n"
45
+ @agent.stub :query, @response do
46
+ assert_equal true, @agent.send(:verify)
47
+ end
48
+
49
+ @response.data="> configshow |grep \"RBAC\"\nRBAC permission denied.\n"
50
+ @agent.stub :query, @response do
51
+ assert_equal false, @agent.send(:verify)
52
+ end
53
+ end
54
+
55
+ def test_lock_transaction
56
+ @agent.instance_variable_set(:@transaction,Provisioning::Agent::Transaction.new({:id=>"32323",:abortable=>true}))
57
+ # returns true if transaction is already in progress (transaction block within transaction)
58
+ assert @agent.send :lock_transaction
59
+
60
+ @agent.instance_variable_set(:@transaction,nil)
61
+ # if there is existing different transaction from outside
62
+ @agent.stub :get_transaction,true do
63
+ assert_equal false, @agent.send(:lock_transaction)
64
+ end
65
+
66
+ # locking
67
+ @agent.multistub [
68
+ [:get_transaction, false],
69
+ [:alias_create,:alias_create],
70
+ [:alias_delete,:alias_delete]
71
+ ] do
72
+ assert @agent.send(:lock_transaction)
73
+ # normaly this should be of Transaction instance but we stubbed it
74
+ assert_equal false, @agent.instance_variable_get(:@transaction)
75
+ end
76
+
77
+ # some uneexpected error
78
+ error = lambda {
79
+ raise "unexpected"
80
+ }
81
+ @agent.stub :get_transaction,error do
82
+ assert_equal false, @agent.send(:lock_transaction)
83
+ end
84
+ end
85
+
86
+ def test_get_transaction
87
+ # not transaction
88
+ @response.data="> cfgtransshow\nThere is no outstanding zoning transaction\n"
89
+ @agent.stub :query, @response do
90
+ @agent.query_stub do
91
+ assert_equal false, @agent.get_transaction
92
+ assert_equal "cfgtransshow", @agent.instance_variable_get(:@query_string)
93
+ end
94
+ end
95
+ # abortable
96
+ @response.data="> cfgtransshow\nCurrent transaction token is 271010736\nIt is abortable\n"
97
+ @agent.stub :query, @response do
98
+ trans = @agent.get_transaction
99
+ assert_instance_of Brocade::SAN::Provisioning::Agent::Transaction, trans
100
+ assert_equal "271010736", trans.id
101
+ assert_equal true, trans.abortable?
102
+ end
103
+ # not abortable
104
+ @response.data="> cfgtransshow\nCurrent transaction token is 0xfffffff0\nIt is not abortable\n"
105
+ @agent.stub :query, @response do
106
+ trans = @agent.get_transaction
107
+ assert_instance_of Brocade::SAN::Provisioning::Agent::Transaction, trans
108
+ assert_equal "0xfffffff0", trans.id
109
+ assert_equal false, trans.abortable?
110
+ end
111
+ # error
112
+ @response.data="> cfgtransshow\nunexpected shit\nunexpected shit2\n"
113
+ @agent.stub :query, @response do
114
+ exp = assert_raises Provisioning::Agent::Error do
115
+ @agent.get_transaction
116
+ end
117
+ assert_equal Provisioning::Agent::Error::TRANS_UNEXPECTED, exp.message
118
+ end
119
+ end
120
+
121
+ def test_transaction
122
+ @agent.multistub [
123
+ [:cfg_save, :cfg_save],
124
+ [:abort_transaction, :abort_transaction],
125
+ [:check_for_running_transaction, false],
126
+ [:lock_transaction, true],
127
+ [:get_transaction, true]
128
+ ] do
129
+ # if all is good call cfg_save - > last method of transaction block
130
+ res = @agent.transaction do
131
+ end
132
+ assert_equal :cfg_save, res
133
+
134
+ # else raise error and abort transaction
135
+ # strus abort transaction which then set trans_aborted instance variable
136
+ @agent.abort_transaction_stub do
137
+ exp = assert_raises RuntimeError do
138
+ res = @agent.transaction do
139
+ raise "test"
140
+ end
141
+ end
142
+ # confirm abort_transaction was started
143
+ assert @agent.instance_variable_get(:@trans_aborted)
144
+ assert_equal "test", exp.message
145
+ end
146
+
147
+ @agent.transaction do
148
+ assert_equal true, @agent.instance_variable_get(:@transaction)
149
+ assert_instance_of Mock::Net::SSH::Session, @agent.instance_variable_get(:@session)
150
+ assert_equal 1, @agent.instance_variable_get(:@transaction_level)
151
+ @agent.transaction do
152
+ assert_equal 2, @agent.instance_variable_get(:@transaction_level)
153
+ end
154
+ end
155
+ assert_equal 0, @agent.instance_variable_get(:@transaction_level)
156
+ assert_equal nil, @agent.instance_variable_get(:@transaction)
157
+ end
158
+
159
+ @agent.stub :check_for_running_transaction, true do
160
+ # if there is transaction already in progress raises error
161
+ exp = assert_raises Provisioning::Agent::Error do
162
+ @agent.transaction do
163
+ end
164
+ end
165
+ assert_equal Provisioning::Agent::Error::TRNS_IPRG, exp.message
166
+ end
167
+
168
+ @agent.multistub [
169
+ [:lock_transaction, false],
170
+ [:check_for_running_transaction, false]
171
+ ] do
172
+ # if we cannot lock transactino for some reason
173
+ exp = assert_raises Provisioning::Agent::Error do
174
+ @agent.transaction do
175
+ end
176
+ end
177
+ assert_equal Provisioning::Agent::Error::TRANS_UNLOCKABLE, exp.message
178
+ end
179
+ end
180
+
181
+ def test_check_for_running_transaction
182
+ @response.data="> cfgtransshow\nThere is no outstanding zoning transaction\n"
183
+ @agent.stub :query, @response do
184
+ assert_equal false, @agent.check_for_running_transaction
185
+ end
186
+
187
+ # old version response
188
+ @response.data="> cfgtransshow\nThere is no outstanding zoning transactions\n"
189
+ @agent.stub :query, @response do
190
+ assert_equal false, @agent.check_for_running_transaction
191
+ end
192
+
193
+ @response.data="> cfgtransshow\nCurrent transaction token is 271010736\nIt is abortable\n"
194
+ @agent.stub :query, @response do
195
+ assert_equal true, @agent.check_for_running_transaction
196
+ end
197
+
198
+ #verify we are sending the proper command
199
+ @agent.query_stub do
200
+ @agent.check_for_running_transaction
201
+ assert_equal "cfgtransshow", @agent.instance_variable_get(:@query_string)
202
+ end
203
+ end
204
+
205
+ def test_transaction_abort
206
+ @response.data="> cfgtransabort\n"
207
+ @agent.stub :query, @response do
208
+ assert_equal true, @agent.abort_transaction
209
+
210
+ #verify we are sending the proper command
211
+ @agent.query_stub do
212
+ @agent.abort_transaction
213
+ assert_equal "cfgtransabort", @agent.instance_variable_get(:@query_string)
214
+ end
215
+ end
216
+
217
+ @response.data="> cfgtransabort\nThere is no outstanding transactions\n"
218
+ @agent.stub :query, @response do
219
+ assert_equal false, @agent.abort_transaction
220
+ end
221
+
222
+ # should raise error if there is transaction but we do not own it
223
+ @response.data="> cfgtransabort\ntrans_abort: there is an outstanding transaction, and you are not owner of that transaction.\n"
224
+ @agent.stub :query, @response do
225
+ exp = assert_raises Provisioning::Agent::Error do
226
+ @agent.abort_transaction
227
+ end
228
+ assert_equal Provisioning::Agent::Error::TRANS_NOTOWNER, exp.message
229
+ end
230
+
231
+ # should raise error if unexpected reply
232
+ @response.data="> cfgtransabort\nkvakvakva\n"
233
+ @agent.stub :query, @response do
234
+ exp = assert_raises Provisioning::Agent::Error do
235
+ @agent.abort_transaction
236
+ end
237
+ assert_equal "kvakvakva", exp.message
238
+ end
239
+ end
240
+
241
+ def test_exist?
242
+ @response.data="> alishow\n"
243
+ @agent.stub :query, @response do
244
+ @agent.query_stub do
245
+ assert_equal true, @agent.exist?("test")
246
+ # verifies the cmd sent to switch
247
+ assert_equal "zoneshow \"test\"", @agent.instance_variable_get(:@query_string)
248
+ @agent.instance_variable_set(:@query_string,"")
249
+ assert_equal true, @agent.exist?("test",:object => :zone)
250
+ assert_equal "zoneshow \"test\"", @agent.instance_variable_get(:@query_string)
251
+ @agent.instance_variable_set(:@query_string,"")
252
+ assert_equal true, @agent.exist?("test",:object => :alias)
253
+ assert_equal "alishow \"test\"", @agent.instance_variable_get(:@query_string)
254
+ @agent.instance_variable_set(:@query_string,"")
255
+ assert_equal true, @agent.exist?("test",:object => :cfg)
256
+ assert_equal "cfgshow \"test\"", @agent.instance_variable_get(:@query_string)
257
+ @agent.instance_variable_set(:@query_string,"")
258
+ assert_equal true, @agent.exist?("test",:object => :test)
259
+ assert_equal "zoneshow \"test\"", @agent.instance_variable_get(:@query_string)
260
+ @agent.instance_variable_set(:@query_string,"")
261
+ end
262
+ end
263
+ @response.data="> alishow\ndoes not exist\n"
264
+ @agent.stub :query, @response do
265
+ assert_equal false, @agent.exist?("test")
266
+ assert_equal false, @agent.exist?("test",:object => :zone)
267
+ assert_equal false, @agent.exist?("test",:object => :alias)
268
+ assert_equal false, @agent.exist?("test",:object => :cfg)
269
+ assert_equal false, @agent.exist?("test",:object => :test)
270
+ end
271
+ end
272
+
273
+ def test_cfgsave
274
+ # should raise error if cancelled
275
+ @response.data="> cfgsave\nOperation cancelled...\n"
276
+ @agent.stub :query, @response do
277
+ exp = assert_raises Provisioning::Agent::Error do
278
+ @agent.send :cfg_save
279
+ end
280
+ assert_equal Provisioning::Agent::Error::CFGSAVE_CANC, exp.message
281
+ assert_equal 'script', @agent.get_mode
282
+ end
283
+
284
+ # should raise error nothing changed
285
+ @response.data="> cfgsave\nNothing changed: nothing to save, returning ...\n"
286
+ @agent.stub :query, @response do
287
+ exp = assert_raises Provisioning::Agent::Error do
288
+ @agent.send :cfg_save
289
+ end
290
+ assert_equal Provisioning::Agent::Error::CFGSAVE_NOCHANGE, exp.message
291
+ assert_equal 'script', @agent.get_mode
292
+ end
293
+
294
+ # should return true if saved
295
+ @response.data="> cfgsave\nUpdating flash ...\n"
296
+ @agent.stub :query, @response do
297
+ @agent.query_stub do
298
+ assert_equal true, @agent.send(:cfg_save)
299
+ assert_equal 'script', @agent.get_mode
300
+ assert_equal "cfgsave,y", @agent.instance_variable_get(:@query_string)
301
+ end
302
+ end
303
+ end
304
+
305
+ def test_cfgenable
306
+ cfg = ZoneConfiguration.new("test")
307
+
308
+ # should raise error if not zone configuration
309
+ exp = assert_raises Provisioning::Agent::Error do
310
+ @agent.cfg_enable("test")
311
+ end
312
+ assert_equal Provisioning::Agent::Error::CFG_BAD, exp.message
313
+
314
+ # should raise error if cancelled
315
+ @response.data="> cfgenable test\nOperation cancelled...\n"
316
+ @agent.stub :query, @response do
317
+ exp = assert_raises Provisioning::Agent::Error do
318
+ @agent.cfg_enable(cfg)
319
+ end
320
+ assert_equal Provisioning::Agent::Error::CFGSAVE_CANC, exp.message
321
+ assert_equal 'script', @agent.get_mode
322
+ end
323
+
324
+ # should return true if saved
325
+ @response.data="> cfgenable test\nUpdating flash ...\n"
326
+ @agent.stub :query, @response do
327
+ @agent.query_stub do
328
+ assert_equal true, @agent.cfg_enable(cfg)
329
+ assert_equal 'script', @agent.get_mode
330
+ assert_equal "cfgenable \"test\",y", @agent.instance_variable_get(:@query_string)
331
+ end
332
+ end
333
+ end
334
+
335
+ def test_obj_create
336
+ zones = [Zone.new("koza"),Zone.new("byk")]
337
+ als = [Alias.new("koza"),Alias.new("byk")]
338
+ wwns = ["50:01:02:03:04:05:06:07"]
339
+ objs = [
340
+ {:obj=>ZoneConfiguration.new("zctest"),
341
+ :klass=>ZoneConfiguration,
342
+ :cmd => "cfgcreate",
343
+ :member_name => "Zone",
344
+ :error=>Provisioning::Agent::Error::CFG_BAD,:method=>:cfg_create,
345
+ :msg_invalid => "> cfgcreate \"test-04\",\"koza; byk\"\nInvalid name\n",
346
+ :resp_invalid => "Invalid name",
347
+ :msg_ok => "> cfgcreate \"test\",\"koza; byk\"\n",
348
+ :resp_ok => "",
349
+ :msg_duplicate => "> cfgcreate cfg1, zone1\n\"cfg1\" duplicate name\n",
350
+ :resp_duplicate => "\"cfg1\" duplicate name",
351
+ :members => zones.map {|z| z.to_s}
352
+ },
353
+ {:obj=>Zone.new("zonetest"),
354
+ :klass=>Zone,
355
+ :cmd => "zonecreate",
356
+ :member_name => "Alias",
357
+ :error => Provisioning::Agent::Error::ZONE_BAD,:method=>:zone_create,
358
+ :msg_invalid => "> zonecreate \"test-04\",\"koza; byk\"\nInvalid name\n",
359
+ :resp_invalid => "Invalid name",
360
+ :msg_ok => "> zonecreate \"test\",\"koza; byk\"\n",
361
+ :resp_ok => "",
362
+ :msg_duplicate => "> zonecreate WYN_vls1_node3_fc0, 5B:49:9B:AF:F0:93:00:13\n\"WYN_vls1_node3_fc0\" duplicate name\n",
363
+ :resp_duplicate => "\"WYN_vls1_node3_fc0\" duplicate name",
364
+ :members => als.map {|a| a.to_s}
365
+ },
366
+ {:obj=>Alias.new("aliastest"),
367
+ :klass=>Alias,
368
+ :cmd => "alicreate",
369
+ :member_name => "Wwn",
370
+ :error => Provisioning::Agent::Error::ALIAS_BAD,:method=>:alias_create,
371
+ :msg_invalid => "> alicreate \"test\",\"50:00; 50:02\"\nInvalid alias\n",
372
+ :resp_invalid => "Invalid alias",
373
+ :msg_ok => "> alicreate \"test\",\"50:00; 50:02\"\n",
374
+ :resp_ok => "",
375
+ :msg_duplicate => "> alicreate WYN_vls1_node3_fc0, 5B:49:9B:AF:F0:93:00:13\n\"WYN_vls1_node3_fc0\" duplicate name\n",
376
+ :resp_duplicate => "\"WYN_vls1_node3_fc0\" duplicate name",
377
+ :members => wwns.map {|w| w.to_s}
378
+ }
379
+ ]
380
+
381
+ # should raise error if obj is not ok
382
+ objs.each do |obj|
383
+ exp = assert_raises Provisioning::Agent::Error do
384
+ @agent.send :obj_create,"query_string",obj[:klass]
385
+ end
386
+ assert_equal obj[:error], exp.message
387
+ # test wrapper - enough to test teh wrapper for this
388
+ exp = assert_raises Provisioning::Agent::Error do
389
+ @agent.send obj[:method],"query_string"
390
+ end
391
+ assert_equal obj[:error], exp.message
392
+
393
+ # test if transaction is ongoing
394
+ @agent.stub :check_for_running_transaction, true do
395
+ exp = assert_raises Provisioning::Agent::Error do
396
+ @agent.send :obj_create,obj[:obj],obj[:klass]
397
+ end
398
+ assert_equal Provisioning::Agent::Error::TRNS_IPRG, exp.message
399
+ end
400
+
401
+ @agent.stub :check_for_running_transaction, false do
402
+ @agent.stub :exist?, true do
403
+ # empty members check
404
+ @response.data=obj[:msg_invalid]
405
+ @agent.stub :query, @response do
406
+ exp = assert_raises Provisioning::Agent::Error do
407
+ @agent.send :obj_create,obj[:obj],obj[:klass]
408
+ end
409
+ assert_equal Provisioning::Agent::Error::MEMBERS_EMPTY, exp.message
410
+ end
411
+
412
+ # set members
413
+ obj[:members].each do |mem|
414
+ obj[:obj].add_member mem
415
+ end
416
+ @agent.stub :zones, zones do
417
+ # check invalid objects responses
418
+ @response.data=obj[:msg_invalid]
419
+ @agent.stub :query, @response do
420
+ exp = assert_raises Provisioning::Agent::Error do
421
+ @agent.send :obj_create,obj[:obj],obj[:klass]
422
+ end
423
+ assert_equal obj[:resp_invalid], exp.message
424
+ end
425
+ # check ok response
426
+ @response.data=obj[:msg_ok]
427
+ @agent.multistub [
428
+ [:query, @response],
429
+ [:cfg_save, true],
430
+ [:pull, obj[:obj]]
431
+ ] do
432
+ @agent.query_stub do
433
+ assert_equal obj[:obj], @agent.send(:obj_create,obj[:obj],obj[:klass])
434
+ # checks the cmd sent to query
435
+ assert_equal "#{obj[:cmd]} \"#{obj[:obj].name}\", \"#{obj[:obj].members.join(";")}\"", @agent.instance_variable_get(:@query_string)
436
+ end
437
+ end
438
+
439
+ # check duplicate respones
440
+ @response.data= obj[:msg_duplicate]
441
+ @agent.stub :query, @response do
442
+ exp = assert_raises Provisioning::Agent::Error do
443
+ @agent.send(:obj_create,obj[:obj],obj[:klass])
444
+ end
445
+ assert_equal obj[:resp_duplicate], exp.message
446
+ end
447
+ end
448
+ end
449
+ # checking members exists
450
+ # do not do the following for alias
451
+ next if obj[:klass]==Alias
452
+ #obj[:obj].add_member("test2")
453
+ @response.data=obj[:msg_ok]
454
+ @agent.multistub [
455
+ [:exist?, false],
456
+ [:query, @response],
457
+ [:pull, obj[:obj]],
458
+ [:zones, []]
459
+ ] do
460
+ exp = assert_raises Provisioning::Agent::Error do
461
+ @agent.send(:obj_create,obj[:obj],obj[:klass])
462
+ end
463
+ assert_equal "#{obj[:member_name]} #{obj[:members][0]} #{Provisioning::Agent::Error::OBJ_NOTEXIST}", exp.message
464
+
465
+ # special test only for zone members
466
+ # if member is wwn check should not be done
467
+ if obj[:klass]==Zone
468
+ a = Zone.new("test")
469
+ a.add_member("50:00:10:20:30:40:50:60")
470
+ @agent.stub :cfg_save, true do
471
+ assert_equal obj[:obj], @agent.zone_create(a)
472
+ end
473
+ end
474
+ end
475
+ end
476
+ end
477
+ end
478
+
479
+ def test_obj_delete
480
+
481
+ objs = [
482
+ {:obj=>ZoneConfiguration.new("zctest"),
483
+ :klass=>ZoneConfiguration,
484
+ :cmd => "cfgdelete",
485
+ :member_name => "Zone",
486
+ :error=>Provisioning::Agent::Error::CFG_BAD,
487
+ :method=>:cfg_delete,
488
+ :msg_not_found => "> cfgdelete \"test\"\nnot found\n",
489
+ :resp_not_found => "not found",
490
+ :msg_ok => "> cfgedelete \"test\"\n",
491
+ :resp_ok => ""
492
+ },
493
+ {:obj=>Zone.new("zonetest"),
494
+ :klass=>Zone,
495
+ :cmd => "zonedelete",
496
+ :member_name => "Alias",
497
+ :error => Provisioning::Agent::Error::ZONE_BAD,
498
+ :method=>:zone_delete,
499
+ :msg_not_found => "> zonedelete \"test\"\nnot found\n",
500
+ :resp_not_found => "not found",
501
+ :msg_ok => "> zonedelete \"test\"\n",
502
+ :resp_ok => ""
503
+ },
504
+ {:obj=>Alias.new("aliastest"),
505
+ :klass=>Alias,
506
+ :cmd => "alidelete",
507
+ :member_name => "Wwn",
508
+ :error => Provisioning::Agent::Error::ALIAS_BAD,
509
+ :method=>:alias_delete,
510
+ :msg_not_found => "> alidelete \"test\"\nnot found\n",
511
+ :resp_not_found => "not found",
512
+ :msg_ok => "> alidelete \"test\"\n",
513
+ :resp_ok => ""
514
+ }
515
+ ]
516
+
517
+ objs.each do |obj|
518
+ # should raise error if not alias
519
+ exp = assert_raises Provisioning::Agent::Error do
520
+ @agent.send :obj_delete, "query_string",obj[:klass]
521
+ end
522
+ assert_equal obj[:error], exp.message
523
+
524
+ # test wrapper - enough to test teh wrapper for this
525
+ exp = assert_raises Provisioning::Agent::Error do
526
+ @agent.send obj[:method],"query_string"
527
+ end
528
+ assert_equal obj[:error], exp.message
529
+
530
+ # test if transaction is ongoing
531
+ @agent.stub :check_for_running_transaction, true do
532
+ exp = assert_raises Provisioning::Agent::Error do
533
+ @agent.send :obj_delete,obj[:obj],obj[:klass]
534
+ end
535
+ assert_equal Provisioning::Agent::Error::TRNS_IPRG, exp.message
536
+ end
537
+
538
+
539
+ # test delete complains
540
+ @agent.stub :check_for_running_transaction, false do
541
+ @response.data=obj[:msg_not_found]
542
+ @agent.stub :query, @response do
543
+ exp = assert_raises Provisioning::Agent::Error do
544
+ @agent.send :obj_delete ,obj[:obj],obj[:klass]
545
+ end
546
+ assert_equal obj[:resp_not_found], exp.message
547
+ end
548
+ @response.data=obj[:msg_ok]
549
+ @agent.multistub [
550
+ [:query, @response],
551
+ [:cfg_save, true],
552
+ [:pull, obj[:obj]]
553
+ ] do
554
+ @agent.query_stub do
555
+ assert_equal obj[:obj], @agent.send(:obj_delete,obj[:obj],obj[:klass])
556
+ # checks the cmd sent to query
557
+ assert_equal "#{obj[:cmd]} \"#{obj[:obj].name}\"", @agent.instance_variable_get(:@query_string)
558
+ end
559
+ end
560
+ end
561
+ end
562
+ end
563
+
564
+ def test_obj_change
565
+ # obj_change call obj delete and obj create, so we test only that thei are called
566
+ # the responses of obj_delete and obj_create are tested in their respective tests
567
+ objs = [
568
+ {:obj=>Zone.new("zonetest"),
569
+ :klass=>Zone,
570
+ :queries => ["zonedelete","zonecreate"],
571
+ :method => :zone_change
572
+ },
573
+ {:obj=>Alias.new("aliastest"),
574
+ :klass=>Alias,
575
+ :queries => ["alidelete","alicreate"],
576
+ :method => :alias_change
577
+ }
578
+ ]
579
+ @response.data="> alidelete \"test\"\n"
580
+ objs.each do |obj|
581
+ @agent.multistub [
582
+ [:check_for_running_transaction, false],
583
+ [:lock_transaction, true],
584
+ [:get_transaction, true],
585
+ [:query, @response],
586
+ [:raise_if_members_do_not_exist, :true],
587
+ [:cfg_save, true],
588
+ [:pull, obj[:obj]]
589
+ ] do
590
+ @agent.query_stub do
591
+ assert_equal obj[:obj], @agent.send(:obj_change,obj[:obj],obj[:klass])
592
+ # checks the cmd sent to query
593
+ assert_equal "#{obj[:queries][0]} \"#{obj[:obj].name}\"#{obj[:queries][1]} \"#{obj[:obj].name}\", \"#{obj[:obj].members.join(";")}\"", @agent.instance_variable_get(:@query_string)
594
+ @agent.instance_variable_set(:@query_string,"")
595
+ # test wrapper method
596
+ @agent.send obj[:method],obj[:obj]
597
+ assert_equal "#{obj[:queries][0]} \"#{obj[:obj].name}\"#{obj[:queries][1]} \"#{obj[:obj].name}\", \"#{obj[:obj].members.join(";")}\"", @agent.instance_variable_get(:@query_string)
598
+ end
599
+ end
600
+ end
601
+ end
602
+
603
+ def test_obj_remove
604
+ objs = [
605
+ {:obj=>ZoneConfiguration.new("zctest"),
606
+ :klass=>ZoneConfiguration,
607
+ :cmd => "cfgremove",
608
+ :name => "Config",
609
+ :member_name => "Zone",
610
+ :member => Zone.new("zonetest"),
611
+ :members_ok => [Zone.new("zonetest")],
612
+ :error=>Provisioning::Agent::Error::CFG_BAD,
613
+ :error_member => Provisioning::Agent::Error::ZONE_BAD,
614
+ :method=>:cfg_remove,
615
+ :msg_not_found => "> cfgremove \"zctest\",\"zonetest\"\nnot found\n",
616
+ :resp_not_found => "not found",
617
+ :msg_ok => "> cfgremove \"zctest\",\"zonetest\"\n",
618
+ :resp_ok => ""
619
+ },
620
+ {:obj=>Zone.new("zonetest"),
621
+ :klass=>Zone,
622
+ :cmd => "zoneremove",
623
+ :name => "Zone",
624
+ :member_name => "Alias",
625
+ :member => Alias.new("aliastest"),
626
+ :members_ok => [Alias.new("aliastest"), Wwn.new("50:01:02:03:04:05:06:07","target",1,1),"50:01:02:03:04:05:06:07","1,1"],
627
+ :error => Provisioning::Agent::Error::ZONE_BAD,
628
+ :error_member => Provisioning::Agent::Error::MEMBER_BAD,
629
+ :method=>:zone_remove,
630
+ :msg_not_found => "> zoneremove \"zonename\",\"aliastest\"\nnot found\n",
631
+ :resp_not_found => "not found",
632
+ :msg_ok => "> zoneremove \"zonename\",\"aliastest\"\n",
633
+ :resp_ok => ""
634
+ },
635
+ {:obj=>Alias.new("aliastest"),
636
+ :klass=>Alias,
637
+ :cmd => "aliremove",
638
+ :name => "Alias",
639
+ :member_name => "Wwn",
640
+ :member => "50:01:02:03:04:05:06:07",
641
+ :members_ok => [Wwn.new("50:01:02:03:04:05:06:07","target",1,1),"50:01:02:03:04:05:06:07","1,1"],
642
+ :error => Provisioning::Agent::Error::ALIAS_BAD,
643
+ :error_member => Provisioning::Agent::Error::ALIAS_MEMBER_BAD,
644
+ :method=>:alias_remove,
645
+ :msg_not_found => "> aliremove \"aliastest\",\"50:00; 50:02\"\nnot found\n",
646
+ :resp_not_found => "not found",
647
+ :msg_ok => "> aliremove \"aliastest\",\"50:00; 50:02\"\n",
648
+ :resp_ok => ""
649
+ }
650
+ ]
651
+
652
+
653
+ objs.each do |obj|
654
+ # should raise error if obj is not ok
655
+ exp = assert_raises Provisioning::Agent::Error do
656
+ @agent.send :obj_remove,"query_string",obj[:klass],"member"
657
+ end
658
+ assert_equal obj[:error], exp.message
659
+ # should raise error if member is not ok
660
+ exp = assert_raises Provisioning::Agent::Error do
661
+ @agent.send :obj_remove,obj[:obj],obj[:klass],"member"
662
+ end
663
+ assert_equal obj[:error_member], exp.message
664
+
665
+ # test wrapper - enough to test teh wrapper for this
666
+ exp = assert_raises Provisioning::Agent::Error do
667
+ @agent.send obj[:method],"query_string","member"
668
+ end
669
+ assert_equal obj[:error], exp.message
670
+
671
+ # test if transaction is ongoing
672
+ @agent.stub :check_for_running_transaction, true do
673
+ exp = assert_raises Provisioning::Agent::Error do
674
+ @agent.send :obj_remove,obj[:obj],obj[:klass],obj[:member]
675
+ end
676
+ assert_equal Provisioning::Agent::Error::TRNS_IPRG, exp.message
677
+ end
678
+
679
+ @agent.stub :check_for_running_transaction, false do
680
+ @response.data=obj[:msg_not_found]
681
+ @agent.stub :query, @response do
682
+ exp = assert_raises Provisioning::Agent::Error do
683
+ @agent.send :obj_remove ,obj[:obj],obj[:klass],obj[:member]
684
+ end
685
+ assert_equal obj[:resp_not_found], exp.message
686
+ end
687
+
688
+ # ok response
689
+
690
+ @response.data=obj[:msg_ok]
691
+ @agent.multistub [
692
+ [:query, @response],
693
+ [:cfg_save, true],
694
+ [:exist?, true],
695
+ [:pull, obj[:obj]]
696
+ ] do
697
+ @agent.query_stub do
698
+ obj[:members_ok].each do |mem_ok|
699
+ assert_equal obj[:obj], @agent.send(:obj_remove,obj[:obj],obj[:klass],mem_ok)
700
+ assert_equal "#{obj[:cmd]} \"#{obj[:obj].name}\", \"#{mem_ok}\"", @agent.instance_variable_get(:@query_string)
701
+ @agent.instance_variable_set(:@query_string,"")
702
+ # test wrapper method
703
+ @agent.send obj[:method],obj[:obj],mem_ok
704
+ assert_equal "#{obj[:cmd]} \"#{obj[:obj].name}\", \"#{mem_ok}\"", @agent.instance_variable_get(:@query_string)
705
+ @agent.instance_variable_set(:@query_string,"")
706
+ end
707
+ end
708
+ end
709
+
710
+ # checking obj exists
711
+ @response.data=obj[:msg_ok]
712
+ @agent.multistub [
713
+ [:exist?, false],
714
+ [:query, @response]
715
+ ] do
716
+ exp = assert_raises Provisioning::Agent::Error do
717
+ @agent.send(:obj_remove,obj[:obj],obj[:klass],obj[:member])
718
+ end
719
+ assert_equal "#{obj[:name]} #{obj[:obj].name} #{Provisioning::Agent::Error::OBJ_NOTEXIST}", exp.message
720
+ end
721
+ end
722
+ end
723
+ end
724
+
725
+ def test_obj_add
726
+
727
+ objs = [
728
+ {:obj=>ZoneConfiguration.new("zctest"),
729
+ :klass=>ZoneConfiguration,
730
+ :cmd => "cfgadd",
731
+ :name => "Config",
732
+ :member_name => "Zone",
733
+ :member => Zone.new("zonetest"),
734
+ :members_ok => [Zone.new("zonetest")],
735
+ :error=>Provisioning::Agent::Error::CFG_BAD,
736
+ :error_member => Provisioning::Agent::Error::ZONE_BAD,
737
+ :method=>:cfg_add,
738
+ :msg_not_found => "> cfgadd \"zctest\",\"zonetest\"\nnot found\n",
739
+ :resp_not_found => "not found",
740
+ :msg_ok => "> cfgadd \"zctest\",\"zonetest\"\n",
741
+ :resp_ok => ""
742
+ },
743
+ {:obj=>Zone.new("zonetest"),
744
+ :klass=>Zone,
745
+ :cmd => "zoneadd",
746
+ :name => "Zone",
747
+ :member_name => "Alias",
748
+ :member => Alias.new("aliastest"),
749
+ :members_ok => [Alias.new("aliastest"), Wwn.new("50:01:02:03:04:05:06:07","target",1,1),"50:01:02:03:04:05:06:07","1,1"],
750
+ :error => Provisioning::Agent::Error::ZONE_BAD,
751
+ :error_member => Provisioning::Agent::Error::MEMBER_BAD,
752
+ :method=>:zone_add,
753
+ :msg_not_found => "> zoneadd \"zonename\",\"aliastest\"\nnot found\n",
754
+ :resp_not_found => "not found",
755
+ :msg_ok => "> zoneadd \"zonename\",\"aliastest\"\n",
756
+ :resp_ok => ""
757
+ },
758
+ {:obj=>Alias.new("aliastest"),
759
+ :klass=>Alias,
760
+ :cmd => "aliadd",
761
+ :name => "Alias",
762
+ :member_name => "Wwn",
763
+ :member => "50:01:02:03:04:05:06:07",
764
+ :members_ok => [Wwn.new("50:01:02:03:04:05:06:07","target",1,1),"50:01:02:03:04:05:06:07","1,1"],
765
+ :error => Provisioning::Agent::Error::ALIAS_BAD,
766
+ :error_member => Provisioning::Agent::Error::ALIAS_MEMBER_BAD,
767
+ :method=>:alias_add,
768
+ :msg_not_found => "> aliadd \"aliastest\",\"50:00; 50:02\"\nnot found\n",
769
+ :resp_not_found => "not found",
770
+ :msg_ok => "> aliadd \"aliastest\",\"50:00; 50:02\"\n",
771
+ :resp_ok => ""
772
+ }
773
+ ]
774
+
775
+
776
+ objs.each do |obj|
777
+ # should raise error if obj is not ok
778
+ exp = assert_raises Provisioning::Agent::Error do
779
+ @agent.send :obj_add,"query_string",obj[:klass],"member"
780
+ end
781
+ assert_equal obj[:error], exp.message
782
+ # should raise error if member is not ok
783
+ exp = assert_raises Provisioning::Agent::Error do
784
+ @agent.send :obj_add,obj[:obj],obj[:klass],"member"
785
+ end
786
+ assert_equal obj[:error_member], exp.message
787
+
788
+ # test wrapper - enough to test teh wrapper for this
789
+ exp = assert_raises Provisioning::Agent::Error do
790
+ @agent.send obj[:method],"query_string","member"
791
+ end
792
+ assert_equal obj[:error], exp.message
793
+
794
+ # test if transaction is ongoing
795
+ @agent.stub :check_for_running_transaction, true do
796
+ exp = assert_raises Provisioning::Agent::Error do
797
+ @agent.send :obj_add,obj[:obj],obj[:klass],obj[:member]
798
+ end
799
+ assert_equal Provisioning::Agent::Error::TRNS_IPRG, exp.message
800
+ end
801
+
802
+ @agent.stub :check_for_running_transaction, false do
803
+ @response.data=obj[:msg_not_found]
804
+ @agent.stub :query, @response do
805
+ exp = assert_raises Provisioning::Agent::Error do
806
+ @agent.send :obj_add ,obj[:obj],obj[:klass],obj[:member]
807
+ end
808
+ assert_equal obj[:resp_not_found], exp.message
809
+ end
810
+
811
+ # ok response
812
+
813
+ @response.data=obj[:msg_ok]
814
+ @agent.multistub [
815
+ [:query, @response],
816
+ [:cfg_save, true],
817
+ [:exist?, true],
818
+ [:pull, obj[:obj]]
819
+ ] do
820
+ @agent.query_stub do
821
+ obj[:members_ok].each do |mem_ok|
822
+ assert_equal obj[:obj], @agent.send(:obj_add,obj[:obj],obj[:klass],mem_ok)
823
+ assert_equal "#{obj[:cmd]} \"#{obj[:obj].name}\", \"#{mem_ok}\"", @agent.instance_variable_get(:@query_string)
824
+ @agent.instance_variable_set(:@query_string,"")
825
+ # test wrapper method
826
+ @agent.send obj[:method],obj[:obj],mem_ok
827
+ assert_equal "#{obj[:cmd]} \"#{obj[:obj].name}\", \"#{mem_ok}\"", @agent.instance_variable_get(:@query_string)
828
+ @agent.instance_variable_set(:@query_string,"")
829
+ end
830
+ end
831
+ end
832
+
833
+ # checking obj exists
834
+ # do not do the following for alias
835
+ # the #exist? method is run for both object and member
836
+ # the following stub only checks the obj
837
+ @response.data=obj[:msg_ok]
838
+ @agent.multistub [
839
+ [:exist?, false],
840
+ [:query, @response]
841
+ ] do
842
+ exp = assert_raises Provisioning::Agent::Error do
843
+ @agent.send(:obj_add,obj[:obj],obj[:klass],obj[:member])
844
+ end
845
+ assert_equal "#{obj[:name]} #{obj[:obj].name} #{Provisioning::Agent::Error::OBJ_NOTEXIST}", exp.message
846
+
847
+ # following hack ensures the exist? will be started for the 2nd run only so the member exists part
848
+ @agent.raise_if_obj_do_not_exist_stub do
849
+ exp = assert_raises Provisioning::Agent::Error do
850
+ @agent.send(:obj_add,obj[:obj],obj[:klass],obj[:member])
851
+ end
852
+ # ignore assert for Alias as it will not check if member exist-> will not raise error
853
+ if !obj[:name]=="Alias"
854
+ assert_equal "#{obj[:member_name]} #{obj[:member]} #{Provisioning::Agent::Error::OBJ_NOTEXIST}", exp.message
855
+ end
856
+ @agent.instance_variable_set(:@run,nil)
857
+ end
858
+ end
859
+ end
860
+ end
861
+ end
862
+
863
+ def test_obj_purge
864
+ # obj_purge call obj remove and obj delete, so we test only that they are called
865
+ # the responses of obj_delete and obj_remove are tested in their respective tests
866
+ objs = [
867
+ {:obj=>Zone.new("zonetest"),
868
+ :klass=>Zone,
869
+ :queries => ["cfgremove","zonedelete"],
870
+ :method => :zone_purge,
871
+ :parents => [ZoneConfiguration.new("cfgtest")]
872
+ },
873
+ {:obj=>Alias.new("aliastest"),
874
+ :klass=>Alias,
875
+ :queries => ["zoneremove","alidelete"],
876
+ :method => :alias_purge,
877
+ :parents => [Zone.new("zonetest")]
878
+ }
879
+ ]
880
+ # some ok response
881
+ @response.data="> alidelete \"test\"\n"
882
+ objs.each do |obj|
883
+ @agent.multistub [
884
+ [:check_for_running_transaction, false],
885
+ [:lock_transaction, true],
886
+ [:query, @response],
887
+ [:cfg_save, true],
888
+ [:exist?, true],
889
+ [:get_transaction, true],
890
+ [:find_by_member, obj[:parents]],
891
+ [:pull, obj[:obj]]
892
+ ] do
893
+ @agent.query_stub do
894
+ assert_equal obj[:obj], @agent.send(:obj_purge,obj[:obj],obj[:klass])
895
+ # checks the cmd sent to query
896
+ assert_equal "#{obj[:queries][0]} \"#{obj[:parents][0]}\", \"#{obj[:obj]}\"#{obj[:queries][1]} \"#{obj[:obj]}\"", @agent.instance_variable_get(:@query_string)
897
+ @agent.instance_variable_set(:@query_string,"")
898
+ # test wrapper method
899
+ @agent.send obj[:method],obj[:obj]
900
+ assert_equal "#{obj[:queries][0]} \"#{obj[:parents][0]}\", \"#{obj[:obj]}\"#{obj[:queries][1]} \"#{obj[:obj]}\"", @agent.instance_variable_get(:@query_string)
901
+ end
902
+ end
903
+ end
904
+ end
905
+
906
+ def test_object_pull
907
+ tmp_zone=Zone.new("zonetest")
908
+ tmp_zone.add_member "alias1"
909
+ tmp_zone.add_member "alias3"
910
+
911
+ tmp_alias=Alias.new("aliastest")
912
+ tmp_alias.add_member "50:01:43:80:12:0E:25:18"
913
+
914
+ tmp_cfg = ZoneConfiguration.new("cfgtest")
915
+ tmp_cfg.add_member "zone1"
916
+ tmp_cfg.add_member "zone2"
917
+ tmp_cfg.add_member "zone3"
918
+
919
+ objs = [
920
+ {:obj=>tmp_zone,
921
+ :klass=>Zone,
922
+ :queries => ["zoneshow"],
923
+ :method => :zone_purge,
924
+ :msg_ok => "> zoneshow \"zonetest\"\n zone: zonetest alias1;\n\talias3\n",
925
+ :msg_bad => "> zoneshow\nerror\n"
926
+ },
927
+ {:obj=>tmp_alias,
928
+ :klass=>Alias,
929
+ :queries => ["alishow"],
930
+ :method => :alias_purge,
931
+ :msg_ok => "> alishow \"aliastest\"\n alias: aliastest\n\t50:01:43:80:12:0E:25:18",
932
+ :msg_bad => "> alishow\nerror\n"
933
+ },
934
+ {:obj=>tmp_cfg,
935
+ :klass=>ZoneConfiguration,
936
+ :queries => ["cfgshow"],
937
+ :method => :alias_purge,
938
+ :msg_ok => "> cfgshow \"cfgtest\"\n cfg: cfgtest zone1;\n\tzone2;zone3\n",
939
+ :msg_bad => "> cfgshow\nerror\n"
940
+ }
941
+ ]
942
+ objs.each do |obj|
943
+ @response.data=obj[:msg_ok]
944
+ @agent.stub :query, @response do
945
+ @agent.query_stub do
946
+ test_obj = @agent.send(:obj_pull,obj[:obj],obj[:klass])
947
+ assert_equal obj[:obj].name, test_obj.name
948
+ assert_equal obj[:obj].members, test_obj.members
949
+ assert_equal "#{obj[:queries][0]} \"#{obj[:obj]}\"", @agent.instance_variable_get(:@query_string)
950
+ @agent.instance_variable_set(:@query_string,"")
951
+ end
952
+ end
953
+
954
+ # not processable means we could not find it
955
+ @response.data=obj[:msg_bad]
956
+ @agent.stub :query, @response do
957
+ @agent.query_stub do
958
+ assert_nil @agent.send(:obj_pull,obj[:obj],obj[:klass])
959
+ end
960
+ end
961
+
962
+ # string instead of object, asks 3 times and returns nil in this case
963
+ @response.data=obj[:msg_bad]
964
+ @agent.stub :query, @response do
965
+ @agent.query_stub do
966
+ assert_nil @agent.send(:obj_pull,"test",String)
967
+ assert_equal "cfgshow \"test\"zoneshow \"test\"alishow \"test\"", @agent.instance_variable_get(:@query_string)
968
+ end
969
+ end
970
+ # very difficult to test if one of the response would be ok so skipping
971
+ end
972
+ end
973
+
974
+ def test_rename_object
975
+ objs = [
976
+ {:obj=>Zone.new("zonetest"),
977
+ :new_obj=>Zone.new("zonetest_new"),
978
+ :klass=>Zone,
979
+ :msg_ok => "> zoneobjectrename \"zonetest\", \"zonetest_new\"\n",
980
+ :msg_not_found => "> zoneobjectrename \"zonetest\", \"zonetest_new\"\nnot found \"zonetest\"\n"
981
+ },
982
+ {:obj=>Alias.new("aliastest"),
983
+ :new_obj=>Alias.new("aliastest_new"),
984
+ :klass=>Alias,
985
+ :msg_ok => "> zoneobjectrename \"aliastest\", \"aliastest_new\"\n",
986
+ :msg_not_found => "> zoneobjectrename \"aliastest\", \"aliastest_new\"\nnot found \"aliastest\"\n"
987
+ },
988
+ {:obj=>ZoneConfiguration.new("cfgtest"),
989
+ :new_obj=>ZoneConfiguration.new("cfgtest_new"),
990
+ :klass=>Alias,
991
+ :msg_ok => "> zoneobjectrename \"cfgtest\", \"cfgtest_new\"\n",
992
+ :msg_not_found => "> zoneobjectrename \"cfgtest\", \"cfgtest_new\"\nnot found \"cfgtest\"\n"
993
+ },
994
+ {:obj=>"test",
995
+ :new_obj=>"test_new",
996
+ :klass=>"String",
997
+ :msg_ok => "> zoneobjectrename \"test\", \"test_new\"\n",
998
+ :msg_not_found => "> zoneobjectrename \"test\", \"test_new\"\nnot found \"test\"\n"
999
+ }
1000
+ ]
1001
+
1002
+ objs.each do |obj|
1003
+ #response ok
1004
+ @response.data = obj[:msg_ok]
1005
+ @agent.multistub [
1006
+ [:query, @response],
1007
+ [:pull, obj[:new_obj]],
1008
+ [:cfg_save, :cfg_save]
1009
+ ] do
1010
+ @agent.query_stub do
1011
+ test_obj = @agent.send(:rename_object,obj[:obj],"#{obj[:obj]}_new")
1012
+ assert_equal obj[:new_obj].to_s, test_obj.to_s
1013
+ assert_equal "zoneobjectrename \"#{obj[:obj]}\", \"#{obj[:obj]}_new\"", @agent.instance_variable_get(:@query_string)
1014
+ @agent.instance_variable_set(:@query_string,"")
1015
+ end
1016
+ end
1017
+
1018
+ #response bad
1019
+ @response.data = obj[:msg_not_found]
1020
+ @agent.multistub [
1021
+ [:query, @response],
1022
+ [:pull, obj[:obj]],
1023
+ [:cfg_save, :cfg_save]
1024
+ ] do
1025
+ @agent.query_stub do
1026
+ exp = assert_raises Provisioning::Agent::Error do
1027
+ test_obj = @agent.send(:rename_object,obj[:obj],"#{obj[:obj]}_new")
1028
+ end
1029
+ assert_equal "not found \"#{obj[:obj]}\"", exp.message
1030
+ end
1031
+ end
1032
+ end
1033
+ end
1034
+
1035
+ def test_get_obj_type
1036
+ assert_equal :zone, @agent.send(:get_obj_type, Zone.new("test"))
1037
+ assert_equal :alias, @agent.send(:get_obj_type, Alias.new("test"))
1038
+ assert_equal :cfg, @agent.send(:get_obj_type, ZoneConfiguration.new("test"))
1039
+ assert_equal :all, @agent.send(:get_obj_type, "test")
1040
+ end
1041
+ end
1042
+
1043
+ end; end