Skip to content

Commit 07cfd6c

Browse files
authored
update code to python3 (#10903)
* update code to python3 * add changelog frag * rollback adjustment for plugins/lookup/lmdb_kv.py * accept PR suggestion for plugins/module_utils/utm_utils.py * accept PR suggestion for plugins/module_utils/vexata.py * Apply suggestions from code review * Update changelogs/fragments/10903-2to3.yml * Update changelogs/fragments/10903-2to3.yml
1 parent 056633e commit 07cfd6c

File tree

8 files changed

+18
-24
lines changed

8 files changed

+18
-24
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
minor_changes:
2+
- pickle cache plugin - use Python 3 idioms (https://github.com/ansible-collections/community.general/pull/10903).
3+
- counter_enabled callback plugin - use Python 3 idioms (https://github.com/ansible-collections/community.general/pull/10903).
4+
- wsl connection plugin - use Python 3 idioms (https://github.com/ansible-collections/community.general/pull/10903).
5+
- cobbler inventory plugin - use Python 3 idioms (https://github.com/ansible-collections/community.general/pull/10903).
6+
- linode inventory plugin - use Python 3 idioms (https://github.com/ansible-collections/community.general/pull/10903).
7+
- utm_utils module_utils plugin - use Python 3 idioms (https://github.com/ansible-collections/community.general/pull/10903).
8+
- vexata module_utils plugin - use Python 3 idioms (https://github.com/ansible-collections/community.general/pull/10903).

plugins/cache/pickle.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,7 @@
4242
type: float
4343
"""
4444

45-
try:
46-
import cPickle as pickle
47-
except ImportError:
48-
import pickle
45+
import pickle
4946

5047
from ansible.plugins.cache import BaseFileCacheModule
5148

plugins/callback/counter_enabled.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def v2_playbook_on_start(self, playbook):
6767
def v2_playbook_on_play_start(self, play):
6868
name = play.get_name().strip()
6969
if not name:
70-
msg = u"play"
70+
msg = "play"
7171
else:
7272
msg = f"PLAY [{name}]"
7373

plugins/connection/wsl.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,9 +525,9 @@ def _connect(self) -> Connection:
525525
raise AnsibleAuthenticationFailure(msg)
526526
except Exception as e:
527527
msg = to_text(e)
528-
if u'PID check failed' in msg:
528+
if 'PID check failed' in msg:
529529
raise AnsibleError('paramiko version issue, please upgrade paramiko on the machine running ansible')
530-
elif u'Private key file is encrypted' in msg:
530+
elif 'Private key file is encrypted' in msg:
531531
msg = (
532532
f'ssh {self.get_option("remote_user")}@{self.get_options("remote_addr")}:{port} : '
533533
f'{msg}\nTo connect as a different user, use -u <username>.'

plugins/inventory/cobbler.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,10 @@
139139

140140
# xmlrpc
141141
try:
142-
import xmlrpclib as xmlrpc_client
142+
import xmlrpc.client as xmlrpc_client
143143
HAS_XMLRPC_CLIENT = True
144144
except ImportError:
145-
try:
146-
import xmlrpc.client as xmlrpc_client
147-
HAS_XMLRPC_CLIENT = True
148-
except ImportError:
149-
HAS_XMLRPC_CLIENT = False
145+
HAS_XMLRPC_CLIENT = False
150146

151147

152148
class TimeoutTransport (xmlrpc_client.SafeTransport):

plugins/inventory/linode.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,7 @@ def _get_instances_inventory(self):
167167

168168
def _add_groups(self):
169169
"""Add Linode instance groups to the dynamic inventory."""
170-
self.linode_groups = set(
171-
filter(None, [
172-
instance.group
173-
for instance
174-
in self.instances
175-
])
176-
)
170+
self.linode_groups = {instance.group for instance in self.instances if instance.group}
177171

178172
for linode_group in self.linode_groups:
179173
self.inventory.add_group(linode_group)

plugins/module_utils/utm_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def _lookup_entry(self, module, request_url):
183183
result = None
184184
if response is not None:
185185
results = json.loads(response.read())
186-
result = next(iter([d for d in results if d['name'] == module.params.get('name')]), None)
186+
result = next((d for d in results if d['name'] == module.params.get('name')), None)
187187
return info, result
188188

189189
def _clean_result(self, result):

plugins/module_utils/vexata.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@
2020
def get_version(iocs_json):
2121
if not iocs_json:
2222
raise Exception('Invalid IOC json')
23-
active = [x for x in iocs_json if x['mgmtRole']]
24-
if not active:
23+
active = next((x for x in iocs_json if x['mgmtRole']), None)
24+
if active is None:
2525
raise Exception('Unable to detect active IOC')
26-
active = active[0]
2726
ver = active['swVersion']
2827
if ver[0] != 'v':
2928
raise Exception('Illegal version string')

0 commit comments

Comments
 (0)