Skip to content

Commit

Permalink
Move operational data about software state from confd => yanger
Browse files Browse the repository at this point in the history
Statd is now responsible for operational, move last big part
(infix-system-software) to yanger.
  • Loading branch information
mattiaswal committed Dec 13, 2024
1 parent 34f0c5a commit 0b5a305
Show file tree
Hide file tree
Showing 14 changed files with 329 additions and 189 deletions.
2 changes: 2 additions & 0 deletions configs/aarch64_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ BR2_PACKAGE_RAUC=y
BR2_PACKAGE_RAUC_DBUS=y
BR2_PACKAGE_RAUC_GPT=y
BR2_PACKAGE_RAUC_NETWORK=y
BR2_PACKAGE_RAUC_JSON=y
BR2_PACKAGE_SYSKLOGD=y
BR2_PACKAGE_SYSKLOGD_LOGGER=y
BR2_PACKAGE_WATCHDOGD=y
Expand Down Expand Up @@ -161,6 +162,7 @@ BR2_PACKAGE_TETRIS=y
BR2_PACKAGE_ROUSETTE=y
BR2_PACKAGE_LIBINPUT=y
BR2_PACKAGE_HOST_PYTHON_YANGDOC=y
BR2_PACKAGE_RAUC_INSTALLATION_STATUS=y
DISK_IMAGE_BOOT_BIN=y
TRUSTED_KEYS=y
TRUSTED_KEYS_DEVELOPMENT=y
Expand Down
2 changes: 2 additions & 0 deletions configs/aarch64_minimal_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ BR2_PACKAGE_RAUC=y
BR2_PACKAGE_RAUC_DBUS=y
BR2_PACKAGE_RAUC_GPT=y
BR2_PACKAGE_RAUC_NETWORK=y
BR2_PACKAGE_RAUC_JSON=y
BR2_PACKAGE_SYSKLOGD=y
BR2_PACKAGE_SYSKLOGD_LOGGER=y
BR2_PACKAGE_WATCHDOGD=y
Expand Down Expand Up @@ -134,6 +135,7 @@ BR2_PACKAGE_MCD=y
BR2_PACKAGE_MDNS_ALIAS=y
BR2_PACKAGE_LIBINPUT=y
BR2_PACKAGE_ROUSETTE=y
BR2_PACKAGE_RAUC_INSTALLATION_STATUS=y
DISK_IMAGE_BOOT_BIN=y
TRUSTED_KEYS=y
TRUSTED_KEYS_DEVELOPMENT=y
Expand Down
2 changes: 2 additions & 0 deletions configs/x86_64_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ BR2_PACKAGE_RAUC=y
BR2_PACKAGE_RAUC_DBUS=y
BR2_PACKAGE_RAUC_GPT=y
BR2_PACKAGE_RAUC_NETWORK=y
BR2_PACKAGE_RAUC_JSON=y
BR2_PACKAGE_SYSKLOGD=y
BR2_PACKAGE_SYSKLOGD_LOGGER=y
BR2_PACKAGE_WATCHDOGD=y
Expand Down Expand Up @@ -164,6 +165,7 @@ BR2_PACKAGE_PODMAN_DRIVER_VFS=y
BR2_PACKAGE_TETRIS=y
BR2_PACKAGE_ROUSETTE=y
BR2_PACKAGE_HOST_PYTHON_YANGDOC=y
BR2_PACKAGE_RAUC_INSTALLATION_STATUS=y
TRUSTED_KEYS=y
TRUSTED_KEYS_DEVELOPMENT=y
GNS3_APPLIANCE_RAM=512
Expand Down
2 changes: 2 additions & 0 deletions configs/x86_64_minimal_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ BR2_PACKAGE_RAUC=y
BR2_PACKAGE_RAUC_DBUS=y
BR2_PACKAGE_RAUC_GPT=y
BR2_PACKAGE_RAUC_NETWORK=y
BR2_PACKAGE_RAUC_JSON=y
BR2_PACKAGE_SYSKLOGD=y
BR2_PACKAGE_SYSKLOGD_LOGGER=y
BR2_PACKAGE_WATCHDOGD=y
Expand Down Expand Up @@ -137,6 +138,7 @@ BR2_PACKAGE_LOWDOWN=y
BR2_PACKAGE_MCD=y
BR2_PACKAGE_MDNS_ALIAS=y
BR2_PACKAGE_ROUSETTE=y
BR2_PACKAGE_RAUC_INSTALLATION_STATUS=y
TRUSTED_KEYS=y
TRUSTED_KEYS_DEVELOPMENT=y
GNS3_APPLIANCE_RAM=512
Expand Down
1 change: 1 addition & 0 deletions package/Config.in
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@ source "$BR2_EXTERNAL_INFIX_PATH/package/sysrepo-cpp/Config.in"
source "$BR2_EXTERNAL_INFIX_PATH/package/rousette/Config.in"
source "$BR2_EXTERNAL_INFIX_PATH/package/nghttp2-asio/Config.in"
source "$BR2_EXTERNAL_INFIX_PATH/package/date-cpp/Config.in"
source "$BR2_EXTERNAL_INFIX_PATH/package/rauc-installation-status/Config.in"

endmenu
7 changes: 7 additions & 0 deletions package/rauc-installation-status/Config.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
config BR2_PACKAGE_RAUC_INSTALLATION_STATUS
bool rauc-installation-status
help
Simple tool to read the installation status and errors
from rauc in a JSON format.

https://github.com/kernelkit/infix
20 changes: 20 additions & 0 deletions package/rauc-installation-status/rauc-installation-status.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
################################################################################
#
# rauc installation status
#
################################################################################

RAUC_INSTALLATION_STATUS_VERSION = 1.0
RAUC_INSTALLATION_STATUS_LICENSE = ISC
RAUC_INSTALLATION_STATUS_LICENSE_FILES = LICENSE
RAUC_INSTALLATION_STATUS_SITE_METHOD = local
RAUC_INSTALLATION_STATUS_SITE = $(BR2_EXTERNAL_INFIX_PATH)/src/rauc-installation-status
RAUC_INSTALLATION_STATUS_REDISTRIBUTE = NO
RAUC_INSTALLATION_STATUS_AUTORECONF = YES
RAUC_INSTALLATION_STATUS_DEPENDENCIES = host-pkgconf jansson libglib2
RAUC_INSTALLATION_STATUS_CONF_OPTS = --disable-silent-rules
define RAUC_INSTALLATION_STATUS_CONF_ENV
CFLAGS="$(INFIX_CFLAGS)"
endef

$(eval $(autotools-package))
189 changes: 0 additions & 189 deletions src/confd/src/infix-system-software.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "core.h"
#include "rauc-installer.h"

#define SW_STATE_PATH_ "/ietf-system:system-state/infix-system:software"

static RaucInstaller *infix_system_sw_new_rauc(void)
{
Expand All @@ -25,191 +24,6 @@ static RaucInstaller *infix_system_sw_new_rauc(void)
return rauc;
}

static sr_error_t infix_system_sw_state_fill_installer(struct lyd_node *inst,
RaucInstaller *rauc)
{
struct lyd_node *progress;
GVariant *props, *val;
const char *strval;

strval = rauc_installer_get_operation(rauc);
if (strval && strval[0] &&
lyd_new_term(inst, NULL, "operation", strval, 0, NULL))
return SR_ERR_INTERNAL;

strval = rauc_installer_get_last_error(rauc);
if (strval && strval[0] &&
lyd_new_term(inst, NULL, "last-error", strval, 0, NULL))
return SR_ERR_INTERNAL;

props = rauc_installer_get_progress(rauc);
if (props) {
if (lyd_new_inner(inst, NULL, "progress", 0, &progress))
return SR_ERR_INTERNAL;

g_variant_get(props, "(@isi)", &val, &strval, NULL);

if (lyd_new_term(progress, NULL, "percentage",
g_variant_print(val, FALSE), 0, NULL))
return SR_ERR_INTERNAL;

if (strval && strval[0] &&
lyd_new_term(progress, NULL, "message", strval, 0, NULL))
return SR_ERR_INTERNAL;
}
return SR_ERR_OK;
}

static sr_error_t infix_system_sw_state_fill_slot(struct lyd_node *slot,
GVariant *props)
{
static const char *strprops[] = {
"bootname",
"class",
"state",
"sha256",
NULL
};
struct lyd_node *section;
const char **strprop;
const char *strval;
GVariant *val;

for (strprop = strprops; *strprop; strprop++) {
if (g_variant_lookup(props, *strprop, "s", &strval) &&
lyd_new_term(slot, NULL, *strprop, strval, 0, NULL))
return SR_ERR_INTERNAL;
}

if (g_variant_lookup(props, "size", "@t", &val) &&
lyd_new_term(slot, NULL, "size", g_variant_print(val, FALSE), 0, NULL))
return SR_ERR_INTERNAL;


if (lyd_new_inner(slot, NULL, "bundle", 0, &section))
return SR_ERR_INTERNAL;

if (g_variant_lookup(props, "bundle.compatible", "s", &strval) &&
lyd_new_term(section, NULL, "compatible", strval, 0, NULL))
return SR_ERR_INTERNAL;

if (g_variant_lookup(props, "bundle.version", "s", &strval) &&
lyd_new_term(section, NULL, "version", strval, 0, NULL))
return SR_ERR_INTERNAL;


if (lyd_new_inner(slot, NULL, "installed", 0, &section))
return SR_ERR_INTERNAL;

if (g_variant_lookup(props, "installed.timestamp", "s", &strval) &&
lyd_new_term(section, NULL, "datetime", strval, 0, NULL))
return SR_ERR_INTERNAL;

if (g_variant_lookup(props, "installed.count", "@u", &val) &&
lyd_new_term(section, NULL, "count", g_variant_print(val, FALSE), 0, NULL))
return SR_ERR_INTERNAL;


if (lyd_new_inner(slot, NULL, "activated", 0, &section))
return SR_ERR_INTERNAL;

if (g_variant_lookup(props, "activated.timestamp", "s", &strval) &&
lyd_new_term(section, NULL, "datetime", strval, 0, NULL))
return SR_ERR_INTERNAL;

if (g_variant_lookup(props, "activated.count", "@u", &val) &&
lyd_new_term(section, NULL, "count", g_variant_print(val, FALSE), 0, NULL))
return SR_ERR_INTERNAL;

return SR_ERR_OK;
}

static sr_error_t infix_system_sw_state_fill(struct lyd_node *sw,
RaucInstaller *rauc)
{
struct lyd_node *slot, *inst;
GVariant *slots, *props;
GError *raucerr = NULL;
GVariantIter slotiter;
sr_error_t srerr;
char *slotname;
const char *val;

val = rauc_installer_get_compatible(rauc);
if (val && val[0] && lyd_new_term(sw, NULL, "compatible", val, 0, NULL))
return SR_ERR_INTERNAL;

val = rauc_installer_get_variant(rauc);
if (val && val[0] && lyd_new_term(sw, NULL, "variant", val, 0, NULL))
return SR_ERR_INTERNAL;

val = rauc_installer_get_boot_slot(rauc);
if (val && val[0] && lyd_new_term(sw, NULL, "booted", val, 0, NULL))
return SR_ERR_INTERNAL;

if (lyd_new_inner(sw, NULL, "installer", 0, &inst))
return SR_ERR_INTERNAL;

srerr = infix_system_sw_state_fill_installer(inst, rauc);
if (srerr)
return srerr;

if (!rauc_installer_call_get_slot_status_sync(rauc, &slots, NULL, &raucerr)) {
/* Slot status is not available while an installation
* is in progress, so we don't consider that an error.
*/
g_error_free(raucerr);
return SR_ERR_OK;
}

for (g_variant_iter_init(&slotiter, slots);
g_variant_iter_next(&slotiter, "(s@a{sv})", &slotname, &props);) {
if (lyd_new_list(sw, NULL, "slot", 0, &slot, slotname))
return SR_ERR_INTERNAL;

srerr = infix_system_sw_state_fill_slot(slot, props);
if (srerr)
break;
}

return srerr;
}

static int infix_system_sw_state(sr_session_ctx_t *session, uint32_t sub_id,
const char *module, const char *path,
const char *request_path, uint32_t request_id,
struct lyd_node **parent, void *priv)
{
sr_error_t srerr = SR_ERR_INTERNAL;
const struct lys_module *ixsys;
const struct ly_ctx *ly;
RaucInstaller *rauc;
struct lyd_node *sw;

DEBUG("%s", path);

rauc = infix_system_sw_new_rauc();
if (!rauc)
return SR_ERR_INTERNAL;

ly = sr_acquire_context(sr_session_get_connection(session));
ixsys = ly_ctx_get_module_implemented(ly, "infix-system");
sr_release_context(sr_session_get_connection(session));
if (!ixsys) {
ERROR("infix-system module not found");
goto out;
}

if (lyd_new_inner(*parent, ixsys, "software", 0, &sw))
goto out;

srerr = infix_system_sw_state_fill(sw, rauc);
out:
g_object_unref(rauc);
return srerr;
}


static int infix_system_sw_install(sr_session_ctx_t *session, uint32_t sub_id,
const char *path, const sr_val_t *input,
const size_t input_cnt, sr_event_t event,
Expand Down Expand Up @@ -243,9 +57,6 @@ int infix_system_sw_init(struct confd *confd)
{
int rc = 0;

REGISTER_OPER(confd->session, "ietf-system", SW_STATE_PATH_,
infix_system_sw_state, NULL, 0, &confd->sub);

REGISTER_RPC(confd->session, "/infix-system:install-bundle",
infix_system_sw_install, NULL, &confd->sub);

Expand Down
14 changes: 14 additions & 0 deletions src/rauc-installation-status/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Copyright (c) 2024 The KernelKit Authors

Permission to use, copy, modify, and/or distribute this software for any purpose
with or without fee is hereby granted, provided that the above copyright notice
and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
THIS SOFTWARE.

25 changes: 25 additions & 0 deletions src/rauc-installation-status/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
AM_CPPFLAGS = -D_DEFAULT_SOURCE -D_XOPEN_SOURCE -D_GNU_SOURCE
bin_PROGRAMS = rauc-installation-status
rauc_installation_status_SOURCES = rauc-installation-status.c

rauc_installation_status_CFLAGS = \
$(glib_CFLAGS) \
$(jansson_CFLAGS) \
$(CFLAGS)
rauc_installation_status_LDADD = \
$(glib_LIBS) \
$(jansson_LIBS)

BUILT_SOURCES = $(rauc_installer_sources)
EXTRA_DIST = de.pengutronix.rauc.Installer.xml

rauc_installer_sources = rauc-installer.c rauc-installer.h
$(rauc_installer_sources): de.pengutronix.rauc.Installer.xml
$(AM_V_GEN) gdbus-codegen \
--generate-c-code rauc-installer \
--c-generate-autocleanup all \
--c-namespace Rauc \
--interface-prefix de.pengutronix.rauc. \
$<

nodist_rauc_installation_status_SOURCES = $(rauc_installer_sources)
29 changes: 29 additions & 0 deletions src/rauc-installation-status/configure.ac
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
AC_PREREQ(2.61)
AC_INIT([rauc-installation-status], [1.0], [https://github.com/kernelkit/infix/issues])
AM_INIT_AUTOMAKE(1.11 foreign subdir-objects)
AM_SILENT_RULES(yes)

AC_CONFIG_FILES([
Makefile
])

AC_PROG_CC
AC_PROG_INSTALL
LT_INIT


PKG_PROG_PKG_CONFIG

test "x$prefix" = xNONE && prefix=$ac_default_prefix
test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'

PKG_CHECK_MODULES([glib], [glib-2.0 >= 2.50 gio-2.0 gio-unix-2.0])
PKG_CHECK_MODULES([jansson], [jansson >= 2.0.0])


LIBDIR=`eval echo $libdir`
LIBDIR=`eval echo $LIBDIR`

AC_SUBST(LIBDIR)

AC_OUTPUT
Loading

0 comments on commit 0b5a305

Please sign in to comment.