Skip to content

Commit 63eeaf8

Browse files
olethanhnesitor
authored andcommitted
add debug info
1 parent 3584770 commit 63eeaf8

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/aleph/vm/network/firewall.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,26 @@ def get_customized_nftables() -> Nftables:
2929

3030
def execute_json_nft_commands(commands: list[dict]) -> dict:
3131
"""Executes a list of nftables commands and returns the json output"""
32+
if not commands:
33+
return {}
3234
nft = get_customized_nftables()
35+
3336
commands_dict = {"nftables": commands}
3437
try:
3538
logger.debug("Validating nftables rules")
3639
nft.json_validate(commands_dict)
3740
except Exception as e:
3841
logger.error(f"Failed to verify nftables rules: {e}")
3942

40-
logger.debug("Inserting nftables rules")
43+
def _format_command_for_debug():
44+
l = []
45+
for c in commands:
46+
for command_name, entity in c.items():
47+
for entity_type, entity_args in entity.items():
48+
l.append(f"{command_name} {entity_type} {entity_args.get('name', '')}")
49+
return ", ".join(l)
50+
51+
logger.debug("Nftables commands: %s", _format_command_for_debug())
4152
return_code, output, error = nft.json_cmd(commands_dict)
4253
if return_code != 0:
4354
logger.error("Failed to add nftables rules: %s -- %s", error, json.dumps(commands, indent=4))

0 commit comments

Comments
 (0)