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

lxc_container: open files as text, fixes #30571 #30572

Merged
merged 4 commits into from
Sep 28, 2017
Merged

Conversation

bit
Copy link
Contributor

@bit bit commented Sep 19, 2017

SUMMARY

fix python3 support

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

modules/cloud/lxc/lxc_container.py

ANSIBLE VERSION
ansible 2.5.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/j/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/j/.local/lib/python3.5/site-packages/ansible-2.5.0-py3.5.egg/ansible
  executable location = /home/j/.local/bin/ansible
  python version = 3.5.4 (default, Sep  5 2017, 18:32:10) [GCC 7.2.0]

@ansibot
Copy link
Contributor

ansibot commented Sep 19, 2017

@ansibot ansibot added affects_2.5 This issue/PR affects Ansible v2.5 bugfix_pull_request cloud community_review In order to be merged, this PR must follow the community review workflow. module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. python3 support:community This issue/PR relates to code supported by the Ansible community. labels Sep 19, 2017
@@ -722,7 +723,7 @@ def _config(self):

container_config_file = self.container.config_file_name
with open(container_config_file, 'rb') as f:
container_config = f.readlines()
container_config = [to_text(line, errors='surrogate_or_strict') for line in f.readlines()]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: It's probably faster to write this like this:

container_config = to_text(f.read(), errors='surrogate_or_strict').splitlines()

There's overhead from calling the text conversion functions so calling them only once should be quicker.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I'm not sure if it matters but you could use to_native() instead of to_text() if container_config should be byte strings on python2 and text strings on python3. In a quick look at the following code I didn't see anything that would be a problem with text strings on python2 but I put that out there in case @cloudnull does see something.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of using to_native, my first commit to just open the file with 'r' and write with 'w' might be cleaner. that way it will be bytes in py2 and text in py3. After reading the py3 docs assumed you want to always use to_text/to_bytes in those cases.

@ansibot ansibot removed the needs_triage Needs a first human triage before being processed. label Sep 21, 2017
@abadger
Copy link
Contributor

abadger commented Sep 21, 2017 via email

@abadger abadger merged commit 0a11443 into ansible:devel Sep 28, 2017
abadger pushed a commit that referenced this pull request Sep 28, 2017
call to_text on full config file

fixes issue #30571
(cherry picked from commit 0a11443)
@abadger
Copy link
Contributor

abadger commented Sep 28, 2017

Merged to devel and cherry-picked to stable-2.4 for the 2.4.1 release.

@ansibot ansibot added bug This issue/PR relates to a bug. and removed bugfix_pull_request labels Mar 6, 2018
@ansible ansible locked and limited conversation to collaborators Apr 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.5 This issue/PR affects Ansible v2.5 bug This issue/PR relates to a bug. cloud community_review In order to be merged, this PR must follow the community review workflow. module This issue/PR relates to a module. python3 support:community This issue/PR relates to code supported by the Ansible community.
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

3 participants