diff --git a/.github/workflows/cs9-x86.yml b/.github/workflows/cs9-x86.yml index f960715..2947c6b 100644 --- a/.github/workflows/cs9-x86.yml +++ b/.github/workflows/cs9-x86.yml @@ -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: @@ -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" diff --git a/.github/workflows/rhel9-x86.yml b/.github/workflows/rhel9-x86.yml index 34c7952..ae6552d 100644 --- a/.github/workflows/rhel9-x86.yml +++ b/.github/workflows/rhel9-x86.yml @@ -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: @@ -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 }} @@ -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 @@ -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" diff --git a/os-replace.sh b/os-replace.sh index 6e4ec23..4f3aafb 100755 --- a/os-replace.sh +++ b/os-replace.sh @@ -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" diff --git a/playbooks/deploy-libvirt.yaml b/playbooks/deploy-libvirt.yaml new file mode 100644 index 0000000..04f6599 --- /dev/null +++ b/playbooks/deploy-libvirt.yaml @@ -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 diff --git a/playbooks/templates/libvirt_nocloud.sh.j2 b/playbooks/templates/libvirt_nocloud.sh.j2 new file mode 100644 index 0000000..84072b3 --- /dev/null +++ b/playbooks/templates/libvirt_nocloud.sh.j2 @@ -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 }} diff --git a/playbooks/templates/libvirt_vm_template.xml.j2 b/playbooks/templates/libvirt_vm_template.xml.j2 new file mode 100644 index 0000000..c920c26 --- /dev/null +++ b/playbooks/templates/libvirt_vm_template.xml.j2 @@ -0,0 +1,46 @@ + + {{ instance_name }} + 2097152 + 2097152 + 1 + + +{% if arch == 'x86_64' %} + hvm +{% elif arch == 'aarch64' %} + /usr/share/AAVMF/AAVMF_CODE.fd + /var/lib/libvirt/qemu/nvram/AAVMF_VARS.fd +{% elif arch == 'ppc64le' %} + hvm +{% elif arch == 's390x' %} + hvm +{% endif %} + + + + +{% if arch == 'x86_64' or arch == 'ppc64le' or arch == 's390x' %} + +{% elif arch == 'aarch64' %} + +{% endif %} + + /usr/libexec/qemu-kvm + + + + + + + + + + + + + + + + + + diff --git a/tmt/plans/all.fmf b/tmt/plans/all.fmf index 82f80f5..37e03ec 100644 --- a/tmt/plans/all.fmf +++ b/tmt/plans/all.fmf @@ -1,5 +1,11 @@ discover: how: fmf +adjust: + - when: arch == x86_64 + provision: + hardware: + virtualization: + is-supported: true prepare: - how: install package: @@ -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: @@ -33,7 +39,7 @@ execute: /gcp: summary: Run os-replace test on gcp - tag: [gcp, stable] + tag: gcp environment+: PLATFORM: gcp prepare+: @@ -42,8 +48,6 @@ execute: - how: install package: - google-cloud-cli - discover+: - test: os-replace adjust: - when: arch == x86_64 or arch == aarch64 discover+: @@ -57,8 +61,6 @@ execute: tag: aws environment+: PLATFORM: aws - discover+: - test: os-replace adjust: - when: arch == x86_64 or arch == aarch64 discover+: @@ -66,3 +68,23 @@ execute: - 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