/
test_profile_snia_server.py
277 lines (231 loc) · 11.5 KB
/
test_profile_snia_server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
"""
End2end tests for SNIA 'Server' profile.
"""
from __future__ import absolute_import, print_function
import warnings
from .utils.pytest_extensions import ProfileTest, skip_if_unsupported_capability
from .utils.assertions import assert_number_of_instances_equal, \
assert_number_of_instances_minimum, assert_instance_of, \
assert_instance_consistency, assert_mandatory_properties, \
assert_property_one_of, assert_property_contains
from .utils.utils import server_func_asserted, server_prop_asserted
# Note: The wbem_connection fixture uses the es_server fixture, and
# due to the way py.test searches for fixtures, it also need to be imported.
# pylint: disable=unused-import,wrong-import-order
from .utils.pytest_extensions import wbem_connection # noqa: F401
from pytest_easy_server import es_server # noqa: F401
from .utils.pytest_extensions import assert_association_func # noqa: F401
# pylint: enable=unused-import,wrong-import-order
# pylint: disable=wrong-import-position, wrong-import-order, invalid-name
from ..utils import import_installed
pywbem = import_installed('pywbem')
from pywbem import ToleratedServerIssueWarning # noqa: E402
from pywbem._utils import _format # noqa: E402
# pylint: enable=wrong-import-position, wrong-import-order, invalid-name
class Test_SNIA_Server_Profile(ProfileTest):
"""
All end2end tests for SNIA 'Server' profile.
"""
def init_profile(self, conn): # pylint: disable=arguments-differ
super(Test_SNIA_Server_Profile, self).init_profile(
conn, profile_org='SNIA', profile_name='Server')
def test_get_central_instances(self, wbem_connection): # noqa: F811
# pylint: disable=redefined-outer-name
"""
Test WBEMServer.get_central_instances() for this profile.
"""
skip_if_unsupported_capability(wbem_connection, 'snia-server')
self.init_profile(wbem_connection)
central_inst_paths = server_func_asserted(
self.server, 'get_central_instances',
profile_path=self.profile_inst.path,
central_class=self.profile_definition['central_class'],
scoping_class=self.profile_definition['scoping_class'],
scoping_path=self.profile_definition['scoping_path'],
reference_direction=self.profile_definition['reference_direction'])
central_insts_msg = _format(
"central instances of profile {0} {1!A} (version: {2})",
self.profile_definition['registered_org'],
self.profile_definition['registered_name'],
self.profile_definition['registered_version'] or 'any')
# Check that there is just one central instance for this profile
assert_number_of_instances_equal(
wbem_connection, central_inst_paths, central_insts_msg, 1)
def test_central_instance(self, wbem_connection): # noqa: F811
# pylint: disable=redefined-outer-name
"""
Test the CIM_ObjectManager central instance.
"""
skip_if_unsupported_capability(wbem_connection, 'snia-server')
self.init_profile(wbem_connection)
self.init_central_instances()
central_inst_path = self.central_inst_paths[0]
assert_instance_of(
wbem_connection, central_inst_path, 'CIM_ObjectManager')
central_inst = self.conn.GetInstance(
central_inst_path,
asserted=True)
assert_instance_of(
wbem_connection, central_inst, 'CIM_ObjectManager')
assert_instance_consistency(
wbem_connection, central_inst, central_inst_path)
assert_mandatory_properties(
wbem_connection, central_inst,
['SystemCreationClassName', 'SystemName', 'CreationClassName',
'Name', 'ElementName', 'Description', 'OperationalStatus',
'Started'])
def test_Namespace(
self, assert_association_func, wbem_connection): # noqa: F811
# pylint: disable=redefined-outer-name
"""
Test the associated CIM_Namespace instances.
"""
skip_if_unsupported_capability(wbem_connection, 'snia-server')
self.init_profile(wbem_connection)
self.init_central_instances()
central_inst_path = self.central_inst_paths[0]
far_insts, _ = assert_association_func(
conn=wbem_connection,
profile_id=self.profile_id,
source_path=central_inst_path,
source_role='Antecedent',
assoc_class='CIM_NamespaceInManager',
far_role='Dependent',
far_class='CIM_Namespace')
far_insts_msg = _format(
"CIM_Namespace instances associated via "
"CIM_NamespaceInManager to "
"central instance of profile {0} {1!A} (version {2})",
self.profile_definition['registered_org'],
self.profile_definition['registered_name'],
self.profile_definition['registered_version'] or 'any')
for inst in far_insts:
assert_mandatory_properties(
wbem_connection, inst,
['SystemCreationClassName', 'SystemName',
'ObjectManagerCreationClassName', 'ObjectManagerName',
'CreationClassName', 'Name', 'ClassType'])
# Check that they are the namespaces determined by WBEMServer.
# Because the Interop namespace is added if missing, we need to also
# do that here.
inst_names = [inst['Name'].lower() for inst in far_insts]
interop_ns_lower = server_prop_asserted(
self.server, 'interop_ns').lower()
if interop_ns_lower not in inst_names:
inst_names.append(interop_ns_lower)
# pylint: disable=not-an-iterable
determined_names = [ns.lower()
for ns in server_prop_asserted(
self.server, 'namespaces')]
if set(inst_names) != set(determined_names):
raise AssertionError(
_format("Server {0} at {1}: The namespaces ({2}) of the {3} "
"do not match the namespaces ({4}) determined by the "
"WBEMServer class",
wbem_connection.es_server.nickname,
wbem_connection.url,
set(inst_names), far_insts_msg,
set(determined_names)))
def test_ObjectManagerCommunicationMechanism(
self, assert_association_func, wbem_connection): # noqa: F811
# pylint: disable=redefined-outer-name
"""
Test the associated CIM_ObjectManagerCommunicationMechanism instances.
"""
skip_if_unsupported_capability(wbem_connection, 'snia-server')
self.init_profile(wbem_connection)
self.init_central_instances()
central_inst_path = self.central_inst_paths[0]
far_insts, _ = assert_association_func(
conn=wbem_connection,
profile_id=self.profile_id,
source_path=central_inst_path,
source_role='Antecedent',
assoc_class='CIM_CommMechanismForManager',
far_role='Dependent',
far_class='CIM_ObjectManagerCommunicationMechanism')
far_insts_msg = _format(
"CIM_ObjectManagerCommunicationMechanism instances associated via "
"CIM_CommMechanismForManager to "
"central instance of profile {0} {1!A} (version {2})",
self.profile_definition['registered_org'],
self.profile_definition['registered_name'],
self.profile_definition['registered_version'] or 'any')
for inst in far_insts:
assert_mandatory_properties(
wbem_connection, inst,
['SystemCreationClassName', 'SystemName', 'CreationClassName',
'Name', 'ElementName', 'CommunicationMechanism',
'FunctionalProfilesSupported', 'MultipleOperationsSupported',
'AuthenticationMechanismsSupported'])
assert_property_one_of(
wbem_connection, inst,
'CommunicationMechanism', [2, 4])
# Note: The SNIA Server profile mandates that the
# FunctionalProfilesSupported property is 0 (Unknown), but it
# is an array property. Even after fixing this to an array
# with one item 0, it does not make much sense to require
# that that support is not implemented just because the
# profile does not use it.
# TODO 2018-12 AM: This should be brought back to SMI-S.
try:
assert_property_contains(
wbem_connection, inst,
'FunctionalProfilesSupported', 0)
except AssertionError as exc:
warnings.warn("Downgraded the following test failure to a "
"warning: {0}: {1}".
format(exc.__class__.__name__, exc),
ToleratedServerIssueWarning)
# Note: The SNIA Server profile mandates that the
# MultipleOperationsSupported property is False, but it does
# not make much sense to require that that support is not
# implemented just because the profile does not use it.
# TODO 2018-12 AM: This should be brought back to SMI-S.
try:
assert_property_one_of(
wbem_connection, inst,
'MultipleOperationsSupported', [False])
except AssertionError as exc:
warnings.warn("Downgraded the following test failure to a "
"warning: {0}: {1}".
format(exc.__class__.__name__, exc),
ToleratedServerIssueWarning)
# Check that there is at least one associated istance
assert_number_of_instances_minimum(
wbem_connection, far_insts, far_insts_msg, 1)
def test_System(
self, assert_association_func, wbem_connection): # noqa: F811
# pylint: disable=redefined-outer-name
"""
Test the associated CIM_System instance.
"""
skip_if_unsupported_capability(wbem_connection, 'snia-server')
self.init_profile(wbem_connection)
self.init_central_instances()
central_inst_path = self.central_inst_paths[0]
far_insts, _ = assert_association_func(
conn=wbem_connection,
profile_id=self.profile_id,
source_path=central_inst_path,
source_role='Dependent',
assoc_class='CIM_HostedService',
far_role='Antecedent',
far_class='CIM_System')
far_insts_msg = _format(
"CIM_System instances associated via CIM_HostedService to "
"central instance of profile {0} {1!A} (version {2})",
self.profile_definition['registered_org'],
self.profile_definition['registered_name'],
self.profile_definition['registered_version'] or 'any')
for inst in far_insts:
assert_mandatory_properties(
wbem_connection, inst,
['CreationClassName', 'Name', 'NameFormat', 'Description',
'ElementName', 'OperationalStatus'])
assert_property_one_of(
wbem_connection, inst,
'NameFormat', ['IP', 'WWN', 'Other'])
# Check that there is one associated CIM_System instance
assert_number_of_instances_equal(
wbem_connection, far_insts, far_insts_msg, 1)