The module implements methods needed to run DTS. It handles the creation
of objects and eventually the whole DTS workflow, such as running node
setups, test gathering, setup and execution and various cleanups.

Signed-off-by: Owen Hilyard <ohily...@iol.unh.edu>
Signed-off-by: Juraj Linkeš <juraj.lin...@pantheon.tech>
---
 dts/framework/dts.py      | 70 +++++++++++++++++++++++++++++++++++++++
 dts/framework/settings.py | 11 ++++++
 dts/framework/utils.py    | 19 +++++++++++
 3 files changed, 100 insertions(+)
 create mode 100644 dts/framework/dts.py

diff --git a/dts/framework/dts.py b/dts/framework/dts.py
new file mode 100644
index 0000000000..1938ea6af8
--- /dev/null
+++ b/dts/framework/dts.py
@@ -0,0 +1,70 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2010-2019 Intel Corporation
+# Copyright(c) 2022 PANTHEON.tech s.r.o.
+# Copyright(c) 2022 University of New Hampshire
+#
+
+import sys
+from typing import Iterable, Optional
+
+import framework.logger as logger
+
+from .config import CONFIGURATION
+from .logger import getLogger
+from .node import Node
+from .settings import SETTINGS
+from .utils import check_dts_python_version
+
+log_handler: Optional[logger.DTSLOG] = None
+
+
+def run_all() -> None:
+    """
+    Main process of DTS, it will run all test suites in the config file.
+    """
+
+    global log_handler
+
+    # check the python version of the server that run dts
+    check_dts_python_version()
+
+    # init log_handler handler
+    if SETTINGS.verbose is True:
+        logger.set_verbose()
+
+    log_handler = getLogger("dts")
+
+    nodes = {}
+    # This try/finally block means "Run the try block, if there is an 
exception,
+    # run the finally block before passing it upward. If there is not an 
exception,
+    # run the finally block after the try block is finished." This helps avoid 
the
+    # problem of python's interpreter exit context, which essentially prevents 
you
+    # from making certain system calls. This makes cleaning up resources 
difficult,
+    # since most of the resources in DTS are network-based, which is 
restricted.
+    #
+    # An except block SHOULD NOT be added to this. A failure at this level 
should
+    # deliver a full stack trace for debugging, since the only place that 
exceptions
+    # should be caught and handled is in the testing code.
+    try:
+        # for all Execution sections
+        for execution in CONFIGURATION.executions:
+            sut_config = execution.system_under_test
+            if sut_config.name not in nodes:
+                nodes[sut_config.name] = Node(sut_config)
+
+    finally:
+        quit_execution(nodes.values())
+
+
+def quit_execution(sut_nodes: Iterable[Node]) -> None:
+    """
+    Close session to SUT and TG before quit.
+    Return exit status when failure occurred.
+    """
+    for sut_node in sut_nodes:
+        # close all session
+        sut_node.node_exit()
+
+    if log_handler is not None:
+        log_handler.info("DTS ended")
+    sys.exit(0)
diff --git a/dts/framework/settings.py b/dts/framework/settings.py
index 07952b9f9e..c9621d4e3d 100644
--- a/dts/framework/settings.py
+++ b/dts/framework/settings.py
@@ -41,6 +41,7 @@ def wrapper(**kwargs) -> _EnvironmentArgument:
 class _Settings:
     config_file_path: str
     timeout: float
+    verbose: bool
 
 
 def _get_parser() -> argparse.ArgumentParser:
@@ -62,6 +63,15 @@ def _get_parser() -> argparse.ArgumentParser:
         help="[DTS_TIMEOUT] The default timeout for all DTS operations except 
for compiling DPDK.",
     )
 
+    parser.add_argument(
+        "-v",
+        "--verbose",
+        action=_env_arg("DTS_VERBOSE"),
+        default="N",
+        required=False,
+        help="[DTS_VERBOSE] Set to 'Y' to enable verbose output, logging all 
messages to the console.",
+    )
+
     return parser
 
 
@@ -70,6 +80,7 @@ def _get_settings() -> _Settings:
     return _Settings(
         config_file_path=args.config_file,
         timeout=float(args.timeout),
+        verbose=(args.verbose == "Y"),
     )
 
 
diff --git a/dts/framework/utils.py b/dts/framework/utils.py
index db87349827..2a174831d0 100644
--- a/dts/framework/utils.py
+++ b/dts/framework/utils.py
@@ -4,9 +4,28 @@
 # Copyright(c) 2022 University of New Hampshire
 #
 
+import sys
+
+
 def RED(text: str) -> str:
     return f"\u001B[31;1m{str(text)}\u001B[0m"
 
 
 def GREEN(text: str) -> str:
     return f"\u001B[32;1m{str(text)}\u001B[0m"
+
+
+def check_dts_python_version() -> None:
+    if sys.version_info.major < 3 or (
+        sys.version_info.major == 3 and sys.version_info.minor < 10
+    ):
+        print(
+            RED(
+                (
+                    "WARNING: DTS execution node's python version is lower 
than"
+                    "python 3.10, is deprecated and will not work in future 
releases."
+                )
+            ),
+            file=sys.stderr,
+        )
+        print(RED("Please use Python >= 3.10 instead"), file=sys.stderr)
-- 
2.30.2

Reply via email to