FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
feast/sdk/python/tests/integration/conftest.py at stable · feast-dev/feast · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
feast-dev
/
feast
Public
Notifications
You must be signed in to change notification settings
Fork
1.4k
Star
7.2k
Code
Issues
218
Pull requests
191
Discussions
Actions
Security and quality
1
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
feast
/
sdk
/
python
/
tests
/
integration
/
conftest.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
162 lines (124 loc) · 4.23 KB
Breadcrumbs
feast
/
sdk
/
python
/
tests
/
integration
/
conftest.py
Copy path
File metadata and controls
162 lines (124 loc) · 4.23 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import
atexit
import
json
import
logging
import
random
import
tempfile
import
time
from
pathlib
import
Path
from
typing
import
Optional
import
pytest
from
testcontainers
.
keycloak
import
KeycloakContainer
from
testcontainers
.
minio
import
MinioContainer
from
testcontainers
.
mysql
import
MySqlContainer
from
testcontainers
.
postgres
import
PostgresContainer
from
tests
.
utils
.
auth_permissions_util
import
setup_permissions_on_keycloak
logger
=
logging
.
getLogger
(
__name__
)
logger
.
setLevel
(
logging
.
INFO
)
# Shared Keycloak state
_keycloak_container
:
Optional
[
KeycloakContainer
]
=
None
_keycloak_info_file
=
Path
(
tempfile
.
gettempdir
())
/
"feast_keycloak_info.json"
def
_is_keycloak_healthy
(
url
:
str
)
->
bool
:
"""Health check for Keycloak."""
try
:
import
requests
response
=
requests
.
get
(
f"
{
url
}
/health/ready"
,
timeout
=
3
)
return
response
.
status_code
==
200
except
Exception
:
try
:
import
requests
response
=
requests
.
get
(
f"
{
url
}
/auth/realms/master"
,
timeout
=
3
)
return
response
.
status_code
in
[
200
,
404
]
except
Exception
:
return
False
def
_get_shared_keycloak_url
()
->
Optional
[
str
]:
"""Get URL of existing Keycloak instance if available."""
try
:
if
_keycloak_info_file
.
exists
():
with
open
(
_keycloak_info_file
,
"r"
)
as
f
:
info
=
json
.
load
(
f
)
url
=
info
.
get
(
"url"
)
if
url
and
_is_keycloak_healthy
(
url
):
return
url
else
:
_keycloak_info_file
.
unlink
()
except
Exception
as
e
:
logger
.
debug
(
f"Error reading Keycloak info:
{
e
}
"
)
try
:
_keycloak_info_file
.
unlink
()
except
Exception
:
pass
return
None
def
_save_keycloak_info
(
url
:
str
):
"""Save Keycloak info to shared file."""
try
:
info
=
{
"url"
:
url
,
"timestamp"
:
time
.
time
()}
with
open
(
_keycloak_info_file
,
"w"
)
as
f
:
json
.
dump
(
info
,
f
)
except
Exception
as
e
:
logger
.
warning
(
f"Failed to save Keycloak info:
{
e
}
"
)
def
_cleanup_keycloak
():
"""Cleanup Keycloak container on exit."""
global
_keycloak_container
if
_keycloak_container
:
try
:
logger
.
info
(
"Stopping Keycloak container"
)
_keycloak_container
.
stop
()
except
Exception
as
e
:
logger
.
warning
(
f"Error stopping Keycloak:
{
e
}
"
)
finally
:
_keycloak_container
=
None
try
:
_keycloak_info_file
.
unlink
()
except
Exception
:
pass
@
pytest
.
fixture
(
scope
=
"session"
)
def
start_keycloak_server
():
global
_keycloak_container
existing_url
=
_get_shared_keycloak_url
()
if
existing_url
:
logger
.
info
(
f"Reusing existing Keycloak at
{
existing_url
}
"
)
yield
existing_url
return
time
.
sleep
(
random
.
uniform
(
0
,
0.5
))
existing_url
=
_get_shared_keycloak_url
()
if
existing_url
:
logger
.
info
(
f"Found Keycloak started by another process:
{
existing_url
}
"
)
yield
existing_url
return
try
:
logger
.
info
(
"Starting new Keycloak instance"
)
_keycloak_container
=
KeycloakContainer
(
"quay.io/keycloak/keycloak:24.0.1"
)
_keycloak_container
.
start
()
setup_permissions_on_keycloak
(
_keycloak_container
.
get_client
())
keycloak_url
=
_keycloak_container
.
get_url
()
_save_keycloak_info
(
keycloak_url
)
atexit
.
register
(
_cleanup_keycloak
)
logger
.
info
(
f"Keycloak ready at
{
keycloak_url
}
"
)
yield
keycloak_url
except
Exception
as
e
:
logger
.
error
(
f"Failed to start Keycloak:
{
e
}
"
)
if
_keycloak_container
:
try
:
_keycloak_container
.
stop
()
except
Exception
:
pass
_keycloak_container
=
None
raise
@
pytest
.
fixture
(
scope
=
"session"
)
def
mysql_server
():
container
=
MySqlContainer
(
"mysql:latest"
,
dialect
=
"pymysql"
)
container
.
start
()
yield
container
container
.
stop
()
@
pytest
.
fixture
(
scope
=
"session"
)
def
postgres_server
():
container
=
PostgresContainer
()
container
.
start
()
yield
container
container
.
stop
()
@
pytest
.
fixture
(
scope
=
"session"
)
def
minio_server
():
container
=
MinioContainer
()
container
.
start
()
yield
container
container
.
stop
()
Back
|
FazBrowse Home
|
New Git URL