Skip to content

Commit

Permalink
Merge pull request #1045 from pywbem/andy/#1031-property-array-size
Browse files Browse the repository at this point in the history
Fixes #1031: (7) Added support for ARRAYSIZE to PROPERTY.ARRAY in tupleparser; test cases
  • Loading branch information
andy-maier committed Feb 5, 2018
2 parents f410478 + 470be9e commit 3110d2e
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 50 deletions.
5 changes: 5 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,11 @@ Bug fixes
already had been supported for array values sent to the server, or in CIM-XML
created by `toximcml()` methods (Issue #1022).

* Fixed the issue that the size of a fixed-size array property declaration was
ignored when retrieving classes from CIM operations. It is now represented
in the `array_size` attribute of the returned `CIMProperty` objects.
(Issue #1031).

Cleanup
^^^^^^^

Expand Down
83 changes: 36 additions & 47 deletions pywbem/tupleparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,6 @@
from __future__ import absolute_import
import re
import six
try:
from collections import OrderedDict
except ImportError:
from ordereddict import OrderedDict

from .cim_obj import CIMInstance, CIMInstanceName, CIMClass, CIMClassName, \
CIMProperty, CIMMethod, CIMParameter, CIMQualifier, \
Expand Down Expand Up @@ -1122,10 +1118,10 @@ def parse_qualifier_declaration(tup_tree):
except KeyError:
is_array = False

try:
array_size = int(attrl['ARRAYSIZE'])
except KeyError:
array_size = None
array_size = attrl.get('ARRAYSIZE', None)
if array_size is not None:
# TODO 2/18 AM #1044: Clarify if hex support is needed.
array_size = int(array_size)

flavors = {}
for flavor in ['OVERRIDABLE', 'TOSUBCLASS', 'TOINSTANCE', 'TRANSLATABLE']:
Expand Down Expand Up @@ -1236,10 +1232,6 @@ def parse_property(tup_tree):
'EMBEDDEDOBJECT'],
['QUALIFIER', 'VALUE'])

quals = OrderedDict()
for qual in list_of_matching(tup_tree, ['QUALIFIER']):
quals[qual.name] = qual

attrl = attrs(tup_tree)
try:
val = unpack_value(tup_tree)
Expand All @@ -1249,6 +1241,8 @@ def parse_property(tup_tree):
"'PROPERTY' element with name %r: %s" %
(attrl['NAME'], msg))

qualifiers = list_of_matching(tup_tree, ['QUALIFIER'])

embedded_object = None
if 'EmbeddedObject' in attrl or 'EMBEDDEDOBJECT' in attrl:
try:
Expand All @@ -1264,7 +1258,7 @@ def parse_property(tup_tree):
class_origin=attrl.get('CLASSORIGIN', None),
propagated=unpack_boolean(attrl.get('PROPAGATED',
'false')),
qualifiers=quals,
qualifiers=qualifiers,
embedded_object=embedded_object)


Expand All @@ -1288,19 +1282,22 @@ def parse_property_array(tup_tree):
['QUALIFIER', 'VALUE.ARRAY'])
# TODO: Remove 'REFERENCECLASS' from attrs list, above.

quals = OrderedDict()
for qual in list_of_matching(tup_tree, ['QUALIFIER']):
quals[qual.name] = qual

values = unpack_value(tup_tree)
attrl = attrs(tup_tree)

qualifiers = list_of_matching(tup_tree, ['QUALIFIER'])

array_size = attrl.get('ARRAYSIZE', None)
if array_size is not None:
# TODO 2/18 AM #1044: Clarify if hex support is needed.
array_size = int(array_size)

embedded_object = None
if 'EmbeddedObject' in attrl or 'EMBEDDEDOBJECT' in attrl:
try:
embedded_object = attrl['EmbeddedObject']
except KeyError:
embedded_object = attrl['EMBEDDEDOBJECT']

if embedded_object is not None:
values = parse_embeddedObject(values)

Expand All @@ -1310,10 +1307,10 @@ def parse_property_array(tup_tree):
class_origin=attrl.get('CLASSORIGIN', None),
propagated=unpack_boolean(attrl.get('PROPAGATED',
'false')),
qualifiers=quals,
qualifiers=qualifiers,
is_array=True,
array_size=array_size,
embedded_object=embedded_object)
# TODO #1031: Add support and tests for arraysize

return obj

Expand Down Expand Up @@ -1345,14 +1342,12 @@ def parse_property_reference(tup_tree):
"'VALUE.REFERENCE' (allowed are zero or one)" %
name(tup_tree))

quals = OrderedDict()
for qual in list_of_matching(tup_tree, ['QUALIFIER']):
quals[qual.name] = qual

attrl = attrs(tup_tree)

qualifiers = list_of_matching(tup_tree, ['QUALIFIER'])

pref = CIMProperty(attrl['NAME'], value, type='reference',
qualifiers=quals,
qualifiers=qualifiers,
reference_class=attrl.get('REFERENCECLASS', None),
class_origin=attrl.get('CLASSORIGIN', None),
propagated=unpack_boolean(attrl.get('PROPAGATED',
Expand All @@ -1379,14 +1374,14 @@ def parse_method(tup_tree):
['QUALIFIER', 'PARAMETER', 'PARAMETER.REFERENCE',
'PARAMETER.ARRAY', 'PARAMETER.REFARRAY'])

qualifiers = list_of_matching(tup_tree, ['QUALIFIER'])
attrl = attrs(tup_tree)

parameters = list_of_matching(tup_tree, ['PARAMETER',
'PARAMETER.REFERENCE',
'PARAMETER.ARRAY',
'PARAMETER.REFARRAY'])

attrl = attrs(tup_tree)
qualifiers = list_of_matching(tup_tree, ['QUALIFIER'])

# TODO 2/18 AM #1038: Clarify how to deal with omitted TYPE of METHOD
# In DSP0201, TYPE is optional and omitting it means a void return
Expand Down Expand Up @@ -1415,14 +1410,12 @@ def parse_parameter(tup_tree):

check_node(tup_tree, 'PARAMETER', ['NAME', 'TYPE'], [], ['QUALIFIER'])

quals = OrderedDict()
for qual in list_of_matching(tup_tree, ['QUALIFIER']):
quals[qual.name] = qual

attrl = attrs(tup_tree)

qualifiers = list_of_matching(tup_tree, ['QUALIFIER'])

return CIMParameter(attrl['NAME'], type=attrl['TYPE'],
qualifiers=quals)
qualifiers=qualifiers)


def parse_parameter_reference(tup_tree):
Expand All @@ -1438,16 +1431,14 @@ def parse_parameter_reference(tup_tree):
check_node(tup_tree, 'PARAMETER.REFERENCE', ['NAME'], ['REFERENCECLASS'],
['QUALIFIER'])

quals = OrderedDict()
for qual in list_of_matching(tup_tree, ['QUALIFIER']):
quals[qual.name] = qual

attrl = attrs(tup_tree)

qualifiers = list_of_matching(tup_tree, ['QUALIFIER'])

return CIMParameter(attrl['NAME'],
type='reference',
reference_class=attrl.get('REFERENCECLASS', None),
qualifiers=quals)
qualifiers=qualifiers)


def parse_parameter_array(tup_tree):
Expand All @@ -1464,21 +1455,20 @@ def parse_parameter_array(tup_tree):
check_node(tup_tree, 'PARAMETER.ARRAY', ['NAME', 'TYPE'],
['ARRAYSIZE'], ['QUALIFIER'])

quals = OrderedDict()
for qual in list_of_matching(tup_tree, ['QUALIFIER']):
quals[qual.name] = qual

attrl = attrs(tup_tree)

array_size = attrl.get('ARRAYSIZE', None)
if array_size is not None:
# TODO 2/18 AM #1044: Clarify if hex support is needed.
array_size = int(array_size)

qualifiers = list_of_matching(tup_tree, ['QUALIFIER'])

return CIMParameter(attrl['NAME'],
type=attrl['TYPE'],
is_array=True,
array_size=array_size,
qualifiers=quals)
qualifiers=qualifiers)


def parse_parameter_refarray(tup_tree):
Expand All @@ -1495,21 +1485,20 @@ def parse_parameter_refarray(tup_tree):
check_node(tup_tree, 'PARAMETER.REFARRAY', ['NAME'],
['REFERENCECLASS', 'ARRAYSIZE'], ['QUALIFIER'])

quals = OrderedDict()
for qual in list_of_matching(tup_tree, ['QUALIFIER']):
quals[qual.name] = qual

attrl = attrs(tup_tree)

array_size = attrl.get('ARRAYSIZE', None)
if array_size is not None:
# TODO 2/18 AM #1044: Clarify if hex support is needed.
array_size = int(array_size)

qualifiers = list_of_matching(tup_tree, ['QUALIFIER'])

return CIMParameter(attrl['NAME'], 'reference',
is_array=True,
reference_class=attrl.get('REFERENCECLASS', None),
array_size=array_size,
qualifiers=quals)
qualifiers=qualifiers)


#
Expand Down
3 changes: 2 additions & 1 deletion pywbem/tupletree.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
The NAME is the name of the element.
The ATTRS are a name-value dictionary of element attributes, not pres. order.
The ATTRS are a name-value dictionary of element attributes, not preserving
order.
The CONTENTS is a list of child elements, preserving order.
Expand Down
17 changes: 15 additions & 2 deletions testsuite/test_tupleparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -6020,7 +6020,7 @@ def test_tupleparse_roundtrip(
None, None, True
),
(
"PROPERTY.ARRAY with ARRAYSIZE attribute",
"PROPERTY.ARRAY fixed array",
dict(
xml_str=''
'<PROPERTY.ARRAY NAME="Foo" TYPE="string" ARRAYSIZE="10"/>',
Expand All @@ -6029,7 +6029,7 @@ def test_tupleparse_roundtrip(
propagated=False
),
),
None, None, False # TODO 1/18 AM #1031: Enable once ARRAYSIZE implem.
None, None, True
),
(
"PROPERTY.ARRAY with missing required attribute TYPE",
Expand Down Expand Up @@ -8594,6 +8594,19 @@ def test_tupleparse_roundtrip(
),
None, None, True
),
(
"QUALIFIER.DECLARATION fixed array",
dict(
xml_str=''
'<QUALIFIER.DECLARATION NAME="Qual" TYPE="string" ARRAYSIZE="10"'
' ISARRAY="true"/>',
exp_result=CIMQualifierDeclaration(
'Qual', value=None, type='string',
is_array=True, array_size=10,
),
),
None, None, True
),
(
"QUALIFIER.DECLARATION with OVERRIDABLE attribute (true)",
dict(
Expand Down

0 comments on commit 3110d2e

Please sign in to comment.