Skip to content

confd: Add mount constraint for container config #1046

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions doc/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ All notable changes to the project are documented in this file.
### Fixes
- Fix containers with multiple mounts
- Correct description for LAG LACP modes
- Fix #1040: Add `mount` constraint for container config


[v25.04.0][] - 2025-04-30
Expand Down
28 changes: 28 additions & 0 deletions src/confd/src/infix-containers.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,35 @@ static int change(sr_session_ctx_t *session, uint32_t sub_id, const char *module
switch (event) {
case SR_EV_DONE:
break;

case SR_EV_CHANGE:
err = sr_get_data(session, CFG_XPATH "//.", 0, 0, 0, &cfg);
if (err || !cfg)
return SR_ERR_INTERNAL;

cifs = lydx_get_descendant(cfg->tree, "containers", "container", NULL);
LYX_LIST_FOR_EACH(cifs, cif, "container") {
struct lyd_node *mount;
LYX_LIST_FOR_EACH(lyd_child(cif), mount, "mount") {
const char *src = lydx_get_cattr(mount, "source");
const char *id = lydx_get_cattr(mount, "name");

if (src && access(src, R_OK) != 0) {
char errmsg[256];
const char *reason = strerror(errno);
snprintf(errmsg, sizeof(errmsg),
"Container '%s': mount '%s' source file '%s' is invalid: %s",
lydx_get_cattr(cif, "name"), id, src, reason);
sr_session_set_error_message(session, errmsg);
sr_release_data(cfg);
return SR_ERR_VALIDATION_FAILED;
}
}
}

sr_release_data(cfg);
return SR_ERR_OK;

case SR_EV_ABORT:
default:
return SR_ERR_OK;
Expand Down
8 changes: 8 additions & 0 deletions src/confd/yang/confd/infix-containers.yang
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ module infix-containers {
prefix infix-sys;
}

revision 2025-05-14 {
description
"Validation improvement:
- Added constraint to require either 'source' or 'content' in a container mount.";
reference "internal";
}

revision 2024-11-15 {
description "Two major changes:
- Add support for ftp/http/https images with checksum
Expand Down Expand Up @@ -342,6 +349,7 @@ module infix-containers {
}

choice data {
mandatory true;
case source {
leaf source {
description "Host path to mount in container, may be a glob.
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/confd/yang/containers.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
# REMEMBER TO UPDATE infix-interfaces ALSO IN confd.inc
MODULES=(
"[email protected] -e vlan-filtering -e containers"
"infix-containers@2024-11-15.yang"
"infix-containers@2025-05-14.yang"
)