freeconf / restconf

Implementation of RESTCONF Management protocol - IETF RFC8040
Apache License 2.0
27 stars 9 forks source link

Question: how to view full config after change #61

Open b-kamphorst opened 2 months ago

b-kamphorst commented 2 months ago

Hi!

I'm trying to set up a RESTCONF client through FREECONF. I'm working through the Car example and aim to present the user with configuration, update the configuration, and display the new configuration. Unfortunately, after a configuration update I fail to display the full configuration again.

My client code:

// Courtesy to https://freeconf.org/docs/examples/restconf-client/

package main

import (
    "github.com/freeconf/restconf"
    "github.com/freeconf/restconf/client"
    "github.com/freeconf/yang/nodeutil"
)

func connectClient() {

    // YANG: just need YANG file ietf-yang-library.yang, not the yang of remote system as that will
    // be downloaded as needed
    ypath := restconf.InternalYPath

    // Connect
    proto := client.ProtocolHandler(ypath)
    dev, err := proto("http://localhost:8080/restconf")
    if err != nil {
        panic(err)
    }

    // Get a browser to walk server's management API for car
    car, err := dev.Browser("car")
    if err != nil {
        panic(err)
    }
    root := car.Root()
    defer root.Release()

    actual, err := nodeutil.WritePrettyJSON(car.Root())
    if err != nil {
        panic(err)
    }
    println("========== initial config ==========")
    println(actual)

    n, err := nodeutil.ReadJSON(`{"speed":50}`)
    if err != nil {
        panic(err)
    }

    err = root.UpsertFrom(n)
    if err != nil {
        panic(err)
    }

    actual, err = nodeutil.WritePrettyJSON(car.Root())
    if err != nil {
        panic(err)
    }
    println("========== config after setting speed ==========")
    println(actual)

    n, err = nodeutil.ReadJSON(`{"pollInterval":50}`)
    if err != nil {
        panic(err)
    }
    err = root.UpsertFrom(n)
    if err != nil {
        panic(err)
    }
    actual, err = nodeutil.WritePrettyJSON(car.Root())
    if err != nil {
        panic(err)
    }
    println("========== config after setting pollInterval ==========")
    println(actual)
}

func main() {
    connectClient()
}

The output:

========== initial config ==========
{
"speed":50,
"pollInterval":50,
"running":false,
"miles":0,
"lastRotation":0,
"tire":[
  {
    "pos":0,
    "size":"H15",
    "worn":false,
    "wear":100,
    "flat":false},
  {
    "pos":1,
    "size":"H15",
    "worn":false,
    "wear":100,
    "flat":false},
  {
    "pos":2,
    "size":"H15",
    "worn":false,
    "wear":100,
    "flat":false},
  {
    "pos":3,
    "size":"H15",
    "worn":false,
    "wear":100,
    "flat":false}]}
========== config after setting speed ==========
{
"speed":50,
"tire":[
  {
    "size":"H15"},
  {
    "size":"H15"},
  {
    "size":"H15"},
  {
    "size":"H15"}]}
========== config after setting pollInterval ==========
{
"pollInterval":50,
"tire":[
  {
    "size":"H15"},
  {
    "size":"H15"},
  {
    "size":"H15"},
  {
    "size":"H15"}]}

I had expected that the nodeutil.WritePrettyJSON(car.Root()) calls would return the full config, not just the updated part + all configuration further dow the hierarchy. I'd be happy to learn how to obtain the full config (and why the above output is sensible).

Could you help me out? Looking forward to your (usually impressively swift) reply!

dhubler commented 2 months ago

I don't any obvious issues with this. I'll have to try this later and let you know.

On Wed, May 1, 2024 at 11:04 AM bart @.***> wrote:

Hi!

I'm trying to set up a RESTCONF client through FREECONF. I'm working through the Car example https://freeconf.org/docs/examples/restconf-client/ and aim to present the user with configuration, update the configuration, and display the new configuration. Unfortunately, after a configuration update I fail to display the full configuration again.

My client code:

// Courtesy to https://freeconf.org/docs/examples/restconf-client/ package main import ( "github.com/freeconf/restconf" "github.com/freeconf/restconf/client" "github.com/freeconf/yang/nodeutil" ) func connectClient() {

// YANG: just need YANG file ietf-yang-library.yang, not the yang of remote system as that will // be downloaded as needed ypath := restconf.InternalYPath

// Connect proto := client.ProtocolHandler(ypath) dev, err := proto("http://localhost:8080/restconf") if err != nil { panic(err) }

// Get a browser to walk server's management API for car car, err := dev.Browser("car") if err != nil { panic(err) } root := car.Root() defer root.Release()

actual, err := nodeutil.WritePrettyJSON(car.Root()) if err != nil { panic(err) } println("========== initial config ==========") println(actual)

n, err := nodeutil.ReadJSON({"speed":50}) if err != nil { panic(err) }

err = root.UpsertFrom(n) if err != nil { panic(err) }

actual, err = nodeutil.WritePrettyJSON(car.Root()) if err != nil { panic(err) } println("========== config after setting speed ==========") println(actual)

n, err = nodeutil.ReadJSON({"pollInterval":50}) if err != nil { panic(err) } err = root.UpsertFrom(n) if err != nil { panic(err) } actual, err = nodeutil.WritePrettyJSON(car.Root()) if err != nil { panic(err) } println("========== config after setting pollInterval ==========") println(actual) } func main() { connectClient() }

The output:

========== initial config =========={"speed":50,"pollInterval":50,"running":false,"miles":0,"lastRotation":0,"tire":[ { "pos":0, "size":"H15", "worn":false, "wear":100, "flat":false}, { "pos":1, "size":"H15", "worn":false, "wear":100, "flat":false}, { "pos":2, "size":"H15", "worn":false, "wear":100, "flat":false}, { "pos":3, "size":"H15", "worn":false, "wear":100, "flat":false}]}========== config after setting speed =========={"speed":50,"tire":[ { "size":"H15"}, { "size":"H15"}, { "size":"H15"}, { "size":"H15"}]}========== config after setting pollInterval =========={"pollInterval":50,"tire":[ { "size":"H15"}, { "size":"H15"}, { "size":"H15"}, { "size":"H15"}]}

I had expected that the nodeutil.WritePrettyJSON(car.Root()) calls would return the full config, not just the updated part + all configuration further dow the hierarchy. I'd be happy to learn how to obtain the full config (and why the above output is sensible).

Could you help me out? Looking forward to your (usually impressively swift) reply!

— Reply to this email directly, view it on GitHub https://github.com/freeconf/restconf/issues/61, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAACA7SVLLBR45MZBI6HSRLZAD76PAVCNFSM6AAAAABHCDCFDWVHI2DSMVQWIX3LMV43ASLTON2WKOZSGI3TGNRWGQ3TIMA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

dhubler commented 1 month ago

This is an issue. Once an edit is done, it doesn't go back into a state where it can read correctly again.

If you re-get the browser before dumping config, it works, but shouldn't have to do that

car, _ = dev.Browser("car") actual, err = nodeutil.WritePrettyJSON(car.Root()) if err != nil { panic(err) }

I confirmed this is a bug. Wasn't obvious how to fix it w/o causing other issues so will take some time to fix. Maybe the above hack will get you going for now

On Wed, May 1, 2024 at 11:11 AM Douglas Hubler @.***> wrote:

I don't any obvious issues with this. I'll have to try this later and let you know.

On Wed, May 1, 2024 at 11:04 AM bart @.***> wrote:

Hi!

I'm trying to set up a RESTCONF client through FREECONF. I'm working through the Car example https://freeconf.org/docs/examples/restconf-client/ and aim to present the user with configuration, update the configuration, and display the new configuration. Unfortunately, after a configuration update I fail to display the full configuration again.

My client code:

// Courtesy to https://freeconf.org/docs/examples/restconf-client/ package main import ( "github.com/freeconf/restconf" "github.com/freeconf/restconf/client" "github.com/freeconf/yang/nodeutil" ) func connectClient() {

// YANG: just need YANG file ietf-yang-library.yang, not the yang of remote system as that will // be downloaded as needed ypath := restconf.InternalYPath

// Connect proto := client.ProtocolHandler(ypath) dev, err := proto("http://localhost:8080/restconf") if err != nil { panic(err) }

// Get a browser to walk server's management API for car car, err := dev.Browser("car") if err != nil { panic(err) } root := car.Root() defer root.Release()

actual, err := nodeutil.WritePrettyJSON(car.Root()) if err != nil { panic(err) } println("========== initial config ==========") println(actual)

n, err := nodeutil.ReadJSON({"speed":50}) if err != nil { panic(err) }

err = root.UpsertFrom(n) if err != nil { panic(err) }

actual, err = nodeutil.WritePrettyJSON(car.Root()) if err != nil { panic(err) } println("========== config after setting speed ==========") println(actual)

n, err = nodeutil.ReadJSON({"pollInterval":50}) if err != nil { panic(err) } err = root.UpsertFrom(n) if err != nil { panic(err) } actual, err = nodeutil.WritePrettyJSON(car.Root()) if err != nil { panic(err) } println("========== config after setting pollInterval ==========") println(actual) } func main() { connectClient() }

The output:

========== initial config =========={"speed":50,"pollInterval":50,"running":false,"miles":0,"lastRotation":0,"tire":[ { "pos":0, "size":"H15", "worn":false, "wear":100, "flat":false}, { "pos":1, "size":"H15", "worn":false, "wear":100, "flat":false}, { "pos":2, "size":"H15", "worn":false, "wear":100, "flat":false}, { "pos":3, "size":"H15", "worn":false, "wear":100, "flat":false}]}========== config after setting speed =========={"speed":50,"tire":[ { "size":"H15"}, { "size":"H15"}, { "size":"H15"}, { "size":"H15"}]}========== config after setting pollInterval =========={"pollInterval":50,"tire":[ { "size":"H15"}, { "size":"H15"}, { "size":"H15"}, { "size":"H15"}]}

I had expected that the nodeutil.WritePrettyJSON(car.Root()) calls would return the full config, not just the updated part + all configuration further dow the hierarchy. I'd be happy to learn how to obtain the full config (and why the above output is sensible).

Could you help me out? Looking forward to your (usually impressively swift) reply!

— Reply to this email directly, view it on GitHub https://github.com/freeconf/restconf/issues/61, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAACA7SVLLBR45MZBI6HSRLZAD76PAVCNFSM6AAAAABHCDCFDWVHI2DSMVQWIX3LMV43ASLTON2WKOZSGI3TGNRWGQ3TIMA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

dhubler commented 1 month ago

ok, i pushed fix to master branch that appears to address the issue in the example you sent. Can you update and try it again?

On Mon, May 6, 2024 at 9:22 PM Douglas Hubler @.***> wrote:

This is an issue. Once an edit is done, it doesn't go back into a state where it can read correctly again.

If you re-get the browser before dumping config, it works, but shouldn't have to do that

car, _ = dev.Browser("car") actual, err = nodeutil.WritePrettyJSON(car.Root()) if err != nil { panic(err) }

I confirmed this is a bug. Wasn't obvious how to fix it w/o causing other issues so will take some time to fix. Maybe the above hack will get you going for now

On Wed, May 1, 2024 at 11:11 AM Douglas Hubler @.***> wrote:

I don't any obvious issues with this. I'll have to try this later and let you know.

On Wed, May 1, 2024 at 11:04 AM bart @.***> wrote:

Hi!

I'm trying to set up a RESTCONF client through FREECONF. I'm working through the Car example https://freeconf.org/docs/examples/restconf-client/ and aim to present the user with configuration, update the configuration, and display the new configuration. Unfortunately, after a configuration update I fail to display the full configuration again.

My client code:

// Courtesy to https://freeconf.org/docs/examples/restconf-client/ package main import ( "github.com/freeconf/restconf" "github.com/freeconf/restconf/client" "github.com/freeconf/yang/nodeutil" ) func connectClient() {

// YANG: just need YANG file ietf-yang-library.yang, not the yang of remote system as that will
// be downloaded as needed
ypath := restconf.InternalYPath

// Connect
proto := client.ProtocolHandler(ypath)
dev, err := proto("http://localhost:8080/restconf")
if err != nil {
    panic(err)
}

// Get a browser to walk server's management API for car
car, err := dev.Browser("car")
if err != nil {
    panic(err)
}
root := car.Root()
defer root.Release()

actual, err := nodeutil.WritePrettyJSON(car.Root())
if err != nil {
    panic(err)
}
println("========== initial config ==========")
println(actual)

n, err := nodeutil.ReadJSON(`{"speed":50}`)
if err != nil {
    panic(err)
}

err = root.UpsertFrom(n)
if err != nil {
    panic(err)
}

actual, err = nodeutil.WritePrettyJSON(car.Root())
if err != nil {
    panic(err)
}
println("========== config after setting speed ==========")
println(actual)

n, err = nodeutil.ReadJSON(`{"pollInterval":50}`)
if err != nil {
    panic(err)
}
err = root.UpsertFrom(n)
if err != nil {
    panic(err)
}
actual, err = nodeutil.WritePrettyJSON(car.Root())
if err != nil {
    panic(err)
}
println("========== config after setting pollInterval ==========")
println(actual)

} func main() { connectClient() }

The output:

========== initial config =========={"speed":50,"pollInterval":50,"running":false,"miles":0,"lastRotation":0,"tire":[ { "pos":0, "size":"H15", "worn":false, "wear":100, "flat":false}, { "pos":1, "size":"H15", "worn":false, "wear":100, "flat":false}, { "pos":2, "size":"H15", "worn":false, "wear":100, "flat":false}, { "pos":3, "size":"H15", "worn":false, "wear":100, "flat":false}]}========== config after setting speed =========={"speed":50,"tire":[ { "size":"H15"}, { "size":"H15"}, { "size":"H15"}, { "size":"H15"}]}========== config after setting pollInterval =========={"pollInterval":50,"tire":[ { "size":"H15"}, { "size":"H15"}, { "size":"H15"}, { "size":"H15"}]}

I had expected that the nodeutil.WritePrettyJSON(car.Root()) calls would return the full config, not just the updated part + all configuration further dow the hierarchy. I'd be happy to learn how to obtain the full config (and why the above output is sensible).

Could you help me out? Looking forward to your (usually impressively swift) reply!

— Reply to this email directly, view it on GitHub https://github.com/freeconf/restconf/issues/61, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAACA7SVLLBR45MZBI6HSRLZAD76PAVCNFSM6AAAAABHCDCFDWVHI2DSMVQWIX3LMV43ASLTON2WKOZSGI3TGNRWGQ3TIMA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

b-kamphorst commented 1 month ago

I confirm that master (3972ca6) fixes this issue (rather than #62 as referenced by the commit message). Thank you!

b-kamphorst commented 1 month ago

Perhaps we are not done entirely. This time, I select and print the value of a leaf after the config change. After that, I don't get the full config again if I print car.Root(). It appears that the root has been changed?

// Courtesy to https://freeconf.org/docs/examples/restconf-client/

package main

import (
    "github.com/freeconf/restconf"
    "github.com/freeconf/restconf/client"
    "github.com/freeconf/yang/nodeutil"
)

func connectClient() {

    // YANG: just need YANG file ietf-yang-library.yang, not the yang of remote system as that will
    // be downloaded as needed
    ypath := restconf.InternalYPath

    // Connect
    proto := client.ProtocolHandler(ypath)
    dev, err := proto("http://localhost:8080/restconf")
    if err != nil {
        panic(err)
    }

    // Get a browser to walk server's management API for car
    car, err := dev.Browser("car")
    if err != nil {
        panic(err)
    }
    root := car.Root()
    defer root.Release()

    actual, err := nodeutil.WritePrettyJSON(car.Root())
    if err != nil {
        panic(err)
    }
    println("========== initial config ==========")
    println(actual)

    n, err := nodeutil.ReadJSON(`{"speed":50}`)
    if err != nil {
        panic(err)
    }

    err = root.UpsertFrom(n)
    if err != nil {
        panic(err)
    }

    actual, err = nodeutil.WritePrettyJSON(car.Root())
    if err != nil {
        panic(err)
    }
    println("========== config after setting speed ==========")
    println(actual)

    speed, err := root.Find("speed")
    if err != nil {
        panic(err)
    }
    speed_json, err := nodeutil.WritePrettyJSON(speed)
    if err != nil {
        panic(err)
    }
    println("========== just showing the value of speed ==========")
    println(speed_json)

        actual, err := nodeutil.WritePrettyJSON(car.Root())
    if err != nil {
        panic(err)
    }
    println("========== full config ==========")
    println(actual)
}

func main() {
    connectClient()
}

Output:

========== initial config ==========
{
"speed":1000,
"pollInterval":1000,
... // actual full config
========== config after setting speed ==========
{
"speed":50,
"pollInterval":1000,
... // actual full config
========== just showing the value of speed ==========
{
"speed":50}
========== full config ==========
{
"speed":50}

Not sure whether this is related though, as in the original example I didn't make a call to root.Find.

dhubler commented 1 month ago

ok, i was able to reproduce this and it related only in that there is more state leftover from previous calls. I will take another swing in next day or so.

On Tue, May 7, 2024 at 3:12 AM bart @.***> wrote:

Perhaps we are not done entirely. This time, I select and print the value of a leaf after the config change. After that, I don't get the full config again if I print car.Root(). It appears that the root has been changed?

// Courtesy to https://freeconf.org/docs/examples/restconf-client/ package main import ( "github.com/freeconf/restconf" "github.com/freeconf/restconf/client" "github.com/freeconf/yang/nodeutil" ) func connectClient() {

// YANG: just need YANG file ietf-yang-library.yang, not the yang of remote system as that will // be downloaded as needed ypath := restconf.InternalYPath

// Connect proto := client.ProtocolHandler(ypath) dev, err := proto("http://localhost:8080/restconf") if err != nil { panic(err) }

// Get a browser to walk server's management API for car car, err := dev.Browser("car") if err != nil { panic(err) } root := car.Root() defer root.Release()

actual, err := nodeutil.WritePrettyJSON(car.Root()) if err != nil { panic(err) } println("========== initial config ==========") println(actual)

n, err := nodeutil.ReadJSON({"speed":50}) if err != nil { panic(err) }

err = root.UpsertFrom(n) if err != nil { panic(err) }

actual, err = nodeutil.WritePrettyJSON(car.Root()) if err != nil { panic(err) } println("========== config after setting speed ==========") println(actual)

speed, err := root.Find("speed") if err != nil { panic(err) } speed_json, err := nodeutil.WritePrettyJSON(speed) if err != nil { panic(err) } println("========== just showing the value of speed ==========") println(speed_json)

    actual, err := nodeutil.WritePrettyJSON(car.Root())

if err != nil { panic(err) } println("========== full config ==========") println(actual) } func main() { connectClient() }

Output:

========== initial config =========={"speed":1000,"pollInterval":1000,... // actual full config========== config after setting speed =========={"speed":50,"pollInterval":1000,... // actual full config========== just showing the value of speed =========={"speed":50}========== full config =========={"speed":50}

Not sure whether this is related though, as in the original example I didn't make a call to root.Find.

— Reply to this email directly, view it on GitHub https://github.com/freeconf/restconf/issues/61#issuecomment-2097603739, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAACA7UUXM6IPCSX2OYU2V3ZBB5GZAVCNFSM6AAAAABHCDCFDWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAOJXGYYDGNZTHE . You are receiving this because you commented.Message ID: @.***>

b-kamphorst commented 1 month ago

Note: the example runs as expected when I add speed.Release() after println(speed_json). Still, it is counterintuitive to me that root prints only partial information while a reference a speed selection is locked (and why that was locked to begin with).

dhubler commented 1 month ago

what do you mean by "locked"?

There is definitely state somewhere in the client node logic that is to blame.

On Thu, May 16, 2024 at 11:03 AM bart @.***> wrote:

Note: the example runs as expected when I add speed.Release() after println(speed_json). Still, it is counterintuitive to me that root prints only partial information while a reference a speed selection is locked (and why that was locked to begin with).

— Reply to this email directly, view it on GitHub https://github.com/freeconf/restconf/issues/61#issuecomment-2115497150, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAACA7SSD2RJWIQAPVQVMP3ZCTDEVAVCNFSM6AAAAABHCDCFDWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMJVGQ4TOMJVGA . You are receiving this because you commented.Message ID: @.***>

b-kamphorst commented 1 month ago

I mean whatever it is in the state of the Selection/Node that prevents us from getting the expected results before calling Release() but does allow us to do so after releasing the Selection. Perhaps "locked" is not the right term here, but the behaviour and name "release" made me think of mutexes.

Op do 16 mei 2024 21:16 schreef Douglas Hubler @.***>:

what do you mean by "locked"?

There is definitely state somewhere in the client node logic that is to blame.

On Thu, May 16, 2024 at 11:03 AM bart @.***> wrote:

Note: the example runs as expected when I add speed.Release() after println(speed_json). Still, it is counterintuitive to me that root prints only partial information while a reference a speed selection is locked (and why that was locked to begin with).

— Reply to this email directly, view it on GitHub https://github.com/freeconf/restconf/issues/61#issuecomment-2115497150,

or unsubscribe < https://github.com/notifications/unsubscribe-auth/AAACA7SSD2RJWIQAPVQVMP3ZCTDEVAVCNFSM6AAAAABHCDCFDWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMJVGQ4TOMJVGA>

. You are receiving this because you commented.Message ID: @.***>

— Reply to this email directly, view it on GitHub https://github.com/freeconf/restconf/issues/61#issuecomment-2116010957, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOXDNCBVDUZSDIYNIRKL3ODZCUA2HAVCNFSM6AAAAABHCDCFDWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMJWGAYTAOJVG4 . You are receiving this because you modified the open/close state.Message ID: @.***>