Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enumerations in unions that are used as keys in a list #301

Closed
shmuelnatan opened this issue Feb 8, 2022 · 13 comments
Closed

enumerations in unions that are used as keys in a list #301

shmuelnatan opened this issue Feb 8, 2022 · 13 comments

Comments

@shmuelnatan
Copy link
Contributor

I noticed the following behavior. Let's say I have the following union that contains an enum and some other type (in this case a string), and the union is used as key in a list.

typedef union-type {
        type union {
            type enumeration {
                enum enum-foo1 {
                }
                enum enum-foo2 {
                }
            }
            type string {
            }
         }
}

list modules {
    leaf "module" {
       type union-type;
    }
    key "module";
    leaf content{
        type string;
    }
}

Then I set a node in the list with an enum key (and commit I it)
set modules module enum-foo1 content foo
I then try to change the value of content but the autocompletion of content disappears. It only returns if I delete the node using enum-foo1 as the key and reset it.

delete modules module enum-foo1
commit
set modules module enum-foo1 content boo

This phenomenon only happens to enumerations in unions that are used as keys.

@olofhagsand olofhagsand added the bug label Feb 8, 2022
@olofhagsand
Copy link
Member

After some investigation, it turns out this occurs also for other leafs, not just keys in the autocli, and was introduced in Clixon 5.4.
This means it worked in 5.3 but is broken in 5.4 and 5.5
See also clicon/cligen#73 with the same problem for included tree references

@shmuelnatan
Copy link
Contributor Author

I checked it in our systems and the auto cli works but for some reason when I commit anything with the list that contains the union with the enumeration, the clixon doesn't show it to me in a show command

@olofhagsand
Copy link
Member

Yes, I see I can set it once, but not a second time, from test_cli_union.sh:

olof@alarik /> set tablekey parkey u1 <?>
  <cr>
  value                
olof@alarik /> set tablekey parkey u1 <cr>
olof@alarik /> set tablekey parkey u1 <?>
  <cr>
       # <--- No value option

also at commit

olofhagsand added a commit to clicon/cligen that referenced this issue Feb 16, 2022
olofhagsand added a commit that referenced this issue Feb 16, 2022
@olofhagsand
Copy link
Member

New fixes. Can you please verify again?

@shmuelnatan
Copy link
Contributor Author

shmuelnatan commented Feb 16, 2022

I checked it in our systems and the auto cli works but for some reason when I commit anything with the list that contains the union with the enumeration, the clixon doesn't show it to me in a show command

I still have the same problem. I'll give an example with the example in the bug
cli> set modules module enum-foo1 content boo
cli> commit
cli> show modules module
cli>
I'm expecting to see the saved value but it doesn't appear in the database after a commit

@olofhagsand
Copy link
Member

I cannot recreate it.
See testcase :

new "show running"

where a union key is set and committed and shows up in show config.
Can you please check the testcase and see how your example is diffferent?

@shmuelnatan
Copy link
Contributor Author

shmuelnatan commented Feb 21, 2022

I cannot recreate it. See testcase :

new "show running"

where a union key is set and committed and shows up in show config.
Can you please check the testcase and see how your example is diffferent?

There are two problems I noticed with your fix:

  1. In autocompletion with a set command you can get a field that is in state data (i.e., config false). Setting this field does nothing but nevertheless, this field shouldn't appear in autocompletion.
  2. A problem I encountered is when we have two modules each one with a different namespace. Module A has uses ModuleB:foo and foo is a list (I checked this by lists). When one tries to set foo the cli thinks that foo has the namespace of ModuleA which results in an error since foo isn't described in ModuleB.

@olofhagsand
Copy link
Member

olofhagsand commented Feb 23, 2022

  1. In autocompletion with a set command you can get a field that is in state data (i.e., config false). Setting this field does nothing but nevertheless, this field shouldn't appear in autocompletion.

I cannot recreate.
I tried with eg:

    container tablekey{
	list parkey{
	    description "key is union type";
	    key name;
	    leaf name{
		type uniontype;
	    }
	    leaf value{
		type string;
	    }
	    leaf stat{
		config false;
		type int32;
	    }
    }

but no state variable

olof@alarik /> set tablekey parkey u2 ?
  <cr>
  value                
olof@alarik /> set tablekey parkey u2 

Please provide an example where this happens, eg, what does the the yang look like and in what way is the state completion shown?

  1. A problem I encountered is when we have two modules each one with a different namespace. Module A has uses ModuleB:foo and foo is a list (I checked this by lists). When one tries to set foo the cli thinks that foo has the namespace of ModuleA which results in an error since foo isn't described in ModuleB.

This sounds like a separate issue? There is an issue with same symbols in different namespaces since prefixes have not been introduced in the auto-cli yet. Some preparations have been made though.
Can you please make this issue as a concrete usecase and file a separate issue?

@shmuelnatan
Copy link
Contributor Author

shmuelnatan commented Feb 24, 2022

Regarding the state data, it seems like it's connected to the previous namespace issue. Here are examples of the two modules.

module A {
  namespace "http://A";
  grouping GroupA {
    container ContainerA{
      config false;
      list ListA{
        key name;
        leaf name{
          type string;
        }
        leaf value{
          type string;
        }
      }
    }
  }
}
module B {
  namespace "http://B";
  import A {
    prefix "MA";
  }
  container ContainerB1{
    leaf foo {
      type string;
    }
    container ContainerB2{
      config false;
      uses MA:GroupA;
    }
  }

The auto cli allows to write the following command
cli> set ContainerB1 ContainerB2 ContainerA ListA boo value boo

I know that this behavior did not happen in the 5.2 version

@olofhagsand
Copy link
Member

I take it #2 is moved to #309? (Plz remove it from here.)
Is #1 still an issue?

@shmuelnatan
Copy link
Contributor Author

shmuelnatan commented Mar 15, 2022

Regarding the initial bug #301 (comment), I noticed that with your fix (i.e., cligen 5.6.0) I get an error when I want to set a module that is not an enumeration.

typedef union-type {
        type union {
            type enumeration {
                enum enum-foo1 {
                }
            }
            type string {
            }
         }
}

list modules {
    leaf "module" {
       type union-type;
    }
    key "module";
    leaf content{
        type string;
    }
}
cli> set modules enum-foo1 content foo1
cli> commit
cli> set modules boo content boo
cli> commit
Mar 15 00:00:02: Commit failed. Edit and try again or discard changes: application operation-failed Module boo is unknown
CLI command error

But since the key of the list is a union, then it should allow other values that are not enumerations.

@olofhagsand
Copy link
Member

olofhagsand commented Mar 15, 2022

Cannot recreate:

olof@alarik> clixon_cli -f /usr/local/etc/example.xml
olof@alarik /> set modules enum-foo1 content foo1
olof@alarik /> commit 
olof@alarik /> set modules boo content boo
olof@alarik /> commit
olof@alarik /> show configuration xml 
<modules xmlns="urn:example:clixon">
   <module>boo</module>
   <content>boo</content>
</modules>
<modules xmlns="urn:example:clixon">
   <module>enum-foo1</module>
   <content>foo1</content>
</modules>
olof@alarik /> 

@olofhagsand olofhagsand reopened this Mar 15, 2022
@olofhagsand
Copy link
Member

Cannot recreate, please reopen and add new info if you still consider it an issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants