Merge 9996a48cf7 into bbcd058061
This commit is contained in:
commit
dde07b37d8
|
|
@ -36,7 +36,8 @@ environments are stored in the ``server_environment_files`` companion
|
|||
module.
|
||||
|
||||
The ``server_environment_files`` module is optional, the values can be set using
|
||||
an environment variable with a fallback on default values in the database.
|
||||
an environment variable with a fallback on default values in the database. you
|
||||
will be able to overwrite some odoo options.
|
||||
|
||||
The configuration read from the files are visible under the Configuration
|
||||
menu. If you are not in the 'dev' environment you will not be able to
|
||||
|
|
@ -96,6 +97,12 @@ You can edit the settings you need in the ``server_environment_files`` addon. Th
|
|||
and can override or extend default values;
|
||||
* you can override or extend values in the main configuration
|
||||
file of your instance;
|
||||
* In some platforms (like odoo.sh where production config file is copied to staging)
|
||||
it can be usefull to overwrite options write in the `[options]` section. You must
|
||||
allow the overwrite by adding `server_environment_allow_overwrite_options_section = True``
|
||||
to the former `odoo.cfg` config file or through the environment variable:
|
||||
`export SERVER_ENVIRONMENT_ALLOW_OVERWRITE_OPTIONS_SECTION=True` (if both are set
|
||||
config file take precedent).
|
||||
|
||||
Environment variable
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
|
|
|
|||
|
|
@ -30,6 +30,12 @@ You can edit the settings you need in the ``server_environment_files`` addon. Th
|
|||
and can override or extend default values;
|
||||
* you can override or extend values in the main configuration
|
||||
file of your instance;
|
||||
* In some platforms (like odoo.sh where production config file is copied to staging)
|
||||
it can be usefull to overwrite options write in the `[options]` section. You must
|
||||
allow the overwrite by adding `server_environment_allow_overwrite_options_section = True``
|
||||
to the former `odoo.cfg` config file or through the environment variable:
|
||||
`export SERVER_ENVIRONMENT_ALLOW_OVERWRITE_OPTIONS_SECTION=True` (if both are set
|
||||
config file take precedent).
|
||||
|
||||
Environment variable
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
|
|
|
|||
|
|
@ -6,7 +6,8 @@ environments are stored in the ``server_environment_files`` companion
|
|||
module.
|
||||
|
||||
The ``server_environment_files`` module is optional, the values can be set using
|
||||
an environment variable with a fallback on default values in the database.
|
||||
an environment variable with a fallback on default values in the database. you
|
||||
will be able to overwrite some odoo options.
|
||||
|
||||
The configuration read from the files are visible under the Configuration
|
||||
menu. If you are not in the 'dev' environment you will not be able to
|
||||
|
|
|
|||
|
|
@ -107,6 +107,19 @@ def _listconf(env_path):
|
|||
return files
|
||||
|
||||
|
||||
def _update_odoo_config_options(config_p):
|
||||
allow_overwrite = system_base_config.get(
|
||||
"server_environment_allow_overwrite_options_section",
|
||||
os.environ.get("SERVER_ENVIRONMENT_ALLOW_OVERWRITE_OPTIONS_SECTION"),
|
||||
)
|
||||
if isinstance(allow_overwrite, str) and allow_overwrite:
|
||||
allow_overwrite = _boolean_states.get(allow_overwrite.lower(), False)
|
||||
if allow_overwrite and config_p.has_section("options"):
|
||||
system_base_config.options.update(
|
||||
{k: v for k, v in config_p["options"].items()}
|
||||
)
|
||||
|
||||
|
||||
def _load_config_from_server_env_files(config_p):
|
||||
default = os.path.join(_dir, "default")
|
||||
running_env = os.path.join(_dir, system_base_config["running_env"])
|
||||
|
|
@ -121,6 +134,7 @@ def _load_config_from_server_env_files(config_p):
|
|||
raise Exception(
|
||||
'Cannot read config files "{}": {}'.format(conf_files, e)
|
||||
) from e
|
||||
_update_odoo_config_options(config_p)
|
||||
|
||||
|
||||
def _load_config_from_rcfile(config_p):
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
|
|
@ -377,7 +376,8 @@ the main configuration file, and the values for the various possible
|
|||
environments are stored in the <tt class="docutils literal">server_environment_files</tt> companion
|
||||
module.</p>
|
||||
<p>The <tt class="docutils literal">server_environment_files</tt> module is optional, the values can be set using
|
||||
an environment variable with a fallback on default values in the database.</p>
|
||||
an environment variable with a fallback on default values in the database. you
|
||||
will be able to overwrite some odoo options.</p>
|
||||
<p>The configuration read from the files are visible under the Configuration
|
||||
menu. If you are not in the ‘dev’ environment you will not be able to
|
||||
see the values contained in the defined secret keys
|
||||
|
|
@ -443,6 +443,12 @@ environment.</p>
|
|||
and can override or extend default values;</li>
|
||||
<li>you can override or extend values in the main configuration
|
||||
file of your instance;</li>
|
||||
<li>In some platforms (like odoo.sh where production config file is copied to staging)
|
||||
it can be usefull to overwrite options write in the <cite>[options]</cite> section. You must
|
||||
allow the overwrite by adding <cite>server_environment_allow_overwrite_options_section = True`</cite>
|
||||
to the former <cite>odoo.cfg</cite> config file or through the environment variable:
|
||||
<cite>export SERVER_ENVIRONMENT_ALLOW_OVERWRITE_OPTIONS_SECTION=True</cite> (if both are set
|
||||
config file take precedent).</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="environment-variable">
|
||||
|
|
|
|||
|
|
@ -58,3 +58,61 @@ class TestEnv(common.ServerEnvironmentCase):
|
|||
self.assertEqual(val, "testing")
|
||||
val = parser.get("external_service.ftp", "host")
|
||||
self.assertEqual(val, "sftp.example.com")
|
||||
|
||||
@patch.dict(os.environ, {"SERVER_ENVIRONMENT_ALLOW_OVERWRITE_OPTIONS_SECTION": "0"})
|
||||
@patch.dict(
|
||||
odoo_config.options,
|
||||
{
|
||||
"running_env": "testing",
|
||||
"server_environment_allow_overwrite_options_section": True,
|
||||
"odoo_test_option": "fake odoo config",
|
||||
},
|
||||
)
|
||||
def test_server_environment_allow_overwrite_options_section(self):
|
||||
with self.set_config_dir("testfiles"):
|
||||
server_env._load_config()
|
||||
self.assertEqual(
|
||||
odoo_config["odoo_test_option"], "Set in config file for testing env"
|
||||
)
|
||||
|
||||
@patch.dict(os.environ, {"SERVER_ENVIRONMENT_ALLOW_OVERWRITE_OPTIONS_SECTION": "1"})
|
||||
@patch.dict(
|
||||
odoo_config.options,
|
||||
{
|
||||
"running_env": "testing",
|
||||
"server_environment_allow_overwrite_options_section": False,
|
||||
"odoo_test_option": "fake odoo config",
|
||||
},
|
||||
)
|
||||
def test_server_environment_disabled_overwrite_options_section(self):
|
||||
with self.set_config_dir("testfiles"):
|
||||
server_env._load_config()
|
||||
self.assertEqual(odoo_config["odoo_test_option"], "fake odoo config")
|
||||
|
||||
@patch.dict(os.environ, {"SERVER_ENVIRONMENT_ALLOW_OVERWRITE_OPTIONS_SECTION": "1"})
|
||||
@patch.dict(
|
||||
odoo_config.options,
|
||||
{
|
||||
"running_env": "testing",
|
||||
"odoo_test_option": "fake odoo config",
|
||||
},
|
||||
)
|
||||
def test_server_environment_allow_overwrite_options_section_by_env(self):
|
||||
with self.set_config_dir("testfiles"):
|
||||
server_env._load_config()
|
||||
self.assertEqual(
|
||||
odoo_config["odoo_test_option"], "Set in config file for testing env"
|
||||
)
|
||||
|
||||
@patch.dict(os.environ, {"SERVER_ENVIRONMENT_ALLOW_OVERWRITE_OPTIONS_SECTION": "0"})
|
||||
@patch.dict(
|
||||
odoo_config.options,
|
||||
{
|
||||
"running_env": "testing",
|
||||
"odoo_test_option": "fake odoo config",
|
||||
},
|
||||
)
|
||||
def test_server_environment_disabled_overwrite_options_section_by_env(self):
|
||||
with self.set_config_dir("testfiles"):
|
||||
server_env._load_config()
|
||||
self.assertEqual(odoo_config["odoo_test_option"], "fake odoo config")
|
||||
|
|
|
|||
|
|
@ -1,2 +1,5 @@
|
|||
[options]
|
||||
odoo_test_option = Set in config file for testing env
|
||||
|
||||
[external_service.ftp]
|
||||
user = testing
|
||||
|
|
|
|||
Loading…
Reference in New Issue