Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 133 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,135 @@
# Runtime folder
runtime/
venv/
net_orc/
.vscode/
.vscode/

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/
3 changes: 2 additions & 1 deletion cmd/install
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

GIT_URL=https://github.com/auto-iot
NET_ORC_DIR=net_orc
NET_ORC_VERSION="dev"

python3 -m venv venv

Expand All @@ -10,7 +11,7 @@ source venv/bin/activate
pip3 install -r etc/requirements.txt

rm -rf $NET_ORC_DIR
git clone $GIT_URL/network-orchestrator $NET_ORC_DIR
git clone -b $NET_ORC_VERSION $GIT_URL/network-orchestrator $NET_ORC_DIR
chown -R $USER $NET_ORC_DIR

pip3 install -r $NET_ORC_DIR/python/requirements.txt
Expand Down
8 changes: 7 additions & 1 deletion cmd/start
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@ if [[ "$EUID" -ne 0 ]]; then
exit 1
fi

# Ensure that /var/run/netns folder exists
mkdir -p /var/run/netns

# Clear up existing runtime files
rm -rf runtime

# Check if python modules exist. Install if not
[ ! -d "venv" ] && cmd/install

# Activate Python virtual environment
source venv/bin/activate

# TODO: Execute python code
python -u framework/run.py
python -u framework/run.py $@

deactivate
10 changes: 5 additions & 5 deletions conf/system.json.example
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"network": {
"device_intf": "enx123456789123",
"internet_intf": "enx123456789124"
},
"log_level": "INFO"
"network": {
"device_intf": "enx123456789123",
"internet_intf": "enx123456789124"
},
"log_level": "INFO"
}
45 changes: 35 additions & 10 deletions framework/logger.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,48 @@
"""Manages all things logging."""
"""Manages stream and file loggers."""
import json
import logging
import os

LOGGERS = {}
_LOG_FORMAT = "%(asctime)s %(name)-8s %(levelname)-7s %(message)s"
_DATE_FORMAT = '%b %02d %H:%M:%S'
_CONF_DIR="conf"
_CONF_FILE_NAME="system.json"
_DEFAULT_LOG_LEVEL = logging.INFO
_LOG_LEVEL = logging.INFO
_CONF_DIR = "conf"
_CONF_FILE_NAME = "system.json"
_LOG_DIR = "runtime/testing/"

with open(os.path.join(_CONF_DIR, _CONF_FILE_NAME), encoding='utf-8') as config_file:
system_conf_json = json.load(config_file)
log_level_str = system_conf_json['log_level']
log_level = logging.getLevelName(log_level_str)
# Set log level
with open(os.path.join(_CONF_DIR, _CONF_FILE_NAME), encoding='utf-8') as system_conf_file:
system_conf_json = json.load(system_conf_file)
log_level_str = system_conf_json['log_level']

logging.basicConfig(format=_LOG_FORMAT, datefmt=_DATE_FORMAT, level=log_level)
temp_log = logging.getLogger('temp')
try:
temp_log.setLevel(logging.getLevelName(log_level_str))
_LOG_LEVEL = logging.getLevelName(log_level_str)
except ValueError:
print('Invalid log level set in ' + _CONF_DIR + '/' + _CONF_FILE_NAME +
'. Using INFO as log level')
_LOG_LEVEL = _DEFAULT_LOG_LEVEL

def get_logger(name):
"""Returns the logger belonging to the class calling the method."""
log_format = logging.Formatter(fmt=_LOG_FORMAT, datefmt=_DATE_FORMAT)

def add_file_handler(log, log_file):
handler = logging.FileHandler(_LOG_DIR + log_file + ".log")
handler.setFormatter(log_format)
log.addHandler(handler)

def add_stream_handler(log):
handler = logging.StreamHandler()
handler.setFormatter(log_format)
log.addHandler(handler)

def get_logger(name, log_file=None):
if name not in LOGGERS:
LOGGERS[name] = logging.getLogger(name)
LOGGERS[name].setLevel(_LOG_LEVEL)
add_stream_handler(LOGGERS[name])
if log_file is not None:
add_file_handler(LOGGERS[name], log_file)
return LOGGERS[name]
45 changes: 40 additions & 5 deletions framework/run.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,40 @@
"""Starts Test Run."""

from testrun import TestRun

testrun = TestRun()
"""Starts Test Run."""

import argparse
import sys
from testrun import TestRun
import logger

LOGGER = logger.get_logger('runner')

class TestRunner:

def __init__(self, local_net=True):

LOGGER.info('Starting Test Run')

testrun = TestRun(local_net)

testrun.load_config()

testrun.start_network()

testrun.run_tests()

testrun.stop_network()


def run(argv):
parser = argparse.ArgumentParser(description="Test Run",
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("-r", "--remote-net", action="store_false",
help='''Use the network orchestrator from the parent directory instead
of the one downloaded locally from the install script.''')

args, unknown = parser.parse_known_args()

TestRunner(args.remote_net)


if __name__ == "__main__":
run(sys.argv)
Loading