Skip to content

Commit 3503e5c

Browse files
committed
Do not fail if querying for a server throws an error in the API
Unfortunately, some serves stay in the DB with wrong metadata (probably old servers, with some information that was not correctly migrated, and they throw an error when requesting their information. If this happens, there are no records being generated for the rest of the period, since we did not catch the exception. This change fixes this.
1 parent 796c50e commit 3503e5c

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

caso/extract/nova.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,17 @@ def extract_for_project(self, project, extract_from, extract_to):
243243
for usage in usages:
244244
# 4.1 and 4.2 Get the server if it is not yet there
245245
if usage["instance_id"] not in records:
246-
server = nova.servers.get(usage["instance_id"])
246+
try:
247+
server = nova.servers.get(usage["instance_id"])
248+
except novaclient.exceptions.ClientException as e:
249+
LOG.error("Cannot get server '%s' from the Nova API, "
250+
"probably because it is an old VM that whose "
251+
"metadata is wrong in the DB. There will be no "
252+
"record generated for this VM. " %
253+
usage["instance_id"])
254+
LOG.exception(e)
255+
256+
continue
247257

248258
server_start = self._get_server_start(server)
249259
if server_start > extract_to:

0 commit comments

Comments
 (0)