mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-04-28 09:26:44 +00:00
Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aa877fe0fb | ||
|
|
86f06cac4c | ||
|
|
b97737affd | ||
|
|
f8650f8d85 | ||
|
|
48fbd69835 | ||
|
|
141f32c78b | ||
|
|
b3c99aea72 | ||
|
|
3356c77f81 | ||
|
|
23859e0ec3 | ||
|
|
79d85cc83c | ||
|
|
a11b8fd517 | ||
|
|
8a6b673fce | ||
|
|
7ec8b50361 | ||
|
|
d91c6fedc2 |
@@ -47,7 +47,7 @@ variables:
|
||||
resources:
|
||||
containers:
|
||||
- container: default
|
||||
image: quay.io/ansible/azure-pipelines-test-container:1.9.0
|
||||
image: quay.io/ansible/azure-pipelines-test-container:3.0.0
|
||||
|
||||
pool: Standard
|
||||
|
||||
|
||||
@@ -9,6 +9,10 @@ PATH="${PWD}/bin:${PATH}"
|
||||
|
||||
mkdir "${agent_temp_directory}/coverage/"
|
||||
|
||||
if [[ "$(ansible --version)" =~ \ 2\.9\. ]]; then
|
||||
exit
|
||||
fi
|
||||
|
||||
options=(--venv --venv-system-site-packages --color -v)
|
||||
|
||||
ansible-test coverage combine --group-by command --export "${agent_temp_directory}/coverage/" "${options[@]}"
|
||||
|
||||
@@ -5,6 +5,10 @@ set -o pipefail -eu
|
||||
|
||||
PATH="${PWD}/bin:${PATH}"
|
||||
|
||||
if [[ "$(ansible --version)" =~ \ 2\.9\. ]]; then
|
||||
exit
|
||||
fi
|
||||
|
||||
if ! ansible-test --help >/dev/null 2>&1; then
|
||||
# Install the devel version of ansible-test for generating code coverage reports.
|
||||
# This is only used by Ansible Collections, which are typically tested against multiple Ansible versions (in separate jobs).
|
||||
|
||||
2
.github/BOTMETA.yml
vendored
2
.github/BOTMETA.yml
vendored
@@ -1287,5 +1287,5 @@ macros:
|
||||
team_rhn: FlossWare alikins barnabycourt vritant
|
||||
team_scaleway: remyleone abarbare
|
||||
team_solaris: bcoca fishman jasperla jpdasma mator scathatheworm troy2914 xen0l
|
||||
team_suse: commel dcermak evrardjp lrupp toabctl AnderEnder alxgu andytom sealor
|
||||
team_suse: commel evrardjp lrupp toabctl AnderEnder alxgu andytom sealor
|
||||
team_virt: joshainglis karmab tleguern Thulium-Drake Ajpantuso
|
||||
|
||||
@@ -6,6 +6,27 @@ Community General Release Notes
|
||||
|
||||
This changelog describes changes after version 3.0.0.
|
||||
|
||||
v4.8.3
|
||||
======
|
||||
|
||||
Release Summary
|
||||
---------------
|
||||
|
||||
Bugfix release.
|
||||
|
||||
Minor Changes
|
||||
-------------
|
||||
|
||||
- ModuleHelper module utils - improved ``ModuleHelperException``, using ``to_native()`` for the exception message (https://github.com/ansible-collections/community.general/pull/4755).
|
||||
|
||||
Bugfixes
|
||||
--------
|
||||
|
||||
- nmcli - fix error caused by adding undefined module arguments for list options (https://github.com/ansible-collections/community.general/issues/4373, https://github.com/ansible-collections/community.general/pull/4813).
|
||||
- redhat_subscription - fix unsubscribing on RHEL 9 (https://github.com/ansible-collections/community.general/issues/4741).
|
||||
- sudoers - ensure sudoers config files are created with the permissions requested by sudoers (0440) (https://github.com/ansible-collections/community.general/pull/4814).
|
||||
- sudoers - fix incorrect handling of ``state: absent`` (https://github.com/ansible-collections/community.general/issues/4852).
|
||||
|
||||
v4.8.2
|
||||
======
|
||||
|
||||
|
||||
@@ -1835,3 +1835,24 @@ releases:
|
||||
- 4733-redis-fail.yml
|
||||
- simplified-bsd-license.yml
|
||||
release_date: '2022-06-06'
|
||||
4.8.3:
|
||||
changes:
|
||||
bugfixes:
|
||||
- nmcli - fix error caused by adding undefined module arguments for list options
|
||||
(https://github.com/ansible-collections/community.general/issues/4373, https://github.com/ansible-collections/community.general/pull/4813).
|
||||
- redhat_subscription - fix unsubscribing on RHEL 9 (https://github.com/ansible-collections/community.general/issues/4741).
|
||||
- sudoers - ensure sudoers config files are created with the permissions requested
|
||||
by sudoers (0440) (https://github.com/ansible-collections/community.general/pull/4814).
|
||||
- 'sudoers - fix incorrect handling of ``state: absent`` (https://github.com/ansible-collections/community.general/issues/4852).'
|
||||
minor_changes:
|
||||
- ModuleHelper module utils - improved ``ModuleHelperException``, using ``to_native()``
|
||||
for the exception message (https://github.com/ansible-collections/community.general/pull/4755).
|
||||
release_summary: Bugfix release.
|
||||
fragments:
|
||||
- 4.8.3.yml
|
||||
- 4755-mhexception-improvement.yml
|
||||
- 4809-redhat_subscription-unsubscribe.yaml
|
||||
- 4813-fix-nmcli-convert-list.yaml
|
||||
- 4814-sudoers-file-permissions.yml
|
||||
- 4852-sudoers-state-absent.yml
|
||||
release_date: '2022-06-20'
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace: community
|
||||
name: general
|
||||
version: 4.8.2
|
||||
version: 4.8.3
|
||||
readme: README.md
|
||||
authors:
|
||||
- Ansible (https://github.com/ansible)
|
||||
|
||||
@@ -6,17 +6,13 @@
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
from ansible.module_utils.common.text.converters import to_native
|
||||
|
||||
|
||||
class ModuleHelperException(Exception):
|
||||
@staticmethod
|
||||
def _get_remove(key, kwargs):
|
||||
if key in kwargs:
|
||||
result = kwargs[key]
|
||||
del kwargs[key]
|
||||
return result
|
||||
return None
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.msg = self._get_remove('msg', kwargs) or "Module failed with exception: {0}".format(self)
|
||||
self.update_output = self._get_remove('update_output', kwargs) or {}
|
||||
def __init__(self, msg, update_output=None, *args, **kwargs):
|
||||
self.msg = to_native(msg or "Module failed with exception: {0}".format(self))
|
||||
if update_output is None:
|
||||
update_output = {}
|
||||
self.update_output = update_output
|
||||
super(ModuleHelperException, self).__init__(*args)
|
||||
|
||||
@@ -83,7 +83,7 @@ options:
|
||||
version_added: 1.3.0
|
||||
clone:
|
||||
description:
|
||||
- Name of VM to be cloned. If C(vmid) is setted, C(clone) can take arbitrary value but required for initiating the clone.
|
||||
- Name of VM to be cloned. If I(vmid) is set, I(clone) can take an arbitrary value but is required for initiating the clone.
|
||||
type: str
|
||||
cores:
|
||||
description:
|
||||
|
||||
@@ -1742,7 +1742,10 @@ class Nmcli(object):
|
||||
|
||||
@staticmethod
|
||||
def list_to_string(lst):
|
||||
return ",".join(lst or [""])
|
||||
if lst is None:
|
||||
return None
|
||||
else:
|
||||
return ",".join(lst)
|
||||
|
||||
@staticmethod
|
||||
def settings_type(setting):
|
||||
|
||||
@@ -468,7 +468,7 @@ class Rhsm(RegistrationBase):
|
||||
items = ["--all"]
|
||||
|
||||
if items:
|
||||
args = [SUBMAN_CMD, 'unsubscribe'] + items
|
||||
args = [SUBMAN_CMD, 'remove'] + items
|
||||
rc, stderr, stdout = self.module.run_command(args, check_rc=True)
|
||||
return serials
|
||||
|
||||
|
||||
@@ -115,6 +115,8 @@ from ansible.module_utils.common.text.converters import to_native
|
||||
|
||||
class Sudoers(object):
|
||||
|
||||
FILE_MODE = 0o440
|
||||
|
||||
def __init__(self, module):
|
||||
self.check_mode = module.check_mode
|
||||
self.name = module.params['name']
|
||||
@@ -134,6 +136,8 @@ class Sudoers(object):
|
||||
with open(self.file, 'w') as f:
|
||||
f.write(self.content())
|
||||
|
||||
os.chmod(self.file, self.FILE_MODE)
|
||||
|
||||
def delete(self):
|
||||
if self.check_mode:
|
||||
return
|
||||
@@ -145,7 +149,12 @@ class Sudoers(object):
|
||||
|
||||
def matches(self):
|
||||
with open(self.file, 'r') as f:
|
||||
return f.read() == self.content()
|
||||
content_matches = f.read() == self.content()
|
||||
|
||||
current_mode = os.stat(self.file).st_mode & 0o777
|
||||
mode_matches = current_mode == self.FILE_MODE
|
||||
|
||||
return content_matches and mode_matches
|
||||
|
||||
def content(self):
|
||||
if self.user:
|
||||
@@ -159,9 +168,12 @@ class Sudoers(object):
|
||||
return "{owner} ALL={runas}{nopasswd} {commands}\n".format(owner=owner, runas=runas_str, nopasswd=nopasswd_str, commands=commands_str)
|
||||
|
||||
def run(self):
|
||||
if self.state == 'absent' and self.exists():
|
||||
self.delete()
|
||||
return True
|
||||
if self.state == 'absent':
|
||||
if self.exists():
|
||||
self.delete()
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
if self.exists() and self.matches():
|
||||
return False
|
||||
|
||||
@@ -29,6 +29,11 @@
|
||||
commands: /usr/local/bin/command
|
||||
register: rule_1
|
||||
|
||||
- name: Stat my-sudo-rule-1 file
|
||||
ansible.builtin.stat:
|
||||
path: "{{ sudoers_path }}/my-sudo-rule-1"
|
||||
register: rule_1_stat
|
||||
|
||||
- name: Grab contents of my-sudo-rule-1
|
||||
ansible.builtin.slurp:
|
||||
src: "{{ sudoers_path }}/my-sudo-rule-1"
|
||||
@@ -130,8 +135,27 @@
|
||||
register: revoke_rule_1_stat
|
||||
|
||||
|
||||
- name: Revoke non-existing rule
|
||||
community.general.sudoers:
|
||||
name: non-existing-rule
|
||||
state: absent
|
||||
register: revoke_non_existing_rule
|
||||
|
||||
- name: Stat non-existing rule
|
||||
ansible.builtin.stat:
|
||||
path: "{{ sudoers_path }}/non-existing-rule"
|
||||
register: revoke_non_existing_rule_stat
|
||||
|
||||
|
||||
# Run assertions
|
||||
|
||||
- name: Check rule 1 file stat
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- rule_1_stat.stat.exists
|
||||
- rule_1_stat.stat.isreg
|
||||
- rule_1_stat.stat.mode == '0440'
|
||||
|
||||
- name: Check changed status
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
@@ -139,6 +163,7 @@
|
||||
- rule_1_again is not changed
|
||||
- rule_5 is changed
|
||||
- revoke_rule_1 is changed
|
||||
- revoke_non_existing_rule is not changed
|
||||
|
||||
- name: Check contents
|
||||
ansible.builtin.assert:
|
||||
@@ -154,3 +179,4 @@
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- not revoke_rule_1_stat.stat.exists
|
||||
- not revoke_non_existing_rule_stat.stat.exists
|
||||
|
||||
@@ -207,50 +207,53 @@
|
||||
that:
|
||||
- remove_repo is changed
|
||||
|
||||
- name: add new repository via url to .repo file
|
||||
community.general.zypper_repository:
|
||||
repo: http://download.opensuse.org/repositories/systemsmanagement:/Uyuni:/Stable/openSUSE_Leap_{{ ansible_distribution_version }}/systemsmanagement:Uyuni:Stable.repo
|
||||
state: present
|
||||
register: added_by_repo_file
|
||||
# For now, the URL does not work for 15.4
|
||||
- when: ansible_distribution_version is version('15.4', '<')
|
||||
block:
|
||||
- name: add new repository via url to .repo file
|
||||
community.general.zypper_repository:
|
||||
repo: http://download.opensuse.org/repositories/systemsmanagement:/Uyuni:/Stable/openSUSE_Leap_{{ ansible_distribution_version }}/systemsmanagement:Uyuni:Stable.repo
|
||||
state: present
|
||||
register: added_by_repo_file
|
||||
|
||||
- name: get repository details from zypper
|
||||
command: zypper lr systemsmanagement_Uyuni_Stable
|
||||
register: get_repository_details_from_zypper
|
||||
- name: get repository details from zypper
|
||||
command: zypper lr systemsmanagement_Uyuni_Stable
|
||||
register: get_repository_details_from_zypper
|
||||
|
||||
- name: verify adding via .repo file was successful
|
||||
assert:
|
||||
that:
|
||||
- "added_by_repo_file is changed"
|
||||
- "get_repository_details_from_zypper.rc == 0"
|
||||
- "'/systemsmanagement:/Uyuni:/Stable/' in get_repository_details_from_zypper.stdout"
|
||||
- name: verify adding via .repo file was successful
|
||||
assert:
|
||||
that:
|
||||
- "added_by_repo_file is changed"
|
||||
- "get_repository_details_from_zypper.rc == 0"
|
||||
- "'/systemsmanagement:/Uyuni:/Stable/' in get_repository_details_from_zypper.stdout"
|
||||
|
||||
- name: add same repository via url to .repo file again to verify idempotency
|
||||
community.general.zypper_repository:
|
||||
repo: http://download.opensuse.org/repositories/systemsmanagement:/Uyuni:/Stable/openSUSE_Leap_{{ ansible_distribution_version }}/systemsmanagement:Uyuni:Stable.repo
|
||||
state: present
|
||||
register: added_again_by_repo_file
|
||||
- name: add same repository via url to .repo file again to verify idempotency
|
||||
community.general.zypper_repository:
|
||||
repo: http://download.opensuse.org/repositories/systemsmanagement:/Uyuni:/Stable/openSUSE_Leap_{{ ansible_distribution_version }}/systemsmanagement:Uyuni:Stable.repo
|
||||
state: present
|
||||
register: added_again_by_repo_file
|
||||
|
||||
- name: verify nothing was changed adding a repo with the same .repo file
|
||||
assert:
|
||||
that:
|
||||
- added_again_by_repo_file is not changed
|
||||
- name: verify nothing was changed adding a repo with the same .repo file
|
||||
assert:
|
||||
that:
|
||||
- added_again_by_repo_file is not changed
|
||||
|
||||
- name: remove repository via url to .repo file
|
||||
community.general.zypper_repository:
|
||||
repo: http://download.opensuse.org/repositories/systemsmanagement:/Uyuni:/Stable/openSUSE_Leap_{{ ansible_distribution_version }}/systemsmanagement:Uyuni:Stable.repo
|
||||
state: absent
|
||||
register: removed_by_repo_file
|
||||
- name: remove repository via url to .repo file
|
||||
community.general.zypper_repository:
|
||||
repo: http://download.opensuse.org/repositories/systemsmanagement:/Uyuni:/Stable/openSUSE_Leap_{{ ansible_distribution_version }}/systemsmanagement:Uyuni:Stable.repo
|
||||
state: absent
|
||||
register: removed_by_repo_file
|
||||
|
||||
- name: get list of files in /etc/zypp/repos.d/
|
||||
command: ls /etc/zypp/repos.d/
|
||||
changed_when: false
|
||||
register: etc_zypp_reposd
|
||||
- name: get list of files in /etc/zypp/repos.d/
|
||||
command: ls /etc/zypp/repos.d/
|
||||
changed_when: false
|
||||
register: etc_zypp_reposd
|
||||
|
||||
- name: verify removal via .repo file was successful, including cleanup of local .repo file in /etc/zypp/repos.d/
|
||||
assert:
|
||||
that:
|
||||
- "removed_by_repo_file"
|
||||
- "'/systemsmanagement:/Uyuni:/Stable/' not in etc_zypp_reposd.stdout"
|
||||
- name: verify removal via .repo file was successful, including cleanup of local .repo file in /etc/zypp/repos.d/
|
||||
assert:
|
||||
that:
|
||||
- "removed_by_repo_file"
|
||||
- "'/systemsmanagement:/Uyuni:/Stable/' not in etc_zypp_reposd.stdout"
|
||||
|
||||
- name: Copy test .repo file
|
||||
copy:
|
||||
|
||||
@@ -449,6 +449,17 @@ ipv6.ignore-auto-dns: no
|
||||
ipv6.ignore-auto-routes: no
|
||||
"""
|
||||
|
||||
TESTCASE_GENERIC_ZONE_ONLY = [
|
||||
{
|
||||
'type': 'generic',
|
||||
'conn_name': 'non_existent_nw_device',
|
||||
'ifname': 'generic_non_existant',
|
||||
'state': 'present',
|
||||
'zone': 'public',
|
||||
'_ansible_check_mode': False,
|
||||
}
|
||||
]
|
||||
|
||||
TESTCASE_BOND = [
|
||||
{
|
||||
'type': 'bond',
|
||||
@@ -1805,6 +1816,30 @@ def test_generic_connection_zone_unchanged(mocked_generic_connection_zone_unchan
|
||||
assert not results['changed']
|
||||
|
||||
|
||||
@pytest.mark.parametrize('patch_ansible_module', TESTCASE_GENERIC_ZONE_ONLY, indirect=['patch_ansible_module'])
|
||||
def test_generic_connection_modify_zone_only(mocked_generic_connection_modify, capfd):
|
||||
"""
|
||||
Test : Generic connection modified with zone only
|
||||
"""
|
||||
with pytest.raises(SystemExit):
|
||||
nmcli.main()
|
||||
|
||||
assert nmcli.Nmcli.execute_command.call_count == 1
|
||||
arg_list = nmcli.Nmcli.execute_command.call_args_list
|
||||
args, kwargs = arg_list[0]
|
||||
|
||||
assert 'connection.zone' in args[0]
|
||||
assert 'ipv4.addresses' not in args[0]
|
||||
assert 'ipv4.gateway' not in args[0]
|
||||
assert 'ipv6.addresses' not in args[0]
|
||||
assert 'ipv6.gateway' not in args[0]
|
||||
|
||||
out, err = capfd.readouterr()
|
||||
results = json.loads(out)
|
||||
assert not results.get('failed')
|
||||
assert results['changed']
|
||||
|
||||
|
||||
@pytest.mark.parametrize('patch_ansible_module', TESTCASE_CONNECTION, indirect=['patch_ansible_module'])
|
||||
def test_zone_none(mocked_connection_exists, capfd):
|
||||
"""
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Author: Jiri Hnidek (jhnidek@redhat.com)
|
||||
#
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
@@ -118,7 +119,7 @@ TEST_CASES = [
|
||||
(0, 'system identity: b26df632-25ed-4452-8f89-0308bfd167cb', '')
|
||||
),
|
||||
(
|
||||
['/testbin/subscription-manager', 'unsubscribe', '--all'],
|
||||
['/testbin/subscription-manager', 'remove', '--all'],
|
||||
{'check_rc': True},
|
||||
(0, '', '')
|
||||
),
|
||||
@@ -755,7 +756,7 @@ Entitlement Type: Physical
|
||||
(
|
||||
[
|
||||
'/testbin/subscription-manager',
|
||||
'unsubscribe',
|
||||
'remove',
|
||||
'--serial=7807912223970164816',
|
||||
],
|
||||
{'check_rc': True},
|
||||
|
||||
@@ -23,6 +23,7 @@ pytest-forked < 1.0.2 ; python_version < '2.7' # pytest-forked 1.0.2 and later r
|
||||
pytest-forked >= 1.0.2 ; python_version >= '2.7' # pytest-forked before 1.0.2 does not work with pytest 4.2.0+ (which requires python 2.7+)
|
||||
ntlm-auth >= 1.3.0 # message encryption support using cryptography
|
||||
requests < 2.20.0 ; python_version < '2.7' # requests 2.20.0 drops support for python 2.6
|
||||
requests < 2.28 ; python_version >= '2.7' and python_version < '3.7' # requests 2.28.0 drops support for python 3.6 and before
|
||||
requests-ntlm >= 1.1.0 # message encryption support
|
||||
requests-credssp >= 0.1.0 # message encryption support
|
||||
voluptuous >= 0.11.0 # Schema recursion via Self
|
||||
|
||||
Reference in New Issue
Block a user