mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Gitlab variables pagination (#968)
* Workaround increasing per_page to max * Update plugins/modules/source_control/gitlab/gitlab_group_variable.py * Create 968-gitlab_variables-pagination-increase.yml * Update changelogs/fragments/968-gitlab_variables-pagination-increase.yml Co-authored-by: Felix Fontein <felix@fontein.de> * Update changelogs/fragments/968-gitlab_variables-pagination-increase.yml Co-authored-by: Felix Fontein <felix@fontein.de> * Proper support of pagination * Fix E303 too many blank lines * Add test for pagination * Fix last vars removal test * Apply suggestions from code review Check misalignement fixed Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
3af4be34b2
commit
98486c0ee2
5 changed files with 170 additions and 8 deletions
4
changelogs/fragments/968-gitlab_variables-pagination.yml
Normal file
4
changelogs/fragments/968-gitlab_variables-pagination.yml
Normal file
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
bugfixes:
|
||||
- gitlab_project_variable - support for GitLab pagination limitation by iterating over GitLab variable pages (https://github.com/ansible-collections/community.general/pull/968).
|
||||
- gitlab_group_variable - support for GitLab pagination limitation by iterating over GitLab variable pages (https://github.com/ansible-collections/community.general/pull/968).
|
|
@ -158,7 +158,14 @@ class GitlabGroupVariables(object):
|
|||
return self.repo.groups.get(group_name)
|
||||
|
||||
def list_all_group_variables(self):
|
||||
return self.group.variables.list()
|
||||
page_nb = 1
|
||||
variables = []
|
||||
vars_page = self.group.variables.list(page=page_nb)
|
||||
while len(vars_page) > 0:
|
||||
variables += vars_page
|
||||
page_nb += 1
|
||||
vars_page = self.group.variables.list(page=page_nb)
|
||||
return variables
|
||||
|
||||
def create_variable(self, key, value, masked, protected, variable_type):
|
||||
if self._module.check_mode:
|
||||
|
|
|
@ -155,7 +155,14 @@ class GitlabProjectVariables(object):
|
|||
return self.repo.projects.get(project_name)
|
||||
|
||||
def list_all_project_variables(self):
|
||||
return self.project.variables.list()
|
||||
page_nb = 1
|
||||
variables = []
|
||||
vars_page = self.project.variables.list(page=page_nb)
|
||||
while len(vars_page) > 0:
|
||||
variables += vars_page
|
||||
page_nb += 1
|
||||
vars_page = self.project.variables.list(page=page_nb)
|
||||
return variables
|
||||
|
||||
def create_variable(self, key, value, masked, protected, variable_type):
|
||||
if self._module.check_mode:
|
||||
|
|
|
@ -495,6 +495,78 @@
|
|||
- gitlab_group_variable_state.group_variable.updated|length == 0
|
||||
- gitlab_group_variable_state.group_variable.removed[0] == "my_test_var"
|
||||
|
||||
- name: set complete page and purge existing ones
|
||||
gitlab_group_variable:
|
||||
api_url: "{{ gitlab_host }}"
|
||||
api_token: "{{ gitlab_login_token }}"
|
||||
group: "{{ gitlab_group_name }}"
|
||||
vars:
|
||||
page1_var01: value
|
||||
page1_var02: value
|
||||
page1_var03: value
|
||||
page1_var04: value
|
||||
page1_var05: value
|
||||
page1_var06: value
|
||||
page1_var07: value
|
||||
page1_var08: value
|
||||
page1_var09: value
|
||||
page1_var10: value
|
||||
page1_var11: value
|
||||
page1_var12: value
|
||||
page1_var13: value
|
||||
page1_var14: value
|
||||
page1_var15: value
|
||||
page1_var16: value
|
||||
page1_var17: value
|
||||
page1_var18: value
|
||||
page1_var19: value
|
||||
page1_var20: value
|
||||
purge: True
|
||||
register: gitlab_group_variable_state
|
||||
|
||||
- name: complete page added state must be changed
|
||||
assert:
|
||||
that:
|
||||
- gitlab_group_variable_state is changed
|
||||
- gitlab_group_variable_state.group_variable.added|length == 20
|
||||
- gitlab_group_variable_state.group_variable.untouched|length == 0
|
||||
|
||||
- name: set complete page and keep existing ones
|
||||
gitlab_group_variable:
|
||||
api_url: "{{ gitlab_host }}"
|
||||
api_token: "{{ gitlab_login_token }}"
|
||||
group: "{{ gitlab_group_name }}"
|
||||
vars:
|
||||
page2_var01: value
|
||||
page2_var02: value
|
||||
page2_var03: value
|
||||
page2_var04: value
|
||||
page2_var05: value
|
||||
page2_var06: value
|
||||
page2_var07: value
|
||||
page2_var08: value
|
||||
page2_var09: value
|
||||
page2_var10: value
|
||||
page2_var11: value
|
||||
page2_var12: value
|
||||
page2_var13: value
|
||||
page2_var14: value
|
||||
page2_var15: value
|
||||
page2_var16: value
|
||||
page2_var17: value
|
||||
page2_var18: value
|
||||
page2_var19: value
|
||||
page2_var20: value
|
||||
purge: False
|
||||
register: gitlab_group_variable_state
|
||||
|
||||
- name: existing page untouched state must be changed
|
||||
assert:
|
||||
that:
|
||||
- gitlab_group_variable_state is changed
|
||||
- gitlab_group_variable_state.group_variable.added|length == 20
|
||||
- gitlab_group_variable_state.group_variable.untouched|length == 20
|
||||
|
||||
- name: check that no variables are left
|
||||
gitlab_group_variable:
|
||||
api_url: "{{ gitlab_host }}"
|
||||
|
@ -503,11 +575,11 @@
|
|||
purge: True
|
||||
register: gitlab_group_variable_state
|
||||
|
||||
- name: check that no variables are untoucheded state must be changed
|
||||
- name: check that no variables are untouched state must be changed
|
||||
assert:
|
||||
that:
|
||||
- not gitlab_group_variable_state.changed
|
||||
- gitlab_group_variable_state.changed
|
||||
- gitlab_group_variable_state.group_variable.added|length == 0
|
||||
- gitlab_group_variable_state.group_variable.untouched|length == 0
|
||||
- gitlab_group_variable_state.group_variable.removed|length == 0
|
||||
- gitlab_group_variable_state.group_variable.removed|length == 40
|
||||
- gitlab_group_variable_state.group_variable.updated|length == 0
|
||||
|
|
|
@ -494,6 +494,78 @@
|
|||
- gitlab_project_variable_state.project_variable.updated|length == 0
|
||||
- gitlab_project_variable_state.project_variable.removed[0] == "my_test_var"
|
||||
|
||||
- name: set complete page and purge existing ones
|
||||
gitlab_project_variable:
|
||||
api_url: "{{ gitlab_host }}"
|
||||
api_token: "{{ gitlab_login_token }}"
|
||||
project: "{{ gitlab_project_name }}"
|
||||
vars:
|
||||
page1_var01: value
|
||||
page1_var02: value
|
||||
page1_var03: value
|
||||
page1_var04: value
|
||||
page1_var05: value
|
||||
page1_var06: value
|
||||
page1_var07: value
|
||||
page1_var08: value
|
||||
page1_var09: value
|
||||
page1_var10: value
|
||||
page1_var11: value
|
||||
page1_var12: value
|
||||
page1_var13: value
|
||||
page1_var14: value
|
||||
page1_var15: value
|
||||
page1_var16: value
|
||||
page1_var17: value
|
||||
page1_var18: value
|
||||
page1_var19: value
|
||||
page1_var20: value
|
||||
purge: True
|
||||
register: gitlab_project_variable_state
|
||||
|
||||
- name: complete page added state must be changed
|
||||
assert:
|
||||
that:
|
||||
- gitlab_project_variable_state is changed
|
||||
- gitlab_project_variable_state.project_variable.added|length == 20
|
||||
- gitlab_project_variable_state.project_variable.untouched|length == 0
|
||||
|
||||
- name: set complete page and keep existing ones
|
||||
gitlab_project_variable:
|
||||
api_url: "{{ gitlab_host }}"
|
||||
api_token: "{{ gitlab_login_token }}"
|
||||
project: "{{ gitlab_project_name }}"
|
||||
vars:
|
||||
page2_var01: value
|
||||
page2_var02: value
|
||||
page2_var03: value
|
||||
page2_var04: value
|
||||
page2_var05: value
|
||||
page2_var06: value
|
||||
page2_var07: value
|
||||
page2_var08: value
|
||||
page2_var09: value
|
||||
page2_var10: value
|
||||
page2_var11: value
|
||||
page2_var12: value
|
||||
page2_var13: value
|
||||
page2_var14: value
|
||||
page2_var15: value
|
||||
page2_var16: value
|
||||
page2_var17: value
|
||||
page2_var18: value
|
||||
page2_var19: value
|
||||
page2_var20: value
|
||||
purge: False
|
||||
register: gitlab_project_variable_state
|
||||
|
||||
- name: existing page untouched state must be changed
|
||||
assert:
|
||||
that:
|
||||
- gitlab_project_variable_state is changed
|
||||
- gitlab_project_variable_state.project_variable.added|length == 20
|
||||
- gitlab_project_variable_state.project_variable.untouched|length == 20
|
||||
|
||||
- name: check that no variables are left
|
||||
gitlab_project_variable:
|
||||
api_url: "{{ gitlab_host }}"
|
||||
|
@ -502,11 +574,11 @@
|
|||
purge: True
|
||||
register: gitlab_project_variable_state
|
||||
|
||||
- name: check that no variables are untoucheded state must be changed
|
||||
- name: check that no variables are untouched state must be changed
|
||||
assert:
|
||||
that:
|
||||
- not gitlab_project_variable_state.changed
|
||||
- gitlab_project_variable_state.changed
|
||||
- gitlab_project_variable_state.project_variable.added|length == 0
|
||||
- gitlab_project_variable_state.project_variable.untouched|length == 0
|
||||
- gitlab_project_variable_state.project_variable.removed|length == 0
|
||||
- gitlab_project_variable_state.project_variable.removed|length == 40
|
||||
- gitlab_project_variable_state.project_variable.updated|length == 0
|
||||
|
|
Loading…
Reference in a new issue