Removed module test stubs, added command line option to specify config file location

parent 84e12b88
......@@ -6,7 +6,6 @@ import sys
import signal
from colorlog import error, info
from importlib import import_module
from yangson.enumerations import ContentType, ValidationScope
from . import usr_op_handlers, usr_state_data_handlers
from .rest_server import RestServer
......@@ -26,9 +25,23 @@ from .usr_conf_data_handlers import (
def main():
config_file = "jetconf/config.yaml"
# Parse command line arguments
try:
opts, args = getopt.getopt(sys.argv[1:], "c:")
except getopt.GetoptError:
print("Invalid argument detected. Possibles are: -c (config file)")
sys.exit(1)
for opt, arg in opts:
if opt == '-c':
config_file = arg
# Load configuration
load_config("jetconf/config.yaml")
load_config(config_file)
# Set logging level
log_level = {
"error": logging.ERROR,
"warning": logging.WARNING,
......@@ -150,25 +163,4 @@ def main():
if __name__ == "__main__":
opts, args = (None, None)
test_module = None
try:
opts, args = getopt.getopt(sys.argv[1:], "t:")
except getopt.GetoptError:
print("Invalid argument detected. Possibles are: -t (test module)")
exit()
for opt, arg in opts:
if opt == '-t':
test_module = arg
if test_module is not None:
try:
tm = import_module("." + test_module, "jetconf")
tm.test()
except ImportError as e:
print(e.msg)
else:
main()
main()
\ No newline at end of file
......@@ -684,7 +684,3 @@ class JsonDatastore(BaseDatastore):
def save(self):
with open(self.json_file, "w") as jfd:
json.dump(self._data.raw_value(), jfd, indent=4)
def test():
error("Tests moved to tests/tests_jetconf.py")
from datetime import datetime
from enum import Enum
from typing import Dict, List, Any
from hashlib import sha1
from jetconf.yang_json_path import BasePath
class YangNodeType(Enum):
UNKNOWN = 0
CONTAINER = 1
LIST = 2
LEAF_LIST = 3
LEAF = 4
ANYDATA = 5
ANYXML = 6
class YangDataType(Enum):
UNKNOWN = 0
STRING = 1
BOOLEAN = 2
ENUM = 2
BITS = 3
BINARY = 4
LEAFREF = 5
IDENTITYREF = 6
EMPTY = 7
UNION = 8
INSTANCE_ID = 9
INT8 = 10
INT16 = 11
INT32 = 12
INT64 = 13
UINT8 = 14
UINT16 = 15
UINT32 = 16
UINT64 = 17
class JsonDoc:
def __init__(self):
self.root = None # type: JsonNodeObject
self.root_prefix_path = None # type: BasePath
class JsonNode:
def __init__(self):
self.parent = None # type: JsonNode
self.last_modified = None # type: datetime
self.etag = None # type: str
self.yang_node_type = None # type: YangNodeType
def _update_etag(self):
self.last_modified = datetime.now()
etag_data = str(id(self)) + str(self.last_modified)
sha_obj = sha1()
sha_obj.update(etag_data.encode())
self.etag = sha_obj.hexdigest()
class JsonNodeList(JsonNode):
def __init__(self):
super().__init__()
self.children = [] # type: List[JsonNode]
def append(self, item: JsonNode):
self.children.append(item)
self._update_etag()
def pop(self, i: int) -> JsonNode:
n = self.children.pop(i)
self._update_etag()
return n
class JsonNodeObject(JsonNode):
def __init__(self):
super().__init__()
self.children = {} # type: Dict[JsonNode]
def add_child(self, key: str, val: JsonNode):
self.children[key] = val
self._update_etag()
def remove_child(self, key: str):
try:
del self.children[key]
self._update_etag()
except KeyError:
pass
class JsonNodeLeaf(JsonNode):
def __init__(self):
super().__init__()
self.yang_leaf_type = None # type: YangDataType
self._value = None # type: str, numeric or bool
def set_value(self, val: Any):
self._value = val
self._update_etag()
def get_value(self) -> Any:
return self._value
......@@ -395,7 +395,3 @@ class UserNacm:
return rpc_rule.action
return self.default_exec
def test():
error("Tests moved to tests/tests_jetconf.py")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment