Skip to content
This repository has been archived by the owner on May 1, 2021. It is now read-only.

Fix boolean conditional for fqdn generation. #49

Closed

Conversation

dimosthenes-fioretos
Copy link

Hello,
While using the inventory generation script, I had faced an issue with exceptions on concatenating string with None objects:

Traceback (most recent call last):
  File "oci_inventory.py", line 408, in __init__
    self.build_inventory()
  File "oci_inventory.py", line 1217, in build_inventory
    instances,
  File "/usr/local/Cellar/python@2/2.7.16/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/pool.py", line 253, in map
    return self.map_async(func, iterable, chunksize).get()
  File "/usr/local/Cellar/python@2/2.7.16/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/pool.py", line 572, in get
    raise self._value
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'

unsupported operand type(s) for +: 'NoneType' and 'str'

I traced this to the following code:

            oraclevcn_domain_name = ".oraclevcn.com"
            if not (vnic.hostname_label or subnet.dns_label or vcn.dns_label):
                return None
            fqdn = (
                vnic.hostname_label
                + "."
                + subnet.dns_label
                + "."
                + vcn.dns_label
                + oraclevcn_domain_name
            )
            self.log("FQDN for VNIC: {0} is {1}.".format(vnic.id, fqdn))
            return fqdn

If I understand correctly, here you try to implement the logic of a three way or gate to detect any False values, whereas you should use an "and" gate logic. This can be checked out by the following code snippet:

vals = ["a_value", None]
for s1 in vals:
    for s2 in vals:
        for s3 in vals:
            print "%s\t%s\t%s\t\t%s\t%s" % (s1, s2, s3, bool(s1 and s2 and s3), bool(s1 or s2 or s3))

with output:

Value 1    Value 2    Value 3     AND     OR
--------------------------------------------------
a_value    a_value    a_value     True    True
a_value    a_value    None        False   True
a_value    None       a_value     False   True
a_value    None       None        False   True
None       a_value    a_value     False   True
None       a_value    None        False   True
None       None       a_value     False   True
None       None       None        False   False

This PR solves this issue, in a more pythonic way.

nalsaber added a commit that referenced this pull request May 31, 2019
Added
- Added the following features in existing modules:
    - Added `iscsi_attach_commands` and `iscsi_detach_commands` return values to `oci_volume_attachment` and `oci_volume_attachment_facts` modules.

Fixed
- Fix installation script for Ansible 2.8.0 [issue](#53)
- Fix idempotency when updating a route table entry [issue](#52)
- Fix invalid options error for FQDN generation in inventory script [issue](#49)
- Fix error updating cross connects on a virtual circuit

Co-authored-by: Manoj Meda <manoj.meda@oracle.com>
Co-authored-by: Nabeel Al Saber <nabeel.al.saber@oracle.com>
Co-authored-by: Mike Ross <mike.c.ross@oracle.com>
@manojmeda
Copy link
Member

We appreciate your contribution but the legacy OCI Ansible modules have been deprecated in favour of the new OCI Ansible collection. These are no longer supported and there will be no further updates or fixes. Please migrate to the OCI Ansible collection for improved features and continued support. Refer to the Migration Guide for best practices.

@manojmeda manojmeda closed this May 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants