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: minor refactor #5358

Merged

Conversation

russoz
Copy link
Collaborator

@russoz russoz commented Oct 14, 2022

SUMMARY

Minor refactor: mostly pythonisms, but removing the call to os.path.expanduser() in line 1361 (pre-change) because:

  • source_dir is passed as a parameter to the _create_tar() method
  • _create_tar() is only called in one spot in the code, in line 1568 (post-change), inside the method _container_create_tar() as self._create_tar(source_dir=work_dir)
  • the variable work_dir is defined in lines 1498-1502 (post-change) as:
            # Create a temp dir
            temp_dir = tempfile.mkdtemp()
    
            # Set the name of the working dir, temp + container_name
            work_dir = os.path.join(temp_dir, self.container_name)

Therefore, work_dir will always be an absolute path, therefore expanduser() is redundant.

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

plugins/modules/cloud/lxc/lxc_container.py

@ansibullbot
Copy link
Collaborator

@ansibullbot ansibullbot added bug This issue/PR relates to a bug cloud module module plugins plugin (any type) tests tests labels Oct 14, 2022
@github-actions
Copy link

github-actions bot commented Oct 14, 2022

Docs Build 📝

Thank you for contribution!✨

This PR has been merged and your docs changes will be incorporated when they are next published.

Copy link
Contributor

@cloudnull cloudnull left a comment

Choose a reason for hiding this comment

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

lgtm!

@felixfontein felixfontein added check-before-release PR will be looked at again shortly before release and merged if possible. backport-5 labels Oct 14, 2022
@felixfontein felixfontein merged commit 6f88426 into ansible-collections:main Oct 14, 2022
@patchback
Copy link

patchback bot commented Oct 14, 2022

Backport to stable-5: 💚 backport PR created

✅ Backport PR branch: patchback/backports/stable-5/6f88426cf1dc7f3a84fb6750bef1bf56b772f5d1/pr-5358

Backported as #5364

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

@felixfontein felixfontein removed the check-before-release PR will be looked at again shortly before release and merged if possible. label Oct 14, 2022
patchback bot pushed a commit that referenced this pull request Oct 14, 2022
* lxc_container: minor refactor

* add changelog fragment

(cherry picked from commit 6f88426)
@felixfontein
Copy link
Collaborator

@russoz thanks for your contribution!
@cloudnull thanks for reviewing this!

felixfontein pushed a commit that referenced this pull request Oct 14, 2022
* lxc_container: minor refactor

* add changelog fragment

(cherry picked from commit 6f88426)

Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
@russoz russoz deleted the lxc-container-refactor branch October 14, 2022 20:57
bratwurzt pushed a commit to bratwurzt/community.general that referenced this pull request Nov 7, 2022
* lxc_container: minor refactor

* add changelog fragment
bratwurzt pushed a commit to bratwurzt/community.general that referenced this pull request Nov 7, 2022
* lxc_container: minor refactor

* add changelog fragment
This was referenced Nov 20, 2022
lynxis added a commit to lynxis/community.general that referenced this pull request Dec 5, 2022
lxc_container fails when executing the lxc command (e.g. when creating
a new container) because PR#5358 broke the module argument
parsing. The resulting argument dict contained only the module argument name
and the argument flag but not the value. E.g.
```
- lxc_container:
    template: debian
```
would result in lxc command arguments `lxc template --template` instead of
`lxc --template debian`.

Fixes: 6f88426 ("lxc_container: minor refactor (ansible-collections#5358)")
Closes ansible-collections#5578

Signed-off-by: Alexander Couzens <lynxis@fe80.eu>
lynxis added a commit to lynxis/community.general that referenced this pull request Dec 5, 2022
lxc_container fails when executing the lxc command (e.g. when creating
a new container) because PR#5358 broke the module argument
parsing. The resulting argument dict contained only the module argument name
and the argument flag but not the value. E.g.
```
- lxc_container:
    template: debian
```
would result in lxc command arguments `lxc template --template` instead of
`lxc --template debian`.

Fixes: 6f88426 ("lxc_container: minor refactor (ansible-collections#5358)")
Fixes ansible-collections#5578

Signed-off-by: Alexander Couzens <lynxis@fe80.eu>
lynxis added a commit to lynxis/community.general that referenced this pull request Dec 16, 2022
lxc_container fails when executing the lxc command (e.g. when creating
a new container) because PR#5358 broke the module argument
parsing. The resulting argument dict contained only the module argument name
and the argument flag but not the value. E.g.
```
- lxc_container:
    template: debian
```
would result in lxc command arguments `lxc template --template` instead of
`lxc --template debian`.

Fixes: 6f88426 ("lxc_container: minor refactor (ansible-collections#5358)")
Fixes ansible-collections#5578

Signed-off-by: Alexander Couzens <lynxis@fe80.eu>
felixfontein pushed a commit that referenced this pull request Dec 17, 2022
lxc_container fails when executing the lxc command (e.g. when creating
a new container) because PR#5358 broke the module argument
parsing. The resulting argument dict contained only the module argument name
and the argument flag but not the value. E.g.
```
- lxc_container:
    template: debian
```
would result in lxc command arguments `lxc template --template` instead of
`lxc --template debian`.

Fixes: 6f88426 ("lxc_container: minor refactor (#5358)")
Fixes #5578

Signed-off-by: Alexander Couzens <lynxis@fe80.eu>

Signed-off-by: Alexander Couzens <lynxis@fe80.eu>
patchback bot pushed a commit that referenced this pull request Dec 17, 2022
lxc_container fails when executing the lxc command (e.g. when creating
a new container) because PR#5358 broke the module argument
parsing. The resulting argument dict contained only the module argument name
and the argument flag but not the value. E.g.
```
- lxc_container:
    template: debian
```
would result in lxc command arguments `lxc template --template` instead of
`lxc --template debian`.

Fixes: 6f88426 ("lxc_container: minor refactor (#5358)")
Fixes #5578

Signed-off-by: Alexander Couzens <lynxis@fe80.eu>

Signed-off-by: Alexander Couzens <lynxis@fe80.eu>
(cherry picked from commit af53271)
patchback bot pushed a commit that referenced this pull request Dec 17, 2022
lxc_container fails when executing the lxc command (e.g. when creating
a new container) because PR#5358 broke the module argument
parsing. The resulting argument dict contained only the module argument name
and the argument flag but not the value. E.g.
```
- lxc_container:
    template: debian
```
would result in lxc command arguments `lxc template --template` instead of
`lxc --template debian`.

Fixes: 6f88426 ("lxc_container: minor refactor (#5358)")
Fixes #5578

Signed-off-by: Alexander Couzens <lynxis@fe80.eu>

Signed-off-by: Alexander Couzens <lynxis@fe80.eu>
(cherry picked from commit af53271)
felixfontein pushed a commit that referenced this pull request Dec 17, 2022
…t when executing lxc command (#5697)

lxc_container: fix lxc argument when executing lxc command (#5659)

lxc_container fails when executing the lxc command (e.g. when creating
a new container) because PR#5358 broke the module argument
parsing. The resulting argument dict contained only the module argument name
and the argument flag but not the value. E.g.
```
- lxc_container:
    template: debian
```
would result in lxc command arguments `lxc template --template` instead of
`lxc --template debian`.

Fixes: 6f88426 ("lxc_container: minor refactor (#5358)")
Fixes #5578

Signed-off-by: Alexander Couzens <lynxis@fe80.eu>

Signed-off-by: Alexander Couzens <lynxis@fe80.eu>
(cherry picked from commit af53271)

Co-authored-by: Alexander Couzens <lynxis@fe80.eu>
felixfontein pushed a commit that referenced this pull request Dec 17, 2022
…t when executing lxc command (#5698)

lxc_container: fix lxc argument when executing lxc command (#5659)

lxc_container fails when executing the lxc command (e.g. when creating
a new container) because PR#5358 broke the module argument
parsing. The resulting argument dict contained only the module argument name
and the argument flag but not the value. E.g.
```
- lxc_container:
    template: debian
```
would result in lxc command arguments `lxc template --template` instead of
`lxc --template debian`.

Fixes: 6f88426 ("lxc_container: minor refactor (#5358)")
Fixes #5578

Signed-off-by: Alexander Couzens <lynxis@fe80.eu>

Signed-off-by: Alexander Couzens <lynxis@fe80.eu>
(cherry picked from commit af53271)

Co-authored-by: Alexander Couzens <lynxis@fe80.eu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue/PR relates to a bug cloud module module plugins plugin (any type) tests tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants