[OLS-563] Add version to ols-ucentral-client

Add version to ols-ucentral-client
Augment the build to pull the schema version file from the ols-ucentral-schema repo (if present) based on commit id of
schema used as baseline for this client version.
Use both it and the version to provide the version information in the connect message.

Signed-off-by: Mike Hansen <mike.hansen@netexperience.com>
This commit is contained in:
Mike Hansen
2025-01-22 19:49:46 -05:00
parent 5936fbed88
commit 00ae4001e7
10 changed files with 160 additions and 21 deletions

View File

@@ -3,7 +3,7 @@ LABEL Description="Ucentral client (Build) environment"
ARG HOME /root
ARG EXTERNAL_LIBS ${HOME}/ucentral-external-libs
ARG SCHEMA_COMMITID adeeb0457b7060d192e4180f96eca60d562d1d15
SHELL ["/bin/bash", "-c"]
RUN apt-get update -q -y && apt-get -q -y --no-install-recommends install \
@@ -30,6 +30,7 @@ RUN git clone https://github.com/DaveGamble/cJSON.git ${HOME}/ucentral-external-
RUN git clone https://libwebsockets.org/repo/libwebsockets ${HOME}/ucentral-external-libs/libwebsockets/
RUN git clone --recurse-submodules -b v1.50.0 --depth 1 --shallow-submodules https://github.com/grpc/grpc ${HOME}/ucentral-external-libs/grpc/
RUN git clone --recursive --branch v7.1.4 https://github.com/zhaojh329/rtty.git ${HOME}/ucentral-external-libs/rtty/
RUN git clone https://github.com/Telecominfraproject/ols-ucentral-schema.git ${HOME}/ucentral-external-libs/ols-ucentral-schema/
# The following libs should be prebuilt in docker-build-env img to speed-up
# recompilation of only the ucentral-client itself
@@ -62,3 +63,7 @@ RUN cd ${HOME}/ucentral-external-libs/rtty/ && \
cd build && \
cmake .. && \
make -j4
RUN cd ${HOME}/ucentral-external-libs/ols-ucentral-schema/ && \
git checkout ${SCHEMA_COMMITID}

View File

@@ -50,8 +50,13 @@ build-ucentral-app: run-host-env
@echo Running ucentralclient docker-build-env container to build ucentral-client...;
docker exec -t ${CONTAINER_NAME} /root/ols-nos/docker-build-client.sh
docker cp ${CONTAINER_NAME}:/root/deliverables/ src/docker/
# copy the schema version, if it is there
docker cp ${CONTAINER_NAME}:/root/ucentral-external-libs/ols-ucentral-schema/schema.json src/docker/ || true
docker container stop ${CONTAINER_NAME} > /dev/null 2>&1 || true;
docker container rm ${CONTAINER_NAME} > /dev/null 2>&1 || true;
if [ -f version.json ]; then
cp version.json src/docker/
fi
build-ucentral-docker-img: build-ucentral-app
pushd src
@@ -91,6 +96,8 @@ clean:
rm -rf src/docker/deliverables || true;
rm -rf src/docker/lib* || true;
rm -rf src/docker/ucentral-client || true;
rm -rf src/docker/version.json || true;
rm -rf src/docker/schema.json || true;
rm -rf src/debian/ucentral-client.substvars 2>/dev/null || true;
rm -rf src/debian/shasta-ucentral-client.debhelper.log 2>/dev/null || true;
rm -rf src/debian/.debhelper src/debian/ucentral-client 2>/dev/null || true;

View File

@@ -21,6 +21,8 @@ COPY /ucentral-client /usr/local/bin/ucentral-client
COPY /rtty /usr/local/bin/
COPY /lib* /usr/local/lib/
COPY /version.jso[n] /etc/
COPY /schema.jso[n] /etc/
RUN ldconfig
RUN ls -l /usr/local/bin/ucentral-client

View File

@@ -2,4 +2,8 @@ plat.a: plat-example.o
ar crs $@ $^
%.o: %.c
ifdef PLATFORM_REVISION
gcc -c -o $@ ${CFLAGS} -I ./ -I ../../include -D PLATFORM_REVISION='"$(PLATFORM_REVISION)"' $^
else
gcc -c -o $@ ${CFLAGS} -I ./ -I ../../include $^
endif

View File

@@ -2,6 +2,7 @@
#include <ucentral-platform.h>
#include <ucentral-log.h>
#include <plat-revision.h>
#define UNUSED_PARAM(param) (void)((param))
@@ -12,7 +13,11 @@ int plat_init(void)
int plat_info_get(struct plat_platform_info *info)
{
UNUSED_PARAM(info);
*info = (struct plat_platform_info){0};
snprintf(info->platform, sizeof info->platform, "%s", "Example Platform" );
snprintf(info->hwsku, sizeof info->hwsku, "%s", "example-platform-sku");
snprintf(info->mac, sizeof info->mac, "%s", "24:fe:9a:0f:48:f0");
return 0;
}
@@ -156,10 +161,45 @@ int plat_port_num_get(uint16_t *num_of_active_ports)
UNUSED_PARAM(num_of_active_ports);
return 0;
}
int plat_revision_get(char *str, size_t str_max_len)
{
snprintf(str, str_max_len, PLATFORM_REVISION);
return 0;
}
int plat_reboot_cause_get(struct plat_reboot_cause *cause)
{
UNUSED_PARAM(cause);
return 0;
}
int plat_event_subscribe(const struct plat_event_callbacks *cbs)
{
UNUSED_PARAM(cbs);
return 0;
}
void plat_event_unsubscribe(void)
{
return;
}
int plat_running_img_name_get(char *str, size_t str_max_len)
{
UNUSED_PARAM(str_max_len);
UNUSED_PARAM(str);
return 0;
}
int plat_metrics_save(const struct plat_metrics_cfg *cfg)
{
UNUSED_PARAM(cfg);
return 0;
}
int plat_metrics_restore(struct plat_metrics_cfg *cfg)
{
UNUSED_PARAM(cfg);
return 0;
}
int plat_run_script(struct plat_run_script *p)
{
UNUSED_PARAM(p);
return 0;
}

View File

@@ -0,0 +1,14 @@
#ifndef _PLAT_REVISION
#define _PLAT_REVISION
#define XSTR(x) STR(x)
#define STR(x) #x
#define PLATFORM_REL_NUM 3.2.0
#define PLATFORM_BUILD_NUM 5
#ifndef PLATFORM_REVISION
#define PLATFORM_REVISION "Rel " XSTR(PLATFORM_REL_NUM) " build " XSTR(PLATFORM_BUILD_NUM)
#endif
#endif

View File

@@ -406,17 +406,46 @@ err:
proto_destroy_blob(&blob);
}
void
connect_send(void)
{
static cJSON *readJsonFile(const char *filename) {
FILE *file = fopen(filename, "r");
if (!file) {
fprintf(stderr, "Error opening file: %s\n", filename);
return NULL;
}
cJSON *ret;
// Get the file size
fseek(file, 0, SEEK_END);
long fileSize = ftell(file);
fseek(file, 0, SEEK_SET);
// Read the entire file into a buffer
char *buffer = (char *)malloc(fileSize + 1);
fread(buffer, 1, fileSize, file);
buffer[fileSize] = '\0'; // Null-terminate the string
// Close the file
fclose(file);
ret = cJSON_Parse(buffer);
return ret;
}
void connect_send(void) {
/* WIP: TMP hardcode; to be removed*/
unsigned mac[6];
struct plat_platform_info pinfo = {0};
struct plat_metrics_cfg restore_metrics = { 0 };
struct plat_metrics_cfg restore_metrics = {0};
struct blob blob = {0};
uint64_t uuid_buf; /* fixed storage size */
cJSON *params;
cJSON *cap;
cJSON *ver;
int ret;
blob.obj = proto_new_blob("connect");
@@ -446,7 +475,6 @@ connect_send(void)
if (password) {
if (!cJSON_AddStringToObject(params, "password", password))
goto err;
memset(password, 0, strlen(password));
free(password);
password = NULL;
@@ -456,30 +484,60 @@ connect_send(void)
if (!cap)
goto err;
ver = cJSON_AddObjectToObject(cap, "version");
if (!ver)
goto err;
if (plat_info_get(&pinfo)) {
UC_LOG_CRIT("failed to get platform info");
} else {
if (!cJSON_AddStringToObject(cap, "compatible", pinfo.hwsku))
goto err;
if (!cJSON_AddStringToObject(cap, "model", pinfo.platform))
goto err;
}
if (!cJSON_AddStringToObject(cap, "serial", client.serial))
goto err;
if (!cJSON_AddStringToObject(cap, "firmware", client.firmware))
goto err;
cJSON *client_version_json = readJsonFile(client.ols_client_version_file);
if (!client_version_json)
goto err;
if (!cJSON_AddItemToObject(ver, "switch", client_version_json))
goto err;
else
UC_LOG_DBG("client version added to connect.capabilities.version");
cJSON *schema_version_json = readJsonFile(client.ols_schema_version_file);
if (!schema_version_json) {
UC_LOG_DBG("No schema version present.");
}
else {
if (!cJSON_AddItemToObject(ver, "schema", schema_version_json))
goto err;
else
UC_LOG_DBG("schema version added to connect.capabilities.version");
}
if (!cJSON_AddStringToObject(cap, "compatible", pinfo.hwsku))
goto err;
if (!cJSON_AddStringToObject(cap, "model", pinfo.platform))
goto err;
if (!cJSON_AddStringToObject(cap, "platform", "switch"))
goto err;
if (client.serial &&
sscanf(client.serial, "%2x%2x%2x%2x%2x%2x",
&mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]) == 6) {
sscanf(client.serial, "%2x%2x%2x%2x%2x%2x",
&mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]) == 6) {
char label_mac[32];
snprintf(label_mac, sizeof label_mac,
"%02x:%02x:%02x:%02x:%02x:%02x",
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
"%02x:%02x:%02x:%02x:%02x:%02x",
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
if (!cJSON_AddStringToObject(cap, "label_macaddr", label_mac)) {
goto err;
}
} else {
}
else {
UC_LOG_DBG("failed to parse serial as label_macaddr");
}
@@ -490,11 +548,11 @@ connect_send(void)
if (ucentral_metrics.state.enabled)
plat_state_poll(state_send,
ucentral_metrics.state.interval);
ucentral_metrics.state.interval);
if (ucentral_metrics.healthcheck.enabled)
plat_health_poll(health_send,
ucentral_metrics.healthcheck.interval);
ucentral_metrics.healthcheck.interval);
}
UC_LOG_DBG("xmit connect\n");

View File

@@ -67,6 +67,8 @@ lws_protocols protocols[] = {
struct client_config client = {
.redirector_file = "/tmp/ucentral-redirector.json",
.redirector_file_dbg = "/tmp/firstcontact.hdr",
.ols_schema_version_file = "/etc/schema.json",
.ols_client_version_file = "/etc/version.json",
.server = NULL,
.port = 15002,
.path = "/",

View File

@@ -41,6 +41,8 @@ extern "C" {
struct client_config {
const char *redirector_file;
const char *redirector_file_dbg;
const char *ols_client_version_file;
const char *ols_schema_version_file;
const char *server;
int16_t port;
const char *path;

5
version.json Normal file
View File

@@ -0,0 +1,5 @@
{
"major": 3,
"minor": 2,
"patch": 7
}