From 227204cde39de05c40f93599bc940a2406ca8755 Mon Sep 17 00:00:00 2001 From: Seth Grover Date: Tue, 5 Nov 2024 13:28:40 -0700 Subject: [PATCH] v0.4.2 --- pyproject.toml | 2 +- src/maltest/__init__.py | 3 +- src/maltest/maltest.py | 39 +++++++++++++++---- src/maltest/utils.py | 1 + .../virter/malcolm-init/01-clone-install.toml | 2 +- 5 files changed, 36 insertions(+), 11 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 4747722..09c51ed 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "malcolm-test" -version = "0.4.1" +version = "0.4.2" authors = [ { name="Seth Grover", email="mero.mero.guero@gmail.com" }, ] diff --git a/src/maltest/__init__.py b/src/maltest/__init__.py index 49535f7..e4309d4 100644 --- a/src/maltest/__init__.py +++ b/src/maltest/__init__.py @@ -1,7 +1,8 @@ from importlib.metadata import version, PackageNotFoundError +from maltest.utils import MALTEST_PROJECT_NAME try: - __version__ = version("malcolm-test") + __version__ = version(MALTEST_PROJECT_NAME) except PackageNotFoundError: __version__ = None diff --git a/src/maltest/maltest.py b/src/maltest/maltest.py index 52b22ea..c5f889d 100755 --- a/src/maltest/maltest.py +++ b/src/maltest/maltest.py @@ -12,7 +12,10 @@ import signal import sys +import importlib.metadata + from maltest.utils import ( + MALTEST_PROJECT_NAME, MalcolmTestCollection, MalcolmVM, set_malcolm_vm_info, @@ -45,7 +48,7 @@ def main(): ), formatter_class=argparse.RawTextHelpFormatter, add_help=True, - usage=f'{script_name} ', + usage=f'{MALTEST_PROJECT_NAME} ', ) parser.add_argument( '--verbose', @@ -55,15 +58,14 @@ def main(): help='Increase verbosity (e.g., -v, -vv, etc.)', ) parser.add_argument( - '-r', - '--rm', - dest='removeAfterExec', + '--version', + dest='showVersion', type=mmguero.str2bool, nargs='?', metavar="true|false", const=True, default=False, - help="Remove virtual Malcolm instance after execution is complete", + help="Show script version and exit", ) repoArgGroup = parser.add_argument_group('Malcolm Git repo') @@ -226,6 +228,17 @@ def main(): default=True, help=f'Start Malcolm once provisioning is complete (default true)', ) + parser.add_argument( + '-r', + '--rm', + dest='removeAfterExec', + type=mmguero.str2bool, + nargs='?', + metavar="true|false", + const=True, + default=False, + help="Remove virtual Malcolm instance after execution is complete", + ) configArgGroup.add_argument( '--stay-up', dest='stayUp', @@ -268,6 +281,11 @@ def main(): help=f'Run test suite once Malcolm is started', ) + if len(sys.argv) == 1: + mmguero.eprint(f'{MALTEST_PROJECT_NAME} v{importlib.metadata.version(MALTEST_PROJECT_NAME)}') + parser.print_usage(sys.stderr) + sys.exit(1) + try: parser.error = parser.exit args, extraArgs = parser.parse_known_args() @@ -289,10 +307,14 @@ def main(): if args.verbose > logging.DEBUG: sys.tracebacklimit = 0 + if args.showVersion: + mmguero.eprint(f'{MALTEST_PROJECT_NAME} v{importlib.metadata.version(MALTEST_PROJECT_NAME)}') + return 0 + # the whole thing runs on virter, so if we don't have that what are we even doing here err, _ = mmguero.RunProcess(['virter', 'version']) if err != 0: - logging.error(f'{script_name} requires virter, please see https://github.com/LINBIT/virter') + logging.error(f'{MALTEST_PROJECT_NAME} requires virter, please see https://github.com/LINBIT/virter') return 1 # handle sigint and sigterm for graceful shutdown @@ -330,6 +352,7 @@ def main(): ) # for the tests we're about to run, get the set of PCAP files referenced and upload them to Malcolm + pcaps = [] if testSetPreExec.collected: pcaps = testSetPreExec.PCAPsReferenced() logging.debug( @@ -352,7 +375,7 @@ def main(): set_pcap_hash(pcapFile, pcapHash) # wait for all logs to finish being ingested into the system - if not malcolmVm.WaitForLastEventTime(): + if pcaps and (not malcolmVm.WaitForLastEventTime()): logging.warning(f"Malcolm instance never achieved idle state after inserting events") # run the tests @@ -366,7 +389,7 @@ def main(): finally: del malcolmVm - logging.info(f'{script_name} returning {exitCode}') + logging.info(f'{MALTEST_PROJECT_NAME} returning {exitCode}') return exitCode diff --git a/src/maltest/utils.py b/src/maltest/utils.py index b4c8f37..294d95e 100644 --- a/src/maltest/utils.py +++ b/src/maltest/utils.py @@ -21,6 +21,7 @@ from datetime import datetime, timezone from requests.auth import HTTPBasicAuth +MALTEST_PROJECT_NAME = "malcolm-test" ShuttingDown = [False] diff --git a/src/maltest/virter/malcolm-init/01-clone-install.toml b/src/maltest/virter/malcolm-init/01-clone-install.toml index 9a74b7a..1f92e3d 100644 --- a/src/maltest/virter/malcolm-init/01-clone-install.toml +++ b/src/maltest/virter/malcolm-init/01-clone-install.toml @@ -36,7 +36,7 @@ LOGSTASH_WORKERS = "0" LOGSTASH_EXPOSE = "false" OPENSEARCH_EXPOSE = "false" FILEBEAT_TCP_EXPOSE = "false" -SFTP_EXPOSE = "false" +SFTP_EXPOSE = "true" PCAP_PATH = "" ZEEK_PATH = "" SURICATA_PATH = ""