Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion qnapstats/qnap_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def _get_url(self, url, retry_on_error=True, **kwargs):
result = self._execute_get_url(url, **kwargs)
if (self._session_error or result is None) and retry_on_error:
self._debuglog("Error occured, retrying...")
self._get_url(url, False, **kwargs)
return self._get_url(url, False, **kwargs)

return result

Expand Down
13 changes: 13 additions & 0 deletions tests/test-models.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,19 @@ def file_get_contents(directory, file):
return myfile.read()


# A successful retry must return the retried response, not the failed first attempt.
qnap = qnapstats.QNAPStats("localhost", 8080, "admin", "correcthorsebatterystaple")
with patch.object(qnap, "_init_session"), \
patch.object(qnap, "_execute_get_url", side_effect=[None, {"ok": "1"}]) as execute_get_url:
assert qnap._get_url("some/url.cgi") == {"ok": "1"}
assert execute_get_url.call_count == 2

with patch.object(qnap, "_init_session"), \
patch.object(qnap, "_execute_get_url", return_value=None) as execute_get_url:
assert qnap._get_url("some/url.cgi") is None
assert execute_get_url.call_count == 2


# Missing NIC fields must not prevent other interfaces from being returned.
nic_fields = (
"eth_status", "eth_max_speed", "eth_ip", "eth_mask", "eth_mac",
Expand Down
Loading