Skip to content

Commit

Permalink
Fixed TypeError when setting 'ssc_dns_servers' in partition module.
Browse files Browse the repository at this point in the history
Details:
- The 'to_unicode()' function that was used for converting the new
  property value did not handle lists of strings, and this property
  is a list of strings. Extended to_unicode() to handle lists
  and tuples of strings.
- Enabled the partition function test cases for the new SSC properties
  that had been commented out so far.

Signed-off-by: Andreas Maier <maiera@de.ibm.com>
  • Loading branch information
andy-maier authored and leopoldjuergen committed Mar 2, 2018
1 parent 98fb88a commit c3cbf78
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
5 changes: 5 additions & 0 deletions docs/changes.rst
Expand Up @@ -30,6 +30,11 @@ Released: not yet

**Bug fixes:**

* Fixed the bug that a TypeError was raised when setting the 'ssc_dns_servers'
property for a Partition. The property value is a list of strings, and
lists of values were not supported previously. Extended the function test
cases for partitions accordingly. (Issue #34).

* Fixed that the "type" property for Partitions could not be specified.
It is valid for Partition creation, and the only restriction is that
its value cannot be changed once the Partition exists. Along with fixing
Expand Down
14 changes: 6 additions & 8 deletions tests/function/test_func_partition.py
Expand Up @@ -886,8 +886,7 @@ def setup_crypto_adapter(self, adapter_props):
({'boot_world_wide_port_name': '0123456789abcdef'}, True),
({'boot_os_specific_parameters': u'fak\u00E9'}, True),
({'boot_iso_ins_file': u'fak\u00E9'}, True),
# TODO: Add tests for SSC properties:
# ({'ssc_boot_selection': 'fake'}, True),
({'ssc_boot_selection': 'fake'}, True),
# allowed create+update properties:
({'description': 'fake'}, True),
Expand Down Expand Up @@ -930,12 +929,11 @@ def setup_crypto_adapter(self, adapter_props):
({'access_diagnostic_sampling': True}, True),
({'permit_des_key_import_functions': False}, True),
({'permit_aes_key_import_functions': False}, True),
# TODO: Add tests for SSC properties:
# ({'ssc_host_name': u'fak\u00E9'}, True),
# ({'ssc_ipv4_gateway': u'fak\u00E9'}, True),
# ({'ssc_dns_servers': u'fak\u00E9''}, True),
# ({'ssc_master_userid': u'fak\u00E9'}, True),
# ({'ssc_master_pw': u'fak\u00E9'}, True),
({'ssc_host_name': u'fak\u00E9'}, True),
({'ssc_ipv4_gateway': u'fak\u00E9'}, True),
({'ssc_dns_servers': [u'fak\u00E9']}, True),
({'ssc_master_userid': u'fak\u00E9'}, True),
({'ssc_master_pw': u'fak\u00E9'}, True),
])
@mock.patch("zhmc_ansible_modules.zhmc_partition.AnsibleModule",
autospec=True)
Expand Down
19 changes: 14 additions & 5 deletions zhmc_ansible_modules/utils/__init__.py
Expand Up @@ -289,18 +289,27 @@ def to_unicode(value):
"""
Return the input value as a unicode string.
The input value may be a binary string or a unicode string, or None.
If it is a binary string, it is encoded to a unicode string using UTF-8.
The input value may be and will result in:
* None -> None
* binary string -> decoded using UTF-8 to unicode string
* unicode string -> unchanged
* list or tuple with items of any of the above -> list with converted items
"""
if isinstance(value, six.binary_type):
if isinstance(value, (list, tuple)):
list_uval = []
for val in value:
uval = to_unicode(val)
list_uval.append(uval)
return list_uval
elif isinstance(value, six.binary_type):
return value.decode('utf-8')
elif isinstance(value, six.text_type):
return value
elif value is None:
return None
else:
raise TypeError("Value is not a binary or unicode string: {!r} {}".
format(value, type(value)))
raise TypeError("Value of {} cannot be converted to unicode: {!r}".
format(type(value), value))


def process_normal_property(
Expand Down

0 comments on commit c3cbf78

Please sign in to comment.