Skip to content

Commit

Permalink
Merge branch 'main' into improve-documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicoretti authored Feb 22, 2024
2 parents a7e4418 + ed82c5e commit 80fa543
Show file tree
Hide file tree
Showing 7 changed files with 832 additions and 637 deletions.
4 changes: 3 additions & 1 deletion doc/changes/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Changes

* [2.1.0](changes_2.1.0.md)
* [2.0.0](changes_2.0.0.md)
* [1.7.1](changes_1.7.1.md)
* [1.7.0](changes_1.7.0.md)
Expand Down Expand Up @@ -29,6 +30,7 @@
---
hidden:
---
changes_2.1.0
changes_2.0.0
changes_1.7.1
changes_1.7.0
Expand All @@ -52,4 +54,4 @@ changes_0.3.1
changes_0.3.0
changes_0.2.0
changes_0.1.0
```
```
19 changes: 19 additions & 0 deletions doc/changes/changes_2.1.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Integration-Test-Docker-Environment 2.1.0, released 2024-02-22

## Summary

This release addresses dependencies updates and dependency issues.

### Supported Exasol Versions

* **7.1**: up to 7.1.17
* **8**: 8.18.1

## Dependencies

* Constrain docker dependency to `>= 4.0.0, < 7.0.0`, for further details see [docker/docker-py#3223](https://github.com/docker/docker-py/issues/3223)

## Internal

* #184: Streamlined error messages
* Added exasol-error-reporting library
47 changes: 27 additions & 20 deletions exasol_integration_test_docker_environment/doctor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,54 @@
package and also provide help to find potential fixes.
"""
import sys
from typing import Iterable
from exasol import error
from enum import Enum
from typing import Iterator

import docker
from docker.errors import DockerException

SUPPORTED_PLATFORMS = ["linux", "darwin"]


class ErrorCodes(Enum):
"""The equivalent of ICD-10 codes this doctor is using"""
class Error(Enum):
Unknown = error.ExaError(
"E-ITDE-0",
"Unknown issue.",
["An unknown error occurred, please contact the maintainer."],
{}
)

Unknown = "Unknown issue"
UnixSocketNotAvailable = "Could not find unix socket to connect to"
TargetPlatformNotSupported = "The platform you are running on is not supported."
UnixSocketNotAvailable = error.ExaError(
"E-ITDE-1",
"Could not find unix socket to connect to.",
["Make sure environment variable DOCKER_HOST is configured correctly."],
{}
)

TargetPlatformNotSupported = error.ExaError(
"E-ITDE-2",
"The platform ITDE is running on is not supported.",
["Make sure you are using one of the following platforms: [linux, darwin]."],
{}
)

def recommend_mitigation(error_code) -> str:
"""Get treatment advice based on the error_code"""
return {
ErrorCodes.Unknown: "You are sick but this symptoms are unknown, please contact the maintainer.",
ErrorCodes.UnixSocketNotAvailable: "Make sure your DOCKER_HOST environment variable is configured correctly.",
ErrorCodes.TargetPlatformNotSupported: f"Make sure you are using one of the following platforms: {SUPPORTED_PLATFORMS}.",
}[error_code]


def diagnose_docker_daemon_not_available() -> Iterator[ErrorCodes]:
def diagnose_docker_daemon_not_available() -> Iterable[error.ExaError]:
"""Diagnose reasons why docker deamon is not available"""

def _is_unix_socket_issue(message: str) -> bool:
return "FileNotFoundError(2, 'No such file or directory')" in message

errors = set()
errors = list()
try:
_docker = docker.from_env()
except DockerException as ex:
msg = f"{ex}"
if _is_unix_socket_issue(msg):
errors.add(ErrorCodes.UnixSocketNotAvailable)
errors.append(Error.UnixSocketNotAvailable)
if len(errors) == 0:
errors.add(ErrorCodes.Unknown)
errors.append(Error.Unknown)
return errors


Expand All @@ -65,15 +72,15 @@ def is_supported_platform() -> bool:
return sys.platform in SUPPORTED_PLATFORMS


def health_checkup() -> Iterator[ErrorCodes]:
def health_checkup() -> Iterable[error.ExaError]:
"""
Runs all known examinations
return an iterator of error codes specifying which problems have been identified.
"""
examinations = [
(is_docker_daemon_available, diagnose_docker_daemon_not_available),
(is_supported_platform, lambda: ErrorCodes.TargetPlatformNotSupported),
(is_supported_platform, lambda: Error.TargetPlatformNotSupported),
]
for is_fine, diagnosis in examinations:
if not is_fine():
Expand Down
23 changes: 5 additions & 18 deletions exasol_integration_test_docker_environment/lib/api/health.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from inspect import cleandoc

from exasol_integration_test_docker_environment.doctor import health_checkup, recommend_mitigation
from exasol_integration_test_docker_environment.doctor import health_checkup
from exasol_integration_test_docker_environment.lib.api.api_errors import HealthProblem
from exasol_integration_test_docker_environment.lib.api.common import cli_function

Expand All @@ -17,31 +17,18 @@ def health():
:raises HealthProblem
"""

problems = set(health_checkup())
if not problems:
errors = set(health_checkup())
if not errors:
return

suggestion_template = cleandoc(
"""
* {problem}
Fix: {suggestion}
"""
)
message = cleandoc(
"""
{count} problem(s) have been identified.
{problems}
"""
).format(
count=len(problems),
problems="\n".join(
(
suggestion_template.format(
problem=icd.value, suggestion=recommend_mitigation(icd)
)
for icd in problems
)
),
count=len(errors),
problems="\n".join(f"{error.value}" for error in errors),
)
raise HealthProblem(message)
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from exasol_integration_test_docker_environment.doctor import (
SUPPORTED_PLATFORMS,
ErrorCodes,
Error,
diagnose_docker_daemon_not_available,
is_docker_daemon_available,
is_supported_platform,
Expand Down Expand Up @@ -56,13 +56,13 @@ class DiagnoseDockerDaemonNotAvailable(unittest.TestCase):
"""

def test_non_existing_unix_socket(self):
expected = {ErrorCodes.UnixSocketNotAvailable}
expected = [Error.UnixSocketNotAvailable]
env = {"DOCKER_HOST": "unix:///var/non/existent/path"}
with temporary_env(env):
self.assertEqual(expected, diagnose_docker_daemon_not_available())

def test_unknown_error(self):
expected = {ErrorCodes.Unknown}
expected = [Error.Unknown]
env = {"DOCKER_HOST": "https://foobar"}
with temporary_env(env):
self.assertEqual(expected, diagnose_docker_daemon_not_available())
Expand Down
Loading

0 comments on commit 80fa543

Please sign in to comment.