Skip to content

Invalid parser for YANG enumeration type #1415

Open
@alexandergall

Description

@alexandergall

Consider the schema

module test {
  namespace test;
  prefix test;
  
  leaf test {
    type enumeration {
      enum foo { value 1; }
      enum bar { value 2; }
    }
  }
}

In my understanding, the following should be a valid configuration

test foo;

and the parser should produce the Lua table

{ test = 1 }

Instead, I get an error

test foo;
         ^
lib/yang/parser.lua:49: <unknown>:1:9: error: enumeration foo is not a valid value

The error originates from lib.yang.data

local function enum_validator(enums, f)
   if not enums then return f end
   return function (val, P)
      if not enums[val] then
         P:error('enumeration '..val..' is not a valid value')
      end
      return f(val, P)
   end
end

The enums table is keyed by the enumeration values, rather than the names of the enum objects. This seems backwards to me unless I completely misunderstand the semantics of enumeration.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions