Skip to contentSkip to conversation

tests/functional: more asset download robustness fixes

PATCH In review Daniel P. Berrangé 2 participants 5 messages Sep 18, 2025

lore
Share & tools
lore
#0 lore raw

cover tests/functional: more asset download robustness fixes

Daniel P. Berrangé (2):
tests/functional: retry when seeing ConnectionError exception tests/functional: treat unknown exceptions as transient faults

 tests/functional/qemu_test/asset.py | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
Signature · 1 line
2.50.1
#1 lore raw

PATCH 1/2 tests/functional: retry when seeing ConnectionError exception

This base class is used for many different socket connection errors, corresponding to ECONNRESET, ECONNREFUSED, ECONNABORTED and more. Most of these are things you might expect to see every now and then as transient flaws. We should thus retry the asset download when seeing them.

---
 tests/functional/qemu_test/asset.py | 7 +++++++
 1 file changed, 7 insertions(+)
tests/functional/qemu_test/asset.py +7 -0
index 2dd32bf28d..f8b87d2153 100644
@@ -179,6 +179,13 @@ def fetch(self):
                                self.url, e.reason)
                 raise AssetError(self, "Unable to download: URL error %s" %
                                  e.reason, transient=True)
+            except ConnectionError as e:
+                # A socket connection failure, such as dropped conn
+                # or refused conn
+                tmp_cache_file.unlink()
+                self.log.error("Unable to download %s: Connection error %s",
+                               self.url, e)
+                continue
             except Exception as e:
                 tmp_cache_file.unlink()
                 raise AssetError(self, "Unable to download: %s" % e)
Signature · 1 line
2.50.1
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] tests/functional: retry when seeing ConnectionError exception

Quoted 19 lines · Daniel P. Berrangé

This base class is used for many different socket connection errors, corresponding to ECONNRESET, ECONNREFUSED, ECONNABORTED and more. Most of these are things you might expect to see every now and then as transient flaws. We should thus retry the asset download when seeing them.

---
  tests/functional/qemu_test/asset.py | 7 +++++++
  1 file changed, 7 insertions(+)
tests/functional/qemu_test/asset.py +0 -0
index 2dd32bf28d..f8b87d2153 100644
@@ -179,6 +179,13 @@ def fetch(self):
                                 self.url, e.reason)
                  raise AssetError(self, "Unable to download: URL error %s" %
                                   e.reason, transient=True)

tests/functional/qemu_test/asset.py def fetch(self): · line 191

Quoted 10 lines
tests/functional/qemu_test/asset.py +7 -0
+            except ConnectionError as e:
+                # A socket connection failure, such as dropped conn
+                # or refused conn
+                tmp_cache_file.unlink()
+                self.log.error("Unable to download %s: Connection error %s",
+                               self.url, e)
+                continue
              except Exception as e:
                  tmp_cache_file.unlink()
                  raise AssetError(self, "Unable to download: %s" % e)
#3 lore raw

PATCH 2/2 tests/functional: treat unknown exceptions as transient faults

In reply to Daniel P. Berrangé

To maximise the robustness of the functional tests we want to treat most asset download failures as non-fatal to the test suite. Instead it should just skip the tests which need that particular asset. The only time aim to make it fatal is for 404 errors which are highly likely to reflect genuine problems to be fixed.

We catch certain exception classes and handle them as transient errors, but unfortunately it is proving difficult to predict what exception classes urlopen() is capable of raising, with new possibilities being discovered.

To provide a fail-safe, treat the generic Exception class as being a transient error too. This may well mask certain genuine bugs, but it is preferrable to prioritize running the test suite to the greatest extent practical.

---
 tests/functional/qemu_test/asset.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tests/functional/qemu_test/asset.py +2 -1
index f8b87d2153..2971a989d1 100644
@@ -188,7 +188,8 @@ def fetch(self):
                 continue
             except Exception as e:
                 tmp_cache_file.unlink()
-                raise AssetError(self, "Unable to download: %s" % e)
+                raise AssetError(self, "Unable to download: %s" % e,
+                                 transient=True)
 
         if not os.path.exists(tmp_cache_file):
             raise AssetError(self, "Download retries exceeded", transient=True)
Signature · 1 line
2.50.1
Reviewed-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] tests/functional: treat unknown exceptions as transient faults

Quoted 26 lines · Daniel P. Berrangé

To maximise the robustness of the functional tests we want to treat most asset download failures as non-fatal to the test suite. Instead it should just skip the tests which need that particular asset. The only time aim to make it fatal is for 404 errors which are highly likely to reflect genuine problems to be fixed.

We catch certain exception classes and handle them as transient errors, but unfortunately it is proving difficult to predict what exception classes urlopen() is capable of raising, with new possibilities being discovered.

To provide a fail-safe, treat the generic Exception class as being a transient error too. This may well mask certain genuine bugs, but it is preferrable to prioritize running the test suite to the greatest extent practical.

---
  tests/functional/qemu_test/asset.py | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
tests/functional/qemu_test/asset.py +0 -0
index f8b87d2153..2971a989d1 100644

tests/functional/qemu_test/asset.py def fetch(self): · line 195

Quoted 9 lines
tests/functional/qemu_test/asset.py +2 -1
@@ -188,7 +188,8 @@ def fetch(self):
                  continue
              except Exception as e:
                  tmp_cache_file.unlink()
-                raise AssetError(self, "Unable to download: %s" % e)
+                raise AssetError(self, "Unable to download: %s" % e,
+                                 transient=True)
 
          if not os.path.exists(tmp_cache_file):
              raise AssetError(self, "Download retries exceeded", transient=True)