Object storage inactivation: changes INACTIVE concept for DISABLE

This commit is contained in:
Stephane Mangin
2022-05-18 16:24:50 +03:00
committed by Maksym Yankin
co-authored by Maksym Yankin
parent de19785632
commit 361891fedb
3 changed files with 16 additions and 16 deletions
+2 -2
View File
@@ -163,7 +163,7 @@ environment. It will refuse to start if anything is badly configured.
The checks can be bypassed with the environment variable The checks can be bypassed with the environment variable
`ODOO_CLOUD_PLATFORM_UNSAFE` set to `1`. `ODOO_CLOUD_PLATFORM_UNSAFE` set to `1`.
### Attachment storage inactivation ### Attachment storage disability
To prevent object storage to be accessed while failing for any kind of reason To prevent object storage to be accessed while failing for any kind of reason
set this environment variable `ATTACHMENT_STORAGE_INACTIVE` set to `1`. set this environment variable `DISABLE_ATTACHMENT_STORAGE` set to `1`.
+3 -3
View File
@@ -39,8 +39,8 @@ Default configuration means:
* application/javascript are stored in database whatever their size * application/javascript are stored in database whatever their size
* text/css are stored in database whatever their size * text/css are stored in database whatever their size
Inactivate attachment storage I/O Disable attachment storage I/O
--------------------------------- ------------------------------
Define a environment variable `ATTACHMENT_STORAGE_INACTIVE` set to `1` Define a environment variable `DISABLE_ATTACHMENT_STORAGE` set to `1`
This will prevent any kind of exceptions and read/write on storage attachments. This will prevent any kind of exceptions and read/write on storage attachments.
@@ -46,16 +46,16 @@ class IrAttachment(models.Model):
_inherit = 'ir.attachment' _inherit = 'ir.attachment'
@staticmethod @staticmethod
def is_storage_inactive(storage=None, log=True): def is_storage_disabled(storage=None, log=True):
msg = _("Storages are inactive (see environment configuration).") msg = _("Storages are disabled (see environment configuration).")
if storage: if storage:
msg = _( msg = _(
"Storage '%s' is inactive (see environment configuration)." "Storage '%s' is disabled (see environment configuration)."
) % (storage,) ) % (storage,)
is_inactive = is_true(os.environ.get("ATTACHMENT_STORAGE_INACTIVE")) is_disabled = is_true(os.environ.get("DISABLE_ATTACHMENT_STORAGE"))
if is_inactive and log: if is_disabled and log:
_logger.warning(msg) _logger.warning(msg)
return is_inactive return is_disabled
def _register_hook(self): def _register_hook(self):
super()._register_hook() super()._register_hook()
@@ -168,7 +168,7 @@ class IrAttachment(models.Model):
``_store_in_db_instead_of_object_storage_domain``. ``_store_in_db_instead_of_object_storage_domain``.
""" """
if self.is_storage_inactive(): if self.is_storage_disabled():
return True return True
storage_config = self._get_storage_force_db_config() storage_config = self._get_storage_force_db_config()
for mimetype_key, limit in storage_config.items(): for mimetype_key, limit in storage_config.items():
@@ -249,7 +249,7 @@ class IrAttachment(models.Model):
@api.model @api.model
def _is_file_from_a_store(self, fname): def _is_file_from_a_store(self, fname):
for store_name in self._get_stores(): for store_name in self._get_stores():
if self.is_storage_inactive(store_name): if self.is_storage_disabled(store_name):
continue continue
uri = '{}://'.format(store_name) uri = '{}://'.format(store_name)
if fname.startswith(uri): if fname.startswith(uri):
@@ -286,7 +286,7 @@ class IrAttachment(models.Model):
_logger.info('inspecting attachment %s (%d)', self.name, self.id) _logger.info('inspecting attachment %s (%d)', self.name, self.id)
fname = self.store_fname fname = self.store_fname
storage = fname.partition('://')[0] storage = fname.partition('://')[0]
if self.is_storage_inactive(storage): if self.is_storage_disabled(storage):
fname = False fname = False
if fname: if fname:
# migrating from filesystem filestore # migrating from filesystem filestore
@@ -330,7 +330,7 @@ class IrAttachment(models.Model):
It is not called anywhere, but can be called by RPC or scripts. It is not called anywhere, but can be called by RPC or scripts.
""" """
storage = self._storage() storage = self._storage()
if self.is_storage_inactive(storage): if self.is_storage_disabled(storage):
return return
if storage not in self._get_stores(): if storage not in self._get_stores():
return return
@@ -385,7 +385,7 @@ class IrAttachment(models.Model):
def _force_storage_to_object_storage(self, new_cr=False): def _force_storage_to_object_storage(self, new_cr=False):
_logger.info('migrating files to the object storage') _logger.info('migrating files to the object storage')
storage = self.env.context.get('storage_location') or self._storage() storage = self.env.context.get('storage_location') or self._storage()
if self.is_storage_inactive(storage): if self.is_storage_disabled(storage):
return return
# The weird "res_field = False OR res_field != False" domain # The weird "res_field = False OR res_field != False" domain
# is required! It's because of an override of _search in ir.attachment # is required! It's because of an override of _search in ir.attachment