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.
- data/AUTHORS +1 -0
- data/CHANGELOG +3 -0
- data/LICENSE +339 -0
- data/README +28 -0
- data/Rakefile +146 -0
- data/lib/wbem.rb +23 -0
- data/lib/wbem/cim_constants.rb +50 -0
- data/lib/wbem/cim_http.rb +137 -0
- data/lib/wbem/cim_obj.rb +1148 -0
- data/lib/wbem/cim_operations.rb +571 -0
- data/lib/wbem/cim_types.rb +195 -0
- data/lib/wbem/cim_xml.rb +1428 -0
- data/lib/wbem/tupleparse.rb +1181 -0
- data/lib/wbem/tupletree.rb +138 -0
- data/ruby-wbem.spec +54 -0
- data/testsuite/CIM_DTD_V22.dtd +324 -0
- data/testsuite/comfychair.rb +442 -0
- data/testsuite/runtests.sh +56 -0
- data/testsuite/test_cim_obj.rb +1610 -0
- data/testsuite/test_cim_operations.rb +702 -0
- data/testsuite/test_cim_xml.rb +1495 -0
- data/testsuite/test_nocasehash.rb +248 -0
- data/testsuite/test_tupleparse.rb +208 -0
- data/testsuite/validate.rb +93 -0
- metadata +68 -0
@@ -0,0 +1,248 @@
|
|
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 case-insensitive hash implementation.
|
19
|
+
#
|
20
|
+
|
21
|
+
require "comfychair"
|
22
|
+
require "validate"
|
23
|
+
require "wbem"
|
24
|
+
|
25
|
+
module WBEM
|
26
|
+
module Test
|
27
|
+
|
28
|
+
class TestInit < Comfychair::TestCase
|
29
|
+
def runtest
|
30
|
+
|
31
|
+
# Basic init
|
32
|
+
d = NocaseHash.new()
|
33
|
+
self.assert_(d.length == 0)
|
34
|
+
|
35
|
+
# Initialise from sequence object
|
36
|
+
d = NocaseHash.new([['Dog', 'Cat'], ['Budgie', 'Fish']])
|
37
|
+
self.assert_(d.length == 2)
|
38
|
+
self.assert_(d['Dog'] == 'Cat' || d['Budgie'] == 'Fish')
|
39
|
+
|
40
|
+
# Initialise from mapping object
|
41
|
+
d = NocaseHash.new({'Dog' => 'Cat', 'Budgie' => 'Fish'})
|
42
|
+
self.assert_(d.length == 2)
|
43
|
+
self.assert_(d['Dog'] == 'Cat' || d['Budgie'] == 'Fish')
|
44
|
+
|
45
|
+
# Initialise from kwargs (not really kwargs for ruby)
|
46
|
+
d = NocaseHash.new("Dog" => 'Cat', "Budgie" => 'Fish')
|
47
|
+
self.assert_(d.length == 2)
|
48
|
+
self.assert_(d['Dog'] == 'Cat' || d['Budgie'] == 'Fish')
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class BaseTest < Comfychair::TestCase
|
53
|
+
attr_reader :d
|
54
|
+
def setup
|
55
|
+
@d = NocaseHash.new()
|
56
|
+
@d['Dog'] = 'Cat'
|
57
|
+
@d['Budgie'] = 'Fish'
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
class TestGetitem < BaseTest
|
62
|
+
def runtest
|
63
|
+
self.assert_(self.d['dog'] == 'Cat')
|
64
|
+
self.assert_(self.d['DOG'] == 'Cat')
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
class TestLen < BaseTest
|
69
|
+
def runtest
|
70
|
+
self.assert_(self.d.length == 2)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
class TestSetitem < BaseTest
|
75
|
+
def runtest
|
76
|
+
|
77
|
+
self.d['DOG'] = 'Kitten'
|
78
|
+
self.assert_(self.d['DOG'] == 'Kitten')
|
79
|
+
self.assert_(self.d['Dog'] == 'Kitten')
|
80
|
+
self.assert_(self.d['dog'] == 'Kitten')
|
81
|
+
|
82
|
+
# Check that using a non-string key raises an exception
|
83
|
+
|
84
|
+
begin
|
85
|
+
self.d[1234] = '1234'
|
86
|
+
rescue IndexError
|
87
|
+
else
|
88
|
+
self.fail('IndexError expected')
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
class TestDelitem < BaseTest
|
94
|
+
def runtest
|
95
|
+
self.d.delete('DOG')
|
96
|
+
self.d.delete('budgie')
|
97
|
+
self.assert_(self.d.keys() == [])
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
class TestHasKey < BaseTest
|
102
|
+
def runtest
|
103
|
+
self.assert_(self.d.has_key?('DOG'))
|
104
|
+
self.assert_(self.d.has_key?('budgie'))
|
105
|
+
self.assert_(!self.d.has_key?(1234))
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
class TestKeys < BaseTest
|
110
|
+
def runtest
|
111
|
+
keys = self.d.keys()
|
112
|
+
animals = ['Budgie', 'Dog']
|
113
|
+
animals.each do |a|
|
114
|
+
self.assert_(keys.include?(a))
|
115
|
+
keys.delete(a)
|
116
|
+
end
|
117
|
+
self.assert_(keys == [])
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
class TestValues < BaseTest
|
122
|
+
def runtest
|
123
|
+
values = self.d.values()
|
124
|
+
animals = ['Cat', 'Fish']
|
125
|
+
animals.each do |a|
|
126
|
+
self.assert_(values.include?(a))
|
127
|
+
values.delete(a)
|
128
|
+
end
|
129
|
+
self.assert_(values == [])
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
class TestItems < BaseTest
|
134
|
+
def runtest
|
135
|
+
items = self.d.to_a
|
136
|
+
animals = [['Dog', 'Cat'], ['Budgie', 'Fish']]
|
137
|
+
animals.each do |a|
|
138
|
+
self.assert_(items.include?(a))
|
139
|
+
items.delete(a)
|
140
|
+
end
|
141
|
+
self.assert_(items == [])
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
class TestClear < BaseTest
|
146
|
+
def runtest
|
147
|
+
self.d.clear()
|
148
|
+
self.assert_(self.d.length == 0)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
class TestUpdate < BaseTest
|
153
|
+
def runtest
|
154
|
+
self.d.clear()
|
155
|
+
self.d.update({'Chicken' => 'Ham'})
|
156
|
+
self.assert_(self.d.keys() == ['Chicken'])
|
157
|
+
self.assert_(self.d.values() == ['Ham'])
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
class TestCopy < BaseTest
|
162
|
+
def runtest
|
163
|
+
c = self.d.copy()
|
164
|
+
self.assert_equal(c, self.d)
|
165
|
+
self.assert_(c.is_a?(NocaseHash))
|
166
|
+
c['Dog'] = 'Kitten'
|
167
|
+
self.assert_(self.d['Dog'] == 'Cat')
|
168
|
+
self.assert_(c['Dog'] == 'Kitten')
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
#class TestGet(BaseTest):
|
173
|
+
# def runtest(self):
|
174
|
+
# self.assert_(self.d.get('Dog', 'Chicken') == 'Cat')
|
175
|
+
# self.assert_(self.d.get('Ningaui') == None)
|
176
|
+
# self.assert_(self.d.get('Ningaui', 'Chicken') == 'Chicken')
|
177
|
+
#
|
178
|
+
#class TestSetDefault < BaseTest
|
179
|
+
# def runtest
|
180
|
+
# self.d.setdefault('Dog', 'Kitten')
|
181
|
+
# self.assert_(self.d['Dog'] == 'Cat')
|
182
|
+
# self.d.setdefault('Ningaui', 'Chicken')
|
183
|
+
# self.assert_(self.d['Ningaui'] == 'Chicken')
|
184
|
+
|
185
|
+
#class TestPopItem < BaseTest
|
186
|
+
# def runtest
|
187
|
+
# pass
|
188
|
+
|
189
|
+
class TestEqual < BaseTest
|
190
|
+
def runtest
|
191
|
+
c = NocaseHash.new({'dog' => 'Cat', 'Budgie' => 'Fish'})
|
192
|
+
self.assert_(self.d == c)
|
193
|
+
c['Budgie'] = 'fish'
|
194
|
+
self.assert_(self.d != c)
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
class TestContains < BaseTest
|
199
|
+
def runtest
|
200
|
+
self.assert_(self.d.include?('dog'))
|
201
|
+
self.assert_(self.d.include?('Dog'))
|
202
|
+
self.assert_(!self.d.include?('Cat'))
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
#class TestIterkeys < BaseTest
|
207
|
+
# def runtest
|
208
|
+
# for k in self.d.iterkeys():
|
209
|
+
# self.assert_(k in ['Budgie', 'Dog'])
|
210
|
+
#
|
211
|
+
#class TestItervalues < BaseTest
|
212
|
+
# def runtest
|
213
|
+
# for v in self.d.itervalues():
|
214
|
+
# self.assert_(v in ['Cat', 'Fish'])
|
215
|
+
#
|
216
|
+
#class TestIteritems < BaseTest
|
217
|
+
# def runtest
|
218
|
+
# for i in self.d.iteritems():
|
219
|
+
# self.assert_(i in [('Budgie', 'Fish'), ('Dog', 'Cat')])
|
220
|
+
|
221
|
+
TESTS = [
|
222
|
+
TestInit,
|
223
|
+
TestGetitem,
|
224
|
+
TestSetitem,
|
225
|
+
TestDelitem,
|
226
|
+
TestLen,
|
227
|
+
TestHasKey,
|
228
|
+
TestKeys,
|
229
|
+
TestValues,
|
230
|
+
TestItems,
|
231
|
+
TestClear,
|
232
|
+
TestUpdate,
|
233
|
+
TestCopy,
|
234
|
+
# TestGet,
|
235
|
+
# TestSetDefault,
|
236
|
+
# TestPopItem,
|
237
|
+
TestEqual,
|
238
|
+
TestContains,
|
239
|
+
# TestIterkeys,
|
240
|
+
# TestItervalues,
|
241
|
+
# TestIteritems,
|
242
|
+
]
|
243
|
+
|
244
|
+
if __FILE__ == $0
|
245
|
+
Comfychair.main(TESTS)
|
246
|
+
end
|
247
|
+
end
|
248
|
+
end
|
@@ -0,0 +1,208 @@
|
|
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 XML parsing routines.
|
19
|
+
#
|
20
|
+
# These tests check that we don't lose any information by converting
|
21
|
+
# an object to XML then parsing it again. The round trip should
|
22
|
+
# produce an object that is identical to the one we started with.
|
23
|
+
#
|
24
|
+
require "comfychair"
|
25
|
+
require "validate"
|
26
|
+
require "wbem"
|
27
|
+
|
28
|
+
module WBEM
|
29
|
+
module Test
|
30
|
+
|
31
|
+
class TupleTest < Comfychair::TestCase
|
32
|
+
|
33
|
+
def test(obj)
|
34
|
+
|
35
|
+
# Convert object to xml
|
36
|
+
|
37
|
+
xml = obj.tocimxml().toxml()
|
38
|
+
self.log('before: %s' % xml)
|
39
|
+
|
40
|
+
# Parse back to an object
|
41
|
+
result = WBEM.parse_any(WBEM.xml_to_tupletree(xml))
|
42
|
+
self.log('after: %s' % result.tocimxml().toxml())
|
43
|
+
|
44
|
+
# Assert that the before and after objects should be equal
|
45
|
+
|
46
|
+
self.assert_equal(obj, result)
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
class ParseCIMInstanceName < TupleTest
|
52
|
+
#"""Test parsing of CIMInstanceName objects."""
|
53
|
+
|
54
|
+
def runtest
|
55
|
+
self.test(CIMInstanceName.new('CIM_Foo'))
|
56
|
+
self.test(CIMInstanceName.new('CIM_Foo',
|
57
|
+
{'Name' => 'Foo', 'Chicken' => 'Ham'}))
|
58
|
+
|
59
|
+
self.test(CIMInstanceName.new('CIM_Foo', {'Name' => 'Foo',
|
60
|
+
'Number' => 42,
|
61
|
+
'Boolean' => false,
|
62
|
+
'Ref' => CIMInstanceName.new('CIM_Bar')}))
|
63
|
+
self.test(CIMInstanceName.new('CIM_Foo', {'Name' => 'Foo'},
|
64
|
+
nil, 'root/cimv2'))
|
65
|
+
|
66
|
+
self.test(CIMInstanceName.new('CIM_Foo', {'Name' => 'Foo'},
|
67
|
+
'woot.com',
|
68
|
+
'root/cimv2'))
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
class ParseCIMInstance < TupleTest
|
73
|
+
#"""Test parsing of CIMInstance objects."""
|
74
|
+
|
75
|
+
def runtest
|
76
|
+
|
77
|
+
self.test(CIMInstance.new('CIM_Foo'))
|
78
|
+
|
79
|
+
self.test(CIMInstance.new('CIM_Foo',{'string' => 'string',
|
80
|
+
'uint8' => Uint8.new(0),
|
81
|
+
'uint8array' => [Uint8.new(1), Uint8.new(2)],
|
82
|
+
'ref' => CIMInstanceName.new('CIM_Bar')}))
|
83
|
+
|
84
|
+
self.test(CIMInstance.new('CIM_Foo',
|
85
|
+
{'InstanceID' => '1234'},
|
86
|
+
{},
|
87
|
+
CIMInstanceName.new('CIM_Foo',
|
88
|
+
{'InstanceID' => '1234'})))
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
class ParseCIMClass < TupleTest
|
93
|
+
#"""Test parsing of CIMClass objects."""
|
94
|
+
|
95
|
+
def runtest
|
96
|
+
|
97
|
+
self.test(CIMClass.new('CIM_Foo'))
|
98
|
+
self.test(CIMClass.new('CIM_Foo', nil, nil, nil, 'CIM_bar'))
|
99
|
+
|
100
|
+
self.test(
|
101
|
+
CIMClass.new(
|
102
|
+
'CIM_CollectionInSystem',
|
103
|
+
{'Parent' => CIMProperty.new('Parent', nil, 'reference', nil, nil, nil,
|
104
|
+
{'Key' => CIMQualifier.new('Key',
|
105
|
+
true,
|
106
|
+
nil,
|
107
|
+
false),
|
108
|
+
'Aggregate' => CIMQualifier.new('Aggregate',
|
109
|
+
true,
|
110
|
+
nil,
|
111
|
+
false),
|
112
|
+
'Max' => CIMQualifier.new('Max',
|
113
|
+
Uint32.new(1))},
|
114
|
+
'CIM_System'),
|
115
|
+
'Child' => CIMProperty.new('Child', nil, 'reference', nil, nil, nil,
|
116
|
+
{'Key' => CIMQualifier.new('Key',
|
117
|
+
true,
|
118
|
+
nil,
|
119
|
+
false)},
|
120
|
+
'CIM_Collection')},
|
121
|
+
{'ASSOCIATION' => CIMQualifier.new('ASSOCIATION', true, nil, false),
|
122
|
+
'Aggregation' => CIMQualifier.new('Aggregation', true, nil, false),
|
123
|
+
'Version' => CIMQualifier.new('Version', '2.6.0', nil, nil, false, nil, false),
|
124
|
+
'Description' => CIMQualifier.new('Description',
|
125
|
+
'CIM_CollectionInSystem is an association used to establish a parent-child relationship between a collection and an \'owning\' System such as an AdminDomain or ComputerSystem. A single collection should not have both a CollectionInOrganization and a CollectionInSystem association.',
|
126
|
+
nil, nil, nil, nil, true)}
|
127
|
+
))
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
class ParseCIMProperty < TupleTest
|
132
|
+
#"""Test parsing of CIMProperty objects."""
|
133
|
+
|
134
|
+
def runtest
|
135
|
+
|
136
|
+
# Single-valued properties
|
137
|
+
|
138
|
+
self.test(CIMProperty.new('Spotty', 'Foot'))
|
139
|
+
self.test(CIMProperty.new('Age', Uint16.new(32)))
|
140
|
+
self.test(CIMProperty.new('Age', nil, 'uint16', nil, nil, nil,
|
141
|
+
{'Key' => CIMQualifier.new('Key', true)}))
|
142
|
+
|
143
|
+
# Property arrays
|
144
|
+
|
145
|
+
self.test(CIMProperty.new('Foo', ['a', 'b', 'c']))
|
146
|
+
self.test(CIMProperty.new('Foo', nil, 'string'))
|
147
|
+
self.test(CIMProperty.new('Foo', [1, 2, 3].collect {|x| Uint8.new(x)},
|
148
|
+
nil, nil, nil, nil,
|
149
|
+
{'Key' => CIMQualifier.new('Key', true)}))
|
150
|
+
|
151
|
+
# Reference properties
|
152
|
+
|
153
|
+
self.test(CIMProperty.new('Foo', nil, 'reference'))
|
154
|
+
self.test(CIMProperty.new('Foo', CIMInstanceName.new('CIM_Foo')))
|
155
|
+
self.test(CIMProperty.new('Foo', CIMInstanceName.new('CIM_Foo'),
|
156
|
+
nil, nil, nil, nil,
|
157
|
+
{'Key' => CIMQualifier.new('Key', true)}))
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
class ParseCIMParameter < TupleTest
|
162
|
+
#"""Test parsing of CIMParameter objects."""
|
163
|
+
|
164
|
+
def runtest
|
165
|
+
|
166
|
+
# Single-valued parameters
|
167
|
+
|
168
|
+
self.test(CIMParameter.new('Param', 'string'))
|
169
|
+
self.test(CIMParameter.new('Param', 'string', nil, nil, nil,
|
170
|
+
{'Key' => CIMQualifier.new('Key', true)}))
|
171
|
+
|
172
|
+
# Reference parameters
|
173
|
+
|
174
|
+
self.test(CIMParameter.new('RefParam', 'reference'))
|
175
|
+
self.test(CIMParameter.new('RefParam', 'reference', 'CIM_Foo'))
|
176
|
+
self.test(CIMParameter.new('RefParam', 'reference', 'CIM_Foo', nil, nil,
|
177
|
+
{'Key' => CIMQualifier.new('Key', true)}))
|
178
|
+
|
179
|
+
# Array parameters
|
180
|
+
|
181
|
+
self.test(CIMParameter.new('Array', 'string', nil, true))
|
182
|
+
self.test(CIMParameter.new('Array', 'string', nil, true, 10))
|
183
|
+
self.test(CIMParameter.new('Array', 'string', nil, true, 10,
|
184
|
+
{'Key' => CIMQualifier.new('Key', true)}))
|
185
|
+
|
186
|
+
# Reference array parameters
|
187
|
+
|
188
|
+
self.test(CIMParameter.new('RefArray', 'reference', nil, true))
|
189
|
+
self.test(CIMParameter.new('RefArray', 'reference', 'CIM_Foo', true))
|
190
|
+
self.test(CIMParameter.new('RefArray', 'reference', 'CIM_Foo', true, 10))
|
191
|
+
self.test(CIMParameter.new('RefArray', 'reference', 'CIM_Foo', true, 10,
|
192
|
+
{'Key' => CIMQualifier.new('Key', true)}))
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
TESTS = [
|
197
|
+
ParseCIMInstanceName,
|
198
|
+
ParseCIMInstance,
|
199
|
+
ParseCIMClass,
|
200
|
+
ParseCIMProperty,
|
201
|
+
ParseCIMParameter,
|
202
|
+
]
|
203
|
+
|
204
|
+
if __FILE__ == $0
|
205
|
+
Comfychair.main(TESTS)
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|