[13.0][IMP] Make cloud_platform fully abstract + update related modules (#244)

This commit is contained in:
Patrick Tombez
2021-11-11 19:17:48 +01:00
committed by Yannick Vaucher
co-authored by Yannick Vaucher
parent 52570f9cb4
commit 3e58a3888d
9 changed files with 262 additions and 192 deletions
+19 -14
View File
@@ -3,17 +3,22 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
{'name': 'Cloud Platform Exoscale',
'summary': 'Addons required for the Camptocamp Cloud Platform on Exoscale',
'version': '11.0.1.0.0',
'author': 'Camptocamp,Odoo Community Association (OCA)',
'license': 'AGPL-3',
'category': 'Extra Tools',
'depends': [
'cloud_platform',
'attachment_s3',
],
'website': 'https://www.camptocamp.com',
'data': [],
'installable': True,
}
{
"name": "Cloud Platform Exoscale",
"summary": "Addons required for the Camptocamp Cloud Platform on Exoscale",
"version": "11.0.1.0.0",
"author": "Camptocamp,Odoo Community Association (OCA)",
"license": "AGPL-3",
"category": "Extra Tools",
"depends": [
"cloud_platform",
"attachment_s3",
"monitoring_statsd",
],
"excludes": [
"cloud_platform_ovh",
],
"website": "https://www.camptocamp.com",
"data": [],
"installable": True,
}
@@ -2,12 +2,109 @@
# Copyright 2016 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
import logging
import re
import os
from odoo import models
from odoo import models, api
from odoo.addons.cloud_platform.models.cloud_platform import FilestoreKind
from odoo.addons.cloud_platform.models.cloud_platform import PlatformConfig
_logger = logging.getLogger(__name__)
S3_STORE_KIND = FilestoreKind('s3', 'remote')
class CloudPlatform(models.AbstractModel):
_inherit = 'cloud.platform'
@api.model
def _filestore_kinds(self):
kinds = super(CloudPlatform, self)._filestore_kinds()
kinds['s3'] = S3_STORE_KIND
return kinds
@api.model
def _platform_kinds(self):
kinds = super(CloudPlatform, self)._platform_kinds()
kinds.append('exoscale')
return kinds
@api.model
def _config_by_server_env_for_exoscale(self):
fs_kinds = self._filestore_kinds()
configs = {
'prod': PlatformConfig(filestore=fs_kinds['s3']),
'integration': PlatformConfig(filestore=fs_kinds['s3']),
'labs': PlatformConfig(filestore=fs_kinds['s3']),
'test': PlatformConfig(filestore=fs_kinds['db']),
'dev': PlatformConfig(filestore=fs_kinds['db']),
}
return configs
@api.model
def _check_filestore(self, environment_name):
params = self.env['ir.config_parameter'].sudo()
use_s3 = (params.get_param('ir_attachment.location') ==
S3_STORE_KIND.name)
if environment_name in ('prod', 'integration'):
# Labs instances use s3 by default, but we don't want
# to enforce it in case we want to test something with a different
# storage. At your own risks!
assert use_s3, (
"S3 must be used on production and integration instances. "
"It is activated by setting 'ir_attachment.location.' to 's3'."
" The 'install()' function sets this option "
"automatically."
)
if use_s3:
assert os.environ.get('AWS_ACCESS_KEY_ID'), (
"AWS_ACCESS_KEY_ID environment variable is required when "
"ir_attachment.location is 's3'."
)
assert os.environ.get('AWS_SECRET_ACCESS_KEY'), (
"AWS_SECRET_ACCESS_KEY environment variable is required when "
"ir_attachment.location is 's3'."
)
bucket_name = os.environ.get('AWS_BUCKETNAME', '')
if environment_name in ('prod', 'integration', 'labs'):
assert bucket_name, (
"AWS_BUCKETNAME environment variable is required when "
"ir_attachment.location is 's3'.\n"
"Normally, 's3' is activated on labs, integration "
"and production, but should not be used in dev environment"
" (or using a dedicated dev bucket, never using the "
"integration/prod bucket).\n"
"If you don't actually need a bucket, change the"
" 'ir_attachment.location' parameter."
)
# A bucket name is defined under the following format
# <client>-odoo-<env>
#
# Use AWS_BUCKETNAME_UNSTRUCTURED to by-pass check on bucket name
# structure
if os.environ.get('AWS_BUCKETNAME_UNSTRUCTURED'):
return
prod_bucket = bool(re.match(r'[a-z-0-9]+-odoo-prod', bucket_name))
if environment_name == 'prod':
assert prod_bucket, (
"AWS_BUCKETNAME should match '<client>-odoo-prod', "
"we got: '%s'" % (bucket_name,)
)
else:
# if we are using the prod bucket on another instance
# such as an integration, we must be sure to be in read only!
assert not prod_bucket, (
"AWS_BUCKETNAME should not match '<client>-odoo-prod', "
"we got: '%s'" % (bucket_name,)
)
elif environment_name == 'test':
# store in DB so we don't have files local to the host
assert params.get_param('ir_attachment.location') == 'db', (
"In test instances, files must be stored in the database with "
"'ir_attachment.location' set to 'db'. This is "
"automatically set by the function 'install()'."
)
@api.model
def install(self):
self._install('exoscale')