Skip to content

Commit 8d6e840

Browse files
committed
ci: Add tft plan and workflow
This change is for running tests in Testing Farm CI. This is a replacement for BaseOS CI that we are currently using. Running it Testing Farm gives us more control. It adds a workflow for running tests, and a plans directory containing a test plan and a README-plans.md with some info. Note that this workflow runs from the main branch. This means that changes to the workflow must be merged to main, then pull requests will be able to run it. This is because the workflow uses on: issue_comment context, this is a security measure recommended by GitHub. It saves us from leaking organization secrets. The functionality is WIP, so await future fixes and updates. Signed-off-by: Sergei Petrosian <[email protected]>
1 parent e8ffa61 commit 8d6e840

File tree

6 files changed

+272
-53
lines changed

6 files changed

+272
-53
lines changed

.fmf/version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1

.github/workflows/tft.yml

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
name: Testing Farm
2+
on:
3+
issue_comment:
4+
types:
5+
- created
6+
permissions:
7+
contents: read
8+
# This is required for the ability to create/update the Pull request status
9+
statuses: write
10+
# The concurrency key is used to prevent multiple workflows from running at the same time
11+
concurrency:
12+
# group name contains reponame-pr_num to allow simualteneous runs in different PRs
13+
group: testing-farm-${{ github.event.repository.name }}-${{ github.event.issue.number }}
14+
cancel-in-progress: true
15+
jobs:
16+
prepare_vars:
17+
name: Get supported platforms from meta/main.yml
18+
# Let's schedule tests only on user request. NOT automatically.
19+
# Only repository owner or member can schedule tests
20+
if: |
21+
github.event.issue.pull_request
22+
&& (contains(github.event.comment.body, '[citest]') || contains(github.event.comment.body, '[citest-all]'))
23+
&& (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), github.event.comment.author_association) || contains('systemroller', github.event.comment.user.login))
24+
runs-on: ubuntu-latest
25+
outputs:
26+
supported_platforms: ${{ steps.supported_platforms.outputs.supported_platforms }}
27+
head_sha: ${{ steps.head_sha.outputs.head_sha }}
28+
datetime: ${{ steps.datetime.outputs.datetime }}
29+
memory: ${{ steps.memory.outputs.memory }}
30+
steps:
31+
32+
- name: Checkout repo
33+
uses: actions/checkout@v4
34+
35+
- name: Get head sha of the PR
36+
id: head_sha
37+
run: |
38+
head_sha=$(gh api "repos/$REPO/pulls/$PR_NO" --jq '.head.sha')
39+
echo "head_sha=$head_sha" >> $GITHUB_OUTPUT
40+
env:
41+
REPO: ${{ github.repository }}
42+
PR_NO: ${{ github.event.issue.number }}
43+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
44+
45+
- name: Get cuurent datetime
46+
id: datetime
47+
run: |
48+
printf -v datetime '%(%Y%m%d-%H%M%S)T' -1
49+
echo "datetime=$datetime" >> $GITHUB_OUTPUT
50+
51+
- name: Get memory
52+
id: memory
53+
run: |
54+
memory=$(grep -rPo ' m: \K(.*)' tests/provision.fmf)
55+
if [ -n "$memory" ]; then
56+
echo "memory=$memory" >> $GITHUB_OUTPUT
57+
else
58+
echo "memory=2048" >> $GITHUB_OUTPUT
59+
fi
60+
61+
- name: Get supported platforms
62+
id: supported_platforms
63+
run: |
64+
supported_platforms=""
65+
meta_main=meta/main.yml
66+
# All Fedora are supported, add latest Fedora versions to supported_platforms
67+
if yq '.galaxy_info.galaxy_tags[]' "$meta_main" | grep -qi fedora$; then
68+
supported_platforms+=" Fedora-39"
69+
supported_platforms+=" Fedora-40"
70+
fi
71+
# Specific Fedora versions supported
72+
if yq '.galaxy_info.galaxy_tags[]' "$meta_main" | grep -qiP 'fedora\d+$'; then
73+
for fedora_ver in $(yq '.galaxy_info.galaxy_tags[]' "$meta_main" | grep -iPo 'fedora\K(\d+$)'); do
74+
supported_platforms+=" Fedora-$fedora_ver"
75+
done
76+
fi
77+
if yq '.galaxy_info.galaxy_tags[]' "$meta_main" | grep -qi el7; then
78+
supported_platforms+=" CentOS-7-latest"
79+
fi
80+
for ver in 8 9 10; do
81+
if yq '.galaxy_info.galaxy_tags[]' "$meta_main" | grep -qi el"$ver"; then
82+
supported_platforms+=" CentOS-Stream-$ver"
83+
fi
84+
done
85+
echo "supported_platforms=$supported_platforms" >> $GITHUB_OUTPUT
86+
87+
testing-farm:
88+
name: ${{ matrix.platform }}/ansible-${{ matrix.ansible_version }}
89+
needs: prepare_vars
90+
strategy:
91+
fail-fast: false
92+
matrix:
93+
include:
94+
- platform: Fedora-39
95+
ansible_version: 2.17
96+
- platform: Fedora-40
97+
ansible_version: 2.17
98+
- platform: CentOS-7-latest
99+
ansible_version: 2.9
100+
- platform: CentOS-Stream-8
101+
ansible_version: 2.9
102+
# On CentOS-Stream-8, latest supported Ansible is 2.16
103+
- platform: CentOS-Stream-8
104+
ansible_version: 2.16
105+
- platform: CentOS-Stream-9
106+
ansible_version: 2.17
107+
- platform: CentOS-Stream-10
108+
ansible_version: 2.17
109+
runs-on: ubuntu-latest
110+
env:
111+
ARTIFACTS_DIR_NAME: "tf_${{ github.event.repository.name }}-${{ github.event.issue.number }}_\
112+
${{ matrix.platform }}-${{ matrix.ansible_version }}_\
113+
${{ needs.prepare_vars.outputs.datetime }}/artifacts"
114+
ARTIFACT_TARGET_DIR: /srv/pub/alt/linuxsystemroles/logs
115+
steps:
116+
- name: Set commit status as pending
117+
if: contains(needs.prepare_vars.outputs.supported_platforms, matrix.platform)
118+
uses: myrotvorets/set-commit-status-action@master
119+
with:
120+
sha: ${{ needs.prepare_vars.outputs.head_sha }}
121+
status: pending
122+
context: ${{ matrix.platform }}/ansible-${{ matrix.ansible_version }}
123+
description: Test started
124+
125+
- name: Set commit status as success with a description that platform is skipped
126+
if: "!contains(needs.prepare_vars.outputs.supported_platforms, matrix.platform)"
127+
uses: myrotvorets/set-commit-status-action@master
128+
with:
129+
sha: ${{ needs.prepare_vars.outputs.head_sha }}
130+
status: success
131+
context: ${{ matrix.platform }}/ansible-${{ matrix.ansible_version }}
132+
description: The role does not support this platform. Skipping.
133+
targetUrl: ""
134+
135+
- uses: sclorg/testing-farm-as-github-action@v2
136+
if: contains(needs.prepare_vars.outputs.supported_platforms, matrix.platform)
137+
env:
138+
ARTIFACTS_DIR: ${{ env.ARTIFACT_TARGET_DIR }}/${{ env.ARTIFACTS_DIR_NAME }}
139+
ARTIFACTS_URL: https://dl.fedoraproject.org/pub/alt/linuxsystemroles/logs/${{ env.ARTIFACTS_DIR_NAME }}
140+
with:
141+
git_url: ${{ github.server_url }}/${{ github.repository }}
142+
git_ref: ${{ needs.prepare_vars.outputs.head_sha }}
143+
pipeline_settings: '{ "type": "tmt-multihost" }'
144+
variables: "ANSIBLE_VER=${{ matrix.ansible_version }};\
145+
REPO_NAME=${{ github.event.repository.name }};\
146+
GITHUB_ORG=linux-system-roles;\
147+
PR_NUM=${{ github.event.issue.number }};\
148+
ARTIFACTS_DIR=${{ env.ARTIFACTS_DIR }};\
149+
ARTIFACTS_URL=${{ env.ARTIFACTS_URL }}"
150+
# Note that LINUXSYSTEMROLES_SSH_KEY must be single-line, TF doesn't read multi-line variables fine.
151+
secrets: "LINUXSYSTEMROLES_USER=${{ secrets.LINUXSYSTEMROLES_USER }};\
152+
LINUXSYSTEMROLES_DOMAIN=${{ secrets.LINUXSYSTEMROLES_DOMAIN }};\
153+
LINUXSYSTEMROLES_SSH_KEY=${{ secrets.LINUXSYSTEMROLES_SSH_KEY }}"
154+
compose: ${{ matrix.platform }}
155+
# There are two blockers for using public ranch:
156+
# 1. multihost is not supported in public https://github.com/teemtee/tmt/issues/2620
157+
# 2. Security issue that leaks long secrets - Jira TFT-2698
158+
tf_scope: private
159+
api_key: ${{ secrets.TF_API_KEY_RH }}
160+
update_pull_request_status: false
161+
tmt_hardware: '{ "memory": ">= ${{ needs.prepare_vars.outputs.memory }} MB" }'
162+
163+
- name: Set final commit status
164+
uses: myrotvorets/set-commit-status-action@master
165+
if: always() && contains(needs.prepare_vars.outputs.supported_platforms, matrix.platform)
166+
env:
167+
ARTIFACTS_URL: https://dl.fedoraproject.org/pub/alt/linuxsystemroles/logs/${{ env.ARTIFACTS_DIR_NAME }}
168+
with:
169+
sha: ${{ needs.prepare_vars.outputs.head_sha }}
170+
status: ${{ job.status }}
171+
targetUrl: ${{ env.ARTIFACTS_URL }}
172+
context: ${{ matrix.platform }}/ansible-${{ matrix.ansible_version }}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Role Name
22

3-
[![ansible-lint.yml](https://github.com/linux-system-roles/template/actions/workflows/ansible-lint.yml/badge.svg)](https://github.com/linux-system-roles/template/actions/workflows/ansible-lint.yml) [![ansible-test.yml](https://github.com/linux-system-roles/template/actions/workflows/ansible-test.yml/badge.svg)](https://github.com/linux-system-roles/template/actions/workflows/ansible-test.yml) [![markdownlint.yml](https://github.com/linux-system-roles/template/actions/workflows/markdownlint.yml/badge.svg)](https://github.com/linux-system-roles/template/actions/workflows/markdownlint.yml) [![shellcheck.yml](https://github.com/linux-system-roles/template/actions/workflows/shellcheck.yml/badge.svg)](https://github.com/linux-system-roles/template/actions/workflows/shellcheck.yml) [![woke.yml](https://github.com/linux-system-roles/template/actions/workflows/woke.yml/badge.svg)](https://github.com/linux-system-roles/template/actions/workflows/woke.yml)
3+
[![ansible-lint.yml](https://github.com/linux-system-roles/template/actions/workflows/ansible-lint.yml/badge.svg)](https://github.com/linux-system-roles/template/actions/workflows/ansible-lint.yml) [![ansible-test.yml](https://github.com/linux-system-roles/template/actions/workflows/ansible-test.yml/badge.svg)](https://github.com/linux-system-roles/template/actions/workflows/ansible-test.yml) [![markdownlint.yml](https://github.com/linux-system-roles/template/actions/workflows/markdownlint.yml/badge.svg)](https://github.com/linux-system-roles/template/actions/workflows/markdownlint.yml) [![shellcheck.yml](https://github.com/linux-system-roles/template/actions/workflows/shellcheck.yml/badge.svg)](https://github.com/linux-system-roles/template/actions/workflows/shellcheck.yml) [![tft.yml](https://github.com/linux-system-roles/template/actions/workflows/tft.yml/badge.svg)](https://github.com/linux-system-roles/template/actions/workflows/tft.yml) [![woke.yml](https://github.com/linux-system-roles/template/actions/workflows/woke.yml/badge.svg)](https://github.com/linux-system-roles/template/actions/workflows/woke.yml)
44

55
![template](https://github.com/linux-system-roles/template/workflows/tox/badge.svg)
66

meta/main.yml

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,20 @@
11
# SPDX-License-Identifier: MIT
22
---
33
galaxy_info:
4-
# Replace with role's author name:
54
author: John Doe <[email protected]>
6-
# Replace with the real description of what is role's purpose:
75
description: Basic template for Linux system roles
8-
# Replace with the company the role's author is member of:
96
company: John Doe, Inc.
10-
11-
# If the issue tracker for your role is not on github, uncomment the next
12-
# line and provide a value
13-
# issue_tracker_url: http://example.com/issue/tracker
14-
15-
# Some suggested licenses:
16-
# - BSD (default)
17-
# - MIT
18-
# - GPLv2
19-
# - GPLv3
20-
# - Apache
21-
# - CC-BY
227
license: MIT
23-
248
min_ansible_version: "2.9"
25-
26-
# Optionally specify the branch Galaxy will use when accessing the GitHub
27-
# repo for this role. During role install, if no tags are available, Galaxy
28-
# will use this branch. During import Galaxy will access files on this
29-
# branch. If Travis integration is configured, only notifications for this
30-
# branch will be accepted. Otherwise, in all cases, the repo's default branch
31-
# (usually main) will be used.
32-
# github_branch:
33-
34-
#
35-
# platforms is a list of platforms, and each platform has a name and a list
36-
# of versions.
37-
#
38-
# platforms:
39-
# - name: Fedora
40-
# versions:
41-
# - all
42-
# - "25"
43-
# - name: SomePlatform
44-
# versions:
45-
# - all
46-
# - "1.0"
47-
# - "7"
48-
# - "99.99"
499
platforms:
50-
# Replace the below with your platform list:
5110
- name: Fedora
5211
versions:
5312
- all
5413
- name: EL
5514
versions:
5615
- "9"
57-
5816
galaxy_tags:
59-
- fedora
6017
- el9
6118
- el10
62-
# List tags for your role here, one per line. A tag is a keyword that
63-
# describes and categorizes the role. Users find roles by searching for tags.
64-
# tags are also used to list platform/version support.
65-
#
66-
# NOTE: A tag is limited to a single word comprised of alphanumeric
67-
# characters. Maximum 20 tags per role.
68-
19+
- fedora
6920
dependencies: []
70-
# List your role dependencies here, one per line. Be sure to remove the '[]'
71-
# above, if you add dependencies to this list.

plans/README-plans.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Introduction CI Testing Plans
2+
3+
Linux System Roles CI runs [tmt](https://tmt.readthedocs.io/en/stable/index.html) test plans in [Testing farm](https://docs.testing-farm.io/Testing%20Farm/0.1/index.html) with the [tmt.yml](https://github.com/linux-system-roles/template/blob/main/.github/workflows/tmt.yml) GitHub workflow.
4+
5+
The plans/general.fmf plan is a test plan that is general for all roles. It does the following steps:
6+
7+
1. Provisions two machines, one used as an Ansible control node, and second used as a managed node.
8+
2. Does the required preparation on machines.
9+
3. For the given role and the given PR, runs the general test from [test.sh](https://github.com/linux-system-roles/tft-tests/blob/main/tests/general/test.sh).
10+
11+
The [tmt.yml](https://github.com/linux-system-roles/template/blob/main/.github/workflows/tmt.yml) workflow runs the above plan and uploads the results to our Fedora storage for public access.
12+
This workflow uses Testing Farm's Github Action [Schedule tests on Testing Farm](https://github.com/marketplace/actions/schedule-tests-on-testing-farm).
13+
14+
## Running Tests
15+
16+
You can run tests locally with the `tmt try` cli.
17+
18+
### Prerequisites
19+
20+
* Install `tmt` as described in [Installation](https://tmt.readthedocs.io/en/stable/stories/install.html).
21+
22+
### Running Tests Locally
23+
24+
For now, this functionality requires you to push changes to a PR because the plan only runs from the main branch, or from the PR branch.
25+
So this is WIP.
26+
27+
To run tests locally, in the role repository, enter `tmt run plans --name plans/general <platform>`.
28+
Where `<platform>` is the name of the platform you want to run tests against.
29+
30+
For example, `tmt run plans --name plans/general Fedora-40`.
31+
32+
This command identifies the plans/general plan and provisions two machines, one used as an Ansible control node, and second used as a managed node.
33+
34+
You can also use `tmt try` to get to an interreactive prompt and be able to ssh into test machines.
35+
You must run `tmt try -p plans/general Fedora-40`, and the in the promt type `p` to prepare the machines, then `t` to run the tests.

plans/general.fmf

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
summary: A general test for a system role
2+
provision:
3+
- name: control_node
4+
role: control_node
5+
# TF uses `how: artemis`, tmt try uses `how: virtual`. No need to define `how`
6+
# `connection: system` is for `how: virtual` to make VMs get a real IP to configure ssh easily
7+
# This setting is ignored on artemis so we can keep it
8+
connection: system
9+
- name: managed_node1
10+
role: managed_node
11+
connection: system
12+
environment:
13+
ANSIBLE_VER: 2.17
14+
REPO_NAME: template
15+
PYTHON_VERSION: 3.12
16+
SYSTEM_ROLES_ONLY_TESTS: ""
17+
PR_NUM: ""
18+
prepare:
19+
- name: Use vault.centos.org repos (CS 7, 8 EOL workaround)
20+
script: |
21+
if grep -q -e 'CentOS Stream release 8' -e 'CentOS Linux release 7.9' /etc/redhat-release; then
22+
sed -i '/^mirror/d;s/#\(baseurl=http:\/\/\)mirror/\1vault/' /etc/yum.repos.d/*.repo
23+
fi
24+
25+
- name: Enable epel to install beakerlib on all platforms except CS10 and Fedora, there it's not available and not needed
26+
script: |
27+
if ! grep -q -e 'CentOS Stream release 10' -e 'Fedora release' /etc/redhat-release; then
28+
yum install epel-release -y
29+
fi
30+
where: control_node
31+
32+
- name: Additional steps to enable EPEL on EL 7
33+
script: |
34+
if grep -q 'CentOS Linux release 7.9' /etc/redhat-release; then
35+
yum install yum-utils -y
36+
yum-config-manager --enable epel epel-debuginfo epel-source
37+
fi
38+
where: control_node
39+
40+
- name: Install python on managed node when running CS8 with ansible!=2.9
41+
script: |
42+
if [ "$ANSIBLE_VER" != "2.9" ] && grep -q 'CentOS Stream release 8' /etc/redhat-release; then
43+
dnf install -y python"$PYTHON_VERSION"
44+
fi
45+
where: managed_node
46+
47+
- name: Distribute SSH keys when provisioned with how=virtual
48+
script: |
49+
if [ -f ${TMT_TREE%/*}/provision/control_node/id_ecdsa.pub ]; then
50+
cat ${TMT_TREE%/*}/provision/control_node/id_ecdsa.pub >> ~/.ssh/authorized_keys
51+
fi
52+
where: managed_node
53+
54+
discover:
55+
- name: Run test playbooks from control_node
56+
how: fmf
57+
url: https://github.com/linux-system-roles/tft-tests
58+
ref: main
59+
where: control_node
60+
filter: tag:test_playbooks
61+
execute:
62+
how: tmt

0 commit comments

Comments
 (0)