Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup role to initialize openshift-tests-private repo #30

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ This repository consists of additional ansible playbooks for the following:
1. Deploy Kubernetes NMState Operator and run e2e
1. Enable pod disruption budget (pdb)
1. Scheduler profile configuration and run e2e tests
1. Setup role for openshift-tests-private repo

## Assumptions:

Expand Down
9 changes: 9 additions & 0 deletions examples/openshift_tests_private_setup_vars.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---

## openshift-tests-private-setup vars
openshift_tests_private_setup_enable: false
golang_install_tarball: "https://go.dev/dl/go1.19.4.linux-ppc64le.tar.gz"
openshift_tests_private_basedir: "~/ocp-validation"
openshift_tests_private_clone_url: "https://github.com/openshift/openshift-tests-private"
openshift_tests_private_branch: "master"
openshift_tests_private_make_build_target: "~/ocp-validation/openshift-tests-private"
3 changes: 3 additions & 0 deletions playbooks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,6 @@
- import_playbook: ocp-scheduler.yml
when: scheduler_role_enable is defined and scheduler_role_enable

- import_playbook: openshift-tests-private-setup.yaml
when: openshift_tests_private_setup_enable is defined and openshift_tests_private_setup_enable

6 changes: 6 additions & 0 deletions playbooks/openshift-tests-private-setup.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---

- name: openshift-tests-private repository setup role
hosts: bastion
roles:
- openshift-tests-private-setup
92 changes: 92 additions & 0 deletions playbooks/roles/openshift-tests-private-setup/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
openshift-tests-private-setup
==========

This role initializes the following steps to setup `openshift-tests-private` test repository.
- Installing development tools
- Creating sub-directory
- Clonning the git repository
- Installing golang
- Running make build in the target directory

This role can be included in the other roles for initializing the above pre-requisites.


Requirements
------------

- The cluster is in a known good state, without any errors.


Role Variables
--------------

| Variable | Required | Default | Comments |
|-------------------------------------------|----------|--------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------|
| openshift_tests_private_setup_enable | no | false | Set the flag `true` to run this playbook. |
| golang_install_tarball | no | `https://go.dev/dl/go1.19.4.linux-ppc64le.tar.gz` | Golang tarball for `ppc64le` arch with version `>= 1.18` as per the minimum requirement. |
| openshift_tests_private_basedir | no | `~/ocp-validation` | Base directory path to clone the `openshift-tests-private` repo. It will get created if path not exists or not provided. |
| openshift_tests_private_clone_url | no | `https://github.com/openshift/openshift-tests-private` | Git clone URL of the tests private repo. |
| openshift_tests_private_branch | no | master | Branch to be used for specified test repo. |
| openshift_tests_private_make_build_target | no | `~/ocp-validation/openshift-tests-private` | Target directory for make build command. |


Environment Variables
---------------------

| Variable | Required | Comments |
|----------------------|----------------|------------------------------------------------------------------------|
| GITHUB_USERNAME | yes | Public GitHub account username to which the repository access granted. |
| GITHUB_ACCESS_TOKEN | yes | GitHub personal access token to clone the repository. |


**Note- The above environment variables are required to be set to provide your GitHub credentials.**


Example Playbook
----------------

```
- name: openshift-tests-private repository setup role
hosts: bastion
roles:
- openshift-tests-private-setup
```


Steps to use this role
----------------------

To use this role in other roles to setup `openshift-tests-private` repo, use the `include_role` module and supply the role variables in the `vars` as below:

```
- name: Include the openshift-tests-private-setup role
include_role:
name: openshift-tests-private-setup
vars:
golang_install_tarball: "https://go.dev/dl/go1.19.4.linux-ppc64le.tar.gz"
openshift_tests_private_basedir: "~/ocp-validation"
openshift_tests_private_clone_url: "https://github.com/openshift/openshift-tests-private"
openshift_tests_private_branch: "master"
openshift_tests_private_make_build_target: "~/ocp-validation/openshift-tests-private"
```

To run this role indenpendently add host in the inventory file, set the role variables in the `ocp4-playbooks-extras/examples/openshift_tests_private_vars.yaml` and run the below sample command from `ocp4-playbooks-extras`.


Sample Command
---------------

ansible-playbook -i inventory -e @openshift_tests_private_setup_vars.yaml ~/ocp4-playbooks-extras/playbooks/openshift-tests-private-setup.yaml


License
-------

See LICENCE.txt


Author Information
------------------

[email protected]

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---

## init-setup default vars
golang_install_tarball: "https://go.dev/dl/go1.19.4.linux-ppc64le.tar.gz"
openshift_tests_private_basedir: "~/ocp-validation"
openshift_tests_private_clone_url: "https://github.com/openshift/openshift-tests-private"
openshift_tests_private_branch: "master"
openshift_tests_private_make_build_target: "~/ocp-validation/openshift-tests-private"
64 changes: 64 additions & 0 deletions playbooks/roles/openshift-tests-private-setup/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---

## Test initialization setup playbook

- set_fact:
github_username: "{{ lookup('ansible.builtin.env','GITHUB_USERNAME') }}"
github_personal_access_token: "{{ lookup('ansible.builtin.env','GITHUB_ACCESS_TOKEN') }}"

# Check the environment vars for git username and personal access token
- fail:
msg: "Please ensure that you have been set the environment variables GITHUB_USERNAME and GITHUB_ACCESS_TOKEN"
when: github_username == "" or github_personal_access_token == ""

- name: Install the development tools
yum:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is'nt it better to use dnf instead? @pravin-dsilva

name:
- git
- "@Development tools"
state: present
when: |
(ansible_distribution == "CentOS") or
(ansible_distribution == "RedHat") or
(ansible_distribution == "Fedora")

- name: Include a golang installation role
include_role:
name: golang-installation
vars:
go_tarball: "{{ golang_install_tarball }}"
golang_path: "/usr/local/"

- name: Check if the given base-directory path already exists
stat:
path: "{{ openshift_tests_private_basedir }}"
register: basedir_path_status

- name: Create a base directory for openshift-test-private
file:
path: "{{ openshift_tests_private_basedir }}"
state: directory
mode: 0755
when: not basedir_path_status.stat.exists

- name: Clone the git repo
git:
repo: "https://{{ github_username }}:{{ github_personal_access_token }}@github.com/{{ openshift_tests_private_clone_url | urlsplit('path') }}"
dest: "{{ repo_dest_path }}"
version: "{{ openshift_tests_private_branch }}"
force: true
vars:
repo_dest_path: "{{ [openshift_tests_private_basedir, openshift_tests_private_clone_url.split('/')[-1]] | join('/') }}"
when:
- openshift_tests_private_clone_url != ""
- openshift_tests_private_branch != ""
- github_username != ""
- github_personal_access_token != ""

- name: Run make build command at target
make:
chdir: "{{ openshift_tests_private_make_build_target }}"
target: build
environment:
PATH: "{{ ansible_env.PATH }}:/usr/local/go/bin"
when: openshift_tests_private_make_build_target != ""