Skip to content

Commit

Permalink
Scripts deployment refactoring [run aws tests] (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahsimb authored Dec 20, 2023
1 parent ae483de commit 8e0cf6b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 21 deletions.
3 changes: 1 addition & 2 deletions exasol_sagemaker_extension/deployment/deploy_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def main(host: str, port: str, user: str, pwd: str, schema: str,
logging.basicConfig(format='%(asctime)s - %(module)s - %(message)s',
level=logging.DEBUG)

deployment = DeployCreateStatements(
DeployCreateStatements.create_and_run(
db_host=host,
db_port=port,
db_user=user,
Expand All @@ -29,7 +29,6 @@ def main(host: str, port: str, user: str, pwd: str, schema: str,
to_print=verbose,
develop=develop
)
deployment.run()


if __name__ == "__main__":
Expand Down
57 changes: 41 additions & 16 deletions exasol_sagemaker_extension/deployment/deploy_create_statements.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,12 @@ class DeployCreateStatements:
that generate scripts deploying the sagemaker-extension project.
"""

def __init__(self, db_host: str, db_port: str, db_user: str, db_pass: str,
def __init__(self, exasol_conn: pyexasol.ExaConnection,
schema: str, to_print: bool, develop: bool):
self._db_host = db_host
self._db_port = db_port
self._db_user = db_user
self._db_pass = db_pass
self._schema = schema
self._to_print = to_print
self._develop = develop
self.__exasol_conn = pyexasol.connect(
dsn="{host}:{port}".format(
host=self._db_host, port=self._db_port),
user=self._db_user,
password=self._db_pass,
compression=True,
encryption=True,
websocket_sslopt={
"cert_reqs": ssl.CERT_NONE,
}
)
self.__exasol_conn = exasol_conn

@property
def statement_maps(self):
Expand Down Expand Up @@ -131,3 +117,42 @@ def create_statements():
stmt_generator.save_statement()
logger.debug(f"{stmt_generator.__class__.__name__} "
"is created and saved.")

@classmethod
def create_and_run(cls,
db_host: str,
db_port: str,
db_user: str,
db_pass: str,
schema: str,
to_print: bool,
develop: bool):
"""
Creates a database connection object based on the provided credentials
Creates an instance of the DeployCreateStatements passing the connection
object to it and calls its run method.
Parameters:
db_host - database host address
db_port - database port
db_user - database username
db_pass - the user password
schema - schema where the scripts should be created
to_print - if True the script creation SQL commands will be
printed rather than executed
develop - if True the scripts will be generated from scratch
"""

exasol_conn = pyexasol.connect(
dsn=f"{db_host}:{db_port}",
user=db_user,
password=db_pass,
compression=True,
encryption=True,
websocket_sslopt={
"cert_reqs": ssl.CERT_NONE,
}
)

deployer = cls(exasol_conn, schema, to_print, develop)
deployer.run()
4 changes: 1 addition & 3 deletions tests/deployment/test_deploy_create_statements.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def get_all_scripts(db_conn):


def test_deploy_create_statements(db_conn, register_language_container):
deployer = DeployCreateStatements(
DeployCreateStatements.create_and_run(
db_host=db_params.host,
db_port=db_params.port,
db_user=db_params.user,
Expand All @@ -37,8 +37,6 @@ def test_deploy_create_statements(db_conn, register_language_container):
develop=False
)

deployer.run()

all_schemas = get_all_schemas(db_conn)
all_scripts = get_all_scripts(db_conn)

Expand Down

0 comments on commit 8e0cf6b

Please sign in to comment.