From 43b6c4191d4e90aa65564823eb731dfa09c6e2cd Mon Sep 17 00:00:00 2001
From: Fabien Boucher <fboucher@redhat.com>
Date: May 10 2019 14:08:32 +0000
Subject: [PATCH 1/4] Add DLRN local driver support


Change-Id: I5fe065b345ed3e88be1e4b6592e578fab35c7f8a

---

diff --git a/local.yaml.example b/local.yaml.example
new file mode 100644
index 0000000..ea3f14c
--- /dev/null
+++ b/local.yaml.example
@@ -0,0 +1,15 @@
+- hosts: localhost
+  roles:
+    - ensure-dlrn
+    - dlrn-prepare
+    - dlrn-build
+  vars:
+    ansible_user_dir: /home/fabien/dlrn-exp/fake_ansible_user_dir
+    zuul:
+      executor:
+        src_root: /home/fabien/dlrn-exp/src_root
+      project:
+        src_dir: python-redis
+    dlrn_repo: file:///home/fabien/git/softwarefactory-project.io-git/DLRN
+    dlrn_project: fedora-rawhide-x86_64
+    dlrn_config_dir: fedora-packaging/mock
diff --git a/roles/dlrn-build/defaults/main.yaml b/roles/dlrn-build/defaults/main.yaml
index 2bb3aec..7b9c0c4 100644
--- a/roles/dlrn-build/defaults/main.yaml
+++ b/roles/dlrn-build/defaults/main.yaml
@@ -1,6 +1,4 @@
 ---
 working_dir: "{{ ansible_user_dir }}/{{ zuul.project.src_dir | dirname }}"
 dlrn_data: "{{ working_dir }}/DLRN/data"
-dlrn_scripts_dir: "/opt/rh/rh-python35/root/usr/share/dlrn/scripts"
-dlrn_templates_dir: "/opt/rh/rh-python35/root/usr/lib/python3.5/site-packages/dlrn/templates"
 rdoinfo_dir: "{{ ansible_user_dir }}/__rdoinfo"
diff --git a/roles/dlrn-build/tasks/main.yaml b/roles/dlrn-build/tasks/main.yaml
index ab3305c..8ae5836 100644
--- a/roles/dlrn-build/tasks/main.yaml
+++ b/roles/dlrn-build/tasks/main.yaml
@@ -34,26 +34,29 @@
 
       {% endif %}{% endfor %}
 
-- name: Get project info
-  command: "{{ rdopkg }} findpkg {{ zuul.project.name }} -l {{ rdoinfo_dir }}"
-  register: result_info
+- name: Prepare source and distgit source in the data directory
+  when: dlrn_build_type == 'rdoinfo'
+  block:
+    - name: Get project info
+      command: "{{ rdopkg }} findpkg {{ zuul.project.name }} -l {{ rdoinfo_dir }}"
+      register: result_info
 
-- set_fact:
-    project_info: "{{ result_info.stdout | from_yaml }}"
+    - set_fact:
+        project_info: "{{ result_info.stdout | from_yaml }}"
 
-- name: Copy distgit in data directory
-  shell:
-    cmd: "ln -s {{ ansible_user_dir }}/{{ zuul.project.src_dir }} {{ dlrn_data }}/{{ project_info['name'] }}_distro"
-  when: zuul.project.name is match(".*-distgit$") or project_info['upstream'] == project_info['distgit']
+    - name: Copy distgit in data directory
+      shell:
+        cmd: "ln -s {{ ansible_user_dir }}/{{ zuul.project.src_dir }} {{ dlrn_data }}/{{ project_info['name'] }}_distro"
+      when: zuul.project.name is match(".*-distgit$") or project_info['upstream'] == project_info['distgit']
 
-- name: Copy source in data directory
-  shell:
-    cmd: "ln -s {{ ansible_user_dir }}/{{ zuul.project.src_dir }} {{ dlrn_data }}/{{ project_info['name'] }}"
-  when: not zuul.project.name is match(".*-distgit$") or project_info['upstream'] == project_info['distgit']
+    - name: Copy source in data directory
+      shell:
+        cmd: "ln -s {{ ansible_user_dir }}/{{ zuul.project.src_dir }} {{ dlrn_data }}/{{ project_info['name'] }}"
+      when: not zuul.project.name is match(".*-distgit$") or project_info['upstream'] == project_info['distgit']
 
 - name: Set project.ini values according to current config
   template:
-    src: projects.ini.j2
+    src: "{{ dlrn_build_type }}-projects.ini.j2"
     dest: "{{ working_dir }}/projects.ini"
 
 - name: Clean previous commits.sqlite
@@ -61,7 +64,8 @@
     path: "{{ working_dir }}/commits.sqlite"
     state: absent
 
-- name: Run DLRN build
+- name: Run DLRN build (rdoinfo driver)
+  when: dlrn_build_type == 'rdoinfo'
   command: >
     {{ dlrn }} --config-file projects.ini
          --package-name {{ project_info['name'] }}
@@ -74,6 +78,16 @@
   ignore_errors: yes
   register: dlrnbuild
 
+- name: Run DLRN build (local driver)
+  when: dlrn_build_type == 'local'
+  command: >
+    {{ dlrn }} --config-file {{ working_dir }}/projects.ini
+         --verbose-build
+  args:
+    chdir: "{{ ansible_user_dir }}/{{ zuul.project.src_dir }}"
+  ignore_errors: yes
+  register: dlrnbuild
+
 - name: Make sure current link is set
   shell:
     cmd: "test -L current || ln -s $(dirname $(find . -name commit.yaml)) current"
diff --git a/roles/dlrn-build/templates/local-projects.ini.j2 b/roles/dlrn-build/templates/local-projects.ini.j2
new file mode 100644
index 0000000..e5ef128
--- /dev/null
+++ b/roles/dlrn-build/templates/local-projects.ini.j2
@@ -0,0 +1,17 @@
+[DEFAULT]
+configdir={{ working_dir }}
+datadir={{ dlrn_data }}
+scriptsdir={{ ansible_user_dir }}/.local/share/dlrn/scripts
+distro=master
+source=master
+target={{ dlrn_project }}
+project_name={{ dlrn_project }}
+reponame=delorean
+maxretries=3
+smtpserver=
+pkginfo_driver=dlrn.drivers.local.LocalDriver
+tags=
+workers=1
+database_connection=sqlite:///{{ working_dir }}/commits.sqlite
+fallback_to_master=1
+release_numbering=0.1.date.hash
diff --git a/roles/dlrn-build/templates/projects.ini.j2 b/roles/dlrn-build/templates/projects.ini.j2
deleted file mode 100644
index 6f856d4..0000000
--- a/roles/dlrn-build/templates/projects.ini.j2
+++ /dev/null
@@ -1,19 +0,0 @@
-[DEFAULT]
-configdir={{ working_dir }}
-datadir={{ dlrn_data }}
-scriptsdir={{ dlrn_scripts_dir }}
-baseurl={{ dlrn_url }}/{{ dlrn_project }}
-distro=master
-source=master
-target={{ dlrn_project }}
-project_name={{ dlrn_project }}
-reponame=delorean
-templatedir={{ dlrn_templates_dir }}
-maxretries=3
-smtpserver=
-pkginfo_driver=dlrn.drivers.rdoinfo.RdoInfoDriver
-tags=
-workers=1
-database_connection=sqlite:///commits.sqlite
-fallback_to_master=1
-release_numbering=0.1.date.hash
diff --git a/roles/dlrn-build/templates/rdoinfo-projects.ini.j2 b/roles/dlrn-build/templates/rdoinfo-projects.ini.j2
new file mode 100644
index 0000000..b991e04
--- /dev/null
+++ b/roles/dlrn-build/templates/rdoinfo-projects.ini.j2
@@ -0,0 +1,18 @@
+[DEFAULT]
+configdir={{ working_dir }}
+datadir={{ dlrn_data }}
+scriptsdir={{ ansible_user_dir }}/.local/share/dlrn/scripts
+baseurl={{ dlrn_url }}/{{ dlrn_project }}
+distro=master
+source=master
+target={{ dlrn_project }}
+project_name={{ dlrn_project }}
+reponame=delorean
+maxretries=3
+smtpserver=
+pkginfo_driver=dlrn.drivers.rdoinfo.RdoInfoDriver
+tags=
+workers=1
+database_connection=sqlite:///commits.sqlite
+fallback_to_master=1
+release_numbering=0.1.date.hash
diff --git a/roles/dlrn-prepare/defaults/main.yaml b/roles/dlrn-prepare/defaults/main.yaml
new file mode 100644
index 0000000..51d13da
--- /dev/null
+++ b/roles/dlrn-prepare/defaults/main.yaml
@@ -0,0 +1 @@
+dlrn_build_type: local
diff --git a/roles/dlrn-prepare/tasks/main.yaml b/roles/dlrn-prepare/tasks/main.yaml
index fdf5113..714049f 100644
--- a/roles/dlrn-prepare/tasks/main.yaml
+++ b/roles/dlrn-prepare/tasks/main.yaml
@@ -1,12 +1,33 @@
-- name: Ensure __rdoinfo exists
-  file:
-    path: "{{ ansible_user_dir }}/__rdoinfo"
-    state: directory
+- name: Check dlrn_project is defined
+  assert:
+    that:
+      - dlrn_project is defined
+    fail_msg: "'dlrn_project' must be set to the packaging project name"
 
-- name: Create rdo.yml
-  shell: |
-    curl "{{ dlrn_config_url }}/{{ dlrn_project }}" > "{{ ansible_user_dir }}/__rdoinfo/rdo.yml"
-    ln -s rdo.yml "{{ ansible_user_dir }}/__rdoinfo/rdo-full.yml"
+- name: Check dlrn_config_dir is defined
+  assert:
+    that:
+      - dlrn_config_dir is defined
+    fail_msg: "'dlrn_config_dir' must be set to the repository name containing the mock config named {{ dlrn_project }}.cfg"
+
+- name: Prepare for RdoInfo driver build type
+  when: dlrn_build_type == 'rdoinfo'
+  block:
+    - name: Check dlrn_config_dir is defined
+      assert:
+        that:
+          - dlrn_config_url is defined
+        fail_msg: "'dlrn_config_url' must be set to an URL where {{ dlrn_project }} can be downloaded. This is the rdoinfo file."
+
+    - name: Ensure __rdoinfo exists
+      file:
+        path: "{{ ansible_user_dir }}/__rdoinfo"
+        state: directory
+
+    - name: Create rdo.yml
+      shell: |
+        curl "{{ dlrn_config_url }}/{{ dlrn_project }}" > "{{ ansible_user_dir }}/__rdoinfo/rdo.yml"
+        ln -s rdo.yml "{{ ansible_user_dir }}/__rdoinfo/rdo-full.yml"
 
 - name: Copy project mock config
   copy:

From d86b6c756d7f2a8b05e2047e3f490158b18fa3a9 Mon Sep 17 00:00:00 2001
From: Tristan de Cacqueray <tdecacqu@redhat.com>
Date: May 21 2019 10:30:34 +0000
Subject: [PATCH 2/4] Add dlrn-setup and run-tests-yml roles


---

diff --git a/roles/dlrn-setup/tasks/main.yaml b/roles/dlrn-setup/tasks/main.yaml
new file mode 100644
index 0000000..510472b
--- /dev/null
+++ b/roles/dlrn-setup/tasks/main.yaml
@@ -0,0 +1,14 @@
+---
+- name: Add intermediary repositories from changes ahead
+  become: yes
+  copy:
+    dest: "/etc/yum.repos.d/zuul-build.repo"
+    content: |
+      {% for artifact in zuul.artifacts|default([]) %}{% if artifact.name == 'dlrn-repo' %}
+      [{{ artifact.project }}-{{ artifact.change }}-{{ artifact.patchset }}]
+      name={{ artifact.project }}-{{ artifact.change }}-{{ artifact.patchset }}
+      enabled=1
+      baseurl={{ artifact.url }}/current
+      gpgcheck=0
+
+      {% endif %}{% endfor %}
diff --git a/roles/run-tests-yml/files/standard-test-beakerlib/tasks/main.yaml b/roles/run-tests-yml/files/standard-test-beakerlib/tasks/main.yaml
new file mode 100644
index 0000000..eecbf2b
--- /dev/null
+++ b/roles/run-tests-yml/files/standard-test-beakerlib/tasks/main.yaml
@@ -0,0 +1,11 @@
+---
+- name: Install packages
+  package:
+    name: "{{ required_packages }}"
+    state: latest
+
+- name: Run tests
+  command: ansible-playbook runtest.yml
+  args:
+    chdir: "{{ item }}"
+  with_items: "{{ tests }}"
diff --git a/roles/run-tests-yml/tasks/main.yaml b/roles/run-tests-yml/tasks/main.yaml
new file mode 100644
index 0000000..97eb928
--- /dev/null
+++ b/roles/run-tests-yml/tasks/main.yaml
@@ -0,0 +1,20 @@
+---
+- name: Install ansible.cfg
+  copy:
+    dest: "{{ zuul.project.src_dir }}/tests/ansible.cfg"
+    content: |
+      [defaults]
+      roles_path = .
+      stdout_callback = yaml
+
+- name: Copy mock role
+  synchronize:
+    src: "{{ item }}/"
+    dest: "{{ zuul.project.src_dir }}/tests/{{ item }}/"
+  with_items:
+    - standard-test-beakerlib
+
+- name: Run the tests
+  command: ansible-playbook tests.yml
+  args:
+    chdir: "{{ zuul.project.src_dir }}/tests"

From 0cf698d7ce1e50d1bb6dad4de64468d7c77f2317 Mon Sep 17 00:00:00 2001
From: Fabien Boucher <fboucher@redhat.com>
Date: May 21 2019 10:43:12 +0000
Subject: [PATCH 3/4] Merge #1 `Add dlrn-setup and run-tests-yml roles`


---

diff --git a/roles/dlrn-setup/tasks/main.yaml b/roles/dlrn-setup/tasks/main.yaml
new file mode 100644
index 0000000..510472b
--- /dev/null
+++ b/roles/dlrn-setup/tasks/main.yaml
@@ -0,0 +1,14 @@
+---
+- name: Add intermediary repositories from changes ahead
+  become: yes
+  copy:
+    dest: "/etc/yum.repos.d/zuul-build.repo"
+    content: |
+      {% for artifact in zuul.artifacts|default([]) %}{% if artifact.name == 'dlrn-repo' %}
+      [{{ artifact.project }}-{{ artifact.change }}-{{ artifact.patchset }}]
+      name={{ artifact.project }}-{{ artifact.change }}-{{ artifact.patchset }}
+      enabled=1
+      baseurl={{ artifact.url }}/current
+      gpgcheck=0
+
+      {% endif %}{% endfor %}
diff --git a/roles/run-tests-yml/files/standard-test-beakerlib/tasks/main.yaml b/roles/run-tests-yml/files/standard-test-beakerlib/tasks/main.yaml
new file mode 100644
index 0000000..eecbf2b
--- /dev/null
+++ b/roles/run-tests-yml/files/standard-test-beakerlib/tasks/main.yaml
@@ -0,0 +1,11 @@
+---
+- name: Install packages
+  package:
+    name: "{{ required_packages }}"
+    state: latest
+
+- name: Run tests
+  command: ansible-playbook runtest.yml
+  args:
+    chdir: "{{ item }}"
+  with_items: "{{ tests }}"
diff --git a/roles/run-tests-yml/tasks/main.yaml b/roles/run-tests-yml/tasks/main.yaml
new file mode 100644
index 0000000..97eb928
--- /dev/null
+++ b/roles/run-tests-yml/tasks/main.yaml
@@ -0,0 +1,20 @@
+---
+- name: Install ansible.cfg
+  copy:
+    dest: "{{ zuul.project.src_dir }}/tests/ansible.cfg"
+    content: |
+      [defaults]
+      roles_path = .
+      stdout_callback = yaml
+
+- name: Copy mock role
+  synchronize:
+    src: "{{ item }}/"
+    dest: "{{ zuul.project.src_dir }}/tests/{{ item }}/"
+  with_items:
+    - standard-test-beakerlib
+
+- name: Run the tests
+  command: ansible-playbook tests.yml
+  args:
+    chdir: "{{ zuul.project.src_dir }}/tests"

From 60d3c2942f42cb1c00e8daf1352c5b78badd915f Mon Sep 17 00:00:00 2001
From: Tristan de Cacqueray <tdecacqu@redhat.com>
Date: May 28 2019 09:15:16 +0000
Subject: [PATCH 4/4] run-tests-yml: run tests.yml playbook as root


---

diff --git a/roles/run-tests-yml/tasks/main.yaml b/roles/run-tests-yml/tasks/main.yaml
index 97eb928..a0d530f 100644
--- a/roles/run-tests-yml/tasks/main.yaml
+++ b/roles/run-tests-yml/tasks/main.yaml
@@ -16,5 +16,6 @@
 
 - name: Run the tests
   command: ansible-playbook tests.yml
+  become: yes
   args:
     chdir: "{{ zuul.project.src_dir }}/tests"

