Skip to content
This repository has been archived by the owner on May 28, 2024. It is now read-only.

Add libvirt support #40

Merged
merged 2 commits into from
Feb 2, 2024
Merged
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
24 changes: 24 additions & 0 deletions .github/workflows/cs9-x86.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
endsWith(github.event.comment.body, '/test-cs9-x86-openstack-replace') ||
endsWith(github.event.comment.body, '/test-cs9-x86-gcp-replace') ||
endsWith(github.event.comment.body, '/test-cs9-x86-aws-replace') ||
endsWith(github.event.comment.body, '/test-cs9-x86-libvirt-replace') ||
endsWith(github.event.comment.body, '/test-cs9-x86-anaconda')) }}
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -116,3 +117,26 @@ jobs:
tmt_plan_regex: "aws"
tf_scope: private
secrets: "AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }};AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }};AWS_REGION=${{ secrets.AWS_REGION }};QUAY_USERNAME=${{ secrets.QUAY_USERNAME }};QUAY_PASSWORD=${{ secrets.QUAY_PASSWORD }};TEST_OS=centos-stream-9"

cs9-x86-libvirt-replace:
needs: pr-info
runs-on: ubuntu-latest

steps:
- name: Clone repository
uses: actions/checkout@v4
with:
ref: ${{ needs.pr-info.outputs.sha }}
fetch-depth: 0

- name: Run the tests
uses: sclorg/testing-farm-as-github-action@v1
with:
compose: CentOS-Stream-9
api_key: ${{ secrets.TF_API_KEY }}
git_url: ${{ needs.pr-info.outputs.repo_url }}
git_ref: ${{ needs.pr-info.outputs.ref }}
pull_request_status_name: "bootc-cs9-x86-libvirt-replace"
tmt_plan_regex: "local"
tf_scope: private
secrets: "QUAY_USERNAME=${{ secrets.QUAY_USERNAME }};QUAY_PASSWORD=${{ secrets.QUAY_PASSWORD }};TEST_OS=centos-stream-9"
34 changes: 29 additions & 5 deletions .github/workflows/rhel9-x86.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
endsWith(github.event.comment.body, '/test-rhel94-x86-openstack-replace') ||
endsWith(github.event.comment.body, '/test-rhel94-x86-gcp-replace') ||
endsWith(github.event.comment.body, '/test-rhel94-x86-aws-replace') ||
endsWith(github.event.comment.body, '/test-rhel94-x86-libvirt-replace') ||
endsWith(github.event.comment.body, '/test-rhel94-x86-anaconda')) }}
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -62,7 +63,7 @@ jobs:
- name: Run the tests
uses: sclorg/testing-farm-as-github-action@v1
with:
compose: CentOS-Stream-9
compose: RHEL-9.4.0-Nightly
api_key: ${{ secrets.TF_API_KEY }}
git_url: ${{ needs.pr-info.outputs.repo_url }}
git_ref: ${{ needs.pr-info.outputs.ref }}
Expand All @@ -85,14 +86,14 @@ jobs:
- name: Run the tests
uses: sclorg/testing-farm-as-github-action@v1
with:
compose: CentOS-Stream-9
compose: RHEL-9.4.0-Nightly
api_key: ${{ secrets.TF_API_KEY }}
git_url: ${{ needs.pr-info.outputs.repo_url }}
git_ref: ${{ needs.pr-info.outputs.ref }}
pull_request_status_name: "bootc-rhel94-x86-gcp-replace"
tmt_plan_regex: "gcp"
tf_scope: private
secrets: "GCP_PROJECT=${{ secrets.GCP_PROJECT }};GCP_SERVICE_ACCOUNT_NAME=${{ secrets.GCP_SERVICE_ACCOUNT_NAME }};GCP_SERVICE_ACCOUNT_FILE_B64=${{ secrets.GCP_SERVICE_ACCOUNT_FILE_B64 }};QUAY_USERNAME=${{ secrets.QUAY_USERNAME }};QUAY_PASSWORD=${{ secrets.QUAY_PASSWORD }};RHEL_REGISTRY_URL=${{ secrets.RHEL_REGISTRY_URL }};DOWNLOAD_NODE=${{ secrets.DOWNLOAD_NODE }};TEST_OS=centos-stream-9"
secrets: "GCP_PROJECT=${{ secrets.GCP_PROJECT }};GCP_SERVICE_ACCOUNT_NAME=${{ secrets.GCP_SERVICE_ACCOUNT_NAME }};GCP_SERVICE_ACCOUNT_FILE_B64=${{ secrets.GCP_SERVICE_ACCOUNT_FILE_B64 }};QUAY_USERNAME=${{ secrets.QUAY_USERNAME }};QUAY_PASSWORD=${{ secrets.QUAY_PASSWORD }};RHEL_REGISTRY_URL=${{ secrets.RHEL_REGISTRY_URL }};DOWNLOAD_NODE=${{ secrets.DOWNLOAD_NODE }};TEST_OS=rhel-9-4"

rhel94-x86-aws-replace:
needs: pr-info
Expand All @@ -108,11 +109,34 @@ jobs:
- name: Run the tests
uses: sclorg/testing-farm-as-github-action@v1
with:
compose: CentOS-Stream-9
compose: RHEL-9.4.0-Nightly
api_key: ${{ secrets.TF_API_KEY }}
git_url: ${{ needs.pr-info.outputs.repo_url }}
git_ref: ${{ needs.pr-info.outputs.ref }}
pull_request_status_name: "bootc-rhel94-x86-aws-replace"
tmt_plan_regex: "aws"
tf_scope: private
secrets: "AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }};AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }};AWS_REGION=${{ secrets.AWS_REGION }};QUAY_USERNAME=${{ secrets.QUAY_USERNAME }};QUAY_PASSWORD=${{ secrets.QUAY_PASSWORD }};RHEL_REGISTRY_URL=${{ secrets.RHEL_REGISTRY_URL }};DOWNLOAD_NODE=${{ secrets.DOWNLOAD_NODE }};TEST_OS=centos-stream-9"
secrets: "AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }};AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }};AWS_REGION=${{ secrets.AWS_REGION }};QUAY_USERNAME=${{ secrets.QUAY_USERNAME }};QUAY_PASSWORD=${{ secrets.QUAY_PASSWORD }};RHEL_REGISTRY_URL=${{ secrets.RHEL_REGISTRY_URL }};DOWNLOAD_NODE=${{ secrets.DOWNLOAD_NODE }};TEST_OS=rhel-9-4"

rhel94-x86-libvirt-replace:
needs: pr-info
runs-on: ubuntu-latest

steps:
- name: Clone repository
uses: actions/checkout@v4
with:
ref: ${{ needs.pr-info.outputs.sha }}
fetch-depth: 0

- name: Run the tests
uses: sclorg/testing-farm-as-github-action@v1
with:
compose: RHEL-9.4.0-Nightly
api_key: ${{ secrets.TF_API_KEY }}
git_url: ${{ needs.pr-info.outputs.repo_url }}
git_ref: ${{ needs.pr-info.outputs.ref }}
pull_request_status_name: "bootc-rhel94-x86-libvirt-replace"
tmt_plan_regex: "local"
tf_scope: private
secrets: "QUAY_USERNAME=${{ secrets.QUAY_USERNAME }};QUAY_PASSWORD=${{ secrets.QUAY_PASSWORD }};RHEL_REGISTRY_URL=${{ secrets.RHEL_REGISTRY_URL }};DOWNLOAD_NODE=${{ secrets.DOWNLOAD_NODE }};TEST_OS=rhel-9-4"
2 changes: 2 additions & 0 deletions os-replace.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ esac
TEST_IMAGE_NAME="${IMAGE_NAME}-os_replace"
TEST_IMAGE_URL="quay.io/redhat_emp1/${TEST_IMAGE_NAME}:${QUAY_REPO_TAG}"

[[ $- =~ x ]] && debug=1 && set +x
sed "s/REPLACE_ME/$(echo -n "${QUAY_USERNAME}:${QUAY_PASSWORD}" | base64 -w 0)/g" files/auth.template | tee auth.json > /dev/null
[[ $debug == 1 ]] && set -x
greenprint "Create $TEST_OS installation Containerfile"
tee "$INSTALL_CONTAINERFILE" > /dev/null << EOF
FROM "$TIER1_IMAGE_URL"
Expand Down
119 changes: 119 additions & 0 deletions playbooks/deploy-libvirt.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
---
- hosts: cloud
gather_facts: false
become: false
vars:
test_os: "{{ lookup('env', 'TEST_OS') | default('centos-stream-9', true) }}"
arch: "{{ lookup('env', 'ARCH') | default('x86_64', true) }}"
ssh_key_pub: ""
inventory_file: ""
download_node: "{{ lookup('env', 'DOWNLOAD_NODE') | default('', true) }}"
instance_name: bootc-{{ test_os }}
image_path: "/var/lib/libvirt/images"

tasks:
- set_fact:
random_num: "{{ 9999 | random(start=1001) }}"

- name: Get rhel-guest-image filename
shell: curl -s http://{{ download_node }}/rhel-9/nightly/RHEL-9/latest-RHEL-9.4.0/compose/BaseOS/{{ arch }}/images/ | grep -oP '(?<=href=")rhel-guest-image-[^"]+.qcow2(?=")'
register: out

- set_fact:
rhel_guest_image_fname: "{{ out.stdout }}"

- name: Download rhel-guest-image
uri:
url: "http://{{ download_node }}/rhel-9/nightly/RHEL-9/latest-RHEL-9.4.0/compose/BaseOS/{{ arch }}/images/{{ rhel_guest_image_fname }}"
dest: "{{ image_path }}"
creates: "{{ image_path }}/{{ rhel_guest_image_fname }}"
validate_certs: false

- name: Read ssh_key_pub content
command: cat "{{ ssh_key_pub }}"
register: out

- set_fact:
ssh_pubkey_content: "{{ out.stdout }}"

- name: Start libvirtd service
command: systemctl start libvirtd.service
become: true

- name: Generate libvirt_nocloud.sh
template:
src: libvirt_nocloud.sh.j2
dest: "{{ playbook_dir }}/libvirt_nocloud.sh"
mode: 0755

- name: Generate nocloud.iso
command: "{{ playbook_dir }}/libvirt_nocloud.sh"

- name: Define a VM
community.libvirt.virt:
command: define
xml: "{{ lookup('template', 'libvirt_vm_template.xml.j2') }}"
become: true

- name: Start a VM
community.libvirt.virt:
name: "{{ instance_name }}"
state: running
xml: "{{ lookup('template', 'libvirt_vm_template.xml.j2') }}"
become: true

- name: Get VM IP address
shell:
virsh domifaddr {{ instance_name }} | grep -oP '(?:\d+\.){3}\d+'
register: result
until: result.stdout != ""
retries: 30
delay: 10
become: true

- set_fact:
instance_ip: "{{ result.stdout }}"

- name: Waits until instance is reachable
wait_for:
host: "{{ instance_ip }}"
port: 22
search_regex: OpenSSH
delay: 10
retries: 30
register: result_ssh_check
until: result_ssh_check is success

- name: Add instance ip into host group guest
add_host:
name: "{{ instance_ip }}"
groups: guest

- name: Wait 10 seconds for VM
wait_for:
timeout: 10
delegate_to: localhost

- name: Write instance ip to inventory file
community.general.ini_file:
path: "{{ inventory_file }}"
section: guest
option: guest ansible_host
value: "{{ instance_ip }}"
no_extra_spaces: true

- name: Write random number to inventory file
community.general.ini_file:
path: "{{ inventory_file }}"
section: cloud:vars
option: random_num
value: "{{ random_num }}"
no_extra_spaces: true

- name: Write instance name to inventory file
community.general.ini_file:
path: "{{ inventory_file }}"
section: cloud:vars
option: instance_name
value: "{{ instance_name }}"
no_extra_spaces: true
35 changes: 35 additions & 0 deletions playbooks/templates/libvirt_nocloud.sh.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

{
echo instance-id: id-{{ random_num }}
echo local-hostname: {{ test_os }}
} >meta-data

printf "#cloud-config
users:
- default
disable_root: false
runcmd:
- echo 'PermitRootLogin yes' >> /etc/ssh/sshd_config
- systemctl reload sshd
ssh_authorized_keys:
- {{ ssh_pubkey_content }}
write_files:
- path: /etc/yum.repos.d/eng.repo
permissions: '0644'
content: |
[RHEL-\$releasever-AppStream]
name = RHEL-\$releasever-AppStream
baseurl = http://{{ download_node }}/rhel-\$releasever/nightly/RHEL-\$releasever/latest-RHEL-\$releasever/compose/AppStream/\$basearch/os/
enabled = 1
gpgcheck = 0

[RHEL-\$releasever-BaseOS]
name = RHEL-\$releasever-BaseOS
baseurl = http://{{ download_node }}/rhel-\$releasever/nightly/RHEL-\$releasever/latest-RHEL-\$releasever/compose/BaseOS/\$basearch/os/
enabled = 1
gpgcheck = 0
owner: 'root:root'
" >user-data
xorriso -as mkisofs -input-charset utf8 -o nocloud.iso -volid cidata -joliet -rock user-data meta-data
[[ -w {{ image_path }} ]] && mv nocloud.iso {{ image_path }}
46 changes: 46 additions & 0 deletions playbooks/templates/libvirt_vm_template.xml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<domain type='kvm'>
<name>{{ instance_name }}</name>
<memory unit='KiB'>2097152</memory>
<currentMemory unit='KiB'>2097152</currentMemory>
<vcpu>1</vcpu>
<os>
<boot dev='hd'/>
{% if arch == 'x86_64' %}
<type arch='x86_64' machine='q35'>hvm</type>
{% elif arch == 'aarch64' %}
<loader readonly='yes' type='pflash'>/usr/share/AAVMF/AAVMF_CODE.fd</loader>
<nvram template='/usr/share/AAVMF/AAVMF_VARS.fd'>/var/lib/libvirt/qemu/nvram/AAVMF_VARS.fd</nvram>
{% elif arch == 'ppc64le' %}
<type arch='ppc64le' machine='pseries'>hvm</type>
{% elif arch == 's390x' %}
<type arch='s390x' machine='s390-ccw-virtio'>hvm</type>
{% endif %}
</os>
<features>
<apic/>
</features>
{% if arch == 'x86_64' or arch == 'ppc64le' or arch == 's390x' %}
<cpu mode='host-model'/>
{% elif arch == 'aarch64' %}
<cpu mode='host-passthrough'/>
{% endif %}
<devices>
<emulator>/usr/libexec/qemu-kvm</emulator>
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
<source file='{{ image_path }}/{{ rhel_guest_image_fname }}'/>
<target dev='sda' bus='scsi'/>
</disk>
<disk type='file' device='cdrom'>
<driver name='qemu' type='raw'/>
<source file='{{ image_path }}/nocloud.iso'/>
<target dev='sdb'/>
<readonly/>
</disk>
<interface type='network'>
<source network='default' bridge='virbr0'/>
<model type='virtio'/>
</interface>
<console type='pty'/>
</devices>
</domain>
34 changes: 28 additions & 6 deletions tmt/plans/all.fmf
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
discover:
how: fmf
adjust:
- when: arch == x86_64
provision:
hardware:
virtualization:
is-supported: true
prepare:
- how: install
package:
Expand All @@ -13,7 +19,7 @@ prepare:
- how: shell
script: |
pip install boto3 botocore openstacksdk
ansible-galaxy collection install openstack.cloud community.general amazon.aws ansible.posix
ansible-galaxy collection install openstack.cloud community.general community.libvirt amazon.aws ansible.posix
- how: shell
script: curl "https://awscli.amazonaws.com/awscli-exe-linux-$(uname -m).zip" -o "awscliv2.zip" && unzip awscliv2.zip && sudo ./aws/install
execute:
Expand All @@ -33,7 +39,7 @@ execute:

/gcp:
summary: Run os-replace test on gcp
tag: [gcp, stable]
tag: gcp
environment+:
PLATFORM: gcp
prepare+:
Expand All @@ -42,8 +48,6 @@ execute:
- how: install
package:
- google-cloud-cli
discover+:
test: os-replace
adjust:
- when: arch == x86_64 or arch == aarch64
discover+:
Expand All @@ -57,12 +61,30 @@ execute:
tag: aws
environment+:
PLATFORM: aws
discover+:
test: os-replace
adjust:
- when: arch == x86_64 or arch == aarch64
discover+:
test: os-replace
- when: arch != x86_64 and arch != aarch64
discover+:
test: N/A

/local:
summary: Run os-replace test locally (nested)
tag: [local, stable]
environment+:
PLATFORM: libvirt
prepare+:
- how: install
package:
- python3-libvirt
- python3-lxml
- qemu-kvm
- libvirt
- xorriso
adjust:
- when: arch == x86_64
discover+:
test: os-replace
- when: arch != x86_64
enabled: false
Loading