-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Suppress most cli errors, but still warn if we get too many (#416)
* Suppress most cli errors, but still warn if we get too many * Add a config option for setting the error threshold * Add some clarification about config resolution order * Fix typo in docs/reference/cli-config.rst Co-authored-by: tang-mm <3333407+tang-mm@users.noreply.github.com> * Workaround strange pylint issue on github --------- Co-authored-by: tang-mm <3333407+tang-mm@users.noreply.github.com>
- Loading branch information
Showing
6 changed files
with
132 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Copyright (C) 2024 Canonical | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
|
||
""" | ||
Unit tests for the Client class | ||
""" | ||
|
||
import logging | ||
import pytest | ||
import requests | ||
|
||
from testflinger_cli.client import Client | ||
|
||
|
||
def test_get_error_threshold(caplog, requests_mock): | ||
"""Test that a warning is logged when error_threshold is reached""" | ||
caplog.set_level(logging.WARNING) | ||
requests_mock.get( | ||
"http://testflinger/test", exc=requests.exceptions.ConnectionError | ||
) | ||
client = Client("http://testflinger", error_threshold=3) | ||
for _ in range(2): | ||
with pytest.raises(requests.exceptions.ConnectionError): | ||
client.get("test") | ||
assert ( | ||
"Error communicating with the server for the past" | ||
not in caplog.text | ||
) | ||
with pytest.raises(requests.exceptions.ConnectionError): | ||
client.get("test") | ||
assert ( | ||
"Error communicating with the server for the past 3 requests" | ||
in caplog.text | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
Command Line Interface Configuration | ||
==================================== | ||
|
||
The Testflinger CLI can be configured on the command line using the parameters described in ``testflinger --help``. However, sometimes it also supports using environment variables, or reading values from a configuration file. This can be helpful for CI/CD environments, or for setting up a config with different default values read from a config file. | ||
|
||
The configuration file is read from ``$XDG_CONFIG_HOME/testflinger-cli.conf`` by default, but this can be overridden with the ``--configfile`` parameter. | ||
|
||
When a configuration variable is defined in multiple locations, Testflinger resolves the value by applying the following priority order, from highest to lowest: | ||
|
||
1. command-line parameter (for example, ``--server <local_server>``) | ||
|
||
2. configuration file | ||
|
||
3. environment variable | ||
|
||
You can show the current values stored in the config file by running ``testflinger config``. If no value is found on the command line, config file, or environment variable, then a safe default value will be used. | ||
|
||
To set a configuration value in the config file, you can edit it directly or use ``testflinger config key=value``. | ||
|
||
Testflinger Config Variables | ||
---------------------------- | ||
|
||
The following config values are currently supported: | ||
|
||
* server - Testflinger Server URL to use | ||
|
||
* Config file key: ``server`` | ||
* Environment variable: ``TESTFLINGER_SERVER`` | ||
* Default: ``https://testflinger.canonical.com`` | ||
|
||
* error_threshold - warn the user of possible server/network problems after failing to read from the server after this many consecutive attempts | ||
|
||
* Config file key: ``error_threshold`` | ||
* Environment variable: ``TESTFLINGER_ERROR_THRESHOLD`` | ||
* Default: ``3`` | ||
|
||
* client_id - Client ID to use for APIs that require authorisation | ||
|
||
* Config file key: ``client_id`` | ||
* Environment variable: ``TESTFLINGER_CLIENT_ID`` | ||
* Default: ``None`` | ||
|
||
* secret_key - Secret key to use for APIs that require authorisation | ||
|
||
* Config file key: ``secret_key`` | ||
* Environment variable: ``TESTFLINGER_SECRET_KEY`` | ||
* Default: ``None`` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters