From 7063b476f8744ab21f79de33e2127119a195c832 Mon Sep 17 00:00:00 2001 From: Jose Luis Franco Arza Date: Fri, 24 May 2019 16:18:47 +0200 Subject: [PATCH] Automate the undercloud leapp upgrade. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch covers the automation of the undercloud's operating system upgrade using Leapp. It includes a new option for Infrared --undercloud_os_upgrade that will allow us to run only the specific bits to upgrade the undercloud's OS. The node subscription needs to be done before running this set of tasks, otherwise it will fail. Before running leapp it's needed to clean up all the RHEL7 packages and some other packages which conflict with leapp, like is the case of rhos-release. Once the whole leapp upgrade and reboot has been performed, the undercloud might be unsubscribed if desired by setting the leapp_unregister variable. Due to the incompatibility of the python2 binary interpreter and RHEL8, we also need to set the ansible_python_interpreter variable at playbook level inside infrared-plugin/main.yml. Co-Authored: Natal Ngétal Change-Id: Ided7f974c571c45ab83a59c6dd35ad522555caa3 --- defaults/main.yml | 4 ++ infrared_plugin/main.yml | 10 +++- infrared_plugin/plugin.spec | 5 ++ tasks/common/undercloud_reboot.yaml | 45 ++++++++++++++++ tasks/common/undercloud_validate_upgrade.yaml | 46 +--------------- tasks/main.yml | 16 ++++-- .../create-undercloud-upgrade-scripts.yaml | 1 + tasks/upgrade/main.yml | 23 +++++++- tasks/upgrade/undercloud_os_upgrade.yaml | 53 +++++++++++++++++++ templates/workarounds.sh.j2 | 2 + 10 files changed, 156 insertions(+), 49 deletions(-) create mode 100644 tasks/common/undercloud_reboot.yaml create mode 100644 tasks/upgrade/undercloud_os_upgrade.yaml diff --git a/defaults/main.yml b/defaults/main.yml index 2a3ff4b5..2f669157 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -16,6 +16,7 @@ overcloud_stack_name: "overcloud" upgrade_noop: false update_noop: false undercloud_upgrade: false +undercloud_os_upgrade: false containerized_undercloud_upgrade: true overcloud_upgrade: false undercloud_update: false @@ -252,3 +253,6 @@ roles_upgrade_order: '__undefined__' # Packet loss threshold for a ping test loss_threshold: 1 + +# Leapp OS upgrade variables +leapp_unregister: true diff --git a/infrared_plugin/main.yml b/infrared_plugin/main.yml index e82d05bd..3d5eee2f 100644 --- a/infrared_plugin/main.yml +++ b/infrared_plugin/main.yml @@ -6,7 +6,10 @@ become: true become_method: sudo become_user: stack - + vars: + # Explicit ansible_python_interpreter to allow connecting + # to different OS releases (EL7/8) while using delegate_to. + ansible_python_interpreter: /usr/libexec/platform-python pre_tasks: - name: Set upgrade workload launch @@ -44,6 +47,11 @@ undercloud_upgrade: true when: install.undercloud.upgrade + - name: Set undercloud operating system upgrade + set_fact: + undercloud_os_upgrade: true + when: install.undercloud.os.upgrade + - name: Set undercloud reboot set_fact: undercloud_reboot: true diff --git a/infrared_plugin/plugin.spec b/infrared_plugin/plugin.spec index ed6c7ddd..42568b30 100644 --- a/infrared_plugin/plugin.spec +++ b/infrared_plugin/plugin.spec @@ -14,6 +14,11 @@ subparsers: NOTE: Upgrade require overcloud deployment script to be available in home directory of undercloud user at undercloud node default: false + undercloud-os-upgrade: + type: Bool + help: | + Upgrade Undercloud's Operating System + default: false undercloud-upgrade: type: Bool help: | diff --git a/tasks/common/undercloud_reboot.yaml b/tasks/common/undercloud_reboot.yaml new file mode 100644 index 00000000..3f556150 --- /dev/null +++ b/tasks/common/undercloud_reboot.yaml @@ -0,0 +1,45 @@ +--- +- name: reboot the undercloud + shell: "sleep 2 && shutdown -r now" + async: 1 + poll: 0 + ignore_errors: true + become: true + become_user: root + +- name: wait for node to go down + become: false + command: ping -c1 {{ ansible_host }} + register: node_down + until: node_down.rc != 0 + retries: 60 + delay: 3 + ignore_errors: true + delegate_to: localhost + when: "'hypervisor' not in groups and 'virthost' not in groups" + +- name: wait for node to go down + command: ping -c1 {{ ansible_host }} + register: node_down + until: node_down.rc != 0 + retries: 60 + delay: 3 + ignore_errors: true + delegate_to: hypervisor + when: "'hypervisor' in groups" + +- name: wait for node to go down + command: ping -c1 {{ ansible_host }} + register: node_down + until: node_down.rc != 0 + retries: 60 + delay: 3 + ignore_errors: true + delegate_to: virthost + when: "'virthost' in groups" + +- name: waiting for the undercloud to be ssh-able + wait_for_connection: + connect_timeout: 5 + sleep: 3 + timeout: 630 diff --git a/tasks/common/undercloud_validate_upgrade.yaml b/tasks/common/undercloud_validate_upgrade.yaml index bab11658..6fe54b33 100644 --- a/tasks/common/undercloud_validate_upgrade.yaml +++ b/tasks/common/undercloud_validate_upgrade.yaml @@ -22,50 +22,8 @@ - name: handle undercloud reboot block: - - name: reboot the undercloud - shell: "sleep 2 && shutdown -r now" - async: 1 - poll: 0 - ignore_errors: true - become: true - become_user: root - - - name: wait for node to go down - become: false - command: ping -c1 {{ ansible_host }} - register: node_down - until: node_down.rc != 0 - retries: 60 - delay: 3 - ignore_errors: true - delegate_to: localhost - when: "'hypervisor' not in groups and 'virthost' not in groups" - - - name: wait for node to go down - command: ping -c1 {{ ansible_host }} - register: node_down - until: node_down.rc != 0 - retries: 60 - delay: 3 - ignore_errors: true - delegate_to: hypervisor - when: "'hypervisor' in groups" - - - name: wait for node to go down - command: ping -c1 {{ ansible_host }} - register: node_down - until: node_down.rc != 0 - retries: 60 - delay: 3 - ignore_errors: true - delegate_to: virthost - when: "'virthost' in groups" - - - name: waiting for the undercloud to be ssh-able - wait_for_connection: - connect_timeout: 5 - sleep: 3 - timeout: 630 + - name: Reboot the undercloud + import_tasks: undercloud_reboot.yaml - name: assert UC services started shell: | diff --git a/tasks/main.yml b/tasks/main.yml index 305fb367..be520308 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -11,10 +11,20 @@ when: workload_launch - include: upgrade/main.yml - when: upgrade_noop|bool or undercloud_upgrade|bool or overcloud_upgrade|bool + when: > + upgrade_noop|bool or + undercloud_upgrade|bool or + undercloud_os_upgrade|bool or + overcloud_upgrade|bool - include: update/main.yml - when: update_noop|bool or undercloud_update|bool or overcloud_update|bool + when: > + update_noop|bool or + undercloud_update|bool or + overcloud_update|bool - include: fast-forward-upgrade/main.yml - when: ffu_noop|bool or ffu_undercloud_upgrade|bool or ffu_overcloud_upgrade|bool + when: > + ffu_noop|bool or + ffu_undercloud_upgrade|bool or + ffu_overcloud_upgrade|bool diff --git a/tasks/upgrade/create-undercloud-upgrade-scripts.yaml b/tasks/upgrade/create-undercloud-upgrade-scripts.yaml index 63f7838f..7b0ec6b8 100644 --- a/tasks/upgrade/create-undercloud-upgrade-scripts.yaml +++ b/tasks/upgrade/create-undercloud-upgrade-scripts.yaml @@ -12,6 +12,7 @@ dest: "{{ working_dir }}/{{ item }}.sh" mode: 0775 loop: + - 'pre_undercloud_os_upgrade_workarounds' - 'pre_undercloud_upgrade_workarounds' - 'post_undercloud_upgrade_workarounds' when: upgrade_workarounds diff --git a/tasks/upgrade/main.yml b/tasks/upgrade/main.yml index edf65dea..6dddb17c 100644 --- a/tasks/upgrade/main.yml +++ b/tasks/upgrade/main.yml @@ -5,7 +5,28 @@ apply: tags: create_undercloud_upgrade_scripts tags: create_undercloud_upgrade_scripts - when: upgrade_noop|bool or undercloud_upgrade|bool + when: > + upgrade_noop|bool or + undercloud_upgrade|bool or + undercloud_os_upgrade|bool + +- block: + - name: apply pre undercloud OS upgrade workarounds + shell: | + set -o pipefail + bash {{ working_dir }}/pre_undercloud_os_upgrade_workarounds.sh 2>&1 {{ timestamper_cmd }} > pre_undercloud_os_upgrade_workarounds.log + args: + chdir: "{{ working_dir }}" + when: upgrade_workarounds|bool + + - name: Upgrade operating system + become: true + become_user: root + import_tasks: undercloud_os_upgrade.yaml + when: not use_oooq|bool + + when: undercloud_os_upgrade|bool + tags: undercloud_os_upgrade - block: - name: apply pre undercloud upgrade workarounds diff --git a/tasks/upgrade/undercloud_os_upgrade.yaml b/tasks/upgrade/undercloud_os_upgrade.yaml new file mode 100644 index 00000000..c1b0daeb --- /dev/null +++ b/tasks/upgrade/undercloud_os_upgrade.yaml @@ -0,0 +1,53 @@ +--- +- name: Remove old RHEL7 packages + shell: | + yum -y remove *el7ost* -- \ + -*openvswitch* \ + -python2-babel \ + -python2-dateutil \ + -python2-ipaddress \ + -python2-jinja2 \ + -python2-markupsafe \ + -python2-jsonpatch \ + -python2-six \ + -python-PyMySQL \ + -python-jsonpointer + +- name: Install leapp + package: + name: leapp + state: latest + +- name: Check if rhos-release is installed + package: + name: rhos-release + state: present + check_mode: true + failed_when: false + register: rhos_release_installed + +- block: + - name: Remove rhos-release repos + command: rhos-release -x + + - name: Remove conflicting rhos-release package + package: + name: rhos-release + state: absent + when: + - rhos_release_installed.rc == 0 + - not rhos_release_installed.changed + +- name: Run leapp upgrade (download packages) + shell: | + set -o pipefail + leapp upgrade --debug 2>&1 | \ + tee {{ working_dir }}/undercloud_leapp_upgrade.log + +- name: Reboot the undercloud + import_tasks: ../common/undercloud_reboot.yaml + +- name: Unregister the node once the OS was upgraded if desired + redhat_subscription: + state: absent + when: leapp_unregister|bool diff --git a/templates/workarounds.sh.j2 b/templates/workarounds.sh.j2 index ce8bad44..26b5c728 100644 --- a/templates/workarounds.sh.j2 +++ b/templates/workarounds.sh.j2 @@ -45,6 +45,8 @@ apply_patch {{ value.basedir }} {{ value.id }} {% endif -%} {% endmacro -%} +{{ render_workarounds(pre_undercloud_os_upgrade_workarounds|default([]),'pre_undercloud_os_upgrade_workarounds') }} +{# finish pre_undercloud_os_upgrade_workarounds #} {{ render_workarounds(pre_undercloud_upgrade_workarounds|default([]),'pre_undercloud_upgrade_workarounds') }} {# finish pre_undercloud_upgrade_workarounds #} {{ render_workarounds(post_undercloud_upgrade_workarounds|default([]),'post_undercloud_upgrade_workarounds') }}