From 35ed6c6065b1e263eb69725e71639a6ea6d54cc7 Mon Sep 17 00:00:00 2001
From: James Slagle <jslagle@redhat.com>
Date: Fri, 11 Aug 2017 08:05:10 -0400
Subject: [PATCH] Don't unregister on system/resource delete

Don't unregister systems from the portal/satellite
when deleting from Heat. There are several reasons why
it's compelling to fix this behavior. See
https://bugs.launchpad.net/tripleo/+bug/1710144
for full information. The previous behavior can be triggered
by setting the DeleteOnRHELUnregistration parameter to "true".

Closes-Bug: #1710144
Change-Id: I909a6f7a049dc23fc27f2231a4893d428f06a1f1
---
 .../rhel-registration/rhel-registration.yaml  | 35 ++++++++++---------
 ...unregister-on-delete-9708f7cbc73a0d2f.yaml |  8 +++++
 2 files changed, 26 insertions(+), 17 deletions(-)
 create mode 100644 releasenotes/notes/dont-unregister-on-delete-9708f7cbc73a0d2f.yaml

diff --git a/extraconfig/pre_deploy/rhel-registration/rhel-registration.yaml b/extraconfig/pre_deploy/rhel-registration/rhel-registration.yaml
index 8b2b230898..b9fd08b4db 100644
--- a/extraconfig/pre_deploy/rhel-registration/rhel-registration.yaml
+++ b/extraconfig/pre_deploy/rhel-registration/rhel-registration.yaml
@@ -59,19 +59,18 @@ parameters:
     description: |
       When enabled, the system will perform a yum update after performing the
       RHEL Registration process.
-  deployment_actions:
-    default: ['CREATE', 'UPDATE']
-    type: comma_delimited_list
-    description: >
-      List of stack actions that will trigger any deployments in this
-      templates. The actions will be an empty list of the server is in the
-      toplevel DeploymentServerBlacklist parameter's value.
+  DeleteOnRHELUnregistration:
+    type: boolean
+    default: false
+    description: |
+      When true, the system profile will be deleted from the registration
+      service when the rhel-registration.yaml nested stack is deleted.
 
 conditions:
-  deployment_actions_empty:
+  unregister_on_delete:
     equals:
-      - {get_param: deployment_actions}
-      - []
+      - {get_param: DeleteOnRHELUnregistration}
+      - true
   update_requested:
     equals:
       - {get_param: UpdateOnRHELRegistration}
@@ -79,6 +78,12 @@ conditions:
 
 resources:
 
+  DeploymentActions:
+    type: OS::Heat::Value
+    properties:
+      value:
+        yaql
+
   RHELRegistration:
     type: OS::Heat::SoftwareConfig
     properties:
@@ -155,9 +160,9 @@ resources:
       config: {get_resource: RHELUnregistration}
       actions:
         if:
-          - deployment_actions_empty
+          - unregister_on_delete
+          - ['DELETE']
           - []
-          - ['DELETE'] # Only do this on DELETE
       input_values:
         REG_METHOD: {get_param: rhel_reg_method}
 
@@ -189,11 +194,7 @@ resources:
       name: UpdateDeploymentAfterRHELRegistration
       config: {get_resource: YumUpdateConfigurationAfterRHELRegistration}
       server:  {get_param: server}
-      actions:
-        if:
-          - deployment_actions_empty
-          - []
-          - ['CREATE'] # Only do this on CREATE
+      actions: ['CREATE'] # Only do this on CREATE
 
 outputs:
   deploy_stdout:
diff --git a/releasenotes/notes/dont-unregister-on-delete-9708f7cbc73a0d2f.yaml b/releasenotes/notes/dont-unregister-on-delete-9708f7cbc73a0d2f.yaml
new file mode 100644
index 0000000000..96e6234dc2
--- /dev/null
+++ b/releasenotes/notes/dont-unregister-on-delete-9708f7cbc73a0d2f.yaml
@@ -0,0 +1,8 @@
+---
+fixes:
+  - Don't unregister systems from the portal/satellite
+    when deleting from Heat. There are several reasons why
+    it's compelling to fix this behavior. See
+    https://bugs.launchpad.net/tripleo/+bug/1710144
+    for full information. The previous behavior can be triggered
+    by setting the DeleteOnRHELUnregistration parameter to "true".