Merge pull request #128 from sebalix/7.0-backport-labs-support

[7.0] Add support of 'labs' RUNNING_ENV in cloud_platform
This commit is contained in:
Guewen Baconnier
2020-06-22 07:40:36 +02:00
committed by GitHub
co-authored by GitHub
2 changed files with 43 additions and 21 deletions
+42 -21
View File
@@ -63,6 +63,14 @@ class CloudPlatform(osv.osv_abstract):
configs = configs_getter() if configs_getter else {} configs = configs_getter() if configs_getter else {}
return configs.get(environment) or FilestoreKind.db return configs.get(environment) or FilestoreKind.db
def _get_running_env(self):
environment_name = config['running_env']
if environment_name.startswith('labs'):
# We allow to have environments such as 'labs-logistics'
# or 'labs-finance', in order to have the matching ribbon.
environment_name = 'labs'
return environment_name
# Due to the addition of the ovh cloud platform # Due to the addition of the ovh cloud platform
# This will be moved to cloud_platform_exoscale on v11 # This will be moved to cloud_platform_exoscale on v11
def install_exoscale(self, cr, uid, context=None): def install_exoscale(self, cr, uid, context=None):
@@ -76,8 +84,8 @@ class CloudPlatform(osv.osv_abstract):
'cloud.platform.kind', platform_kind, 'cloud.platform.kind', platform_kind,
context=context context=context
) )
environment = config['running_env'] environment_name = self._get_running_env()
configs = self._config_by_server_env(platform_kind, environment) configs = self._config_by_server_env(platform_kind, environment_name)
params.set_param( params.set_param(
cr, SUPERUSER_ID, cr, SUPERUSER_ID,
'ir_attachment.location', configs.filestore, 'ir_attachment.location', configs.filestore,
@@ -98,6 +106,9 @@ class CloudPlatform(osv.osv_abstract):
) == FilestoreKind.swift ) == FilestoreKind.swift
) )
if environment_name in ('prod', 'integration'): if environment_name in ('prod', 'integration'):
# Labs instances use swift or 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_swift, ( assert use_swift, (
"Swift must be used on production and integration instances. " "Swift must be used on production and integration instances. "
"It is activated, setting 'ir_attachment.location.' to 'swift'" "It is activated, setting 'ir_attachment.location.' to 'swift'"
@@ -117,13 +128,18 @@ class CloudPlatform(osv.osv_abstract):
"SWIFT_PASSWORD environment variable is required when " "SWIFT_PASSWORD environment variable is required when "
"ir_attachment.location is 'swift'." "ir_attachment.location is 'swift'."
) )
container_name = os.environ['SWIFT_WRITE_CONTAINER'] container_name = os.environ.get('SWIFT_WRITE_CONTAINER')
if environment_name in ('integration', 'prod'): assert container_name, (
assert container_name, ( "SWIFT_WRITE_CONTAINER environment variable is required when "
"SWIFT_WRITE_CONTAINER must not be empty for prod " "ir_attachment.location is 'swift'.\n"
"and integration" "Normally, 'swift' is activated on labs, integration "
) "and production, but should not be used in dev environment"
prod_container = bool(re.match(r'[a-z0-9_-]+-odoo-prod', " (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."
)
prod_container = bool(re.match(r'[a-z0-9-]+-odoo-prod',
container_name)) container_name))
if environment_name == 'prod': if environment_name == 'prod':
assert prod_container, ( assert prod_container, (
@@ -152,6 +168,9 @@ class CloudPlatform(osv.osv_abstract):
cr, SUPERUSER_ID, 'ir_attachment.location', context=context cr, SUPERUSER_ID, 'ir_attachment.location', context=context
) == FilestoreKind.s3 ) == FilestoreKind.s3
if environment_name in ('prod', 'integration'): if environment_name in ('prod', 'integration'):
# Labs instances use swift or 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, ( assert use_s3, (
"S3 must be used on production and integration instances. " "S3 must be used on production and integration instances. "
"It is activated by setting 'ir_attachment.location.' to 's3'." "It is activated by setting 'ir_attachment.location.' to 's3'."
@@ -167,16 +186,18 @@ class CloudPlatform(osv.osv_abstract):
"AWS_SECRET_ACCESS_KEY environment variable is required when " "AWS_SECRET_ACCESS_KEY environment variable is required when "
"ir_attachment.location is 's3'." "ir_attachment.location is 's3'."
) )
assert os.environ.get('AWS_BUCKETNAME'), ( bucket_name = os.environ.get('AWS_BUCKETNAME')
assert bucket_name, (
"AWS_BUCKETNAME environment variable is required when " "AWS_BUCKETNAME environment variable is required when "
"ir_attachment.location is 's3'.\n" "ir_attachment.location is 's3'.\n"
"Normally, 's3' is activated on integration and production, " "Normally, 's3' is activated on labs, integration "
"but should not be used in dev environment (or at least " "and production, but should not be used in dev environment"
"not with a dev bucket, but never the " " (or using a dedicated dev bucket, never using the "
"integration/prod bucket)." "integration/prod bucket).\n"
"If you don't actually need a bucket, change the"
" 'ir_attachment.location' parameter."
) )
bucket_name = os.environ['AWS_BUCKETNAME'] prod_bucket = bool(re.match(r'[a-z-0-9]+-odoo-prod', bucket_name))
prod_bucket = bool(re.match(r'[a-z0-9_-]+-odoo-prod', bucket_name))
if environment_name == 'prod': if environment_name == 'prod':
assert prod_bucket, ( assert prod_bucket, (
"AWS_BUCKETNAME should match '<client>-odoo-prod', " "AWS_BUCKETNAME should match '<client>-odoo-prod', "
@@ -200,10 +221,10 @@ class CloudPlatform(osv.osv_abstract):
) )
def _check_redis(self, cr, uid, environment_name, context=None): def _check_redis(self, cr, uid, environment_name, context=None):
if environment_name in ('prod', 'integration', 'test'): if environment_name in ('prod', 'integration', 'labs', 'test'):
assert is_true(os.environ.get('ODOO_SESSION_REDIS')), ( assert is_true(os.environ.get('ODOO_SESSION_REDIS')), (
"Redis must be activated on prod, integration, test instances." "Redis must be activated on prod, integration, labs,"
"This is done by setting ODOO_SESSION_REDIS=1." " test instances. This is done by setting ODOO_SESSION_REDIS=1."
) )
assert (os.environ.get('ODOO_SESSION_REDIS_HOST') or assert (os.environ.get('ODOO_SESSION_REDIS_HOST') or
os.environ.get('ODOO_SESSION_REDIS_SENTINEL_HOST')), ( os.environ.get('ODOO_SESSION_REDIS_SENTINEL_HOST')), (
@@ -216,7 +237,7 @@ class CloudPlatform(osv.osv_abstract):
) )
prefix = os.environ['ODOO_SESSION_REDIS_PREFIX'] prefix = os.environ['ODOO_SESSION_REDIS_PREFIX']
assert re.match(r'[a-z0-9_-]+-odoo-[a-z]+', prefix), ( assert re.match(r'^[a-z-0-9]+-odoo-[a-z-0-9]+$', prefix), (
"ODOO_SESSION_REDIS_PREFIX must match '<client>-odoo-<env>'" "ODOO_SESSION_REDIS_PREFIX must match '<client>-odoo-<env>'"
", we got: '%s'" % (prefix,) ", we got: '%s'" % (prefix,)
) )
@@ -236,7 +257,7 @@ class CloudPlatform(osv.osv_abstract):
"probably run 'env['cloud.platform'].install_exoscale()'" "probably run 'env['cloud.platform'].install_exoscale()'"
) )
return return
environment_name = config['running_env'] environment_name = self._get_running_env()
if kind == 'exoscale': if kind == 'exoscale':
self._check_s3(cr, uid, environment_name, context) self._check_s3(cr, uid, environment_name, context)
elif kind == 'ovh': elif kind == 'ovh':
@@ -31,6 +31,7 @@ class CloudPlatform(osv.osv_abstract):
configs = { configs = {
'prod': PlatformConfig(filestore=FilestoreKind.swift), 'prod': PlatformConfig(filestore=FilestoreKind.swift),
'integration': PlatformConfig(filestore=FilestoreKind.swift), 'integration': PlatformConfig(filestore=FilestoreKind.swift),
'labs': PlatformConfig(filestore=FilestoreKind.swift),
'test': PlatformConfig(filestore=FilestoreKind.db), 'test': PlatformConfig(filestore=FilestoreKind.db),
'dev': PlatformConfig(filestore=FilestoreKind.db), 'dev': PlatformConfig(filestore=FilestoreKind.db),
} }