Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3 compatibility: updated iteritems to items. #31

Merged
merged 9 commits into from
Mar 21, 2020
Merged

Python 3 compatibility: updated iteritems to items. #31

merged 9 commits into from
Mar 21, 2020

Conversation

r-2st
Copy link
Contributor

@r-2st r-2st commented Mar 17, 2020

While trying to bring up the environment ../templates/etc/frr/frr.conf.j2 & ../templates/etc/frr/zebra.conf.j2 errored out with:

fatal: [spine1]: FAILED! => {"changed": false, "msg": "AnsibleUndefinedVariable: 'dict object' has no attribute 'iteritems'"}
fatal: [spine2]: FAILED! => {"changed": false, "msg": "AnsibleUndefinedVariable: 'dict object' has no attribute 'iteritems'"}
fatal: [leaf1]: FAILED! => {"changed": false, "msg": "AnsibleUndefinedVariable: 'dict object' has no attribute 'iteritems'"}
fatal: [leaf2]: FAILED! => {"changed": false, "msg": "AnsibleUndefinedVariable: 'dict object' has no attribute 'iteritems'"}
fatal: [leaf3]: FAILED! => {"changed": false, "msg": "AnsibleUndefinedVariable: 'dict object' has no attribute 'iteritems'"}
fatal: [leaf4]: FAILED! => {"changed": false, "msg": "AnsibleUndefinedVariable: 'dict object' has no attribute 'iteritems'"}
fatal: [compute1]: FAILED! => {"changed": false, "msg": "AnsibleUndefinedVariable: 'dict object' has no attribute 'iteritems'"}
fatal: [compute2]: FAILED! => {"changed": false, "msg": "AnsibleUndefinedVariable: 'dict object' has no attribute 'iteritems'"}

After doing some digging it was due to my installed version of ansible using python3:

>  ansible --version
ansible 2.9.2
  config file = None
  configured module search path = ['/Users/ross.thompson/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.7/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.7.7 (default, Mar 10 2020, 15:43:33) [Clang 11.0.0 (clang-1100.0.33.17)]

In the template files iteritems was changed to items for python3 compatibility. After that the environment was able to launch without issue:

PLAY RECAP *********************************************************************
compute1                   : ok=53   changed=20   unreachable=0    failed=0    skipped=44   rescued=0    ignored=0
compute2                   : ok=53   changed=20   unreachable=0    failed=0    skipped=44   rescued=0    ignored=0
leaf1                      : ok=34   changed=11   unreachable=0    failed=0    skipped=18   rescued=0    ignored=0
leaf2                      : ok=34   changed=11   unreachable=0    failed=0    skipped=18   rescued=0    ignored=0
leaf3                      : ok=34   changed=11   unreachable=0    failed=0    skipped=18   rescued=0    ignored=0
leaf4                      : ok=34   changed=11   unreachable=0    failed=0    skipped=18   rescued=0    ignored=0
spine1                     : ok=34   changed=11   unreachable=0    failed=0    skipped=18   rescued=0    ignored=0
spine2                     : ok=34   changed=11   unreachable=0    failed=0    skipped=18   rescued=0    ignored=0

Did a quick test to confirm python2 backwards compatibility to make sure this change would not break things:

Python 2.7.17 (default, Dec 23 2019, 21:25:33)
[GCC 4.2.1 Compatible Apple LLVM 11.0.0 (clang-1100.0.33.16)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> d={1:'one',2:'two',3:'three'}
>>> print 'd.items():'
d.items():
>>> for k,v in d.items():
...    if d[k] is v: print '\tthey are the same object'
...    else: print '\tthey are different'
...
	they are the same object
	they are the same object
	they are the same object
>>> print 'd.iteritems():'
d.iteritems():
>>> for k,v in d.iteritems():
...    if d[k] is v: print '\tthey are the same object'
...    else: print '\tthey are different'
...
	they are the same object
	they are the same object
	they are the same object
>>> quit()

Please let me know if there are any points that were missed and ill be happy to look into them.
-Ross

@r-2st r-2st mentioned this pull request Mar 17, 2020
@mrlesmithjr mrlesmithjr merged commit de300d7 into mrlesmithjr:master Mar 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants