Skip to content

Commit 12ee5ff

Browse files
committed
added support for enterprise images
1 parent 2ae94ef commit 12ee5ff

File tree

4 files changed

+75
-15
lines changed

4 files changed

+75
-15
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,19 @@
2424

2525
The snippet above will spin up a InterSystems IRIS database in a container. The get_connection_url() convenience method returns a sqlalchemy compatible url we use to connect to the database and retrieve the database version.
2626

27+
It is possible to run Enterprise edition as well, with passing a valid iris.key.
28+
29+
```python
30+
iris_container = IRISContainer(
31+
"containers.intersystems.com/intersystems/iris:2023.3",
32+
license_key="/full/path/to/iris.key",
33+
username="testuser",
34+
password="testpass",
35+
namespace="TEST",
36+
)
37+
38+
```
39+
40+
`username`, `password`, `namespace` will be created during start of the container with required values, user will get %All role
41+
2742
More extensive documentation can be found at [Read The Docs](https://testcontainers-python.readthedocs.io/).

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
setup(
66
name="testcontainers-iris",
7-
version="1.0.2",
7+
version="1.1.0",
88
packages=find_namespace_packages(),
99
description=description,
1010
long_description=open('README.md').read(),

testcontainers/iris/__init__.py

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from typing import Optional
33
from testcontainers.core.generic import DbContainer
44
# from testcontainers.core.utils import raise_for_deprecated_parameter
5-
5+
from testcontainers.core.waiting_utils import wait_for_logs
66

77
class IRISContainer(DbContainer):
88
"""
@@ -27,27 +27,54 @@ class IRISContainer(DbContainer):
2727
>>> version
2828
'IRIS for UNIX (Ubuntu Server LTS for ARM64 Containers) 2023.2 (Build 227U) Mon Jul 31 2023 17:43:25 EDT'
2929
"""
30-
def __init__(self, image: str = "intersystemsdc/iris-community:latest", port: int = 1972,
31-
username: Optional[str] = None, password: Optional[str] = None,
32-
dbname: Optional[str] = None, driver: str = "iris", **kwargs) -> None:
30+
def __init__(self, image: str = "intersystemsdc/iris-community:latest",
31+
port: int = 1972,
32+
username: Optional[str] = None,
33+
password: Optional[str] = None,
34+
namespace: Optional[str] = None,
35+
driver: str = "iris",
36+
license_key: str = None,
37+
**kwargs
38+
) -> None:
3339
# raise_for_deprecated_parameter(kwargs, "user", "username")
3440
super(IRISContainer, self).__init__(image=image, **kwargs)
41+
self.image = image
3542
self.username = username or os.environ.get("IRIS_USERNAME", "test")
3643
self.password = password or os.environ.get("IRIS_PASSWORD", "test")
37-
self.dbname = dbname or os.environ.get("IRIS_NAMESPACE", "USER")
44+
self.namespace = namespace or os.environ.get("IRIS_NAMESPACE", "USER")
3845
self.port = port
3946
self.driver = driver
47+
self.license_key = license_key
4048

4149
self.with_exposed_ports(self.port)
4250

4351
def _configure(self) -> None:
4452
self.with_env("IRIS_USERNAME", self.username)
4553
self.with_env("IRIS_PASSWORD", self.password)
46-
self.with_env("IRIS_NAMESPACE", self.dbname)
54+
self.with_env("IRIS_NAMESPACE", self.namespace)
55+
if self.license_key:
56+
self.with_volume_mapping(self.license_key, "/usr/irissys/mgr/iris.key", "ro")
57+
def _connect(self) -> None:
58+
wait_for_logs(self, predicate="Enabling logons")
59+
if self.image.startswith("intersystemsdc"):
60+
wait_for_logs(self, predicate="executed command")
61+
else:
62+
if self.namespace.upper() != "USER":
63+
cmd = f"iris session iris -U %%SYS '##class(%%SQL.Statement).%%ExecDirect(,\"CREATE DATABASE %s\")'" % (
64+
self.namespace,
65+
)
66+
self.exec(cmd)
67+
cmd = f"iris session iris -U %%SYS '##class(Security.Users).Create(\"%s\",\"%s\",\"%s\",,\"%s\")'" % (
68+
self.username,
69+
"%ALL",
70+
self.password,
71+
self.namespace,
72+
)
73+
res = self.exec(cmd)
4774

4875
def get_connection_url(self, host=None) -> str:
4976
return super()._create_connection_url(
5077
dialect=f"iris", username=self.username,
51-
password=self.password, db_name=self.dbname, host=host,
78+
password=self.password, db_name=self.namespace, host=host,
5279
port=self.port,
5380
)

tests/test_iris.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,30 @@
1+
import os
12
import sqlalchemy
23
from testcontainers.iris import IRISContainer
34

5+
creds = {
6+
"username": "test",
7+
"password": "test",
8+
"namespace": "TEST",
9+
}
410

5-
def test_docker_run_iris():
6-
iris_container = IRISContainer("intersystemsdc/iris-community:2023.1.1.380.0-zpm")
11+
12+
def check_connection(iris):
13+
engine = sqlalchemy.create_engine(iris.get_connection_url())
14+
with engine.begin() as connection:
15+
result = connection.execute(sqlalchemy.text("select $username, $namespace"))
16+
assert result.fetchone() == (creds["username"], creds["namespace"])
17+
18+
19+
def test_community():
20+
iris_container = IRISContainer("intersystemsdc/iris-community:2023.1.1.380.0-zpm", **creds)
21+
with iris_container as iris:
22+
check_connection(iris)
23+
24+
25+
def test_enterprise():
26+
license_key = os.path.abspath(os.path.expanduser("~/iris.key"))
27+
iris_container = IRISContainer("containers.intersystems.com/intersystems/iris:2023.3", license_key=license_key,
28+
**creds)
729
with iris_container as iris:
8-
engine = sqlalchemy.create_engine(iris.get_connection_url())
9-
with engine.begin() as connection:
10-
result = connection.execute(sqlalchemy.text("select $zversion"))
11-
for row in result:
12-
assert "2023.1.1 (Build 380U)" in row[0]
30+
check_connection(iris)

0 commit comments

Comments
 (0)