Skip to content

Commit

Permalink
Fix for features not loading when defined within submodules that augm…
Browse files Browse the repository at this point in the history
…ents external module element
  • Loading branch information
aweast committed Jun 5, 2018
1 parent 8357cd6 commit 1de6c5c
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 7 deletions.
31 changes: 25 additions & 6 deletions src/data_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,25 @@ dm_module_difflist_free(void *item)
free(difflist);
}

/**
* @brief include dependencies in test for has_persist
*/
static bool
dm_module_has_persist(md_module_t *module)
{
CHECK_NULL_ARG(module);
bool has_persist = module->has_persist;

sr_llist_node_t *item = module->deps->first;
while (item && !has_persist) {
md_dep_t *dep = (md_dep_t *)item->data;
has_persist = dep->dest->submodule && dep->dest->has_persist;
item = item->next;
}

return has_persist;
}

/**
* @brief Enables/disables the features in tmp_ctx to match the settings from persist file.
*
Expand All @@ -357,7 +376,7 @@ dm_enable_features_in_tmp_module(dm_ctx_t *dm_ctx, md_module_t *md_module, const
md_dep_t *md_dep = NULL;
bool locked = false;

if (!md_module->has_persist) {
if (!dm_module_has_persist(md_module)) {
return SR_ERR_OK;
}

Expand Down Expand Up @@ -916,7 +935,7 @@ dm_apply_persist_data_for_model_imports(dm_ctx_t *dm_ctx, dm_session_t *session,
ll_node = module->deps->first;
while (ll_node) {
dep = (md_dep_t *) ll_node->data;
if (dep->dest->has_persist) {
if (dm_module_has_persist(dep->dest)) {
if (dep->type == MD_DEP_IMPORT) {
rc = dm_apply_persist_data_for_model_imports(dm_ctx, session, si, dep->dest);
CHECK_RC_LOG_GOTO(rc, cleanup, "Failed to apply features from persist data for module %s", dep->dest->name);
Expand Down Expand Up @@ -1064,7 +1083,7 @@ dm_load_module(dm_ctx_t *dm_ctx, const char *module_name, const char *revision,
CHECK_RC_LOG_GOTO(rc, cleanup, "Failed to initialize private data for module %s", module->name);

/* apply persist data enable features, running datastore */
if (module->has_persist) {
if (dm_module_has_persist(module)) {
rc = dm_apply_persist_data_for_model_imports(dm_ctx, NULL, si, module); /* TODO: session should be known here */
CHECK_RC_LOG_GOTO(rc, cleanup, "Failed to apply persist data for imports of module %s", module_name);
rc = dm_apply_persist_data_for_model(dm_ctx, NULL, module_name, si, false); /* TODO: session should be known here */
Expand All @@ -1074,7 +1093,7 @@ dm_load_module(dm_ctx_t *dm_ctx, const char *module_name, const char *revision,
ll_node = module->deps->first;
while (ll_node) {
dep = (md_dep_t *) ll_node->data;
if (dep->dest->has_persist) {
if (dm_module_has_persist(dep->dest)) {
if (dep->type == MD_DEP_EXTENSION || dep->type == MD_DEP_DATA) {
rc = dm_apply_persist_data_for_model_imports(dm_ctx, NULL, si, dep->dest); /* TODO: session should be known here */
CHECK_RC_LOG_GOTO(rc, cleanup, "Failed to apply persist data for imports of module %s", dep->dest->name);
Expand Down Expand Up @@ -5059,7 +5078,7 @@ dm_install_module(dm_ctx_t *dm_ctx, dm_session_t *session, const char *module_na
rc = dm_init_missing_node_priv_data(si);
CHECK_RC_LOG_GOTO(rc, unlock, "Failed to initialize private data for module %s", module->name);

if (module->has_persist) {
if (dm_module_has_persist(module)) {
rc = dm_apply_persist_data_for_model(dm_ctx, session, module->name, si, false);
CHECK_RC_LOG_GOTO(rc, unlock, "Failed to apply persist data for %s", module->name);
}
Expand Down Expand Up @@ -5091,7 +5110,7 @@ dm_install_module(dm_ctx_t *dm_ctx, dm_session_t *session, const char *module_na
rc = dm_init_missing_node_priv_data(si_ext);
CHECK_RC_LOG_GOTO(rc, unlock, "Failed to initialize private data for module %s", dep->dest->name);

if (module->has_persist) {
if (dm_module_has_persist(module)) {
rc = dm_apply_persist_data_for_model(dm_ctx, session, module->name, si_ext, false);
CHECK_RC_LOG_GOTO(rc, unlock, "Failed to apply persist data for %s", module->name);
}
Expand Down
38 changes: 37 additions & 1 deletion tests/rp_dt_edit_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -2610,6 +2610,11 @@ static int set_items_data_and_feature_import_setup(void **state)
exec_shell_command("../src/sysrepoctl --install --yang=" TEST_SOURCE_DIR "/yang/data-submodule-main.yang", ".*", true, 0);
test_file_exists(TEST_SCHEMA_SEARCH_DIR "data-submodule-main.yang", true);

exec_shell_command("../src/sysrepoctl --install --yang=" TEST_SOURCE_DIR "/yang/feature-submodule-main.yang", ".*", true, 0);
test_file_exists(TEST_SCHEMA_SEARCH_DIR "feature-submodule-main.yang", true);

exec_shell_command("../src/sysrepoctl --feature-enable test-submodule-feature --module feature-submodule-main", ".*", true, 0);

setup(state);

return 0;
Expand All @@ -2634,10 +2639,12 @@ static int set_items_data_and_feature_import_teardown(void **state)
test_file_exists(TEST_SCHEMA_SEARCH_DIR "data-imp-dep-B.yang", false);
exec_shell_command("../src/sysrepoctl --uninstall --module=data-imp-dep-C", ".*", true, 0);
test_file_exists(TEST_SCHEMA_SEARCH_DIR "data-imp-dep-C.yang", false);

exec_shell_command("../src/sysrepoctl --uninstall --module=data-submodule-main", ".*", true, 0);
test_file_exists(TEST_SCHEMA_SEARCH_DIR "data-submodule-main.yang", false);

exec_shell_command("../src/sysrepoctl --uninstall --module=feature-submodule-main", ".*", true, 0);
test_file_exists(TEST_SCHEMA_SEARCH_DIR "feature-submodule-main.yang", false);

teardown(state);

return 0;
Expand Down Expand Up @@ -2730,6 +2737,34 @@ void set_and_get_items_from_top_level_in_submodule(void **state)
test_rp_session_cleanup(ctx, session);
}

void set_and_get_items_from_feature_of_submodule(void **state)
{
int rc;
rp_ctx_t *ctx = *state;
rp_session_t *session = NULL;
sr_error_info_t *errors = NULL;
size_t e_cnt = 0;
dm_commit_context_t *c_ctx = NULL;
sr_val_t *val = NULL;

test_rp_session_create(ctx, SR_DS_STARTUP, &session);
set_item("/feature-submodule-mod:mod-container/feature-submodule-main:augmented-data-val", "aug-data", SR_STRING_T, ctx, session);

rc = rp_dt_commit(ctx, session, &c_ctx, false, &errors, &e_cnt);
assert_int_equal(rc, SR_ERR_OK);
assert_int_equal(e_cnt, 0);
assert_ptr_equal(errors, NULL);

rc = rp_dt_get_value_wrapper(ctx, session, NULL, "/feature-submodule-mod:mod-container/feature-submodule-main:augmented-data-val", &val);
assert_int_equal(SR_ERR_OK, rc);
assert_non_null(val);
assert_int_equal(SR_STRING_T, val->type);
assert_string_equal("aug-data", val->data.string_val);
sr_free_val(val);

test_rp_session_cleanup(ctx, session);
}

int main(){

sr_log_stderr(SR_LL_DBG);
Expand Down Expand Up @@ -2773,6 +2808,7 @@ int main(){
cmocka_unit_test_setup_teardown(set_items_data_and_feature_import, set_items_data_and_feature_import_setup, set_items_data_and_feature_import_teardown),
cmocka_unit_test_setup_teardown(set_items_data_and_import_implemented, set_items_data_and_feature_import_setup, set_items_data_and_feature_import_teardown),
cmocka_unit_test_setup_teardown(set_and_get_items_from_top_level_in_submodule, set_items_data_and_feature_import_setup, set_items_data_and_feature_import_teardown),
cmocka_unit_test_setup_teardown(set_and_get_items_from_feature_of_submodule, set_items_data_and_feature_import_setup, set_items_data_and_feature_import_teardown)
};

watchdog_start(300);
Expand Down
6 changes: 6 additions & 0 deletions tests/yang/feature-submodule-main.yang
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module feature-submodule-main {
namespace "test:feature-submodule-main";
prefix fsm;

include feature-submodule-sub;
}
14 changes: 14 additions & 0 deletions tests/yang/feature-submodule-mod.yang
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module feature-submodule-mod {
namespace "test:feature-submodule-mod";
prefix fsmod;

container mod-container {
description "Top-level container defined in a module";

leaf leaf1 {
description "Leaf of external module";
type string;
}
}

}
23 changes: 23 additions & 0 deletions tests/yang/feature-submodule-sub.yang
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
submodule feature-submodule-sub {
belongs-to feature-submodule-main {
prefix fsm;
}

import feature-submodule-mod {
prefix fsmod;
}

feature test-submodule-feature {
description
"Submodule feature used for tests.";
}

augment "/fsmod:mod-container" {
leaf augmented-data-val {
if-feature test-submodule-feature;
type string;
description
"Test data for feature dependent leaf.";
}
}
}

0 comments on commit 1de6c5c

Please sign in to comment.