From 9f4cbcfbc27fc30bc9811611324f67a346baaba9 Mon Sep 17 00:00:00 2001 From: Ian Wienand Date: Thu, 28 Jan 2021 13:52:08 +1100 Subject: [PATCH] Expand gerrit testing to multiple changes This reworks the gerrit testing slightly to give some broader coverage. It sets up ssh keys for the user; not really necessary but can be helpful when interacting on a held host. It sets up groups and verification labels just so Zuul can comment with -2/+2; again this is not really necessary, but makes things a little closer to production reality. We make multiple changes, so we can better test navigating between them. The change comments are updated to have some randomness in them so they don't all look the same. We take screen shots of two change pages to validate the navigation between them. Change-Id: I60b869e4fdcf8849de836e33db643743128f8a70 --- playbooks/test-review.yaml | 149 +++++++++++++++++++++++++++++-- testinfra/test_gerrit.py | 41 ++++++--- zuul.d/docker-images/gerrit.yaml | 2 + 3 files changed, 172 insertions(+), 20 deletions(-) diff --git a/playbooks/test-review.yaml b/playbooks/test-review.yaml index 1d7ef3d577..9913161374 100644 --- a/playbooks/test-review.yaml +++ b/playbooks/test-review.yaml @@ -12,6 +12,17 @@ delay: 1 retries: 120 + - name: Create CI group + uri: + url: 'http://localhost:8081/a/groups/CI-tools' + method: PUT + user: admin + password: secret + body_format: json + body: + description: 'Continuous Integration Tools' + status_code: 201 + - name: Create Zuul user uri: url: http://localhost:8081/a/accounts/zuul @@ -25,6 +36,75 @@ http_password: 'secret' status_code: 201 + - name: Add Zuul to group + uri: + url: 'http://localhost:8081/a/groups/CI-tools/members/zuul' + method: PUT + user: admin + password: secret + status_code: 201 + + - name: Get group UUID + uri: + url: 'http://localhost:8081/a/groups/CI-tools' + method: GET + user: admin + password: secret + status_code: 200 + return_content: yes + register: group_raw + + - name: Debug serialized json + debug: + var: group_raw + + - name: Deserialize returned data to internal variable. + set_fact: + # The first 4 bytes of the returned data are )]}' which is + # invalid json. + group_json: '{{ group_raw.content | regex_replace("^....", "") | from_json }}' + + - name: Debug deserialized json + debug: + var: group_json + + - name: Setup key and initial gerrit config + shell: + executable: /bin/bash + cmd: | + set -xe + + ssh-keygen -t ed25519 -f /root/.ssh/id_25519 -P "" + curl -X POST --user "admin:secret" -H "Content-Type: text/plain" -d@/root/.ssh/id_25519.pub http://localhost:8081/a/accounts/admin/sshkeys + ssh-keyscan -p 29418 localhost >> /root/.ssh/known_hosts + + git config --global user.name "Admin" + git config --global user.email "admin@example.com" + + git clone http://admin:secret@localhost:8081/a/All-Projects + + pushd All-Projects + + echo "{{ group_json.id }} CI-tools" >> groups # noqa 203 + git commit -a -m "Add CI-tools group" + git push origin HEAD:refs/meta/config + + cat >> project.config << EOF + [label "Verified"] + function = MaxWithBlock + value = -2 Fails + value = -1 Doesn't seem to work + value = 0 No score + value = +1 Works for me + value = +2 Verified + [access "refs/heads/*"] + label-Verified = -2..+2 group CI-tools + EOF + git commit -a -m 'Update verify tags' + git push origin HEAD:refs/meta/config + + popd + - name: Create temp dir for project creation shell: mktemp -d register: project_tmp @@ -43,9 +123,8 @@ chdir: "{{ project_tmp.stdout }}" cmd: | set -x + git init . - git config user.name "Admin" - git config user.email "admin@example.com" cat >.gitreview <file.txt <file-1.txt <file-2.txt <file-3.txt <