mbj4668 / pyang

An extensible YANG validator and converter in python
ISC License
528 stars 342 forks source link

UML Plugin: Fix missing notifications defined in interior data nodes #877

Closed nkhancock closed 8 months ago

nkhancock commented 11 months ago

Notifications defined in interior data nodes (containers, lists) are not rendered in the UML diagram generated by the UML Plugin. This pull request fixes this shortcoming,

The following example illustrate what has been fixed.

The following YANG data model were used to test this fix:

test-notifications ``` module test-notifications { yang-version 1.1; namespace "http://www.example.com/ns/yang/test-notifications"; prefix tst-nfc; revision 2023-07-21 { description "Initial revision."; reference "None."; } grouping notificatication-grouping { description "A grouping defining a notification."; notification grp-nfc { description "A notification in a list."; leaf binary-leaf { type binary; description "A leaf in a notification that is in a list."; } } } container container-a { description "A top-level container."; list list-a { key name; description "A list in a top-level container."; leaf name { type string; description "The name of the entry."; } notification list-a-nfc { description "A notification in a list."; leaf binary-leaf { type binary; description "A leaf in a notification that is in a list."; } container container-3 { description "A container in a notification that is in a list."; leaf another-leaf { type string; description "Just another leaf."; } leaf b-list-ref { type leafref { path "/tst-nfc:container-b" + "/tst-nfc:list-b/tst-nfc:name"; } } } } } } container container-b { description "A another top-level container."; list list-b { key name; description "A list in a top-level container."; leaf name { type string; description "The name of the entry."; } uses notificatication-grouping; } } notification top-level-nfc { description "A top-level notification."; container container-4 { description "A container in a top-level notification."; leaf a-leaf { type uint32; description "Just a leaf."; } leaf list-b-ref { type leafref { path "/tst-nfc:container-b" + "/tst-nfc:list-b/tst-nfc:name"; } } } leaf just-a-leaf { type string; description "A leaf in a top-level notification."; } } } ```

Example

Before the fix:

image

After the fix:

image

nkhancock commented 11 months ago

Am closing this PR temporarily as I have identified an issue with the --uml-inline-augments not working as previously on notifications. I will reopen, once I have corrected the issue.

nkhancock commented 11 months ago

Am reopening this pull request as the cause of the issue discussed in the last comment lies with PlantUML's stricter scoping rules and not with the changes made in this pull request. The issue does not occur when rendering the UML with a PlantUML release < 1.2023.2.

Note the stricter scoping rules impacts the correct rendering of the UML-specific option --uml-inline-augment for classes representing containers and lists as well. The impact of the stricter scoping rules on the rendering of inline augments has to be addressed separately in a further pull request.

Keywords defined within a package apparently now only have scope within that package and therefore keywords for data nodes defined in module B to be augmented to the class in module A are not visible in module A, so the data nodes are rendered in module B.

nkhancock commented 11 months ago

The initial commit for this pull request had issues when the UML-specific option --uml-inline-augments was selected. This was in addition to issues arising when using a PlantUML release >= 1.2023.2.

When rendering using PlantUML release 1.2022.12 using the UML-specific option --uml-inline-augments, duplicate attribute definitions and relations for augmented nodes were present, although duplicate relations were also seen in the master branch without these changes. When rendering using PlantUML 1.2023.9 the inline augments did not work and further issues are seen.

Commit a8e17d0 removes the duplicate attribute definitions seen using PlantUML release 1.2022.12 and the inline augmentation behavior is now consistent with that in the master branch.

When rendering using PlantUML 1.2023.9 the inline augments still do not work as a result of the stricter scoping rules in PlantUML release >= 1.2023.2. A further pull request will need to address these issues (which I am working, but may take a while).

The following YANG modules were used to test this fix:

test-augments-1 ``` module test-augments-1 { yang-version 1.1; namespace "http://www.example.com/ns/yang/test-augments-1"; prefix tst-aug-1; revision 2023-07-28 { description "Initial revision."; reference "None."; } container container-a { description "A top-level container."; list list-a { key name; description "A list in a top-level container."; leaf name { type string; description "The name of the entry."; } choice a-choice { case case-a { leaf case-a { type empty; description "..."; } } } notification list-a-nfc { description "A notification in a list."; leaf binary-leaf { type binary; description "A leaf in a notification that is in a list."; } container container-3 { description "A container in a notification that is in a list."; leaf another-leaf { type string; description "Just another leaf."; } leaf b-list-ref { type leafref { path "/tst-aug-1:container-b" + "/tst-aug-1:list-b/tst-aug-1:name"; } } } } } } container container-b { description "A another top-level container."; list list-b { key name; description "A list in a top-level container."; leaf name { type string; description "The name of the entry."; } leaf binary-leaf { type binary; description "A leaf in a notification that is in a list."; } } } notification top-level-nfc { description "A top-level notification."; container container-4 { description "A container in a top-level notification."; leaf a-leaf { type uint32; description "Just a leaf."; } leaf list-b-ref { type leafref { path "/tst-aug-1:container-b" + "/tst-aug-1:list-b/tst-aug-1:name"; } } } leaf just-a-leaf { type string; description "A leaf in a top-level notification."; } } } ```
test-augments-2 ``` module test-augments-2 { yang-version 1.1; namespace "http://www.example.com/ns/yang/test-augments-2"; prefix tst-aug-2; import test-augments-1 { prefix tst-aug-1; } revision 2023-07-28 { description "Initial revision."; reference "None."; } augment "/tst-aug-1:container-a/tst-aug-1:list-a" { description "..."; leaf augmented-leaf { type string; description "..."; } } augment "/tst-aug-1:top-level-nfc" { description "..."; leaf just-an-augmented-leaf { type string; description "..."; } } augment "/tst-aug-1:container-a/tst-aug-1:list-a/tst-aug-1:a-choice" { description "..."; case case-b { leaf case-b { type string; description "..."; } } } augment "/tst-aug-1:container-a/tst-aug-1:list-a/tst-aug-1:a-choice" + "/tst-aug-1:case-a" { description "..."; leaf another-case-leaf { type string; description "..."; } } } ```

PlantUML release 1.2022.12

Before the fix:

image

After the fix:

image

PlantUML release 1.2023.9

Before the fix:

image

After the fix:

image