diff options
author | Jose M. Guisado <jguisado@soleta.eu> | 2022-11-17 15:55:42 +0100 |
---|---|---|
committer | Jose M. Guisado <jguisado@soleta.eu> | 2022-11-17 15:55:42 +0100 |
commit | 699a6c242ae0ed31e69559f7684db3f83932a07b (patch) | |
tree | 3ed1c91a8ea780b0076dfbbab8e640ac2b6b079d | |
parent | 94f6793f96e75292bdccf20e58e1769b992f4db2 (diff) |
live: improve error pathsv1.2.3
Fix error paths in live operations which do not
reset the "browser" to the main page (one with the menu).
Add error logging messages when:
* _restartBrowser fails.
* ogChangeRepo fails.
Improve checksum fetch error handling. For example, when an invalid
repository IP is specified.
-rw-r--r-- | src/live/ogOperations.py | 16 | ||||
-rw-r--r-- | src/utils/tiptorrent.py | 11 |
2 files changed, 22 insertions, 5 deletions
diff --git a/src/live/ogOperations.py b/src/live/ogOperations.py index 870ca12..61da45b 100644 --- a/src/live/ogOperations.py +++ b/src/live/ogOperations.py @@ -45,6 +45,7 @@ class OgLiveOperations: proc = subprocess.call(["pkill", "-9", "browser"]) proc = subprocess.Popen(["browser", "-qws", url]) except: + logging.error('Cannot restart browser') raise ValueError('Error: cannot restart browser') def _refresh_payload_disk(self, cxt, part_setup, num_disk): @@ -137,6 +138,7 @@ class OgLiveOperations: def _restore_image_unicast(self, repo, name, devpath, cache=False): if ogChangeRepo(repo).returncode != 0: + self._restartBrowser(self._url) logging.error('ogChangeRepo could not change repository to %s', repo) raise ValueError(f'Error: Cannot change repository to {repo}') logging.debug(f'restore_image_unicast: name => {name}') @@ -151,9 +153,13 @@ class OgLiveOperations: def _restore_image_tiptorrent(self, repo, name, devpath): image_path = f'/opt/opengnsys/cache/opt/opengnsys/images/{name}.img' - if (not os.path.exists(image_path) or - not tip_check_csum(repo, name)): - tip_client_get(repo, name) + try: + if (not os.path.exists(image_path) or + not tip_check_csum(repo, name)): + tip_client_get(repo, name) + except: + self._restartBrowser(self._url) + raise ValueError('Error before restoring image') self._restore_image(image_path, devpath) def _restore_image(self, image_path, devpath): @@ -361,6 +367,7 @@ class OgLiveOperations: self._restartBrowser(self._url_log) if ogChangeRepo(repo).returncode != 0: + self._restartBrowser(self._url) logging.error('ogChangeRepo could not change repository to %s', repo) raise ValueError(f'Error: Cannot change repository to {repo}') @@ -371,6 +378,7 @@ class OgLiveOperations: executable=OG_SHELL) (output, error) = ogRest.proc.communicate() except: + self._restartBrowser(self._url) logging.error('Exception when running software inventory subprocess') raise ValueError('Error: Incorrect command value') @@ -387,6 +395,7 @@ class OgLiveOperations: pa = cxt.partitions[i] if pa is None: + self._restartBrowser(self._url) logging.error('Target partition not found') raise ValueError('Target partition number not found') @@ -425,6 +434,7 @@ class OgLiveOperations: image_info = ogGetImageInfo(image_path) except: + self._restartBrowser(self._url) logging.error('Exception when running "image create" subprocess') raise ValueError('Error: Incorrect command value') diff --git a/src/utils/tiptorrent.py b/src/utils/tiptorrent.py index 25a3ab8..e749d96 100644 --- a/src/utils/tiptorrent.py +++ b/src/utils/tiptorrent.py @@ -21,8 +21,15 @@ def tip_fetch_csum(tip_addr, image_name): """ """ url = f'http://{tip_addr}:9999/{image_name}.img.full.sum' - with urllib.request.urlopen(f'{url}') as resp: - r = resp.readline().rstrip().decode('utf-8') + try: + with urllib.request.urlopen(f'{url}') as resp: + r = resp.readline().rstrip().decode('utf-8') + except urllib.error.URLError as e: + logging.warning('URL error when fetching checksum: {e.reason}') + raise e + except urllib.error.HTTPError as e: + logging.warning(f'HTTP Error when fetching checksum: {e.reason}') + raise e return r |