rubywbem 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,702 @@
1
+ #
2
+ # Copyright 2006, Red Hat, Inc
3
+ # Scott Seago <sseago@redhat.com>
4
+ #
5
+ # derived from pywbem, written by Tim Potter <tpot@hp.com>, Martin Pool <mbp@hp.com>
6
+ #
7
+ # This program is free software; you can redistribute it and/or modify
8
+ # it under the terms of the GNU General Public License as published by
9
+ # the Free Software Foundation; either version 2 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # You should have received a copy of the GNU General Public License
13
+ # along with this program; if not, write to the Free Software
14
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15
+ #
16
+
17
+ #
18
+ # Test CIM operations function interface. The return codes here may
19
+ # be specific to OpenPegasus.
20
+ #
21
+
22
+ require "comfychair"
23
+ require "date"
24
+ require "singleton"
25
+ require "wbem"
26
+
27
+ module WBEM
28
+ module Test
29
+ class Hostinfo
30
+ include Singleton
31
+ private_class_method :new
32
+ attr_reader :host, :username, :password
33
+ attr_writer :host, :username, :password
34
+ end
35
+ class ClientTest < Comfychair::TestCase
36
+ #"""A base class that creates a WBEM::WBEMConnection for
37
+ #subclasses to use."""
38
+ attr :conn
39
+ def setup
40
+ #"""Create a connection."""
41
+
42
+ # Use globals host, username and password
43
+ @conn = WBEMConnection.new("https://%s" % Hostinfo.instance.host,
44
+ [Hostinfo.instance.username, Hostinfo.instance.password])
45
+ end
46
+ #def cimcall(fn, *args, **kw)
47
+ def cimcall(fn, *args)
48
+ #"""Make a RubyWBEM call and log the request and response XML."""
49
+ begin
50
+ result = self.conn.method(fn).call(*args)
51
+ ensure
52
+ self.log("Request:\n\n%s\n" % self.conn.last_request)
53
+ self.log("Reply:\n\n%s\n" % self.conn.last_reply)
54
+ end
55
+ return result
56
+ end
57
+ end
58
+ #################################################################
59
+ # Instance provider interface tests
60
+ #################################################################
61
+
62
+ class EnumerateInstances < ClientTest
63
+
64
+ def runtest
65
+
66
+ # Simplest invocation
67
+ instances = cimcall(:EnumerateInstances,
68
+ "CIM_Process")
69
+
70
+ instances.each {|i| assert_(i.is_a?(CIMInstance)) }
71
+
72
+ # Call with optional namespace path
73
+
74
+ begin
75
+ self.cimcall(:EnumerateInstances,
76
+ 'CIM_Process',
77
+ :LocalNamespacePath => 'root/pywbem')
78
+
79
+ rescue CIMError => arg
80
+ if arg.code != CIM_ERR_INVALID_NAMESPACE
81
+ raise
82
+ end
83
+ end
84
+ # Try some keyword parameters
85
+
86
+ begin
87
+ self.cimcall(:EnumerateInstances,
88
+ 'CIM_Process',
89
+ :FooParam => 'FooValue')
90
+ rescue CIMError => arg
91
+ if arg.code != CIM_ERR_NOT_SUPPORTED
92
+ raise
93
+ end
94
+ end
95
+ end
96
+ end
97
+
98
+ class EnumerateInstanceNames < ClientTest
99
+
100
+ def runtest
101
+
102
+ # Simplest invocation
103
+
104
+ names = cimcall(:EnumerateInstanceNames,
105
+ 'CIM_Process')
106
+
107
+ names.each {|i| assert_(i.is_a?(CIMInstanceName)) }
108
+
109
+ # Call with optional namespace path
110
+
111
+ begin
112
+ self.cimcall(:EnumerateInstanceNames,
113
+ 'CIM_Process',
114
+ :LocalNamespacePath => 'root/pywbem')
115
+
116
+ rescue CIMError => arg
117
+ if arg.code != CIM_ERR_INVALID_NAMESPACE
118
+ raise
119
+ end
120
+ end
121
+ # Try some keyword parameters
122
+
123
+ begin
124
+ self.cimcall(:EnumerateInstanceNames,
125
+ 'CIM_Process',
126
+ :FooParam => 'FooValue')
127
+ rescue CIMError => arg
128
+ if arg.code != CIM_ERR_NOT_SUPPORTED
129
+ raise
130
+ end
131
+ end
132
+ end
133
+ end
134
+
135
+ class GetInstance < ClientTest
136
+
137
+ def runtest
138
+
139
+ names = cimcall(:EnumerateInstanceNames,
140
+ 'CIM_Process')
141
+ # Simplest invocation
142
+
143
+ obj = cimcall(:GetInstance, names[0])
144
+
145
+ assert_(obj.is_a?(CIMInstance))
146
+
147
+ # Call with optional namespace path
148
+
149
+ begin
150
+ self.cimcall(:GetInstance,
151
+ names[0],
152
+ :LocalNamespacePath => 'root/pywbem')
153
+
154
+ rescue CIMError => arg
155
+ if arg.code != CIM_ERR_INVALID_NAMESPACE
156
+ raise
157
+ end
158
+ end
159
+ # Try some keyword parameters
160
+
161
+ begin
162
+ self.cimcall(:GetInstance,
163
+ names[0],
164
+ :FooParam => 'FooValue')
165
+ rescue CIMError => arg
166
+ if arg.code != CIM_ERR_NOT_SUPPORTED
167
+ raise
168
+ end
169
+ end
170
+
171
+ # CIMInstanceName with host and namespace set
172
+
173
+ iname = names[0].clone
174
+
175
+ iname.host = 'woot.com'
176
+ iname.namespace = 'smash'
177
+
178
+ self.cimcall(:GetInstance, iname)
179
+
180
+ end
181
+ end
182
+
183
+ class CreateInstance < ClientTest
184
+
185
+ def runtest
186
+
187
+ instance = cimcall(:EnumerateInstances, 'CIM_Process')[0]
188
+
189
+ # Single arg
190
+ begin
191
+ obj = cimcall(:CreateInstance, instance)
192
+ rescue CIMError => arg
193
+ if arg.code != CIM_ERR_NOT_SUPPORTED
194
+ raise
195
+ end
196
+ end
197
+
198
+ # Arg plus namespace
199
+
200
+ begin
201
+ self.cimcall(:CreateInstance,
202
+ instance,
203
+ :LocalNamespacePath => 'root/pywbem')
204
+
205
+ rescue CIMError => arg
206
+ if arg.code != CIM_ERR_INVALID_NAMESPACE
207
+ raise
208
+ end
209
+ end
210
+ end
211
+ end
212
+
213
+ class DeleteInstance < ClientTest
214
+
215
+ def runtest
216
+
217
+ name = cimcall(:EnumerateInstanceNames, 'CIM_Process')[0]
218
+
219
+ # Single arg
220
+ begin
221
+ obj = cimcall(:DeleteInstance, name)
222
+ rescue CIMError => arg
223
+ if arg.code != CIM_ERR_NOT_SUPPORTED
224
+ raise
225
+ end
226
+ end
227
+
228
+ # Arg plus namespace
229
+
230
+ begin
231
+ self.cimcall(:DeleteInstance,
232
+ name,
233
+ :LocalNamespacePath => 'root/pywbem')
234
+
235
+ rescue CIMError => arg
236
+ if arg.code != CIM_ERR_INVALID_NAMESPACE
237
+ raise
238
+ end
239
+ end
240
+
241
+ # CIMInstanceName with host and namespace set
242
+
243
+ iname = name.clone
244
+
245
+ iname.host = 'woot.com'
246
+ iname.namespace = 'smash'
247
+
248
+ begin
249
+ self.cimcall(:DeleteInstance, iname)
250
+ rescue CIMError => arg
251
+ raise if arg.code != CIM_ERR_NOT_SUPPORTED
252
+ end
253
+
254
+ end
255
+ end
256
+
257
+ class ModifyInstance < ClientTest
258
+
259
+ def runtest
260
+
261
+ namedInstance = cimcall(:EnumerateInstances, 'CIM_Process')[0]
262
+
263
+ begin
264
+ obj = cimcall(:ModifyInstance, namedInstance)
265
+ rescue CIMError => arg
266
+ if arg.code != CIM_ERR_NOT_SUPPORTED
267
+ raise
268
+ end
269
+ end
270
+
271
+ # Test without a named instance
272
+ namedInstance2 = namedInstance.clone
273
+ namedInstance2.path = nil
274
+ begin
275
+ obj = cimcall(:ModifyInstance, namedInstance2)
276
+ rescue ArgumentError => arg
277
+ # should throw an argument error
278
+ else
279
+ fail('ArgumentError not thrown')
280
+ end
281
+ end
282
+ end
283
+
284
+ #################################################################
285
+ # Method provider interface tests
286
+ #################################################################
287
+
288
+ class InvokeMethod < ClientTest
289
+
290
+ def runtest
291
+
292
+ # Invoke on classname
293
+
294
+ begin
295
+ cimcall(:InvokeMethod,
296
+ 'FooMethod',
297
+ 'CIM_Process')
298
+ rescue CIMError => arg
299
+ if arg.code != CIM_ERR_METHOD_NOT_AVAILABLE
300
+ raise
301
+ end
302
+ end
303
+
304
+ # Invoke on an InstanceName
305
+
306
+ name = cimcall(:EnumerateInstanceNames, 'CIM_Process')[0]
307
+
308
+ begin
309
+ cimcall(:InvokeMethod,
310
+ 'FooMethod',
311
+ name)
312
+ rescue CIMError => arg
313
+ if arg.code != CIM_ERR_METHOD_NOT_AVAILABLE
314
+ raise
315
+ end
316
+ end
317
+
318
+ # Test remote instance name
319
+ name2 = name.clone
320
+ name2.host = 'woot.com'
321
+ name2.namespace = 'root/cimv2'
322
+
323
+ begin
324
+ self.cimcall(:InvokeMethod,
325
+ 'FooMethod',
326
+ name)
327
+ rescue CIMError => arg
328
+ if arg.code != CIM_ERR_METHOD_NOT_AVAILABLE
329
+ raise
330
+ end
331
+ end
332
+
333
+ # Call with all possible parameter types
334
+
335
+ begin
336
+ cimcall(:InvokeMethod,
337
+ 'FooMethod',
338
+ 'CIM_Process',
339
+ :String => 'Spotty',
340
+ :Uint8 => Uint8.new(1),
341
+ :Sint8 => Sint8.new(2),
342
+ :Uint16 => Uint16.new(3),
343
+ :Uint32 => Uint32.new(4),
344
+ :Sint32 => Sint32.new(5),
345
+ :Uint64 => Uint64.new(6),
346
+ :Sint64 => Sint64.new(7),
347
+ :Real32 => Real32.new(8),
348
+ :Real64 => Real64.new(9),
349
+ :Bool => Boolean.new(true),
350
+ :Date1 => DateTime.now,
351
+ :Date2 => TimeDelta.new(60),
352
+ :Ref => name)
353
+ rescue CIMError => arg
354
+ if arg.code != CIM_ERR_METHOD_NOT_AVAILABLE
355
+ raise
356
+ end
357
+ end
358
+
359
+ # Call with non-empty arrays
360
+
361
+ begin
362
+ cimcall(:InvokeMethod,
363
+ 'FooMethod',
364
+ name,
365
+ :StringArray => 'Spotty',
366
+ :Uint8Array => [Uint8.new(1)],
367
+ :Sint8Array => [Sint8.new(2)],
368
+ :Uint16Array => [Uint16.new(3)],
369
+ :Uint32Array => [Uint32.new(4)],
370
+ :Sint32Array => [Sint32.new(5)],
371
+ :Uint64Array => [Uint64.new(6)],
372
+ :Sint64Array => [Sint64.new(7)],
373
+ :Real32Array => [Real32.new(8)],
374
+ :Real64Array => [Real64.new(9)],
375
+ :BoolArray => [Boolean.new(false), Boolean.new(true)],
376
+ :Date1Array => [DateTime.now, DateTime.now],
377
+ :Date2Array => [TimeDelta.new(0), TimeDelta.new(60)],
378
+ :RefArray => [name, name])
379
+ rescue CIMError => arg
380
+ if arg.code != CIM_ERR_METHOD_NOT_AVAILABLE
381
+ raise
382
+ end
383
+ end
384
+
385
+ # TODO: Call with empty arrays
386
+
387
+ # TODO: Call with weird VALUE.REFERENCE child types:
388
+ # (CLASSPATH|LOCALCLASSPATH|CLASSNAME|INSTANCEPATH|LOCALINSTANCEPATH|
389
+ # INSTANCENAME)
390
+ end
391
+ end
392
+ #################################################################
393
+ # Association provider interface tests
394
+ #################################################################
395
+
396
+ class Associators < ClientTest
397
+ def runtest
398
+ # TODO: Associators call on ClassName and ClassPath
399
+
400
+ css = self.cimcall(:EnumerateInstanceNames, 'CIM_ComputerSystem')
401
+
402
+ css.each do |cs|
403
+ begin
404
+ instances = self.cimcall(:Associators, cs)
405
+ instances.each do |i|
406
+ self.assert_(i.is_a?(CIMInstance))
407
+ n = i.path
408
+ self.assert_(n.is_a?(CIMInstanceName))
409
+ self.assert_(n.host && n.namespace)
410
+ end
411
+ rescue CIMError => arg
412
+ if arg.code != CIM_ERR_NOT_SUPPORTED
413
+ raise
414
+ end
415
+ end
416
+ end
417
+ end
418
+ end
419
+
420
+ class AssociatorNames < ClientTest
421
+ def runtest
422
+ # TODO: AssociatorNames call on ClassName and ClassPath
423
+
424
+ css = self.cimcall(:EnumerateInstanceNames, 'CIM_ComputerSystem')
425
+
426
+ css.each do |cs|
427
+ begin
428
+ names = self.cimcall(:AssociatorNames, cs)
429
+ names.each do |n|
430
+ self.assert_(n.is_a?(CIMInstanceName))
431
+ self.assert_(n.host && n.namespace)
432
+ end
433
+ rescue CIMError => arg
434
+ if arg.code != CIM_ERR_NOT_SUPPORTED
435
+ raise
436
+ end
437
+ end
438
+ end
439
+ end
440
+ end
441
+
442
+ class References < ClientTest
443
+ def runtest
444
+ # TODO: References call on ClassName and ClassPath
445
+
446
+ css = self.cimcall(:EnumerateInstanceNames, 'CIM_ComputerSystem')
447
+
448
+ css.each do |cs|
449
+ begin
450
+ instances = self.cimcall(:References, cs)
451
+ instances.each do |i|
452
+ self.assert_(i.is_a?(CIMInstance))
453
+ n = i.path
454
+ self.assert_(n.is_a?(CIMInstanceName))
455
+ self.assert_(n.host && n.namespace)
456
+ end
457
+ rescue CIMError => arg
458
+ if arg.code != CIM_ERR_NOT_SUPPORTED
459
+ raise
460
+ end
461
+ end
462
+ end
463
+ end
464
+ end
465
+
466
+ class ReferenceNames < ClientTest
467
+ def runtest
468
+ # TODO: ReferenceNames call on ClassName and ClassPath
469
+
470
+ css = self.cimcall(:EnumerateInstanceNames, 'CIM_ComputerSystem')
471
+
472
+ css.each do |cs|
473
+ begin
474
+ names = self.cimcall(:ReferenceNames, cs)
475
+ names.each do |n|
476
+ self.assert_(n.is_a?(CIMInstanceName))
477
+ self.assert_(n.host && n.namespace)
478
+ end
479
+ rescue CIMError => arg
480
+ if arg.code != CIM_ERR_NOT_SUPPORTED
481
+ raise
482
+ end
483
+ end
484
+ end
485
+ end
486
+ end
487
+
488
+ #################################################################
489
+ # Schema manipulation interface tests
490
+ #################################################################
491
+
492
+ module ClassVerifier
493
+ #"""Includable module for testing CIMClass instances."""
494
+
495
+ def verify_property(p)
496
+ assert_(p.value.nil?)
497
+ assert_(p.is_a?(CIMProperty))
498
+ end
499
+
500
+ def verify_qualifier(q)
501
+ assert_(q.name)
502
+ assert_(q.value)
503
+ end
504
+
505
+ def verify_method(m)
506
+ end
507
+
508
+ def verify_class(cl)
509
+
510
+ # Verify simple attributes
511
+ assert_(cl.classname)
512
+
513
+ unless cl.superclass.nil?
514
+ assert_(cl.superclass)
515
+ end
516
+
517
+ # Verify properties
518
+
519
+ assert_(!cl.properties.empty?)
520
+ cl.properties.values.each { |p| self.verify_property(p) }
521
+
522
+ # Verify qualifiers
523
+
524
+ # assert_(!cl.qualifiers.empty?)
525
+ cl.qualifiers.values.each { |p| self.verify_qualifier(p) }
526
+
527
+ # Verify methods
528
+ cl.cim_methods.values.each { |p| self.verify_method(p) }
529
+ end
530
+ end
531
+
532
+ class EnumerateClassNames < ClientTest
533
+ def runtest
534
+ names = cimcall(:EnumerateClassNames)
535
+ names.each { |n| assert_(n.is_a?(String)) }
536
+ end
537
+ end
538
+
539
+ class EnumerateClasses < ClientTest
540
+ include ClassVerifier
541
+
542
+ def runtest
543
+ classes = cimcall(:EnumerateClasses)
544
+ classes.each { |c| assert_(c.is_a?(CIMClass)) }
545
+ classes.each { |c| verify_class(c) }
546
+ end
547
+ end
548
+
549
+ class GetClass < ClientTest
550
+ include ClassVerifier
551
+
552
+ def runtest
553
+ name = cimcall(:EnumerateClassNames)[0]
554
+ cimcall(:GetClass, name)
555
+ end
556
+ end
557
+
558
+ class CreateClass < ClientTest
559
+ def runtest
560
+ raise Comfychair::NotRunError
561
+ end
562
+ end
563
+
564
+ class DeleteClass < ClientTest
565
+ def runtest
566
+ raise Comfychair::NotRunError
567
+ end
568
+ end
569
+
570
+ class ModifyClass < ClientTest
571
+ def runtest
572
+ raise Comfychair::NotRunError
573
+ end
574
+ end
575
+
576
+ #################################################################
577
+ # Property provider interface tests
578
+ #################################################################
579
+
580
+ class GetProperty < ClientTest
581
+ def runtest
582
+ raise Comfychair::NotRunError
583
+ end
584
+ end
585
+
586
+ class SetProperty < ClientTest
587
+ def runtest
588
+ raise Comfychair::NotRunError
589
+ end
590
+ end
591
+
592
+ #################################################################
593
+ # Qualifier provider interface tests
594
+ #################################################################
595
+
596
+ class EnumerateQualifiers < ClientTest
597
+ def runtest
598
+ raise Comfychair::NotRunError
599
+ end
600
+ end
601
+
602
+ class GetQualifier < ClientTest
603
+ def runtest
604
+ raise Comfychair::NotRunError
605
+ end
606
+ end
607
+
608
+ class SetQualifier < ClientTest
609
+ def runtest
610
+ raise Comfychair::NotRunError
611
+ end
612
+ end
613
+
614
+ class DeleteQualifier < ClientTest
615
+ def runtest
616
+ raise Comfychair::NotRunError
617
+ end
618
+ end
619
+
620
+ #################################################################
621
+ # Query provider interface
622
+ #################################################################
623
+
624
+ class ExecuteQuery < ClientTest
625
+ def runtest
626
+ raise Comfychair::NotRunError
627
+ end
628
+ end
629
+
630
+ #################################################################
631
+ # Main function
632
+ #################################################################
633
+
634
+
635
+
636
+ TESTS = [
637
+ # Instance provider interface tests
638
+
639
+ EnumerateInstances,
640
+ EnumerateInstanceNames,
641
+ GetInstance,
642
+ CreateInstance,
643
+ DeleteInstance,
644
+ ModifyInstance,
645
+
646
+ # Method provider interface tests
647
+
648
+ InvokeMethod,
649
+
650
+ # Association provider interface tests
651
+
652
+ Associators,
653
+ AssociatorNames,
654
+ References,
655
+ ReferenceNames,
656
+
657
+ # Schema manipulation interface tests
658
+
659
+ EnumerateClassNames,
660
+ EnumerateClasses,
661
+ GetClass,
662
+ CreateClass,
663
+ DeleteClass,
664
+ ModifyClass,
665
+
666
+ # Property provider interface tests
667
+
668
+ GetProperty,
669
+ SetProperty,
670
+
671
+ # Qualifier provider interface tests
672
+
673
+ EnumerateQualifiers,
674
+ GetQualifier,
675
+ SetQualifier,
676
+ DeleteQualifier,
677
+
678
+ # Query provider interface tests
679
+
680
+ ExecuteQuery
681
+
682
+ ]
683
+
684
+ if __FILE__ == $0
685
+
686
+ if ARGV.size < 2
687
+ print 'Usage: test_cim_operations.rb HOST USERNAME%PASSWORD\n'
688
+ exit(0)
689
+ end
690
+
691
+ Hostinfo.instance.host = ARGV[0]
692
+ Hostinfo.instance.username, Hostinfo.instance.password = ARGV[1].split('%')
693
+
694
+ ARGV.shift
695
+ ARGV.shift
696
+
697
+ Comfychair.main(TESTS)
698
+ end
699
+
700
+ end
701
+ end
702
+