Browse Source

Move upload-git-mirror test job in-repo

This was previously defined in openstack-zuul-jobs, but
we're working out a way of keeping these in-repo, so move
it here.

This was entirely authored by David Simard.

Change-Id: I743b8e9011f717569589d9e16ac0228ad3d112d1
Co-Authored-By: David Moreau Simard <dmsimard@redhat.com>
changes/50/668050/5
James E. Blair 1 month ago
parent
commit
9a82ac0f60

+ 1
- 0
doc/source/test-jobs.rst View File

@@ -8,3 +8,4 @@ these unless you are making changes to the roles in this repository.
8 8
 
9 9
 .. zuul:autojob:: zuul-jobs-test-install-nodejs
10 10
 .. zuul:autojob:: zuul-jobs-test-registry
11
+.. zuul:autojob:: zuul-jobs-test-upload-git-mirror

+ 91
- 0
test-playbooks/upload-git-mirror.yaml View File

@@ -0,0 +1,91 @@
1
+- name: Run tests for the upload-git-mirror role
2
+  hosts: all
3
+  vars:
4
+    test_repo: https://opendev.org/zuul/zuul-jobs
5
+    test_repo_path: "{{ ansible_user_dir }}/tests/zuul-jobs"
6
+  pre_tasks:
7
+    - name: Create tests directory
8
+      file:
9
+        path: "{{ ansible_user_dir }}/tests"
10
+        state: directory
11
+
12
+    # For pushing to localhost over ssh
13
+    - name: Create a test ssh keypair
14
+      command: "ssh-keygen -t rsa -b 2048 -N '' -f {{ ansible_user_dir }}/tests/id_rsa"
15
+
16
+    - name: Get test private key
17
+      command: "cat {{ ansible_user_dir }}/tests/id_rsa"
18
+      changed_when: false
19
+      register: private_key_contents
20
+
21
+    - name: Get test public key
22
+      command: "cat {{ ansible_user_dir }}/tests/id_rsa.pub"
23
+      changed_when: false
24
+      register: public_key_contents
25
+
26
+    - name: Add public key to authorized_keys
27
+      authorized_key:
28
+        user: "{{ ansible_user }}"
29
+        state: present
30
+        key: "{{ public_key_contents.stdout }}"
31
+
32
+    - name: Get localhost ssh host public key
33
+      shell: ssh-keyscan -t rsa localhost
34
+      register: host_key
35
+  tasks:
36
+    - name: Get git commit hash for current patch of zuul-jobs
37
+      command: git rev-parse HEAD
38
+      changed_when: false
39
+      args:
40
+        chdir: "{{ ansible_user_dir }}/{{ zuul.project.src_dir }}"
41
+      register: current_commit
42
+
43
+    - name: Clone upstream zuul-jobs as a bare repository
44
+      git:
45
+        repo: "{{ test_repo }}"
46
+        dest: "{{ test_repo_path }}"
47
+        bare: yes
48
+      register: test_repo_clone
49
+
50
+    - name: Assert that the git repositories have different commits for HEAD
51
+      assert:
52
+        that:
53
+          - test_repo_clone.after != current_commit.stdout
54
+
55
+    - name: Run upload-git-mirror with specified credentials
56
+      vars:
57
+        git_mirror_credentials:
58
+          user: "{{ ansible_user }}"
59
+          host: localhost
60
+          ssh_key: "{{ private_key_contents.stdout }}"
61
+          host_key: "{{ host_key.stdout }}"
62
+          # TODO: key is renamed to ssh_key to prevent ambiguity with host_key.
63
+          # Remove key when the rename has landed in the role.
64
+          key: "{{ private_key_contents.stdout }}"
65
+        git_mirror_repository: "{{ test_repo_path }}"
66
+      include_role:
67
+        name: upload-git-mirror
68
+
69
+    - name: Get new repository HEAD commit
70
+      command: git rev-parse HEAD
71
+      changed_when: false
72
+      args:
73
+        chdir: "{{ test_repo_path }}"
74
+      register: after_mirror
75
+
76
+    - name: Assert that the git repositories have the same commit for HEAD
77
+      assert:
78
+        that:
79
+          - after_mirror.stdout == current_commit.stdout
80
+
81
+    - name: Check that the private key has been removed
82
+      stat:
83
+        path: "{{ ssh_private_key_tmp.path }}"
84
+      register: private_key_stat
85
+
86
+    - name: Assert that the private key and the config was removed
87
+      assert:
88
+        that:
89
+          - git_mirror_key_removed is changed
90
+          - not private_key_stat.stat.exists
91
+          - git_mirror_ssh_config_removed is changed

+ 10
- 0
zuul.d/test-general-roles-jobs.yaml View File

@@ -0,0 +1,10 @@
1
+# Jobs which test roles listed in general-roles.rst
2
+
3
+- job:
4
+    name: zuul-jobs-test-upload-git-mirror
5
+    description: |
6
+      Tests for the upload-git-mirror role from zuul-jobs
7
+    run: test-playbooks/upload-git-mirror.yaml
8
+    files:
9
+      - ^roles/upload-git-mirror/.*
10
+      - ^test-playbooks/upload-git-mirror.yaml

Loading…
Cancel
Save