mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-27 10:40:22 -07:00
Allow gitlab_runner to function for non-admin users (#1491)
* Allow gitlab_runner to function for non-admin users * Fix errant whitespace * Allow later python-gitlab versions * gitlab_runner: Switch to feature instead of bugfix, add examples * Fix version_added in gitlab_runner * Cleanup documentation for gitlab_runner fix * Update plugins/modules/source_control/gitlab/gitlab_runner.py Co-authored-by: Brendan Batliner <brendan.batliner@gmail.com> * Update plugins/modules/source_control/gitlab/gitlab_runner.py Co-authored-by: Felix Fontein <felix@fontein.de> * Revert docs change * Clarify docs * Clarify docs Co-authored-by: Brendan Batliner <brendan.batliner@gmail.com> Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
298e0f60be
commit
11cb136971
5 changed files with 93 additions and 28 deletions
|
@ -524,20 +524,8 @@ RUNNER API
|
|||
'''
|
||||
|
||||
|
||||
@urlmatch(scheme="http", netloc="localhost", path="/api/v4/runners/all", method="get")
|
||||
@urlmatch(scheme="http", netloc="localhost", path=r'/api/v4/runners/all$', method="get")
|
||||
def resp_find_runners_all(url, request):
|
||||
headers = {'content-type': 'application/json'}
|
||||
content = ('[{"active": true,"description": "test-1-20150125","id": 1,'
|
||||
'"is_shared": false,"ip_address": "127.0.0.1","name": null,'
|
||||
'"online": true,"status": "online"},{"active": true,'
|
||||
'"description": "test-2-20150125","id": 2,"ip_address": "127.0.0.1",'
|
||||
'"is_shared": false,"name": null,"online": false,"status": "offline"}]')
|
||||
content = content.encode("utf-8")
|
||||
return response(200, content, headers, None, 5, request)
|
||||
|
||||
|
||||
@urlmatch(scheme="http", netloc="localhost", path="/api/v4/runners", method="get")
|
||||
def resp_find_runners_list(url, request):
|
||||
headers = {'content-type': 'application/json',
|
||||
"X-Page": 1,
|
||||
"X-Next-Page": 2,
|
||||
|
@ -553,7 +541,41 @@ def resp_find_runners_list(url, request):
|
|||
return response(200, content, headers, None, 5, request)
|
||||
|
||||
|
||||
@urlmatch(scheme="http", netloc="localhost", path="/api/v4/runners/1", method="get")
|
||||
@urlmatch(scheme="http", netloc="localhost", path=r'/api/v4/runners$', method="get")
|
||||
def resp_find_runners_list(url, request):
|
||||
headers = {'content-type': 'application/json',
|
||||
"X-Page": 1,
|
||||
"X-Next-Page": 2,
|
||||
"X-Per-Page": 1,
|
||||
"X-Total-Pages": 1,
|
||||
"X-Total": 2}
|
||||
content = ('[{"active": true,"description": "test-1-20201214","id": 1,'
|
||||
'"is_shared": false,"ip_address": "127.0.0.1","name": null,'
|
||||
'"online": true,"status": "online"},{"active": true,'
|
||||
'"description": "test-2-20201214","id": 2,"ip_address": "127.0.0.1",'
|
||||
'"is_shared": false,"name": null,"online": false,"status": "offline"}]')
|
||||
content = content.encode("utf-8")
|
||||
return response(200, content, headers, None, 5, request)
|
||||
|
||||
|
||||
@urlmatch(scheme="http", netloc="localhost", path=r'/api/v4/runners/1$', method="put")
|
||||
def resp_update_runner(url, request):
|
||||
headers = {'content-type': 'application/json',
|
||||
"X-Page": 1,
|
||||
"X-Next-Page": 2,
|
||||
"X-Per-Page": 1,
|
||||
"X-Total-Pages": 1,
|
||||
"X-Total": 2}
|
||||
content = ('[{"active": true,"description": "test-1-20201214","id": 1,'
|
||||
'"is_shared": false,"ip_address": "127.0.0.1","name": null,'
|
||||
'"online": true,"status": "online"},{"active": true,'
|
||||
'"description": "test-2-20201214","id": 2,"ip_address": "127.0.0.1",'
|
||||
'"is_shared": false,"name": null,"online": false,"status": "offline"}]')
|
||||
content = content.encode("utf-8")
|
||||
return response(200, content, headers, None, 5, request)
|
||||
|
||||
|
||||
@urlmatch(scheme="http", netloc="localhost", path=r'/api/v4/runners/1$', method="get")
|
||||
def resp_get_runner(url, request):
|
||||
headers = {'content-type': 'application/json'}
|
||||
content = ('{"active": true,"description": "test-1-20150125","id": 1,'
|
||||
|
@ -563,7 +585,7 @@ def resp_get_runner(url, request):
|
|||
return response(200, content, headers, None, 5, request)
|
||||
|
||||
|
||||
@urlmatch(scheme="http", netloc="localhost", path="/api/v4/runners", method="post")
|
||||
@urlmatch(scheme="http", netloc="localhost", path=r'/api/v4/runners$', method="post")
|
||||
def resp_create_runner(url, request):
|
||||
headers = {'content-type': 'application/json'}
|
||||
content = ('{"active": true,"description": "test-1-20150125","id": 1,'
|
||||
|
@ -573,7 +595,7 @@ def resp_create_runner(url, request):
|
|||
return response(201, content, headers, None, 5, request)
|
||||
|
||||
|
||||
@urlmatch(scheme="http", netloc="localhost", path="/api/v4/runners/1", method="delete")
|
||||
@urlmatch(scheme="http", netloc="localhost", path=r'/api/v4/runners/1$', method="delete")
|
||||
def resp_delete_runner(url, request):
|
||||
headers = {'content-type': 'application/json'}
|
||||
content = ('{}')
|
||||
|
|
|
@ -21,6 +21,7 @@ pytestmark = []
|
|||
try:
|
||||
from .gitlab import (GitlabModuleTestCase,
|
||||
python_version_match_requirement,
|
||||
resp_find_runners_all,
|
||||
resp_find_runners_list, resp_get_runner,
|
||||
resp_create_runner, resp_delete_runner)
|
||||
|
||||
|
@ -50,9 +51,9 @@ class TestGitlabRunner(GitlabModuleTestCase):
|
|||
|
||||
self.moduleUtil = GitLabRunner(module=self.mock_module, gitlab_instance=self.gitlab_instance)
|
||||
|
||||
@with_httmock(resp_find_runners_list)
|
||||
@with_httmock(resp_find_runners_all)
|
||||
@with_httmock(resp_get_runner)
|
||||
def test_runner_exist(self):
|
||||
def test_runner_exist_all(self):
|
||||
rvalue = self.moduleUtil.existsRunner("test-1-20150125")
|
||||
|
||||
self.assertEqual(rvalue, True)
|
||||
|
@ -61,6 +62,17 @@ class TestGitlabRunner(GitlabModuleTestCase):
|
|||
|
||||
self.assertEqual(rvalue, False)
|
||||
|
||||
@with_httmock(resp_find_runners_list)
|
||||
@with_httmock(resp_get_runner)
|
||||
def test_runner_exist_owned(self):
|
||||
rvalue = self.moduleUtil.existsRunner("test-1-20201214", True)
|
||||
|
||||
self.assertEqual(rvalue, True)
|
||||
|
||||
rvalue = self.moduleUtil.existsRunner("test-3-00000000", True)
|
||||
|
||||
self.assertEqual(rvalue, False)
|
||||
|
||||
@with_httmock(resp_create_runner)
|
||||
def test_create_runner(self):
|
||||
runner = self.moduleUtil.createRunner({"token": "token", "description": "test-1-20150125"})
|
||||
|
@ -68,7 +80,7 @@ class TestGitlabRunner(GitlabModuleTestCase):
|
|||
self.assertEqual(type(runner), Runner)
|
||||
self.assertEqual(runner.description, "test-1-20150125")
|
||||
|
||||
@with_httmock(resp_find_runners_list)
|
||||
@with_httmock(resp_find_runners_all)
|
||||
@with_httmock(resp_get_runner)
|
||||
def test_update_runner(self):
|
||||
runner = self.moduleUtil.findRunner("test-1-20150125")
|
||||
|
@ -84,7 +96,7 @@ class TestGitlabRunner(GitlabModuleTestCase):
|
|||
self.assertEqual(changed, False)
|
||||
self.assertEqual(newRunner.description, "Runner description")
|
||||
|
||||
@with_httmock(resp_find_runners_list)
|
||||
@with_httmock(resp_find_runners_all)
|
||||
@with_httmock(resp_get_runner)
|
||||
@with_httmock(resp_delete_runner)
|
||||
def test_delete_runner(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue