Handle newer Gerrit ls-groups command syntax

In Gerrit 2.14 the -q flag to ls-groups was deprecated in favor of -g.
At some point between 2.14 and 3.2 the -q support was removed entirely.
This change checks the gerrit version then uses the appropriate flag for
querying a group based on that.

We also add more robust testing to check creation of groups with spaces
in their names. We also check that if an acl is updated without group
changes that we don't try to recreate the group and get the group uuid
successfully.

Change-Id: I58c0aa2b496bcd792c8f4bc7db89b08cefa3af3d
This commit is contained in:
Clark Boylan 2020-12-02 14:36:20 -08:00
parent 05d2786986
commit a7f00a4d9b
4 changed files with 44 additions and 1 deletions

View File

@ -347,9 +347,19 @@ class Gerrit(object):
cmd = 'gerrit ls-groups -v'
else:
cmd = 'gerrit ls-groups'
version = None
try:
version = self.parseGerritVersion(self.getVersion())
except Exception:
# If no version then we know version is old and should use -q
pass
if not version or version < (2, 14):
query_flag = '-q'
else:
query_flag = '-g'
# ensure group names with spaces are escaped and quoted
group = "\"%s\"" % group.replace(' ', r'\ ')
out, err = self._ssh(' '.join([cmd, '-q', group]))
out, err = self._ssh(' '.join([cmd, query_flag, group]))
return list(filter(None, out.split('\n')))
def listPlugins(self):

View File

@ -71,6 +71,19 @@
shell:
cmd: PROJECTS_INI=tools/projects.ini PROJECTS_YAML=tools/projects.yaml manage-projects -v
chdir: src/opendev.org/opendev/gerritlib
- name: Change test-repo-1 acls but don't change groups
lineinfile:
path: src/opendev.org/opendev/gerritlib/tools/projects.yaml
regexp: '^ acl-config: tools/acls/test/test.config'
line: ' acl-config: tools/acls/test/test2.config'
- name: Update single gerrit project with new acl
shell:
cmd: PROJECTS_INI=tools/projects.ini PROJECTS_YAML=tools/projects.yaml manage-projects -v test/test-repo-1
chdir: src/opendev.org/opendev/gerritlib
- name: Manage all gerrit projects again after acl update
shell:
cmd: PROJECTS_INI=tools/projects.ini PROJECTS_YAML=tools/projects.yaml manage-projects -v
chdir: src/opendev.org/opendev/gerritlib
- name: Check test-repo-1 exists
shell:
cmd: ssh -i tools/sshkey/admin -p 29418 admin@localhost gerrit ls-projects | grep test-repo-1

View File

@ -1,7 +1,13 @@
[access "refs/heads/*"]
abandon = group Registered Users
abandon = group test-group
abandon = group Test Group With Spaces
label-Code-Review = -2..+2 group Registered Users
label-Code-Review = -2..+2 group test-group
label-Code-Review = -2..+2 group Test Group With Spaces
label-Workflow = -1..+1 group Registered Users
label-Workflow = -1..+1 group test-group
label-Workflow = -1..+1 group Test Group With Spaces
[receive]
requireChangeId = true

View File

@ -0,0 +1,14 @@
[access "refs/heads/*"]
abandon = group Registered Users
abandon = group Test Group With Spaces
label-Code-Review = -2..+2 group Registered Users
label-Code-Review = -2..+2 group test-group
label-Code-Review = -2..+2 group Test Group With Spaces
label-Workflow = -1..+1 group Registered Users
label-Workflow = -1..+1 group test-group
[receive]
requireChangeId = true
[submit]
mergeContent = true