Skip to content

Commit

Permalink
v0.4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
mmguero committed Nov 5, 2024
1 parent 3b5a192 commit 227204c
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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="[email protected]" },
]
Expand Down
3 changes: 2 additions & 1 deletion src/maltest/__init__.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
39 changes: 31 additions & 8 deletions src/maltest/maltest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
import signal
import sys

import importlib.metadata

from maltest.utils import (
MALTEST_PROJECT_NAME,
MalcolmTestCollection,
MalcolmVM,
set_malcolm_vm_info,
Expand Down Expand Up @@ -45,7 +48,7 @@ def main():
),
formatter_class=argparse.RawTextHelpFormatter,
add_help=True,
usage=f'{script_name} <flags> <extra arguments for pytest>',
usage=f'{MALTEST_PROJECT_NAME} <flags> <extra arguments for pytest>',
)
parser.add_argument(
'--verbose',
Expand All @@ -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')
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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
Expand All @@ -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


Expand Down
1 change: 1 addition & 0 deletions src/maltest/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from datetime import datetime, timezone
from requests.auth import HTTPBasicAuth

MALTEST_PROJECT_NAME = "malcolm-test"

ShuttingDown = [False]

Expand Down
2 changes: 1 addition & 1 deletion src/maltest/virter/malcolm-init/01-clone-install.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand Down

0 comments on commit 227204c

Please sign in to comment.