From 834e39fc7e66c3c9973a1a44c13580e935bba40b Mon Sep 17 00:00:00 2001
From: Martin Kopec <mkopec@redhat.com>
Date: Wed, 17 Feb 2021 23:12:11 +0000
Subject: [PATCH] refstack: Edit URL of public RefStackAPI

The previous refstack server had 'api' in the endpoint
addresses of API calls. Let's try to set it in the new
instance as well to keep the same interface.

Also, fix the typo in the testinfra host match and in
the test name.

Change-Id: I7319990144396b3a753678975a09b0add3ac4465
---
 .../roles/refstack/templates/refstack.vhost.j2      | 13 +++++++++++++
 testinfra/test_refstack.py                          |  8 ++++----
 zuul.d/system-config-run.yaml                       |  1 +
 3 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/playbooks/roles/refstack/templates/refstack.vhost.j2 b/playbooks/roles/refstack/templates/refstack.vhost.j2
index cdbbc24ab7..6dec957502 100644
--- a/playbooks/roles/refstack/templates/refstack.vhost.j2
+++ b/playbooks/roles/refstack/templates/refstack.vhost.j2
@@ -40,6 +40,19 @@
   ProxyPass  / http://localhost:8000/ retry=0
   ProxyPassReverse / http://localhost:8000/
 
+  # Redirect all /api requests to the internal server's address for backward
+  # compatibility - previously the vhost configuration redirected all /api
+  # requests to a wsgi app which executed refstack to handle the request.
+  # Now the refstack server is containerized and the server is served by pecan
+  # where 'pecan serve' does the same as the wsgi app before plus it also
+  # serves the UI interface. This has caused that the resources previously
+  # found under /api/ are one level higher (omitting the /api part of the
+  # URLs).
+  # Example: <hostname>/api/v1/results is now at <hostname>/v1/results
+  <Location "/api/">
+    ProxyPass "http://localhost:8000/"
+  </Location>
+
   <Location "/robots.txt">
     ProxyPass !
   </Location>
diff --git a/testinfra/test_refstack.py b/testinfra/test_refstack.py
index b126f02d45..9fbb7f469b 100644
--- a/testinfra/test_refstack.py
+++ b/testinfra/test_refstack.py
@@ -17,7 +17,7 @@ import time
 import urllib3
 
 
-testinfra_hosts = ['refstack01.openstack.org:8000']
+testinfra_hosts = ['refstack01.openstack.org']
 
 test_result_json = {
     "cpid": "9cddf99456964d7c90b98362e7175a12",
@@ -49,10 +49,10 @@ def test_refstack_container_running(host):
     assert out[0]["State"]["Status"] == "running"
     assert out[0]["RestartCount"] == 0
 
-def test_result_submission(host):
-    url = testinfra_hosts[0] + "/v1/results/"
+def test_refstack_result_submission(host):
+    url = "https://refstack01.openstack.org/v1/results/"
     headers = {'Content-type': 'application/json'}
     data = json.dumps(test_result_json)
-    http = urllib3.PoolManager()
+    http = urllib3.PoolManager(cert_reqs='CERT_NONE')
     resp = http.request('POST', url, body=data, headers=headers)
     assert resp.status == 201
diff --git a/zuul.d/system-config-run.yaml b/zuul.d/system-config-run.yaml
index 7b9eb5cc51..ef0837bc2f 100644
--- a/zuul.d/system-config-run.yaml
+++ b/zuul.d/system-config-run.yaml
@@ -909,6 +909,7 @@
     host-vars:
       refstack01.openstack.org:
         host_copy_output:
+          '/var/log/apache2/': logs
           '/var/lib/refstack/': logs
           '/var/refstack/': logs
     vars: