Commit 5dacbc19 authored by Samuel GAIST's avatar Samuel GAIST

[databases] Use db environment info for container creation

Following the latest updates of beat/beat.core>, use
the environment field if available to find the correct
database image to use. Otherwise, use the original
technique based on the database list provided with
the image.
parent 9ee51763
Pipeline #41071 passed with stage
in 4 minutes and 4 seconds
......@@ -221,6 +221,19 @@ def start_db_container(
with open(json_path, "w") as f:
simplejson.dump(db_data, f, indent=4)
environment = database.environment
if environment:
environment_name = utils.build_env_name(environment)
try:
db_envkey = host.dbenv2docker(environment_name)
except KeyError:
raise RuntimeError(
"Environment {} not found for the database '{}' "
"- available environments are {}".format(
environment_name, db_name, ", ".join(host.db_environments.keys())
)
)
else:
try:
db_envkey = host.db2docker([db_name])
except Exception:
......@@ -230,6 +243,8 @@ def start_db_container(
% (db_name, ", ".join(host.db_environments.keys()))
)
logger.info("Indexing using {}".format(db_envkey))
# Creation of the container
# Note: we only support one databases image loaded at the same time
CONTAINER_PREFIX = "/beat/prefix"
......
......@@ -209,3 +209,13 @@ class TestIndex(core.AssetBaseTest):
% (expected_errors, existing_errors)
),
)
def test_index_error_invalid_env(self):
db_name = "integers_db_invalid_env/1"
with nose.tools.assert_raises(RuntimeError) as context:
self.call("index", "--docker", db_name)
print(context.exception)
nose.tools.assert_true(
"Environment Does not exist (1.4.0) not found for the database"
in context.exception.args[0]
)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment