From 2f44b40d6846cee88c985d43ec87472397c5363b Mon Sep 17 00:00:00 2001
From: Cristian Calin <6627509+cristicalin@users.noreply.github.com>
Date: Mon, 29 Nov 2021 23:39:21 +0200
Subject: [PATCH] OEL7: Fix CentOS7 Extras for OEL7 (#8219)

* OEL7: Fix CentOS7 Extras for OEL7

* Molecule: add logs collection for jobs
---
 .gitlab-ci/vagrant.yml                        | 6 ++++++
 roles/bootstrap-os/tasks/bootstrap-centos.yml | 2 +-
 tests/scripts/molecule_logs.sh                | 9 +++++++++
 tests/scripts/molecule_run.sh                 | 6 +++---
 4 files changed, 19 insertions(+), 4 deletions(-)
 create mode 100755 tests/scripts/molecule_logs.sh

diff --git a/.gitlab-ci/vagrant.yml b/.gitlab-ci/vagrant.yml
index b6cf2df1a..a847923c1 100644
--- a/.gitlab-ci/vagrant.yml
+++ b/.gitlab-ci/vagrant.yml
@@ -16,6 +16,12 @@ molecule_tests:
     - ./tests/scripts/vagrant_clean.sh
   script:
     - ./tests/scripts/molecule_run.sh
+  after_script:
+    - chronic ./tests/scripts/molecule_logs.sh
+  artifacts:
+    when: always
+    paths:
+      - molecule_logs/
 
 .vagrant:
   extends: .testcases
diff --git a/roles/bootstrap-os/tasks/bootstrap-centos.yml b/roles/bootstrap-os/tasks/bootstrap-centos.yml
index 3e8aae8a2..23ca011b7 100644
--- a/roles/bootstrap-os/tasks/bootstrap-centos.yml
+++ b/roles/bootstrap-os/tasks/bootstrap-centos.yml
@@ -79,7 +79,7 @@
     - { option: "name", value: "CentOS-{{ ansible_distribution_major_version }} - Extras" }
     - { option: "enabled", value: "1" }
     - { option: "gpgcheck", value: "0" }
-    - { option: "baseurl", value: "http://mirror.centos.org/centos/{{ ansible_distribution_major_version }}/extras/$basearch/os/" }
+    - { option: "baseurl", value: "http://mirror.centos.org/centos/{{ ansible_distribution_major_version }}/extras/$basearch/{% if ansible_distribution_major_version|int > 7 %}os/{% endif %}" }
   when:
     - use_oracle_public_repo|default(true)
     - '''ID="ol"'' in os_release.stdout_lines'
diff --git a/tests/scripts/molecule_logs.sh b/tests/scripts/molecule_logs.sh
new file mode 100755
index 000000000..4908d81d5
--- /dev/null
+++ b/tests/scripts/molecule_logs.sh
@@ -0,0 +1,9 @@
+#!/bin/bash
+
+# Ensure a clean environent
+rm -fr molecule_logs
+mkdir -p molecule_logs
+
+# Collect and archive the logs
+find ~/.cache/molecule/ -name \*.out -o -name \*.err -type f | xargs tar -uf molecule_logs/molecule.tar
+gzip molecule_logs/molecule.tar
diff --git a/tests/scripts/molecule_run.sh b/tests/scripts/molecule_run.sh
index deb064268..ff2966fd0 100755
--- a/tests/scripts/molecule_run.sh
+++ b/tests/scripts/molecule_run.sh
@@ -6,7 +6,7 @@ export LANG=C.UTF-8
 
 for d in $(find roles -name molecule -type d)
 do
-    cd $(dirname $d)
+    pushd $(dirname $d)
     molecule test --all
-    cd -
-done
\ No newline at end of file
+    popd
+done
-- 
GitLab