From d34881b45a7814f6324427e046f28446e03f32dd Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Mon, 3 Feb 2020 16:00:52 -0800 Subject: [PATCH] Google logs: Link to index.html files When generating index.html files for uploading to Google Cloud Storage, link directories to their index.html files because (except in certain circumstances) Google does not automatically serve index.html files at directory URLs. Change-Id: Ie854de328057ed080c80df9328163da98014ea36 --- .../test_zuul_google_storage_upload.py | 35 ++++++++++++------- .../library/zuul_google_storage_upload.py | 4 ++- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/roles/upload-logs-gcs/library/test_zuul_google_storage_upload.py b/roles/upload-logs-gcs/library/test_zuul_google_storage_upload.py index 582893f62..01fd71c7f 100644 --- a/roles/upload-logs-gcs/library/test_zuul_google_storage_upload.py +++ b/roles/upload-logs-gcs/library/test_zuul_google_storage_upload.py @@ -194,7 +194,7 @@ class TestFileList(testtools.TestCase): self.assertEqual(len(rows), 1) - self.assertEqual(rows[0].find('a').get('href'), 'logs/') + self.assertEqual(rows[0].find('a').get('href'), 'logs/index.html') self.assertEqual(rows[0].find('a').text, 'logs/') subdir_index = self.find_file( @@ -202,7 +202,7 @@ class TestFileList(testtools.TestCase): page = open(subdir_index.full_path).read() page = BeautifulSoup(page, 'html.parser') rows = page.find_all('tr')[1:] - self.assertEqual(rows[0].find('a').get('href'), '../') + self.assertEqual(rows[0].find('a').get('href'), '../index.html') self.assertEqual(rows[0].find('a').text, '../') # Test proper escaping of files with funny names @@ -247,17 +247,19 @@ class TestFileList(testtools.TestCase): self.assertEqual(len(rows), 3) - self.assertEqual(rows[0].find('a').get('href'), 'controller/') + self.assertEqual(rows[0].find('a').get('href'), + 'controller/index.html') self.assertEqual(rows[0].find('a').text, 'controller/') - self.assertEqual(rows[1].find('a').get('href'), 'zuul-info/') + self.assertEqual(rows[1].find('a').get('href'), + 'zuul-info/index.html') self.assertEqual(rows[1].find('a').text, 'zuul-info/') subdir_index = self.find_file(fl, 'controller/subdir/index.html') page = open(subdir_index.full_path).read() page = BeautifulSoup(page, 'html.parser') rows = page.find_all('tr')[1:] - self.assertEqual(rows[0].find('a').get('href'), '../') + self.assertEqual(rows[0].find('a').get('href'), '../index.html') self.assertEqual(rows[0].find('a').text, '../') # Test proper escaping of files with funny names @@ -304,20 +306,23 @@ class TestFileList(testtools.TestCase): self.assertEqual(len(rows), 4) - self.assertEqual(rows[0].find('a').get('href'), '../') + self.assertEqual(rows[0].find('a').get('href'), + '../index.html') self.assertEqual(rows[0].find('a').text, '../') - self.assertEqual(rows[1].find('a').get('href'), 'controller/') + self.assertEqual(rows[1].find('a').get('href'), + 'controller/index.html') self.assertEqual(rows[1].find('a').text, 'controller/') - self.assertEqual(rows[2].find('a').get('href'), 'zuul-info/') + self.assertEqual(rows[2].find('a').get('href'), + 'zuul-info/index.html') self.assertEqual(rows[2].find('a').text, 'zuul-info/') subdir_index = self.find_file(fl, 'controller/subdir/index.html') page = open(subdir_index.full_path).read() page = BeautifulSoup(page, 'html.parser') rows = page.find_all('tr')[1:] - self.assertEqual(rows[0].find('a').get('href'), '../') + self.assertEqual(rows[0].find('a').get('href'), '../index.html') self.assertEqual(rows[0].find('a').text, '../') # Test proper escaping of files with funny names @@ -364,11 +369,15 @@ class TestFileList(testtools.TestCase): self.assertEqual(len(rows), 3) - self.assertEqual(rows[0].find('a').get('href'), 'controller/') - self.assertEqual(rows[0].find('a').text, 'controller/') + self.assertEqual(rows[0].find('a').get('href'), + 'controller/index.html') + self.assertEqual(rows[0].find('a').text, + 'controller/') - self.assertEqual(rows[1].find('a').get('href'), 'zuul-info/') - self.assertEqual(rows[1].find('a').text, 'zuul-info/') + self.assertEqual(rows[1].find('a').get('href'), + 'zuul-info/index.html') + self.assertEqual(rows[1].find('a').text, + 'zuul-info/') subdir_index = self.find_file(fl, 'controller/subdir/index.html') page = open(subdir_index.full_path).read() diff --git a/roles/upload-logs-gcs/library/zuul_google_storage_upload.py b/roles/upload-logs-gcs/library/zuul_google_storage_upload.py index e5a21434c..774a786df 100755 --- a/roles/upload-logs-gcs/library/zuul_google_storage_upload.py +++ b/roles/upload-logs-gcs/library/zuul_google_storage_upload.py @@ -465,10 +465,12 @@ class Indexer(): file_details.filename), })) filename = file_details.filename + link_filename = filename if file_details.folder: filename += '/' + link_filename += '/index.html' output += '%s' % ( - urlparse.quote(filename), + urlparse.quote(link_filename), filename) output += '%s' % time.asctime( file_details.last_modified)