Fixed bug causing datastore will not unlock

parent 806fe866
......@@ -7,7 +7,7 @@ import signal
from colorlog import error, info
from importlib import import_module
from yangson.enumerations import ContentType
from yangson.enumerations import ContentType, ValidationScope
from . import usr_op_handlers, usr_state_data_handlers
from .rest_server import RestServer
from .config import CONFIG, load_config, print_config
......@@ -119,7 +119,7 @@ def main():
datastore.load()
datastore.load_yl_data("data/yang-library-data.json")
datastore.get_data_root().validate(ContentType.config)
datastore.get_data_root().validate(ValidationScope.all, ContentType.config)
# Register schema listeners
CONF_DATA_HANDLES.register_handler(KnotConfServerListener(datastore, "/dns-server:dns-server/server-options"))
......
......@@ -314,8 +314,7 @@ class BaseDatastore:
else:
root = self._data
n = root.goto(ii)
sch_pth_list = filter(lambda n: isinstance(n, MemberName), ii)
sch_pth_list = filter(lambda isel: isinstance(isel, MemberName), ii)
sch_pth = DataHelpers.ii2str(sch_pth_list)
sn = self.get_schema_node(sch_pth)
state_roots = sn.state_roots()
......@@ -331,7 +330,7 @@ class BaseDatastore:
raise NoHandlerForStateDataError()
self.commit_end_callback()
n = root.goto(ii)
n = root.goto(ii)
try:
with_defs = rpc.qs["with-defaults"][0]
......
......@@ -106,36 +106,43 @@ def _get(ds: BaseDatastore, pth: str, username: str, yl_data: bool=False, stagin
try:
ds.lock_data(username)
n = ds.get_node_rpc(rpc1, yl_data, staging)
ds.unlock_data()
response = json.dumps(n.raw_value(), indent=4)
add_headers = OrderedDict()
add_headers["ETag"] = hash(n.value)
n = None
http_resp = None
try:
lm_time = DateTimeHelpers.to_httpdate_str(n.value.timestamp, CONFIG_GLOBAL["TIMEZONE"])
add_headers["Last-Modified"] = lm_time
except AttributeError:
# Only arrays and objects have last_modified attribute
pass
n = ds.get_node_rpc(rpc1, yl_data, staging)
except NacmForbiddenError as e:
warn(epretty(e))
http_resp = HttpResponse.empty(HttpStatus.Forbidden)
except (NonexistentSchemaNode, NonexistentInstance) as e:
warn(epretty(e))
http_resp = HttpResponse.empty(HttpStatus.NotFound)
except InstanceValueError as e:
warn(epretty(e))
http_resp = HttpResponse.empty(HttpStatus.BadRequest)
except KnotError as e:
error(epretty(e))
http_resp = HttpResponse.empty(HttpStatus.InternalServerError)
finally:
ds.unlock_data()
if n is not None:
response = json.dumps(n.raw_value(), indent=4)
add_headers = OrderedDict()
add_headers["ETag"] = hash(n.value)
try:
lm_time = DateTimeHelpers.to_httpdate_str(n.value.timestamp, CONFIG_GLOBAL["TIMEZONE"])
add_headers["Last-Modified"] = lm_time
except AttributeError:
# Only arrays and objects have last_modified attribute
pass
http_resp = HttpResponse(HttpStatus.Ok, response.encode(), CT_YANG_JSON, extra_headers=add_headers)
http_resp = HttpResponse(HttpStatus.Ok, response.encode(), CT_YANG_JSON, extra_headers=add_headers)
except DataLockError as e:
warn(epretty(e))
http_resp = HttpResponse.empty(HttpStatus.InternalServerError)
except NacmForbiddenError as e:
warn(epretty(e))
http_resp = HttpResponse.empty(HttpStatus.Forbidden)
except (NonexistentSchemaNode, NonexistentInstance) as e:
warn(epretty(e))
http_resp = HttpResponse.empty(HttpStatus.NotFound)
except InstanceValueError as e:
warn(epretty(e))
http_resp = HttpResponse.empty(HttpStatus.BadRequest)
except KnotError as e:
error(epretty(e))
http_resp = HttpResponse.empty(HttpStatus.InternalServerError)
return http_resp
......
from colorlog import error
from datetime import datetime
from typing import Dict, Any, List, Union
from yangson.datamodel import DataModel
from yangson.instance import InstanceRoute, InstanceNode, Value, EntryKeys, NonexistentInstance
from yangson.instance import InstanceRoute, InstanceNode, EntryKeys, NonexistentInstance
from jetconf.knot_api import KnotInternalError
from .libknot.control import KnotCtl
......@@ -115,18 +116,21 @@ class ZoneStateHandler(StateNodeHandlerBase):
zones_list = []
for zone_name, zone_status in resp.items():
zone_name = zone_name.rstrip(".")
zone_obj = {
"domain": zone_name,
"class": "IN",
"serial": int(zone_status.get("serial")),
"server-role": zone_status.get("type")
}
for m, h in self.member_handlers.items():
zone_obj[m] = h.update_node(node_ii + [EntryKeys({"domain": zone_name})], data_root, False)
zones_list.append(zone_obj)
try:
zone_name = zone_name.rstrip(".")
zone_obj = {
"domain": zone_name,
"class": "IN",
"serial": int(zone_status.get("serial")),
"server-role": zone_status.get("type")
}
for m, h in self.member_handlers.items():
zone_obj[m] = h.update_node(node_ii + [EntryKeys({"domain": zone_name})], data_root, False)
zones_list.append(zone_obj)
except ValueError:
error("Error parsing Knot zone status data")
if with_container:
retval = self.gen_container(node_ii[0:2], zones_list)
......
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