1
+ import logging
1
2
import tempfile
2
3
import time
3
4
import uuid
@@ -21,17 +22,29 @@ def fixture_dir(test_dir):
21
22
def reset_gitlab (gl ):
22
23
# previously tools/reset_gitlab.py
23
24
for project in gl .projects .list ():
25
+ logging .info (f"Mark for deletion project: { project .name !r} " )
24
26
for deploy_token in project .deploytokens .list ():
27
+ logging .info (
28
+ f"Mark for deletion token: { deploy_token .name !r} in "
29
+ f"project: { project .name !r} "
30
+ )
25
31
deploy_token .delete ()
26
32
project .delete ()
27
33
for group in gl .groups .list ():
34
+ logging .info (f"Mark for deletion group: { group .name !r} " )
28
35
for deploy_token in group .deploytokens .list ():
36
+ logging .info (
37
+ f"Mark for deletion token: { deploy_token .name !r} in "
38
+ f"group: { group .name !r} "
39
+ )
29
40
deploy_token .delete ()
30
41
group .delete ()
31
42
for variable in gl .variables .list ():
43
+ logging .info (f"Mark for deletion variable: { variable .name !r} " )
32
44
variable .delete ()
33
45
for user in gl .users .list ():
34
46
if user .username != "root" :
47
+ logging .info (f"Mark for deletion user: { user .username !r} " )
35
48
user .delete (hard_delete = True )
36
49
37
50
max_iterations = int (TIMEOUT / SLEEP_INTERVAL )
@@ -44,13 +57,27 @@ def wait_for_maximum_list_length(
44
57
) -> None :
45
58
"""Wait for the list() length to be no greater than expected maximum or fail
46
59
test if timeout is exceeded"""
47
- for _ in range (max_iterations ):
48
- if len (rest_manager .list ()) <= max_length :
60
+ logging .info (f"Checking { description !r} has no more than { max_length } items" )
61
+ for count in range (max_iterations ):
62
+ items = rest_manager .list ()
63
+ if len (items ) <= max_length :
49
64
break
65
+ logging .info (
66
+ f"Iteration: { count } Waiting for { description !r} items to be deleted: "
67
+ f"{ [x .name for x in items ]} "
68
+ )
50
69
time .sleep (SLEEP_INTERVAL )
51
- assert len (rest_manager .list ()) <= max_length , (
52
- f"Did not delete required items for { description } . "
53
- f"Elapsed_time: { time .perf_counter () - start_time } "
70
+
71
+ items = rest_manager .list ()
72
+ elapsed_time = time .perf_counter () - start_time
73
+ if len (items ) > max_length :
74
+ logging .error (
75
+ f"Too many { description !r} items still remaining and timeout "
76
+ f"({ elapsed_time } ) exceeded: { [x .name for x in items ]} "
77
+ )
78
+ assert len (items ) <= max_length , (
79
+ f"Did not delete required items for { description !r} . "
80
+ f"Elapsed_time: { elapsed_time } "
54
81
)
55
82
56
83
wait_for_maximum_list_length (rest_manager = gl .projects , description = "projects" )
@@ -62,6 +89,7 @@ def wait_for_maximum_list_length(
62
89
63
90
64
91
def set_token (container , fixture_dir ):
92
+ logging .info ("Creating API token." )
65
93
set_token_rb = fixture_dir / "set_token.rb"
66
94
67
95
with open (set_token_rb , "r" ) as f :
@@ -76,6 +104,7 @@ def set_token(container, fixture_dir):
76
104
set_token_command ,
77
105
]
78
106
output = check_output (rails_command ).decode ().strip ()
107
+ logging .info ("Finished creating API token." )
79
108
80
109
return output
81
110
@@ -85,7 +114,7 @@ def pytest_report_collectionfinish(config, startdir, items):
85
114
"" ,
86
115
"Starting GitLab container." ,
87
116
"Waiting for GitLab to reconfigure." ,
88
- "This may take a few minutes." ,
117
+ "This will take a few minutes." ,
89
118
]
90
119
91
120
@@ -129,6 +158,7 @@ def check_is_alive():
129
158
"""
130
159
131
160
def _check (container ):
161
+ logging .info ("Checking if GitLab container is up..." )
132
162
logs = ["docker" , "logs" , container ]
133
163
return "gitlab Reconfigured!" in check_output (logs ).decode ()
134
164
@@ -144,7 +174,7 @@ def wait_for_sidekiq(gl):
144
174
"""
145
175
146
176
def _wait (timeout = 30 , step = 0.5 ):
147
- for _ in range (timeout ):
177
+ for count in range (timeout ):
148
178
time .sleep (step )
149
179
busy = False
150
180
processes = gl .sidekiq .process_metrics ()["processes" ]
@@ -153,6 +183,7 @@ def _wait(timeout=30, step=0.5):
153
183
busy = True
154
184
if not busy :
155
185
return True
186
+ logging .info (f"sidekiq busy { count } of { timeout } " )
156
187
return False
157
188
158
189
return _wait
@@ -163,9 +194,11 @@ def gitlab_config(check_is_alive, docker_ip, docker_services, temp_dir, fixture_
163
194
config_file = temp_dir / "python-gitlab.cfg"
164
195
port = docker_services .port_for ("gitlab" , 80 )
165
196
197
+ logging .info ("Waiting for GitLab container to become ready." )
166
198
docker_services .wait_until_responsive (
167
199
timeout = 200 , pause = 5 , check = lambda : check_is_alive ("gitlab-test" )
168
200
)
201
+ logging .info ("GitLab container is now ready." )
169
202
170
203
token = set_token ("gitlab-test" , fixture_dir = fixture_dir )
171
204
@@ -188,7 +221,9 @@ def gitlab_config(check_is_alive, docker_ip, docker_services, temp_dir, fixture_
188
221
def gl (gitlab_config ):
189
222
"""Helper instance to make fixtures and asserts directly via the API."""
190
223
224
+ logging .info ("Create python-gitlab gitlab.Gitlab object" )
191
225
instance = gitlab .Gitlab .from_config ("local" , [gitlab_config ])
226
+
192
227
reset_gitlab (instance )
193
228
194
229
return instance
0 commit comments