Skip to content

Commit

Permalink
Testing extracted baremetal job
Browse files Browse the repository at this point in the history
  • Loading branch information
lewisdenny committed Mar 26, 2024
1 parent f3007af commit b111ef3
Show file tree
Hide file tree
Showing 11 changed files with 305 additions and 75 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/require-checklist.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Require Checklist

on: # noqa: yaml[truthy]
pull_request:
types: [opened, edited, synchronize]
types: [opened, edited, synchronize, ready_for_review]

# According to github, the "actor" for dependabot is dependabot[bot]:
# https://docs.github.com/en/code-security/dependabot/working-with-dependabot/automating-dependabot-with-github-actions#responding-to-events
Expand All @@ -18,6 +18,7 @@ jobs:
github.actor != 'dependabot[bot]' &&
github.actor != 'renovate[bot]'
runs-on: ubuntu-latest
if: ${{ github.event_name == 'push' || !github.event.pull_request.draft }}
steps:
- uses: mheap/require-checklist-action@v2
with:
Expand Down
35 changes: 35 additions & 0 deletions ci/playbooks/edpm_baremetal_deployment/run_extracted.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
- name: "Run ci/playbooks/edpm_baremetal_deployment/run_extracted.yml"
hosts: "{{ cifmw_zuul_target_host | default('all') }}"
gather_facts: true
tasks:
- name: Filter out host if needed
when:
- cifmw_zuul_target_host is defined
- cifmw_zuul_target_host != 'all'
- inventory_hostname != cifmw_zuul_target_host
ansible.builtin.meta: end_host

- name: Check for edpm-ansible.yml file
ansible.builtin.stat:
path: "{{ ansible_user_dir }}/ci-framework-data/artifacts/edpm-ansible.yml"
register: edpm_file

- name: Perform Podified and EDPM deployment on compute nodes with virtual baremetal
ansible.builtin.command:
chdir: "{{ ansible_user_dir }}/src/github.com/openstack-k8s-operators/ci-framework"
cmd: >-
ansible-playbook deploy-edpm.yml
-i "{{ ansible_user_dir }}/ci-framework-data/artifacts/zuul_inventory.yml"
-e @scenarios/centos-9/base.yml
-e @scenarios/centos-9/edpm_ci.yml
-e @scenarios/centos-9/edpm_baremetal_deployment_ci_extracted.yml
{%- if edpm_file.stat.exists %}
-e @{{ ansible_user_dir }}/ci-framework-data/artifacts/edpm-ansible.yml
{%- endif %}
{%- if cifmw_extras is defined %}
{%- for extra_var in cifmw_extras %}
-e "{{ extra_var }}"
{%- endfor %}
{%- endif %}
-e "@{{ ansible_user_dir }}/ci-framework-data/artifacts/parameters/zuul-params.yml"
13 changes: 13 additions & 0 deletions roles/edpm_deploy_baremetal/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@

# All variables intended for modification should be placed in this file.
# All variables within this role should have a prefix of "cifmw_edpm_deploy_baremetal"
cifmw_edpm_deploy_baremetal_hypervisor_target: baremetal-hypervisor
cifmw_edpm_deploy_baremetal_basedir: "{{ cifmw_basedir | default(ansible_user_dir ~ '/ci-framework-data') }}"
cifmw_edpm_deploy_baremetal_manifests_dir: "{{ cifmw_manifests | default(cifmw_edpm_deploy_baremetal_basedir ~ '/artifacts/manifests') }}"
cifmw_edpm_deploy_baremetal_dry_run: false
cifmw_edpm_deploy_baremetal_libvirt_user: sushyemu
cifmw_edpm_deploy_baremetal_wait_provisionserver_retries: 60
cifmw_edpm_deploy_baremetal_wait_provisionserver_timeout_mins: 20
cifmw_edpm_deploy_baremetal_wait_ironic_timeout_mins: 20
Expand All @@ -28,3 +30,14 @@ cifmw_edpm_deploy_baremetal_wait_dataplane_timeout_mins: 40
cifmw_edpm_deploy_baremetal_update_os_containers: false
cifmw_edpm_deploy_baremetal_repo_setup_override: false
cifmw_edpm_deploy_baremetal_create_vms: true
cifmw_edpm_deploy_baremetal_instance_node_count: 2
cifmw_edpm_deploy_baremetal_instance_network_name: default
cifmw_edpm_deploy_baremetal_instance_node_name_prefix: edpm-compute
cifmw_edpm_deploy_baremetal_instance_memory: 4096
cifmw_edpm_deploy_baremetal_instance_vcpu: 2
cifmw_edpm_deploy_baremetal_instance_disk_size: 20
cifmw_edpm_deploy_baremetal_instance_os_variant: centos-stream9
cifmw_edpm_deploy_baremetal_instance_virt_type: kvm
cifmw_edpm_deploy_baremetal_instance_net_model: virtio
cifmw_edpm_deploy_baremetal_console_log_dir: "/var/log/bmaas_console_logs"
cifmw_edpm_deploy_baremetal_libvirt_hooks_path: /etc/libvirt/hooks/qemu.d
19 changes: 19 additions & 0 deletions roles/edpm_deploy_baremetal/files/console_log_readme
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
This directory contains the serial console log files from the virtual BMaaS
bare-metal nodes. The *_console_* log files are the original log files and
include ANSI control codes which can make the output difficult to read. The
*_no_ansi_* log files have had ANSI control codes removed from the file and are
easier to read.

On some occasions there won't be a corresponding *_no_ansi_* log file. You may
see a log file without a date/time in the file name. In that case you can
display the logfile in your console by doing:
$ curl URL_TO_LOGFILE

This will have your terminal process the ANSI escape codes.

Another option, if you have the 'pv' executable installed, is to simulate a
low-speed connection. In this example simulate a 300 Bytes/second connection.
$ curl URL_TO_LOGFILE | pv -q -L 300

This can allow you to see some of the content before the screen is cleared by
an ANSI escape sequence.
71 changes: 71 additions & 0 deletions roles/edpm_deploy_baremetal/tasks/create_virtual_baremetal_vms.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
---
- name: Ensure packages are present
ansible.builtin.package:
name: "{{ item }}"
loop:
- libvirt
- virt-install
- qemu-kvm

- name: Ensure directories are present
ansible.builtin.file:
path: "{{ item }}"
state: directory
loop:
- "{{ cifmw_edpm_deploy_baremetal_console_log_dir }}"
- "{{ cifmw_edpm_deploy_baremetal_libvirt_hooks_path }}"

- name: Set selinux context type to "virt_log_t"
community.general.sefcontext:
target: "{{ cifmw_edpm_deploy_baremetal_console_log_dir }}(/.*)?"
setype: virt_log_t
state: present

- name: Copy README into console log directory
ansible.builtin.copy:
src: console_log_readme
dest: "{{ (cifmw_edpm_deploy_baremetal_console_log_dir, '/README') | path_join }}"

- name: Copy the qemu hook to the right directory
ansible.builtin.template:
src: logrotate_hook_py.j2
dest: "{{ (cifmw_edpm_deploy_baremetal_libvirt_hooks_path, '/10-logrotate.py') | path_join }}"
mode: u+x,g+x,o+x

- name: Enable virtualization services
ansible.builtin.systemd:
name: "{{ item }}"
state: started
enabled: true
loop:
- virtqemud
- virtstoraged
- virtnetworkd

- name: Create VMs XML
become: false
ansible.builtin.command:
cmd: >-
virt-install --connect qemu:///system
--name "{{ cifmw_edpm_deploy_baremetal_instance_node_name_prefix}}-{{ item }}"
--memory "{{ cifmw_edpm_deploy_baremetal_instance_memory }}"
--vcpus "{{ cifmw_edpm_deploy_baremetal_instance_vcpu }}"
--boot uefi,hd,bootmenu.enable=yes,firmware.feature0.name=secure-boot,firmware.feature0.enabled=no
--os-variant "{{ cifmw_edpm_deploy_baremetal_instance_os_variant }}"
--disk size="{{ cifmw_edpm_deploy_baremetal_instance_disk_size }}"
--network network="{{ cifmw_edpm_deploy_baremetal_instance_network_name }}",model="{{ cifmw_edpm_deploy_baremetal_instance_net_model }}"
--graphics vnc
--virt-type "{{ cifmw_edpm_deploy_baremetal_instance_virt_type }}"
--serial file,path="{{ cifmw_edpm_deploy_baremetal_console_log_dir }}/{{ cifmw_edpm_deploy_baremetal_instance_node_name_prefix}}-{{ item }}_console.log"
--rng /dev/urandom,rate.period=100,rate.bytes=1024
--print-xml
register: vms_xml
loop: "{{ range(1, cifmw_edpm_deploy_baremetal_instance_node_count + 1) | list }}"

- name: Define VMs
become: false
community.libvirt.virt:
command: define
xml: "{{ item.stdout }}"
uri: 'qemu:///system'
with_items: "{{vms_xml.results}}"
27 changes: 19 additions & 8 deletions roles/edpm_deploy_baremetal/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,26 @@
ansible.builtin.include_role:
name: set_openstack_containers

- name: Create virtual baremetal
when: cifmw_edpm_deploy_baremetal_create_vms | bool
vars:
make_edpm_baremetal_compute_env: "{{ cifmw_edpm_deploy_baremetal_common_env |
combine(cifmw_edpm_deploy_baremetal_make_openstack_env)}}"
make_edpm_baremetal_compute_dryrun: "{{ cifmw_edpm_deploy_baremetal_dry_run }}"
- name: "Create user {{ cifmw_edpm_deploy_baremetal_libvirt_user }}"
become: true
delegate_to: "{{ cifmw_edpm_deploy_baremetal_hypervisor_target }}"
ansible.builtin.user:
name: "{{ cifmw_edpm_deploy_baremetal_libvirt_user }}"
group: libvirt

- name: Create virtual baremetal VMs
ansible.builtin.import_tasks: create_virtual_baremetal_vms.yml
args:
apply:
delegate_to: "{{ cifmw_edpm_deploy_baremetal_hypervisor_target }}"
remote_user: "{{ cifmw_edpm_deploy_baremetal_libvirt_user }}"
become: true


- name: Deploy and configure sushy-emulator
ansible.builtin.include_role:
name: 'install_yamls_makes'
tasks_from: 'make_edpm_baremetal_compute'
name: 'sushy_emulator'
tasks_from: 'main'

- name: Deploy EDPM with baremetal
vars:
Expand Down
102 changes: 102 additions & 0 deletions roles/edpm_deploy_baremetal/templates/logrotate_hook_py.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#!/usr/bin/python3

# Copyright (c) 2017 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import datetime
import os
import re
import sys


# This script is run as a libvirt hook.
# More information here: https://libvirt.org/hooks.html

# The vbm-setup.sh script in function will replace LOG_DIR with the correct
# location. And will place the script into the correct directory.
VM_LOG_DIR = os.path.abspath("{{ cifmw_edpm_deploy_baremetal_console_log_dir }}")

# Regular expression to find ANSI escape sequences at the beginning of a string
ANSI_ESCAPE_RE = re.compile(r"""
^\x1b\[ # ANSI escape codes are ESC (0x1b) [
?([\d;]*)(\w)""", re.VERBOSE)

NOW = datetime.datetime.now().strftime("%Y-%m-%d-%H:%M:%S")


def main():
if len(sys.argv) < 3:
return

guest_name = sys.argv[1]
action = sys.argv[2]

if action != "release":
return

if not console_log_exists(guest_name):
return

new_path = move_console_log(guest_name)
if not new_path:
return

no_ansi_filename = "{}_no_ansi_{}.log".format(guest_name, NOW)
no_ansi_path = os.path.join(VM_LOG_DIR, no_ansi_filename)
create_no_ansi_file(new_path, no_ansi_path)


def create_no_ansi_file(source_filename, dest_filename):
with open(source_filename) as in_file:
data = in_file.read()

data = remove_ansi_codes(data)

with open(dest_filename, 'w') as out_file:
out_file.write(data)


def get_console_log_path(guest_name):
logfile_name = "{}_console.log".format(guest_name)
return os.path.join(VM_LOG_DIR, logfile_name)


def console_log_exists(guest_name):
return os.path.isfile(get_console_log_path(guest_name))


def move_console_log(guest_name):
new_logfile_name = "{}_console_{}.log".format(guest_name, NOW)
new_path = os.path.join(VM_LOG_DIR, new_logfile_name)
if os.path.exists(new_path):
return False
os.rename(get_console_log_path(guest_name), new_path)
return new_path


def remove_ansi_codes(data):
"""Remove any ansi codes from the provided string"""
output = ''
while data:
result = ANSI_ESCAPE_RE.match(data)
if not result:
output += data[0]
data = data[1:]
else:
data = data[result.end():]
return output


if '__main__' == __name__:
sys.exit(main())
11 changes: 11 additions & 0 deletions scenarios/centos-9/edpm_baremetal_deployment_ci_extracted.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
cifmw_install_yamls_vars:
DEPLOY_DIR: "{{ cifmw_basedir }}/artifacts/edpm_compute" # used during Baremetal deployment
INFRA_REPO: "{{ ansible_user_dir }}/src/github.com/openstack-k8s-operators/infra-operator"
BMAAS_INSTANCE_MEMORY: 8192
BMAAS_INSTANCE_VCPUS: 6
BMAAS_INSTANCE_DISK_SIZE: 40
DATAPLANE_GROWVOLS_ARGS: "/=8GB /tmp=1GB /home=1GB /var=8GB"

# edpm_deploy role vars
cifmw_edpm_deploy_baremetal: true
12 changes: 12 additions & 0 deletions zuul.d/edpm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@
crc_parameters: "--memory 32000 --disk-size 240 --cpus 12"
cifmw_manage_secrets_pullsecret_content: '{}'

# Extracted baremetal job
- job:
name: podified-multinode-edpm-deployment-crc-baremetal
nodeset: centos-9-medium-2x-centos-9-crc-extracted-2.30-3xl
parent: cifmw-podified-multinode-edpm-base-crc
vars:
cifmw_extras:
- '@scenarios/centos-9/multinode-ci.yml'
run:
- ci/playbooks/edpm_baremetal_deployment/run_extracted.yml


# Podified galera job
- job:
name: cifmw-crc-podified-galera-deployment
Expand Down
19 changes: 19 additions & 0 deletions zuul.d/nodeset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,22 @@
- name: ocps
nodes:
- crc

- nodeset:
name: centos-9-medium-2x-centos-9-crc-extracted-2.30-3xl
nodes:
- name: controller
label: cloud-centos-9-stream-tripleo-medium
- name: compute-0
label: cloud-centos-9-stream-tripleo
- name: baremetal-hypervisor
label: cloud-centos-9-stream-tripleo
- name: crc
label: coreos-crc-extracted-2-30-0-3xl
groups:
- name: computes
nodes:
- compute-0
- name: ocps
nodes:
- crc
Loading

0 comments on commit b111ef3

Please sign in to comment.