mirror of
https://github.com/camptocamp/odoo-cloud-platform.git
synced 2026-06-24 08:47:40 +00:00
Propagage region_name to swift connection
Otherwise, the bucket will be in the incorrect region
This commit is contained in:
@@ -36,6 +36,10 @@ class IrAttachment(models.Model):
|
|||||||
account = os.environ.get('SWIFT_ACCOUNT')
|
account = os.environ.get('SWIFT_ACCOUNT')
|
||||||
password = os.environ.get('SWIFT_PASSWORD')
|
password = os.environ.get('SWIFT_PASSWORD')
|
||||||
tenant_name = os.environ.get('SWIFT_TENANT_NAME')
|
tenant_name = os.environ.get('SWIFT_TENANT_NAME')
|
||||||
|
region = os.environ.get('SWIFT_REGION_NAME')
|
||||||
|
os_options = {}
|
||||||
|
if region:
|
||||||
|
os_options['region_name'] = region
|
||||||
if not (host and account and password and tenant_name):
|
if not (host and account and password and tenant_name):
|
||||||
raise exceptions.UserError(_(
|
raise exceptions.UserError(_(
|
||||||
"Problem connecting to Swift store, are the env variables "
|
"Problem connecting to Swift store, are the env variables "
|
||||||
@@ -47,7 +51,9 @@ class IrAttachment(models.Model):
|
|||||||
user=account,
|
user=account,
|
||||||
key=password,
|
key=password,
|
||||||
tenant_name=tenant_name,
|
tenant_name=tenant_name,
|
||||||
auth_version='2.0')
|
auth_version='2.0',
|
||||||
|
os_options=os_options,
|
||||||
|
)
|
||||||
except ClientException:
|
except ClientException:
|
||||||
_logger.exception('Error connecting to Swift object store')
|
_logger.exception('Error connecting to Swift object store')
|
||||||
raise exceptions.UserError(_('Error on Swift connection'))
|
raise exceptions.UserError(_('Error on Swift connection'))
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ class TestAttachmentSwift(TestIrAttachment):
|
|||||||
os.environ['SWIFT_ACCOUNT'] = 'account'
|
os.environ['SWIFT_ACCOUNT'] = 'account'
|
||||||
os.environ['SWIFT_PASSWORD'] = 'password'
|
os.environ['SWIFT_PASSWORD'] = 'password'
|
||||||
os.environ['SWIFT_TENANT_NAME'] = 'tenant_name'
|
os.environ['SWIFT_TENANT_NAME'] = 'tenant_name'
|
||||||
|
os.environ['SWIFT_REGION_NAME'] = 'NOWHERE'
|
||||||
attachment = self.Attachment
|
attachment = self.Attachment
|
||||||
attachment._get_swift_connection()
|
attachment._get_swift_connection()
|
||||||
mock_swift_client.Connection.assert_called_once_with(
|
mock_swift_client.Connection.assert_called_once_with(
|
||||||
@@ -31,7 +32,8 @@ class TestAttachmentSwift(TestIrAttachment):
|
|||||||
user=os.environ.get('SWIFT_ACCOUNT'),
|
user=os.environ.get('SWIFT_ACCOUNT'),
|
||||||
key=os.environ.get('SWIFT_PASSWORD'),
|
key=os.environ.get('SWIFT_PASSWORD'),
|
||||||
tenant_name=os.environ.get('SWIFT_TENANT_NAME'),
|
tenant_name=os.environ.get('SWIFT_TENANT_NAME'),
|
||||||
auth_version='2.0'
|
auth_version='2.0',
|
||||||
|
os_options={'region_name': os.environ.get('SWIFT_REGION_NAME')},
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_store_file_on_swift(self):
|
def test_store_file_on_swift(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user