From 31ed556e6746319a97a00fc43fc4b986ebc68883 Mon Sep 17 00:00:00 2001
From: Jim Rollenhagen <jim@jimrollenhagen.com>
Date: Thu, 27 Dec 2018 14:41:53 -0500
Subject: [PATCH] Allow swift proxy server to use independent hostnames

This allows swift service endpoints to use custom hostnames, and adds the
following variables:

* swift_internal_fqdn
* swift_external_fqdn

These default to the old values of kolla_internal_fqdn or
kolla_external_fqdn.

This also adds a swift_proxy_server_listen_port option, which defaults to
swift_proxy_server_port for backward compatibility.

This option allow the user to differentiate between the port the
service listens on, and the port the service is reachable on. This is
useful for external load balancers which live on the same host as the
service itself.

While we're in here, use the ``internal_protocol`` variable for the swift
endpoint in cinder's swift backup driver configuration, instead of hardcoding
to ``http``.

Change-Id: Ibc01618383c26e16c0067f7f6b9cf5160d968d1e
Implements: blueprint service-hostnames
---
 ansible/group_vars/all.yml                         |  3 +++
 ansible/roles/cinder/templates/cinder.conf.j2      |  2 +-
 ansible/roles/swift/defaults/main.yml              | 10 +++++-----
 ansible/roles/swift/tasks/precheck.yml             |  2 +-
 ansible/roles/swift/templates/proxy-server.conf.j2 |  2 +-
 5 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/ansible/group_vars/all.yml b/ansible/group_vars/all.yml
index 4944742987..42a22f6226 100644
--- a/ansible/group_vars/all.yml
+++ b/ansible/group_vars/all.yml
@@ -380,7 +380,10 @@ storm_worker_port_range:
   start: 6700
   end: 6703
 
+swift_internal_fqdn: "{{ kolla_internal_fqdn }}"
+swift_external_fqdn: "{{ kolla_external_fqdn }}"
 swift_proxy_server_port: "8080"
+swift_proxy_server_listen_port: "{{ swift_proxy_server_port }}"
 swift_object_server_port: "6000"
 swift_account_server_port: "6001"
 swift_container_server_port: "6002"
diff --git a/ansible/roles/cinder/templates/cinder.conf.j2 b/ansible/roles/cinder/templates/cinder.conf.j2
index 6eef0f113c..789010084f 100644
--- a/ansible/roles/cinder/templates/cinder.conf.j2
+++ b/ansible/roles/cinder/templates/cinder.conf.j2
@@ -42,7 +42,7 @@ backup_share = {{ cinder_backup_share }}
 backup_file_size = 327680000
 {% elif enable_swift | bool and cinder_backup_driver == "swift" %}
 backup_driver = cinder.backup.drivers.swift.SwiftBackupDriver
-backup_swift_url = http://{{ kolla_internal_vip_address }}:{{ swift_proxy_server_port }}/v1/AUTH_
+backup_swift_url = {{ internal_protocol }}://{{ swift_internal_fqdn }}:{{ swift_proxy_server_port }}/v1/AUTH_
 backup_swift_auth = per_user
 backup_swift_auth_version = 1
 backup_swift_user =
diff --git a/ansible/roles/swift/defaults/main.yml b/ansible/roles/swift/defaults/main.yml
index 30aa7ed40c..d1d7d31386 100644
--- a/ansible/roles/swift/defaults/main.yml
+++ b/ansible/roles/swift/defaults/main.yml
@@ -10,12 +10,12 @@ swift_services:
         enabled: "{{ enable_swift }}"
         mode: "http"
         external: false
-        port: "{{ swift_proxy_server_port }}"
+        port: "{{ swift_proxy_server_listen_port }}"
       swift_api_external:
         enabled: "{{ enable_swift }}"
         mode: "http"
         external: true
-        port: "{{ swift_proxy_server_port }}"
+        port: "{{ swift_proxy_server_listen_port }}"
 
 ####################
 # Docker
@@ -52,9 +52,9 @@ swift_log_level: "{{ 'INFO' if openstack_logging_debug == 'False' else 'DEBUG'}}
 ####################
 # OpenStack
 ####################
-swift_admin_endpoint: "{{ admin_protocol }}://{{ kolla_internal_fqdn }}:{{ swift_proxy_server_port }}/v1"
-swift_internal_endpoint: "{{ internal_protocol }}://{{ kolla_internal_fqdn }}:{{ swift_proxy_server_port }}/v1/AUTH_%(tenant_id)s"
-swift_public_endpoint: "{{ public_protocol }}://{{ kolla_external_fqdn }}:{{ swift_proxy_server_port }}/v1/AUTH_%(tenant_id)s"
+swift_admin_endpoint: "{{ admin_protocol }}://{{ swift_internal_fqdn }}:{{ swift_proxy_server_port }}/v1"
+swift_internal_endpoint: "{{ internal_protocol }}://{{ swift_internal_fqdn }}:{{ swift_proxy_server_port }}/v1/AUTH_%(tenant_id)s"
+swift_public_endpoint: "{{ public_protocol }}://{{ swift_external_fqdn }}:{{ swift_proxy_server_port }}/v1/AUTH_%(tenant_id)s"
 
 swift_logging_debug: "{{ openstack_logging_debug }}"
 
diff --git a/ansible/roles/swift/tasks/precheck.yml b/ansible/roles/swift/tasks/precheck.yml
index 50291c03c9..dc53cabf3c 100644
--- a/ansible/roles/swift/tasks/precheck.yml
+++ b/ansible/roles/swift/tasks/precheck.yml
@@ -55,7 +55,7 @@
 - name: Checking free port for Swift Proxy Server
   wait_for:
     host: "{{ api_interface_address }}"
-    port: "{{ swift_proxy_server_port }}"
+    port: "{{ swift_proxy_server_listen_port }}"
     connect_timeout: 1
     timeout: 1
     state: stopped
diff --git a/ansible/roles/swift/templates/proxy-server.conf.j2 b/ansible/roles/swift/templates/proxy-server.conf.j2
index 84067cf006..c842c556a8 100644
--- a/ansible/roles/swift/templates/proxy-server.conf.j2
+++ b/ansible/roles/swift/templates/proxy-server.conf.j2
@@ -1,6 +1,6 @@
 [DEFAULT]
 bind_ip = {{ api_interface_address }}
-bind_port = {{ swift_proxy_server_port }}
+bind_port = {{ swift_proxy_server_listen_port }}
 
 log_udp_host = {{ syslog_server }}
 log_udp_port = {{ syslog_udp_port }}