Skip to content

Commit b192104

Browse files
committed
start testing ibm db2 compatibility
1 parent d482fd7 commit b192104

File tree

5 files changed

+80
-3
lines changed

5 files changed

+80
-3
lines changed

.github/workflows/ci.yml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@ jobs:
3838
matrix:
3939
os: [Ubuntu]
4040
python-version: ['3.8', '3.9', '3.10']
41+
services:
42+
ibm_db2:
43+
image: ibmcom/db2:11.5.5.1
44+
env:
45+
LICENSE: accept
46+
DB2INSTANCE: db2inst1
47+
DB2INST1_PASSWORD: password
48+
DBNAME: testdb
49+
UPDATEAVAIL: "NO"
50+
options: --privileged
51+
ports:
52+
- 50000:50000
4153
steps:
4254
- name: Checkout branch
4355
uses: actions/[email protected]
@@ -83,7 +95,7 @@ jobs:
8395

8496
- name: Install dependencies
8597
shell: bash
86-
run: poetry install -vvv
98+
run: poetry install -vvv -E mssql -E ibm_db2
8799

88100
- name: Start Docker Compose
89101
uses: isbang/[email protected]
@@ -94,8 +106,12 @@ jobs:
94106
shell: bash
95107
run: sleep 2
96108

109+
- name: Wait for DB/2
110+
timeout-minutes: 2
111+
run: until docker logs "${{ job.services.ibm_db2.id }}" 2>&1 | grep -q "Setup has completed"; do sleep 10; echo Waiting; done
112+
97113
- name: Test
98114
shell: bash
99115
run: |
100-
# poetry run pytest -q tests
101-
poetry run pytest -s tests # interactive log output
116+
poetry run pytest -q tests
117+
# poetry run pytest -s tests # interactive log output

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,19 @@ You can inspect the contents of the PipeDAT Postgres database at `postgresql://p
6565
To reset the state of the docker containers you can run `docker compose down`.
6666
This might be necessary if the database cache gets corrupted.
6767

68+
## Testing db2 functionality
69+
70+
For running @pytest.mark.ibm_db2 tests, you need to spin up a docker container without `docker compose` since it needs
71+
the `--priviledged` option which `docker compose` does not offer.
72+
73+
```bash
74+
docker run -h db2server --name db2server --restart=always --detach --privileged=true -p 50000:50000 --env-file docker_db2.env_list -v /Docker:/database ibmcom/db2
75+
```
76+
77+
Then check `docker logs db2server | grep -i completed` until you see `(*) Setup has completed.`.
78+
79+
Afterwards you can run `pytest --ibm_db2`.
80+
6881
## Troubleshooting
6982

7083
### Installing mssql odbc driver for linux

docker_db2.env_list

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
LICENSE=accept
2+
DB2INSTANCE=db2inst1
3+
DB2INST1_PASSWORD=password
4+
DBNAME=testdb
5+
BLU=false
6+
ENABLE_ORACLE_COMPATIBILITY=false
7+
UPDATEAVAIL=NO
8+
TO_CREATE_SAMPLEDB=false
9+
REPODB=false
10+
IS_OSXFS=false
11+
PERSISTENT_HOME=true
12+
HADR_ENABLED=false
13+
ETCD_ENDPOINT=
14+
ETCD_USERNAME=
15+
ETCD_PASSWORD=

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ sphinx-rtd-theme = { version = "^1.0.0", optional = true }
4141
sphinxcontrib-apidoc = { version="^0.3.0", optional = true }
4242
python-box = "^6.1.0"
4343

44+
pyodbc = { version = "^4.0.35", optional = true }
45+
ibm-db = { version = "^3.1.4", optional = true }
46+
ibm-db-sa = { version = "^0.3.8", optional = true }
4447
prefect = { version = ">=1.3,<2", optional = true }
4548
# for prefect 2 (radical change of paradigmns especially in task graph display => not ideal for rather linear pipeline)
4649
# prefect = { version = "prefect>=2.0,<3", optional = true }
@@ -50,6 +53,7 @@ filelock = ["filelock"]
5053
zookeeper = ["kazoo"]
5154
docs = ["Sphinx", "sphinx-rtd-theme", "sphinxcontrib-apidoc"]
5255
mssql = ["pyodbc"]
56+
ibm_db2 = ["ibm-db", "ibm-db-sa"]
5357
prefect = ["prefect", "docker-compose"]
5458

5559
[tool.poetry.dev-dependencies]

tests/test_db2.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import ibm_db
2+
import pandas as pd
3+
import sqlalchemy as sa
4+
import structlog
5+
6+
7+
def test_db2():
8+
logger = structlog.getLogger(module=__name__)
9+
conn = ibm_db.connect(
10+
"DATABASE=testdb;HOSTNAME=localhost;PORT=50000;PROTOCOL=TCPIP;UID=db2inst1;PWD=password;",
11+
"",
12+
"",
13+
)
14+
query = "SELECT 1 as a FROM SYSIBM.SYSDUMMY1"
15+
stmt = ibm_db.exec_immediate(conn, query)
16+
row = True
17+
rows = []
18+
while row is not False:
19+
row = ibm_db.fetch_assoc(stmt)
20+
print(row)
21+
logger.info("DB2 test row", row=row)
22+
rows.append(row)
23+
24+
25+
def test_db2_sqlalchemy():
26+
logger = structlog.getLogger(module=__name__)
27+
engine = sa.create_engine("db2+ibm_db://db2inst1:password@localhost:50000/testdb")
28+
df = pd.read_sql("SELECT 1 as a FROM SYSIBM.SYSDUMMY1", con=engine)
29+
logger.info("DB2 test df", df="\n" + str(df))

0 commit comments

Comments
 (0)