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 <oliver.leahy@hp.com>
This commit is contained in:
Nate Potter
2016-07-12 17:51:39 +00:00
parent d7cbb19929
commit 4080179c8b
2 changed files with 27 additions and 2 deletions
+13 -2
View File
@@ -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')
@@ -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')