-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#70 Added LanguageContainerDeployerCli class
- Loading branch information
Showing
5 changed files
with
201 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
exasol/python_extension_common/cli/language_container_deployer_cli.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
from pathlib import Path | ||
|
||
from exasol.python_extension_common.deployment.language_container_deployer import LanguageContainerDeployer | ||
from exasol.python_extension_common.connections.pyexasol_connection import open_pyexasol_connection | ||
from exasol.python_extension_common.connections.bucketfs_location import create_bucketfs_location | ||
from exasol.python_extension_common.cli.std_options import StdParams | ||
|
||
|
||
class LanguageContainerDeployerCli: | ||
""" | ||
The class provides a CLI callback function that creates and runs the | ||
LangaugeContainerDeployer. | ||
At first glance, it may look a bit over-designed. The reason for wrapping a | ||
callback function in a class is to let the user define the option names for the | ||
container URL and container name. These options are not defined in the StdParams | ||
but rather generated by formatters. The user can give them arbitrary names. | ||
Hence, we don't want to assume any particular names in the callback function. | ||
""" | ||
|
||
def __init__(self, | ||
container_url_arg: str | None = None, | ||
container_name_arg: str | None = None) -> None: | ||
self._container_url_arg = container_url_arg | ||
self._container_name_arg = container_name_arg | ||
|
||
def __call__(self, **kwargs): | ||
|
||
pyexasol_connection = open_pyexasol_connection(**kwargs) | ||
bucketfs_location = create_bucketfs_location(**kwargs) | ||
|
||
language_alias = kwargs[StdParams.language_alias.name] | ||
container_file = kwargs[StdParams.container_file.name] | ||
upload_container = kwargs[StdParams.upload_container.name] | ||
alter_system = kwargs[StdParams.alter_system.name] | ||
allow_override = kwargs[StdParams.allow_override.name] | ||
wait_for_completion = kwargs[StdParams.wait_for_completion.name] | ||
|
||
deployer = LanguageContainerDeployer(pyexasol_connection, | ||
language_alias, | ||
bucketfs_location) | ||
if not upload_container: | ||
deployer.run(alter_system=alter_system, | ||
allow_override=allow_override, | ||
wait_for_completion=wait_for_completion) | ||
elif container_file: | ||
deployer.run(container_file=Path(container_file), | ||
alter_system=alter_system, | ||
allow_override=allow_override, | ||
wait_for_completion=wait_for_completion) | ||
elif (self._container_url_arg and self._container_name_arg and | ||
kwargs[self._container_url_arg] and kwargs[self._container_name_arg]): | ||
deployer.download_and_run(kwargs[self._container_url_arg], | ||
kwargs[self._container_name_arg], | ||
alter_system=alter_system, | ||
allow_override=allow_override, | ||
wait_for_completion=wait_for_completion) | ||
else: | ||
raise ValueError("To upload a language container either its release version " | ||
f"(--{StdParams.version.name}) or a path of the already " | ||
f"downloaded container file (--{StdParams.container_file.name}) " | ||
"must be provided.") |
99 changes: 99 additions & 0 deletions
99
test/integration/cli/test_language_container_deployer_cli.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
from typing import Any | ||
from urllib.parse import urlparse | ||
import pytest | ||
import click | ||
from click.testing import CliRunner | ||
|
||
from exasol.python_extension_common.cli.std_options import ( | ||
StdTags, StdParams, ParameterFormatters, select_std_options) | ||
from exasol.python_extension_common.connections.pyexasol_connection import ( | ||
open_pyexasol_connection) | ||
from exasol.python_extension_common.cli.language_container_deployer_cli import ( | ||
LanguageContainerDeployerCli) | ||
from test.utils.db_utils import assert_udf_running | ||
|
||
CONTAINER_URL_ARG = 'container_url' | ||
CONTAINER_NAME_ARG = 'container_name' | ||
|
||
|
||
@pytest.fixture | ||
def onprem_params(exasol_config, | ||
bucketfs_config, | ||
language_alias) -> dict[str, Any]: | ||
|
||
parsed_url = urlparse(bucketfs_config.url) | ||
host, port = parsed_url.netloc.split(":") | ||
return { | ||
StdParams.dsn.name: f'{exasol_config.host}:{exasol_config.port}', | ||
StdParams.db_user.name: exasol_config.username, | ||
StdParams.db_password.name: exasol_config.password, | ||
StdParams.bucketfs_host.name: host, | ||
StdParams.bucketfs_port.name: port, | ||
StdParams.bucketfs_use_https.name: parsed_url.scheme.lower() == 'https', | ||
StdParams.bucketfs_user.name: bucketfs_config.username, | ||
StdParams.bucketfs_password.name: bucketfs_config.password, | ||
StdParams.bucketfs_name.name: 'bfsdefault', | ||
StdParams.bucket.name: 'default', | ||
StdParams.use_ssl_cert_validation.name: False, | ||
StdParams.path_in_bucket.name: 'container', | ||
StdParams.language_alias: language_alias | ||
} | ||
|
||
|
||
def make_args_string(**kwargs) -> str: | ||
return ' '.join(f'--{k} {v}' for k, v in kwargs.items()) | ||
|
||
|
||
def test_slc_deployer_cli_onprem_url(use_onprem, | ||
backend_aware_onprem_database, | ||
container_version, | ||
container_name, | ||
container_url_formatter, | ||
language_alias, | ||
db_schema, | ||
onprem_params): | ||
if not use_onprem: | ||
pytest.skip("The test is not configured to use ITDE.") | ||
|
||
ver_formatter = ParameterFormatters() | ||
ver_formatter.set_formatter(CONTAINER_URL_ARG, container_url_formatter) | ||
ver_formatter.set_formatter(CONTAINER_NAME_ARG, container_name) | ||
|
||
opts = select_std_options( | ||
[StdTags.DB | StdTags.ONPREM, StdTags.BFS | StdTags.ONPREM, StdTags.SLC], | ||
formatters={StdParams.version: ver_formatter}) | ||
cli_callback = LanguageContainerDeployerCli( | ||
container_url_arg=CONTAINER_URL_ARG, | ||
container_name_arg=CONTAINER_NAME_ARG) | ||
extra_params = {StdParams.version: container_version} | ||
args = make_args_string(**onprem_params, **extra_params) | ||
|
||
cmd = click.Command('deploy_slc', params=opts, callback=cli_callback) | ||
runner = CliRunner() | ||
runner.invoke(cmd, args=args) | ||
|
||
with open_pyexasol_connection(**onprem_params) as conn: | ||
assert_udf_running(conn, language_alias, db_schema) | ||
|
||
|
||
def test_slc_deployer_cli_onprem_file(use_onprem, | ||
backend_aware_onprem_database, | ||
container_path, | ||
language_alias, | ||
db_schema, | ||
onprem_params): | ||
if not use_onprem: | ||
pytest.skip("The test is not configured to use ITDE.") | ||
|
||
opts = select_std_options( | ||
[StdTags.DB | StdTags.ONPREM, StdTags.BFS | StdTags.ONPREM, StdTags.SLC]) | ||
cli_callback = LanguageContainerDeployerCli() | ||
extra_params = {StdParams.container_file: container_path} | ||
args = make_args_string(**onprem_params, **extra_params) | ||
|
||
cmd = click.Command('deploy_slc', params=opts, callback=cli_callback) | ||
runner = CliRunner() | ||
runner.invoke(cmd, args=args) | ||
|
||
with open_pyexasol_connection(**onprem_params) as conn: | ||
assert_udf_running(conn, language_alias, db_schema) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters