Skip to content

Commit

Permalink
configd: T7119: fix misleading debug messages
Browse files Browse the repository at this point in the history
An artifact of T6899 included a report of 'error_code 1' on success: for
consistency with shim error codes 1 == SUCCESS, however, the debug
message is misleading and is here corrected.
  • Loading branch information
jestabro committed Jan 31, 2025
1 parent 0f0fb04 commit 2134406
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions src/services/vyos-configd
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import traceback
import importlib.util
import io
from contextlib import redirect_stdout
from enum import Enum

import zmq

Expand Down Expand Up @@ -60,11 +61,14 @@ SOCKET_PATH = 'ipc:///run/vyos-configd.sock'
MAX_MSG_SIZE = 65535
PAD_MSG_SIZE = 6


# Response error codes
R_SUCCESS = 1
R_ERROR_COMMIT = 2
R_ERROR_DAEMON = 4
R_PASS = 8
class Response(Enum):
SUCCESS = 1
ERROR_COMMIT = 2
ERROR_DAEMON = 4
PASS = 8


vyos_conf_scripts_dir = directories['conf_mode']
configd_include_file = os.path.join(directories['data'], 'configd-include.json')
Expand Down Expand Up @@ -129,7 +133,7 @@ def write_stdout_log(file_name, msg):
f.write(msg)


def run_script(script_name, config, args) -> tuple[int, str]:
def run_script(script_name, config, args) -> tuple[Response, str]:
# pylint: disable=broad-exception-caught

script = conf_mode_scripts[script_name]
Expand All @@ -142,13 +146,13 @@ def run_script(script_name, config, args) -> tuple[int, str]:
script.apply(c)
except ConfigError as e:
logger.error(e)
return R_ERROR_COMMIT, str(e)
return Response.ERROR_COMMIT, str(e)
except Exception:
tb = traceback.format_exc()
logger.error(tb)
return R_ERROR_COMMIT, tb
return Response.ERROR_COMMIT, tb

return R_SUCCESS, ''
return Response.SUCCESS, ''


def initialization(socket):
Expand Down Expand Up @@ -218,11 +222,11 @@ def initialization(socket):
return config


def process_node_data(config, data, _last: bool = False) -> tuple[int, str]:
def process_node_data(config, data, _last: bool = False) -> tuple[Response, str]:
if not config:
out = 'Empty config'
logger.critical(out)
return R_ERROR_DAEMON, out
return Response.ERROR_DAEMON, out

script_name = None
os.environ['VYOS_TAGNODE_VALUE'] = ''
Expand All @@ -238,7 +242,7 @@ def process_node_data(config, data, _last: bool = False) -> tuple[int, str]:
if not script_name:
out = 'Missing script_name'
logger.critical(out)
return R_ERROR_DAEMON, out
return Response.ERROR_DAEMON, out
if res.group(3):
args = res.group(3).split()
args.insert(0, f'{script_name}.py')
Expand All @@ -250,7 +254,7 @@ def process_node_data(config, data, _last: bool = False) -> tuple[int, str]:
scripts_called.append(script_record)

if script_name not in include_set:
return R_PASS, ''
return Response.PASS, ''

with redirect_stdout(io.StringIO()) as o:
result, err_out = run_script(script_name, config, args)
Expand All @@ -263,13 +267,15 @@ def process_node_data(config, data, _last: bool = False) -> tuple[int, str]:


def send_result(sock, err, msg):
err_no = err.value
err_name = err.name
msg = msg if msg else ''
msg_size = min(MAX_MSG_SIZE, len(msg))

err_rep = err.to_bytes(1)
err_rep = err_no.to_bytes(1)
msg_size_rep = f'{msg_size:#0{PAD_MSG_SIZE}x}'

logger.debug(f'Sending reply: error_code {err} with output')
logger.debug(f'Sending reply: {err_name} with output')
sock.send_multipart([err_rep, msg_size_rep.encode(), msg.encode()])

write_stdout_log(script_stdout_log, msg)
Expand Down Expand Up @@ -335,7 +341,7 @@ if __name__ == '__main__':
scripts_called = getattr(config, 'scripts_called', [])
logger.debug(f'scripts_called: {scripts_called}')

if res == R_SUCCESS:
if res == Response.SUCCESS:
tmp = get_frrender_dict(config)
if frr.generate(tmp):
# only apply a new FRR configuration if anything changed
Expand Down

0 comments on commit 2134406

Please sign in to comment.