Skip to content

Commit

Permalink
lib UPDATE leverage sysrepo install modules update
Browse files Browse the repository at this point in the history
  • Loading branch information
michalvasko committed May 31, 2024
1 parent fb94468 commit 00ce3ad
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 93 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ set(LIBNETCONF2_DEP_SOVERSION 4.2.0)
set(LIBNETCONF2_DEP_SOVERSION_MAJOR 4)

# sysrepo required version
set(SYSREPO_DEP_VERSION 2.2.159)
set(SYSREPO_DEP_SOVERSION 7.24.0)
set(SYSREPO_DEP_VERSION 2.5.0)
set(SYSREPO_DEP_SOVERSION 7.25.6)
set(SYSREPO_DEP_SOVERSION_MAJOR 7)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -std=c99")
Expand Down
91 changes: 0 additions & 91 deletions lib/np2_sr_setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,88 +30,6 @@
#define ERR(msg, ...) fprintf(stderr, msg "\n", __VA_ARGS__)
#define ERRMSG(msg) fprintf(stderr, msg "\n")

/**
* @brief Check a module in the specific revision and all the features is not already installed.
*
* @param[in] file YANG module file name.
* @param[in] features Array of enabled features.
* @param[in] conn Sysrepo connection to use.
* @param[out] processed Whether the module needs tobe installed or was processed.
* @return 0 on success.
* @return non-zero on error.
*/
static int
np2_sr_setup_mod_check(const char *file, const char **features, sr_conn_ctx_t *conn, int *processed)
{
int rc = 0, i, r;
const struct ly_ctx *ctx = sr_acquire_context(conn);
const struct lys_module *mod;
const char *ptr;
char *name = NULL, *revision = NULL;
LY_ERR lyrc;

*processed = 0;

/* parse name and revision */
ptr = strchr(file, '@');
name = strndup(file, ptr - file);
++ptr;
revision = strndup(ptr, strlen(ptr) - 5);
if (!name || !revision) {
ERRMSG("Failed to allocate memory.");
rc = 1;
goto cleanup;
}

/* check the file is installed */
mod = ly_ctx_get_module_implemented(ctx, name);
if (!mod) {
goto cleanup;
}
if (!revision || strcmp(mod->revision, revision)) {
/* different revision, will fail during installation */
goto cleanup;
}

/* we will adjust enabled features */
*processed = 1;

if (!features) {
goto cleanup;
}

/* check/enable all the features */
for (i = 0; features[i]; ++i) {
lyrc = lys_feature_value(mod, features[i]);
if (lyrc == LY_ENOTFOUND) {
ERR("Failed to find feature \"%s\" in \"%s\".", features[i], name);
rc = 1;
goto cleanup;
}

if (lyrc == LY_ENOT) {
/* enable feature, context will be changed */
sr_release_context(conn);
r = sr_enable_module_feature(conn, name, features[i]);
ctx = sr_acquire_context(conn);

if (r) {
ERR("Failed to enable feature \"%s\" in \"%s\".", features[i], name);
rc = 1;
goto cleanup;
}

mod = ly_ctx_get_module_implemented(ctx, name);
}
}

cleanup:
sr_release_context(conn);
free(name);
free(revision);
return rc;
}

int
np2_sr_setup(const char *owner, const char *group, mode_t perm)
{
Expand Down Expand Up @@ -157,15 +75,6 @@ np2_sr_setup(const char *owner, const char *group, mode_t perm)
}
mod_count = 0;
for (i = 0; i < yang_install_count; ++i) {
/* first check that the module is not installed already and all its features enabled */
if (np2_sr_setup_mod_check(yang_install[i], yang_features[i], conn, &r)) {
rc = 1;
goto cleanup;
}
if (r) {
continue;
}

mods[mod_count].schema_path = yang_install[i];
mods[mod_count].features = yang_features[i];
mods[mod_count].owner = owner;
Expand Down

0 comments on commit 00ce3ad

Please sign in to comment.