diff --git a/src/commands/config/config_cli.py b/src/commands/config/config_cli.py index ef627be..03bcac4 100644 --- a/src/commands/config/config_cli.py +++ b/src/commands/config/config_cli.py @@ -78,7 +78,7 @@ class ConfigSet(Command): mongodb.cluster Indicates whether a MongoDB cluster is being used (true/false). - + mongodb.cluster_secret_key This key is uploaded to all nodes within the MongoDB cluster. It is used for mutual authentication between nodes, ensuring that only authorized nodes can communicate with each other. diff --git a/src/commands/das/das_cli.py b/src/commands/das/das_cli.py index 529453c..f4720c8 100644 --- a/src/commands/das/das_cli.py +++ b/src/commands/das/das_cli.py @@ -15,7 +15,7 @@ ) -class PermissionError(Exception): ... +class PermissionError(Exception): ... # noqa: E701 class DasCliUpdateVersion(Command): diff --git a/src/commands/das/das_ubuntu_advanced_packaging_tool.py b/src/commands/das/das_ubuntu_advanced_packaging_tool.py index 7a243e4..10485a0 100644 --- a/src/commands/das/das_ubuntu_advanced_packaging_tool.py +++ b/src/commands/das/das_ubuntu_advanced_packaging_tool.py @@ -3,10 +3,10 @@ from typing import Tuple, Union -class DasError(Exception): ... +class DasError(Exception): ... # noqa: E701 -class DasNotFoundError(DasError): ... +class DasNotFoundError(DasError): ... # noqa: E701 class DasUbuntuAdvancedPackagingTool: diff --git a/src/commands/db/db_cli.py b/src/commands/db/db_cli.py index 07020c7..dbb19bf 100644 --- a/src/commands/db/db_cli.py +++ b/src/commands/db/db_cli.py @@ -61,7 +61,7 @@ def _redis_node(self, context, ip, username): ) def _redis(self): - self.stdout(f"Stopping Redis service...") + self.stdout("Stopping Redis service...") redis_nodes = self._settings.get("redis.nodes", []) @@ -70,7 +70,7 @@ def _redis(self): self._redis_node(**redis_node) except DockerError as e: self.stdout( - f"\nError occurred while trying to stop Redis\n", + "\nError occurred while trying to stop Redis\n", severity=StdoutSeverity.ERROR, ) raise e @@ -93,7 +93,7 @@ def _mongodb_node(self, context, ip, username): ) def _mongodb(self): - self.stdout(f"Stopping MongoDB service...") + self.stdout("Stopping MongoDB service...") mongodb_nodes = self._settings.get("mongodb.nodes", []) @@ -103,7 +103,7 @@ def _mongodb(self): except DockerError as e: self.stdout( - f"\nError occurred while trying to stop MongoDB\n", + "\nError occurred while trying to stop MongoDB\n", severity=StdoutSeverity.ERROR, ) raise e @@ -170,14 +170,14 @@ def _redis_node( f"Redis is already running. It is currently listening on port {redis_port} at {node_ip} under the server user {node_username}.", severity=StdoutSeverity.WARNING, ) - except DockerError as e: + except DockerError: self.stdout( f"\nError occurred while trying to start Redis on port {redis_port} at {node_ip} under the server user {node_username}.\n", severity=StdoutSeverity.ERROR, ) def _redis(self) -> None: - self.stdout(f"Starting Redis service...") + self.stdout("Starting Redis service...") redis_port = self._settings.get("redis.port") redis_nodes = self._settings.get("redis.nodes", []) @@ -191,7 +191,7 @@ def _redis(self) -> None: self._redis_container_manager.start_cluster(redis_nodes, redis_port) except Exception as e: self.stdout( - f"\nFailed to start the cluster. Please check the conectivity between the nodes and try again.\n", + "\nFailed to start the cluster. Please check the conectivity between the nodes and try again.\n", severity=StdoutSeverity.ERROR, ) raise e @@ -246,7 +246,7 @@ def _mongodb_node( raise e def _mongodb(self) -> None: - self.stdout(f"Starting MongoDB service...") + self.stdout("Starting MongoDB service...") mongodb_port = self._settings.get("mongodb.port") mongodb_username = self._settings.get("mongodb.username") @@ -275,7 +275,7 @@ def _mongodb(self) -> None: ) except Exception as e: self.stdout( - f"\nFailed to start the cluster. Please check the conectivity between the nodes and try again.\n", + "\nFailed to start the cluster. Please check the conectivity between the nodes and try again.\n", severity=StdoutSeverity.ERROR, ) raise e @@ -293,7 +293,9 @@ class DbRestart(Command): short_help = "Restart all DBMS containers." help = """ -'das-cli db restart' restarts all database containers previously started with 'das-cli start'. If no database have been started, 'das-cli db restart' just start them. +'das-cli db restart' restarts all database containers previously started with +'das-cli start'. If no database have been started, 'das-cli db restart' just +start them. IMPORTANTE NOTE: Restarting the databases will result in all data being lost. Databases are started empty. @@ -320,7 +322,11 @@ class DbCli(CommandGroup): short_help = "Manage db-related operations." - help = "'das-cli db' commands allow you to manage DAS backend DBMSs for use with the DAS CLI. 'das-cli db' provides commands to start, stop, and restart the databases as needed." + help = """ + 'das-cli db' commands allow you to manage DAS backend DBMSs for use + with the DAS CLI. 'das-cli db' provides commands to start, stop, and + restart the databases as needed. + """ @inject def __init__( diff --git a/src/commands/faas/faas_cli.py b/src/commands/faas/faas_cli.py index f99b9b3..641ae83 100644 --- a/src/commands/faas/faas_cli.py +++ b/src/commands/faas/faas_cli.py @@ -45,7 +45,10 @@ class FaaSStop(Command): short_help = "Stop the running OpenFaaS service.." help = """ -'das-cli faas stop' allows you to stop the execution of the DAS function in OpenFaaS. This is useful for terminating the function's operation when it's no longer needed. After stopping the faas, the function will no longer be available and cannot be used with the DAS. +'das-cli faas stop' allows you to stop the execution of the DAS function in +OpenFaaS. This is useful for terminating the function's operation when it's no +longer needed. After stopping the faas, the function will no longer be +available and cannot be used with the DAS. .SH EXAMPLES @@ -62,7 +65,7 @@ def __init__(self, settings: Settings) -> None: def run(self): self._settings.raise_on_missing_file() - self.stdout(f"Stopping OpenFaaS service...") + self.stdout("Stopping OpenFaaS service...") openfaas_container_name = self._settings.get("openfaas.container_name") @@ -80,12 +83,24 @@ class FaaSStart(Command): short_help = "Start OpenFaaS service." - help = """ -OpenFaaS, an open-source serverless computing platform, makes running functions in containers fast and simple. With this command, you can initialize the DAS remotely through a function in OpenFaaS, which can be run on your server or locally. - -If you've just installed the DAS CLI, the function will be executed using the latest version by default. However, if you want to specify a particular version, you can use the faas update-version command. Versions are available at https://github.com/singnet/das-serverless-functions/releases, or you can choose to leave it as latest, which will always use the latest available version. - -Since the function needs to communicate with databases, you need to run db start to establish this communication. Upon the first execution of the function, it might take a little longer as it needs to fetch the specified version and set everything up for you. Subsequent initializations will be faster unless you change the version, which will require the same process again to set everything up. + help = r""" +OpenFaaS, an open-source serverless computing platform, makes running functions +in containers fast and simple. With this command, you can initialize the DAS +remotely through a function in OpenFaaS, which can be run on your server or +locally. + +If you've just installed the DAS CLI, the function will be executed using the +latest version by default. However, if you want to specify a particular +version, you can use the faas update-version command. Versions are available at +https://github.com/singnet/das-serverless-functions/releases, or you can choose +to leave it as latest, which will always use the latest available version. + +Since the function needs to communicate with databases, you need to run db +start to establish this communication. Upon the first execution of the +function, it might take a little longer as it needs to fetch the specified +version and set everything up for you. Subsequent initializations will be +faster unless you change the version, which will require the same process again +to set everything up. .B Ensure that the following ports are open: @@ -99,7 +114,8 @@ class FaaSStart(Command): .IP \[bu] 2 Port 5000: For the watchdog -After starting the function, you will receive a message on the screen with the function version and the port on which the function is being executed. +After starting the function, you will receive a message on the screen with the +function version and the port on which the function is being executed. .SH EXAMPLES @@ -209,7 +225,12 @@ class FaaSRestart(Command): short_help = "Restart OpenFaaS service." help = """ -'das-cli faas restart' restarts OpenFaaS server container. This is useful when you want to restart the function to apply configuration changes. During this process, there is typically a downtime until the function is running again and deemed healthy. This downtime occurs because the existing instance of the function needs to be stopped, and then a new instance needs to be started with the updated configuration or changes. +'das-cli faas restart' restarts OpenFaaS server container. This is useful when +you want to restart the function to apply configuration changes. During this +process, there is typically a downtime until the function is running again and +deemed healthy. This downtime occurs because the existing instance of the +function needs to be stopped, and then a new instance needs to be started with +the updated configuration or changes. .SH EXAMPLES @@ -235,7 +256,10 @@ class FaaSVersion(Command): short_help = "Get OpenFaaS function version." help = """ -'das-cli faas version' is used to display the current version of the DAS function in OpenFaaS. This command is particularly useful for checking the version of the deployed function, which can be helpful troubleshooting issues, or ensuring compatibility. +'das-cli faas version' is used to display the current version of the DAS +function in OpenFaaS. This command is particularly useful for checking the +version of the deployed function, which can be helpful troubleshooting issues, +or ensuring compatibility. .SH EXAMPLES @@ -275,7 +299,14 @@ class FaaSUpdateVersion(Command): short_help = "Update an OpenFaaS service to a newer version." help = """ -'das-cli update-version' allows you to update the version of your function in OpenFaaS. All available versions can be found at https://github.com/singnet/das-serverless-functions/releases. This command has two optional parameters. When executed without parameters, it will fetch the latest version of the 'query-engine' function and update it on your local server if a newer version is found. You can also specify the function you want to update in OpenFaaS (currently only 'query-engine' is available), and define the version of the function you want to use, as mentioned earlier. +'das-cli update-version' allows you to update the version of your function in +OpenFaaS. All available versions can be found at +https://github.com/singnet/das-serverless-functions/releases. This command has +two optional parameters. When executed without parameters, it will fetch the +latest version of the 'query-engine' function and update it on your local +server if a newer version is found. You can also specify the function you want +to update in OpenFaaS (currently only 'query-engine' is available), and define +the version of the function you want to use, as mentioned earlier. .SH EXAMPLES diff --git a/src/commands/jupyter_notebook/jupyter_notebook_cli.py b/src/commands/jupyter_notebook/jupyter_notebook_cli.py index c96c792..31fccdf 100644 --- a/src/commands/jupyter_notebook/jupyter_notebook_cli.py +++ b/src/commands/jupyter_notebook/jupyter_notebook_cli.py @@ -88,7 +88,7 @@ def __init__(self, settings: Settings) -> None: def run(self): self._settings.raise_on_missing_file() - self.stdout(f"Stopping jupyter notebook...") + self.stdout("Stopping jupyter notebook...") jupyter_notebook_container_name = self._settings.get("jupyter_notebook.container_name") diff --git a/src/commands/python_library/python_library_package.py b/src/commands/python_library/python_library_package.py index 3bfefcb..78906fe 100644 --- a/src/commands/python_library/python_library_package.py +++ b/src/commands/python_library/python_library_package.py @@ -4,10 +4,10 @@ import requests -class PackageError(Exception): ... +class PackageError(Exception): ... # noqa: E701 -class PackageNotFoundError(PackageError): ... +class PackageNotFoundError(PackageError): ... # noqa: E701 class PythonLibraryPackage: @@ -59,7 +59,7 @@ def get_version(self, package_name): raise PackageNotFoundError( f"Version information not found for package '{package_name}'." ) - except subprocess.CalledProcessError as e: + except subprocess.CalledProcessError: raise PackageNotFoundError(f"Package '{package_name}' is not installed.") def update_version(self, package_name, version=None): diff --git a/src/commands/release_notes/release_notes_package.py b/src/commands/release_notes/release_notes_package.py index ab86a35..4c84f96 100644 --- a/src/commands/release_notes/release_notes_package.py +++ b/src/commands/release_notes/release_notes_package.py @@ -7,10 +7,10 @@ from config import RELEASE_NOTES_URL -class ReleaseNoteError(Exception): ... +class ReleaseNoteError(Exception): ... # noqa: E701 -class ReleaseNoteNotFound(ReleaseNoteError): ... +class ReleaseNoteNotFound(ReleaseNoteError): ... # noqa: E701 class Library: diff --git a/src/common/__init__.py b/src/common/__init__.py index 57b45e0..449376a 100644 --- a/src/common/__init__.py +++ b/src/common/__init__.py @@ -11,7 +11,8 @@ from .logger import logger from .module import Module from .network import get_public_ip -from .prompt_types import Choice, FunctionVersion, IntRange, Path, ReachableIpAddress +from .prompt_types import FunctionVersion, ReachableIpAddress +from click import Choice, IntRange, Path from .settings import JsonHandler, Settings from .utils import ( get_rand_token, @@ -20,3 +21,32 @@ is_executable_bin, remove_special_characters, ) + +__all__ = [ + "ssh", + "Command", + "CommandArgument", + "CommandGroup", + "CommandOption", + "StdoutSeverity", + "StdoutType", + "Container", + "ContainerManager", + "ImageManager", + "RemoteContextManager", + "logger", + "Module", + "get_public_ip", + "Choice", + "FunctionVersion", + "IntRange", + "Path", + "ReachableIpAddress", + "JsonHandler", + "Settings", + "get_rand_token", + "get_script_name", + "get_server_username", + "is_executable_bin", + "remove_special_characters", +] diff --git a/src/common/docker/__init__.py b/src/common/docker/__init__.py index 8c8c019..c8437a0 100644 --- a/src/common/docker/__init__.py +++ b/src/common/docker/__init__.py @@ -1,3 +1,5 @@ from .container_manager import Container, ContainerManager from .image_manager import ImageManager from .remote_context_manager import RemoteContextManager + +__all__ = ["Container", "ContainerManager", "ImageManager", "RemoteContextManager"] diff --git a/src/common/docker/container_manager.py b/src/common/docker/container_manager.py index 25a8fd0..930c68c 100644 --- a/src/common/docker/container_manager.py +++ b/src/common/docker/container_manager.py @@ -167,7 +167,8 @@ def stop(self): try: container.kill() - except: + # TODO: better exception handling, for now do not use bare except + except Exception: pass try: diff --git a/src/common/docker/exceptions.py b/src/common/docker/exceptions.py index cba7aa7..f862211 100644 --- a/src/common/docker/exceptions.py +++ b/src/common/docker/exceptions.py @@ -28,12 +28,6 @@ class DockerContainerNotFoundError(DockerError): pass -class DockerImageNotFoundError(DockerError): - """Exception raised when a specified image cannot be found.""" - - pass - - class DockerImageNotFoundError(DockerError): """Exception raised when a specified Docker image cannot be found.""" diff --git a/src/common/logger.py b/src/common/logger.py index 18b0196..68477bc 100644 --- a/src/common/logger.py +++ b/src/common/logger.py @@ -3,7 +3,7 @@ from config.config import LOG_FILE_NAME -class LoggerError(Exception): ... +class LoggerError(Exception): ... # noqa: E701 class Logger: diff --git a/src/common/network.py b/src/common/network.py index 7dae923..4f204c3 100644 --- a/src/common/network.py +++ b/src/common/network.py @@ -8,7 +8,8 @@ def get_public_ip(): try: return requests.get("https://api.ipify.org").content.decode("utf8") - except: + # TODO: better exception handler, for now do not use bare except + except Exception: return None diff --git a/src/common/prompt_types.py b/src/common/prompt_types.py index 97609ad..4c92228 100644 --- a/src/common/prompt_types.py +++ b/src/common/prompt_types.py @@ -1,7 +1,7 @@ import re from typing import Union -from click import Choice, IntRange, ParamType, Path +from click import ParamType from common.network import is_server_port_available diff --git a/src/config/__init__.py b/src/config/__init__.py index 7fd56bc..9251849 100644 --- a/src/config/__init__.py +++ b/src/config/__init__.py @@ -1,2 +1,36 @@ -from .config import * +from .config import ( + VERSION, + RELEASE_NOTES_URL, + USER_DAS_PATH, + LOG_FILE_NAME, + LOG_FILE_DIR, + REDIS_IMAGE_NAME, + REDIS_IMAGE_VERSION, + MONGODB_IMAGE_NAME, + MONGODB_IMAGE_VERSION, + METTA_PARSER_IMAGE_NAME, + METTA_PARSER_IMAGE_VERSION, + OPENFAAS_IMAGE_NAME, + JUPYTER_NOTEBOOK_IMAGE_NAME, + JUPYTER_NOTEBOOK_IMAGE_VERSION, +) from .secrets import Secret + + +__all__ = [ + "VERSION", + "RELEASE_NOTES_URL", + "USER_DAS_PATH", + "LOG_FILE_NAME", + "LOG_FILE_DIR", + "REDIS_IMAGE_NAME", + "REDIS_IMAGE_VERSION", + "MONGODB_IMAGE_NAME", + "MONGODB_IMAGE_VERSION", + "METTA_PARSER_IMAGE_NAME", + "METTA_PARSER_IMAGE_VERSION", + "OPENFAAS_IMAGE_NAME", + "JUPYTER_NOTEBOOK_IMAGE_NAME", + "JUPYTER_NOTEBOOK_IMAGE_VERSION", + "Secret", +]