From 32681cf95f6797f6e1fe2b3d3dc3f416c4e1a84a Mon Sep 17 00:00:00 2001 From: "Mahadik, Mukul Chandrakant" Date: Thu, 22 Aug 2024 08:45:39 -0700 Subject: [PATCH] Corrected 1st log message for local emission environment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The tests failed since despite using ENV vars, it wasn’t picking up value. This was because ENV vars are being deleted in setUp(). Added CONDA_DEFAULT_ENV to the skipped env vars. However, this approach of fetching ENV vars programmatically in the assert statement isn’t correct. This is because the code in get_config() itself uses ENV vars to set the ret_val which is the exact value as being fetched in setUp(). Thus the values will always match. ——— Then I thought of adding another log message for the `emission` environment name. While testing this I found that the 1st message isn’t being used in the normal situations when testing locally. This message is observed when the conf/storage/db.conf file is used instead of the sample file. But in normal operation, the server repo doesn’t have any conf files to begin with. Additionally, we now set the DB_HOST as db and WEB_SERVER_HOST as 0.0.0.0 in the Dockerfile by default. Hence the assert log message should also contain `Config file not found…` message like the other two messages. It should also have DB_HOST set to Db like the 3rd message. --- .../tests/storageTests/TestTokenQueries.py | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/emission/tests/storageTests/TestTokenQueries.py b/emission/tests/storageTests/TestTokenQueries.py index e7913b966..d9bfeb44a 100644 --- a/emission/tests/storageTests/TestTokenQueries.py +++ b/emission/tests/storageTests/TestTokenQueries.py @@ -168,30 +168,24 @@ def test_run_script_show(self): esdt.insert({'token':'y'}) esdt.insert({'token':'z'}) sp = subprocess.run(["python3", "bin/auth/insert_tokens.py", "--show"], capture_output=True) - current_conda_env = os.environ.get('CONDA_DEFAULT_ENV', 'emission') - logging.debug("CONDA_DEFAULT_ENV: %s" % current_conda_env) - print("CONDA_DEFAULT_ENV: %s" % current_conda_env) - # The first message is displayed when we run tests locally + # The first message is displayed when we run tests locally with the emission environment; we are now setting DB_HOST to `db` by default # The second is displayed when we run in the CI/CD, but with the local install # The third is displayed when we run in the docker CI since the `DB_HOST` is set to `db` self.assertIn(sp.stdout, - [b'Retrieved config {\'DB_HOST\': \'localhost\', \'DB_RESULT_LIMIT\': 250000}\nURL not formatted, defaulting to "Stage_database"\nConnecting to database URL localhost\nx\ny\nz\n', - 'Config file not found, returning a copy of the environment variables instead...\nRetrieved config {{\'PYTHONPATH\': \'.\', \'PATH\': \'/home/runner/miniconda-23.5.2/envs/{0}/bin:/home/runner/miniconda-23.5.2/condabin:/snap/bin:/home/runner/.local/bin:/opt/pipx_bin:/home/runner/.cargo/bin:/home/runner/.config/composer/vendor/bin:/usr/local/.ghcup/bin:/home/runner/.dotnet/tools:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/runner/.dotnet/tools\', \'LC_CTYPE\': \'C.UTF-8\'}}\nURL not formatted, defaulting to "Stage_database"\nConnecting to database URL localhost\nx\ny\nz\n'.format(current_conda_env).encode(), - 'Config file not found, returning a copy of the environment variables instead...\nRetrieved config {{\'PYTHONPATH\': \'.\', \'DB_HOST\': \'db\', \'PATH\': \'/root/miniconda-23.5.2/envs/{0}/bin:/root/miniconda-23.5.2/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\', \'LC_CTYPE\': \'C.UTF-8\'}}\nURL not formatted, defaulting to "Stage_database"\nConnecting to database URL db\nx\ny\nz\n'.format(current_conda_env).encode() + [b'Config file not found, returning a copy of the environment variables instead...\nRetrieved config {\'PYTHONPATH\': \'.\', \'DB_HOST\': \'db\', \'PATH\': \'/root/miniconda-23.5.2/envs/emission/bin:/root/miniconda-23.5.2/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\', \'LC_CTYPE\': \'C.UTF-8\'}\nURL not formatted, defaulting to "Stage_database"\nConnecting to database URL db\nx\ny\nz\n', + b'Config file not found, returning a copy of the environment variables instead...\nRetrieved config {\'PYTHONPATH\': \'.\', \'PATH\': \'/home/runner/miniconda-23.5.2/envs/emissiontest/bin:/home/runner/miniconda-23.5.2/condabin:/snap/bin:/home/runner/.local/bin:/opt/pipx_bin:/home/runner/.cargo/bin:/home/runner/.config/composer/vendor/bin:/usr/local/.ghcup/bin:/home/runner/.dotnet/tools:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/runner/.dotnet/tools\', \'LC_CTYPE\': \'C.UTF-8\'}\nURL not formatted, defaulting to "Stage_database"\nConnecting to database URL localhost\nx\ny\nz\n', + b'Config file not found, returning a copy of the environment variables instead...\nRetrieved config {\'PYTHONPATH\': \'.\', \'DB_HOST\': \'db\', \'PATH\': \'/root/miniconda-23.5.2/envs/emissiontest/bin:/root/miniconda-23.5.2/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\', \'LC_CTYPE\': \'C.UTF-8\'}\nURL not formatted, defaulting to "Stage_database"\nConnecting to database URL db\nx\ny\nz\n' ]) def test_run_script_empty(self): sp = subprocess.run(["python3", "bin/auth/insert_tokens.py"], capture_output=True) - current_conda_env = os.environ.get('CONDA_DEFAULT_ENV', 'emission') - logging.debug("CONDA_DEFAULT_ENV: %s" % current_conda_env) - print("CONDA_DEFAULT_ENV: %s" % current_conda_env) - # The first message is displayed when we run tests locally + # The first message is displayed when we run tests locally with the emission environment; we are now setting DB_HOST to `db` by default # The second is displayed when we run in the CI/CD, but with the local install # The third is displayed when we run in the docker CI since the `DB_HOST` is set to `db` self.assertIn(sp.stdout, - [b'Retrieved config {\'DB_HOST\': \'localhost\', \'DB_RESULT_LIMIT\': 250000}\nURL not formatted, defaulting to "Stage_database"\nConnecting to database URL localhost\nPlease provide the script with an argument. Use the "--help" option for more details\n', - 'Config file not found, returning a copy of the environment variables instead...\nRetrieved config {{\'PYTHONPATH\': \'.\', \'PATH\': \'/home/runner/miniconda-23.5.2/envs/{0}/bin:/home/runner/miniconda-23.5.2/condabin:/snap/bin:/home/runner/.local/bin:/opt/pipx_bin:/home/runner/.cargo/bin:/home/runner/.config/composer/vendor/bin:/usr/local/.ghcup/bin:/home/runner/.dotnet/tools:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/runner/.dotnet/tools\', \'LC_CTYPE\': \'C.UTF-8\'}}\nURL not formatted, defaulting to "Stage_database"\nConnecting to database URL localhost\nPlease provide the script with an argument. Use the "--help" option for more details\n'.format(current_conda_env).encode(), - 'Config file not found, returning a copy of the environment variables instead...\nRetrieved config {{\'PYTHONPATH\': \'.\', \'DB_HOST\': \'db\', \'PATH\': \'/root/miniconda-23.5.2/envs/{0}/bin:/root/miniconda-23.5.2/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\', \'LC_CTYPE\': \'C.UTF-8\'}}\nURL not formatted, defaulting to "Stage_database"\nConnecting to database URL db\nPlease provide the script with an argument. Use the "--help" option for more details\n'.format(current_conda_env).encode() + [b'Config file not found, returning a copy of the environment variables instead...\nRetrieved config {\'PYTHONPATH\': \'.\', \'DB_HOST\': \'db\', \'PATH\': \'/root/miniconda-23.5.2/envs/emission/bin:/root/miniconda-23.5.2/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\', \'LC_CTYPE\': \'C.UTF-8\'}\nURL not formatted, defaulting to "Stage_database"\nConnecting to database URL db\nPlease provide the script with an argument. Use the "--help" option for more details\n', + b'Config file not found, returning a copy of the environment variables instead...\nRetrieved config {\'PYTHONPATH\': \'.\', \'PATH\': \'/home/runner/miniconda-23.5.2/envs/emissiontest/bin:/home/runner/miniconda-23.5.2/condabin:/snap/bin:/home/runner/.local/bin:/opt/pipx_bin:/home/runner/.cargo/bin:/home/runner/.config/composer/vendor/bin:/usr/local/.ghcup/bin:/home/runner/.dotnet/tools:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/runner/.dotnet/tools\', \'LC_CTYPE\': \'C.UTF-8\'}\nURL not formatted, defaulting to "Stage_database"\nConnecting to database URL localhost\nPlease provide the script with an argument. Use the "--help" option for more details\n', + b'Config file not found, returning a copy of the environment variables instead...\nRetrieved config {\'PYTHONPATH\': \'.\', \'DB_HOST\': \'db\', \'PATH\': \'/root/miniconda-23.5.2/envs/emissiontest/bin:/root/miniconda-23.5.2/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\', \'LC_CTYPE\': \'C.UTF-8\'}\nURL not formatted, defaulting to "Stage_database"\nConnecting to database URL db\nPlease provide the script with an argument. Use the "--help" option for more details\n' ]) #test that no two options can be used together