diff --git a/net_orc/network/devices/faux-dev/bin/start_network_service b/net_orc/network/devices/faux-dev/bin/start_network_service index b727d2091..13e2f6baf 100644 --- a/net_orc/network/devices/faux-dev/bin/start_network_service +++ b/net_orc/network/devices/faux-dev/bin/start_network_service @@ -22,12 +22,12 @@ else fi #Create and set permissions on the output files -LOG_FILE=/runtime/validation/$MODULE_NAME.log -RESULT_FILE=/runtime/validation/result.json +OUTPUT_DIR=/runtime/validation/ +LOG_FILE=$OUTPUT_DIR/$MODULE_NAME.log +RESULT_FILE=$OUTPUT_DIR/result.json touch $LOG_FILE touch $RESULT_FILE -chown $HOST_USER:$HOST_USER $LOG_FILE -chown $HOST_USER:$HOST_USER $RESULT_FILE +chown -R $HOST_USER:$HOST_USER $OUTPUT_DIR # Start dhclient $BIN_DIR/start_dhcp_client $INTF diff --git a/net_orc/python/src/network_orchestrator.py b/net_orc/python/src/network_orchestrator.py index 77af509f2..f53b17d15 100644 --- a/net_orc/python/src/network_orchestrator.py +++ b/net_orc/python/src/network_orchestrator.py @@ -94,6 +94,9 @@ def start(self): """Start the network orchestrator.""" LOGGER.debug('Starting network orchestrator') + + self._host_user = self._get_host_user() + # Get all components ready self.load_network_modules() @@ -174,10 +177,12 @@ def _device_discovered(self, mac_addr): LOGGER.debug( f'Discovered device {mac_addr}. Waiting for device to obtain IP') device = self._get_device(mac_addr=mac_addr) - os.makedirs( - os.path.join(RUNTIME_DIR, + + device_runtime_dir = os.path.join(RUNTIME_DIR, TEST_DIR, - device.mac_addr.replace(':', ''))) + device.mac_addr.replace(':', '')) + os.makedirs(device_runtime_dir) + util.run_command(f'chown -R {self._host_user}:{self._host_user} {device_runtime_dir}') packet_capture = sniff(iface=self._dev_intf, timeout=self._startup_timeout, @@ -469,7 +474,7 @@ def _start_network_service(self, net_module): privileged=True, detach=True, mounts=net_module.mounts, - environment={'HOST_USER': self._get_host_user()}) + environment={'HOST_USER': self._host_user}) except docker.errors.ContainerError as error: LOGGER.error('Container run error') LOGGER.error(error) diff --git a/net_orc/python/src/network_validator.py b/net_orc/python/src/network_validator.py index 4a3a2a080..832a154e3 100644 --- a/net_orc/python/src/network_validator.py +++ b/net_orc/python/src/network_validator.py @@ -48,6 +48,12 @@ def __init__(self): def start(self): """Start the network validator.""" LOGGER.debug('Starting validator') + + # Setup the output directory + host_user = self._get_host_user() + os.makedirs(OUTPUT_DIR, exist_ok=True) + util.run_command(f'chown -R {host_user}:{host_user} {OUTPUT_DIR}') + self._load_devices() self._build_network_devices() self._start_network_devices() diff --git a/test_orc/modules/base/bin/start_module b/test_orc/modules/base/bin/start_module index 6adc53f58..c179668ba 100644 --- a/test_orc/modules/base/bin/start_module +++ b/test_orc/modules/base/bin/start_module @@ -1,5 +1,8 @@ #!/bin/bash +# Define the local mount point to store local files to +OUTPUT_DIR="/runtime/output" + # Directory where all binaries will be loaded BIN_DIR="/testrun/bin" @@ -11,6 +14,9 @@ IFACE=veth0 # HOST_USER mapped in via docker container environemnt variables useradd $HOST_USER +# Set permissions on the output files +chown -R $HOST_USER:$HOST_USER $OUTPUT_DIR + # Enable IPv6 for all containers sysctl net.ipv6.conf.all.disable_ipv6=0 sysctl -p diff --git a/test_orc/modules/dns/python/src/run.py b/test_orc/modules/dns/python/src/run.py index 2b924bbaf..4803f63cd 100644 --- a/test_orc/modules/dns/python/src/run.py +++ b/test_orc/modules/dns/python/src/run.py @@ -20,7 +20,7 @@ from dns_module import DNSModule -LOG_NAME = "dns_module" +LOG_NAME = "dns_runner" LOGGER = logger.get_logger(LOG_NAME) RUNTIME = 1500 @@ -35,12 +35,12 @@ def __init__(self, module): signal.signal(signal.SIGQUIT, self._handler) self.add_logger(module) - LOGGER.info("Starting DNS Test Module") + LOGGER.info("Starting DNS test module") self._test_module = DNSModule(module) self._test_module.run_tests() - LOGGER.info("DNS Test Module Finished") + LOGGER.info("DNS test module finished") def add_logger(self, module): global LOGGER @@ -57,7 +57,7 @@ def _handler(self, signum): def run(): parser = argparse.ArgumentParser( - description="Test Module DNS", + description="DNS Module Help", formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument( diff --git a/test_orc/modules/nmap/python/src/run.py b/test_orc/modules/nmap/python/src/run.py index ecb6cd028..5e33451d9 100644 --- a/test_orc/modules/nmap/python/src/run.py +++ b/test_orc/modules/nmap/python/src/run.py @@ -20,8 +20,8 @@ from nmap_module import NmapModule -LOGGER = logger.get_logger('test_module') - +LOG_NAME = "nmap_runner" +LOGGER = logger.get_logger(LOG_NAME) class NmapModuleRunner: """Run the NMAP module tests.""" @@ -32,12 +32,19 @@ def __init__(self, module): signal.signal(signal.SIGTERM, self._handler) signal.signal(signal.SIGABRT, self._handler) signal.signal(signal.SIGQUIT, self._handler) + self.add_logger(module) - LOGGER.info('Starting nmap Module') + LOGGER.info('Starting nmap module') self._test_module = NmapModule(module) self._test_module.run_tests() + LOGGER.info("nmap test module finished") + + def add_logger(self, module): + global LOGGER + LOGGER = logger.get_logger(LOG_NAME, module) + def _handler(self, signum): LOGGER.debug('SigtermEnum: ' + str(signal.SIGTERM)) LOGGER.debug('Exit signal received: ' + str(signum)) diff --git a/test_orc/python/src/test_orchestrator.py b/test_orc/python/src/test_orchestrator.py index b8b7a3af2..9f0f100ab 100644 --- a/test_orc/python/src/test_orchestrator.py +++ b/test_orc/python/src/test_orchestrator.py @@ -22,10 +22,11 @@ from docker.types import Mount import logger from module import TestModule +import util LOG_NAME = "test_orc" LOGGER = logger.get_logger("test_orc") -RUNTIME_DIR = "runtime" +RUNTIME_DIR = "runtime/test" TEST_MODULES_DIR = "modules" MODULE_CONFIG = "conf/module_config.json" @@ -47,10 +48,15 @@ def __init__(self, net_orc): shutil.rmtree(os.path.join(self._root_path, RUNTIME_DIR), ignore_errors=True) - os.makedirs(os.path.join(self._root_path, RUNTIME_DIR), exist_ok=True) def start(self): LOGGER.debug("Starting test orchestrator") + + # Setup the output directory + self._host_user = self._get_host_user() + os.makedirs(RUNTIME_DIR, exist_ok=True) + util.run_command(f'chown -R {self._host_user}:{self._host_user} {RUNTIME_DIR}') + self._load_test_modules() self.build_test_modules() @@ -101,6 +107,7 @@ def _generate_results(self, device): "runtime/test/" + device.mac_addr.replace(":", "") + "/results.json") with open(out_file, "w", encoding="utf-8") as f: json.dump(results, f, indent=2) + util.run_command(f'chown -R {self._host_user}:{self._host_user} {out_file}') return results def test_in_progress(self): @@ -136,11 +143,12 @@ def _run_test_module(self, module, device): device_startup_capture = os.path.join( self._root_path, "runtime/test/" + device.mac_addr.replace(":", "") + "/startup.pcap") + util.run_command(f'chown -R {self._host_user}:{self._host_user} {device_startup_capture}') device_monitor_capture = os.path.join( self._root_path, "runtime/test/" + device.mac_addr.replace(":", "") + "/monitor.pcap") - + util.run_command(f'chown -R {self._host_user}:{self._host_user} {device_monitor_capture}') client = docker.from_env() @@ -170,7 +178,7 @@ def _run_test_module(self, module, device): read_only=True), ], environment={ - "HOST_USER": self._get_host_user(), + "HOST_USER": self._host_user, "DEVICE_MAC": device.mac_addr, "DEVICE_TEST_MODULES": device.test_modules, "IPV4_SUBNET": self._net_orc.network_config.ipv4_network,