From bedf3dc546982624628267f812bae24d9b73ff44 Mon Sep 17 00:00:00 2001
From: Steven Hardy <shardy@redhat.com>
Date: Thu, 1 Sep 2016 19:24:05 +0100
Subject: [PATCH] Convert SwiftDevicesAndProxyConfig to composable format

Make use of the new composable per-service node_ips lists by
adding a ServiceNetMap entry for SwiftStorage, then
pass the data to construct the raw device list into puppet-tripleo
instead of mangling it in t-h-t inside the role templates.

This will allow running swift storage services on nodes other than
the Controller and ObjectStorage roles, and is required to enable
custom roles.

Depends-On: I11deed1df712ecccf85d36a75b3bd2e9d226af36
Change-Id: I1bf5f8a9d34b1a5d64ab8656b386226b54ec1a27
Partially-Implements: blueprint custom-roles
---
 network/service_net_map.yaml               |  3 +-
 overcloud-resource-registry-puppet.yaml    |  1 -
 overcloud.yaml                             | 24 ++-------------
 puppet/controller.yaml                     | 28 +----------------
 puppet/services/swift-ringbuilder.yaml     | 18 ++++++++++-
 puppet/services/swift-storage.yaml         |  2 +-
 puppet/swift-devices-and-proxy-config.yaml | 35 ----------------------
 puppet/swift-storage.yaml                  | 26 ----------------
 8 files changed, 23 insertions(+), 114 deletions(-)
 delete mode 100644 puppet/swift-devices-and-proxy-config.yaml

diff --git a/network/service_net_map.yaml b/network/service_net_map.yaml
index 4cfff402ee..5d3f087d00 100644
--- a/network/service_net_map.yaml
+++ b/network/service_net_map.yaml
@@ -33,7 +33,7 @@ parameters:
       NovaApiNetwork: internal_api
       NovaMetadataNetwork: internal_api
       NovaVncProxyNetwork: internal_api
-      SwiftMgmtNetwork: storage_mgmt
+      SwiftStorageNetwork: storage_mgmt
       SwiftProxyNetwork: storage
       SaharaApiNetwork: internal_api
       HorizonNetwork: internal_api
@@ -61,6 +61,7 @@ parameters:
       MongoDbNetwork: MongodbNetwork
       RabbitMqNetwork: RabbitmqNetwork
       CephPublicNetwork: CephMonNetwork
+      SwiftMgmtNetwork: SwiftStorageNetwork
     description: Mapping older deprecated service names, intended for
                  internal use only, this will be removed in future.
     type: json
diff --git a/overcloud-resource-registry-puppet.yaml b/overcloud-resource-registry-puppet.yaml
index 6126fb0542..b0723dd71b 100644
--- a/overcloud-resource-registry-puppet.yaml
+++ b/overcloud-resource-registry-puppet.yaml
@@ -17,7 +17,6 @@ resource_registry:
   OS::TripleO::ObjectStoragePostDeployment: puppet/swift-storage-post.yaml
   OS::TripleO::BlockStoragePostDeployment: puppet/cinder-storage-post.yaml
   OS::TripleO::CephStoragePostDeployment: puppet/ceph-storage-post.yaml
-  OS::TripleO::SwiftDevicesAndProxy::SoftwareConfig: puppet/swift-devices-and-proxy-config.yaml
   OS::TripleO::AllNodes::SoftwareConfig: puppet/all-nodes-config.yaml
   OS::TripleO::DefaultPasswords: default_passwords.yaml
 
diff --git a/overcloud.yaml b/overcloud.yaml
index 2a02fda601..f2c4b63126 100644
--- a/overcloud.yaml
+++ b/overcloud.yaml
@@ -818,26 +818,6 @@ resources:
       StorageMgmtIpUri: {get_attr: [StorageMgmtVirtualIP, ip_address_uri]}
       # No tenant or management VIP required
 
-  ControllerSwiftDeployment:
-    type: OS::Heat::StructuredDeployments
-    properties:
-      name: ControllerSwiftDeployment
-      config: {get_attr: [SwiftDevicesAndProxyConfig, config_id]}
-      servers: {get_attr: [Controller, attributes, nova_server_resource]}
-
-  ObjectStorageSwiftDeployment:
-    type: OS::Heat::StructuredDeployments
-    properties:
-      name: ObjectStorageSwiftDeployment
-      config: {get_attr: [SwiftDevicesAndProxyConfig, config_id]}
-      servers: {get_attr: [ObjectStorage, attributes, nova_server_resource]}
-
-  SwiftDevicesAndProxyConfig:
-    type: OS::TripleO::SwiftDevicesAndProxy::SoftwareConfig
-    properties:
-      controller_swift_devices: {get_attr: [Controller, swift_device]}
-      object_store_swift_devices: {get_attr: [ObjectStorage, swift_device]}
-
   ControllerAllNodesDeployment:
     type: OS::Heat::StructuredDeployments
     properties:
@@ -975,7 +955,7 @@ resources:
   # Nested stack deployment runs after all other controller deployments
   ControllerNodesPostDeployment:
     type: OS::TripleO::ControllerPostDeployment
-    depends_on: [ControllerAllNodesDeployment, ControllerSwiftDeployment]
+    depends_on: [ControllerAllNodesDeployment]
     properties:
       servers: {get_attr: [Controller, attributes, nova_server_resource]}
       RoleData: {get_attr: [ControllerServiceChain, role_data]}
@@ -989,7 +969,7 @@ resources:
 
   ObjectStorageNodesPostDeployment:
     type: OS::TripleO::ObjectStoragePostDeployment
-    depends_on: [ObjectStorageSwiftDeployment, ObjectStorageAllNodesDeployment]
+    depends_on: [ObjectStorageAllNodesDeployment]
     properties:
       servers: {get_attr: [ObjectStorage, attributes, nova_server_resource]}
       RoleData: {get_attr: [ObjectStorageServiceChain, role_data]}
diff --git a/puppet/controller.yaml b/puppet/controller.yaml
index 1656aea767..a18d00d79f 100644
--- a/puppet/controller.yaml
+++ b/puppet/controller.yaml
@@ -62,10 +62,6 @@ parameters:
     default: nic1
     description: What interface to bridge onto br-ex for network nodes.
     type: string
-  SwiftRawDisks:
-    default: {}
-    description: 'A hash of additional raw devices to use as Swift backend (eg. {sdb: {}})'
-    type: json
   ServiceNetMap:
     default: {}
     description: Mapping of service_name -> network name. Typically set
@@ -313,8 +309,7 @@ resources:
             - service_configs
             - service_names
             - controller
-            - swift_devices_and_proxy # provided by SwiftDevicesAndProxyConfig
-            - bootstrap_node # provided by allNodesConfig
+            - bootstrap_node # provided by BootstrapNodeConfig
             - all_nodes # provided by allNodesConfig
             - vip_data # provided by allNodesConfig
             - '"%{::osfamily}"'
@@ -465,27 +460,6 @@ outputs:
     description: Heat resource handle for the Nova compute server
     value:
       {get_resource: Controller}
-  swift_device:
-    description: Swift device formatted for swift-ring-builder
-    value:
-      str_replace:
-        template:
-          list_join:
-            - ','
-            - ['r1z1-IP:%PORT%/d1']
-            - repeat:
-                template: 'r1z1-IP:%PORT%/DEVICE'
-                for_each:
-                  DEVICE: {get_param: SwiftRawDisks}
-        params:
-          IP:
-            get_attr:
-              - NetIpMap
-              - net_ip_map
-              - str_replace:
-                  template: "NETWORK_uri"
-                  params:
-                    NETWORK: {get_param: [ServiceNetMap, SwiftMgmtNetwork]}
   tls_key_modulus_md5:
     description: MD5 checksum of the TLS Key Modulus
     value: {get_attr: [NodeTLSData, key_modulus_md5]}
diff --git a/puppet/services/swift-ringbuilder.yaml b/puppet/services/swift-ringbuilder.yaml
index f41228e765..e151d185f7 100644
--- a/puppet/services/swift-ringbuilder.yaml
+++ b/puppet/services/swift-ringbuilder.yaml
@@ -1,4 +1,4 @@
-heat_template_version: 2016-04-08
+heat_template_version: 2016-10-14
 
 description: >
   OpenStack Swift Ringbuilder
@@ -34,6 +34,11 @@ parameters:
     type: number
     default: 3
     description: How many replicas to use in the swift rings.
+  SwiftRawDisks:
+    default: {}
+    description: 'A hash of additional raw devices to use as Swift backend (eg. {sdb: {}})'
+    type: json
+
 
 outputs:
   role_data:
@@ -43,6 +48,17 @@ outputs:
       config_settings:
         tripleo::profile::base::swift::ringbuilder::build_ring: {get_param: SwiftRingBuild}
         tripleo::profile::base::swift::ringbuilder::replicas: {get_param: SwiftReplicas}
+        tripleo::profile::base::swift::ringbuilder::raw_disk_prefix: 'r1z1-'
+        tripleo::profile::base::swift::ringbuilder::raw_disks:
+          yaql:
+            expression: $.data.raw_disk_lists.flatten()
+            data:
+              raw_disk_lists:
+              - [':%PORT%/d1']
+              - repeat:
+                  template: ':%PORT%/DEVICE'
+                  for_each:
+                    DEVICE: {get_param: SwiftRawDisks}
         swift::ringbuilder::part_power: {get_param: SwiftPartPower}
         swift::ringbuilder::min_part_hours: {get_param: SwiftMinPartHours}
       step_config: |
diff --git a/puppet/services/swift-storage.yaml b/puppet/services/swift-storage.yaml
index 91d5256942..7fbb8d90ff 100644
--- a/puppet/services/swift-storage.yaml
+++ b/puppet/services/swift-storage.yaml
@@ -87,6 +87,6 @@ outputs:
               - healthcheck
               - account-server
             swift::storage::disks: {get_param: SwiftRawDisks}
-            swift::storage::all::storage_local_net_ip: {get_param: [ServiceNetMap, SwiftMgmtNetwork]}
+            swift::storage::all::storage_local_net_ip: {get_param: [ServiceNetMap, SwiftStorageNetwork]}
       step_config: |
         include ::tripleo::profile::base::swift::storage
diff --git a/puppet/swift-devices-and-proxy-config.yaml b/puppet/swift-devices-and-proxy-config.yaml
deleted file mode 100644
index afee4dace8..0000000000
--- a/puppet/swift-devices-and-proxy-config.yaml
+++ /dev/null
@@ -1,35 +0,0 @@
-heat_template_version: 2015-04-30
-description: 'Swift Devices and Proxy Config for Puppet'
-
-parameters:
-  controller_swift_devices:
-    type: comma_delimited_list
-  object_store_swift_devices:
-    type: comma_delimited_list
-
-resources:
-
-  SwiftDevicesAndProxyConfigImpl:
-    type: OS::Heat::StructuredConfig
-    properties:
-      group: os-apply-config
-      config:
-        hiera:
-          datafiles:
-            swift_devices_and_proxy:
-              mapped_data:
-                tripleo::profile::base::swift::ringbuilder::devices:
-                  list_join:
-                  - ", "
-                  - - list_join:
-                      - ", "
-                      - {get_param: controller_swift_devices}
-                    - list_join:
-                      - ", "
-                      - {get_param: object_store_swift_devices}
-
-outputs:
-  config_id:
-    description: The ID of the SwiftDevicesAndProxyConfigImpl resource.
-    value:
-      {get_resource: SwiftDevicesAndProxyConfigImpl}
diff --git a/puppet/swift-storage.yaml b/puppet/swift-storage.yaml
index d8e49caced..c414d8e9f7 100644
--- a/puppet/swift-storage.yaml
+++ b/puppet/swift-storage.yaml
@@ -91,10 +91,6 @@ parameters:
     type: string
     description: Command which will be run whenever configuration data changes
     default: os-refresh-config --timeout 14400
-  SwiftRawDisks:
-    default: {}
-    description: 'A hash of additional raw devices to use as Swift backend (eg. {sdb: {}})'
-    type: json
 
 resources:
 
@@ -237,7 +233,6 @@ resources:
             - service_names
             - service_configs
             - object
-            - swift_devices_and_proxy # provided by SwiftDevicesAndProxyConfig
             - bootstrap_node # provided by allNodesConfig
             - all_nodes # provided by allNodesConfig
             - vip_data # provided by allNodesConfig
@@ -361,27 +356,6 @@ outputs:
     description: Heat resource handle for the swift storage server
     value:
       {get_resource: SwiftStorage}
-  swift_device:
-    description: Swift device formatted for swift-ring-builder
-    value:
-      str_replace:
-        template:
-          list_join:
-            - ','
-            - ['r1z1-IP:%PORT%/d1']
-            - repeat:
-                template: 'r1z1-IP:%PORT%/DEVICE'
-                for_each:
-                  DEVICE: {get_param: SwiftRawDisks}
-        params:
-          IP:
-            get_attr:
-              - NetIpMap
-              - net_ip_map
-              - str_replace:
-                  template: "NETWORK_uri"
-                  params:
-                    NETWORK: {get_param: [ServiceNetMap, SwiftMgmtNetwork]}
   external_ip_address:
     description: IP address of the server in the external network
     value: {get_attr: [ExternalPort, ip_address]}