Fix swift backup driver crashing during service startup

This patch fixes a crash in the swift backup driver during service
startup, when the backup_swift_url is None. When backup_swift_url is
None, the initialization code tries to fetch swift's endpoint from the
service catalog. However, this fails during service startup because the
context is missing the information required to access the catalog.

Closes-Bug: #1826434
Change-Id: I7e7dbdae72a08e663a96b6c01340ec2a5cbe883e
This commit is contained in:
Alan Bishop 2019-04-25 14:40:48 -04:00
parent ae5f41e776
commit 3799738872
2 changed files with 15 additions and 3 deletions

View File

@ -155,7 +155,11 @@ class SwiftBackupDriver(chunkeddriver.ChunkedBackupDriver):
backup_default_container,
enable_progress_timer,
db)
if context:
# Do not intialize the instance created when the backup service
# starts up. The context will be missing information to do things
# like fetching endpoints from the service catalog.
if context and context.user_id:
self.initialize()
@staticmethod

View File

@ -107,8 +107,9 @@ class BackupSwiftTestCase(test.TestCase):
{u'type': u'identity', u'name': u'keystone',
u'endpoints': [{
u'publicURL': u'http://example.com'}]}]
self.ctxt = context.get_admin_context()
self.ctxt.service_catalog = service_catalog
self.ctxt = context.RequestContext(user_id=fake.USER_ID,
is_admin=True,
service_catalog=service_catalog)
self.mock_object(swift, 'Connection',
fake_swift_client.FakeSwiftClient.Connection)
@ -879,6 +880,13 @@ class BackupSwiftTestCase(test.TestCase):
self.assertEqual('none', result[0])
self.assertEqual(already_compressed_data, result[1])
@mock.patch('cinder.backup.drivers.swift.SwiftBackupDriver.initialize')
def test_no_user_context(self, mock_initialize):
# With no user_id the driver should not initialize itself.
admin_context = context.get_admin_context()
swift_dr.SwiftBackupDriver(admin_context)
mock_initialize.assert_not_called()
class WindowsBackupSwiftTestCase(BackupSwiftTestCase):
# We're running all the parent class tests, while doing