From 9f2ace711b05b8cae58266badc4e8e9b45887d60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Jeanneret?= Date: Tue, 26 Mar 2024 13:21:29 +0100 Subject: [PATCH] Try to get a faster reproducer role By leveraging some `async` and reorganizing tasks and tags, we're now able to get a slightly faster run of the role itself. It's not really visible yet, mostly due to libvirt_manager being slow, but a notable improvement is at the tags level: running `ansible-playbook [...] --tags bootstrap_env,deploy_architecture`, you'll be able to: - ensure parameters are up-to-date on the controller-0 - go through the "deploy architecture" path More work and doc will come once we're able to validate the various tag combination. --- .../tasks/configure_architecture.yml | 2 + roles/reproducer/tasks/configure_computes.yml | 26 +++- .../reproducer/tasks/configure_controller.yml | 122 +++++++++++------- roles/reproducer/tasks/libvirt_layout.yml | 13 +- roles/reproducer/tasks/main.yml | 37 +++++- 5 files changed, 144 insertions(+), 56 deletions(-) diff --git a/roles/reproducer/tasks/configure_architecture.yml b/roles/reproducer/tasks/configure_architecture.yml index 900764f55c..8478b4af85 100644 --- a/roles/reproducer/tasks/configure_architecture.yml +++ b/roles/reproducer/tasks/configure_architecture.yml @@ -30,5 +30,7 @@ when: - cifmw_deploy_architecture | default(false) | bool no_log: false + async: 7200 # 2h should be enough to deploy EDPM. + poll: 20 ansible.builtin.command: cmd: "/home/zuul/deploy-architecture.sh" diff --git a/roles/reproducer/tasks/configure_computes.yml b/roles/reproducer/tasks/configure_computes.yml index 3596e7d6b2..6e488be4d0 100644 --- a/roles/reproducer/tasks/configure_computes.yml +++ b/roles/reproducer/tasks/configure_computes.yml @@ -43,9 +43,12 @@ - cifmw_repo_setup_rhos_release_rpm is defined block: - name: Get rhos-release - ansible.builtin.import_tasks: rhos_release.yml + ansible.builtin.include_tasks: rhos_release.yml - name: Configure rhos-release + register: _async_rhos_release + async: 120 # 2 minutes should be enough? + poll: 0 ansible.builtin.command: cmd: "rhos-release {{ cifmw_repo_setup_rhos_release_args }}" @@ -61,3 +64,24 @@ loop: "{{ cifmw_reproducer_compute_repos }}" loop_control: label: "{{ item.name }}" + + - name: Ensure rhos-release is configured + become: true + when: + - _async_rhos_release.ansible_job_id is defined + block: + - name: Ensure async flag still exists + register: _async_flag + ansible.builtin.stat: + path: >- + /root/.ansible_async/{{ _async_rhos_release.ansible_job_id }} + + - name: Ensure rhos-release task is over + when: + - _async_flag.stat.exists + ansible.builtin.async_status: + jid: "{{ _async_rhos_release.ansible_job_id }}" + register: _async_result + until: _async_result.finished + retries: 20 + delay: 5 diff --git a/roles/reproducer/tasks/configure_controller.yml b/roles/reproducer/tasks/configure_controller.yml index f3d407cd0c..d53224fee7 100644 --- a/roles/reproducer/tasks/configure_controller.yml +++ b/roles/reproducer/tasks/configure_controller.yml @@ -29,6 +29,58 @@ loop: - parameters - artifacts + - name: Install custom CA if needed + ansible.builtin.import_role: + name: install_ca + + - name: RHEL repository setup for ansible-controller + become: true + when: + - cifmw_repo_setup_rhos_release_rpm is defined + block: + - name: Get rhos-release + ansible.builtin.import_tasks: rhos_release.yml + + - name: Create bundle for CRC + ansible.builtin.shell: + cmd: >- + set -o pipefail; + cat /etc/pki/ca-trust/source/anchors/* > + /etc/pki/ca-trust/source/anchors/rh.crt + creates: "/etc/pki/ca-trust/source/anchors/rh.crt" + + - name: Tweak dnf configuration + become: true + community.general.ini_file: + no_extra_spaces: true + option: "{{ config.option }}" + path: "/etc/dnf/dnf.conf" + section: "{{ config.section | default('main') }}" + state: "{{ config.state | default(omit) }}" + value: "{{ config.value | default(omit) }}" + loop: "{{ cifmw_reproducer_dnf_tweaks }}" + loop_control: + label: "{{ config.option }}" + loop_var: 'config' + + - name: Install some tools + become: true + async: 600 # 10 minutes should be enough + poll: 0 + register: _async_pkg_install + ansible.builtin.package: + name: + - bash-completion + - git-core + - make + - podman + - python3-jmespath + - python3-netaddr + - python3-pip + - tmux + - vim + - wget + - jq - name: Build job inventory for hook usage tags: @@ -48,6 +100,8 @@ - name: Push the MAC mapping data tags: - bootstrap + when: + - cifmw_libvirt_manager_mac_map is defined ansible.builtin.copy: dest: "{{ _ctl_reproducer_basedir }}/parameters/interfaces-info.yml" content: "{{ cifmw_libvirt_manager_mac_map | to_nice_yaml }}" @@ -150,7 +204,8 @@ state: directory owner: zuul group: zuul - mode: "0755" + mode: "0750" + - name: Inject kubeconfig content when: - _devscripts_kubeconfig is defined or _crc_kubeconfig is defined @@ -164,7 +219,7 @@ }} owner: zuul group: zuul - mode: "0644" + mode: "0640" - name: Inject kubeadmin-password if exists when: @@ -193,61 +248,32 @@ state: directory mode: "0755" - - name: Tweak dnf configuration + - name: Ensure packages are installed become: true - community.general.ini_file: - no_extra_spaces: true - option: "{{ config.option }}" - path: "/etc/dnf/dnf.conf" - section: "{{ config.section | default('main') }}" - state: "{{ config.state | default(omit) }}" - value: "{{ config.value | default(omit) }}" - loop: "{{ cifmw_reproducer_dnf_tweaks }}" - loop_control: - label: "{{ config.option }}" - loop_var: 'config' - - - name: Install custom CA if needed - ansible.builtin.import_role: - name: install_ca - - - name: RHEL repository setup for ansible-controller - become: true - when: - - cifmw_repo_setup_rhos_release_rpm is defined block: - - name: Get rhos-release - ansible.builtin.import_tasks: rhos_release.yml + - name: Check if async file is still available + register: _async_flag + ansible.builtin.stat: + path: >- + /root/.ansible_async/{{ _async_pkg_install.ansible_job_id }} - - name: Create bundle for CRC - ansible.builtin.shell: - cmd: >- - set -o pipefail; - cat /etc/pki/ca-trust/source/anchors/* > - /etc/pki/ca-trust/source/anchors/rh.crt - creates: "/etc/pki/ca-trust/source/anchors/rh.crt" - - - name: Install some tools - become: true - ansible.builtin.package: - name: - - bash-completion - - git-core - - make - - podman - - python3-jmespath - - python3-netaddr - - python3-pip - - tmux - - vim - - wget - - jq + - name: Check package install status + when: + - _async_flag.stat.exists + register: _async_status + ansible.builtin.async_status: + jid: "{{ _async_pkg_install.ansible_job_id }}" + until: _async_status.finished + retries: 100 + delay: 5 - name: Install ansible dependencies ansible.builtin.pip: requirements: https://raw.githubusercontent.com/openstack-k8s-operators/ci-framework/main/common-requirements.txt - name: Inject most of the cifmw_ parameters passed to the reproducer run + tags: + - bootstrap_env vars: _filtered_vars: >- {{ diff --git a/roles/reproducer/tasks/libvirt_layout.yml b/roles/reproducer/tasks/libvirt_layout.yml index 50ec00cb4a..1f5e8ddb49 100644 --- a/roles/reproducer/tasks/libvirt_layout.yml +++ b/roles/reproducer/tasks/libvirt_layout.yml @@ -69,7 +69,8 @@ tags: - bootstrap - bootstrap_layout - ansible.builtin.import_tasks: configure_controller.yml + - bootstrap_env + ansible.builtin.include_tasks: configure_controller.yml - name: Configure CRC node if available when: @@ -82,7 +83,12 @@ tags: - bootstrap - bootstrap_layout - ansible.builtin.import_tasks: configure_crc.yml + ansible.builtin.include_tasks: + file: configure_crc.yml + apply: + tags: + - boostrap + - bootstrap_layout # We have to configure the compute ctlplane interface. # In order to do this, we'll consume the generated networking_mapper @@ -103,7 +109,8 @@ _controller_ip4: "{{ cifmw_networking_env_definition.instances['controller-0'].networks.ctlplane.ip_v4 }}" _prefix: "{{cifmw_networking_env_definition.networks.ctlplane.network_v4 | ansible.utils.ipaddr('prefix') }}" ansible.builtin.include_tasks: configure_computes.yml - loop: "{{ cifmw_networking_env_definition.instances | dict2items }}" + loop: >- + {{ cifmw_networking_env_definition.instances | dict2items }} loop_control: loop_var: compute label: "{{ compute.key }}" diff --git a/roles/reproducer/tasks/main.yml b/roles/reproducer/tasks/main.yml index ad36e3d30f..44eeb7e2c3 100644 --- a/roles/reproducer/tasks/main.yml +++ b/roles/reproducer/tasks/main.yml @@ -61,8 +61,13 @@ - name: Bootstrap libvirt if needed when: - cifmw_use_libvirt | default(false) | bool + tags: + - bootstrap_libvirt ansible.builtin.include_role: name: libvirt_manager + apply: + tags: + - bootstrap_libvirt - name: Deploy CRC if needed when: @@ -76,7 +81,13 @@ - bootstrap - bootstrap_layout - crc_layout - ansible.builtin.include_tasks: crc_layout.yml + ansible.builtin.include_tasks: + file: crc_layout.yml + apply: + tags: + - bootstrap + - bootstrap_layout + - crc_layout - name: Consume dev-scripts for OCP cluster when: @@ -89,7 +100,13 @@ tags: - bootstrap - boostrap_layout - ansible.builtin.include_tasks: devscripts_layout.yml + - libvirt_layout + ansible.builtin.include_tasks: + file: devscripts_layout.yml + apply: + tags: + - bootstrap + - bootstrap_layout - name: Consume libvirt_manager when: @@ -97,7 +114,13 @@ tags: - bootstrap - bootstrap_layout - ansible.builtin.include_tasks: libvirt_layout.yml + - bootstrap_env + ansible.builtin.include_tasks: + file: libvirt_layout.yml + apply: + tags: + - bootstrap + - bootstrap_layout - name: Apply VLAN ids to TAP type interfaces. when: @@ -161,7 +184,13 @@ - name: Prepare VA deployment when: - cifmw_architecture_scenario is defined - ansible.builtin.include_tasks: configure_architecture.yml + tags: + - deploy_architecture + ansible.builtin.include_tasks: + file: configure_architecture.yml + apply: + tags: + - deploy_architecture - name: Prepare ci-like EDPM deploy delegate_to: controller-0