From 1d023f087a36df2c4a571ad23c8790c5b478eeff Mon Sep 17 00:00:00 2001
From: sshathee <shunmugam.shatheesh@windriver.com>
Date: Thu, 4 Jul 2024 07:18:32 -0400
Subject: [PATCH] Subcloud rehoming support for usm

The subcloud rehoming process was previously migrating the
patching user/password in the subcloud. Similarly, it is
required to migrate the usm user password and id and update
related services during subcloud rehoming.

Test Plan:
PASS: Perform rehoming on DC subcloud and ensure usm services
are running

Story: 2010676
Task: 50503

Change-Id: I2117e6ea794c405cccec90f5b5f78f728d39c9ce
Signed-off-by: sshathee <shunmugam.shatheesh@windriver.com>
---
 .../update-keystone-data/tasks/main.yml                |  1 +
 .../tasks/migrate_keystone_ids.yml                     |  1 +
 .../tasks/update_keystone_user_password_for_rehome.yml | 10 +++++++++-
 .../tasks/update_secure_hieradata.yml                  |  6 ++++++
 4 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/playbookconfig/src/playbooks/roles/rehome-enroll-common/update-keystone-data/tasks/main.yml b/playbookconfig/src/playbooks/roles/rehome-enroll-common/update-keystone-data/tasks/main.yml
index 8f9d2e8c1..204b36480 100644
--- a/playbookconfig/src/playbooks/roles/rehome-enroll-common/update-keystone-data/tasks/main.yml
+++ b/playbookconfig/src/playbooks/roles/rehome-enroll-common/update-keystone-data/tasks/main.yml
@@ -25,6 +25,7 @@
           - { username: 'fm', password: "{{ users['fm'] }}", service: 'fm-mgr' }
           - { username: 'mtce', password: "{{ users['mtce'] }}", service: 'mtc-agent' }
           - { username: 'patching', password: "{{ users['patching'] }}", service: 'sw-patch-controller-daemon' }
+          - { username: 'usm', password: "{{ users['usm'] }}", service: 'software-controller-daemon' }
           - { username: 'vim', password: "{{ users['vim'] }}", service: 'vim' }
 
     - name: Update keystone passwords in secure hieradata
diff --git a/playbookconfig/src/playbooks/roles/rehome-enroll-common/update-keystone-data/tasks/migrate_keystone_ids.yml b/playbookconfig/src/playbooks/roles/rehome-enroll-common/update-keystone-data/tasks/migrate_keystone_ids.yml
index 748f5a69b..2567aa4b5 100644
--- a/playbookconfig/src/playbooks/roles/rehome-enroll-common/update-keystone-data/tasks/migrate_keystone_ids.yml
+++ b/playbookconfig/src/playbooks/roles/rehome-enroll-common/update-keystone-data/tasks/migrate_keystone_ids.yml
@@ -67,6 +67,7 @@
     - "fm-api"
     - "sm-api"
     - "sw-patch-controller-daemon"
+    - "software-controller-daemon"
 
 - name: Wait until services are restarted after changing keystone IDs
   shell: sm-query service {{ item }} | grep -c enabled-active
diff --git a/playbookconfig/src/playbooks/roles/rehome-enroll-common/update-keystone-data/tasks/update_keystone_user_password_for_rehome.yml b/playbookconfig/src/playbooks/roles/rehome-enroll-common/update-keystone-data/tasks/update_keystone_user_password_for_rehome.yml
index 5f795912b..ad23818bf 100644
--- a/playbookconfig/src/playbooks/roles/rehome-enroll-common/update-keystone-data/tasks/update_keystone_user_password_for_rehome.yml
+++ b/playbookconfig/src/playbooks/roles/rehome-enroll-common/update-keystone-data/tasks/update_keystone_user_password_for_rehome.yml
@@ -81,7 +81,7 @@
       until: service_status.stdout == '1'
       retries: 6
       delay: 10
-      when: username != 'patching'
+      when: username != 'patching' and username != 'usm'
 
     - name: Check sw-patch-controller-daemon service status
       command: systemctl is-active sw-patch-controller-daemon
@@ -91,6 +91,14 @@
       delay: 10
       when: username == 'patching'
 
+    - name: Check software-controller-daemon service status
+      command: systemctl is-active software-controller-daemon
+      register: usm_status
+      until: usm_status.rc == 0
+      retries: 6
+      delay: 10
+      when: username == 'usm'
+
     when: service != 'dcmanager'
 
   when: password_check_result.rc != 0
diff --git a/playbookconfig/src/playbooks/roles/rehome-enroll-common/update-keystone-data/tasks/update_secure_hieradata.yml b/playbookconfig/src/playbooks/roles/rehome-enroll-common/update-keystone-data/tasks/update_secure_hieradata.yml
index 594bf4113..7147ec0a9 100644
--- a/playbookconfig/src/playbooks/roles/rehome-enroll-common/update-keystone-data/tasks/update_secure_hieradata.yml
+++ b/playbookconfig/src/playbooks/roles/rehome-enroll-common/update-keystone-data/tasks/update_secure_hieradata.yml
@@ -55,6 +55,12 @@
         To: "patching::keystone::auth::password: !!python/unicode '{{ users['patching'] }}'" }
     - { From: "^patching::keystone::authtoken::password",
         To: "patching::keystone::authtoken::password: !!python/unicode '{{ users['patching'] }}'" }
+    - { From: "^usm::api::keystone_password",
+        To: "usm::api::keystone_password: !!python/unicode '{{ users['usm'] }}'" }
+    - { From: "^usm::keystone::auth::password",
+        To: "usm::keystone::auth::password: !!python/unicode '{{ users['usm'] }}'" }
+    - { From: "^usm::keystone::authtoken::password",
+        To: "usm::keystone::authtoken::password: !!python/unicode '{{ users['usm'] }}'" }
     - { From: "^platform::mtce::params::auth_pw",
         To: "platform::mtce::params::auth_pw: !!python/unicode '{{ users['mtce'] }}'" }
     - { From: "^sysinv::api::keystone_password",