Skip to content
Snippets Groups Projects
Commit 39c5e73a authored by Malte Bauch's avatar Malte Bauch
Browse files

Correctly init the goStruct within the plugins ValidateChange method

The nodes along a path of the copied model (which is a copy of the
underlying goStruct of the plugin) within the ValidateChange method of a
plugin were not properly initialized.

This means if a JSON string was provided that contained a node that was
not initialized an error was thrown. But since the
`ytypes.IgnoreExtraFields` option was set, the node was just ignored and
no error was thrown.

This change correctly initializes the node at the given path and removes
the `ytypes.IgnoreExtraFields` option.
parent 646ca304
Branches deploy
No related tags found
1 merge request!455Resolve "A set request results in error : no changes between"
Pipeline #139063 failed
basepnduuid = "5f20f34b-cbd0-4511-9ddc-c50cf6a3b49d" basepnduuid = "5f20f34b-cbd0-4511-9ddc-c50cf6a3b49d"
basesouthboundtype = 1
basesouthbounduuid = "ca29311a-3b17-4385-96f8-515b602a97ac"
csbi-orchestrator = "clab-gosdn_csbi_arista_base-csbi-orchestrator:55056" csbi-orchestrator = "clab-gosdn_csbi_arista_base-csbi-orchestrator:55056"
plugin-registry = "clab-gosdn_csbi_arista_base-plugin-registry:55057" plugin-registry = "clab-gosdn_csbi_arista_base-plugin-registry:55057"
help = false help = false
......
...@@ -4,8 +4,6 @@ amqpport = '5672' ...@@ -4,8 +4,6 @@ amqpport = '5672'
amqpprefix = 'amqp://' amqpprefix = 'amqp://'
amqpuser = 'guest' amqpuser = 'guest'
basepnduuid = '5f20f34b-cbd0-4511-9ddc-c50cf6a3b49d' basepnduuid = '5f20f34b-cbd0-4511-9ddc-c50cf6a3b49d'
basesouthboundtype = 1
basesouthbounduuid = 'ca29311a-3b17-4385-96f8-515b602a97ac'
cli_pnd = '0455b241-5863-4660-ad15-dfde7617738e' cli_pnd = '0455b241-5863-4660-ad15-dfde7617738e'
cli_sbi = 'a249f2d2-f7da-481d-8a99-b7f11471e0af' cli_sbi = 'a249f2d2-f7da-481d-8a99-b7f11471e0af'
config = '/home/neil/code/gosdn/controller/configs/development-gosdn.toml' config = '/home/neil/code/gosdn/controller/configs/development-gosdn.toml'
......
...@@ -197,14 +197,28 @@ func (d *DeviceModel) ValidateChange(operation mnepb.ApiOperation, path *gpb.Pat ...@@ -197,14 +197,28 @@ func (d *DeviceModel) ValidateChange(operation mnepb.ApiOperation, path *gpb.Pat
switch operation { switch operation {
case mnepb.ApiOperation_API_OPERATION_UPDATE, mnepb.ApiOperation_API_OPERATION_REPLACE: case mnepb.ApiOperation_API_OPERATION_UPDATE, mnepb.ApiOperation_API_OPERATION_REPLACE:
_, entry, err := ytypes.GetOrCreateNode(d.schema.RootSchema(), modelCopy, path) createdNode, entry, err := ytypes.GetOrCreateNode(d.schema.RootSchema(), modelCopy, path)
if err != nil { if err != nil {
return nil, err return nil, err
} }
validatedCreatedNode, ok := createdNode.(ygot.ValidatedGoStruct)
if !ok {
return nil, &customerrs.InvalidTypeAssertionError{
Value: createdNode,
Type: (*ygot.ValidatedGoStruct)(nil),
}
}
if entry.IsDir() { if entry.IsDir() {
opts := []ytypes.UnmarshalOpt{&ytypes.IgnoreExtraFields{}} opts := []ytypes.UnmarshalOpt{
if err := d.generatedUnmarshalFn(value, modelCopy, opts...); err != nil { // NOTE: I think we should not ignore extra fields if we want
// to validate a specific change. The input for a valid change
// should be correct to be valid.
//
//&ytypes.IgnoreExtraFields{}
}
if err := d.generatedUnmarshalFn(value, validatedCreatedNode, opts...); err != nil {
return nil, err return nil, err
} }
} else if entry.IsLeaf() { } else if entry.IsLeaf() {
...@@ -213,7 +227,7 @@ func (d *DeviceModel) ValidateChange(operation mnepb.ApiOperation, path *gpb.Pat ...@@ -213,7 +227,7 @@ func (d *DeviceModel) ValidateChange(operation mnepb.ApiOperation, path *gpb.Pat
return nil, err return nil, err
} }
opts := []ytypes.SetNodeOpt{&ytypes.InitMissingElements{}, &ytypes.TolerateJSONInconsistencies{}} opts := []ytypes.SetNodeOpt{&ytypes.InitMissingElements{}, &ytypes.TolerateJSONInconsistencies{}}
if err := ytypes.SetNode(d.schema.RootSchema(), modelCopy, path, typedValue, opts...); err != nil { if err := ytypes.SetNode(d.schema.RootSchema(), validatedCreatedNode, path, typedValue, opts...); err != nil {
return nil, err return nil, err
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment