8000 gitlab_runner: Fix idempotency when creating runner (#57833) by Lunik · Pull Request #57996 · ansible/ansible · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

gitlab_runner: Fix idempotency when creating runner (#57833) #57996

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

Merged
merged 1 commit into from
Jun 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- gitlab_runner - Fix idempotency when creating runner (https://github.com/ansible/ansible/issues/57759)
6 changes: 3 additions & 3 deletions lib/ansible/modules/source_control/gitlab_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,10 @@ def updateRunner(self, runner, arguments):
@param description Description of the runner
'''
def findRunner(self, description):
runners = self._gitlab.runners.all()
runners = self._gitlab.runners.list(as_list=False)
for runner in runners:
if (runner['description'] == description):
return self._gitlab.runners.get(runner['id'])
if (runner.description == description):
return self._gitlab.runners.get(runner.id)

'''
@param description Description of the runner
Expand Down
21 changes: 19 additions & 2 deletions test/units/modules/source_control/gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,12 +519,12 @@ def resp_delete_project_hook(url, request):


'''
HOOK API
RUNNER API
'''


@urlmatch(scheme="http", netloc="localhost", path="/api/v4/runners/all", method="get")
def resp_find_runners(url, request):
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,'
Expand All @@ -535,6 +535,23 @@ def resp_find_runners(url, request):
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,
"X-Per-Page": 1,
"X-Total-Pages": 1,
"X-Total": 2}
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/1", method="get")
def resp_get_runner(url, request):
headers = {'content-type': 'application/json'}
Expand Down
8 changes: 4 additions & 4 deletions test/units/modules/source_control/test_gitlab_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from .gitlab import (GitlabModuleTestCase,
python_version_match_requirement,
resp_find_runners, resp_get_runner,
resp_find_runners_list, resp_get_runner,
resp_create_runner, resp_delete_runner)

# Gitlab module requirements
Expand All @@ -26,7 +26,7 @@ def setUp(self):

self.moduleUtil = GitLabRunner(module=self.mock_module, gitlab_instance=self.gitlab_instance)

@with_httmock(resp_find_runners)
@with_httmock(resp_find_runners_list)
@with_httmock(resp_get_runner)
def test_runner_exist(self):
rvalue = self.moduleUtil.existsRunner("test-1-20150125")
Expand All @@ -44,7 +44,7 @@ def test_create_runner(self):
self.assertEqual(type(runner), Runner)
self.assertEqual(runner.description, "test-1-20150125")

@with_httmock(resp_find_runners)
@with_httmock(resp_find_runners_list)
@with_httmock(resp_get_runner)
def test_update_runner(self):
runner = self.moduleUtil.findRunner("test-1-20150125")
Expand All @@ -60,7 +60,7 @@ def test_update_runner(self):
self.assertEqual(changed, False)
self.assertEqual(newRunner.description, "Runner description")

@with_httmock(resp_find_runners)
@with_httmock(resp_find_runners_list)
@with_httmock(resp_get_runner)
@with_httmock(resp_delete_runner)
def test_delete_runner(self):
Expand Down
0