From 8c2580cc85b8e7a2783ece895d7c2c476db81990 Mon Sep 17 00:00:00 2001 From: Don Penney Date: Wed, 10 Mar 2021 12:13:56 -0500 Subject: [PATCH] Introduce SX to DX migration playbook This commit introduces a migrate-subcloud.yml playbook that the user can run, with an overrides file to provide config values, to perform the migration steps for a subcloud. Once the migration playbook has been applied and the subcloud has recovered from the unlock (performed by the playbook), the second controller can be installed and configured. Story: 2008587 Task: 41743 Depends-On: https://review.opendev.org/c/starlingx/config/+/776536 Signed-off-by: Don Penney Change-Id: I1d8c1219694147baaabb183ef3debe1715aaf153 --- .../migrate-subcloud1-overrides-EXAMPLE.yml | 6 ++ .../src/playbooks/migrate_sx_to_dx.yml | 85 +++++++++++++++++++ .../roles/common/host-lock/tasks/main.yml | 28 ++++++ .../roles/common/host-unlock/tasks/main.yml | 13 +++ 4 files changed, 132 insertions(+) create mode 100644 examples/migrate/migrate-subcloud1-overrides-EXAMPLE.yml create mode 100644 playbookconfig/src/playbooks/migrate_sx_to_dx.yml create mode 100644 playbookconfig/src/playbooks/roles/common/host-lock/tasks/main.yml create mode 100644 playbookconfig/src/playbooks/roles/common/host-unlock/tasks/main.yml diff --git a/examples/migrate/migrate-subcloud1-overrides-EXAMPLE.yml b/examples/migrate/migrate-subcloud1-overrides-EXAMPLE.yml new file mode 100644 index 000000000..fdec192a5 --- /dev/null +++ b/examples/migrate/migrate-subcloud1-overrides-EXAMPLE.yml @@ -0,0 +1,6 @@ +--- +{ + "ansible_ssh_pass": "St8rlingX*", + "external_oam_node_0_address": "10.10.10.13", + "external_oam_node_1_address": "10.10.10.14", +} diff --git a/playbookconfig/src/playbooks/migrate_sx_to_dx.yml b/playbookconfig/src/playbooks/migrate_sx_to_dx.yml new file mode 100644 index 000000000..14eb3c595 --- /dev/null +++ b/playbookconfig/src/playbooks/migrate_sx_to_dx.yml @@ -0,0 +1,85 @@ +--- +# +# Copyright (c) 2021 Wind River Systems, Inc. +# +# SPDX-License-Identifier: Apache-2.0 +# +# This playbook provides the capability to migrate a subcloud from +# AIO-SX to AIO-DX. It will lock the subcloud, perform the necessary +# configuration updates, then unlock the subcloud. NOTE: This is for a +# non-ceph subcloud. +# +# To run the playbook, the user would define an overrides file that +# provides the required variable settings, passing this on the ansible +# command-line. +# (see migrate-subcloud1-overrides-EXAMPLE.yml) +# +# Example command: +# ansible-playbook /usr/share/ansible/stx-ansible/playbooks/migrate_sx_to_dx.yml \ +# -e @migrate-subcloud1-overrides.yml -i subcloud1, -v +# + +- hosts: all + gather_facts: no + + tasks: + - name: Check required parameters + debug: + msg: + - "Validating required migration parameters:" + - "ansible_ssh_pass: {{ ansible_ssh_pass | regex_replace('.', '*') }}" + - "external_oam_node_0_address: {{ external_oam_node_0_address }}" + - "external_oam_node_1_address: {{ external_oam_node_1_address }}" + failed_when: (ansible_ssh_pass | length == 0) or + (external_oam_node_0_address | ipaddr == false) or + (external_oam_node_1_address | ipaddr == false) + + - set_fact: + duplex_mode: "{{ duplex_mode | default('duplex') }}" + + - name: Query system_mode + shell: source /etc/platform/openrc; system show | awk '$2 == "system_mode" { print $4 }' + register: current_system_mode + + - name: Query oam_c0_ip + shell: source /etc/platform/openrc; system oam-show | awk '$2 == "oam_c0_ip" { print $4 }' + register: current_oam_c0_ip + + - name: Query oam_c1_ip + shell: source /etc/platform/openrc; system oam-show | awk '$2 == "oam_c1_ip" { print $4 }' + register: current_oam_c1_ip + + - block: + - name: Lock host + include_role: + name: common/host-lock + vars: + target_host: 'controller-0' + + - name: Update system mode + expect: + echo: yes + command: bash -c 'source /etc/platform/openrc; system modify -m {{ duplex_mode }} ' + responses: + (.*)Are you sure you want to continue(.*): "yes" + failed_when: false + when: current_system_mode.stdout == 'simplex' + + - name: Update OAM configuration + shell: >- + source /etc/platform/openrc; + system oam-modify oam_c0_ip={{ external_oam_node_0_address }} oam_c1_ip={{ external_oam_node_1_address }} + args: + warn: false + when: current_oam_c0_ip.stdout != external_oam_node_0_address or + current_oam_c1_ip.stdout != external_oam_node_1_address + + - name: Unlock host + include_role: + name: common/host-unlock + vars: + target_host: 'controller-0' + + when: current_system_mode.stdout == 'simplex' or + current_oam_c0_ip.stdout != external_oam_node_0_address or + current_oam_c1_ip.stdout != external_oam_node_1_address diff --git a/playbookconfig/src/playbooks/roles/common/host-lock/tasks/main.yml b/playbookconfig/src/playbooks/roles/common/host-lock/tasks/main.yml new file mode 100644 index 000000000..2fd8f8a31 --- /dev/null +++ b/playbookconfig/src/playbooks/roles/common/host-lock/tasks/main.yml @@ -0,0 +1,28 @@ +--- +# +# Copyright (c) 2021 Wind River Systems, Inc. +# +# SPDX-License-Identifier: Apache-2.0 +# + +- name: Query administrative state + shell: source /etc/platform/openrc; system host-show {{ target_host }} --column administrative --format value + register: administrative_state + +- block: + - name: Lock host + shell: source /etc/platform/openrc; system host-lock {{ target_host }} + retries: 10 + delay: 30 + register: result + until: result.rc == 0 + + - name: Wait for lock + shell: source /etc/platform/openrc; system host-show {{ target_host }} --column administrative --format value + register: check_lock + failed_when: false + retries: 30 + delay: 10 + until: check_lock.stdout == "locked" + + when: administrative_state.stdout != "locked" diff --git a/playbookconfig/src/playbooks/roles/common/host-unlock/tasks/main.yml b/playbookconfig/src/playbooks/roles/common/host-unlock/tasks/main.yml new file mode 100644 index 000000000..842dd1ca2 --- /dev/null +++ b/playbookconfig/src/playbooks/roles/common/host-unlock/tasks/main.yml @@ -0,0 +1,13 @@ +--- +# +# Copyright (c) 2021 Wind River Systems, Inc. +# +# SPDX-License-Identifier: Apache-2.0 +# + +- name: Unlock host + shell: source /etc/platform/openrc; system host-unlock {{ target_host }} + retries: 10 + delay: 30 + register: result + until: result.rc == 0