Skip to content

Commit

Permalink
some updates
Browse files Browse the repository at this point in the history
  • Loading branch information
daimor committed Jan 8, 2025
1 parent 6488e17 commit bd6a15a
Showing 1 changed file with 35 additions and 19 deletions.
54 changes: 35 additions & 19 deletions testcontainers/iris/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import os
from typing import Optional
from testcontainers.core.generic import DbContainer

# from testcontainers.core.utils import raise_for_deprecated_parameter
from testcontainers.core.waiting_utils import wait_for_logs


class IRISContainer(DbContainer):
"""
InterSystems IRIS database container.
Expand All @@ -27,15 +29,18 @@ class IRISContainer(DbContainer):
>>> version
'IRIS for UNIX (Ubuntu Server LTS for ARM64 Containers) 2023.2 (Build 227U) Mon Jul 31 2023 17:43:25 EDT'
"""
def __init__(self, image: str = "intersystemsdc/iris-community:latest",
port: int = 1972,
username: Optional[str] = None,
password: Optional[str] = None,
namespace: Optional[str] = None,
driver: str = "iris",
license_key: str = None,
**kwargs
) -> None:

def __init__(
self,
image: str = "intersystemsdc/iris-community:latest",
port: int = 1972,
username: Optional[str] = None,
password: Optional[str] = None,
namespace: Optional[str] = None,
driver: str = "iris",
license_key: str = None,
**kwargs,
) -> None:
# raise_for_deprecated_parameter(kwargs, "user", "username")
super(IRISContainer, self).__init__(image=image, **kwargs)
self.image = image
Expand All @@ -53,28 +58,39 @@ def _configure(self) -> None:
self.with_env("IRIS_PASSWORD", self.password)
self.with_env("IRIS_NAMESPACE", self.namespace)
if self.license_key:
self.with_volume_mapping(self.license_key, "/usr/irissys/mgr/iris.key", "ro")
self.with_volume_mapping(
self.license_key, "/usr/irissys/mgr/iris.key", "ro"
)

def _connect(self) -> None:
wait_for_logs(self, predicate="Enabling logons")
if self.image.startswith("intersystemsdc"):
wait_for_logs(self, predicate="executed command")
else:
if self.namespace.upper() != "USER":
cmd = f"iris session iris -U %%SYS '##class(%%SQL.Statement).%%ExecDirect(,\"CREATE DATABASE %s\")'" % (
self.namespace,
cmd = (
f"iris session iris -U %%SYS '##class(%%SQL.Statement).%%ExecDirect(,\"CREATE DATABASE %s\")'"
% (self.namespace,)
)
self.exec(cmd)
cmd = f"iris session iris -U %%SYS '##class(Security.Users).Create(\"%s\",\"%s\",\"%s\",,\"%s\")'" % (
self.username,
"%ALL",
self.password,
self.namespace,
cmd = (
f'iris session iris -U %%SYS \'##class(Security.Users).Create("%s","%s","%s",,"%s")\''
% (
self.username,
"%ALL",
self.password,
self.namespace,
)
)
res = self.exec(cmd)
print("res", cmd, res)

def get_connection_url(self, host=None) -> str:
return super()._create_connection_url(
dialect=f"iris", username=self.username,
password=self.password, db_name=self.namespace, host=host,
dialect="iris",
username=self.username,
password=self.password,
db_name=self.namespace,
host=host,
port=self.port,
)

0 comments on commit bd6a15a

Please sign in to comment.