pyang icon indicating copy to clipboard operation
pyang copied to clipboard

tree is not generated for YANG structures

Open BalazsLengyel opened this issue 5 years ago • 4 comments

[email protected]

pyang -f tree [email protected]

generates nothing. It should generate the tree representation. It produces no output.

Earlier the branch feature/yang-structure generated the tree. However now neither master nor structure branch generated anything.

BalazsLengyel avatar Nov 17 '19 15:11 BalazsLengyel

this is being done in a separate branch. checkout feature/yang-structure to try it out. you need to do -f tree --tree-print-structure as well. it lacks some documentation, test cases and support for augment-structure currently

mbj4668 avatar Nov 20 '19 15:11 mbj4668

When there are augmented structures pyang throws a TypeError.

module foo {
  namespace "urn:ietf:params:xml:ns:yang:foo";
  prefix foo;
  import ietf-yang-structure-ext { prefix sx; }

  sx:structure foo-data {
    container foo-con { }
  }
}
module bar {
  namespace "urn:ietf:params:xml:ns:yang:bar";
  prefix bar;
  import ietf-yang-structure-ext { prefix sx; }
  import foo { prefix foo; }

  sx:augment-structure /foo:foo-data/foo:foo-con {
    leaf add-leaf1 { type int32; }
    leaf add-leaf2 { type string; }
  }
}
$ pyang foo.yang bar.yang -f tree --tree-print-structure
bar.yang:5: warning: imported module "foo" not used
module: foo

  structure foo-data:
    +-- foo-con

Traceback (most recent call last):
  File "/Users/ahuangfeng/.pyenv/versions/3.9.5/bin/pyang", line 580, in <module>
    run()
  File "/Users/ahuangfeng/.pyenv/versions/3.9.5/bin/pyang", line 549, in run
    emit_obj.emit(ctx, modules, fd)
  File "/Users/ahuangfeng/.pyenv/versions/3.9.5/lib/python3.9/site-packages/pyang/plugins/tree.py", line 92, in emit
    emit_tree(ctx, modules, fd, ctx.opts.tree_depth,
  File "/Users/ahuangfeng/.pyenv/versions/3.9.5/lib/python3.9/site-packages/pyang/plugins/tree.py", line 155, in emit_tree
    del printed_header[:]
TypeError: 'bool' object does not support item deletion

ahuangfeng avatar Mar 01 '23 16:03 ahuangfeng

@ahuangfeng Hi, I submitted a PR #849 to fix this crash, Please look at it, if OK, I'll merge it.

fredgan avatar Mar 28 '23 01:03 fredgan

@ahuangfeng Hi, I submitted a PR #849 to fix this crash, Please look at it, if OK, I'll merge it.

Thanks a lot for the fixes (and sorry for the delay). I tested, it does not crash anymore:

$ pyang foo.yang bar.yang --tree-print-structure -f tree                                                                                               ─╯
bar.yang:5: warning: imported module "foo" not used
module: foo

  structure foo-data:
    +-- foo-con

module: bar

  augment-structure /foo:foo-data/foo:foo-con:
    +-- add-leaf1?   int32
    +-- add-leaf2?   string

I have a warning saying that my parent yang module is not used, but it is used for the augmentation. Apart from this, all good.

ahuangfeng avatar May 22 '24 12:05 ahuangfeng