Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0480644

Browse files
chore: make reset_gitlab() better
Saw issues in the CI where reset_gitlab() would fail. It would fail todelete the group that is created when GitLab starts up. Extending thetimeout didn't fix the issue.Changed the code so now it will check if the item is deleted and if itisn't it will call the delete() method again to ensure that GitLabknows it should be deleted. Since making this change I have not beenable to reproduce the failure in reset_gitlab().Also added some logging functionality that can be seen if logging isturned on in pytest.
1 parent1efb123 commit0480644

File tree

1 file changed

+50
-4
lines changed

1 file changed

+50
-4
lines changed

‎tests/functional/conftest.py‎

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,18 @@ def fixture_dir(test_dir):
1919
returntest_dir/"functional"/"fixtures"
2020

2121

22-
defreset_gitlab(gl):
23-
# previously tools/reset_gitlab.py
22+
defreset_gitlab(gl:gitlab.Gitlab)->None:
23+
# Mark our resources for deletion. It takes time for them to actually be deleted
24+
# though.
25+
_reset_gitlab_delete_resources(gl=gl)
26+
27+
# Wait for all resources to be deleted
28+
_reset_gitlab_wait_deletion_finish(gl=gl)
29+
30+
31+
def_reset_gitlab_delete_resources(gl:gitlab.Gitlab)->None:
32+
"""Mark for deletion, resources (such as projects, groups, users) that shouldn't
33+
exist. Once marked they will still take time to be deleted."""
2434
forprojectingl.projects.list():
2535
logging.info(f"Marking for deletion project:{project.path_with_namespace!r}")
2636
fordeploy_tokeninproject.deploytokens.list():
@@ -49,13 +59,24 @@ def reset_gitlab(gl):
4959
logging.info(f"Marking for deletion user:{user.username!r}")
5060
user.delete(hard_delete=True)
5161

62+
63+
def_reset_gitlab_wait_deletion_finish(gl:gitlab.Gitlab)->None:
64+
"""Wait for all of our resources to be deleted.
65+
66+
If anything exists then mark it again for deletion in case initial call to delete
67+
didn't work, which has been seen :("""
68+
5269
max_iterations=int(TIMEOUT/SLEEP_INTERVAL)
5370

5471
# Ensure everything has been reset
5572
start_time=time.perf_counter()
5673

5774
defwait_for_list_size(
58-
rest_manager:gitlab.base.RESTManager,description:str,max_length:int=0
75+
rest_manager:gitlab.base.RESTManager,
76+
description:str,
77+
max_length:int=0,
78+
should_delete_func=lambdax:True,
79+
delete_kwargs={},
5980
)->None:
6081
"""Wait for the list() length to be no greater than expected maximum or fail
6182
test if timeout is exceeded"""
@@ -68,6 +89,19 @@ def wait_for_list_size(
6889
f"Iteration:{count} Waiting for{description!r} items to be deleted: "
6990
f"{[x.nameforxinitems]}"
7091
)
92+
foriteminitems:
93+
ifshould_delete_func(item):
94+
logging.info(
95+
f"Marking{description!r} item again for deletion: "
96+
f"{item.name!r}"
97+
)
98+
try:
99+
item.delete(**delete_kwargs)
100+
exceptgitlab.exceptions.GitlabDeleteErrorasexc:
101+
logging.info(
102+
f"{description!r} item already marked for deletion: "
103+
f"{item.name!r}{exc}"
104+
)
71105
time.sleep(SLEEP_INTERVAL)
72106

73107
elapsed_time=time.perf_counter()-start_time
@@ -82,7 +116,19 @@ def wait_for_list_size(
82116
wait_for_list_size(rest_manager=gl.projects,description="projects")
83117
wait_for_list_size(rest_manager=gl.groups,description="groups")
84118
wait_for_list_size(rest_manager=gl.variables,description="variables")
85-
wait_for_list_size(rest_manager=gl.users,description="users",max_length=1)
119+
120+
defshould_delete_user(user):
121+
ifuser.username=="root":
122+
returnFalse
123+
returnTrue
124+
125+
wait_for_list_size(
126+
rest_manager=gl.users,
127+
description="users",
128+
max_length=1,
129+
should_delete_func=should_delete_user,
130+
delete_kwargs={"hard_delete":True},
131+
)
86132

87133

88134
defset_token(container,fixture_dir):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp