Skip to content

typedef only returns value if prefixed/imported type #153

@Krisscut

Description

@Krisscut

Hi,

I think there is an issue with the implement of the typedef function of the Type class.

If seems to only assume a ":" will be present in the type, but from my understanding this will only be the case for type that are imported from another yang schema:

def typedef(self) -> "Typedef":
if ":" in self.name():
module_prefix, type_name = self.name().split(":")
import_module = self.module().get_module_from_prefix(module_prefix)
if import_module:
return import_module.get_typedef(type_name)
return None

For instance with this schema, my "operation-status" enumeration was not found properly.

module my_imported_module {
    namespace "urn:ietf:params:xml:ns:yang:my-imported-module";
    prefix "my-imported-module";

    typedef operation-status {
        type enumeration {
            enum "inactive" {
                description "The operation is currently inactive and not running";
            }
            enum "active" {
                description "The operation is currently active and running normally";
            }
            enum "pending" {
                description "The operation is pending and waiting to be started";
            }
            enum "error" {
                description "The operation has encountered an error and requires attention";
            }
            enum "maintenance" {
                description "The operation is under maintenance and temporarily unavailable";
            }
        }
        description "Enumeration representing the operational status of a service or component";
    }

    grouping my-imported-container {
        container my-imported-container {
            leaf custom-leaf-config-true {
                config true;
                type string;
            }
            leaf custom-leaf-config-false {
                config false;
                type string;
            }

            leaf operation-status {
                type operation-status;
                description "Requested operational status of this specific service instance in the container";
            }
        }
    }
}

I had to do a "double-pass", with a search using the typedef first, then adding a search in the local module, like so:

    def typedef(self) -> YangTypedef:
        external_typedef = self.type.typedef()
        if external_typedef is not None:
            return YangTypedef(external_typedef)

        # There is a bug in default get_typedef: it only searches in external modules using a prefix
        internal_typedef = self.type.module().get_typedef(self.type.name())
        return YangTypedef(internal_typedef) if internal_typedef is not None else None

is my understanding correct ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions