Skip to content

Commit

Permalink
Setup role for openshift-tests-private repository
Browse files Browse the repository at this point in the history
Signed-off-by: Aditya Honkalas <[email protected]>
  • Loading branch information
AdityaHonkalas committed Jan 23, 2023
1 parent facf1b8 commit e857ecd
Show file tree
Hide file tree
Showing 7 changed files with 184 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ This repository consists of additional ansible playbooks for the following:
1. Configure and run verification-tests
1. Enabling Stream Control Transmission Protocol (SCTP) and run e2e
1. Deploy Kubernetes NMState Operator and run e2e
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"
4 changes: 4 additions & 0 deletions playbooks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,7 @@

- import_playbook: ocp-nmstate-operator.yml
when: nmstate_enabled is defined and nmstate_enabled

- 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`, the default is given for version `1.19.4`. |
| 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, the default has been set for `openshift-tests-private` repository. |
| openshift_tests_private_branch | no | master | Git branch name, the default branch name has been set as `master`. |
| 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:
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 != ""

0 comments on commit e857ecd

Please sign in to comment.