Skip to content

Commit

Permalink
schema compile UPDATE allow deviate-replace implicit properties
Browse files Browse the repository at this point in the history
Fixes #2212
  • Loading branch information
michalvasko committed Apr 2, 2024
1 parent ed27758 commit 2063f20
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 36 deletions.
21 changes: 1 addition & 20 deletions src/schema_compile_amend.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @author Michal Vasko <mvasko@cesnet.cz>
* @brief Schema compilation of augments, deviations, and refines.
*
* Copyright (c) 2015 - 2021 CESNET, z.s.p.o.
* Copyright (c) 2015 - 2024 CESNET, z.s.p.o.
*
* This source code is licensed under BSD 3-Clause License (the "License").
* You may not use this file except in compliance with the License.
Expand Down Expand Up @@ -1499,13 +1499,6 @@ lys_apply_deviate_replace(struct lysc_ctx *ctx, struct lysp_deviate_rpl *d, stru
AMEND_WRONG_NODETYPE("deviation", "replace", "mandatory");
}

if (!(target->flags & LYS_MAND_MASK)) {
LOGVAL(ctx->ctx, LY_VCODE_DEV_NOT_PRESENT, "replacing", "mandatory",
d->flags & LYS_MAND_TRUE ? "mandatory true" : "mandatory false");
ret = LY_EVALID;
goto cleanup;
}

target->flags &= ~LYS_MAND_MASK;
target->flags |= d->flags & LYS_MAND_MASK;
}
Expand All @@ -1523,12 +1516,6 @@ lys_apply_deviate_replace(struct lysc_ctx *ctx, struct lysp_deviate_rpl *d, stru
AMEND_WRONG_NODETYPE("deviation", "replace", "min-elements");
}

if (!(target->flags & LYS_SET_MIN)) {
LOGVAL(ctx->ctx, LYVE_REFERENCE, "Invalid deviation replacing \"min-elements\" property which is not present.");
ret = LY_EVALID;
goto cleanup;
}

*num = d->min;
}

Expand All @@ -1545,12 +1532,6 @@ lys_apply_deviate_replace(struct lysc_ctx *ctx, struct lysp_deviate_rpl *d, stru
AMEND_WRONG_NODETYPE("deviation", "replace", "max-elements");
}

if (!(target->flags & LYS_SET_MAX)) {
LOGVAL(ctx->ctx, LYVE_REFERENCE, "Invalid deviation replacing \"max-elements\" property which is not present.");
ret = LY_EVALID;
goto cleanup;
}

*num = d->max;
}

Expand Down
16 changes: 0 additions & 16 deletions tests/utests/schema/test_tree_schema_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -3607,10 +3607,6 @@ test_deviation(void **state)
"deviation /top {deviate replace {mandatory true;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid deviation of container node - it is not possible to replace \"mandatory\" property.",
"/kk2:{deviation='/top'}", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module kk3 {namespace urn:kk3;prefix kk3; container top {leaf x {type string;}}"
"deviation /top/x {deviate replace {mandatory true;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid deviation replacing \"mandatory\" property \"mandatory true\" which is not present.",
"/kk3:{deviation='/top/x'}", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module kk4 {namespace urn:kk4;prefix kk4; leaf x {mandatory true; type string;}"
"deviation /x {deviate add {mandatory false;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid deviation adding \"mandatory\" property which already exists (with value \"mandatory true\").",
Expand Down Expand Up @@ -3661,18 +3657,6 @@ test_deviation(void **state)
"deviation /x {deviate add {max-elements 1;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid deviation adding \"max-elements\" property which already exists (with value \"5\").",
"/mm8:{deviation='/x'}", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module mm9 {namespace urn:mm9;prefix mm9; leaf-list x {type string;}"
"deviation /x {deviate replace {min-elements 1;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid deviation replacing \"min-elements\" property which is not present.", "/mm9:{deviation='/x'}", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module mm10 {namespace urn:mm10;prefix mm10; list x {config false;}"
"deviation /x {deviate replace {min-elements 1;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid deviation replacing \"min-elements\" property which is not present.", "/mm10:{deviation='/x'}", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module mm11 {namespace urn:mm11;prefix mm11; leaf-list x {type string;}"
"deviation /x {deviate replace {max-elements 1;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid deviation replacing \"max-elements\" property which is not present.", "/mm11:{deviation='/x'}", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module mm12 {namespace urn:mm12;prefix mm12; list x {config false; }"
"deviation /x {deviate replace {max-elements 1;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid deviation replacing \"max-elements\" property which is not present.", "/mm12:{deviation='/x'}", 0);

assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module nn1 {namespace urn:nn1;prefix nn1; anyxml x;"
"deviation /x {deviate replace {type string;}}}", LYS_IN_YANG, &mod));
Expand Down

0 comments on commit 2063f20

Please sign in to comment.