Skip to content

Commit 358bcf1

Browse files
author
Jean-Philippe Braun
committed
feat: don't raise when error occurs on some project
As it would stop the processing of other projects
1 parent dcea882 commit 358bcf1

File tree

2 files changed

+29
-29
lines changed

2 files changed

+29
-29
lines changed

src/cinder_snapshooter/utils.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616
1717
SPDX-License-Identifier: Apache-2.0
1818
"""
19+
1920
import datetime
2021
import logging
22+
import traceback
2123

2224
from typing import Optional
2325

@@ -168,7 +170,13 @@ def run_on_projects(
168170
trust=g["trust_id"],
169171
)
170172
else:
171-
raise
173+
log.error(
174+
"Error while processing project",
175+
project=g["project_id"],
176+
req=err.request_id,
177+
trust=g["trust_id"],
178+
error=traceback.format_exc(),
179+
)
172180

173181
return return_value
174182

tests/test_utils.py

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
1616
SPDX-License-Identifier: Apache-2.0
1717
"""
18+
1819
import argparse
1920
import logging
2021

@@ -168,31 +169,22 @@ def connect_as(**kwargs):
168169
http_status=return_code,
169170
)
170171

171-
if return_code == 403:
172-
rv = cinder_snapshooter.utils.run_on_projects(
173-
os_client,
174-
process_function,
175-
10,
176-
[],
177-
)
178-
assert rv == []
179-
assert os_client.connect_as.call_args_list == [
180-
mocker.call(project_id=projects[0][1]),
181-
mocker.call(trust_id=projects[1][0]),
182-
]
183-
assert process_function.call_args_list == [
184-
mocker.call(
185-
{"project_id": projects[0][1]},
186-
),
187-
mocker.call(
188-
{"trust_id": projects[1][0]},
189-
),
190-
]
191-
else:
192-
with pytest.raises(keystoneauth1.exceptions.HTTPClientError):
193-
cinder_snapshooter.utils.run_on_projects(
194-
os_client,
195-
process_function,
196-
10,
197-
[],
198-
)
172+
rv = cinder_snapshooter.utils.run_on_projects(
173+
os_client,
174+
process_function,
175+
10,
176+
[],
177+
)
178+
assert rv == []
179+
assert os_client.connect_as.call_args_list == [
180+
mocker.call(project_id=projects[0][1]),
181+
mocker.call(trust_id=projects[1][0]),
182+
]
183+
assert process_function.call_args_list == [
184+
mocker.call(
185+
{"project_id": projects[0][1]},
186+
),
187+
mocker.call(
188+
{"trust_id": projects[1][0]},
189+
),
190+
]

0 commit comments

Comments
 (0)