snap: add RV version (#9598)
* snap: add RV version * add chglog frag * fix typo * fix docs * add missing import * fix sanity * more fixes * Update plugins/modules/snap.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/snap_alias.py Co-authored-by: Felix Fontein <felix@fontein.de> --------- Co-authored-by: Felix Fontein <felix@fontein.de>pull/9608/head
parent
8f29976102
commit
f27d5e7a42
|
@ -0,0 +1,3 @@
|
||||||
|
minor_changes:
|
||||||
|
- snap - add return value ``version`` (https://github.com/ansible-collections/community.general/pull/9598).
|
||||||
|
- snap_alias - add return value ``version`` (https://github.com/ansible-collections/community.general/pull/9598).
|
|
@ -41,8 +41,15 @@ def snap_runner(module, **kwargs):
|
||||||
options=cmd_runner_fmt.as_list(),
|
options=cmd_runner_fmt.as_list(),
|
||||||
info=cmd_runner_fmt.as_fixed("info"),
|
info=cmd_runner_fmt.as_fixed("info"),
|
||||||
dangerous=cmd_runner_fmt.as_bool("--dangerous"),
|
dangerous=cmd_runner_fmt.as_bool("--dangerous"),
|
||||||
|
version=cmd_runner_fmt.as_fixed("version"),
|
||||||
),
|
),
|
||||||
check_rc=False,
|
check_rc=False,
|
||||||
**kwargs
|
**kwargs
|
||||||
)
|
)
|
||||||
return runner
|
return runner
|
||||||
|
|
||||||
|
|
||||||
|
def get_version(runner):
|
||||||
|
with runner("version") as ctx:
|
||||||
|
rc, out, err = ctx.run()
|
||||||
|
return dict(x.split() for x in out.splitlines() if len(x.split()) == 2)
|
||||||
|
|
|
@ -167,6 +167,11 @@ options_changed:
|
||||||
type: list
|
type: list
|
||||||
returned: When any options have been changed/set
|
returned: When any options have been changed/set
|
||||||
version_added: 4.4.0
|
version_added: 4.4.0
|
||||||
|
version:
|
||||||
|
description: Versions of snap components as reported by C(snap version).
|
||||||
|
type: dict
|
||||||
|
returned: always
|
||||||
|
version_added: 10.3.0
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
@ -176,7 +181,7 @@ import numbers
|
||||||
from ansible.module_utils.common.text.converters import to_native
|
from ansible.module_utils.common.text.converters import to_native
|
||||||
|
|
||||||
from ansible_collections.community.general.plugins.module_utils.module_helper import StateModuleHelper
|
from ansible_collections.community.general.plugins.module_utils.module_helper import StateModuleHelper
|
||||||
from ansible_collections.community.general.plugins.module_utils.snap import snap_runner
|
from ansible_collections.community.general.plugins.module_utils.snap import snap_runner, get_version
|
||||||
|
|
||||||
|
|
||||||
class Snap(StateModuleHelper):
|
class Snap(StateModuleHelper):
|
||||||
|
@ -210,6 +215,7 @@ class Snap(StateModuleHelper):
|
||||||
|
|
||||||
def __init_module__(self):
|
def __init_module__(self):
|
||||||
self.runner = snap_runner(self.module)
|
self.runner = snap_runner(self.module)
|
||||||
|
self.vars.version = get_version(self.runner)
|
||||||
# if state=present there might be file names passed in 'name', in
|
# if state=present there might be file names passed in 'name', in
|
||||||
# which case they must be converted to their actual snap names, which
|
# which case they must be converted to their actual snap names, which
|
||||||
# is done using the names_from_snaps() method calling 'snap info'.
|
# is done using the names_from_snaps() method calling 'snap info'.
|
||||||
|
|
|
@ -80,13 +80,18 @@ snap_aliases:
|
||||||
type: list
|
type: list
|
||||||
elements: str
|
elements: str
|
||||||
returned: always
|
returned: always
|
||||||
|
version:
|
||||||
|
description: Versions of snap components as reported by C(snap version).
|
||||||
|
type: dict
|
||||||
|
returned: always
|
||||||
|
version_added: 10.3.0
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from ansible_collections.community.general.plugins.module_utils.module_helper import StateModuleHelper
|
from ansible_collections.community.general.plugins.module_utils.module_helper import StateModuleHelper
|
||||||
from ansible_collections.community.general.plugins.module_utils.snap import snap_runner
|
from ansible_collections.community.general.plugins.module_utils.snap import snap_runner, get_version
|
||||||
|
|
||||||
|
|
||||||
class SnapAlias(StateModuleHelper):
|
class SnapAlias(StateModuleHelper):
|
||||||
|
@ -112,6 +117,7 @@ class SnapAlias(StateModuleHelper):
|
||||||
|
|
||||||
def __init_module__(self):
|
def __init_module__(self):
|
||||||
self.runner = snap_runner(self.module)
|
self.runner = snap_runner(self.module)
|
||||||
|
self.vars.version = get_version(self.runner)
|
||||||
self.vars.set("snap_aliases", self._aliases(), change=True, diff=True)
|
self.vars.set("snap_aliases", self._aliases(), change=True, diff=True)
|
||||||
|
|
||||||
def __quit_module__(self):
|
def __quit_module__(self):
|
||||||
|
|
|
@ -376,6 +376,16 @@ issue_6803_kubectl_out = (
|
||||||
"\r\u001b[0m\u001b[?25h\u001b[Kkubectl (1.27/stable) v1.27.2 from Canonical** installed\n"
|
"\r\u001b[0m\u001b[?25h\u001b[Kkubectl (1.27/stable) v1.27.2 from Canonical** installed\n"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
default_env = {'environ_update': {'LANGUAGE': 'C', 'LC_ALL': 'C'}, 'check_rc': False}
|
||||||
|
default_version_out = """\
|
||||||
|
snap 2.66.1+24.04
|
||||||
|
snapd 2.66.1+24.04
|
||||||
|
series 16
|
||||||
|
ubuntu 24.04
|
||||||
|
kernel 6.8.0-49-generic
|
||||||
|
"""
|
||||||
|
|
||||||
TEST_CASES = [
|
TEST_CASES = [
|
||||||
dict(
|
dict(
|
||||||
id="simple case",
|
id="simple case",
|
||||||
|
@ -384,30 +394,37 @@ TEST_CASES = [
|
||||||
flags={},
|
flags={},
|
||||||
mocks=dict(
|
mocks=dict(
|
||||||
run_command=[
|
run_command=[
|
||||||
|
dict(
|
||||||
|
command=['/testbin/snap', 'version'],
|
||||||
|
environ=default_env,
|
||||||
|
rc=0,
|
||||||
|
out=default_version_out,
|
||||||
|
err="",
|
||||||
|
),
|
||||||
dict(
|
dict(
|
||||||
command=['/testbin/snap', 'info', 'hello-world'],
|
command=['/testbin/snap', 'info', 'hello-world'],
|
||||||
environ={'environ_update': {'LANGUAGE': 'C', 'LC_ALL': 'C'}, 'check_rc': False},
|
environ=default_env,
|
||||||
rc=0,
|
rc=0,
|
||||||
out='name: hello-world\n',
|
out='name: hello-world\n',
|
||||||
err="",
|
err="",
|
||||||
),
|
),
|
||||||
dict(
|
dict(
|
||||||
command=['/testbin/snap', 'list'],
|
command=['/testbin/snap', 'list'],
|
||||||
environ={'environ_update': {'LANGUAGE': 'C', 'LC_ALL': 'C'}, 'check_rc': False},
|
environ=default_env,
|
||||||
rc=0,
|
rc=0,
|
||||||
out="",
|
out="",
|
||||||
err="",
|
err="",
|
||||||
),
|
),
|
||||||
dict(
|
dict(
|
||||||
command=['/testbin/snap', 'install', 'hello-world'],
|
command=['/testbin/snap', 'install', 'hello-world'],
|
||||||
environ={'environ_update': {'LANGUAGE': 'C', 'LC_ALL': 'C'}, 'check_rc': False},
|
environ=default_env,
|
||||||
rc=0,
|
rc=0,
|
||||||
out="hello-world (12345/stable) v12345 from Canonical** installed\n",
|
out="hello-world (12345/stable) v12345 from Canonical** installed\n",
|
||||||
err="",
|
err="",
|
||||||
),
|
),
|
||||||
dict(
|
dict(
|
||||||
command=['/testbin/snap', 'list'],
|
command=['/testbin/snap', 'list'],
|
||||||
environ={'environ_update': {'LANGUAGE': 'C', 'LC_ALL': 'C'}, 'check_rc': False},
|
environ=default_env,
|
||||||
rc=0,
|
rc=0,
|
||||||
out=(
|
out=(
|
||||||
"Name Version Rev Tracking Publisher Notes"
|
"Name Version Rev Tracking Publisher Notes"
|
||||||
|
@ -428,37 +445,44 @@ TEST_CASES = [
|
||||||
flags={},
|
flags={},
|
||||||
mocks=dict(
|
mocks=dict(
|
||||||
run_command=[
|
run_command=[
|
||||||
|
dict(
|
||||||
|
command=['/testbin/snap', 'version'],
|
||||||
|
environ=default_env,
|
||||||
|
rc=0,
|
||||||
|
out=default_version_out,
|
||||||
|
err="",
|
||||||
|
),
|
||||||
dict(
|
dict(
|
||||||
command=['/testbin/snap', 'info', 'microk8s', 'kubectl'],
|
command=['/testbin/snap', 'info', 'microk8s', 'kubectl'],
|
||||||
environ={'environ_update': {'LANGUAGE': 'C', 'LC_ALL': 'C'}, 'check_rc': False},
|
environ=default_env,
|
||||||
rc=0,
|
rc=0,
|
||||||
out='name: microk8s\n---\nname: kubectl\n',
|
out='name: microk8s\n---\nname: kubectl\n',
|
||||||
err="",
|
err="",
|
||||||
),
|
),
|
||||||
dict(
|
dict(
|
||||||
command=['/testbin/snap', 'list'],
|
command=['/testbin/snap', 'list'],
|
||||||
environ={'environ_update': {'LANGUAGE': 'C', 'LC_ALL': 'C'}, 'check_rc': False},
|
environ=default_env,
|
||||||
rc=0,
|
rc=0,
|
||||||
out=issue_6803_status_out,
|
out=issue_6803_status_out,
|
||||||
err="",
|
err="",
|
||||||
),
|
),
|
||||||
dict(
|
dict(
|
||||||
command=['/testbin/snap', 'install', '--classic', 'microk8s'],
|
command=['/testbin/snap', 'install', '--classic', 'microk8s'],
|
||||||
environ={'environ_update': {'LANGUAGE': 'C', 'LC_ALL': 'C'}, 'check_rc': False},
|
environ=default_env,
|
||||||
rc=0,
|
rc=0,
|
||||||
out=issue_6803_microk8s_out,
|
out=issue_6803_microk8s_out,
|
||||||
err="",
|
err="",
|
||||||
),
|
),
|
||||||
dict(
|
dict(
|
||||||
command=['/testbin/snap', 'install', '--classic', 'kubectl'],
|
command=['/testbin/snap', 'install', '--classic', 'kubectl'],
|
||||||
environ={'environ_update': {'LANGUAGE': 'C', 'LC_ALL': 'C'}, 'check_rc': False},
|
environ=default_env,
|
||||||
rc=0,
|
rc=0,
|
||||||
out=issue_6803_kubectl_out,
|
out=issue_6803_kubectl_out,
|
||||||
err="",
|
err="",
|
||||||
),
|
),
|
||||||
dict(
|
dict(
|
||||||
command=['/testbin/snap', 'list'],
|
command=['/testbin/snap', 'list'],
|
||||||
environ={'environ_update': {'LANGUAGE': 'C', 'LC_ALL': 'C'}, 'check_rc': False},
|
environ=default_env,
|
||||||
rc=0,
|
rc=0,
|
||||||
out=(
|
out=(
|
||||||
"Name Version Rev Tracking Publisher Notes"
|
"Name Version Rev Tracking Publisher Notes"
|
||||||
|
|
Loading…
Reference in New Issue