diff --git a/tests/configure-gerrit.yml b/tests/configure-gerrit.yml new file mode 100644 index 0000000..b45bd11 --- /dev/null +++ b/tests/configure-gerrit.yml @@ -0,0 +1,109 @@ +- name: Install the gerritforge repo + dnf: + name: 'https://gerritforge.com/gerritforge-repo-1-2.noarch.rpm' + state: present + disable_gpg_check: yes + become: true + +- name: Install gerrit and git review + package: + name: + - initscripts + - gerrit-3.3.2-1 + - git-review + state: present + become: true + +- name: Initialize Gerrit + block: + - command: java -jar /var/gerrit/bin/gerrit.war init --batch --install-all-plugins -d /var/gerrit + become: true + - command: java -jar /var/gerrit/bin/gerrit.war reindex -d /var/gerrit + become: true + - command: git config -f /var/gerrit/etc/gerrit.config gerrit.canonicalWebUrl "http://localhost:8081" + become: true + - command: git config -f /var/gerrit/etc/gerrit.config httpd.listenUrl "http://*:8081" + become: true + - shell: /var/gerrit/bin/gerrit.sh run + become: true + async: 86400 + poll: 0 + +- name: Generate admin SSH key for Gerrit + command: ssh-keygen -f /tmp/admin -N '' + args: + creates: /tmp/admin.pub + +- name: Generate Zuul SSH key for Gerrit + command: ssh-keygen -f /tmp/zuul -N '' -t rsa -m PEM + args: + creates: /tmp/zuul.pub + +- name: Wait for Gerrit first login screen + uri: + url: http://localhost:8081/a/accounts/self/sshkeys + method: GET + user: admin + password: secret + register: first_login + until: first_login.status == 200 + retries: 60 + delay: 1 + ignore_errors: true + +- name: Add admin SSH key to Gerrit + uri: + url: http://localhost:8081/a/accounts/self/sshkeys + method: POST + user: admin + password: secret + body: "{{ lookup('file', '/tmp/admin.pub') }}" + status_code: 201 + headers: + Content-Type: text/plain + +- name: Create temp dir for Gerrit config update + shell: mktemp -d + register: gerrit_tmp + +- name: Check out All-Projects config + git: + repo: ssh://localhost:29418/All-Projects/ + ssh_opts: "-o StrictHostKeyChecking=no -i /tmp/admin -l admin" + dest: "{{ gerrit_tmp.stdout }}/All-Projects" + refspec: '+refs/meta/config:refs/meta/config' + version: refs/meta/config + +- name: Copy new All-Projects config into place + copy: + src: "gerrit-project.config" + dest: "{{ gerrit_tmp.stdout }}/All-Projects/project.config" +- name: Update All-Projects config in Gerrit + shell: | + git config user.email 'admin@example.com' + git commit -a -m 'update config' + git push http://admin:secret@localhost:8081/All-Projects +HEAD:refs/meta/config + args: + chdir: "{{ gerrit_tmp.stdout }}/All-Projects" + warn: false + +- name: Check if zuul user exists + uri: + url: http://localhost:8081/accounts/zuul + status_code: 200, 404 + register: zuul_user_check +- name: Create zuul Gerrit account + when: zuul_user_check.status==404 + uri: + url: http://localhost:8081/a/accounts/zuul + method: PUT + user: admin + password: secret + status_code: 201 + body_format: json + body: + name: Zuul + ssh_key: "{{ lookup('file', '/tmp/zuul.pub') }}" + http_password: secret + groups: + - "Service Users" diff --git a/tests/create_gerrit_project.yml b/tests/create_gerrit_project.yml new file mode 100644 index 0000000..90cd99a --- /dev/null +++ b/tests/create_gerrit_project.yml @@ -0,0 +1,36 @@ +- name: Check if {{ project }} project exists + uri: + url: http://localhost:8081/projects/{{ project }} + status_code: 200, 404 + register: project_check +- name: Create {{ project }} + when: project_check.status==404 + block: + - name: Create temp dir for {{ project }} creation + shell: mktemp -d + register: project_tmp + - name: Create {{ project }} project in Gerrit + uri: + url: http://localhost:8081/a/projects/{{ project }} + method: PUT + user: admin + password: secret + status_code: 201 + - name: Create initial commit in {{ project }} + shell: + executable: /bin/sh + chdir: "{{ project_tmp.stdout }}" + cmd: | + git init . + git config user.name "Admin" + git config user.email "admin@example.com" + cat >.gitreview <