Skip to content

Commit

Permalink
system-plugin: remove storing to startup DS on every change and plugi…
Browse files Browse the repository at this point in the history
…n cleanup
  • Loading branch information
zinccyy committed Oct 25, 2022
1 parent e6ca7da commit 25b834e
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 103 deletions.
10 changes: 5 additions & 5 deletions src/startup/load.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ static int system_startup_load_timezone_name(void *priv, sr_session_ctx_t *sessi
struct lyd_node *clock_container_node = NULL;
bool timezone_name_enabled = false;

SRPC_SAFE_CALL(srpc_check_feature_status(ctx->startup_session, BASE_YANG_MODULE, "timezone-name", &timezone_name_enabled), error_out);
SRPC_SAFE_CALL_ERR(error, srpc_check_feature_status(ctx->startup_session, BASE_YANG_MODULE, "timezone-name", &timezone_name_enabled), error_out);

if (timezone_name_enabled) {
error = system_load_timezone_name(ctx, timezone_name_buffer);
Expand Down Expand Up @@ -233,8 +233,8 @@ static int system_startup_load_ntp(void *priv, sr_session_ctx_t *session, const

SRPLG_LOG_INF(PLUGIN_NAME, "Loading NTP data");

SRPC_SAFE_CALL(srpc_check_feature_status(ctx->startup_session, BASE_YANG_MODULE, "ntp", &ntp_enabled), error_out);
SRPC_SAFE_CALL(srpc_check_feature_status(ctx->startup_session, BASE_YANG_MODULE, "ntp-udp-port", &ntp_udp_port_enabled), error_out);
SRPC_SAFE_CALL_ERR(error, srpc_check_feature_status(ctx->startup_session, BASE_YANG_MODULE, "ntp", &ntp_enabled), error_out);
SRPC_SAFE_CALL_ERR(error, srpc_check_feature_status(ctx->startup_session, BASE_YANG_MODULE, "ntp-udp-port", &ntp_udp_port_enabled), error_out);

if (ntp_enabled) {
error = system_ly_tree_create_ntp(ly_ctx, parent_node, &ntp_container_node);
Expand Down Expand Up @@ -432,8 +432,8 @@ static int system_startup_load_authentication(void *priv, sr_session_ctx_t *sess
bool enabled_authentication = false;
bool enabled_local_users = false;

SRPC_SAFE_CALL(srpc_check_feature_status(ctx->startup_session, BASE_YANG_MODULE, "authentication", &enabled_authentication), error_out);
SRPC_SAFE_CALL(srpc_check_feature_status(ctx->startup_session, BASE_YANG_MODULE, "local-users", &enabled_local_users), error_out);
SRPC_SAFE_CALL_ERR(error, srpc_check_feature_status(ctx->startup_session, BASE_YANG_MODULE, "authentication", &enabled_authentication), error_out);
SRPC_SAFE_CALL_ERR(error, srpc_check_feature_status(ctx->startup_session, BASE_YANG_MODULE, "local-users", &enabled_local_users), error_out);

if (enabled_authentication) {
// create authentication container
Expand Down
10 changes: 5 additions & 5 deletions src/startup/store.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ static int system_startup_store_timezone_name(void *priv, const struct lyd_node

struct lyd_node *clock_container_node = NULL, *timezone_name_node = NULL;

SRPC_SAFE_CALL(srpc_check_feature_status(ctx->startup_session, BASE_YANG_MODULE, "timezone-name", &timezone_name_enabled), error_out);
SRPC_SAFE_CALL_ERR(error, srpc_check_feature_status(ctx->startup_session, BASE_YANG_MODULE, "timezone-name", &timezone_name_enabled), error_out);

if (timezone_name_enabled) {
clock_container_node = srpc_ly_tree_get_child_container(system_container_node, "clock");
Expand Down Expand Up @@ -309,8 +309,8 @@ static int system_startup_store_ntp(void *priv, const struct lyd_node *system_co
system_ntp_server_t temp_server = {0};
srpc_check_status_t server_check_status = srpc_check_status_none;

SRPC_SAFE_CALL(srpc_check_feature_status(ctx->startup_session, BASE_YANG_MODULE, "ntp", &ntp_enabled), error_out);
SRPC_SAFE_CALL(srpc_check_feature_status(ctx->startup_session, BASE_YANG_MODULE, "ntp-udp-port", &ntp_udp_port_enabled), error_out);
SRPC_SAFE_CALL_ERR(error, srpc_check_feature_status(ctx->startup_session, BASE_YANG_MODULE, "ntp", &ntp_enabled), error_out);
SRPC_SAFE_CALL_ERR(error, srpc_check_feature_status(ctx->startup_session, BASE_YANG_MODULE, "ntp-udp-port", &ntp_udp_port_enabled), error_out);

if (ntp_enabled) {
SRPLG_LOG_INF(PLUGIN_NAME, "Storing NTP startup data");
Expand Down Expand Up @@ -729,8 +729,8 @@ static int system_startup_store_authentication(void *priv, const struct lyd_node
// srpc
srpc_check_status_t user_check_status = srpc_check_status_none, key_check_status = srpc_check_status_none;

SRPC_SAFE_CALL(srpc_check_feature_status(ctx->startup_session, BASE_YANG_MODULE, "authentication", &authentication_enabled), error_out);
SRPC_SAFE_CALL(srpc_check_feature_status(ctx->startup_session, BASE_YANG_MODULE, "local-users", &local_users_enabled), error_out);
SRPC_SAFE_CALL_ERR(error, srpc_check_feature_status(ctx->startup_session, BASE_YANG_MODULE, "authentication", &authentication_enabled), error_out);
SRPC_SAFE_CALL_ERR(error, srpc_check_feature_status(ctx->startup_session, BASE_YANG_MODULE, "local-users", &local_users_enabled), error_out);

if (authentication_enabled) {
SRPLG_LOG_INF(PLUGIN_NAME, "Storing authentication startup data");
Expand Down
93 changes: 7 additions & 86 deletions src/subscription/change.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,6 @@ int system_subscription_change_contact(sr_session_ctx_t *session, uint32_t subsc
if (event == SR_EV_ABORT) {
SRPLG_LOG_ERR(PLUGIN_NAME, "Aborting changes for %s", xpath);
goto error_out;
} else if (event == SR_EV_DONE) {
error = sr_copy_config(ctx->startup_session, BASE_YANG_MODULE, SR_DS_RUNNING, 0);
if (error) {
SRPLG_LOG_ERR(PLUGIN_NAME, "sr_copy_config() error (%d): %s", error, sr_strerror(error));
goto error_out;
}
} else if (event == SR_EV_CHANGE) {
error = srpc_iterate_changes(ctx, session, xpath, system_change_contact, NULL, NULL);
if (error) {
Expand All @@ -92,12 +86,6 @@ int system_subscription_change_hostname(sr_session_ctx_t *session, uint32_t subs
if (event == SR_EV_ABORT) {
SRPLG_LOG_ERR(PLUGIN_NAME, "Aborting changes for %s", xpath);
goto error_out;
} else if (event == SR_EV_DONE) {
error = sr_copy_config(ctx->startup_session, BASE_YANG_MODULE, SR_DS_RUNNING, 0);
if (error) {
SRPLG_LOG_ERR(PLUGIN_NAME, "sr_copy_config() error (%d): %s", error, sr_strerror(error));
goto error_out;
}
} else if (event == SR_EV_CHANGE) {
error = srpc_iterate_changes(ctx, session, xpath, system_change_hostname, NULL, NULL);
if (error) {
Expand All @@ -123,12 +111,6 @@ int system_subscription_change_location(sr_session_ctx_t *session, uint32_t subs
if (event == SR_EV_ABORT) {
SRPLG_LOG_ERR(PLUGIN_NAME, "Aborting changes for %s", xpath);
goto error_out;
} else if (event == SR_EV_DONE) {
error = sr_copy_config(ctx->startup_session, BASE_YANG_MODULE, SR_DS_RUNNING, 0);
if (error) {
SRPLG_LOG_ERR(PLUGIN_NAME, "sr_copy_config() error (%d): %s", error, sr_strerror(error));
goto error_out;
}
} else if (event == SR_EV_CHANGE) {
error = srpc_iterate_changes(ctx, session, xpath, system_change_location, NULL, NULL);
if (error) {
Expand Down Expand Up @@ -157,14 +139,8 @@ int system_subscription_change_timezone_name(sr_session_ctx_t *session, uint32_t
if (event == SR_EV_ABORT) {
SRPLG_LOG_ERR(PLUGIN_NAME, "aborting changes for: %s", xpath);
goto error_out;
} else if (event == SR_EV_DONE) {
error = sr_copy_config(ctx->startup_session, BASE_YANG_MODULE, SR_DS_RUNNING, 0);
if (error) {
SRPLG_LOG_ERR(PLUGIN_NAME, "sr_copy_config() error (%d): %s", error, sr_strerror(error));
goto error_out;
}
} else if (event == SR_EV_CHANGE) {
SRPC_SAFE_CALL(srpc_check_feature_status(session, BASE_YANG_MODULE, "timezone-name", &timezone_name_enabled), error_out);
SRPC_SAFE_CALL_ERR(error, srpc_check_feature_status(session, BASE_YANG_MODULE, "timezone-name", &timezone_name_enabled), error_out);

if (timezone_name_enabled) {
error = srpc_iterate_changes(ctx, session, xpath, system_change_timezone_name, NULL, NULL);
Expand Down Expand Up @@ -192,12 +168,6 @@ int system_subscription_change_timezone_utc_offset(sr_session_ctx_t *session, ui
if (event == SR_EV_ABORT) {
SRPLG_LOG_ERR(PLUGIN_NAME, "aborting changes for: %s", xpath);
goto error_out;
} else if (event == SR_EV_DONE) {
error = sr_copy_config(ctx->startup_session, BASE_YANG_MODULE, SR_DS_RUNNING, 0);
if (error) {
SRPLG_LOG_ERR(PLUGIN_NAME, "sr_copy_config() error (%d): %s", error, sr_strerror(error));
goto error_out;
}
} else if (event == SR_EV_CHANGE) {
SRPLG_LOG_ERR(PLUGIN_NAME, "Unsupported option for now");
}
Expand All @@ -222,18 +192,12 @@ int system_subscription_change_ntp_enabled(sr_session_ctx_t *session, uint32_t s
SRPLG_LOG_ERR(PLUGIN_NAME, "aborting changes for: %s", xpath);
error = -1;
goto error_out;
} else if (event == SR_EV_DONE) {
error = sr_copy_config(ctx->startup_session, BASE_YANG_MODULE, SR_DS_RUNNING, 0);
if (error) {
SRPLG_LOG_ERR(PLUGIN_NAME, "sr_copy_config error (%d): %s", error, sr_strerror(error));
goto error_out;
}
} else if (event == SR_EV_CHANGE) {
// get feature status
SRPC_SAFE_CALL(srpc_check_feature_status(session, BASE_YANG_MODULE, "ntp", &ntp_enabled), error_out);
SRPC_SAFE_CALL_ERR(error, srpc_check_feature_status(session, BASE_YANG_MODULE, "ntp", &ntp_enabled), error_out);

if (ntp_enabled) {
SRPC_SAFE_CALL(srpc_iterate_changes(ctx, session, xpath, system_ntp_change_enabled, NULL, NULL), error_out);
SRPC_SAFE_CALL_ERR(error, srpc_iterate_changes(ctx, session, xpath, system_ntp_change_enabled, NULL, NULL), error_out);
}
}

Expand Down Expand Up @@ -261,19 +225,13 @@ int system_subscription_change_ntp_server(sr_session_ctx_t *session, uint32_t su
SRPLG_LOG_ERR(PLUGIN_NAME, "aborting changes for: %s", xpath);
error = -1;
goto error_out;
} else if (event == SR_EV_DONE) {
error = sr_copy_config(ctx->startup_session, BASE_YANG_MODULE, SR_DS_RUNNING, 0);
if (error) {
SRPLG_LOG_ERR(PLUGIN_NAME, "sr_copy_config error (%d): %s", error, sr_strerror(error));
goto error_out;
}
} else if (event == SR_EV_CHANGE) {
// make sure the last change servers were free'd and set to NULL
assert(ctx->temp_ntp_servers == NULL);

// get features
SRPC_SAFE_CALL(srpc_check_feature_status(session, BASE_YANG_MODULE, "ntp", &ntp_enabled), error_out);
SRPC_SAFE_CALL(srpc_check_feature_status(session, BASE_YANG_MODULE, "ntp-udp-port", &ntp_udp_port_enabled), error_out);
SRPC_SAFE_CALL_ERR(error, srpc_check_feature_status(session, BASE_YANG_MODULE, "ntp", &ntp_enabled), error_out);
SRPC_SAFE_CALL_ERR(error, srpc_check_feature_status(session, BASE_YANG_MODULE, "ntp-udp-port", &ntp_udp_port_enabled), error_out);

if (ntp_enabled) {
// load all system NTP servers
Expand Down Expand Up @@ -414,13 +372,6 @@ int system_subscription_change_dns_resolver_search(sr_session_ctx_t *session, ui
SRPLG_LOG_ERR(PLUGIN_NAME, "aborting changes for: %s", xpath);
error = -1;
goto error_out;
} else if (event == SR_EV_DONE) {
SRPLG_LOG_INF(PLUGIN_NAME, "Done processing changes - storing data into startup");
error = sr_copy_config(ctx->startup_session, BASE_YANG_MODULE, SR_DS_RUNNING, 0);
if (error) {
SRPLG_LOG_ERR(PLUGIN_NAME, "sr_copy_config error (%d): %s", error, sr_strerror(error));
goto error_out;
}
} else if (event == SR_EV_CHANGE) {
// make sure the last change search values were free'd and set to NULL
assert(ctx->temp_dns_search == NULL);
Expand Down Expand Up @@ -481,12 +432,6 @@ int system_subscription_change_dns_resolver_server(sr_session_ctx_t *session, ui
SRPLG_LOG_ERR(PLUGIN_NAME, "aborting changes for: %s", xpath);
error = -1;
goto error_out;
} else if (event == SR_EV_DONE) {
error = sr_copy_config(ctx->startup_session, BASE_YANG_MODULE, SR_DS_RUNNING, 0);
if (error) {
SRPLG_LOG_ERR(PLUGIN_NAME, "sr_copy_config error (%d): %s", error, sr_strerror(error));
goto error_out;
}
} else if (event == SR_EV_CHANGE) {
// make sure the last change servers were free'd and set to NULL
assert(ctx->temp_dns_servers == NULL);
Expand Down Expand Up @@ -575,12 +520,6 @@ int system_subscription_change_dns_resolver_timeout(sr_session_ctx_t *session, u
SRPLG_LOG_ERR(PLUGIN_NAME, "aborting changes for: %s", xpath);
error = -1;
goto error_out;
} else if (event == SR_EV_DONE) {
error = sr_copy_config(ctx->startup_session, BASE_YANG_MODULE, SR_DS_RUNNING, 0);
if (error) {
SRPLG_LOG_ERR(PLUGIN_NAME, "sr_copy_config error (%d): %s", error, sr_strerror(error));
goto error_out;
}
} else if (event == SR_EV_CHANGE) {
SRPLG_LOG_ERR(PLUGIN_NAME, "Unsupported option for now");
}
Expand All @@ -601,12 +540,6 @@ int system_subscription_change_dns_resolver_attempts(sr_session_ctx_t *session,
SRPLG_LOG_ERR(PLUGIN_NAME, "aborting changes for: %s", xpath);
error = -1;
goto error_out;
} else if (event == SR_EV_DONE) {
error = sr_copy_config(ctx->startup_session, BASE_YANG_MODULE, SR_DS_RUNNING, 0);
if (error) {
SRPLG_LOG_ERR(PLUGIN_NAME, "sr_copy_config error (%d): %s", error, sr_strerror(error));
goto error_out;
}
} else if (event == SR_EV_CHANGE) {
SRPLG_LOG_ERR(PLUGIN_NAME, "Unsupported option for now");
}
Expand All @@ -628,12 +561,6 @@ int system_subscription_change_authentication_user_authentication_order(sr_sessi
SRPLG_LOG_ERR(PLUGIN_NAME, "aborting changes for: %s", xpath);
error = -1;
goto error_out;
} else if (event == SR_EV_DONE) {
error = sr_copy_config(ctx->startup_session, BASE_YANG_MODULE, SR_DS_RUNNING, 0);
if (error) {
SRPLG_LOG_ERR(PLUGIN_NAME, "sr_copy_config error (%d): %s", error, sr_strerror(error));
goto error_out;
}
} else if (event == SR_EV_CHANGE) {
}

Expand All @@ -660,20 +587,14 @@ int system_subscription_change_authentication_user(sr_session_ctx_t *session, ui
SRPLG_LOG_ERR(PLUGIN_NAME, "aborting changes for: %s", xpath);
error = -1;
goto error_out;
} else if (event == SR_EV_DONE) {
error = sr_copy_config(ctx->startup_session, BASE_YANG_MODULE, SR_DS_RUNNING, 0);
if (error) {
SRPLG_LOG_ERR(PLUGIN_NAME, "sr_copy_config error (%d): %s", error, sr_strerror(error));
goto error_out;
}
} else if (event == SR_EV_CHANGE) {
// assert user database is NULL from the last change
assert(ctx->temp_users.created == NULL);
assert(ctx->temp_users.modified == NULL);
assert(ctx->temp_users.deleted == NULL);

SRPC_SAFE_CALL(srpc_check_feature_status(session, BASE_YANG_MODULE, "authentication", &authentication_enabled), error_out);
SRPC_SAFE_CALL(srpc_check_feature_status(session, BASE_YANG_MODULE, "local-users", &local_users_enabled), error_out);
SRPC_SAFE_CALL_ERR(error, srpc_check_feature_status(session, BASE_YANG_MODULE, "authentication", &authentication_enabled), error_out);
SRPC_SAFE_CALL_ERR(error, srpc_check_feature_status(session, BASE_YANG_MODULE, "local-users", &local_users_enabled), error_out);

if (authentication_enabled && local_users_enabled) {
// load current users into modifed list so they can also be modified
Expand Down
2 changes: 1 addition & 1 deletion src/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ int sr_plugin_init_cb(sr_session_ctx_t *running_session, void **private_data)
const char *feature = features[i];
bool enabled = false;

SRPC_SAFE_CALL(srpc_check_feature_status(running_session, "ietf-system", feature, &enabled), error_out);
SRPC_SAFE_CALL_ERR(error, srpc_check_feature_status(running_session, "ietf-system", feature, &enabled), error_out);

SRPLG_LOG_INF(PLUGIN_NAME, "ietf-system feature \"%s\" status = %s", feature, enabled ? "enabled" : "disabled");
}
Expand Down
12 changes: 6 additions & 6 deletions src/system/api/ntp/change.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ int system_ntp_change_enabled(void *priv, sr_session_ctx_t *session, const srpc_
case SR_OP_CREATED:
case SR_OP_MODIFIED:
if (enabled) {
SRPC_SAFE_CALL(system("systemctl start ntp"), error_out);
SRPC_SAFE_CALL(system("systemctl enable ntp"), error_out);
SRPC_SAFE_CALL_ERR(error, system("systemctl start ntp"), error_out);
SRPC_SAFE_CALL_ERR(error, system("systemctl enable ntp"), error_out);
} else {
SRPC_SAFE_CALL(system("systemctl stop ntp"), error_out);
SRPC_SAFE_CALL(system("systemctl disable ntp"), error_out);
SRPC_SAFE_CALL_ERR(error, system("systemctl stop ntp"), error_out);
SRPC_SAFE_CALL_ERR(error, system("systemctl disable ntp"), error_out);
}
break;
case SR_OP_DELETED:
// set default value = true
SRPC_SAFE_CALL(system("systemctl start ntp"), error_out);
SRPC_SAFE_CALL(system("systemctl enable ntp"), error_out);
SRPC_SAFE_CALL_ERR(error, system("systemctl start ntp"), error_out);
SRPC_SAFE_CALL_ERR(error, system("systemctl enable ntp"), error_out);
break;
case SR_OP_MOVED:
break;
Expand Down

0 comments on commit 25b834e

Please sign in to comment.