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

Commit26f4944

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 parent8677cf4 commit26f4944

File tree

1 file changed

+48
-4
lines changed

1 file changed

+48
-4
lines changed

‎tests/functional/conftest.py‎

Lines changed: 48 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"Mark for deletion project:{project.name!r}")
2636
fordeploy_tokeninproject.deploytokens.list():
@@ -47,13 +57,24 @@ def reset_gitlab(gl):
4757
logging.info(f"Mark for deletion user:{user.username!r}")
4858
user.delete(hard_delete=True)
4959

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

5269
# Ensure everything has been reset
5370
start_time=time.perf_counter()
5471

5572
defwait_for_maximum_list_length(
56-
rest_manager:gitlab.base.RESTManager,description:str,max_length:int=0
73+
rest_manager:gitlab.base.RESTManager,
74+
description:str,
75+
max_length:int=0,
76+
should_delete_func=lambdax:True,
77+
delete_kwargs={},
5778
)->None:
5879
"""Wait for the list() length to be no greater than expected maximum or fail
5980
test if timeout is exceeded"""
@@ -66,6 +87,19 @@ def wait_for_maximum_list_length(
6687
f"Iteration:{count} Waiting for{description!r} items to be deleted: "
6788
f"{[x.nameforxinitems]}"
6889
)
90+
foriteminitems:
91+
ifshould_delete_func(item):
92+
logging.info(
93+
f"Marking{description!r} item again for deletion: "
94+
f"{item.name!r}"
95+
)
96+
try:
97+
item.delete(**delete_kwargs)
98+
exceptgitlab.exceptions.GitlabDeleteErrorasexc:
99+
logging.info(
100+
f"{description!r} item already marked for deletion: "
101+
f"{item.name!r}{exc}"
102+
)
69103
time.sleep(SLEEP_INTERVAL)
70104

71105
items=rest_manager.list()
@@ -83,8 +117,18 @@ def wait_for_maximum_list_length(
83117
wait_for_maximum_list_length(rest_manager=gl.projects,description="projects")
84118
wait_for_maximum_list_length(rest_manager=gl.groups,description="groups")
85119
wait_for_maximum_list_length(rest_manager=gl.variables,description="variables")
120+
121+
defshould_delete_user(user):
122+
ifuser.username=="root":
123+
returnFalse
124+
returnTrue
125+
86126
wait_for_maximum_list_length(
87-
rest_manager=gl.users,description="users",max_length=1
127+
rest_manager=gl.users,
128+
description="users",
129+
max_length=1,
130+
should_delete_func=should_delete_user,
131+
delete_kwargs={"hard_delete":True},
88132
)
89133

90134

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp