infix icon indicating copy to clipboard operation
infix copied to clipboard

confd: Add mount constraint for container config

Open axkar opened this issue 7 months ago • 4 comments

This PR adds a validation rule to prevent incomplete container mount configurations. Ensures that either "source" or "content" is present when "target" is specified, avoiding runtime errors caused by undefined mount sources.

Fixes #1040

Checklist

Tick relevant boxes, this PR is-a or has-a:

  • [x] Bugfix
    • [ ] Regression tests
    • [x] ChangeLog updates (for next release)
    • [x] YANG model change => revision updated?
  • [ ] Feature
    • [ ] YANG model change => revision updated?
    • [ ] Regression tests added?
    • [ ] ChangeLog updates (for next release)
    • [ ] Documentation added?
  • [ ] Test changes
    • [ ] Checked in changed Readme.adoc (make test-spec)
    • [ ] Added new test to group Readme.adoc and yaml file
  • [ ] Code style update (formatting, renaming)
  • [ ] Refactoring (please detail in commit messages)
  • [ ] Build related changes
  • [ ] Documentation content changes
    • [ ] ChangeLog updated (for major changes)
  • [ ] Other (please describe):

axkar avatar May 15 '25 08:05 axkar

Did you verify that adding mandatory true; to the data and content leafs did not solve this issue without an explicit must expression?

wkz avatar May 15 '25 14:05 wkz

Did you verify that adding mandatory true; to the data and content leafs did not solve this issue without an explicit must expression?

My question too.

troglobit avatar May 15 '25 16:05 troglobit

I have just checked. Unfortunately it doesn't seem to work to have it this way:

choice data {
          case source {
            leaf source {
              mandatory true;
              description "...";
              type string {
                pattern '/.*';
              }
            }
          }
          case content {
            leaf content {
              mandatory true;
              description "...";
              type binary;
            }
          }
        }

This looked like the ideal solution, but it seems that libyang might not be handling this correctly. Possibly a bug or a limitation in how it treats choice nodes with mandatory leaves.

axkar avatar May 16 '25 09:05 axkar

It actually works by placing mandatory true; at the top level of choice data.

choice data {
          mandatory true;
          case source {
            leaf source {
              description "...";
              type string {
                pattern '/.*';
              }
            }
          }
          case content {
            leaf content {
              description "...";
              type binary;
            }
          }
        }

Error messages are not perfect though for CLI users who do not interact with YANG models:

admin@test-00-01-00:/config/> leave
Error: Mandatory choice "data" data do not exist. (path "/infix-containers:containers/container[name='xyz']/mount[name='abc']")
Error: Invalid candidate configuration
admin@test-00-01-00:/config/>

There is no mention of source or content. However, this seems to be the way forward. It is minimal and correct :)

axkar avatar May 16 '25 14:05 axkar

It actually works by placing mandatory true; at the top level of choice data.

choice data {
          mandatory true;
          case source {
            leaf source {
              description "...";
              type string {
                pattern '/.*';
              }
            }
          }
          case content {
            leaf content {
              description "...";
              type binary;
            }
          }
        }

Error messages are not perfect though for CLI users who do not interact with YANG models:

admin@test-00-01-00:/config/> leave
Error: Mandatory choice "data" data do not exist. (path "/infix-containers:containers/container[name='xyz']/mount[name='abc']")
Error: Invalid candidate configuration
admin@test-00-01-00:/config/>

There is no mention of source or content. However, this seems to be the way forward. It is minimal and correct :)

data is a very general name, i really think the (choice) node should be renamed to source to more indicate what it is. But this is a separate issue IMHO.

But for now, the user may need to look at the model to know whats happening.

mattiaswal avatar May 19 '25 12:05 mattiaswal