CESNET / netopeer2

NETCONF toolset
BSD 3-Clause "New" or "Revised" License
296 stars 187 forks source link

admin-state node of ietf-hardware.yang notifying failed issue #1409

Closed matlabrui-code closed 11 months ago

matlabrui-code commented 1 year ago

Hi all, When I want to notify the admin-state node of ietf-hardware.yang, netconf server occurred a mistake print as below:

libyang[0]: Invalid leafref value "locked" - no existing target instance "/hardware/component/state/admin-state". (path: Schema location /ietf-hardware:hardware-state-oper-enabled/admin-state, data location /ietf-hardware:hardware-state-oper-enabled/admin-state.)>>>admin_state_enabled_notification send failed, rc=9, Validation failed

And I attched my code as below:

notif[1].type = SR_INSTANCEID_T;
switch(admin_state)
{
    case 0:sr_val_set_str_data(&notif[1], SR_INSTANCEID_T, "unlocked");break;
    case 1:sr_val_set_str_data(&notif[1], SR_INSTANCEID_T, "locked");break;
    case 2:sr_val_set_str_data(&notif[1], SR_INSTANCEID_T, "unknown");break;
    default:sr_val_set_str_data(&notif[1], SR_INSTANCEID_T, "unknown");break;
}

printf(">>>printf the [%s] values: \n",__func__);
size_t i;
for(i=0; i<leaf_cnt; ++i)
{
    sr_print_val(&notif[i]);
}

rc = sr_event_notif_send(session, "/ietf-hardware:hardware-state-oper-disabled", notif, leaf_cnt, 0, 0);

It seems like I didn't fill the value on "/hardware/component/state/admin-state" path. What I've done was for /ietf-"hardware:hardware-state-oper-disabled" notify path, but I think I just want to notfiy the node in the notify path. So, what should I do to check out this issue?

michalvasko commented 1 year ago

Seems you have a leafref in the notification to the configuration data. However, when validating a notification, it is the data from the operational datastore that it is being validated against meaning you need to have /hardware/component/state/admin-state node with value locked in the operational datastore for the notification to validate and be sent. How to get data to this datastore is described in the sysrepo documentation.

matlabrui-code commented 1 year ago

Seems you have a leafref in the notification to the configuration data. However, when validating a notification, it is the data from the operational datastore that it is being validated against meaning you need to have /hardware/component/state/admin-state node with value locked in the operational datastore for the notification to validate and be sent. How to get data to this datastore is described in the sysrepo documentation.

But the notfifcation node branch are different with wtih the node which was reporting the error. So you mean that should I configure the node which is not belonging to the notification branch?

michalvasko commented 1 year ago

I do not understand what you are confused about and am not sure you even understand what a leafref is, so please read about it if you do not. The notification you are trying to send has 3 leaves of the leafref type, which needs to point to existing target instances in the oeprational datastore. These instances (or at least one) do not exist in your case hence you getting the error.

matlabrui-code commented 1 year ago

I do not understand what you are confused about and am not sure you even understand what a leafref is, so please read about it if you do not. The notification you are trying to send has 3 leaves of the leafref type, which needs to point to existing target instances in the oeprational datastore. These instances (or at least one) do not exist in your case hence you getting the error.

OK, I got the reason.The notification leaf "/ietf-hardware:hardware-state-oper-disabled/admin-statae" is relavent to the leaf "/hardware/component/state/admin-state", I should configure the second leaf first ,then the notification would happen.

michalvasko commented 1 year ago

Yes, that is correct.