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

[PR #2411/345d5f2d backport][stable-3] snap - revamp + implementing enabled/disabled states #2542

Conversation

patchback[bot]
Copy link

@patchback patchback bot commented May 17, 2021

This is a backport of PR #2411 as merged into main (345d5f2).

SUMMARY

Adding the states enabled and disabled, and while at it, did a major revamp of the module.

Fixes #1990

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

plugins/modules/packaging/os/snap.py

* revamp of snap module

* added changelog fragment

* fixed description

* Update changelogs/fragments/2411-snap-revamp-enabled-disabled-states.yml

Co-authored-by: Felix Fontein <felix@fontein.de>

Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit 345d5f2)
@felixfontein felixfontein changed the title [PR #2411/345d5f2d backport][stable-3] snap - revamp + implementing enabled/disabled states [DO NOT MERGE YET] [PR #2411/345d5f2d backport][stable-3] snap - revamp + implementing enabled/disabled states May 17, 2021
@ansibullbot
Copy link
Collaborator

@ansibullbot ansibullbot added affects_2.10 community_review feature This issue/PR relates to a feature request module module needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI needs_triage new_contributor Help guide this first time contributor os packaging plugins plugin (any type) stale_ci CI is older than 7 days, rerun before merging labels May 17, 2021
@felixfontein
Copy link
Collaborator

@russoz @aminvakil did one of you happen to run some tests for #2411 (resp. this PR)? There are unfortunately no tests for this module...

@russoz
Copy link
Collaborator

russoz commented May 17, 2021

Not really, but I think I can come up with some tests for that module.

@felixfontein felixfontein added the check-before-release PR will be looked at again shortly before release and merged if possible. label May 18, 2021
@aminvakil
Copy link
Contributor

@felixfontein no, I don't use snap, but I can run @russoz integration tests on a temporary VM/OS if it was destructive or anything (although I don't think a package manager's integration test could be destructive :))

@felixfontein
Copy link
Collaborator

@jkman340, since you seem to be using the snap module, would you mind to help testing this PR? You can find instructions on how that works here: https://github.com/ansible/community-docs/blob/main/test_pr_locally_guide.rst

@staticdev
Copy link

@felixfontein seems to be working here! I also have the problem in #2835.

@felixfontein felixfontein changed the title [DO NOT MERGE YET] [PR #2411/345d5f2d backport][stable-3] snap - revamp + implementing enabled/disabled states [PR #2411/345d5f2d backport][stable-3] snap - revamp + implementing enabled/disabled states Jun 22, 2021
@felixfontein felixfontein merged commit 2d23798 into stable-3 Jun 22, 2021
@felixfontein felixfontein deleted the patchback/backports/stable-3/345d5f2dfa8e8ea4d624da18a92ac69d298522b8/pr-2411 branch June 22, 2021 17:21
@felixfontein
Copy link
Collaborator

@staticdev thanks a lot for testing this :) It's not supposed to fix #2835 (resp. if it would, it would be coincidental), but at least now we can continue with the new codebase (which this backports also adds to stable-3).

@felixfontein felixfontein removed the check-before-release PR will be looked at again shortly before release and merged if possible. label Jun 22, 2021
@russoz
Copy link
Collaborator

russoz commented Jun 25, 2021

@staticdev thanks for testing! Valeu!! ;-)

@jkman340
Copy link

Sorry for delay, was on travel. I've tested the latest stable-3 and see no additional errors. However, #2835 is not fixed for me and still getting same error (Which sounds like is expected for this PR).

@felixfontein
Copy link
Collaborator

@jkman340 thanks for testig! I hope you travelled well :)

@staticdev
Copy link

@russoz I just did some new tests with the newly released 3.3.0 and I am getting a new error in my workstation:

- name: Install pycharm
  community.general.snap:
    name: "pycharm-professional"
    classic: true
  become: true

snap is installed and running and same task work on previous version.

Output with -vvv:

task path: /home/workuser/workspace/linux-developer-playbook/roles/staticdev.python_developer/tasks/pycharm.yml:8
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: static
<127.0.0.1> EXEC /bin/sh -c 'echo ~static && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/workuser/.ansible/tmp `"&& mkdir "` echo /home/workuser/.ansible/tmp/ansible-tmp-1625049418.5947723-17123-195735620733486 `" && echo ansible-tmp-1625049418.5947723-17123-195735620733486="` echo /home/workuser/.ansible/tmp/ansible-tmp-1625049418.5947723-17123-195735620733486 `" ) && sleep 0'
Using module file /home/workuser/.ansible/collections/ansible_collections/community/general/plugins/modules/snap.py
<127.0.0.1> PUT /home/workuser/.ansible/tmp/ansible-local-14024r06yc4gb/tmp_mn2vdpf TO /home/workuser/.ansible/tmp/ansible-tmp-1625049418.5947723-17123-195735620733486/AnsiballZ_snap.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/workuser/.ansible/tmp/ansible-tmp-1625049418.5947723-17123-195735620733486/ /home/workuser/.ansible/tmp/ansible-tmp-1625049418.5947723-17123-195735620733486/AnsiballZ_snap.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'sudo -H -S  -p "[sudo via ansible, key=agogffepwsrldbmzyevgmnvabgykeohg] password:" -u root /bin/sh -c '"'"'echo BECOME-SUCCESS-agogffepwsrldbmzyevgmnvabgykeohg ; /usr/bin/python3 /home/workuser/.ansible/tmp/ansible-tmp-1625049418.5947723-17123-195735620733486/AnsiballZ_snap.py'"'"' && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/workuser/.ansible/tmp/ansible-tmp-1625049418.5947723-17123-195735620733486/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
  File "/tmp/ansible_community.general.snap_payload_8njs35hv/ansible_community.general.snap_payload.zip/ansible_collections/community/general/plugins/module_utils/mh/deco.py", line 42, in wrapper
    func(self, *args, **kwargs)
  File "/tmp/ansible_community.general.snap_payload_8njs35hv/ansible_community.general.snap_payload.zip/ansible_collections/community/general/plugins/module_utils/mh/base.py", line 60, in run
    self.__run__()
  File "/tmp/ansible_community.general.snap_payload_8njs35hv/ansible_community.general.snap_payload.zip/ansible_collections/community/general/plugins/module_utils/mh/mixins/state.py", line 36, in __run__
    return func()
  File "/tmp/ansible_community.general.snap_payload_8njs35hv/ansible_community.general.snap_payload.zip/ansible_collections/community/general/plugins/modules/snap.py", line 196, in state_present
  File "/tmp/ansible_community.general.snap_payload_8njs35hv/ansible_community.general.snap_payload.zip/ansible_collections/community/general/plugins/modules/snap.py", line 193, in validate_input_snaps
ansible_collections.community.general.plugins.module_utils.mh.exceptions.ModuleHelperException
fatal: [127.0.0.1]: FAILED! => {
    "changed": false,
    "cmd_args": [
        "/usr/bin/snap",
        "i",
        "n",
        "f",
        "o",
        "['pycharm-professional']"
    ],
    "force_lang": "C",
    "invocation": {
        "module_args": {
            "channel": "stable",
            "classic": true,
            "name": [
                "pycharm-professional"
            ],
            "state": "present"
        }
    },
    "msg": "No snap matching 'pycharm-professional' available.",
    "output": {
        "cmd_args": [
            "/usr/bin/snap",
            "i",
            "n",
            "f",
            "o",
            "['pycharm-professional']"
        ],
        "force_lang": "C",
        "rc": 64,
        "stderr": "error: unknown command \"i\", see 'snap help'.\n",
        "stdout": ""
    },
    "rc": 64,
    "stderr": "error: unknown command \"i\", see 'snap help'.\n",
    "stderr_lines": [
        "error: unknown command \"i\", see 'snap help'."
    ],
    "stdout": "",
    "stdout_lines": [],
    "vars": {
        "cmd_args": [
            "/usr/bin/snap",
            "i",
            "n",
            "f",
            "o",
            "['pycharm-professional']"
        ],
        "force_lang": "C",
        "rc": 64,
        "stderr": "error: unknown command \"i\", see 'snap help'.\n",
        "stdout": ""
    }
}

@aminvakil
Copy link
Contributor

@staticdev Just to keep all the conversations in one place, is your issue same as #2906 ?
If so can you please paste your log there?

@felixfontein
Copy link
Collaborator

FYI: the version of the module in 3.3.0 is identical to the version in this PR.

@staticdev
Copy link

staticdev commented Jun 30, 2021

Exactly @aminvakil.. and yes, I am sorry @felixfontein, but my initial tests were obviously flawed =/
My mistake.

@russoz
Copy link
Collaborator

russoz commented Jul 2, 2021

@staticdev No worries, man. Thanks for your time on it. Any way, Felix has put up a neat set of automated tests in place, so it should be easier to test (and to add more tests) the next time! Thanks for your support! 👍

@felixfontein
Copy link
Collaborator

The tests are based on work by @aminvakil, it unfortunately turned out that snap doesn't work inside docker (not even for just installing/uninstalling snaps) so I had to spend a bit more work to make them run on the RHEL VMs we have in CI :)

@staticdev
Copy link

staticdev commented Jul 2, 2021

@felixfontein this problem to run on docker I am having for quite some time now, even before this PR. I thought it was related to #2835, but seems not.

I have a molecule scenario that works on a Debian 11 machine, but not on a Debian 11 image on docker (https://github.com/staticdev/ansible-role-python-developer). Scenario is this one: molecule test -s pycharm-install

@aminvakil
Copy link
Contributor

@staticdev snap does not work on docker, I learnt it just yesterday :)
This is not related to this module or any PR.

@staticdev
Copy link

@aminvakil this is strange, I even saw some specific Go code on their repo for docker support: https://github.com/snapcore/snapd/search?q=docker

@russoz
Copy link
Collaborator

russoz commented Jul 2, 2021

@staticdev Apparently snap can interact with docker, but not run from within a container.

See:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community_review feature This issue/PR relates to a feature request has_issue module module needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI new_contributor Help guide this first time contributor os packaging plugins plugin (any type) stale_ci CI is older than 7 days, rerun before merging
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants