mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-04-13 15:35:08 +00:00
Unflatmap community.general (#5461)
* Move files. * Update imports and references. * Move wrongly placed files. * Reverse redirects, deprecate long → short name redirects. * Simplify contribution guidelines for new modules. * Rewrite BOTMETA. * Add changelog fragment. * Fix ignore.txt files.
This commit is contained in:
parent
2b0bebc8fc
commit
b531ecdc9b
1033 changed files with 4802 additions and 1989 deletions
|
|
@ -1,24 +0,0 @@
|
|||
# Copyright (c) Ansible project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import pytest
|
||||
|
||||
from ansible_collections.community.general.plugins.modules.web_infrastructure.apache2_module import create_apache_identifier
|
||||
|
||||
REPLACEMENTS = [
|
||||
('php7.1', 'php7_module'),
|
||||
('php5.6', 'php5_module'),
|
||||
('shib2', 'mod_shib'),
|
||||
('evasive', 'evasive20_module'),
|
||||
('thismoduledoesnotexist', 'thismoduledoesnotexist_module'), # the default
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("replacement", REPLACEMENTS, ids=lambda x: x[0])
|
||||
def test_apache_identifier(replacement):
|
||||
"test the correct replacement of an a2enmod name with an apache2ctl name"
|
||||
assert create_apache_identifier(replacement[0]) == replacement[1]
|
||||
|
|
@ -1,182 +0,0 @@
|
|||
# Copyright (c) Ansible project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from ansible_collections.community.general.tests.unit.compat import unittest
|
||||
from ansible_collections.community.general.tests.unit.compat.mock import patch
|
||||
from ansible.module_utils import basic
|
||||
from ansible.module_utils.common.text.converters import to_bytes
|
||||
from ansible_collections.community.general.plugins.modules.web_infrastructure import jenkins_build
|
||||
|
||||
import json
|
||||
|
||||
|
||||
def set_module_args(args):
|
||||
"""prepare arguments so that they will be picked up during module creation"""
|
||||
args = json.dumps({'ANSIBLE_MODULE_ARGS': args})
|
||||
basic._ANSIBLE_ARGS = to_bytes(args)
|
||||
|
||||
|
||||
class AnsibleExitJson(Exception):
|
||||
"""Exception class to be raised by module.exit_json and caught by the test case"""
|
||||
pass
|
||||
|
||||
|
||||
class AnsibleFailJson(Exception):
|
||||
"""Exception class to be raised by module.fail_json and caught by the test case"""
|
||||
pass
|
||||
|
||||
|
||||
def exit_json(*args, **kwargs):
|
||||
"""function to patch over exit_json; package return data into an exception"""
|
||||
if 'changed' not in kwargs:
|
||||
kwargs['changed'] = False
|
||||
raise AnsibleExitJson(kwargs)
|
||||
|
||||
|
||||
def fail_json(*args, **kwargs):
|
||||
"""function to patch over fail_json; package return data into an exception"""
|
||||
kwargs['failed'] = True
|
||||
raise AnsibleFailJson(kwargs)
|
||||
|
||||
|
||||
class JenkinsMock():
|
||||
|
||||
def get_job_info(self, name):
|
||||
return {
|
||||
"nextBuildNumber": 1234
|
||||
}
|
||||
|
||||
def get_build_info(self, name, build_number):
|
||||
return {
|
||||
"building": True,
|
||||
"result": "SUCCESS"
|
||||
}
|
||||
|
||||
def build_job(self, *args):
|
||||
return None
|
||||
|
||||
def delete_build(self, name, build_number):
|
||||
return None
|
||||
|
||||
def stop_build(self, name, build_number):
|
||||
return None
|
||||
|
||||
|
||||
class JenkinsMockIdempotent():
|
||||
|
||||
def get_job_info(self, name):
|
||||
return {
|
||||
"nextBuildNumber": 1235
|
||||
}
|
||||
|
||||
def get_build_info(self, name, build_number):
|
||||
return {
|
||||
"building": False,
|
||||
"result": "ABORTED"
|
||||
}
|
||||
|
||||
def build_job(self, *args):
|
||||
return None
|
||||
|
||||
def delete_build(self, name, build_number):
|
||||
return None
|
||||
|
||||
def stop_build(self, name, build_number):
|
||||
return None
|
||||
|
||||
|
||||
class TestJenkinsBuild(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.mock_module_helper = patch.multiple(basic.AnsibleModule,
|
||||
exit_json=exit_json,
|
||||
fail_json=fail_json)
|
||||
self.mock_module_helper.start()
|
||||
self.addCleanup(self.mock_module_helper.stop)
|
||||
|
||||
@patch('ansible_collections.community.general.plugins.modules.web_infrastructure.jenkins_build.test_dependencies')
|
||||
def test_module_fail_when_required_args_missing(self, test_deps):
|
||||
test_deps.return_value = None
|
||||
with self.assertRaises(AnsibleFailJson):
|
||||
set_module_args({})
|
||||
jenkins_build.main()
|
||||
|
||||
@patch('ansible_collections.community.general.plugins.modules.web_infrastructure.jenkins_build.test_dependencies')
|
||||
def test_module_fail_when_missing_build_number(self, test_deps):
|
||||
test_deps.return_value = None
|
||||
with self.assertRaises(AnsibleFailJson):
|
||||
set_module_args({
|
||||
"name": "required-if",
|
||||
"state": "stopped"
|
||||
})
|
||||
jenkins_build.main()
|
||||
|
||||
@patch('ansible_collections.community.general.plugins.modules.web_infrastructure.jenkins_build.test_dependencies')
|
||||
@patch('ansible_collections.community.general.plugins.modules.web_infrastructure.jenkins_build.JenkinsBuild.get_jenkins_connection')
|
||||
def test_module_create_build(self, jenkins_connection, test_deps):
|
||||
test_deps.return_value = None
|
||||
jenkins_connection.return_value = JenkinsMock()
|
||||
|
||||
with self.assertRaises(AnsibleExitJson):
|
||||
set_module_args({
|
||||
"name": "host-check",
|
||||
"user": "abc",
|
||||
"token": "xyz"
|
||||
})
|
||||
jenkins_build.main()
|
||||
|
||||
@patch('ansible_collections.community.general.plugins.modules.web_infrastructure.jenkins_build.test_dependencies')
|
||||
@patch('ansible_collections.community.general.plugins.modules.web_infrastructure.jenkins_build.JenkinsBuild.get_jenkins_connection')
|
||||
def test_module_stop_build(self, jenkins_connection, test_deps):
|
||||
test_deps.return_value = None
|
||||
jenkins_connection.return_value = JenkinsMock()
|
||||
|
||||
with self.assertRaises(AnsibleExitJson) as return_json:
|
||||
set_module_args({
|
||||
"name": "host-check",
|
||||
"build_number": "1234",
|
||||
"state": "stopped",
|
||||
"user": "abc",
|
||||
"token": "xyz"
|
||||
})
|
||||
jenkins_build.main()
|
||||
|
||||
self.assertTrue(return_json.exception.args[0]['changed'])
|
||||
|
||||
@patch('ansible_collections.community.general.plugins.modules.web_infrastructure.jenkins_build.test_dependencies')
|
||||
@patch('ansible_collections.community.general.plugins.modules.web_infrastructure.jenkins_build.JenkinsBuild.get_jenkins_connection')
|
||||
def test_module_stop_build_again(self, jenkins_connection, test_deps):
|
||||
test_deps.return_value = None
|
||||
jenkins_connection.return_value = JenkinsMockIdempotent()
|
||||
|
||||
with self.assertRaises(AnsibleExitJson) as return_json:
|
||||
set_module_args({
|
||||
"name": "host-check",
|
||||
"build_number": "1234",
|
||||
"state": "stopped",
|
||||
"user": "abc",
|
||||
"password": "xyz"
|
||||
})
|
||||
jenkins_build.main()
|
||||
|
||||
self.assertFalse(return_json.exception.args[0]['changed'])
|
||||
|
||||
@patch('ansible_collections.community.general.plugins.modules.web_infrastructure.jenkins_build.test_dependencies')
|
||||
@patch('ansible_collections.community.general.plugins.modules.web_infrastructure.jenkins_build.JenkinsBuild.get_jenkins_connection')
|
||||
def test_module_delete_build(self, jenkins_connection, test_deps):
|
||||
test_deps.return_value = None
|
||||
jenkins_connection.return_value = JenkinsMock()
|
||||
|
||||
with self.assertRaises(AnsibleExitJson):
|
||||
set_module_args({
|
||||
"name": "host-check",
|
||||
"build_number": "1234",
|
||||
"state": "absent",
|
||||
"user": "abc",
|
||||
"token": "xyz"
|
||||
})
|
||||
jenkins_build.main()
|
||||
|
|
@ -1,192 +0,0 @@
|
|||
# Copyright (c) Ansible project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from io import BytesIO
|
||||
|
||||
from ansible_collections.community.general.plugins.modules.web_infrastructure.jenkins_plugin import JenkinsPlugin
|
||||
from ansible.module_utils.common._collections_compat import Mapping
|
||||
|
||||
|
||||
def pass_function(*args, **kwargs):
|
||||
pass
|
||||
|
||||
|
||||
GITHUB_DATA = {"url": u'https://api.github.com/repos/ansible/ansible',
|
||||
"response": b"""
|
||||
{
|
||||
"id": 3638964,
|
||||
"name": "ansible",
|
||||
"full_name": "ansible/ansible",
|
||||
"owner": {
|
||||
"login": "ansible",
|
||||
"id": 1507452,
|
||||
"avatar_url": "https://avatars2.githubusercontent.com/u/1507452?v=4",
|
||||
"gravatar_id": "",
|
||||
"url": "https://api.github.com/users/ansible",
|
||||
"html_url": "https://github.com/ansible",
|
||||
"followers_url": "https://api.github.com/users/ansible/followers",
|
||||
"following_url": "https://api.github.com/users/ansible/following{/other_user}",
|
||||
"gists_url": "https://api.github.com/users/ansible/gists{/gist_id}",
|
||||
"starred_url": "https://api.github.com/users/ansible/starred{/owner}{/repo}",
|
||||
"subscriptions_url": "https://api.github.com/users/ansible/subscriptions",
|
||||
"organizations_url": "https://api.github.com/users/ansible/orgs",
|
||||
"repos_url": "https://api.github.com/users/ansible/repos",
|
||||
"events_url": "https://api.github.com/users/ansible/events{/privacy}",
|
||||
"received_events_url": "https://api.github.com/users/ansible/received_events",
|
||||
"type": "Organization",
|
||||
"site_admin": false
|
||||
},
|
||||
"private": false,
|
||||
"html_url": "https://github.com/ansible/ansible",
|
||||
"description": "Ansible is a radically simple IT automation platform that makes your applications and systems easier to deploy.",
|
||||
"fork": false,
|
||||
"url": "https://api.github.com/repos/ansible/ansible",
|
||||
"forks_url": "https://api.github.com/repos/ansible/ansible/forks",
|
||||
"keys_url": "https://api.github.com/repos/ansible/ansible/keys{/key_id}",
|
||||
"collaborators_url": "https://api.github.com/repos/ansible/ansible/collaborators{/collaborator}",
|
||||
"teams_url": "https://api.github.com/repos/ansible/ansible/teams",
|
||||
"hooks_url": "https://api.github.com/repos/ansible/ansible/hooks",
|
||||
"issue_events_url": "https://api.github.com/repos/ansible/ansible/issues/events{/number}",
|
||||
"events_url": "https://api.github.com/repos/ansible/ansible/events",
|
||||
"assignees_url": "https://api.github.com/repos/ansible/ansible/assignees{/user}",
|
||||
"branches_url": "https://api.github.com/repos/ansible/ansible/branches{/branch}",
|
||||
"tags_url": "https://api.github.com/repos/ansible/ansible/tags",
|
||||
"blobs_url": "https://api.github.com/repos/ansible/ansible/git/blobs{/sha}",
|
||||
"git_tags_url": "https://api.github.com/repos/ansible/ansible/git/tags{/sha}",
|
||||
"git_refs_url": "https://api.github.com/repos/ansible/ansible/git/refs{/sha}",
|
||||
"trees_url": "https://api.github.com/repos/ansible/ansible/git/trees{/sha}",
|
||||
"statuses_url": "https://api.github.com/repos/ansible/ansible/statuses/{sha}",
|
||||
"languages_url": "https://api.github.com/repos/ansible/ansible/languages",
|
||||
"stargazers_url": "https://api.github.com/repos/ansible/ansible/stargazers",
|
||||
"contributors_url": "https://api.github.com/repos/ansible/ansible/contributors",
|
||||
"subscribers_url": "https://api.github.com/repos/ansible/ansible/subscribers",
|
||||
"subscription_url": "https://api.github.com/repos/ansible/ansible/subscription",
|
||||
"commits_url": "https://api.github.com/repos/ansible/ansible/commits{/sha}",
|
||||
"git_commits_url": "https://api.github.com/repos/ansible/ansible/git/commits{/sha}",
|
||||
"comments_url": "https://api.github.com/repos/ansible/ansible/comments{/number}",
|
||||
"issue_comment_url": "https://api.github.com/repos/ansible/ansible/issues/comments{/number}",
|
||||
"contents_url": "https://api.github.com/repos/ansible/ansible/contents/{+path}",
|
||||
"compare_url": "https://api.github.com/repos/ansible/ansible/compare/{base}...{head}",
|
||||
"merges_url": "https://api.github.com/repos/ansible/ansible/merges",
|
||||
"archive_url": "https://api.github.com/repos/ansible/ansible/{archive_format}{/ref}",
|
||||
"downloads_url": "https://api.github.com/repos/ansible/ansible/downloads",
|
||||
"issues_url": "https://api.github.com/repos/ansible/ansible/issues{/number}",
|
||||
"pulls_url": "https://api.github.com/repos/ansible/ansible/pulls{/number}",
|
||||
"milestones_url": "https://api.github.com/repos/ansible/ansible/milestones{/number}",
|
||||
"notifications_url": "https://api.github.com/repos/ansible/ansible/notifications{?since,all,participating}",
|
||||
"labels_url": "https://api.github.com/repos/ansible/ansible/labels{/name}",
|
||||
"releases_url": "https://api.github.com/repos/ansible/ansible/releases{/id}",
|
||||
"deployments_url": "https://api.github.com/repos/ansible/ansible/deployments",
|
||||
"created_at": "2012-03-06T14:58:02Z",
|
||||
"updated_at": "2017-09-19T18:10:54Z",
|
||||
"pushed_at": "2017-09-19T18:04:51Z",
|
||||
"git_url": "git://github.com/ansible/ansible.git",
|
||||
"ssh_url": "git@github.com:ansible/ansible.git",
|
||||
"clone_url": "https://github.com/ansible/ansible.git",
|
||||
"svn_url": "https://github.com/ansible/ansible",
|
||||
"homepage": "https://www.ansible.com/",
|
||||
"size": 91174,
|
||||
"stargazers_count": 25552,
|
||||
"watchers_count": 25552,
|
||||
"language": "Python",
|
||||
"has_issues": true,
|
||||
"has_projects": true,
|
||||
"has_downloads": true,
|
||||
"has_wiki": false,
|
||||
"has_pages": false,
|
||||
"forks_count": 8893,
|
||||
"mirror_url": null,
|
||||
"open_issues_count": 4283,
|
||||
"forks": 8893,
|
||||
"open_issues": 4283,
|
||||
"watchers": 25552,
|
||||
"default_branch": "devel",
|
||||
"organization": {
|
||||
"login": "ansible",
|
||||
"id": 1507452,
|
||||
"avatar_url": "https://avatars2.githubusercontent.com/u/1507452?v=4",
|
||||
"gravatar_id": "",
|
||||
"url": "https://api.github.com/users/ansible",
|
||||
"html_url": "https://github.com/ansible",
|
||||
"followers_url": "https://api.github.com/users/ansible/followers",
|
||||
"following_url": "https://api.github.com/users/ansible/following{/other_user}",
|
||||
"gists_url": "https://api.github.com/users/ansible/gists{/gist_id}",
|
||||
"starred_url": "https://api.github.com/users/ansible/starred{/owner}{/repo}",
|
||||
"subscriptions_url": "https://api.github.com/users/ansible/subscriptions",
|
||||
"organizations_url": "https://api.github.com/users/ansible/orgs",
|
||||
"repos_url": "https://api.github.com/users/ansible/repos",
|
||||
"events_url": "https://api.github.com/users/ansible/events{/privacy}",
|
||||
"received_events_url": "https://api.github.com/users/ansible/received_events",
|
||||
"type": "Organization",
|
||||
"site_admin": false
|
||||
},
|
||||
"network_count": 8893,
|
||||
"subscribers_count": 1733
|
||||
}
|
||||
"""
|
||||
}
|
||||
|
||||
|
||||
def test__get_json_data(mocker):
|
||||
"test the json conversion of _get_url_data"
|
||||
|
||||
timeout = 30
|
||||
params = {
|
||||
'url': GITHUB_DATA['url'],
|
||||
'timeout': timeout
|
||||
}
|
||||
module = mocker.Mock()
|
||||
module.params = params
|
||||
|
||||
JenkinsPlugin._csrf_enabled = pass_function
|
||||
JenkinsPlugin._get_installed_plugins = pass_function
|
||||
JenkinsPlugin._get_url_data = mocker.Mock()
|
||||
JenkinsPlugin._get_url_data.return_value = BytesIO(GITHUB_DATA['response'])
|
||||
jenkins_plugin = JenkinsPlugin(module)
|
||||
|
||||
json_data = jenkins_plugin._get_json_data(
|
||||
"{url}".format(url=GITHUB_DATA['url']),
|
||||
'CSRF')
|
||||
|
||||
assert isinstance(json_data, Mapping)
|
||||
|
||||
|
||||
def test__new_fallback_urls(mocker):
|
||||
"test generation of new fallback URLs"
|
||||
|
||||
params = {
|
||||
"url": "http://fake.jenkins.server",
|
||||
"timeout": 30,
|
||||
"name": "test-plugin",
|
||||
"version": "1.2.3",
|
||||
"updates_url": ["https://some.base.url"],
|
||||
"latest_plugins_url_segments": ["test_latest"],
|
||||
"versioned_plugins_url_segments": ["ansible", "versioned_plugins"],
|
||||
"update_json_url_segment": ["unreachable", "updates/update-center.json"],
|
||||
}
|
||||
module = mocker.Mock()
|
||||
module.params = params
|
||||
|
||||
JenkinsPlugin._csrf_enabled = pass_function
|
||||
JenkinsPlugin._get_installed_plugins = pass_function
|
||||
|
||||
jenkins_plugin = JenkinsPlugin(module)
|
||||
|
||||
latest_urls = jenkins_plugin._get_latest_plugin_urls()
|
||||
assert isInList(latest_urls, "https://some.base.url/test_latest/test-plugin.hpi")
|
||||
versioned_urls = jenkins_plugin._get_versioned_plugin_urls()
|
||||
assert isInList(versioned_urls, "https://some.base.url/versioned_plugins/test-plugin/1.2.3/test-plugin.hpi")
|
||||
json_urls = jenkins_plugin._get_update_center_urls()
|
||||
assert isInList(json_urls, "https://some.base.url/updates/update-center.json")
|
||||
|
||||
|
||||
def isInList(l, i):
|
||||
print("checking if %s in %s" % (i, l))
|
||||
for item in l:
|
||||
if item == i:
|
||||
return True
|
||||
return False
|
||||
Loading…
Add table
Add a link
Reference in a new issue