Add Auth Version 3 support in Swift Backup Driver

Currently it is not possible in the Swift Backup Driver
used in single_user mode to connect to Swift in Auth
Version 3. The needed information user_domain,
project_domain and project are not available. This patch
adds the config parameters backup_swift_user_domain,
backup_swift_project_domain and backup_swift_project and
forwards it to the swift client in the os_options parameter.

Adds also the unit test test_backup_swift_auth_v3_single_user
for testing the new configuration parameters.

DocImpact: The config options "backup_swift_user_domain",
"backup_swift_project_domain" and "backup_swift_project"
will need to be added to the Cinder docs. The config option
"backup_swift_auth_version" should reference also version 3.

Closes-Bug: #1518213
Change-Id: Ia57c8b0522f566690a18c8d895ef7db21a558028
This commit is contained in:
Falk Reimann 2015-11-20 09:36:02 +01:00
parent 562a1746bd
commit c2ac7d6604
3 changed files with 70 additions and 1 deletions

View File

@ -82,10 +82,22 @@ swiftbackup_service_opts = [
cfg.StrOpt('backup_swift_auth_version',
default='1',
help='Swift authentication version. Specify "1" for auth 1.0'
', or "2" for auth 2.0'),
', or "2" for auth 2.0 or "3" for auth 3.0'),
cfg.StrOpt('backup_swift_tenant',
help='Swift tenant/account name. Required when connecting'
' to an auth 2.0 system'),
cfg.StrOpt('backup_swift_user_domain',
default=None,
help='Swift user domain name. Required when connecting'
' to an auth 3.0 system'),
cfg.StrOpt('backup_swift_project_domain',
default=None,
help='Swift project domain name. Required when connecting'
' to an auth 3.0 system'),
cfg.StrOpt('backup_swift_project',
default=None,
help='Swift project/account name. Required when connecting'
' to an auth 3.0 system'),
cfg.StrOpt('backup_swift_user',
help='Swift user name'),
cfg.StrOpt('backup_swift_key',
@ -204,12 +216,22 @@ class SwiftBackupDriver(chunkeddriver.ChunkedBackupDriver):
"but %(param)s not set"),
{'param': 'backup_swift_user'})
raise exception.ParameterNotFound(param='backup_swift_user')
os_options = {}
if CONF.backup_swift_user_domain is not None:
os_options['user_domain_name'] = CONF.backup_swift_user_domain
if CONF.backup_swift_project_domain is not None:
os_options['project_domain_name'] = (
CONF.backup_swift_project_domain
)
if CONF.backup_swift_project is not None:
os_options['project_name'] = CONF.backup_swift_project
self.conn = swift.Connection(
authurl=self.auth_url,
auth_version=CONF.backup_swift_auth_version,
tenant_name=CONF.backup_swift_tenant,
user=CONF.backup_swift_user,
key=CONF.backup_swift_key,
os_options=os_options,
retries=self.swift_attempts,
starting_backoff=self.swift_backoff,
insecure=self.backup_swift_auth_insecure,

View File

@ -216,6 +216,7 @@ class BackupSwiftTestCase(test.TestCase):
tenant_name=ANY,
user=ANY,
key=ANY,
os_options={},
retries=ANY,
starting_backoff=ANY,
cacert=ANY)
@ -227,6 +228,49 @@ class BackupSwiftTestCase(test.TestCase):
starting_backoff=ANY,
cacert=ANY)
@ddt.data(
{'auth_version': '3', 'user_domain': 'UserDomain',
'project': 'Project', 'project_domain': 'ProjectDomain'},
{'auth_version': '3', 'user_domain': None,
'project': 'Project', 'project_domain': 'ProjectDomain'},
{'auth_version': '3', 'user_domain': 'UserDomain',
'project': None, 'project_domain': 'ProjectDomain'},
{'auth_version': '3', 'user_domain': 'UserDomain',
'project': 'Project', 'project_domain': None},
{'auth_version': '3', 'user_domain': None,
'project': None, 'project_domain': None},
)
@ddt.unpack
def test_backup_swift_auth_v3_single_user(self, auth_version, user_domain,
project, project_domain):
self.override_config('backup_swift_auth', 'single_user')
self.override_config('backup_swift_user', 'swift-user')
self.override_config('backup_swift_auth_version', auth_version)
self.override_config('backup_swift_user_domain', user_domain)
self.override_config('backup_swift_project', project)
self.override_config('backup_swift_project_domain', project_domain)
os_options = {}
if user_domain is not None:
os_options['user_domain_name'] = user_domain
if project is not None:
os_options['project_name'] = project
if project_domain is not None:
os_options['project_domain_name'] = project_domain
mock_connection = self.mock_object(swift, 'Connection')
swift_dr.SwiftBackupDriver(self.ctxt)
mock_connection.assert_called_once_with(insecure=ANY,
authurl=ANY,
auth_version=auth_version,
tenant_name=ANY,
user=ANY,
key=ANY,
os_options=os_options,
retries=ANY,
starting_backoff=ANY,
cacert=ANY)
def test_backup_uncompressed(self):
volume_id = '2b9f10a3-42b4-4fdf-b316-000000ceb039'
self._create_backup_db_entry(volume_id=volume_id)

View File

@ -0,0 +1,3 @@
---
features:
- Added Keystone v3 support for Swift backup driver in single user mode.