From 9164e6adbdce69a2b7c10e1aea6c5cb309b6754e Mon Sep 17 00:00:00 2001
From: Carlos Camacho <ccamacho@redhat.com>
Date: Mon, 21 Jan 2019 16:05:58 +0100
Subject: [PATCH] Move UpgradeInitCommand and UpgradeInitCommonCommand to run
 by Ansible

This change moves the execution of UpgradeInitCommand
and UpgradeInitCommonCommand to be executed with
Ansible in the upgrade step 0 instead of Heat.

Closes-bug: 1812659
Change-Id: I76eb6a2572e24b6f114e38897a68cd85276af3c6
---
 deployed-server/deployed-server.yaml          | 21 ---------
 .../tripleo-packages-baremetal-puppet.yaml    | 44 +++++++++++++++----
 puppet/role.role.j2.yaml                      | 28 ------------
 3 files changed, 36 insertions(+), 57 deletions(-)

diff --git a/deployed-server/deployed-server.yaml b/deployed-server/deployed-server.yaml
index a777662fba..3f025ed395 100644
--- a/deployed-server/deployed-server.yaml
+++ b/deployed-server/deployed-server.yaml
@@ -69,26 +69,6 @@ resources:
       software_config_transport: {get_param: software_config_transport}
       deployment_swift_data: {get_param: deployment_swift_data}
 
-  UpgradeInitConfig:
-    type: OS::Heat::SoftwareConfig
-    properties:
-      group: script
-      config:
-        list_join:
-        - ''
-        - - "#!/bin/bash\n\n"
-          - "if [[ -f /etc/resolv.conf.save ]] ; then rm /etc/resolv.conf.save; fi\n\n"
-          - get_param: UpgradeInitCommand
-          - get_param: UpgradeInitCommonCommand
-
-  UpgradeInitDeployment:
-    type: OS::Heat::SoftwareDeployment
-    properties:
-      name: UpgradeInitDeployment
-      server: {get_resource: deployed-server}
-      config: {get_resource: UpgradeInitConfig}
-
-
   InstanceIdConfig:
     type: OS::Heat::StructuredConfig
     properties:
@@ -102,7 +82,6 @@ resources:
       name: InstanceIdDeployment
       config: {get_resource: InstanceIdConfig}
       server: {get_resource: deployed-server}
-    depends_on: UpgradeInitDeployment
 
   HostsEntryConfig:
     type: OS::Heat::SoftwareConfig
diff --git a/deployment/tripleo-packages/tripleo-packages-baremetal-puppet.yaml b/deployment/tripleo-packages/tripleo-packages-baremetal-puppet.yaml
index 6a1440b594..e9d82aa00d 100644
--- a/deployment/tripleo-packages/tripleo-packages-baremetal-puppet.yaml
+++ b/deployment/tripleo-packages/tripleo-packages-baremetal-puppet.yaml
@@ -51,6 +51,20 @@ parameters:
       echo "and passed the upstream name (ocata, pike, queens) of the release as first argument"
       exit 1
     type: string
+  UpgradeInitCommand:
+    type: string
+    description: |
+      Command or script snippet to run on all overcloud nodes to
+      initialize the upgrade process. E.g. a repository switch.
+    default: ''
+  UpgradeInitCommonCommand:
+    type: string
+    description: |
+      Common commands required by the upgrades process. This should not
+      normally be modified by the operator and is set and unset in the
+      major-upgrade-composable-steps.yaml and major-upgrade-converge.yaml
+      environment files.
+    default: ''
 
 outputs:
   role_data:
@@ -62,15 +76,29 @@ outputs:
       step_config: |
         include ::tripleo::packages
       upgrade_tasks:
-        - name: Check yum for rpm-python present
+        - name: Package and repo update tasks
           when: step|int == 0
-          package: "name=rpm-python state=present"
-          register: rpm_python_check
-        - name: Fail when rpm-python wasn't present
-          fail: msg="rpm-python package was not present before this run! Check environment before re-running"
-          when:
-            - step|int == 0
-            - rpm_python_check.changed != false
+          block:
+            - name: Run UpgradeInitCommand
+              shell:
+                list_join:
+                  - ''
+                  - - "#!/bin/bash\n\n"
+                    - "if [[ -f /etc/resolv.conf.save ]] ; then rm /etc/resolv.conf.save; fi\n\n"
+                    - {get_param: UpgradeInitCommand}
+            - name: Run UpgradeInitCommonCommand
+              shell:
+                list_join:
+                  - ''
+                  - - "#!/bin/bash\n\n"
+                    - {get_param: UpgradeInitCommonCommand}
+            - name: Check yum for rpm-python present
+              package: "name=rpm-python state=present"
+              register: rpm_python_check
+            - name: Fail when rpm-python wasn't present
+              fail: msg="rpm-python package was not present before this run! Check environment before re-running"
+              when:
+                - rpm_python_check.changed != false
         # With the layered product packaging, the key package is rhosp-openvswitch. It depends on
         # a openvswitch package that includes the version as part of the name (e.g openvswitch2.10).
         # This requires some additional special handling:
diff --git a/puppet/role.role.j2.yaml b/puppet/role.role.j2.yaml
index de3cd571c2..63dcc37736 100644
--- a/puppet/role.role.j2.yaml
+++ b/puppet/role.role.j2.yaml
@@ -630,36 +630,8 @@ resources:
             - {get_param: NetworkDeploymentActions}
           - []
 
-  {{server_resource_name}}UpgradeInitConfig:
-    type: OS::Heat::SoftwareConfig
-    properties:
-      group: script
-      config:
-        list_join:
-        - ''
-        - - "#!/bin/bash\n\n"
-          - "if [[ -f /etc/resolv.conf.save ]] ; then rm /etc/resolv.conf.save; fi\n\n"
-          - get_param: UpgradeInitCommand
-          - get_param: UpgradeInitCommonCommand
-
-  # Note we may be able to make this conditional on UpgradeInitCommandNotEmpty
-  # but https://bugs.launchpad.net/heat/+bug/1649900 needs fixing first
-  {{server_resource_name}}UpgradeInitDeployment:
-    type: OS::Heat::SoftwareDeployment
-    depends_on: NetworkDeployment
-    properties:
-      name: {{server_resource_name}}UpgradeInitDeployment
-      server: {get_resource: {{server_resource_name}}}
-      config: {get_resource: {{server_resource_name}}UpgradeInitConfig}
-      actions:
-        if:
-          - server_not_blacklisted
-          - ['CREATE', 'UPDATE']
-          - []
-
   {{server_resource_name}}Deployment:
     type: OS::Heat::StructuredDeployment
-    depends_on: {{server_resource_name}}UpgradeInitDeployment
     properties:
       name: {{server_resource_name}}Deployment
       config: {get_resource: {{server_resource_name}}Config}