From 4080179c8b9a60ee7215c7daaf05a2fc40140cfc Mon Sep 17 00:00:00 2001 From: Nate Potter Date: Tue, 12 Jul 2016 17:51:39 +0000 Subject: [PATCH] Add proxy config option to google backup driver Enable users to specify a proxy URL for connecting the cinder backup service to GCS. DocImpact: New config option for google backup driver. Change-Id: I46d2b5d202644269ed44abded3fab8dcc230e3da Closes-Bug: #1592730 Co-Authored-By: Ollie Leahy --- cinder/backup/drivers/google.py | 15 +++++++++++++-- .../unit/backup/drivers/test_backup_google.py | 14 ++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/cinder/backup/drivers/google.py b/cinder/backup/drivers/google.py index 534ef72e8b6..3f67e9a6b63 100644 --- a/cinder/backup/drivers/google.py +++ b/cinder/backup/drivers/google.py @@ -91,6 +91,10 @@ gcsbackup_service_opts = [ 'progress notifications to Ceilometer when backing ' 'up the volume to the GCS backend storage. The ' 'default value is True to enable the timer.'), + cfg.URIOpt('backup_gcs_proxy_url', + help='URL for http proxy access.', + secret=True), + ] CONF = cfg.CONF @@ -134,14 +138,21 @@ class GoogleBackupDriver(chunkeddriver.ChunkedBackupDriver): self.bucket_location = CONF.backup_gcs_bucket_location self.storage_class = CONF.backup_gcs_storage_class self.num_retries = CONF.backup_gcs_num_retries - http_user_agent = http.set_user_agent(httplib2.Http(), - CONF.backup_gcs_user_agent) + http_user_agent = http.set_user_agent( + httplib2.Http(proxy_info=self.get_gcs_proxy_info()), + CONF.backup_gcs_user_agent) self.conn = discovery.build('storage', 'v1', http=http_user_agent, credentials=credentials) self.resumable = self.writer_chunk_size != -1 + def get_gcs_proxy_info(self): + if CONF.backup_gcs_proxy_url: + return httplib2.proxy_info_from_url(CONF.backup_gcs_proxy_url) + else: + return httplib2.proxy_info_from_environment() + def check_gcs_options(self): required_options = ('backup_gcs_bucket', 'backup_gcs_credential_file', 'backup_gcs_project_id') diff --git a/cinder/tests/unit/backup/drivers/test_backup_google.py b/cinder/tests/unit/backup/drivers/test_backup_google.py index 954dfde4db7..c8dde288f31 100644 --- a/cinder/tests/unit/backup/drivers/test_backup_google.py +++ b/cinder/tests/unit/backup/drivers/test_backup_google.py @@ -204,6 +204,20 @@ class GoogleBackupDriverTestCase(test.TestCase): service.backup(backup, self.volume_file) self.assertEqual('gcscinderbucket', backup.container) + @gcs_client + @mock.patch('httplib2.proxy_info_from_url') + def test_backup_proxy_configured(self, mock_proxy_info): + google_dr.CONF.set_override("backup_gcs_proxy_url", + "http://myproxy.example.com") + google_dr.GoogleBackupDriver(self.ctxt) + mock_proxy_info.assert_called_with("http://myproxy.example.com") + + @gcs_client + @mock.patch('httplib2.proxy_info_from_environment') + def test_backup_proxy_environment(self, mock_proxy_env): + google_dr.GoogleBackupDriver(self.ctxt) + mock_proxy_env.assert_called_once_with() + @gcs_client @mock.patch('cinder.backup.drivers.google.GoogleBackupDriver.' '_send_progress_end')